mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 19:43:09 +00:00
msggate example
This commit is contained in:
@@ -1,5 +1,18 @@
|
||||
package.cpath = "luaclib/?.so"
|
||||
|
||||
--[[ Status code
|
||||
|
||||
200 OK
|
||||
|
||||
400 Bad Request (通常是登陆协议错误)
|
||||
401 Unauthorized (通常是登陆服务器或游戏服务器验证错误)
|
||||
403 Forbidden (通常是连接游戏服务器的 index 已经过期)
|
||||
404 Not Found (通常是游戏服务器未获得登陆服务器的通知)
|
||||
406 Not Acceptable (通常是登陆服务器转发游戏服务器拒绝登陆)
|
||||
412 Precondition Failed (通常是遗漏了和游戏服务器前次通讯的请求)
|
||||
|
||||
]]
|
||||
|
||||
local socket = require "clientsocket"
|
||||
local cjson = require "cjson"
|
||||
local crypt = require "crypt"
|
||||
@@ -43,6 +56,7 @@ local hmac = crypt.hmac64(challenge, secret)
|
||||
socket.writeline(fd, crypt.base64encode(hmac))
|
||||
|
||||
local token = {
|
||||
server = "sample",
|
||||
user = "hello",
|
||||
pass = "password",
|
||||
}
|
||||
@@ -53,6 +67,49 @@ socket.writeline(fd, crypt.base64encode(etoken))
|
||||
|
||||
print(readline())
|
||||
|
||||
socket.close(fd)
|
||||
|
||||
----- connect to game server
|
||||
|
||||
local input = {}
|
||||
local fd = assert(socket.connect("127.0.0.1", 8888))
|
||||
|
||||
local function readpackage()
|
||||
local line = table.remove(input, 1)
|
||||
if line then
|
||||
return line
|
||||
end
|
||||
|
||||
while true do
|
||||
local status
|
||||
status, last = socket.recv(fd, last, input)
|
||||
if status == nil then
|
||||
error "Server closed"
|
||||
end
|
||||
if not status then
|
||||
socket.usleep(100)
|
||||
else
|
||||
local line = table.remove(input, 1)
|
||||
if line then
|
||||
return line
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local index = 0
|
||||
local request = 0
|
||||
local handshake = string.format("%s@%s:%d:%d", crypt.base64encode(token.user), crypt.base64encode(token.server) , index, request)
|
||||
local hmac = crypt.hmac64(crypt.hashkey(handshake), secret)
|
||||
|
||||
socket.send(fd, handshake .. ":" .. crypt.base64encode(hmac))
|
||||
|
||||
print(readpackage())
|
||||
|
||||
socket.send(fd , "echo")
|
||||
print(readpackage())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user