269 lines
5.5 KiB
Protocol Buffer
269 lines
5.5 KiB
Protocol Buffer
syntax = "proto2";
|
||
package cs;
|
||
option go_package = ".;cs";
|
||
|
||
/*
|
||
约定:
|
||
CM前缀:客户端发给服务器的消息(client message)
|
||
SM前缀:服务器发给客户的的消息(server message)
|
||
MF前缀:消息的内嵌字段,只能作为其他消息的内嵌字段不能send(message field)
|
||
_e后缀:枚举类型
|
||
_uniid后缀:唯一id
|
||
union_前缀:联合体
|
||
_前缀:该字段仅服务器使用客户端无需处理
|
||
|
||
网络包格式:msghead + msgbody
|
||
msghead: packagelen + msgid + seqid + magiccode + reserved = 2 + 2 + 4 + 2 + 2 = 12字节
|
||
msgbody: protobuf数据
|
||
msghead说明
|
||
packagelen(unsigned short): 双字节网络包长度,
|
||
msgid(unsigned short): 双字节消息id
|
||
seqid(unsigned int): 4字节序号id
|
||
magiccode(unsigned short): 2字节魔数,并且为固定常数KS,占位符客户端不需什么处理
|
||
reserved(unsigned short): 保留
|
||
|
||
十六进制位运算数据表示法
|
||
0x01 == 1<<0
|
||
0x02 == 1<<1
|
||
0x04 == 1<<2
|
||
*/
|
||
|
||
//常量
|
||
enum Constant_e
|
||
{
|
||
ProtoVersion = 2023051601; //系统版本
|
||
}
|
||
|
||
//心跳
|
||
message CMPing
|
||
{
|
||
}
|
||
message SMPing
|
||
{
|
||
optional int32 param1 = 1;
|
||
optional int32 source = 2 [default = 0]; //0:tcp 1:udp
|
||
}
|
||
|
||
//rpc调用错误
|
||
message SMRpcError
|
||
{
|
||
optional int32 error_code = 1;
|
||
optional string error_msg = 2;
|
||
optional string debug_msg = 3;
|
||
optional string file = 4;
|
||
optional int32 lineno = 5;
|
||
optional int32 error_param = 6;
|
||
}
|
||
|
||
//int32键值对
|
||
message MFPair
|
||
{
|
||
optional int32 key = 1; //key
|
||
optional int32 value = 2; //val
|
||
}
|
||
|
||
//int64键值对
|
||
message MFPair64
|
||
{
|
||
optional int64 key = 1; //key
|
||
optional int64 value = 2; //val
|
||
}
|
||
|
||
//int32元组
|
||
message MFTuple
|
||
{
|
||
repeated int32 values = 1; //values
|
||
}
|
||
|
||
//string元组
|
||
message MFTupleString
|
||
{
|
||
repeated string values = 1; //values
|
||
}
|
||
|
||
//分页信息
|
||
message MFPagination
|
||
{
|
||
optional int32 total = 1; //总记录数
|
||
optional int32 count = 2; //当前页查到的记录数
|
||
optional int32 current_page = 3; //当前第几页
|
||
optional int32 total_page = 4; //总页数
|
||
}
|
||
|
||
//房间信息(房间列表)
|
||
message MFRoom
|
||
{
|
||
optional string room_id = 1; //房间号
|
||
optional int32 map_id = 2; //地图id
|
||
optional int32 zone_id = 3; //区id
|
||
optional int32 has_passwd = 4; //是否有密码
|
||
optional int32 team_num = 5; //队伍数
|
||
optional int32 player_num = 6; //玩家数
|
||
optional int32 team_max_num = 7; //最大队伍数
|
||
optional int32 player_max_num = 8; //最大玩家数
|
||
|
||
optional MFMember owner = 20; //房主
|
||
}
|
||
|
||
//队伍成员信息
|
||
message MFMember
|
||
{
|
||
optional string account_id = 1; //账号id
|
||
optional string name = 2; //
|
||
optional string avatar_url = 3; //头像
|
||
optional int32 hero_id = 4; //英雄id
|
||
optional int32 state = 9; //0:准备 1:已准备
|
||
optional int32 ping = 20; //ping值(单位毫秒)
|
||
}
|
||
|
||
//队伍信息
|
||
message MFTeam
|
||
{
|
||
optional int32 team_id = 1; //队伍id
|
||
repeated MFMember members = 2; //成员列表
|
||
}
|
||
|
||
//自己所在房间信息
|
||
message MFCurrentRoom
|
||
{
|
||
optional string room_id = 1; //房间号
|
||
optional int32 map_id = 2; //地图id
|
||
optional int32 zone_id = 3; //区id
|
||
optional int32 has_passwd = 4; //是否有密码
|
||
optional int32 team_num = 5; //队伍数
|
||
optional int32 player_num = 6; //玩家数
|
||
optional int32 team_max_num = 7; //最大队伍数
|
||
optional int32 player_max_num = 8; //最大玩家数
|
||
|
||
optional MFMember owner = 20; //房主
|
||
|
||
repeated MFTeam team_list = 30; //队伍列表
|
||
}
|
||
|
||
//登录
|
||
message CMLogin
|
||
{
|
||
optional int32 server_id = 1; //保留
|
||
optional string team_uuid = 2; //保留
|
||
optional string account_id = 3; //账号id
|
||
optional int32 proto_version = 5; //协议版本号Constant_e.ProtoVersion
|
||
optional string session_id = 20; //账号id
|
||
optional int32 zone_id = 21; //国家Id
|
||
}
|
||
|
||
//登录回复
|
||
message SMLogin
|
||
{
|
||
optional int32 errcode = 7; //错误码 0:成功 1:重连失败
|
||
optional string errmsg = 10; //错误描述
|
||
optional string server_info = 9; //服务器信息(重连时使用)
|
||
}
|
||
|
||
//断线重连
|
||
message CMReconnect
|
||
{
|
||
optional int32 server_id = 1; //保留
|
||
optional string team_uuid = 2; //保留
|
||
optional string account_id = 3; //账号id
|
||
optional string session_id = 4; //session_id
|
||
optional string room_uuid = 5; //房间唯一id
|
||
optional string server_info = 6; //服务器信息
|
||
|
||
}
|
||
|
||
//断线重连回复
|
||
message SMReconnect
|
||
{
|
||
optional int32 errcode = 1; //错误码 0:成功 1:重连失败
|
||
optional string errmsg = 2; //错误描述
|
||
}
|
||
|
||
//创建房间
|
||
message CMCreateRoom
|
||
{
|
||
optional string passwd = 1; //密码,空:无密码
|
||
}
|
||
|
||
message SMCreateRoom
|
||
{
|
||
optional int32 errcode = 1; //错误码 0:成功 1:重连失败
|
||
optional string errmsg = 2; //错误描述
|
||
}
|
||
|
||
//获取房间列表
|
||
message CMRoomList
|
||
{
|
||
optional int32 page = 1; //
|
||
}
|
||
|
||
message SMRoomList
|
||
{
|
||
optional MFPagination Pagination = 1; //分页信息
|
||
repeated MFRoom rows = 2; //
|
||
}
|
||
|
||
//加入房间
|
||
message CMJoinRoom
|
||
{
|
||
optional string room_id = 1; //房间号
|
||
optional string passwd = 2; //密码,空:无密码
|
||
}
|
||
|
||
message SMJoinRoom
|
||
{
|
||
|
||
}
|
||
|
||
//解散房间
|
||
message CMDisbandRoom
|
||
{
|
||
optional string room_id = 1; //房间号
|
||
}
|
||
|
||
message SMDisbandRoom
|
||
{
|
||
|
||
}
|
||
|
||
//退出房间
|
||
message CMLeaveRoom
|
||
{
|
||
optional string room_id = 1; //房间号
|
||
}
|
||
|
||
message SMLeaveRoom
|
||
{
|
||
|
||
}
|
||
|
||
//修改房间
|
||
message CMModifyRoom
|
||
{
|
||
optional string room_id = 1; //房间号
|
||
}
|
||
|
||
message SMModifyRoom
|
||
{
|
||
|
||
}
|
||
|
||
//开始游戏
|
||
message CMStartGame
|
||
{
|
||
}
|
||
|
||
message SMStartGame
|
||
{
|
||
|
||
}
|
||
|
||
//准备
|
||
message CMSetPrepare
|
||
{
|
||
}
|
||
|
||
//踢人
|
||
message CMKickout
|
||
{
|
||
}
|