summaryrefslogtreecommitdiff
path: root/gamemode/server/database.lua
blob: 20efafc79dd08b733a422e25f515c70423eefb37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
--Provides an interface to store data in a database of some kind
--[[
Uses:
  GM.StorageMethod
    Can be: "Text", "Static Map", "LZWCompressed"
    If method is "Static Map", then GM.StoreageStaticMap must be a table of strings to string ID's.
  GM.StorageBackend
    Can be: "File"
  GM.StorageDebug
    Can be: true, false
    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
    print("Asked to store:")
    PrintTable(table)
  end
  if (GM.StorageDebug) then
    for k,v in pairs(tbl) do
      if (isfunction(v)) then
        print("Database.lua error: tried to save a table that has a function in it!")
        PrintTable(tbl)
        print("At field:")
        print(k)
      end
    end
  end

end

--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

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
    print("---------ERROR: database.lua-----------")
    print("\tGM.StorageMethod is set to \"Static Map\", but GM.StoreageStaticMap is not defined!")
    return
  end



end

local function convertTableCompressed(tbl)

end

local function parseStaticTable(tbl)

end
--]]