diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-11-08 15:51:26 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-11-08 15:51:26 -0500 |
| commit | 2252904b8147419c551ad2653a20627281d0531f (patch) | |
| tree | c1d76a132fa085940dd33d8af99c08dd9da04675 /gamemode/core/database | |
| parent | 07593f0c983ac6b16161829b20ea6fde887fa7e9 (diff) | |
| download | artery-2252904b8147419c551ad2653a20627281d0531f.tar.gz artery-2252904b8147419c551ad2653a20627281d0531f.tar.bz2 artery-2252904b8147419c551ad2653a20627281d0531f.zip | |
Finished LDoc comments
Diffstat (limited to 'gamemode/core/database')
| -rw-r--r-- | gamemode/core/database/sv_queries.lua | 17 | ||||
| -rw-r--r-- | gamemode/core/database/sv_setup.lua | 28 |
2 files changed, 39 insertions, 6 deletions
diff --git a/gamemode/core/database/sv_queries.lua b/gamemode/core/database/sv_queries.lua index 6ef1201..3c5f309 100644 --- a/gamemode/core/database/sv_queries.lua +++ b/gamemode/core/database/sv_queries.lua @@ -1,12 +1,15 @@ ---[[ - Some helper functions for building sql queries -]] +---Helper functions for saveing and loading players. +-- Defines functions for saveing/loading the player +--@module sv_queries.lua local fn = nrequire("utility/fn.lua") local track = nrequire("core/inventory/sv_invtracker.lua") local log = nrequire("log.lua") local q = {} +---Creats a string representation of a player. +-- The string can be used to re-create the player's data with teh deserialize_player function +--@tparam player ply The player to serialize function q.serialize_player(ply) if not IsValid(ply) and ply.data and ply.data.inventories then return "" end local sdata = {} @@ -24,6 +27,10 @@ function q.serialize_player(ply) return ret end +---Loads a player from a serialized string. +-- Loads a player's data form the string given. The string can be created with the serialize_player() function +--@tparam player ply The player to load data for +--@tparam string str The string representation of the data function q.deserialize_player(ply,str) log.debug("Deserializing player's data : " .. ply:Nick() .. "\n" .. str) track.ClearInventories(ply) @@ -49,6 +56,10 @@ function q.deserialize_player(ply,str) track.SendPlayerData(ply) end +---Formats for an sql query. +-- Kind of like string.format, but arguments are pasesd through SQL sanitization  +--@tparam string fmt The string.format function +--@tparam varargs ... The parameters to format the string with function q.s_fmt(fmt,...) local args = {...} fn.map(args,MySQLite.SQLStr) diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua index 1fac11f..3fa1823 100644 --- a/gamemode/core/database/sv_setup.lua +++ b/gamemode/core/database/sv_setup.lua @@ -1,3 +1,7 @@ +---Functions for working the the mysqlite module. +-- Helps load players into their correct instance +--@module sv_setup.lua + --Adds the MySQLite global nrequire("sv_mysqlite.lua") local config = nrequire("config/sv_sql.lua") @@ -46,8 +50,10 @@ hook.Add("Initialize","initalizedbconnection",function() connect() end) - ---Retruns (PlayerData, MetaData) or nil +---Gets a player's data from the database. +-- Finds a player's data, returns nil if not found. Players are found off their steamid +--@tparam player ply The player to look for's data +--@treturn table|nil {PlayerData, MetaData} function sql.GetPlayerData(ply) local s64 = ply:SteamID64() local q_str = q.s_fmt(fetch_player_query,s64) @@ -82,11 +88,18 @@ function sql.GetPlayerData(ply) MySQLite.query(q_str,q_suc,q_fai) end +---Manually loads data for the caller. +-- Forefully loads a player's data.  +--@concommand artery_loadplayer concommand.Add("artery_loadplayer",function(ply,cmd,args) if not ply:IsAdmin() then return end sql.GetPlayerData(ply) end) +---Creates a new row for the player in the database. +-- Creates a new row for a player, works off the configuration in sv_newplayer.lua +--@see sv_newplayer.lua +--@tparam player ply The player to create the new row for function sql.CreatePlayerTable(ply) --print("Createing player table....") local s64 = ply:SteamID64() @@ -110,6 +123,11 @@ function sql.CreatePlayerTable(ply) MySQLite.query(q_str,q_suc,q_fai) end +---Sends a player to another server. +-- Usually when a player disconnects, their location & server are saved, this overrides that and sends them to another instance when they reconnect. +--@tparam player ply The player to send to a different instace +--@tparam string ls The server to send the player to +--@tparam vector3 ll The location to send the player to on that server function sql.SendPlayerToInstance(ply,ls,ll) local s64 = ply:SteamID64() local plydata = q.serialize_player(ply) @@ -124,7 +142,11 @@ function sql.SendPlayerToInstance(ply,ls,ll) MySQLite.query(q_str,q_suc,q_fai) end -concommand.Add("DoQuery",function(ply,cmd,args) +---Do queries related to the player creation. +-- Create the caller's data, Reload the coller's data, or Send the caller to another instance  +--@usage artery_DoQuery (create|get|send <server> <location>) +--@concommand artery_DoQuery +concommand.Add("artery_DoQuery",function(ply,cmd,args) if not ply:IsAdmin() then return end if args[1] == "create" then sql.CreatePlayerTable(ply) |
