| 314bc5df  zhengshouren
 
提交服务器初始代码 | 1 |   local skynet = require "skynet"
 | 
| 3fe4471e  zhouhaihai
 
热更新 demo | 2 |   require "skynet.manager"
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 3
4
5
6
7
8
9 |   local socket = require "skynet.socket"
  local netpack = require "skynet.netpack"
  local datacenter = require "skynet.datacenter"
  local snax = require "skynet.snax"
  local agent_ctrl = require "services.agent_ctrl"
  local xxtea = require "xxtea"
  local mc = require "skynet.multicast"
 | 
| 875e5071  zhouhaihai
 
服务名称修改 | 10 |   local cluster = require "skynet.cluster"
 | 
| a5486ede  zhouhaihai
 
csvdata 修改为 share... | 11 |   local csvdata = require "shared.csvdata"
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 12
13
14
15
16
17
18 |   
  require "ProtocolCode"
  require "GlobalVar"
  require "shared.init"
  require "utils.init"
  
  local CMD, SOCKET = {}, {}
 | 
| 875e5071  zhouhaihai
 
服务名称修改 | 19 |   local globald, pvpd
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 |   
  local pool_size = tonumber(...)
  
  function SOCKET.open(fd, addr)
  	skynet.call(gate_serv, "lua", "accept" , fd)
  	agent_ctrl:socket_open(fd, addr)
  end
  
  function SOCKET.close(fd)
  	print("socket close", fd)
  	agent_ctrl:socket_close(fd)
  end
  
  function SOCKET.error(fd, msg)
  	print("socket error",fd, msg)
  	agent_ctrl:socket_error(fd)
  end
  
  function SOCKET.data(fd, msg)
 | 
| 759669cc  zhouhaihai
 
报错 | 39 |   	if #msg < 2 then return end
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 40
41
42
43
44
45
46
47
48 |   	local cmd = string.unpack("H", string.sub(msg, 1, 2))
  	if cmd == actionCodes.Role_queryLoginRpc then
  		local data = MsgPack.unpack(xxtea.decrypt(string.sub(msg, 3), XXTEA_KEY))
  		-- TODO: 先检测uid的合法性
  		if not data or not data.uid then return end
  		agent_ctrl:query_agent(fd, data.uid)
   	end
  end
  
 | 
| 3f604f2e  zhouhaihai
 
扩容 redis 和 log服务 | 49 |   
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 50
51
52
53 |   
  -- @desc: agent状态定时检测
  function check_agent_status()
  	pcall(agent_ctrl.check_agent_status, agent_ctrl)
 | 
| 3c0ea5fb  zhouhaihai
 
抽英雄 | 54 |   	skynet.timeout(100, check_agent_status)
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 55
56
57
58 |   end
  
  -- 创建world以及union channel 用于广播
  function create_mutilcast()
 | 
| 06c7246e  测试
 
按500人分线 | 59 |   	for i = 1, 50 do
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 60
61
62
63
64
65
66 |   		local chan_w = mc:new()
  		datacenter.set("MC_W_CHANNEL" .. i, chan_w.channel)
  	end
  end
  
  function CMD.start(conf)
  	skynet.call(gate_serv, "lua", "open" , conf)
 | 
| 3f604f2e  zhouhaihai
 
扩容 redis 和 log服务 | 67 |   	
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 68 |   	skynet.call(pvpd, "lua", "start")
 | 
| 555f745e  zhangqijia
 
feat: 一番赏 | 69
70 |   
  	skynet.call(capsuled, "lua", "start")
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 71
72
73
74
75 |   	-- 开启agent状态检测定时器
  	check_agent_status()
  	-- 创建广播服务
  	create_mutilcast()
  
 | 
| 3fe4471e  zhouhaihai
 
热更新 demo | 76 |   	skynet.call(conf.httpd, "lua", "start")
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 77
78
79
80 |   
  	-- roomServer = skynet.newservice("services/roomServer")
  	-- skynet.call(roomServer, "lua", "start")
  
 | 
| 875e5071  zhouhaihai
 
服务名称修改 | 81
82 |   	skynet.newservice("services/dbseed")
  
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 83
84
85 |   	globald = skynet.newservice("services/globald")
  	skynet.call(globald, "lua", "start")
  
 | 
| 875e5071  zhouhaihai
 
服务名称修改 | 86
87 |   	local servId = tonumber(skynet.getenv("servId"))
  	cluster.open("server" .. servId)
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 88
89
90
91
92
93 |   end
  
  function CMD.forceClose(fd)
  	agent_ctrl:exit_agent(fd)
  end
  
 | 
| 3fe4471e  zhouhaihai
 
热更新 demo | 94
95
96
97 |   function CMD.hotfix(code)
  	agent_ctrl:hotfix(code)
  end
  
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 98
99
100
101
102
103
104
105
106
107
108 |   skynet.start(function()
  	skynet.dispatch("lua", function(session, source, cmd, subcmd, ...)
  		if cmd == "socket" then
  			local f = SOCKET[subcmd]
  			f(...)
  			-- socket api don't need return
  		else
  			local f = assert(CMD[cmd])
  			skynet.ret(skynet.pack(f(subcmd, ...)))
  		end
  	end)
 | 
| a5486ede  zhouhaihai
 
csvdata 修改为 share... | 109 |   	skynet.register ".watchdog"
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 110 |   
 | 
| a5486ede  zhouhaihai
 
csvdata 修改为 share... | 111
112 |   	-- 提前加载好
  	csvdata.init()
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 113
114 |   	print("launch csvdatad ...")
  
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 115
116
117 |   	-- pvp 服务
  	pvpd = skynet.newservice("services/pvpd")
  	cluster.register("pvpd", pvpd)
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 118
119
120
121
122
123
124
125
126
127
128
129
130 |   	
  	local poold = skynet.newservice("services/poold")
  	local obj = skynet.call(poold, "lua", "start", pool_size)
  
  	agent_ctrl:init(obj, poold)
  
  	print(string.format("launch %d agent at the beginning", pool_size))
  
  	-- 全局工具函数
  	skynet.newservice("services/named")
  	skynet.newservice("services/chated")
  	-- 网关服务
  	gate_serv = skynet.newservice("gate")
 | 
| 555f745e  zhangqijia
 
feat: 一番赏 | 131 |   	capsuled = skynet.newservice("services/capsuled")
 | 
| 314bc5df  zhengshouren
 
提交服务器初始代码 | 132 |   end)
 |