0de80321
liuzujun
创建游戏数据库,role对应mys...
|
1
2
3
4
5
6
7
8
9
10
|
local skynet = require "skynet"
require "skynet.manager"
local mysql = require "skynet.db.mysql"
local db
local idx = ...
local command = {}
function command.open(conf)
local function on_connect(db)
|
01be2d78
liuzujun
修改mysql链接断开重连的bug
|
11
|
local servId = skynet.getenv("servId")
|
8e4be7b8
liuzujun
兼容mysql5.7.19 set...
|
12
|
db:query("set names utf8mb4");
|
01be2d78
liuzujun
修改mysql链接断开重连的bug
|
13
|
db:query(string.format("use server_%s", servId))
|
0de80321
liuzujun
创建游戏数据库,role对应mys...
|
14
|
end
|
01be2d78
liuzujun
修改mysql链接断开重连的bug
|
15
|
local servId = skynet.getenv("servId")
|
0de80321
liuzujun
创建游戏数据库,role对应mys...
|
16
|
db=mysql.connect({
|
9b69ca55
liuzujun
mysql 配置添加
|
17
18
|
host=conf.host,
port=conf.port,
|
01be2d78
liuzujun
修改mysql链接断开重连的bug
|
19
|
database= "mysql",
|
9b69ca55
liuzujun
mysql 配置添加
|
20
21
|
user=conf.user,
password=conf.pwd,
|
a12bfcce
liuzujun
添加英雄表
|
22
|
max_packet_size = 5 * 1024 * 1024,
|
0de80321
liuzujun
创建游戏数据库,role对应mys...
|
23
24
25
26
27
|
on_connect = on_connect
})
if not db then
print("failed to connect")
end
|
0de80321
liuzujun
创建游戏数据库,role对应mys...
|
28
29
30
31
32
33
34
|
end
skynet.start(function()
skynet.dispatch("lua", function(session, address, cmd, ...)
if cmd == "open" then
local f = command[string.lower(cmd)]
skynet.ret(skynet.pack(f(...)))
|
6136eaca
liuzujun
添加好友表
|
35
36
|
elseif string.lower(cmd) == "quote_sql_str" then
skynet.ret(skynet.pack(db[string.lower(cmd)](...)))
|
0de80321
liuzujun
创建游戏数据库,role对应mys...
|
37
38
39
40
41
42
43
44
45
|
else
skynet.ret(skynet.pack(db[string.lower(cmd)](db, ...)))
end
end)
skynet.info_func(function()
return skynet.stat("mqlen")
end)
skynet.register(".mysql" .. idx)
end)
|