公共服

错误码

9100~9199 公共服

错误码 描述
9100 success
9101 参数错误
9102 数据库错误
9103 数据反序化失败
9104 游戏玩法ID错误
9105 未知事件
9106 服务器错误
9107 用户未登录
9108 用户重复登录
9109 已在其他设备登录
9110 验证码失效
9111 验证码错误
9112 验证码次数超限
9113 验证码发送失败
9114 短信发送失败
9115 手机号码错误
9116 短信发送成功
9120 用户已存在
9121 用户验证失败
9122 用户不存在
9123 帐号被禁用
9141 数据长度超限
9143 无场次信息
9144 不能发送给自己
9145 用户信息错误
9146 手机号码格式不对
9147 请求第三方服务失败
9148 微信支付失败
9149 不允许微信h5支付
9150 不允许微信APP支付
9151 地区ID不存在
9152 用户已经设置地区ID
9153 不允许支付宝H5支付
9154 房间不存在
9155 房间已开始游戏
9156 该用户没有在任何房间

事件定义

从9100到9199 事件流向:

c->s 客户端发送到服务器端 s->c 服务器端发送给客户端

事件编号 事件名称 事件流向 是否返回 描述
9100 生成验证码 c->s true 通用回包
9102 通用回包 s->c
9103 登录 c->s true 成功登录回包,再推送用户信息 ,失败通用回包
9104 登录回包 s->c
9105 心跳 s->c true 原样回包
9106 查询用户信息 c->s true 成功查询用户信息回包,失败通用回包
9107 查询用户信息回包 s->c
9108 设置用户信息 c->s true 通用回包
9113 用户退出 c->s true 通用回包
9114 客服 c->s true 成功客服回包,失败通用回包
9115 客服回包 s->c
9123 充值列表 c->s true 成功充值列表回包,失败通用回包
9124 充值列表回包 s->c
9127 公告列表 c->s true 成功公告列表回包,失败通用回包
9128 公告列表回包 s->c
9134 游戏内最新消息 s->c -

客户端请求时,所有失败的都会返回9102,以下不会再注明,请知悉!

事件ID 描述 事件流向 返回事件ID 注备
9102 服务器返回 s->c - -
9136 新消息 s->c - 登录时或有新消息时推送
9137 查询联系人 c->s 9138 -
9138 联系人列表 s->c - -
9139 发消息 c->s 9140 -
9140 消息发送成功回包 c->s -
9150 战绩列表 c->s 成功回战绩列表回包,失败通用回包
9151 战绩列表回包 s->c -
9152 战绩详情 c->s 成功回战绩详情回包,失败通用回包
9153 战绩详情回包 s->c -
9154 战绩详情回放 c->s 成功回战绩详情回放回包,失败通用回包
9155 战绩详情回放回包 s->c -
9156 搜索用户 c->s 成功回搜索用户回包,失败通用回包
9157 搜索用户回包 s->c
9165 短信提醒 c->s true 通用回包
9175 发起微信支付 c->s true 成功回发起微信支付回包,失败通用回包
9176 发起微信支付回包 s->c
9177 查询微信结果 c->s true 成功回查询微信结果回包,失败回通用回包
9178 查询微信结果回包 s->c
9180 查询在线支付是否可用 c->s true 返回在线支付是否可用
9181 返回在线支付是否可用 s->c
9182 请求在线信息 c->s true 成功回请求在线信息回包, 失败回通用回包
9183 请求在线信息回包 s->c
9184 用户设置地区ID c->s true 成功失败回通用回包
9189 游戏入口列表 c->s true 成功游戏入口列表回包,失败通用回包
9190 游戏入口列表回包 s->c
9191 进入游戏某场次 c->s true 成功进入游戏某场次回包,失败通用回包
9192 进入游戏某场次回包 s->c
9193 游戏邀请 c->s true 成功回游戏邀请回包,失败通用回包
9194 游戏邀请回包 s->c

PB结构定义

游戏邀请

syntax = "proto3";

package event;

