222a7d5f
 
  zhouhaihai
 
httpGm
 | 
1 
 | 
  
 
 | 
3fe4471e
 
  zhouhaihai
 
热更新 demo
 | 
2
3
4 
 | 
  local urllib = require "http.url"
  require "shared.init"
  require "utils.init"
 
 | 
222a7d5f
 
  zhouhaihai
 
httpGm
 | 
5
6
7
8
9
10 
 | 
  local sockethelper = require "http.sockethelper"
  local httpd = require "http.httpd"
  skynet = require "skynet"
  redisproxy = require "shared.redisproxy"
  netpack = require "skynet.netpack"
  datacenter = require "skynet.datacenter"
 
 | 
222a7d5f
 
  zhouhaihai
 
httpGm
 | 
11 
 | 
  mcast_util = require "services/mcast_util"
 
 | 
a5486ede
 
  zhouhaihai
 
csvdata 修改为 share...
 | 
12 
 | 
  csvdb = require "shared.csvdata"
 
 | 
222a7d5f
 
  zhouhaihai
 
httpGm
 | 
13
14 
 | 
  
  local socket = require "skynet.socket"
 
 | 
222a7d5f
 
  zhouhaihai
 
httpGm
 | 
15
16
17
18
19
20
21
22
23
24
25
26
27
28 
 | 
  
  require "shared.init"
  require "utils.init"
  require "ProtocolCode"
  require "skynet.manager"
  require "RedisKeys"
  require "GlobalVar"
  
  SendPacket = function(...) end
  rpcAgent = function(...) end
  rpcParter = function(...) end
  rpcRole = function(...) end
  rpcUnion = function(...) end
  rpcOtherUnion = function(...) end
 
 | 
3fe4471e
 
  zhouhaihai
 
热更新 demo
 | 
29
30
31
32 
 | 
  
  local table = table
  local string = string
  
 
 | 
c7ecb87f
 
  zhouhaihai
 
添加 测试账号 方法
 | 
33
34 
 | 
  skynet.register_protocol {
  	name = "role",
 
 | 
a5486ede
 
  zhouhaihai
 
csvdata 修改为 share...
 | 
35 
 | 
  	id = 101,
 
 | 
c7ecb87f
 
  zhouhaihai
 
添加 测试账号 方法
 | 
36
37
38
39 
 | 
  	pack = skynet.pack,
  	unpack = skynet.unpack,
  }
  
 
 | 
5e5d7680
 
  zhouhaihai
 
热更新 优化
 | 
40 
 | 
  local port = ...
 
 | 
3fe4471e
 
  zhouhaihai
 
热更新 demo
 | 
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 
 | 
  port = tonumber(port)
  
  local key = "zhaolu1234dangge"
  local function response(id, ...)
  	local ok, err = httpd.write_response(sockethelper.writefunc(id), ...)
  	if not ok then
  		-- if err == sockethelper.socket_error , that means socket closed.
  		skynet.error(string.format("fd = %d, %s", id, err))
  	end
  end
  
  
  local CMD = require "actions.HttpAction"
  
  local function start()
 
 | 
a5486ede
 
  zhouhaihai
 
csvdata 修改为 share...
 | 
56
57 
 | 
  	redisd = skynet.localname(".redis")
  	globalCsv = csvdb["GlobalDefineCsv"]
 
 | 
222a7d5f
 
  zhouhaihai
 
httpGm
 | 
58 
 | 
  	
 
 | 
33be3111
 
  zhouhaihai
 
修改hangPass 结构
 | 
59
60
61
62 
 | 
  	if tonumber(skynet.getenv "logd") == 1 then
  		logd = skynet.localname(".log")
  	end
  	
 
 | 
3fe4471e
 
  zhouhaihai
 
热更新 demo
 | 
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 
 | 
  	local listen_socket = socket.listen("0.0.0.0", port)
  	print("Listen web port " .. port)
  	socket.start(listen_socket , function(id, addr)
  		socket.start(id)
  		local code, url, method, header, body = httpd.read_request(sockethelper.readfunc(id), 8192)
  		if code then
  			if code ~= 200 then
  				response(id, code)
  			else
  				local path, query = urllib.parse(url)
  				local cmd = path:match("([^/]+)")
  				if not CMD[cmd] or not query then
  					response(id, 404)
  					socket.close(id) 
  					return 
  				end
  				local query = urllib.parse_query(query)
  				if query.key ~= key then
  					response(id, 404)
  					socket.close(id) 
  					return 
  				end
  				local content = CMD[cmd](query, body)
  				if not content then
  					code = 404
  				end
 
 | 
f871be67
 
  zhouhaihai
 
返回值要是字符串
 | 
89 
 | 
  				response(id, code, tostring(content))
 
 | 
3fe4471e
 
  zhouhaihai
 
热更新 demo
 | 
90
91
92
93
94
95
96
97
98
99 
 | 
  			end
  		else
  			if url == sockethelper.socket_error then
  				skynet.error("socket closed")
  			else
  				skynet.error(url)
  			end
  		end
  		socket.close(id)
  	end)
 
 | 
e3c5cc5e
 
  zhouhaihai
 
跨服竞技场over
 | 
100
101
102
103
104
105
106
107
108
109
110
111 
 | 
  
  	-- 注册全服广播
  	local channels = {}
  	for i = 1, 10 do
  		local channel = datacenter.get("MC_W_CHANNEL" .. i)
  		if channel then
  			table.insert(channels, channel)
  		end
  	end
  	if #channels > 0 then
  		mcast_util.sub_worlds(channels)
  	end
 
 | 
3fe4471e
 
  zhouhaihai
 
热更新 demo
 | 
112
113
114
115
116
117
118
119
120
121
122 
 | 
  end
  
  local function __init__()
  	skynet.dispatch("lua", function(_,_, command, ...)
  		if command == "start" then
  			skynet.ret(skynet.pack(start(...)))
  		end
  	end)
  end
  
  skynet.start(__init__)
 
 |