Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanjunxiong committed Jun 20, 2017
1 parent a9f8432 commit de03899
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lua-cjson"]
path = lua-cjson
url = https://github.com/mpx/lua-cjson.git
[submodule "luafilesystem"]
path = luafilesystem
url = https://github.com/keplerproject/luafilesystem.git
21 changes: 18 additions & 3 deletions lualib/agent/agent_login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@ local tool = require "tool"

local player = {}

local InitPlayerCMD = {}
function InitPlayerCMD.init_player_data()
local ret = {}
local now = os.time()
ret.login_time = now
ret.register_time = now
return ret
end

local function get_init_data(cname)
local funname = string.format("init_%s_data", cname)
local func = InitPlayerCMD[funname]
assert(type(func) == "function")
return func()
end

local function load_data(cname, uid)
local ret = libdbproxy.findOne(uid, cname)
log.debug("cname: " .. cname .. " uid:" .. uid .. " ret: " .. tool.dump(ret))

ret = ret or {}
ret = ret or get_init_data(cname)
setmetatable(ret, {
__newindex = function(t, k, v)
t.dirty = true
Expand All @@ -21,8 +37,7 @@ end

local function load_all_data()
local ret = {}
ret.player = "dump"
ret.item = "dump"
ret.player = true
for k, v in pairs(ret) do
ret[k] = load_data(k, player.uid)
end
Expand Down
14 changes: 14 additions & 0 deletions lualib/player.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

local Player = {}

Player.__index = Player

function Player.new(o)
local o = o or {}
setmetatable(o, Player)
return o
end


return Player

0 comments on commit de03899

Please sign in to comment.