// 游戏邀请请求
message EventGameInvite { // IRequest 9193
    // 邀请人id
    int32 uId = 1;
}

游戏邀请回包

// 游戏邀请回包
message EventGameInviteReturn { // IResponse 9194
    // 房间IP
    string ip =1;
    // 房间端口
    int32 port =2;
    // 游戏房间号
    int32 roomId   =3;
    // 玩法Id
    int32 playId =4;
    // 玩法场次级别
    int32 playGrade =5;
    // 房间密码(如果为空,则无密码,否则有密码,是VIP房间)
    string pwd = 6;
    // 邀请人id
    int32 uId = 7;
    // 邀请人昵称
    string nickName = 8;
}

用户设置地区ID

message EventSetArea { // IRequest 9184
 // 地区ID, 值在『游戏定义』里
 int32 areaId = 1;
}

请求在线信息

syntax = "proto3";
package event;
// 请求在线信息
message EventOnlineInfo { // IRequest 9182
}

请求在线信息回包

syntax = "proto3";
package event;
// 请求在线信息回包
message EventOnlineInfoReturn { // IResponse 9183
    // 玩家人数
    int32 onlinePlayers = 1;
}

查询在线支付是否可用

syntax = "proto3";
package event;

// 查询在线支付是否可用
message EventOnlinePayValid { // IRequest 9180
}

返回在线支付是否可用

// 返回在线支付是否可用
message EventOnlinePayResponse { // IResponse 9181
    message Valid {
        // 1-微信H5支付 2-微信App支付 3-支付宝H5支付
        int32 kind = 1;
        // 0-不可用 1-可用
        int32 status = 2;
    }
    repeated Valid list = 1[packed = false];
}

查询微信结果回包

// 查询微信结果回包
message EventWXAPPPayReturn { // IResponse 9178
    // 订单号
    string orderId = 1;
    // 用户的总余额(单位:元)
    double allAccount = 2;
    // 用户充值的金额(单位:元)
    double payMoney = 3;
    // 充值时间
    int64 payTime = 4;
}

查询微信结果

// 查询微信结果
message EventWXAPPPayQuery { // IRequest 9177
    // 订单ID
    string orderId = 1;
}

发起微信支付回包

// 发起微信支付请求
message EventWXAppPrePay { // IResponse 9176
    string appid = 1;
    string partnerid = 2;
    string prepayid = 3;
    string package = 4;
    string noncestr = 5;
    string timestamp = 6;
    string sign = 7;
    // 商户的订单ID,用户查询支付结果
    string orderId = 8;
}

发起微信支付

// 发起微信支付请求
message EventWXAPPPay { // IRequest 9175
    // 充值金额
    int32 money = 1;
}

短信提醒

syntax = "proto3";
package event;
// 短信提醒
message EventSmsNotice { // IRequest 9165
    // 用户id
    int32  uid = 1;
}

消息发送成功回包

syntax = "proto3";
package event;
// 消息发送成功回包
message EventSendSuccess { // IResponse 9140
    PBReceiveMessageBody body = 1;
}

发消息

syntax = "proto3";
package event;
// 发送的消息体
message PBSendMessaBody {
    // 消息内容
    string msg = 1;
    // 消息类型 0-纯文本,1-图片,2-语音
    int32 mType = 2;
}

// 发消息
message EventSendMsg { // IRequest 9139
    // 消息
    PBSendMessaBody body = 1;
    // 接收者
    int32 uid = 2;
    // 是否为内存转发的消息(客户端忽略该字段)
    bool isForwardMsg = 3;
    // 是否是第一次发消息
    bool isFirst = 4;
}

联系人列表

syntax = "proto3";
package event;
// 联系人列表
message EventFriendList { // IResponse 9138
    repeated PBBaseUser list = 1[packed = false];
    // 是否是搜索出来的(true-是,false-否)
    bool isSearch = 2;
}

查询联系人

syntax = "proto3";
package event;

