2D捕鱼服务器说明⽂档,这个捕鱼:
(图:2D捕鱼)
服务器器使⽤用引擎:skynet
最新源码:skynet;
消息的交互流程图:
捕⻥鱼项⽬目代码:
server
----logic 逻辑代码
--------activity 活动模块
--------auth 鉴权模块
--------charge 充值模块
--------charge_disk 充值转盘活动
--------... 按模块来划分
----pb 协议⼆二进制⽂文件
----protos
----service
环境部署:
linux 下编译:
make linux
mac 下编译:
make macosx
编译可能需要的⼯工具:
协议源⽂文件skynet服务,进程启动后会启动服务
yum install gcc-c++ g++ automake autoconf libtool make
编译成功,⽬目录中会⽣生产 skynet ⽂文件。
数据库部署:
游戏使⽤用mongo数据库
安装 mongo 数据参考教程:mongo安装及mongo验证机制修改方法;
游戏的基本设置(常⽤用的):
config_public
centerServerHost 中心服务的地址
centerServerKey 中心服务器器的Key
config_port
serverIndex 服务器起始端⼝,例例设置为5,从5000开始,对外监听端口:5901
http_port 对外开⽹的 http 端⼝
whiteIps 可接收http请求的⽩名单地址
secretKey 后台服务器的Key
gameServerKey 后台发⽤到的key
authmod 数据库的参数
mongo_host
mongo_port
mongo_db_name
mongo_username
mongo_password
启动服务器器:
# sh run.sh
关闭服务器器:
# sh stop.sh
数据库的参数
开发相关:
协议注册⽂文件:proto_map.lua
服务器器协议使用的是 google protobuf(⽹上有详细的讲解)
(注:pb⽂件即通过proto文件⽣产而来)
模块的详细说明:
例子一:认证模块
M_Auth = {
module = "auth",service = SERVICE.AUTH,
login = {id = 0x0101, type = 1, request = "auth.LoginRequest", response = "auth.LoginResponse", log = 0, desc = "登 录"},
createRole = {id = 0x0102, type = 1, request = "auth.CreateRoleInfo", response = nil, log = 1, desc = "创建⻆色"},
heartbeat = {id = 0x0103, type = 1, request = nil,response = nil, log = 0, desc = "⼼心跳"},
onOffline = {id = 0x0104, type = 2, response = "auth.OfflineReason", log = 1, desc = "离线"},
getServerTime = {id = 0x0105, type = 1, response = "auth.ServerTime", log = 0, desc = "获取服务器时间"},
}
protoMap.Auth = M_Auth
M_Auth 模块
login 协议名
id = **** 协议号
type = * 协议类型 1:client->server 2:server->client
request 请求数据格式(auth.LoginRequest 详⻅见:auth.proto⽂文件中
LoginRequest)
response 应答数据
例子二:修改玩家开炮的逻辑
1、找到玩家开炮的协议
M_CatchFish = {
module = "catch_fish",
fire = {id = 0x0202, type = 1, request = "catch_fish.FireInfo",
response = nil, log = 0, desc = "开炮"},}
2、打开 catch_fish_impl.lua 找到 fire ⽅法
function catchFishImpl.fire(roleId, fireInfo)
...... (忽略部分代码) ......
local ec, costGold = context.callS2S(context.catchFishSvc, "fire",fireInfo, cost)
...... (红⾊部分代码请求捕鱼服务,开炮) ......
if ec == SystemError.success and costGold then
roleCtrl.setCostGold(roleId, costGold)
end
return ec
end
3、打开 catch_fish_svc.lua 找到 fire ⽅法
function command.fire(fireInfo, cost)
...... (忽略略部分代码) ......
return room:fire(fireInfo, cost)
end
4、打开 room.lua 找到 fire ⽅法
function Room:fire(fireInfo, cost)
...... (这⾥是捕⻥开炮的全部逻辑)
end
......
END!!!
- 1、找到玩家开炮的协议
- 2、打开 catch_fish_impl.lua 找到 fire ⽅法
- 3、打开 catch_fish_svc.lua 找到 fire ⽅法
- 4、打开 room.lua 找到 fire ⽅法
发表评论