diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-21 14:43:56 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-21 14:43:56 -0400 |
| commit | fcdc442a59841957844d3c28e134fd813ac6e9ab (patch) | |
| tree | cbb5c091f4eb83cf500dc77b8dd7f6b4e8cd4f9d | |
| parent | dce5504f263477402bb39f501f46a290f7531dfd (diff) | |
| download | gmstranded-fcdc442a59841957844d3c28e134fd813ac6e9ab.tar.gz gmstranded-fcdc442a59841957844d3c28e134fd813ac6e9ab.tar.bz2 gmstranded-fcdc442a59841957844d3c28e134fd813ac6e9ab.zip | |
More work on getting a proper database to work
| -rw-r--r-- | gamemode/server/database.lua | 64 |
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 +--]] |