// 查询联系人
message EventSearchFriend { // IRequest 9137
    // 关键字, 查全部时为空
    string keyWord = 1;
}

新消息

syntax = "proto3";
package event;
// 接收的消息体
message PBReceiveMessageBody {
    // 发送者的用户
    PBBaseUser user = 1;
    // 消息内容
    string msg = 2;
    // 发送时的时间
    int64 sendTime = 3;
    // 消息类型 0-纯文本,1-图片,2-语音
    int32 mType = 4;
    // 接收者ID
    PBBaseUser receiveUser = 5;
}

// 用户基础信息
message PBBaseUser {
    int32 uid = 1;
    string nickname = 2;
    string headURL = 3;
    string phone = 4;
    // 最近玩的游戏ID 0-表示没有最近游戏,大于0的表示游戏ID(查wiki)
    int32 playerId = 5;
    // 玩家的地区ID
    int32 areaId = 6;
}

// 接收的新消息
message EventNewMessage { // IResponse 9136
    // 消息列表
    repeated PBReceiveMessageBody list = 1[packed = false];
}

用户信息

syntax = "proto3";
package event;
// 用户的房间信息
message PBRoom {
    // 用户ID
    int32 uid = 1;
    // 房间IP
    string ip = 2;
    // 房间端口
    int32 port = 3;
    // 游戏房间号
    int32 roomId = 4;
    // 玩法Id
    int32 playId = 5;
}

// 用户登录后的用户各种信息
message PBUserInfo {
    // 用户ID
    int32 uid = 1;
    // 用户房间(如果在房间里)
    PBRoom room = 2;
    // 用户的社交消息
    EventNewMessage socialMessage = 3;
    // 用户在房间里时的聊天消息
    EventGameNewMessage gameMessage = 4;
    // 用户头像
    string headURL = 5;
    // 用户地区ID
    int32 areaId = 6;
}

游戏内最新消息

syntax = "proto3";
package event;
// 游戏内转发消息
message EventGameNewMessage { // IResponse 9134
    message Message {
        // 发送者
        int32 uid = 1;
        // 发送时间
        int64 sTime = 2;
        // 消息类型 0-纯文本,1-图片,2-语音,3-快捷语
        int32 mType = 3;
        // 消息内容
        string msg = 4;
        // 游戏房间号
        int32 roomId = 5;
    }

    repeated Message list = 1[packed = false];
}

游戏内发消息

syntax = "proto3";
package event;
// 游戏内发送消息
message EventGameSendMessage { // IRequest 9133
    // 接收者
    int32 uid = 1;
    // 消息类型 0-纯文本,1-图片,2-语音,3-快捷语
    int32 mType = 2;
    // 消息内容
    string msg = 3;
    // 游戏房间号
    int32 roomId = 4;
    // 是否为内部转发的消息(客户端忽略该字段)
    bool isForwardMsg = 5;
}

进入游戏某场次

syntax = "proto3";
package event;
// 进入游戏某场次
message EventGameGoldIn { // IRequest 9191
    // 游戏id
    int32 gameId = 1;
    // 场次级别
    int32 grade = 2;
}

进入游戏某场次回包

syntax = "proto3";
package event;
// 进入某场次回包
message EventGameGoldReturn { // IResponse 9192
    // 底分
    int32 baseScore = 1;
    // 准入分
    int32 entryScore = 2;
    // 场次级别
    int32 grade = 3;
    // ip
    string ip = 4;
    // 端口
    int32 port = 5;
    // 游戏id
    int32 gameId = 6;
}

游戏入口列表

syntax = "proto3";
package event;
message EventGameGoldSceneRequest { // IRequest 9189
    // 游戏id
    int32 gameId = 1;
}

游戏入口列表回包

syntax = "proto3";
package event;
message EventGameGoldSceneList { // IResponse 9190
    message Scene {
        // 底分
        int32 baseScore = 1;
        // 准入分
        int32 entryScore = 2;
        // 场次级别
        int32 grade = 3;
    }

    repeated Scene list = 1[packed = false];
    // 游戏id
    int32 gameId = 2;
}

