summaryrefslogtreecommitdiff
path: root/gamemode
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode')
-rw-r--r--gamemode/server/database.lua64
1 files changed, 48 insertions, 16 deletions
diff --git a/gamemode/server/database.lua b/gamemode/server/database.lua
index b736bfb..20efafc 100644
--- a/gamemode/server/database.lua
+++ b/gamemode/server/database.lua
@@ -11,19 +11,21 @@ Uses:
Enables extra debugging to find errors easily
]]
+print("Hello from database.lua!")
+
function loadTable(uniqueIdentifier)
return nil
end
function storeTable(uniqueIdentifier, table)
- if(GM.StorageDebug) then
+ if (GM.StorageDebug) then
print("Asked to store:")
PrintTable(table)
end
- if(GM.StorageDebug) then
+ if (GM.StorageDebug) then
for k,v in pairs(tbl) do
- if(isfunction(v)) then
+ if (isfunction(v)) then
print("Database.lua error: tried to save a table that has a function in it!")
PrintTable(tbl)
print("At field:")
@@ -34,28 +36,57 @@ function storeTable(uniqueIdentifier, table)
end
-local function storetable(tbl)
- if(GM.StorageMethod == "Text") then
-
- elseif(GM.StorageMethod == "Static Map") then
- local storagetable = convertTableStatic(tbl)
- elseif(GM.StorageMethod == "LZWCompressed") then
+--Remove symbols that might be used as part of the storage scheme
+local function encodeSymbolic(mstring)
+ local replacements = {
+ {"\\", "\\\\"},
+ {"{","\\{"},
+ {"}","\\}"},
+ {"(","\\("},
+ {")","\\)"},
+ }
+ local ostring = mstring
+ for k,v in pairs(replacements) do
+ ostring = string.Replace(ostring,v[1],v[2])
+ end
+end
- else
- print("------------ERROR: database.lua----------")
- print("\tGM.StorageMethod is not a valid value!")
- print("Should be on of:\"Text\",\"Static Map\", or \"LZWCompressed\", but is:")
- print(GM.StorageMethod)
+local function convertTableText(tbl)
+ local output = "t("
+ local function addtoout(k)
+ if (istable(k)) then
+ output = output .. convertTableText(k)
+ elseif (isstring(k)) then
+ output = output .. "s(" .. encodeSymbolic(k) .. ")"
+ elseif (isnumber(k)) then
+ output = output .. "n(" .. k .. ")"
+ elseif (isbool(k)) then
+ if (k) then output = output .. "b(true)"
+ else output = output .. "b(false)" end
+ elseif (isangle(k)) then
+ output = output .. "a(" .. k.p .. "," .. k.y .. "," .. k.r .. ")"
+ elseif (isvector(k)) then
+ output = output .. "v(" .. k.x .. "," .. k.y .. "," .. k.z .. ")"
+ else
+ assert(true,"Tried to store unknown value type:")
+ printi(k)
+ end
+ end
+ for k,v in pairs(tbl) do
+ addtoout(k)
+ output = output .. ":"
+ addtoout(v)
end
+ output = output .. ")"
end
+--[[
local function convertTableStatic(tbl)
- if(GM.StorageStaticMap == nil) then
+ if (GM.StorageStaticMap == nil) then
print("---------ERROR: database.lua-----------")
print("\tGM.StorageMethod is set to \"Static Map\", but GM.StoreageStaticMap is not defined!")
return
end
- local converted = {}
@@ -68,3 +99,4 @@ end
local function parseStaticTable(tbl)
end
+--]]