gitxsm 1 год назад
Родитель
Сommit
82e90a4119

+ 414 - 414
script/Main.lua

@@ -1,415 +1,415 @@
- if jit then
-  jit.off()
-  jit.flush()
-  print("jit close")
-end
- 
-real_os_time = real_os_time or os.time 
-local Timer   
-function os.time(tb) 
-    if tb then      
-        return real_os_time(tb)    
-    end    
-    Timer = Timer or require("core.Timer")    
-    local t = Timer.now          
-    return 0 < t and (t - t % 1000) / 1000 or real_os_time()         
-end     
-              
-real_os_date = real_os_date or os.date                     
-local tb = {}     
-for i = 1, 64 do                    
-    tb[i] = {}                          
-end          
-
-                            
-local tblen = 0                                 
-function os.date(fmt, t)                          
-    t = t or os.time()                    
-    if fmt == "*t" then                  
-        tblen = tblen + 1   
-        if #tb < tblen then                  
-            tblen = 1                      
-        end            
-        local d = tb[tblen]       
-        d.year, d.month, d.day, d.hour, d.min, d.sec, d.wday,d.yday = global.date(t)        
-        return d             
-    else
-        return real_os_date(fmt, t) 
-    end 
-end 
-
-adj = adj or {}
-envs = envs or {}
-file_last_modify_time = file_last_modify_time or {}
-loaded = loaded or {}
-str2filename = str2filename or {}
-local sta = {}
-tb_loadfile = tb_loadfile or {} 
-local function hot_dfs(a)
-    if loaded[a] then
-        print("hot=====", a)  
-        loaded[a] = nil
-        for b in pairs(adj[a]) do 
-            hot_dfs(b)  
-        end   
-    end
-end 
-
-local function hot()
-    for k, v in pairs(str2filename) do
-        local a = global.get_file_last_modify_time(v)   
-        if a ~= file_last_modify_time[k] then
-            file_last_modify_time[k] = a 
-            tb_loadfile[k] = nil    
-            hot_dfs(k)
-        end
-    end 
-end
- 
-collectgarbage("step", 100000)
-hot()
-collectgarbage("step", 100000)
-
-local path = {
-    "script/",
-    "script/module/", 
-}  
-
-local require_cnt = 0 
-_G.old_require =  _G.old_require or require 
-
-threadID = threadID or nil
-function _G.get_tid() 
-    if not threadID then  
-        threadID = _G.get_thread_id(_G.logic_id) 
-    end  
-    return threadID     
-end 
-  
-ConfigLoadFile = ConfigLoadFile or nil
-function require(str, not_need_exist) 
-    
-    if not ConfigLoadFile then
-        ConfigLoadFile = {}
-        ConfigLoadFile = require("Config") 
-        print("load excel project:", ConfigLoadFile.PROJECT_NAME)
-    end
-    require_cnt = require_cnt + 1 
-    adj[str] = adj[str] or {} 
-    if sta[#sta] then   
-        adj[str][sta[#sta]] = true 
-    end 
-    sta[#sta + 1] = str    
-    if not loaded[str] then  
-        loaded[str] = true  
-        envs[str] = envs[str] or {  
-            _G = _G,  
-            assert = assert, 
-            error = error, 
-            getfenv = getfenv,  
-            ipairs = ipairs,  
-            load = load,   
-            next = next,   
-            pairs = pairs,
-            pcall = pcall,   
-            print = print,  
-            require = require,    
-            setmetatable = setmetatable,
-            tonumber = tonumber,  
-            tostring = tostring, 
-            type = type,  
-
-            debug = debug,  
-            io = io,  
-            math = math, 
-            string = string,   
-            table = table,  
-            os = os, 
-        } 
-        envs[str]._ENV = envs[str]   
-        if not str2filename[str] then    
-            local filename = string.gsub(str, "%.", "/") .. ".lua"  
-            local _, excelPos = string.find(filename, "excel/", 1, true)
-            if excelPos then
-                local prename = string.sub(filename, 1, excelPos)
-                local lastname = string.sub(filename, excelPos+1, #filename) 
-                filename = prename .. ConfigLoadFile.PROJECT_NAME .. "/" .. lastname
-            end              
-            local ac  
-            for _, v in ipairs(path) do  
-                local pre_filename = v .. filename    
-                local a = global.get_file_last_modify_time(pre_filename)   
-                if a ~= 0 then 
-                    str2filename[str] = pre_filename   
-                    file_last_modify_time[str] = a     
-                    ac = true  
-                    break  
-                end
-            end             
-            if not ac then  
-                if not_need_exist then
-                    return
-                else
-                    assert(nil, str .. " not exist") 
-                end   
-            end 
-        end 
-        local fun = tb_loadfile[str] 
-        if not fun then   
-            local err  
-            fun, err = loadfile(str2filename[str], nil, envs[str])  
-
-            if not fun then 
-                assert(nil, err) 
-            end  
-        end    
-        local require_cnt_old = require_cnt   
-        fun()    
-        if require_cnt_old < require_cnt then   
-            tb_loadfile[str] = fun    
-        end   
-    end  
-    sta[#sta] = nil   
-    return envs[str]  
-end   
-modtb = modtb or nil
-local function cmd2str(cmd)
-    if modtb then  
-      return
-    end  
-    local f = io.popen(cmd) 
-    local str = f:read("*a")   
-    assert(io.close(f)) 
-    return str 
-end 
- 
-local function get_modules(str)
-    if modtb then
-        return modtb   
-    end  
-    modtb = {}
-    local i = 1  
-    while true do 
-        local j = string.find(str, "\n", i)  
-        if not j then  
-            break
-        end 
-        modtb[#modtb + 1] = string.sub(str, i, j - 1) 
-        i = j + 1
-    end 
-    table.sort(modtb)
-    return modtb   
-end
- 
-local cmd = os.getenv("OS") == "Windows_NT" and "dir/b script\\module" or "ls script/module"
-local m = get_modules(cmd2str(cmd))
-local Msg = require("core.Msg") 
-local InnerMsg = require("core.InnerMsg")
-local Config = require("Config")  
-
-if Config.IS_MIDDLE == true then
-    _G['is_middle'] = true
-end
-
-function init_proto_id()  
-    if has_init_proto_id then 
-        return  
-    end  
-    local protoIDS = require("common.ProtoID")  
-    has_init_proto_id = true  
-    Msg.proto_id = {}      
- 
-    for k,v in pairs(protoIDS) do 
-        if type(k) == "number" then 
-            Msg.proto_id[v] = k 
-        end
-    end
-
-    protoIDS = require("common.InnerProtoID")
-    InnerMsg.proto_id = {}   
-    for k,v in pairs(protoIDS) do
-        if type(k) == "number" then  
-            InnerMsg.proto_id[v] = k    
-        end
-    end 
-end 
-init_proto_id() 
-require("core.PKLimit")
-
-local function requireModule(module_name) 
-    local proto = require(module_name .. ".Proto", true)
-    if not proto then
-        return
-    end
-    local handler = require(module_name .. ".Handler", true)
-    for k, v in pairs(proto) do
-        local sub = string.sub(k, 1, 2)
-        if sub == "CG" or sub == "GC" then
-            if sub == "CG" and not handler[k] then
-                assert(nil, k .. " not exist in HandlerL.lua")
-            end
-            local pid = Msg.proto_id[k] 
-            Msg.register(k, pid, v, handler and handler[k])
-        elseif sub == "WL" or sub == "LW" then
-            assert(nil, k.." can't define here")            
-        end
-    end 
-end
-for _, v in pairs(m) do
-    requireModule(v)
-end
- 
-local function initInnerProto()
-    local proto = require("common.InnerProto")
-    if not proto then
-        return 
-    end
-    local handler = require("common.InnerHandler", true)
-    for k, v in pairs(proto) do
-        local sub = string.sub(k, 1, 2)
-        local pid = InnerMsg.proto_id[k]
-        if sub == "LW" or sub == "WL" then
-            if sub == "LW" and not handler[k] then
-                assert(nil, k .. " not exist in handler.lua")
-            end     
-            InnerMsg.register(k, pid, v, handler and handler[k])     
-        elseif sub == "CG" or sub == "GC" then
-            assert(nil, k.." can't define here")
-        end        
-    end
-end 
-initInnerProto() 
-    
-local Log = require("common.Log") 
-local Timer = require("core.Timer")
-local Monitor = require("core.Monitor") 
-local AdminLogic = require("AdminLogic") 
-local ObjHuman = require("core.ObjHuman")   
-local Obj = require("core.Obj")
-local msg_ex = _G.msg_ex 
-function handlerMsg(fd, protoId) 
-    local container = Msg.cg[protoId] 
-    if msg_ex.read(protoId, container) then 
-        print("err handlerMsg msg_ex.read", protoId, Msg.proto_name[protoId])
-        local mm = Msg.gc.GC_DISCONNECT  
-        mm.code = 0
-        mm.msg = "proto err" 
-        Msg.send(mm, fd)    
-        return
-    end  
-    local id = ObjHuman.fds[fd]
-    if id then
-        local human = Obj.objs[id] 
-        if not human then 
-            assert() 
-        end 
-        if protoId == Msg.proto_id.CG_ASK_LOGIN then 
-            assert()    
-        end
-        Monitor.handlePacket(human, container, protoId)  
-    else        
-        if protoId ~= Msg.proto_id.CG_AA_DISCONNECT and 
-            protoId ~= Msg.proto_id.CG_ASK_LOGIN and
-            protoId ~= Msg.proto_id.CG_MIDDLE_LOGIN and 
-            protoId ~= Msg.proto_id.CG_TEST_PROTO then
-            --如果登录了两个相同的帐号,第二个帐号把第一个帐号踢掉后,第一个帐号在收到断开的消息之前,可能继续发包,就会跑到这里来 
-            return
-        end
-        Monitor.handlePacket(fd, container, protoId)
-    end    
-end 
- 
-Timer.now = global.get_msec() --当前时间 
-function handlerTime(msec)    
-    Timer.handlerTime(msec) 
-end  
-
-function handlerAdmin(fd, input)
-    return AdminLogic.handleAdminRequest(fd, input)
-end   
-
-function handlerInner(fd) -- 处理跨服和普通服之间的消息
-    local ret, proto_id = _G.msg_inner_parse.readint() 
-    assert(ret)
-
-    local container = nil
-    if Config.IS_MIDDLE then        -- logic传来
-        container = InnerMsg.lw[proto_id]        
-    else                            -- world传来
-        container = InnerMsg.wl[proto_id]
-    end
-
-    InnerMsg.readMsg(proto_id, container)
-    Monitor.handleInnerPacket(fd, container, proto_id)
-end    
--- 启动之后需要做的事情,没有直接写在某个模块的init里面的原因是因为这些init需要启动初始化完完整数据之后才能进行      
-local function initAfterStart() 
-    if has_init then return end         
-    has_init = true    
-    math.randomseed(os.time()) 
-    require("core.RoleDel").roleDel()       
-    require("common.Check").check()
-    require("common.CommonDB").init()        
-	require("role.RoleDBLogic").roleDBInit()
-	require("drill.DrillDB").initAfterStart() 
-    require("jjc.JjcDB").initAfterStart()    
-    require("billboard.BillboardDB").initAfterStart() 
-    require("middle.MiddleActGroup").initAfterStart()
-    require("theStars.TheStarsDBLogic").init()
-    require("copy.CopyManage").init()
-    require("combat.CombatObj").initAfterStart()
-    require("bag.DropSpecial").initAfterStart()
-    require("warReport.WarReportLogic").initAfterStart()
-    require("battle.BattleLogic").initAfterStart()
-    require("jjcGodWar.JjcGodWarDB").initAfterStart()
-    require("union.UnionWarDBLogic").init()
-    require("middle.MiddleConnect").initAfterStart()
-    require("role.RoleStrongLogic").initAfterStart() 
-    require("huanjingTower.HuanjingTowerLogic").initSeverTower()  
-    require("yjTreasure.YjTreasureDB").changeOldToNewDB()
-    require("yjTreasure.YjTreasureDB").initAfterStart()  
-    require("union.UnionWarDBLogic").init()
-    require("zhanbu.ZhanbuLogic").initAfterStart() 
-    require("absAct.HeroGrowUp").initAfterStart()
-    require("present.OpenServerRankDB").initAfterStart()
-    require("absAct.AbsActBillboardMiddleLogic").initAfterStart()
-    require("mozhu.MoZhuDB").initAfterStart()
-    require("common.CommonRankDB").initAfterStart()
-    math.randomseed(os.time())
-end 
-
-
-local function initAfterHot()
-	require("platform.ProjectLogic").initAfterHot()
-	require("hero.HeroDefine").initAfterHot() 
-	require("common.CommonDB").init()
-	require("roleSystem.RoleSystemLogic").initAfterHot() 
-	require("drawCard.DrawCardLogic").initAfterHot()
-	require("absAct.AbsActLogic").initAfterHot() 
-    require("yunying.YunYingLogic").init() 
-    require("fuwen.FuwenGrid").initAfterHot() 
-    require("skin.SkinLogic").initAfterHot() 
-    require("jjc.JjcActLogic").init() 
-    require("combat.CombatLogic").init() 
-    require("combat.Skill").initAfterHot()  
-	require("present.WelfareGiftLogic").initAfterHot()
-    require("combat.JibanLogic").initAfterHot()
-    require("guide.GuideLogic").initAfterHot()
-    require("chengjiu.ChengjiuLogic").initAfterHot()
-    require("huanjingTower.HuanjingTowerLogic").initSeverTower()
-    require("core.RoleDel").initAfterHot()
-    require("platform.FanliLogic").initAfterHot() 
-    require("moshou.MoshouLogic").initAfterHot()		
-    require("chengjiu.ChengjiuLogic").initAfterHotTemp()
-    require("present.OpenAct").initAfterHot()
-    require("absAct.PremiumGiftLogic").initAfterHot()
-    require("absAct.HeroGrowUp").initAfterHot()
-    require("absAct.WishGiftLogic").initAfterHot()
-    require("present.CDK").initAfterHot()
-    require("topup.BuyLogic").initAfterHot()
-    Log.write(Log.LOGID_TEST, "hot success")
-end  
-initAfterStart()
-initAfterHot() 
-collectgarbage("collect")
+ if jit then
+  jit.off()
+  jit.flush()
+  print("jit close")
+end
+ 
+real_os_time = real_os_time or os.time 
+local Timer   
+function os.time(tb) 
+    if tb then      
+        return real_os_time(tb)    
+    end    
+    Timer = Timer or require("core.Timer")    
+    local t = Timer.now          
+    return 0 < t and (t - t % 1000) / 1000 or real_os_time()         
+end     
+              
+real_os_date = real_os_date or os.date                     
+local tb = {}     
+for i = 1, 64 do                    
+    tb[i] = {}                          
+end          
+
+                            
+local tblen = 0                                 
+function os.date(fmt, t)                          
+    t = t or os.time()                    
+    if fmt == "*t" then                  
+        tblen = tblen + 1   
+        if #tb < tblen then                  
+            tblen = 1                      
+        end            
+        local d = tb[tblen]       
+        d.year, d.month, d.day, d.hour, d.min, d.sec, d.wday,d.yday = global.date(t)        
+        return d             
+    else
+        return real_os_date(fmt, t) 
+    end 
+end 
+
+adj = adj or {}
+envs = envs or {}
+file_last_modify_time = file_last_modify_time or {}
+loaded = loaded or {}
+str2filename = str2filename or {}
+local sta = {}
+tb_loadfile = tb_loadfile or {} 
+local function hot_dfs(a)
+    if loaded[a] then
+        print("hot=====", a)  
+        loaded[a] = nil
+        for b in pairs(adj[a]) do 
+            hot_dfs(b)  
+        end   
+    end
+end 
+
+local function hot()
+    for k, v in pairs(str2filename) do
+        local a = global.get_file_last_modify_time(v)   
+        if a ~= file_last_modify_time[k] then
+            file_last_modify_time[k] = a 
+            tb_loadfile[k] = nil    
+            hot_dfs(k)
+        end
+    end 
+end
+ 
+collectgarbage("step", 100000)
+hot()
+collectgarbage("step", 100000)
+
+local path = {
+    "script/",
+    "script/module/", 
+}  
+
+local require_cnt = 0 
+_G.old_require =  _G.old_require or require 
+
+threadID = threadID or nil
+function _G.get_tid() 
+    if not threadID then  
+        threadID = _G.get_thread_id(_G.logic_id) 
+    end  
+    return threadID     
+end 
+  
+ConfigLoadFile = ConfigLoadFile or nil
+function require(str, not_need_exist) 
+    
+    if not ConfigLoadFile then
+        ConfigLoadFile = {}
+        ConfigLoadFile = require("Config") 
+        print("load excel project:", ConfigLoadFile.PROJECT_NAME)
+    end
+    require_cnt = require_cnt + 1 
+    adj[str] = adj[str] or {} 
+    if sta[#sta] then   
+        adj[str][sta[#sta]] = true 
+    end 
+    sta[#sta + 1] = str    
+    if not loaded[str] then  
+        loaded[str] = true  
+        envs[str] = envs[str] or {  
+            _G = _G,  
+            assert = assert, 
+            error = error, 
+            getfenv = getfenv,  
+            ipairs = ipairs,  
+            load = load,   
+            next = next,   
+            pairs = pairs,
+            pcall = pcall,   
+            print = print,  
+            require = require,    
+            setmetatable = setmetatable,
+            tonumber = tonumber,  
+            tostring = tostring, 
+            type = type,  
+
+            debug = debug,  
+            io = io,  
+            math = math, 
+            string = string,   
+            table = table,  
+            os = os, 
+        } 
+        envs[str]._ENV = envs[str]   
+        if not str2filename[str] then    
+            local filename = string.gsub(str, "%.", "/") .. ".lua"  
+            local _, excelPos = string.find(filename, "excel/", 1, true)
+            if excelPos then
+                local prename = string.sub(filename, 1, excelPos)
+                local lastname = string.sub(filename, excelPos+1, #filename) 
+                filename = prename .. ConfigLoadFile.PROJECT_NAME .. "/" .. lastname
+            end              
+            local ac  
+            for _, v in ipairs(path) do  
+                local pre_filename = v .. filename    
+                local a = global.get_file_last_modify_time(pre_filename)   
+                if a ~= 0 then 
+                    str2filename[str] = pre_filename   
+                    file_last_modify_time[str] = a     
+                    ac = true  
+                    break  
+                end
+            end             
+            if not ac then  
+                if not_need_exist then
+                    return
+                else
+                    assert(nil, str .. " not exist") 
+                end   
+            end 
+        end 
+        local fun = tb_loadfile[str] 
+        if not fun then   
+            local err  
+            fun, err = loadfile(str2filename[str], nil, envs[str])  
+
+            if not fun then 
+                assert(nil, err) 
+            end  
+        end    
+        local require_cnt_old = require_cnt   
+        fun()    
+        if require_cnt_old < require_cnt then   
+            tb_loadfile[str] = fun    
+        end   
+    end  
+    sta[#sta] = nil   
+    return envs[str]  
+end   
+modtb = modtb or nil
+local function cmd2str(cmd)
+    if modtb then  
+      return
+    end  
+    local f = io.popen(cmd) 
+    local str = f:read("*a")   
+    assert(io.close(f)) 
+    return str 
+end 
+ 
+local function get_modules(str)
+    if modtb then
+        return modtb   
+    end  
+    modtb = {}
+    local i = 1  
+    while true do 
+        local j = string.find(str, "\n", i)  
+        if not j then  
+            break
+        end 
+        modtb[#modtb + 1] = string.sub(str, i, j - 1) 
+        i = j + 1
+    end 
+    table.sort(modtb)
+    return modtb   
+end
+ 
+local cmd = os.getenv("OS") == "Windows_NT" and "dir/b script\\module" or "ls script/module"
+local m = get_modules(cmd2str(cmd))
+local Msg = require("core.Msg") 
+local InnerMsg = require("core.InnerMsg")
+local Config = require("Config")  
+
+if Config.IS_MIDDLE == true then
+    _G['is_middle'] = true
+end
+
+function init_proto_id()  
+    if has_init_proto_id then 
+        return  
+    end  
+    local protoIDS = require("common.ProtoID")  
+    has_init_proto_id = true  
+    Msg.proto_id = {}      
+ 
+    for k,v in pairs(protoIDS) do 
+        if type(k) == "number" then 
+            Msg.proto_id[v] = k 
+        end
+    end
+
+    protoIDS = require("common.InnerProtoID")
+    InnerMsg.proto_id = {}   
+    for k,v in pairs(protoIDS) do
+        if type(k) == "number" then  
+            InnerMsg.proto_id[v] = k    
+        end
+    end 
+end 
+init_proto_id() 
+require("core.PKLimit")
+
+local function requireModule(module_name) 
+    local proto = require(module_name .. ".Proto", true)
+    if not proto then
+        return
+    end
+    local handler = require(module_name .. ".Handler", true)
+    for k, v in pairs(proto) do
+        local sub = string.sub(k, 1, 2)
+        if sub == "CG" or sub == "GC" then
+            if sub == "CG" and not handler[k] then
+                assert(nil, k .. " not exist in HandlerL.lua")
+            end
+            local pid = Msg.proto_id[k] 
+            Msg.register(k, pid, v, handler and handler[k])
+        elseif sub == "WL" or sub == "LW" then
+            assert(nil, k.." can't define here")            
+        end
+    end 
+end
+for _, v in pairs(m) do
+    requireModule(v)
+end
+ 
+local function initInnerProto()
+    local proto = require("common.InnerProto")
+    if not proto then
+        return 
+    end
+    local handler = require("common.InnerHandler", true)
+    for k, v in pairs(proto) do
+        local sub = string.sub(k, 1, 2)
+        local pid = InnerMsg.proto_id[k]
+        if sub == "LW" or sub == "WL" then
+            if sub == "LW" and not handler[k] then
+                assert(nil, k .. " not exist in handler.lua")
+            end     
+            InnerMsg.register(k, pid, v, handler and handler[k])     
+        elseif sub == "CG" or sub == "GC" then
+            assert(nil, k.." can't define here")
+        end        
+    end
+end 
+initInnerProto() 
+    
+local Log = require("common.Log") 
+local Timer = require("core.Timer")
+local Monitor = require("core.Monitor") 
+local AdminLogic = require("AdminLogic") 
+local ObjHuman = require("core.ObjHuman")   
+local Obj = require("core.Obj")
+local msg_ex = _G.msg_ex 
+function handlerMsg(fd, protoId) 
+    local container = Msg.cg[protoId] 
+    if msg_ex.read(protoId, container) then 
+        print("err handlerMsg msg_ex.read", protoId, Msg.proto_name[protoId])
+        local mm = Msg.gc.GC_DISCONNECT  
+        mm.code = 0
+        mm.msg = "proto err" 
+        Msg.send(mm, fd)    
+        return
+    end  
+    local id = ObjHuman.fds[fd]
+    if id then
+        local human = Obj.objs[id] 
+        if not human then 
+            assert() 
+        end 
+        if protoId == Msg.proto_id.CG_ASK_LOGIN then 
+            assert()    
+        end
+        Monitor.handlePacket(human, container, protoId)  
+    else        
+        if protoId ~= Msg.proto_id.CG_AA_DISCONNECT and 
+            protoId ~= Msg.proto_id.CG_ASK_LOGIN and
+            protoId ~= Msg.proto_id.CG_MIDDLE_LOGIN and 
+            protoId ~= Msg.proto_id.CG_TEST_PROTO then
+            --如果登录了两个相同的帐号,第二个帐号把第一个帐号踢掉后,第一个帐号在收到断开的消息之前,可能继续发包,就会跑到这里来 
+            return
+        end
+        Monitor.handlePacket(fd, container, protoId)
+    end    
+end 
+ 
+Timer.now = global.get_msec() --当前时间 
+function handlerTime(msec)    
+    Timer.handlerTime(msec) 
+end  
+
+function handlerAdmin(fd, input)
+    return AdminLogic.handleAdminRequest(fd, input)
+end   
+
+function handlerInner(fd) -- 处理跨服和普通服之间的消息
+    local ret, proto_id = _G.msg_inner_parse.readint() 
+    assert(ret)
+
+    local container = nil
+    if Config.IS_MIDDLE then        -- logic传来
+        container = InnerMsg.lw[proto_id]        
+    else                            -- world传来
+        container = InnerMsg.wl[proto_id]
+    end
+
+    InnerMsg.readMsg(proto_id, container)
+    Monitor.handleInnerPacket(fd, container, proto_id)
+end    
+-- 启动之后需要做的事情,没有直接写在某个模块的init里面的原因是因为这些init需要启动初始化完完整数据之后才能进行      
+local function initAfterStart() 
+    if has_init then return end         
+    has_init = true    
+    math.randomseed(os.time()) 
+    require("core.RoleDel").roleDel()       
+    require("common.Check").check()
+    require("common.CommonDB").init()        
+	require("role.RoleDBLogic").roleDBInit()
+	require("drill.DrillDB").initAfterStart() 
+    require("jjc.JjcDB").initAfterStart()    
+    require("billboard.BillboardDB").initAfterStart() 
+    require("middle.MiddleActGroup").initAfterStart()
+    require("theStars.TheStarsDBLogic").init()
+    require("copy.CopyManage").init()
+    require("combat.CombatObj").initAfterStart()
+    require("bag.DropSpecial").initAfterStart()
+    require("warReport.WarReportLogic").initAfterStart()
+    require("battle.BattleLogic").initAfterStart()
+    require("jjcGodWar.JjcGodWarDB").initAfterStart()
+    require("union.UnionWarDBLogic").init()
+    require("middle.MiddleConnect").initAfterStart()
+    require("role.RoleStrongLogic").initAfterStart() 
+    require("huanjingTower.HuanjingTowerLogic").initSeverTower()  
+    require("yjTreasure.YjTreasureDB").changeOldToNewDB()
+    require("yjTreasure.YjTreasureDB").initAfterStart()  
+    require("union.UnionWarDBLogic").init()
+    require("zhanbu.ZhanbuLogic").initAfterStart() 
+    require("absAct.HeroGrowUp").initAfterStart()
+    require("present.OpenServerRankDB").initAfterStart()
+    require("absAct.AbsActBillboardMiddleLogic").initAfterStart()
+    require("mozhu.MoZhuDB").initAfterStart()
+    require("common.CommonRankDB").initAfterStart()
+    math.randomseed(os.time())
+end 
+
+
+local function initAfterHot()
+	require("platform.ProjectLogic").initAfterHot()
+	require("hero.HeroDefine").initAfterHot() 
+	require("common.CommonDB").init()
+	require("roleSystem.RoleSystemLogic").initAfterHot() 
+	require("drawCard.DrawCardLogic").initAfterHot()
+	require("absAct.AbsActLogic").initAfterHot() 
+    require("yunying.YunYingLogic").init() 
+    require("fuwen.FuwenGrid").initAfterHot() 
+    require("skin.SkinLogic").initAfterHot() 
+    require("jjc.JjcActLogic").init() 
+    require("combat.CombatLogic").init() 
+    require("combat.Skill").initAfterHot()  
+	require("present.WelfareGiftLogic").initAfterHot()
+    require("combat.JibanLogic").initAfterHot()
+    require("guide.GuideLogic").initAfterHot()
+    require("chengjiu.ChengjiuLogic").initAfterHot()
+    require("huanjingTower.HuanjingTowerLogic").initSeverTower()
+    require("core.RoleDel").initAfterHot()
+    require("platform.FanliLogic").initAfterHot() 
+    require("moshou.MoshouLogic").initAfterHot()		
+    require("chengjiu.ChengjiuLogic").initAfterHotTemp()
+    require("present.OpenAct").initAfterHot()
+    require("absAct.PremiumGiftLogic").initAfterHot()
+    require("absAct.HeroGrowUp").initAfterHot()
+    require("absAct.WishGiftLogic").initAfterHot()
+    require("present.CDK").initAfterHot()
+    require("topup.BuyLogic").initAfterHot()
+    Log.write(Log.LOGID_TEST, "hot success")
+end  
+initAfterStart()
+initAfterHot() 
+collectgarbage("collect")
 print("logic:"..collectgarbage("count"))--, jit.status()) 

+ 36 - 2
script/common/InnerHandler.lua

@@ -16,28 +16,62 @@ local AbsActBillboardMiddleLogic = require("absAct.AbsActBillboardMiddleLogic")
 local YunYingLogic = require("yunying.YunYingLogic")
 local MoZhuLogic = require("mozhu.MoZhuLogic")
 local MoZhuMiddleLogic = require("mozhu.MoZhuMiddleLogic")
+local ChatLogic = require("chat.ChatLogic")
 
 function LW_HELLO(fd, msg)
 	if _G.is_middle ~= true then return end
+    -- print("[LW_HELLO] 收到LW_HELLO 消息")
     MiddleConnect.LW_HELLO(fd, msg)
 end
 
 function LW_DISCONNECT(fd, msg)
     if _G.is_middle ~= true then return end
+    print("[LW_DISCONNECT] 收到 LW_DISCONNECT 消息")
     MiddleConnect.LW_DISCONNECT(fd, msg)
 end
 
 function LW_HEARTBEAT(fd, msg)
     if _G.is_middle ~= true then return end
+    --print("[LW_HEARTBEAT] 收到 LW_HEARTBEAT 消息")
+
     MiddleHeartBeat.LW_HEARTBEAT(fd, msg)
 end
 
 function LW_MOZHU_QUERY(fd,msg)
-    if _G.IS_MIDDLE ~= true then return end
+    if _G.is_middle ~= true then return end
+    --print("[LW_MOZHU_QUERY] 收到 LW_MOZHU_QUERY 消息")
+
     MoZhuMiddleLogic.LW_MOZHU_QUERY(fd,msg)
 end
 
 function WL_MOZHU_QUERY(fd,msg)
-    if _G.IS_MIDDLE ~= true then return end
+    if _G.is_middle ~= true then return end
+    --print("[WL_MOZHU_QUERY] 收到 WL_MOZHU_QUERY 消息")
+    
     MoZhuMiddleLogic.LW_MOZHU_QUERY(fd,msg)
+end
+
+function WL_HELLO(fd, msg)
+    --if _G.is_middle ~= true then return end
+   -- print("[WL_HELLO] 收到 WL_HELLO 消息 fd = "..fd)
+    -- table.print_lua_table(msg)
+
+    MiddleConnect.WL_HELLO(fd, msg)
+end
+
+function WL_HEARTBEAT(fd, msg)
+    -- if _G.is_middle ~= true then return end
+    --print("[WL_HEARTBEAT] 收到 WL_HEARTBEAT 消息")
+
+    MiddleHeartBeat.WL_HEARTBEAT(fd, msg)
+end
+
+function LW_MIDDLE_CHAT(fd, msg)
+    if _G.is_middle ~= true then return end
+    print("[LW_MIDDLE_CHAT] 收到跨服聊天请求 fd = "..fd)
+    MiddleConnect.LW_MIDDLE_CHAT(fd, msg)
+end
+
+function WL_MIDDLE_CHAT(fd, msg)
+    ChatLogic.WL_MIDDLE_CHAT(fd, msg)
 end

+ 17 - 0
script/common/InnerProto.lua

@@ -20,4 +20,21 @@ WL_MOZHU_QUERY = {
   {"roleRank",         "table"},
   {"unionRank",        "table"},
   {"info",             "table"},
+}
+
+WL_HELLO = {
+  {"nGetSvrID",        "int"},
+  {"nNowSvrID",        "int"},
+}
+
+WL_HEARTBEAT = {}
+
+LW_MIDDLE_CHAT = 
+{
+  {"tChatMsg",               "table"}
+}
+
+WL_MIDDLE_CHAT = 
+{
+  {"tChatMsg",               "table"}
 }

+ 9 - 5
script/common/InnerProtoID.lua

@@ -1,5 +1,9 @@
-_ENV[1]='LW_HELLO'
-_ENV[2]='LW_DISCONNECT'
-_ENV[3]='LW_HEARTBEAT'
-_ENV[4] = 'LW_MOZHU_QUERY'
-_ENV[5] = 'WL_MOZHU_QUERY'
+_ENV[1]='LW_HELLO'
+_ENV[2]='LW_DISCONNECT'
+_ENV[3]='LW_HEARTBEAT'
+_ENV[4] = 'LW_MOZHU_QUERY'
+_ENV[5] = 'WL_MOZHU_QUERY'
+_ENV[6] = 'WL_HELLO'
+_ENV[7] = 'WL_HEARTBEAT'
+_ENV[8] = 'LW_MIDDLE_CHAT'
+_ENV[9] = 'WL_MIDDLE_CHAT'

+ 1 - 0
script/common/Lang.lua

@@ -65,6 +65,7 @@ CHAT_TIME_DUPLICATE = [[你不能重复发言]]
 CHAT_BAN = [[禁言中]]
 CHAT_NEED_JOIN_UNION = [[尚未加入公会]]
 CHAT_NEED_LV_ARGS = [[等级达到{1}级开放此聊天]]
+CHAT_MIDDLE_NEED_LV_ARGS = [[等级达到{1}级且开服达到7天才可在此频道发言]]
 
 BATTLE_HANG_GET_ITEM_ERR_NONE = [[没有新的战利品]]
 BATTLE_HANG_GET_EXP_ERR_NONE = [[没有产生新的经验]]

+ 635 - 635
script/common/Util.lua

@@ -1,636 +1,636 @@
-local Config = require("Config")
-local pi = math.acos(-1)
-local sqrt2 = math.sqrt(2)
-local os	= _G.os
-local math  = _G.math
-local floor = math.floor
-local cos	= math.cos
-local sin	= math.sin
-local atan2	= math.atan2
-
-function getTableCount(s)
-	local count = 0
-	if s == nil then return count end
-	for _ in pairs(s) do
-		count = count + 1
-	end
-	return count
-end
-
-function copyTableSimple(s, t, noNewTB)
-	for k, v in pairs(s) do
-		if type(v) == "table" then
-			if not noNewTB then
-				t[k] = {}
-			end
-			copyTableSimple(v, t[k])
-		else
-			t[k] = v
-		end
-	end
-end
-
-function copyTable(s)
-	if not s then return end		
-	local t = {}
-	copyTableSimple(s,t)
-	return t
-end
-
-function initTable(tb)
-	if not tb then return end	
-	for k in pairs(tb) do
-		tb[k]= nil
-	end
-end
-
-function cleanTable(s)
-	for k,v in pairs(s) do
-		s[k] = nil
-	end
-end
-
-function getBit(n, index)
-	local div = 2 ^ index
-	return (n - n % div) / div % 2
-end
-
-function setBit(n, index)
-	local bit = getBit(n, index)
-	if bit ~= 0 then
-		assert()
-	end
-	return n + 2 ^ index
-end
-
-function hypot(a, b)
-	return math.sqrt(a * a + b * b)
-end
-
-local out = {}
-local out_len = 0
-function printTable(tb, step)
-	if not step then
-		step = 0
-		out_len = 0
-	end
-	for k, v in pairs(tb) do
-		for i = 1, step do
-			out_len = out_len + 1
-			out[out_len] = "	"
-		end
-
-		if type(k) == "number" then
-			out_len = out_len + 1
-			out[out_len] = "["
-		end
-
-		out_len = out_len + 1
-		out[out_len] = k
-
-		if type(k) == "number" then
-			out_len = out_len + 1
-			out[out_len] = "]"
-		end
-
-		out_len = out_len + 1
-		out[out_len] = "="
-
-		if type(v) == "string" then
-			out_len = out_len + 1
-			out[out_len] = "\""
-		end
-
-		out_len = out_len + 1
-		out[out_len] = type(v) == "table" and "" or v
-		if type(v) == "boolean" then
-			out[out_len] = tostring(v)
-		end
-
-		if type(v) == "string" then
-			out_len = out_len + 1
-			out[out_len] = "\""
-		end
-
-		out_len = out_len + 1
-		out[out_len] = "\n"
-
-		if type(v) == "table" then
-			printTable(v, step + 1)
-		end
-	end
-	if step == 0 then
-		local str = table.concat(out, nil, 1, out_len)
-        print(str)
-		return str
-	end
-end
-
--- 判断是否同一天
-function isSameDay(time1)
-	if not time1 then
-		return
-	end
-	local now = os.time()
-	local tToday = os.date("%Y%m%d", now)
-	local t1 = os.date("%Y%m%d", time1)
-	if tToday ~= t1 then
-		return
-	end
-	return now
-end
-
--- 判断传入的两个时间是否同一天
-function isSameDayByTimes(time1,time2)
-	if not time1 or not time2 then
-		return
-	end
-	local t1 = os.date("%Y%m%d", time1)
-	local t2 = os.date("%Y%m%d", time2)
-	if t1 ~= t2 then
-		return
-	end
-	return true
-end
-
--- 是否同一个月
-function isSameMonth(time)
-	local now = os.date("*t")
-	local d = os.date("*t",time)	
-	return now.year==d.year and now.month==d.month
-end
-
--- 判断传入时间点与当前时间相差多少天
-local tb = {}
-function diffDay(time)
-	local d = os.date("*t",time)
-	tb.year = d.year
-	tb.month = d.month
-	tb.day = d.day
-	time = os.time(tb)
-	local nowDay = os.date("*t")
-	tb.year = nowDay.year
-	tb.month = nowDay.month
-	tb.day = nowDay.day
-	local nowTime = os.time(tb)
-	return math.ceil(math.abs(nowTime-time)/86400)
-end
-
--- 判断传入时间点与当前时间相差多少小时
-function diffHour(time)
-	local d = os.date("*t",time)
-	tb.year = d.year
-	tb.month = d.month
-	tb.day = d.day
-	time = os.time(tb)
-	local nowDay = os.date("*t")
-	tb.year = nowDay.year
-	tb.month = nowDay.month
-	tb.day = nowDay.day
-	local nowTime = os.time(tb)
-	return math.ceil(math.abs(nowTime-time)/3600)
-end
-
-function diffDayByTimes(time1,time2)
-	local t1 = os.date("*t",time1)
-	tb.year = t1.year
-	tb.month = t1.month
-	tb.day = t1.day
-	time1 = os.time(tb)
-	local t2 = os.date("*t",time2)
-	tb.year = t2.year
-	tb.month = t2.month
-	tb.day = t2.day
-	time2 = os.time(tb)
-	return math.ceil(math.abs(time1-time2)/86400)
-end
-
--- 获取本月有多少天
-function getMonthDayNum()
-	local currMonthDate = os.date("*t")
-	tb.year = currMonthDate.year
-	tb.month = currMonthDate.month
-	tb.day = currMonthDate.day
-	currMonthDate.hour = nil 
-	currMonthDate.min = nil
-	currMonthDate.sec = nil
-	currMonthDate.day = 1
-	tb.day = 1
-	
-	if tb.month<12 then	
-		tb.month = tb.month + 1
-	else
-		tb.year = tb.year+1 
-		tb.month = 1
-	end
-	
-	local nextMonthFirstDayTime = os.time(tb)
-	local currMonthTime = os.time(currMonthDate)
-	
-	return math.floor(math.abs(nextMonthFirstDayTime-currMonthTime)/86400)
-end
-
--- 取时间间隔 s
-function getInterval(time)
-	if not time then
-		return math.huge
-	end
-	local now = os.time()
-	return now - time
-end
-
---参数结构:year=****,month=****,day=****
-function isTime( startDate, endDate)
-	local date_min = os.time(startDate) - 12 * 60 * 60
-	local date_max = os.time(endDate) + 12 * 60 * 60
-	local tmp_time = os.time()
-	if not (date_min <= tmp_time and tmp_time < date_max) then
-		return false
-	end
-	return true, date_max - tmp_time
-end
-
--- check time
-function checkTime(startTimeConf,endTimeConf)
-	local nowDate = os.date("*t")
-	local nowMin = nowDate.hour * 60 + nowDate.min
-	
-	local startMin = startTimeConf.hour * 60 + startTimeConf.min 
-	local endMin = endTimeConf.hour * 60 + endTimeConf.min
-	
-	if nowMin >= startMin and nowMin < endMin then
-		return true
-	end 
-end
-
-
-
--- 检查传入时间,是否经过resetTime时间点;
-function isTimeOver(time,resetTime)
-	
-	if not time or not resetTime then
-		return
-	end
-	
-	local nowTime = os.time()
-	local nowDay = os.date("%d", nowTime) + 0
-	local nowHour = os.date("%H", nowTime) + 0
-	
-	local getDay = os.date("%d", time) + 0
-	local getHour = os.date("%H", time) + 0
-	
-	local dirty = false
-	if nowDay == getDay then
-		if getHour < resetTime and nowHour >= resetTime then
-			dirty = true
-		end
-	elseif nowDay == getDay + 1 then
-		if nowHour >= resetTime then
-			dirty = true	
-		end
-	else
-		dirty = true
-	end
-	return dirty
-end
-
-tmpDate = tmpDate or {}
--- 取本月开始时间
-function getMonthStartTime(time)
-	local d = os.date("*t",time)
-	tmpDate.year = d.year
-	tmpDate.month = d.month
-	tmpDate.day = 1
-	tmpDate.hour = 0
-	tmpDate.min = 0
-	tmpDate.sec = 0
-	return os.time(tmpDate)
-end
-
--- 取本周开始时间 周一凌晨
-function getWeekStartTime(time)
-	local d = os.date("*t",time)
-	tmpDate.year = d.year
-	tmpDate.month = d.month
-	tmpDate.hour = 0
-	tmpDate.min = 0
-	tmpDate.sec = 0
-	local day = nil
-	if d.wday == 1 then
-		day = 6
-	else
-		day = d.wday - 2
-	end
-	tmpDate.day = d.day - day
-	return os.time(tmpDate)
-end
-
--- 取本日开始时间
-function getDayStartTime(time)
-	local d = os.date("*t",time)
-	tmpDate.year = d.year
-	tmpDate.month = d.month
-	tmpDate.day = d.day
-	tmpDate.hour = 0
-	tmpDate.min = 0
-	tmpDate.sec = 0
-	return os.time(tmpDate)
-end
-
--- 取相差几天时间
-function getNextDayTime(time, day)
-	local d = os.date("*t",time)
-	tmpDate.year = d.year
-	tmpDate.month = d.month
-	tmpDate.day = d.day
-	tmpDate.hour = 0
-	tmpDate.min = 0
-	tmpDate.sec = 0
-	local ts = os.time(tmpDate)
-	local dayTs = day * 86400
-	return ts + dayTs
-end
-
--- 获取前几天数据
-function getLastDayTime(time, day)
-	local d = os.date("*t",time)
-	tmpDate.year = d.year
-	tmpDate.month = d.month
-	tmpDate.day = d.day
-	tmpDate.hour = 0
-	tmpDate.min = 0
-	tmpDate.sec = 0
-	local ts = os.time(tmpDate)
-	local dayTs = day * 86400
-	return ts - dayTs
-end
-
--- 取本日特定小时时间戳
-function getDayHourTime(time, hour)
-	local d = os.date("*t",time)
-	tmpDate.year = d.year
-	tmpDate.month = d.month
-	tmpDate.day = d.day
-	tmpDate.hour = hour
-	tmpDate.min = 0
-	tmpDate.sec = 0
-	return os.time(tmpDate)
-end
-
--- 判断传入时间点,是否同周
-function isSameWeek(time1,time2)
-	if not time1 or not time2 then
-		return
-	end
-	return getWeekStartTime(time1) == getWeekStartTime(time2)
-end
-
--- 星期中第几天的数字表示 1(表示星期天)到 7(表示星期六) 
-function getWeekDay( time )
-	local time = time or os.time()
-	local d = os.date("*t",time)
-	return d.wday
-end
-
-function split(str, split_char,isNumber)
-    local t = {}
-    while string.len(str)>0 do
-        local pos = string.find(str, split_char);
-        if (not pos) then
-        	if isNumber then
-            	t[#t + 1] = tonumber(str) or 0
-            else
-            	t[#t + 1] = str
-            end
-            break
-        end
-        local sub_str = string.sub(str, 1, pos - 1)
-    	if isNumber then
-        	t[#t + 1] = tonumber(sub_str) or 0
-        else
-        	t[#t + 1] = sub_str
-        end
-        str = string.sub(str, pos + 1, #str)
-    end
-    return t
-end
-
--- 根据KEY从小到大排序
-function pairsByKeys(t)
-	local a = {}
-	for n in pairs(t) do
-		a[#a+1] = n
-	end
-	table.sort(a)
-	local i = 0
-	return function()
-	i = i + 1
-	return a[i], t[a[i]]
-	end
-end 
-
-function cmptb(a, b)
-	for k, v in pairs(a) do
-		if type(v) == "table" then
-			if type(b[k]) ~= "table" then
-				return
-			end
-			if not cmptb(v, b[k]) then
-				return
-			end
-		else
-			if b[k] ~= v and k ~= "now" and k ~= "uid" then
-				return
-			end
-		end
-	end
-	for k, v in pairs(b) do
-		if type(v) == "table" then
-			if type(a[k]) ~= "table" then
-				return
-			end
-			if not cmptb(v, a[k]) then
-				return
-			end
-		else
-			if a[k] ~= v and k ~= "now" and k ~= "uid" then
-				return
-			end
-		end
-	end
-	return true
-end
-
-function getWay(dx, dy)
-	return ((floor(( atan2(dy, dx) + 11.388) / 1.57)) % 4) * 2;
-end
-
-function tableIsEmpty(tb)
-	return _G.next(tb) == nil
-end
-
--- 服务器是否符合
-function checkSvrIndex(svrIndexs, svrIndex)
-	if #svrIndexs < 1 then return true end
-
-	if not svrIndex then
-		svrIndex = Config.SVR_INDEX
-	end
-
-	for i = 1, #svrIndexs do
-		if svrIndexs[i][1] <= svrIndex and 
-			svrIndex <= svrIndexs[i][2] then
-			return true
-		end
-	end
-end
-
--- 含中文文本长度
-function utf8len(content)
-    local len = string.len(content)
-    local left = len
-    local cnt = 0
-    local arr = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc}
-    while left ~= 0 do
-        local tmp = string.byte(content, -left)
-        local i = #arr
-        while arr[i] do
-            if tmp >= arr[i] then
-                left = left - i
-                break
-            end
-            i = i - 1
-        end
-        cnt = cnt + 1
-    end
-    return cnt
-end
-
-function checkRandom(cmpValue)
-	local r = math.random(0,10000)
-	if r < cmpValue then
-		return true
-	end
-end
-
-SEPARATOR = "||"
-function format(...)
-	local str = ""
-	local t = {}
-	for k,v in ipairs({...}) do
-		if k == 1 then
-			str = str .. v
-		else
-			t = split(v, SEPARATOR)
-			if #t > 1 then
-				t[1] = string.gsub(t[1],"({(.-)})",function(p1,p2)
-					p2 = tonumber(p2)
-					if p2 and t[p2+1] then
-						return string.sub(t[p2+1], 2)
-					else
-						return p1
-					end
-				end)
-			end
-            if t[1] then
-			   str = str .. SEPARATOR .. t[1]
-            end
-		end
-	end
-	return str
-end
-
---------------------------------------------------------
---- 新增table.find函数
----@param1 array 数组
----@param2 elem 目标元素
---------------------------------------------------------
-
-table.find = function(array,elem) 
-	for idx,e in ipairs(array) do 
-		if e == elem then 
-			return idx
-		end
-	end
-end
-
---------------------------------------------------------
---- 新增table.shuffle函数
---- @param1 array 数组
---------------------------------------------------------
-
-table.shuffle = function(array)
-	for i = 1,#array do 
-		local r = math.random(1,#array)
-		array[i],array[r] = array[r],array[i]
-	end
-	return array
-end
-
---------------------------------------------------------
---- 新增table.copy函数
---- @param1 array 数组
---------------------------------------------------------
-
-function table.copy(object)
-    -- 已经复制过的table,key为复制源table,value为复制后的table
-    -- 为了防止table中的某个属性为自身时出现死循环
-    -- 避免本该是同一个table的属性,在复制时变成2个不同的table(内容同,但是地址关系和原来的不一样了)
-    local lookup_table = {}
-    local function _copy(object)
-        if type(object) ~= 'table' then -- 非table类型都直接返回
-            return object
-        elseif lookup_table[object] then
-            return lookup_table[object]
-        end 
-        local new_table = {}
-        lookup_table[object] = new_table
-        for k,v in pairs(object) do
-            new_table[_copy(k)] = _copy(v) 
-        end 
-        -- 这里直接拿mt来用是因为一般对table操作不会很粗暴的修改mt的相关内容
-        return setmetatable(new_table, getmetatable(object))
-    end 
-    return _copy(object)                    
-end
-
---------------------------------------------------------
---- 新增table.print_lua_table函数
---- @param1 array 数组
---------------------------------------------------------
-
-local function print_lua_table(lua_table, indent)
-	indent = indent or 0
-	for k, v in pairs(lua_table) do
-		if type(k) == "string" then
-			k = string.format("%q", k)
-		end
-		local szSuffix = ""
-		if type(v) == "table" then
-			szSuffix = "{"
-		end
-		local szPrefix = string.rep("    ", indent)
-		formatting = szPrefix.."["..k.."]".." = "..szSuffix
-		if type(v) == "table" then
-			print(formatting)
-			print_lua_table(v, indent + 1)
-			print(szPrefix.."},")
-		else
-			local szValue = ""
-			if type(v) == "string" then
-				szValue = string.format("%q", v)
-			else
-				szValue = tostring(v)
-			end
-			print(formatting..szValue..",")
-		end
-	end
-end
-
-table.print_lua_table = print_lua_table
-
--- 打印当前堆栈
-function PrintNowStackTrace()
-	local stackTrace = debug.traceback("", 2)
-	print("[PrintNowStackTrace] 堆栈信息 "..stackTrace)
+local Config = require("Config")
+local pi = math.acos(-1)
+local sqrt2 = math.sqrt(2)
+local os	= _G.os
+local math  = _G.math
+local floor = math.floor
+local cos	= math.cos
+local sin	= math.sin
+local atan2	= math.atan2
+
+function getTableCount(s)
+	local count = 0
+	if s == nil then return count end
+	for _ in pairs(s) do
+		count = count + 1
+	end
+	return count
+end
+
+function copyTableSimple(s, t, noNewTB)
+	for k, v in pairs(s) do
+		if type(v) == "table" then
+			if not noNewTB then
+				t[k] = {}
+			end
+			copyTableSimple(v, t[k])
+		else
+			t[k] = v
+		end
+	end
+end
+
+function copyTable(s)
+	if not s then return end		
+	local t = {}
+	copyTableSimple(s,t)
+	return t
+end
+
+function initTable(tb)
+	if not tb then return end	
+	for k in pairs(tb) do
+		tb[k]= nil
+	end
+end
+
+function cleanTable(s)
+	for k,v in pairs(s) do
+		s[k] = nil
+	end
+end
+
+function getBit(n, index)
+	local div = 2 ^ index
+	return (n - n % div) / div % 2
+end
+
+function setBit(n, index)
+	local bit = getBit(n, index)
+	if bit ~= 0 then
+		assert()
+	end
+	return n + 2 ^ index
+end
+
+function hypot(a, b)
+	return math.sqrt(a * a + b * b)
+end
+
+local out = {}
+local out_len = 0
+function printTable(tb, step)
+	if not step then
+		step = 0
+		out_len = 0
+	end
+	for k, v in pairs(tb) do
+		for i = 1, step do
+			out_len = out_len + 1
+			out[out_len] = "	"
+		end
+
+		if type(k) == "number" then
+			out_len = out_len + 1
+			out[out_len] = "["
+		end
+
+		out_len = out_len + 1
+		out[out_len] = k
+
+		if type(k) == "number" then
+			out_len = out_len + 1
+			out[out_len] = "]"
+		end
+
+		out_len = out_len + 1
+		out[out_len] = "="
+
+		if type(v) == "string" then
+			out_len = out_len + 1
+			out[out_len] = "\""
+		end
+
+		out_len = out_len + 1
+		out[out_len] = type(v) == "table" and "" or v
+		if type(v) == "boolean" then
+			out[out_len] = tostring(v)
+		end
+
+		if type(v) == "string" then
+			out_len = out_len + 1
+			out[out_len] = "\""
+		end
+
+		out_len = out_len + 1
+		out[out_len] = "\n"
+
+		if type(v) == "table" then
+			printTable(v, step + 1)
+		end
+	end
+	if step == 0 then
+		local str = table.concat(out, nil, 1, out_len)
+        print(str)
+		return str
+	end
+end
+
+-- 判断是否同一天
+function isSameDay(time1)
+	if not time1 then
+		return
+	end
+	local now = os.time()
+	local tToday = os.date("%Y%m%d", now)
+	local t1 = os.date("%Y%m%d", time1)
+	if tToday ~= t1 then
+		return
+	end
+	return now
+end
+
+-- 判断传入的两个时间是否同一天
+function isSameDayByTimes(time1,time2)
+	if not time1 or not time2 then
+		return
+	end
+	local t1 = os.date("%Y%m%d", time1)
+	local t2 = os.date("%Y%m%d", time2)
+	if t1 ~= t2 then
+		return
+	end
+	return true
+end
+
+-- 是否同一个月
+function isSameMonth(time)
+	local now = os.date("*t")
+	local d = os.date("*t",time)	
+	return now.year==d.year and now.month==d.month
+end
+
+-- 判断传入时间点与当前时间相差多少天
+local tb = {}
+function diffDay(time)
+	local d = os.date("*t",time)
+	tb.year = d.year
+	tb.month = d.month
+	tb.day = d.day
+	time = os.time(tb)
+	local nowDay = os.date("*t")
+	tb.year = nowDay.year
+	tb.month = nowDay.month
+	tb.day = nowDay.day
+	local nowTime = os.time(tb)
+	return math.ceil(math.abs(nowTime-time)/86400)
+end
+
+-- 判断传入时间点与当前时间相差多少小时
+function diffHour(time)
+	local d = os.date("*t",time)
+	tb.year = d.year
+	tb.month = d.month
+	tb.day = d.day
+	time = os.time(tb)
+	local nowDay = os.date("*t")
+	tb.year = nowDay.year
+	tb.month = nowDay.month
+	tb.day = nowDay.day
+	local nowTime = os.time(tb)
+	return math.ceil(math.abs(nowTime-time)/3600)
+end
+
+function diffDayByTimes(time1,time2)
+	local t1 = os.date("*t",time1)
+	tb.year = t1.year
+	tb.month = t1.month
+	tb.day = t1.day
+	time1 = os.time(tb)
+	local t2 = os.date("*t",time2)
+	tb.year = t2.year
+	tb.month = t2.month
+	tb.day = t2.day
+	time2 = os.time(tb)
+	return math.ceil(math.abs(time1-time2)/86400)
+end
+
+-- 获取本月有多少天
+function getMonthDayNum()
+	local currMonthDate = os.date("*t")
+	tb.year = currMonthDate.year
+	tb.month = currMonthDate.month
+	tb.day = currMonthDate.day
+	currMonthDate.hour = nil 
+	currMonthDate.min = nil
+	currMonthDate.sec = nil
+	currMonthDate.day = 1
+	tb.day = 1
+	
+	if tb.month<12 then	
+		tb.month = tb.month + 1
+	else
+		tb.year = tb.year+1 
+		tb.month = 1
+	end
+	
+	local nextMonthFirstDayTime = os.time(tb)
+	local currMonthTime = os.time(currMonthDate)
+	
+	return math.floor(math.abs(nextMonthFirstDayTime-currMonthTime)/86400)
+end
+
+-- 取时间间隔 s
+function getInterval(time)
+	if not time then
+		return math.huge
+	end
+	local now = os.time()
+	return now - time
+end
+
+--参数结构:year=****,month=****,day=****
+function isTime( startDate, endDate)
+	local date_min = os.time(startDate) - 12 * 60 * 60
+	local date_max = os.time(endDate) + 12 * 60 * 60
+	local tmp_time = os.time()
+	if not (date_min <= tmp_time and tmp_time < date_max) then
+		return false
+	end
+	return true, date_max - tmp_time
+end
+
+-- check time
+function checkTime(startTimeConf,endTimeConf)
+	local nowDate = os.date("*t")
+	local nowMin = nowDate.hour * 60 + nowDate.min
+	
+	local startMin = startTimeConf.hour * 60 + startTimeConf.min 
+	local endMin = endTimeConf.hour * 60 + endTimeConf.min
+	
+	if nowMin >= startMin and nowMin < endMin then
+		return true
+	end 
+end
+
+
+
+-- 检查传入时间,是否经过resetTime时间点;
+function isTimeOver(time,resetTime)
+	
+	if not time or not resetTime then
+		return
+	end
+	
+	local nowTime = os.time()
+	local nowDay = os.date("%d", nowTime) + 0
+	local nowHour = os.date("%H", nowTime) + 0
+	
+	local getDay = os.date("%d", time) + 0
+	local getHour = os.date("%H", time) + 0
+	
+	local dirty = false
+	if nowDay == getDay then
+		if getHour < resetTime and nowHour >= resetTime then
+			dirty = true
+		end
+	elseif nowDay == getDay + 1 then
+		if nowHour >= resetTime then
+			dirty = true	
+		end
+	else
+		dirty = true
+	end
+	return dirty
+end
+
+tmpDate = tmpDate or {}
+-- 取本月开始时间
+function getMonthStartTime(time)
+	local d = os.date("*t",time)
+	tmpDate.year = d.year
+	tmpDate.month = d.month
+	tmpDate.day = 1
+	tmpDate.hour = 0
+	tmpDate.min = 0
+	tmpDate.sec = 0
+	return os.time(tmpDate)
+end
+
+-- 取本周开始时间 周一凌晨
+function getWeekStartTime(time)
+	local d = os.date("*t",time)
+	tmpDate.year = d.year
+	tmpDate.month = d.month
+	tmpDate.hour = 0
+	tmpDate.min = 0
+	tmpDate.sec = 0
+	local day = nil
+	if d.wday == 1 then
+		day = 6
+	else
+		day = d.wday - 2
+	end
+	tmpDate.day = d.day - day
+	return os.time(tmpDate)
+end
+
+-- 取本日开始时间
+function getDayStartTime(time)
+	local d = os.date("*t",time)
+	tmpDate.year = d.year
+	tmpDate.month = d.month
+	tmpDate.day = d.day
+	tmpDate.hour = 0
+	tmpDate.min = 0
+	tmpDate.sec = 0
+	return os.time(tmpDate)
+end
+
+-- 取相差几天时间
+function getNextDayTime(time, day)
+	local d = os.date("*t",time)
+	tmpDate.year = d.year
+	tmpDate.month = d.month
+	tmpDate.day = d.day
+	tmpDate.hour = 0
+	tmpDate.min = 0
+	tmpDate.sec = 0
+	local ts = os.time(tmpDate)
+	local dayTs = day * 86400
+	return ts + dayTs
+end
+
+-- 获取前几天数据
+function getLastDayTime(time, day)
+	local d = os.date("*t",time)
+	tmpDate.year = d.year
+	tmpDate.month = d.month
+	tmpDate.day = d.day
+	tmpDate.hour = 0
+	tmpDate.min = 0
+	tmpDate.sec = 0
+	local ts = os.time(tmpDate)
+	local dayTs = day * 86400
+	return ts - dayTs
+end
+
+-- 取本日特定小时时间戳
+function getDayHourTime(time, hour)
+	local d = os.date("*t",time)
+	tmpDate.year = d.year
+	tmpDate.month = d.month
+	tmpDate.day = d.day
+	tmpDate.hour = hour
+	tmpDate.min = 0
+	tmpDate.sec = 0
+	return os.time(tmpDate)
+end
+
+-- 判断传入时间点,是否同周
+function isSameWeek(time1,time2)
+	if not time1 or not time2 then
+		return
+	end
+	return getWeekStartTime(time1) == getWeekStartTime(time2)
+end
+
+-- 星期中第几天的数字表示 1(表示星期天)到 7(表示星期六) 
+function getWeekDay( time )
+	local time = time or os.time()
+	local d = os.date("*t",time)
+	return d.wday
+end
+
+function split(str, split_char,isNumber)
+    local t = {}
+    while string.len(str)>0 do
+        local pos = string.find(str, split_char);
+        if (not pos) then
+        	if isNumber then
+            	t[#t + 1] = tonumber(str) or 0
+            else
+            	t[#t + 1] = str
+            end
+            break
+        end
+        local sub_str = string.sub(str, 1, pos - 1)
+    	if isNumber then
+        	t[#t + 1] = tonumber(sub_str) or 0
+        else
+        	t[#t + 1] = sub_str
+        end
+        str = string.sub(str, pos + 1, #str)
+    end
+    return t
+end
+
+-- 根据KEY从小到大排序
+function pairsByKeys(t)
+	local a = {}
+	for n in pairs(t) do
+		a[#a+1] = n
+	end
+	table.sort(a)
+	local i = 0
+	return function()
+	i = i + 1
+	return a[i], t[a[i]]
+	end
+end 
+
+function cmptb(a, b)
+	for k, v in pairs(a) do
+		if type(v) == "table" then
+			if type(b[k]) ~= "table" then
+				return
+			end
+			if not cmptb(v, b[k]) then
+				return
+			end
+		else
+			if b[k] ~= v and k ~= "now" and k ~= "uid" then
+				return
+			end
+		end
+	end
+	for k, v in pairs(b) do
+		if type(v) == "table" then
+			if type(a[k]) ~= "table" then
+				return
+			end
+			if not cmptb(v, a[k]) then
+				return
+			end
+		else
+			if a[k] ~= v and k ~= "now" and k ~= "uid" then
+				return
+			end
+		end
+	end
+	return true
+end
+
+function getWay(dx, dy)
+	return ((floor(( atan2(dy, dx) + 11.388) / 1.57)) % 4) * 2;
+end
+
+function tableIsEmpty(tb)
+	return _G.next(tb) == nil
+end
+
+-- 服务器是否符合
+function checkSvrIndex(svrIndexs, svrIndex)
+	if #svrIndexs < 1 then return true end
+
+	if not svrIndex then
+		svrIndex = Config.SVR_INDEX
+	end
+
+	for i = 1, #svrIndexs do
+		if svrIndexs[i][1] <= svrIndex and 
+			svrIndex <= svrIndexs[i][2] then
+			return true
+		end
+	end
+end
+
+-- 含中文文本长度
+function utf8len(content)
+    local len = string.len(content)
+    local left = len
+    local cnt = 0
+    local arr = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc}
+    while left ~= 0 do
+        local tmp = string.byte(content, -left)
+        local i = #arr
+        while arr[i] do
+            if tmp >= arr[i] then
+                left = left - i
+                break
+            end
+            i = i - 1
+        end
+        cnt = cnt + 1
+    end
+    return cnt
+end
+
+function checkRandom(cmpValue)
+	local r = math.random(0,10000)
+	if r < cmpValue then
+		return true
+	end
+end
+
+SEPARATOR = "||"
+function format(...)
+	local str = ""
+	local t = {}
+	for k,v in ipairs({...}) do
+		if k == 1 then
+			str = str .. v
+		else
+			t = split(v, SEPARATOR)
+			if #t > 1 then
+				t[1] = string.gsub(t[1],"({(.-)})",function(p1,p2)
+					p2 = tonumber(p2)
+					if p2 and t[p2+1] then
+						return string.sub(t[p2+1], 2)
+					else
+						return p1
+					end
+				end)
+			end
+            if t[1] then
+			   str = str .. SEPARATOR .. t[1]
+            end
+		end
+	end
+	return str
+end
+
+--------------------------------------------------------
+--- 新增table.find函数
+---@param1 array 数组
+---@param2 elem 目标元素
+--------------------------------------------------------
+
+table.find = function(array,elem) 
+	for idx,e in ipairs(array) do 
+		if e == elem then 
+			return idx
+		end
+	end
+end
+
+--------------------------------------------------------
+--- 新增table.shuffle函数
+--- @param1 array 数组
+--------------------------------------------------------
+
+table.shuffle = function(array)
+	for i = 1,#array do 
+		local r = math.random(1,#array)
+		array[i],array[r] = array[r],array[i]
+	end
+	return array
+end
+
+--------------------------------------------------------
+--- 新增table.copy函数
+--- @param1 array 数组
+--------------------------------------------------------
+
+function table.copy(object)
+    -- 已经复制过的table,key为复制源table,value为复制后的table
+    -- 为了防止table中的某个属性为自身时出现死循环
+    -- 避免本该是同一个table的属性,在复制时变成2个不同的table(内容同,但是地址关系和原来的不一样了)
+    local lookup_table = {}
+    local function _copy(object)
+        if type(object) ~= 'table' then -- 非table类型都直接返回
+            return object
+        elseif lookup_table[object] then
+            return lookup_table[object]
+        end 
+        local new_table = {}
+        lookup_table[object] = new_table
+        for k,v in pairs(object) do
+            new_table[_copy(k)] = _copy(v) 
+        end 
+        -- 这里直接拿mt来用是因为一般对table操作不会很粗暴的修改mt的相关内容
+        return setmetatable(new_table, getmetatable(object))
+    end 
+    return _copy(object)                    
+end
+
+--------------------------------------------------------
+--- 新增table.print_lua_table函数
+--- @param1 array 数组
+--------------------------------------------------------
+
+local function print_lua_table(lua_table, indent)
+	indent = indent or 0
+	for k, v in pairs(lua_table) do
+		if type(k) == "string" then
+			k = string.format("%q", k)
+		end
+		local szSuffix = ""
+		if type(v) == "table" then
+			szSuffix = "{"
+		end
+		local szPrefix = string.rep("    ", indent)
+		formatting = szPrefix.."["..k.."]".." = "..szSuffix
+		if type(v) == "table" then
+			print(formatting)
+			print_lua_table(v, indent + 1)
+			print(szPrefix.."},")
+		else
+			local szValue = ""
+			if type(v) == "string" then
+				szValue = string.format("%q", v)
+			else
+				szValue = tostring(v)
+			end
+			print(formatting..szValue..",")
+		end
+	end
+end
+
+table.print_lua_table = print_lua_table
+
+-- 打印当前堆栈
+function PrintNowStackTrace()
+	local stackTrace = debug.traceback("", 2)
+	print("[PrintNowStackTrace] 堆栈信息 "..stackTrace)
 end

+ 7 - 6
script/core/InnerMsg.lua

@@ -63,40 +63,41 @@ function readMsg(id, msg)
     if not template then
         assert(nil, "readMsg no template: id:"..id)
     end
+    
     local ret
     for i = 1, #template do
         if template[i][3] == 0 then
             ret, msg[template[i][1] ] = msg_parse.readint()
             if not ret then
-                assert(nil, "inner msg:"..proto_name[id]..template[i][1])
+                assert(nil, "inner msg:"..proto_name[id].." "..template[i][1])
             end
         elseif template[i][3] == 1 then
             ret, msg[template[i][1] ] = msg_parse.readstring()
             if not ret then
-                assert(nil, "inner msg:"..proto_name[id]..template[i][1])
+                assert(nil, "inner msg:"..proto_name[id].." "..template[i][1])
             end
         elseif template[i][3] == 2 then
             msg[template[i][1] ] = {}
             ret = msg_parse.readtable(msg[template[i][1]])
             if not ret then
-                assert(nil, "inner msg:"..proto_name[id]..template[i][1])
+                assert(nil, "inner msg:"..proto_name[id].." "..template[i][1])
             end
         elseif template[i][3] == 3 then
             ret, msg[template[i][1]] = msg_parse.readchunk()
             if not ret then
-                assert(nil, "inner msg:"..proto_name[id]..template[i][1])
+                assert(nil, "inner msg:"..proto_name[id].." "..template[i][1])
             end
         elseif template[i][3] == 4 then
 			msg[template[i][1]] = {}
             ret = msg_parse.readbinary( msg[template[i][1]])
             if not ret then
-                assert(nil, "inner msg:"..proto_name[id]..template[i][1])
+                assert(nil, "inner msg:"..proto_name[id].." "..template[i][1])
             end
         elseif template[i][3] == 5 then
 			msg[template[i][1]] = {}
             ret = msg_parse.readzip( msg[template[i][1]])
             if not ret then
-                assert(nil, "inner msg:"..proto_name[id]..template[i][1])
+                assert(nil, "inner msg:"..proto_name[id].." "..template[i][1])
             end
         end
     end

+ 17 - 2
script/module/chat/ChatLogic.lua

@@ -19,6 +19,7 @@ local RoleDBLogic = require("role.RoleDBLogic")
 local SettingLogic = require("setting.SettingLogic")
 local ObjHuman = require("core.ObjHuman")
 local InnerMsg = require("core.InnerMsg")
+local CommonDB = require("common.CommonDB")
 
 
 function chat(human, recvMsg, isJson)
@@ -39,8 +40,15 @@ function chat(human, recvMsg, isJson)
 
     -- 跨服聊天限制等级
     if recvMsg.msgType == ChatHandler.CHAT_TYPE_MIDDLE then 
+        local nOpenServerDay = CommonDB.getServerOpenDay()
+        if nOpenServerDay < 7 then
+            local str = Util.format(Lang.CHAT_MIDDLE_NEED_LV_ARGS, ChatHandler.CHAT_LV_NEED_MIDDLE)
+			Broadcast.sendDown(human, str)
+            return
+        end
+
 		if human.db.lv < ChatHandler.CHAT_LV_NEED_MIDDLE and VipLogic.getVipLv(human) == 0 then
-			local str = Util.format(Lang.CHAT_NEED_LV_ARGS, ChatHandler.CHAT_LV_NEED_MIDDLE)
+			local str = Util.format(Lang.CHAT_MIDDLE_NEED_LV_ARGS, ChatHandler.CHAT_LV_NEED_MIDDLE)
 			Broadcast.sendDown(human, str)
 			return 
 		end
@@ -145,8 +153,9 @@ function chat(human, recvMsg, isJson)
         if  recvMsg.msgType == ChatHandler.CHAT_TYPE_MIDDLE then
             -- 发送数据到中心服
             local lwMsgRet = InnerMsg.lw.LW_MIDDLE_CHAT
-            lwMsgRet.msg = msgRet
+            lwMsgRet.tChatMsg = msgRet
             InnerMsg.sendMsg(0, lwMsgRet)
+            print("[chat] 发送跨服消息开始")
         else
 		    Msg.sendWorld(msgRet)
             ChatRecord.addRecord(human,msgRet.item, recvMsg.msgType)
@@ -209,4 +218,10 @@ function isDot(human)
     if ChatRecord.CHAT_RECORD_FRIEND[human.db._id] and ChatRecord.CHAT_RECORD_FRIEND[human.db._id].count ~= 0 then 
         return true
     end
+end
+
+-- 跨服消息到达
+function WL_MIDDLE_CHAT(fd, msg)
+    Msg.sendWorld(msg.tChatMsg)
+    ChatRecord.addMiddleRecord(msg.tChatMsg.item, ChatHandler.CHAT_TYPE_MIDDLE)
 end

+ 50 - 16
script/module/chat/ChatRecord.lua

@@ -9,6 +9,7 @@ local RoleDBLogic = require("role.RoleDBLogic")
 local Lang = require("common.Lang")
 
 CHAT_RECORD_CNT = 30 -- 聊天记录保存60条
+CHAT_MIDDLE_CNT = 50    -- 跨服聊天记录缓存条数
 CHAT_RECORD_JINDU = CHAT_RECORD_JINDU or {}                     -- 聊天记录进度
 CHAT_FRIEND_LIST_CNT = 20  -- 私聊最多保留20个好友
 
@@ -227,6 +228,33 @@ function addRecord(human,chatItem, msgType,fUuid)
     end
 end
 
+-- 添加跨服聊天记录
+function addMiddleRecord(chatItem, msgType)
+    if msgType ~= ChatHandler.CHAT_TYPE_MIDDLE then
+        return
+    end
+
+    local record = nil
+    if CHAT_RECORD[msgType] == nil then
+        CHAT_RECORD[msgType] = {}   
+    end
+    record = CHAT_RECORD[msgType]
+
+    local nLen = #record
+    if nLen >= CHAT_MIDDLE_CNT then
+        local nDelLen = nLen - CHAT_MIDDLE_CNT + 1
+        for i = nDelLen, 1, -1 do
+            table.remove(record, i)
+        end
+    end
+
+    local newTb = Util.copyTable(chatItem)
+    table.insert(record, newTb)
+    if #record > CHAT_RECORD_CNT then
+        table.remove(record, 1)
+    end
+end
+
 -- 根据玩家Uuid 删除聊天记录
 function delRecordByUuid(uuid, msgType)
 	local tb = CHAT_RECORD[msgType]
@@ -306,13 +334,17 @@ function getChatRecord(human,type)
             end
         else
             if CHAT_RECORD[i] ~= nil then
-                local len = CHAT_RECORD_JINDU[i]
-                human.db.chatRead[i] = human.db.chatRead[i] or 0
-
-                net.notRead = len - human.db.chatRead[i]
-                if net.notRead >= CHAT_RECORD_CNT then
-                    net.notRead = CHAT_RECORD_CNT
-                elseif net.notRead < 0 then
+                if i ~= ChatHandler.CHAT_TYPE_MIDDLE then
+                    local len = CHAT_RECORD_JINDU[i]
+                    human.db.chatRead[i] = human.db.chatRead[i] or 0
+    
+                    net.notRead = len - human.db.chatRead[i]
+                    if net.notRead >= CHAT_RECORD_CNT then
+                        net.notRead = CHAT_RECORD_CNT
+                    elseif net.notRead < 0 then
+                        net.notRead = 0
+                    end
+                else
                     net.notRead = 0
                 end
             end
@@ -463,16 +495,18 @@ function sendAllNotRead(human)
             end
         else
             if CHAT_RECORD[i] ~= nil then
-                local len = CHAT_RECORD_JINDU[i]
-                human.db.chatRead[i] = human.db.chatRead[i] or 0
-
-                local notRead = len - human.db.chatRead[i]
-                if notRead >= CHAT_RECORD_CNT then
-                    notRead = CHAT_RECORD_CNT
-                elseif notRead < 0 then
-                    notRead = 0
+                if i ~= ChatHandler.CHAT_TYPE_MIDDLE then
+                    local len = CHAT_RECORD_JINDU[i]
+                    human.db.chatRead[i] = human.db.chatRead[i] or 0
+    
+                    local notRead = len - human.db.chatRead[i]
+                    if notRead >= CHAT_RECORD_CNT then
+                        notRead = CHAT_RECORD_CNT
+                    elseif notRead < 0 then
+                        notRead = 0
+                    end
+                    allNotRead = allNotRead + notRead
                 end
-                allNotRead = allNotRead + notRead
             end
         end
     end

+ 30 - 4
script/module/middle/MiddleConnect.lua

@@ -122,19 +122,27 @@ function stopConnectMiddle()
 end
 
 function LW_HELLO(fd, msg)
-    print("LW Hello")
+    --print("LW Hello fd = "..fd)
+    --table.print_lua_table(msg)
+    --local stackTrace = debug.traceback("", 2)
+	--print("[LW_HELLO] 堆栈信息 "..stackTrace)
     Log.write(Log.LOGID_INNER_CLOSE, "LW_HELLO")
 
     MiddleManager.addLogicServer(fd, msg.svrIndex)
 
-    local msg = InnerMsg.wl.WL_HELLO
-    InnerMsg.sendMsg(fd, msg)
+    local szMsgData = InnerMsg.wl.WL_HELLO
+    --table.print_lua_table(szMsgData)
+    szMsgData.nGetSvrID = msg.svrIndex
+    szMsgData.nNowSvrID = Config.SVR_INDEX
+    --table.print_lua_table(msg)
+    --table.print_lua_table(szMsgData)
+    InnerMsg.sendMsg(fd, szMsgData)
 
     msg = InnerMsg.wl.WL_HEARTBEAT
     InnerMsg.sendMsg(fd, msg)
     
     -- 同步其它信息
-    JjcLadderMiddle.sendWLMobaiCnt(fd)
+    -- JjcLadderMiddle.sendWLMobaiCnt(fd)
 end
 
 function WL_HELLO(fd, msg)
@@ -176,3 +184,21 @@ function WL_DISCONNECT(fd, msg)
         print("middle server disconnect!!!---")
     end
 end
+
+-- 跨服聊天请求
+function LW_MIDDLE_CHAT(fd, msg)
+    local tAllConnectFD = MiddleManager.MiddleManager_GetAllFD()
+    if not _G.next(tAllConnectFD) then
+        print("[LW_MIDDLE_CHAT] 不存在连接上的服务器")
+        return
+    end
+
+    local szMsgData = InnerMsg.wl.WL_MIDDLE_CHAT
+    szMsgData.tChatMsg = msg.tChatMsg
+
+    for _, nFD in pairs(tAllConnectFD) do
+        InnerMsg.sendMsg(nFD, szMsgData)
+    end
+
+    print("[LW_MIDDLE_CHAT] 发送消息结束")
+end

+ 1 - 1
script/module/middle/MiddleHeartBeat.lua

@@ -38,7 +38,7 @@ end
 
 
 function LW_HEARTBEAT(fd, msg)
-    print("LW_HEARTBEAT", msg.svrIndexData)
+    --print("LW_HEARTBEAT", msg.svrIndexData)
 
     MiddleManager.onHeartbeat(fd, msg.svrIndexData)
 

+ 12 - 7
script/module/middle/MiddleManager.lua

@@ -140,13 +140,13 @@ end
 
 function getOpenDaySvrCnt(openDay,actDay)
     for k,v in pairs(SVRINDEX_2_OPENDAY) do
-        if v == 0 then
-	    	return 0
-	    end
-	    
-	    local startTime = Util.getDayStartTime(v)
-	    
-	    local now = os.time()
+        if v == 0 then
+	    	return 0
+	    end
+	    
+	    local startTime = Util.getDayStartTime(v)
+	    
+	    local now = os.time()
 	    local openTime = math.ceil((now - startTime + 1) / 24 / 3600)
         
         local actOpenDay = openTime - actDay
@@ -164,4 +164,9 @@ function LW_ABS_ACT_IS_OPEN(fd,msg)
     msgRet.funcID = msg.funcID
     msgRet.isOpen = isOpen
     InnerMsg.sendMsg(fd, msgRet)
+end
+
+-- 获取所有fd
+function MiddleManager_GetAllFD()
+    return SVRINDEX_2_FD
 end