生成验证码

根据phone+gcode生成随机4位数的验证码 生成的验证码写入redis 然后短信发送给注册phone 有效期5分钟,验证成功后失效,5分钟未验证均为失效

    syntax = "proto3";
    package event;
    message EventVCode {
        //用户id
        string  phone          = 1;
        //国家编号
        string gcode     = 2;
    //客户端校验 md5(phone + gcode + secret_key) 服务端和客户端约定secret_key
    string secretString    = 3;
    }

通用回包

    syntax = "proto3";
    package event;
    message EventReturn {
        //事件ID
        int32     eventId         = 1;
        //返回码 9100--表示成功  其它的为错误
        int32     code            = 2;
        //描述
        string    message         = 3;
    }

注册

  1. 先到redis验证vcode的有效性
  2. 然后直接入数据库,phone+gcode唯一
    syntax = "proto3";
    package event;
    message EventRegister {
        //手机号
        string  phone          = 1;
        //国家编号
        string  gcode          = 2;
        //用户验证码
        string vcode     = 3;
        //用户登录密码
        string pwd    = 4;
    //客户端校验 md5(phone + gcode + vcode + pwd  + secret_key) 服务端和客户端约定secret_key
    string secretString    = 5;
    }

登录

  1. 先验证secretString的合法性
  2. 到redis验证token,验证成功后不需要验证用户名和密码;
  3. 失败则验证phone+gcode和pwd,然后生成token,写入redis.
    syntax = "proto3";
    package event;
    message EventPublicLogin {
        //手机号
        string  phone          = 1;
        //用户登录标识
        string token     = 2;
        //国家编号
        string gcode     = 3;
        //用户登录密码
        string pwd    = 4;
       //客户端校验 md5(phone + token + gcode + pwd + vcode + secret_key) 服务端和客户端约定secret_key
  string secretString    = 5;
  //用户验证码
  string vcode     = 6;
  // 极光推送的注册ID
  string registrationID = 7;
    }

登录回包

    syntax = "proto3";
    package event;
 
 // 新人引导微信群
message WeiXinGroup {
    // 区域交流群-崇仁
    string chongRenCopy = 1;
    // 区域交流群-乐安
    string leAnCopy = 2;
    // 区域交流群-宜黄
    string yiHuangCopy = 3;
    // 游戏交流群-崇仁打盾
    string chongRenScroll = 4;
    // 游戏交流群-乐安打盾
    string leAnScroll = 5;
    // 游戏交流群-宜黄红心5
    string yiHuangScroll = 6;
    // 区域交流群-东乡
    string dongxiangCopy = 7;
    // 区域交流群-临川
    string linchuangCopy = 8;
    // 官方交流群
    string governmentCopy = 9;
}

   message EventPublicLoginReturn { // IResponse 9104
    //返回码 0--表示成功  其它的为错误
    int32     code            = 1;
    //描述
    string    message         = 2;
    //token
    string    token         = 3;
    //用户id
    int32    uid         = 4;
    // 用户信息
    PBUserInfo userInfo = 5;
 //上传图像网址
    string    uploadImgUrl         = 6;
  // 用户昵称
    string nickname = 7;
    //推广注册网址
    string    registerUrl         = 8;
 // 微信h5支付网址
    string    weixinPayUrl         = 9;
    // 在线玩家数
    int32 onlinePlayers = 10;
    // 新人引导微信群
    WeiXinGroup group = 11;
}

心跳

 syntax = "proto3";
 package event;
 // 心跳保持
 message EventHeartBeat{
 }

查询用户信息

根据uid从数据库表user查询用户昵称,头像手机号,绑定的银行卡号,支付宝号,微信号 等信息

    syntax = "proto3";
    package event;
    message EventGetUser {
    }

