-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapSvr.lua
More file actions
166 lines (150 loc) · 5.68 KB
/
MapSvr.lua
File metadata and controls
166 lines (150 loc) · 5.68 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---@class MapSvrType
---@field safeStop boolean 安全停服是否已经被触发
---@field IsSafeStop function 返回boolean安全停服是否已经被触发
---@class MapSvr:MapSvrType
MapSvr = MapSvr or {
safeStop = false
};
require("ProtoLuaImport");
local Log = require("Log");
local MsgHandler = require("MsgHandlerLogic")
local PlayerMgr = require("PlayerMgrLogic")
local MapMgr = require("MapMgrLogic")
local FSRoomMgr = require("FSRoomMgrLogic")
local Map3DMgr = require("Map3DMgrLogic")
local TimeMgr = require("TimeMgrLogic")
local AlgorithmRandom = require("AlgorithmRandomLogic")
--- 线程被启动时只调用一次
---@return nil
function MapSvr.OnInit()
AlgorithmRandom.RandomSeed(math.floor(TimeMgr.GetS()))
MapSvr.safeStop = false;
end
--- 线程被终止时触发一次
---@return nil
function MapSvr.OnStop()
PlayerMgr.OnStop()
MapMgr.OnStop()
FSRoomMgr.OnStop()
Map3DMgr.OnStop();
end
--- 线程Tick频率以配置文件变量epoll_wait_time控制
---@return nil
function MapSvr.OnTick()
PlayerMgr.OnTick()
MapMgr.OnTick()
FSRoomMgr.OnTick()
Map3DMgr.OnTick();
end
--- 安全停服,需要在OnStop前被调用,做一些清理工作
---@return nil
function MapSvr.OnSafeStop()
Log:Error("MapSvr.OnSafeStop()");
MapSvr.safeStop = true;
PlayerMgr.OnSafeStop();
MapMgr.OnSafeStop();
FSRoomMgr.OnSafeStop();
Map3DMgr.OnSafeStop();
end
--- 是否已经进行了安全停服
---@return boolean
function MapSvr.IsSafeStop()
return MapSvr.safeStop;
end
--- 当服务器进程被kill -10 或 线程Init时被触发
---@return nil
function MapSvr.OnReload()
-- hot load PlayerLogic scriptss
local reloadList = {}
table.insert(reloadList, "PlayerLogic")
table.insert(reloadList, "PlayerMgrLogic")
table.insert(reloadList, "PlayerCmptBaseLogic")
table.insert(reloadList, "PlayerCmptInfoLogic")
table.insert(reloadList, "PlayerCmptBagLogic")
table.insert(reloadList, "PlayerCmptMapLogic")
table.insert(reloadList, "PlayerCmptMap3DLogic")
table.insert(reloadList, "PlayerCmptFSRoomLogic")
table.insert(reloadList, "MapLogic")
table.insert(reloadList, "MapMgrLogic")
table.insert(reloadList, "FSRoomPlayerLogic")
table.insert(reloadList, "FSRoomPlayerSkillLogic")
table.insert(reloadList, "FSRoomSyncLogic")
table.insert(reloadList, "FSRoomHexMapLogic")
table.insert(reloadList, "FSRoomHexMapAStarLogic")
table.insert(reloadList, "FSRoomIsometricMapLogic")
table.insert(reloadList, "FSRoomIsometricMapAStarLogic")
table.insert(reloadList, "FSRoomSquareMapLogic")
table.insert(reloadList, "FSRoomSquareMapAStarLogic")
table.insert(reloadList, "FSRoomMapFactoryLogic")
table.insert(reloadList, "FSRoomBattleLogic")
table.insert(reloadList, "FSRoomLogic")
table.insert(reloadList, "FSRoomMgrLogic")
table.insert(reloadList, "MsgHandlerFromUDPLogic")
table.insert(reloadList, "MsgHandlerFromOtherLogic")
table.insert(reloadList, "MsgHandlerFromClientLogic")
table.insert(reloadList, "MsgHandlerLogic")
table.insert(reloadList, "ConfigTableMgrLogic")
table.insert(reloadList, "TimeMgrLogic")
table.insert(reloadList, "Map3DLogic")
table.insert(reloadList, "Map3DMgrLogic")
for i, name in ipairs(reloadList) do
package.loaded[name] = nil;
end
---@type table<integer,string>
local reloadErrorList = {};
for i, name in ipairs(reloadList) do
local ok, module = pcall(require, name)
if ok then
Log:Error("%s.lua Reloaded", name);
else
Log:Error("%s.lua Reload Err %s", name, tostring(module))
table.insert(reloadErrorList, name);
end
end
MsgHandler:OnReload();
MapMgr.OnReload();
FSRoomMgr.OnReload();
Map3DMgr.OnReload();
local reloadErrorListStr = "MapSvr.OnReload Error List:[";
for i, name in ipairs(reloadErrorList) do
reloadErrorListStr = reloadErrorListStr .. name;
if i ~= #reloadErrorList then
reloadErrorListStr = reloadErrorListStr .. ",";
end
end
reloadErrorListStr = reloadErrorListStr .. "]";
Log:Error("%s", reloadErrorListStr);
Log:Error("MapSvr.OnReload Done");
end
--- 当C++给Lua虚拟机传递新的Protobuf消息
---@param msg_type integer
---@param cmd integer
---@param message table
---@param uint64_param1_string string
---@param int64_param2_string string
---@param str_param3 string
---@return nil
function MapSvr.OnLuaVMRecvMessage(msg_type,
cmd,
message,
uint64_param1_string,
int64_param2_string,
str_param3)
-- Log:Error("OnLuaVMRecvMessage cmd[%d] uint64_param1_string[%s] int64_param2_string[%s] str_param3[%s]", cmd, uint64_param1_string, int64_param2_string, str_param3)
if msg_type == ProtoLua_ProtoLuaVMMsgType.PROTO_LUA_VM_MSG_TYPE_CLIENT then -- 客户端
local clientGID = uint64_param1_string
local workerIdx = tonumber(int64_param2_string)
if workerIdx == nil then
Log:Error("OnLuaVMRecvMessage workerIdx == nil");
return;
end
MsgHandler:HandlerMsgFromClient(clientGID, workerIdx, cmd, message);
elseif msg_type == ProtoLua_ProtoLuaVMMsgType.PROTO_LUA_VM_MSG_TYPE_IPC then -- ipc
MsgHandler:HandlerMsgFromOther(cmd, message, str_param3);
elseif msg_type == ProtoLua_ProtoLuaVMMsgType.PROTO_LUA_VM_MSG_TYPE_UDP then -- udp
MsgHandler:HandlerMsgFromUDP(cmd, message, str_param3, int64_param2_string);
else
Log:Error("OnLuaVMRecvMessage Unknown msg_type %d", msg_type)
end
end
return MapSvr;