aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-05-20 11:37:23 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-05-20 11:37:23 -0400
commitc6698dad925e75ffd2ca2f2e30a595d4ce48d240 (patch)
tree226338dc7ee26a6316951554cf953112ba072c76 /gamemode/core
parent9e0537b0aa417e88a6a61238484ddcef74080ae0 (diff)
downloadartery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.tar.gz
artery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.tar.bz2
artery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.zip
Massive changes I guess
Diffstat (limited to 'gamemode/core')
-rw-r--r--gamemode/core/database/sv_setup.lua44
-rw-r--r--gamemode/core/inventory/inventory.lua20
-rw-r--r--gamemode/core/inventory/item.lua31
-rw-r--r--gamemode/core/inventory/sv_invtracker.lua13
-rw-r--r--gamemode/core/npc/cl_shop.lua11
-rw-r--r--gamemode/core/npc/sv_npcsystem.lua12
-rw-r--r--gamemode/core/pac/sv_pac.lua37
7 files changed, 96 insertions, 72 deletions
diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua
index 2cb69d1..fd44174 100644
--- a/gamemode/core/database/sv_setup.lua
+++ b/gamemode/core/database/sv_setup.lua
@@ -30,15 +30,15 @@ end
local function connect()
- print("Connecting to the database...")
+ --print("Connecting to the database...")
MySQLite.initialize(config)
end
hook.Add("DatabaseInitialized","setup_table",function()
assert(MySQLite.isMySQL(),"Database wasn't mysqloo, something is probably wrong!")
local setup_success = function(res,li)
- print("Set up connection to db")
+ --print("Set up connection to db")
end
- print("Setup query:",setup_db)
+ --print("Setup query:",setup_db)
MySQLite.query(setup_db,setup_success,q_fai)
end)
@@ -52,56 +52,56 @@ 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)
+ --PrintTable(res)
assert(#res == 1,"Not unique!")
- print("Was 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("We were on the right server")
- print("Before finding data in the metatable, mtbl was ")
- PrintTable(mtbl)
- print(type(mtbl.lastlocation))
+ --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)
+ --print("setting player pos to")
+ --PrintTable(vec)
ply:SetPos(Vector(unpack(vec)))
q.deserialize_player(ply,plyd)
end
end
- print("doing query",q_str)
+ --print("doing query",q_str)
MySQLite.query(q_str,q_suc,q_fai)
end
function sql.CreatePlayerTable(ply)
- print("Createing player table....")
+ --print("Createing player table....")
local s64 = ply:SteamID64()
- print("steamid was", s64)
+ --print("steamid was", s64)
local plytbl = data.newdata()
local plymet = data.newmeta()
local plydata = util.TableToJSON(plytbl)
local metdata = util.TableToJSON(plymet)
local q_str = q.s_fmt(create_player_query,s64,plydata,metdata)
local q_suc = function(res,li)
- print("Inserted new player",ply)
+ --print("Inserted new player",ply)
sql.GetPlayerData(ply)
end
- print("doing query", q_str)
+ --print("doing query", q_str)
MySQLite.query(q_str,q_suc,q_fai)
end
@@ -114,7 +114,7 @@ function sql.SendPlayerToInstance(ply,ls,ll)
})
local q_str = q.s_fmt(save_player_query,plymeta,plydata,s64)
local q_suc = function(res,li)
- print("Successfully saved player data")
+ --print("Successfully saved player data")
end
MySQLite.query(q_str,q_suc,q_fai)
end
@@ -131,6 +131,6 @@ concommand.Add("DoQuery",function(ply,cmd,args)
end
end)
-print("In sv_setup.lua, sql before returning is", sql)
+--print("In sv_setup.lua, sql before returning is", sql)
return sql
diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua
index 6b6f6f4..62e4819 100644
--- a/gamemode/core/inventory/inventory.lua
+++ b/gamemode/core/inventory/inventory.lua
@@ -85,8 +85,8 @@ local function SetDefaultObservers(tbl)
local oldput,oldremove = tbl.Put,tbl.Remove
tbl.Put = function(self,position,item)
for k,v in pairs(self.observers) do
- print("Calling put on observer:")
- PrintTable(v)
+ --print("Calling put on observer:")
+ --PrintTable(v)
v:Put(position,item)
end
oldput(self,position,item)
@@ -120,20 +120,20 @@ function inv.RegisterInventory(tbl)
string.format("Attempted to register inventory with field %q of type %q when it should have been %q",v[1],type(tbl[v[1]]),v[2]))
end
assert(inventories[tbl.Name] == nil,
- "Attempted to register 2 inventories with the same name:" .. tbl.Name)
+ string.format("Attempted to register 2 inventories with the same name: %q", tbl.Name))
assert((tbl.AddObserver == nil and tbl.RemoveObserver == nil) or
(tbl.AddObserver ~= nil and tbl.RemoveObserver ~= nil),
- "AddObserver and RemoveObserver must be defined in pairs")
+ "AddObserver and RemoveObserver must be defined in pairs")
if tbl.AddObserver == nil then
SetDefaultObservers(tbl)
end
inventories[tbl.Name] = tbl
- print("Registered inventory: " .. tbl.Name)
+ --print("Registered inventory: " .. tbl.Name)
end
--Create an inventory
function inv.CreateInventory(name)
- print("Createing inventory", name)
+ --print("Createing inventory", name)
assert(inventories[name] ~= nil, string.format("Tried to create a copy of inventory that does not exist:%s\nValid inventories are:\n\t%s",name,table.concat(table.GetKeys(inventories),"\n\t")))
local ret = TableCopy(inventories[name])
ret.observers = {}
@@ -143,11 +143,11 @@ end
--Recreates an inventory from data
function inv.CreateInventoryFromData(name,data)
local tinv = inv.CreateInventory(name)
- print("tinv was", tinv)
- PrintTable(tinv)
+ --print("tinv was", tinv)
+ --PrintTable(tinv)
tinv:DeSerialize(data)
- print("is now",tinv)
- PrintTable(tinv)
+ --print("is now",tinv)
+ --PrintTable(tinv)
return tinv
end
diff --git a/gamemode/core/inventory/item.lua b/gamemode/core/inventory/item.lua
index 103da7f..a13efa9 100644
--- a/gamemode/core/inventory/item.lua
+++ b/gamemode/core/inventory/item.lua
@@ -23,14 +23,19 @@ local required_fields = {
"Name","Serialize","DeSerialize"
}
-local items = {} --Master table of all item prototypes
+local items = items or {} --Master table of all item prototypes
function itm.RegisterItem(tbl)
for k,v in pairs(required_fields) do
assert(tbl[v] ~= nil, string.format("Attempted to register item without field %q",v))
end
- assert(items[tbl.Name] == nil, string.format("Attempted to register 2 items with the same name %q",tbl.Name))
+ --assert(items[tbl.Name] == nil, string.format("Attempted to register 2 items with the same name %q",tbl.Name))
+ if items[tbl.Name] ~= nil then
+ MsgC(Color(255,255,0),"WARNING: attemtpted to register 2 items with the same name " .. tbl.Name .. "\n")
+ else
+ MsgC(Color(0,255,0),"Registered Item " .. tbl.Name .. "\n")
+ end
items[tbl.Name] = tbl
- print("Registered item: " .. tbl.Name)
+ --print("Registered item: " .. tbl.Name)
end
function itm.GetItemByName(name)
@@ -49,11 +54,23 @@ function itm.GetItemFromData(name,data)
return items[name]:DeSerialize(data)
end
+local function printitems()
+ local tbl = {}
+ for k,v in pairs(items) do
+ tbl[#tbl + 1] = k
+ end
+ print(table.concat(tbl,"\n"))
+end
+
--Must be called in a coroutine.
function itm.DeriveItem(tbl,name)
+ print("Attempting to derive item",name)
while items[name] == nil do
+ print("it dosen't exist yet, items are")
+ printitems()
coroutine.yield()
end
+ print(name,"exists!")
--Create a flywieght copy
local ret = tbl
local mt = {
@@ -64,10 +81,8 @@ function itm.DeriveItem(tbl,name)
setmetatable(ret,mt)
end
-concommand.Add("art_printitems",function()
- for k,v in pairs(items) do
- print(k)
- end
-end)
+hook.Call("artery_include_items")
+
+concommand.Add("art_printitems",printitems)
return itm
diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua
index 47dd164..56407e2 100644
--- a/gamemode/core/inventory/sv_invtracker.lua
+++ b/gamemode/core/inventory/sv_invtracker.lua
@@ -246,25 +246,26 @@ function track.SendPlayerData(ply)
net.Send(ply)
end
-concommand.Add("SendMeData",function(ply,cmd,args)
+concommand.Add("artery_SendMeData",function(ply,cmd,args)
track.ClearInventories(ply)
track.GiveInventoryTo(ply,"Equipment")
track.SendPlayerData(ply)
end)
-concommand.Add("ShowMyInventories",function(ply,cmd,args)
+concommand.Add("artery_ShowMyInventories",function(ply,cmd,args)
PrintTable(ply.data.inventories)
end)
-concommand.Add("AddInventory",function(ply,cmd,args)
+concommand.Add("artery_AddInventory",function(ply,cmd,args)
track.GiveInventoryTo(ply,args[1])
end)
-concommand.Add("GiveItem",function(ply,cmd,args)
+concommand.Add("artery_GiveItem",function(ply,cmd,args)
xpcall(function()
ply:GiveItem(itm.GetItemByName(args[1]))
- end,function()
- print("Could not find a position to put that in!")
+ end,function(err)
+ print("Could not give that item!:")
+ print(err)
end)
end)
diff --git a/gamemode/core/npc/cl_shop.lua b/gamemode/core/npc/cl_shop.lua
index fa076ce..c2c71bc 100644
--- a/gamemode/core/npc/cl_shop.lua
+++ b/gamemode/core/npc/cl_shop.lua
@@ -52,12 +52,9 @@ local function DrawShopItemOnDPanel(dp,itemtbl,cost)
net.SendToServer()
end
- print("Displaying shape:")
- PrintTable(shape)
for k = 1, twidth do
for i = 1, theight do
if not shape[k][i] then
- print("Found false spot:",k,i)
local emptyslot = vgui.Create("DPanel", dp)
emptyslot:SetSize(slotsize,slotsize)
emptyslot:SetPos(slotsize * (i - 1) + 2, slotsize * (k - 1) + 2)
@@ -81,9 +78,7 @@ local slotsize = math.Round(w / 32)
local function DrawShopOnDPanel(dp,items)
--This gets pretty involved, lets try to not make it a clusterfuck.
dp.Paint = function(self, wi, hi) draw.RoundedBox(4, 0,0,wi,hi,Color(100,0,0)) end
- print("dp",dp)
local scrollpanel = vgui.Create( "DScrollPanel",dp )
- print("scollpanel",scrollpanel)
scrollpanel.Paint = function(self, wi, hi) draw.RoundedBox(4, 0,0,wi,hi,Color(0,0,100)) end
scrollpanel:Dock(FILL)
for k,v in pairs(items) do
@@ -93,13 +88,10 @@ local function DrawShopOnDPanel(dp,items)
draw.RoundedBox(4, 1,1,wi-4,hi-4,Color(50,50,50))
draw.RoundedBox(4, 2,2,wi-5,hi-5,Color(100,100,100))
end
- print("invpanel",invpanel)
DrawShopItemOnDPanel(invpanel,itemtbl,v[2])
scrollpanel:AddItem(invpanel)
invpanel:Dock(TOP)
local x,_ = invpanel:GetSize()
- print("item is",v)
- PrintTable(v)
invpanel:SetSize(x,slotsize * (#itemtbl.Shape) + 4)
invpanel:Dock(TOP)
@@ -110,7 +102,6 @@ end
local shopwindow,shoppanel
local function createshopwindow()
- print("Createing shopwindow")
shopwindow = vgui.Create( "DFrame" )
shopwindow:SetPos( w - (w / 4), 0 )
shopwindow:SetSize( w / 4, h )
@@ -129,10 +120,8 @@ end
createshopwindow()
net.Receive("art_openshop",function()
- print("shopwindows was ",shopwindow)
if not shopwindow:IsValid() then createshopwindow() end
assert(shopwindow,"Shopwindow was not created, even after re-createing!")
- print("inv was", inv)
inv.ShowInventory()
shopwindow:SetVisible(true)
local stock = net.ReadTable()
diff --git a/gamemode/core/npc/sv_npcsystem.lua b/gamemode/core/npc/sv_npcsystem.lua
index 78b041f..c53f6ae 100644
--- a/gamemode/core/npc/sv_npcsystem.lua
+++ b/gamemode/core/npc/sv_npcsystem.lua
@@ -12,7 +12,7 @@ end
function n.CreateNPCByName(npcname, pos)
assert(npcs[npcname],string.format("No npc named %q, valid names are:\n%s",npcname,table.concat(table.GetKeys(npcs),"\n")))
- print("Createing a ", npcname, " at ", pos)
+ --print("Createing a ", npcname, " at ", pos)
local npctbl = npcs[npcname]
local npc = ents.Create("npc_huntable")
npc:SetPos(pos)
@@ -28,13 +28,13 @@ end
--Creates a shop npc with this tbl
function n.CreateShop(npc)
- print("Createing shop npc")
+ --print("Createing shop npc")
local npcent = ents.Create("npc_shop")
for k,v in pairs(npc) do
npcent[k] = v
end
npcent:Spawn()
- print("Called spawn")
+ --print("Called spawn")
end
--Creates a townie npc with this tbl
@@ -87,11 +87,11 @@ local function loadMap()
local foldername = "artery/maps/" .. mapname
ExecuteOnFolder(foldername,true,function(path)
- print("I want to run",path)
+ --print("I want to run",path)
local filetxt = file.Read(path,"DATA")
- print("File text is", filetxt)
+ --print("File text is", filetxt)
CompileString(filetxt,path)()
- print("I want to execute",path)
+ --print("I want to execute",path)
end)
end
diff --git a/gamemode/core/pac/sv_pac.lua b/gamemode/core/pac/sv_pac.lua
index 482dea6..30d2ef7 100644
--- a/gamemode/core/pac/sv_pac.lua
+++ b/gamemode/core/pac/sv_pac.lua
@@ -48,28 +48,42 @@ hook.Add("PrePACConfigApply", "stoppacs", function(ply, outfit_data)
end
end)
+local pacsources = {
+ ["data/artery/pacs/"] = "GAME"
+}
+function p3.AddPacSource(filepath,from)
+ pacsources[filepath] = from
+end
+
--When the server starts, get all the pacs and calculate their hashes so we can index them quickly without haveing to read from disk each time.
local pachashes = {}
local function loadhashes()
- local files,_ = file.Find("artery/pacs/*","DATA")
- for _,v in ipairs(files) do
- local filepath = string.format("artery/pacs/%s",v)
- local filetext = file.Read(filepath,"DATA")
- local filehash = util.CRC(filetext)
- pachashes[string.StripExtension(v)] = tonumber(filehash)
+ for path,part in pairs(pacsources) do
+ local files,_ = file.Find(path.."*",part)
+ for _,v in ipairs(files) do
+ local filepath = string.format("%s%s",path,v)
+ local filetext = file.Read(filepath,part)
+ local filehash = util.CRC(filetext)
+ pachashes[string.StripExtension(v)] = tonumber(filehash)
+ end
end
end
loadhashes()
+concommand.Add("artery_reload_pac_hashes",loadhashes)
local appliedpacs = {}
function p3.ApplyPac(what, name)
- print("Applying pac", what, "to",name)
+ print("Applying pac", name, "to",what)
appliedpacs[what] = appliedpacs[what] or {}
appliedpacs[what][name] = pachashes[name]
net.Start("artery_applypac")
net.WriteEntity(what)
net.WriteString(name)
+ --If this pac is from an addon that was loaded after this file was, we may need to reload hashes.
+ if not pachashes[name] then
+ loadhashes()
+ end
net.WriteUInt(pachashes[name],32)
net.Broadcast()
end
@@ -107,6 +121,7 @@ local pac_cache = {}
local function cacheload(key)
--If it's already in the cache, just update the time it was last used and return the pac.
if pac_cache[key] ~= nil then
+ print("Pac was already in the cache.")
pac_cache[key].time = CurTime()
if pac_cache[key].pac == nil then
PrintTable(pac_cache)
@@ -116,8 +131,9 @@ local function cacheload(key)
end
--Otherwise, we need to load it.
- local pacpath = string.format("artery/pacs/%s.txt",key)
- local pacfile = file.Read(pacpath,"DATA")
+ local pacpath = string.format("data/artery/pacs/%s.txt",key)
+ local pacfile = file.Read(pacpath,"GAME")
+ print("Pac was not in cache, reloading, pac txt is",pacfile)
--If we haven't reached max cache yet, just put it in
if pacs_in_cache < max_pacs_in_cache then
@@ -155,6 +171,9 @@ net.Receive("artery_requestpac",function(ln,ply)
local pac_txt = cacheload(pac_name)
+ assert(pac_name,"Pac's name was nil!")
+ assert(pac_txt, "Pac's txt was nil (from the cache)")
+
net.Start("artery_downloadpac")
net.WriteString(pac_name)
net.WriteString(pac_txt)