查询用户信息回包

    syntax = "proto3";
    package event;
    message EventGetUserReturn {
        //用户id
        int32     uid            = 1;
        //手机号
        string     phone            = 2;
        //国家编号
        string     gcode         = 3;
        //昵称
        string    nickname         = 4;
        //游戏币数(单位/分)
        int64    account         = 5;
        //微信号
        string    wxid         = 6;
        //支付宝号
        string    alipayid          = 7;
        //银行卡号
        string    bankid         = 8;
        //银行名称
        string    bankname         = 9;
        //支行名称
        string    bankbranch         = 10;
        //头像标示 存储在客户端
        string    userimg         = 11;
        //推荐人
        int32    refereeid         = 12;
  //银行帐号姓名
        string    bankusername         = 13;
  //银行省份
     string    bankprovince         = 14;
     //银行城市
     string    bankcity         = 15;
  // 性别,0-没设置,1-男性,2-女性
     int32    sex         = 16;
    }

设置用户信息

    syntax = "proto3";
    package event;
    message EventSetUser {
        //昵称
        string    nickname         = 1;
        //微信号
        string    wxid         = 2;
        //支付宝号
        string    alipayid          = 3;
        //银行卡号
        string    bankid         = 4;
        //银行名称
        string    bankname         = 5;
        //支行名称
        string    bankbranch         = 6;
        //头像标示
        string    userimg         = 7;
  //推荐人
        int32    refereeid         = 8;
  //银行帐号姓名
        string    bankusername         = 9;
  //银行省份
     string    bankprovince         = 10;
     //银行城市
     string    bankcity         = 11;
  // 性别,0-没设置,1-男性,2-女性
     int32    sex         = 12;
  // 地区ID
    int32 areaId = 13;
    }

用户退出

服务器删除token,tcp链接断开

    syntax = "proto3";
    package event;
    message EventLoginout {
    }

客服

    syntax = "proto3";
    package event;
    message EventCustomService {
 }

客服回包

    syntax = "proto3";
    package event;
    message EventCustomServiceReturn {
  // 微信客服
  repeated string   weixin = 1[packed = false];
  // qq客服
  repeated string   qq  = 2[packed = false];
 }

充值列表

    syntax = "proto3";
 package event;

 message EventRechargeList {// IRequest 9123
  // 页码,第一页为0,第二页为1,以此类推
  int32 pageIndex = 1;
  // 页大小
  int32 pageSize = 2;
 }

充值列表回包

    syntax = "proto3";
 package event;

 message EventRechargeListReturn {// IResponse 9124
  // 充值项
  repeated PBRechargeItem   items = 1[packed = false];
  // 分页是否结束
  bool isPageEnd = 2;
 }

 // 充值项
 message PBRechargeItem {
  // 金额,单位(分)
  int64  account = 1;
  // 时间(精确到秒)
  int32 unixTime = 2;
 }

公告列表

    syntax = "proto3";
 package event;

 message EventNoticeList {// IRequest 9127
 }

公告列表回包

    syntax = "proto3";
 package event;

 message EventNoticeListReturn {// IResponse 9128
  // 公告项
  repeated PBNoticeItem   items = 1[packed = false];
 }

 // 公告项
 message PBNoticeItem {
  // 内容
  string  content = 1;
  // 类型,7:官方声明,8:玩家须知,9:兑换说明
  int32 type = 2;
  // 时间(精确到秒)
  int32 unixTime = 3;
 }

战绩列表

    syntax = "proto3";
 package event;

 // 战绩列表
 message EventArchiveList { // IRequest 9150
  // 页码, 第一页为0,第二页为1,以此类推
  int32 pageIndex = 1;
  // 页大小
  int32 pageSize = 2;
 }

