aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/core')
-rw-r--r--gamemode/core/database/sv_queries.lua9
-rw-r--r--gamemode/core/database/sv_setup.lua28
-rw-r--r--gamemode/core/inventory/inventory.lua5
-rw-r--r--gamemode/core/inventory/sv_invtracker.lua3
-rw-r--r--gamemode/core/mapstich/sv_mapstich.lua10
5 files changed, 28 insertions, 27 deletions
diff --git a/gamemode/core/database/sv_queries.lua b/gamemode/core/database/sv_queries.lua
index 4e48255..f059b44 100644
--- a/gamemode/core/database/sv_queries.lua
+++ b/gamemode/core/database/sv_queries.lua
@@ -11,19 +11,21 @@ function q.serialize_player(ply)
local sdata = {}
local invs = {}
for k,v in pairs(ply.data.inventories) do
- invs[k] = {v.Name,v:Serialize()}
+ local idata = string.format("%q",v:Serialize())
+ invs[k] = {v.Name,string.sub(idata,2,#idata-1)} --remove the otter quotes
end
sdata.inventories = invs
sdata.skills = ply.data.skills
sdata.quests = ply.data.quests
sdata.prayers = ply.data.prayers
sdata.credits = ply.data.credits
- return util.TableToJSON(sdata)
+ local ret = util.TableToJSON(sdata)
+ return ret
end
function q.deserialize_player(ply,str)
- print("Deseriailizeing player",ply," with ", str)
track.ClearInventories(ply)
+ ply.data = ply.data or {}
local tbl = util.JSONToTable(str)
local invs = tbl.inventories
print("Inventories was", invs)
@@ -32,7 +34,6 @@ function q.deserialize_player(ply,str)
print("Giveing inventory",v[1],v[2])
track.GiveInventoryWithData(ply,v[1],v[2])
end
- ply.data = ply.data or {}
ply.data.skills = tbl.skills or {}
ply.data.quests = tbl.quests or {}
ply.data.prayers = tbl.prayers or {}
diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua
index 607c7be..6a7548d 100644
--- a/gamemode/core/database/sv_setup.lua
+++ b/gamemode/core/database/sv_setup.lua
@@ -52,35 +52,22 @@ function sql.GetPlayerData(ply)
local s64 = ply:SteamID64()
local q_str = q.s_fmt(fetch_player_query,s64)
local q_suc = function(res,li)
- --print("Got player's data:",res,type(res))
+ print("Got player's data:",res,type(res))
if res == nil then
- --print("Was nil, createing player data")
+ print("Was nil, createing player data")
sql.CreatePlayerTable(ply)
else
- --PrintTable(res)
assert(#res == 1,"Not unique!")
- --print("Was unique!")
local meta = res[1].MetaData
local plyd = res[1].PlayerData
local mtbl = util.JSONToTable(meta)
- --print("About to check if we are on the right server")
+ print("About to check if we are on the right server")
if mtbl.lastserver ~= game.GetIPAddress() then
- --print("Connecting player to ", mtbl.lastserver, " was on ", game.GetIPAddress())
+ print("Connecting player to ", mtbl.lastserver, " was on ", game.GetIPAddress())
ply:ConCommand("connect " .. mtbl.lastserver)
return
end
- --print("We were on the right server")
-
- --print("Before finding data in the metatable, mtbl was ")
- --PrintTable(mtbl)
- --print(type(mtbl.lastlocation))
- local _,_,x,y,z = string.find(mtbl.lastlocation,"([-%d%.]+) ([-%d%.]+) ([-%d%.]+)")
- local vec = {x,y,z}
- for k,v in pairs(vec) do vec[k] = tonumber(v) end
- --print("setting player pos to")
- --PrintTable(vec)
-
- ply:SetPos(Vector(unpack(vec)))
+ ply:SetPos(mtbl.lastlocation)
q.deserialize_player(ply,plyd)
end
end
@@ -88,6 +75,11 @@ function sql.GetPlayerData(ply)
MySQLite.query(q_str,q_suc,q_fai)
end
+concommand.Add("artery_loadplayer",function(ply,cmd,args)
+ if not ply:IsAdmin() then return end
+ sql.GetPlayerData(ply)
+end)
+
function sql.CreatePlayerTable(ply)
--print("Createing player table....")
local s64 = ply:SteamID64()
diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua
index f28cc18..5ff4c10 100644
--- a/gamemode/core/inventory/inventory.lua
+++ b/gamemode/core/inventory/inventory.lua
@@ -4,7 +4,7 @@
Registers a new inventory prototype, see below
CreateInventory(string_name) ::table_inventory
Creates a new inventory be sure to set the .owner and .id fields!
- CreateInventoryFromData(string_name,string_data)::table_inventory)
+ CreateInventoryFromData(string_name,string_data,entity_owner)::table_inventory)
Just deserializes an inventory. You still need to set .owner and .id!
DeriveInventory(string_name) ::table_inventory
Creates a new inventory from an old, allows for heiarchy.
@@ -144,8 +144,9 @@ function inv.CreateInventory(name)
end
--Recreates an inventory from data
-function inv.CreateInventoryFromData(name,data)
+function inv.CreateInventoryFromData(name,data,owner)
local tinv = inv.CreateInventory(name)
+ tinv.Owner = owner
--print("tinv was", tinv)
--PrintTable(tinv)
local ret = tinv:DeSerialize(data)
diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua
index c60298c..bb5aba6 100644
--- a/gamemode/core/inventory/sv_invtracker.lua
+++ b/gamemode/core/inventory/sv_invtracker.lua
@@ -171,10 +171,9 @@ end
function track.GiveInventoryWithData(ply,name,data)
print("Giveing inventory with data")
- local i = inv.CreateInventoryFromData(name,data)
+ local i = inv.CreateInventoryFromData(name,data,ply)
local nid = #ply.data.inventories + 1
local observer = track.MakeInventoryObserver(ply,nid)
- i.Owner = ply
i.id = nid
i:AddObserver(observer)
ply.data.inventories[nid] = i
diff --git a/gamemode/core/mapstich/sv_mapstich.lua b/gamemode/core/mapstich/sv_mapstich.lua
index 93f8667..121c0c9 100644
--- a/gamemode/core/mapstich/sv_mapstich.lua
+++ b/gamemode/core/mapstich/sv_mapstich.lua
@@ -19,7 +19,7 @@ local function SavePlayerData(ply)
query = q.s_fmt(query,pdat,ply:SteamID64())
else
query = [[
- UPDATE playerdata SET PlayerData='%s' MetaData='%s' WHERE SteamID=%.0f
+ UPDATE playerdata SET PlayerData='%s', MetaData='%s' WHERE SteamID=%.0f
]]
local pmet = util.TableToJSON({
lastserver = game.GetIPAddress(),
@@ -36,6 +36,10 @@ local function SavePlayerData(ply)
end)
end
+concommand.Add("artery_saveplayer",function(ply,cmd,args)
+ SavePlayerData(ply)
+end)
+
net.Receive("art_zonechange",function(len,ply)
timer.Simple(0.5,function()
@@ -68,3 +72,7 @@ net.Receive("art_zonechange",function(len,ply)
end
end)
end)
+
+hook.Add("PlayerDisconnected","save_data_on_disconnect",function(ply)
+ SavePlayerData(ply)
+end)