战绩列表回包

    syntax = "proto3";
 package event;

 // 战绩列表回包
 message EventArchiveListReturn { // IResponse 9151
  // 战绩项
  repeated PBArchiveItem  items = 1[packed = false];
  // 分页是否结束
  bool isPageEnd = 2;
 }

 // 战绩项
 message PBArchiveItem {
  // 战绩id
  int32 id = 1;
  // 房间id
  int32 roomId = 2;
  // 游戏名称
  string playName = 3;
  // 游戏局数
  int32 playNum = 4;
  // 游戏等级描述
  string playGrade = 5;
  // 结算时间(unix时间戳,精确到秒)
  int64 settlementTime = 7;
  // 玩家列表
  repeated PBArchivePlayer players = 8;
  // 游戏前游戏币数,(精确到分)
  int64 StartCoins = 9;
  // 游戏后游戏币数,(精确到分)
  int64 EndCoins = 10;
  // 游戏Id
     int32 playId = 11;
 }

 // 战绩玩家
 message PBArchivePlayer {
  // 玩家id
  int32 id = 1;
  // 玩家昵称
  string nickName = 2;
  // 积份(有正负)
  int32 score = 3;
 }

战绩详情

    syntax = "proto3";
 package event;

 // 战绩详情
 message EventArchiveDetail { // IRequest 9152
  // 战绩id
  int32 id = 1;
 }

战绩详情回包

    syntax = "proto3";
 package event;

 // 战绩详情回包
 message EventArchiveDetailReturn { // IResponse 9153
  // 战绩id
  int32 id = 1;
  // 房间id
  int32 roomId = 2;
  // 游戏名称
  string playName = 3;
  // 游戏局数
  int32 playNum = 4;
  // 战绩详情项
  repeated PBArchiveDetailItem  items = 5[packed = false];
 }

 // 战绩详情项
 message PBArchiveDetailItem {
  // 战绩详情id
  int32 id = 1;
  // 游戏局数
  int32 playNum = 2;
  // 结算时间(unix时间戳,精确到秒)
  int64 settlementTime = 3;
  // 玩家列表
  repeated PBArchivePlayer players = 4;
 }

战绩详情回放

    syntax = "proto3";
 package event;

 // 战绩详情回放
 message EventArchiveDetailRecord { // IRequest 9154
  // 战绩详情id
  int32 id = 1;
 }

战绩详情回放回包

    syntax = "proto3";
 package event;
 
    message PBReplayCell {
        //对应的事件ID
        int32 eventId           = 1;
        //事件对应序列化后的proto内容
        bytes eventData     = 2;
    }
 
    //回放
    message PBReplay {
        repeated PBReplayCell cells = 1[packed = false];
    }

 // 战绩详情回放回包
 message EventArchiveDetailRecordReturn { // IResponse 9155
  // 战绩详情id
  int32 id = 1;
  // 回放字节流(PBReplay消息序列化后)
  bytes record = 2;
 }

上传图片接口

采用http协议,POST方法,url是[登陆成功回包]中UploadImgUrl字段 回包是json格式,详情见内容

type HeadImgReturn struct {
 // 成功为0,其他都是错误
 Code int32
 // 成功:文件上传后的url,错误:出错原因
 Msg  string
}

// POST方法, multipart/form-data
// 参数名:token,值:用户登录标识
// 参数名:secretString,值:md5(token + secret_key),secret_key是服务端和客户端约定
// 参数名:file,value:二进制字节流
// 返回json(HeadImgReturn)

搜索用户

syntax = "proto3";
package event;

// 查询指定用户
message EventSearchUser { // IRequest 9156
    // 目标用户id
    int32 uId = 1;
}

搜索用户回包

syntax = "proto3";
package event;

// 查询指定用户回包
message EventSearchUserReturn { // IRequest 9157
    // 目标用户id
    int32 uId = 1;
    // 目标用户昵称
    string nickName = 2;
}

redis结构


验证码


说明:加vcode:或vcodeday:前缀,防和其他键值冲突

Type: string
Name: vcode:gcode+phone
Value: vcode
TTL: 5分钟


Type: string
Name: vcodeday:gcode+phone
Value: 次数(暂时最多10次)
TTL: 一天

登陆


说明:加login:前缀,防和其他键值冲突

Type: string
Name: login:token
Value: uid

在线人数


说明:每次玩家登陆或退出都会更新

Type: string
Name: public_player_count
Value: 在线人数