v2.4.3_石剪布
<p>[TOC]</p>
<h1>公共定义</h1>
<pre><code>// 手势形状枚举
const (
FINGER_shape_O = "O" // 石
FINGER_shape_Y = "Y" // 剪
FINGER_shape_W = "W" // 布
)
// 游戏状态枚举
type EFingerState int //
const (
EFingerS_Init EFingerState = 1 // 已创建
EFingerS_Play = 2 // 游戏中
EFingerS_Done = 3 // 已完成
EFingerS_Anew = 4 // 协商中
EFingerS_Over = 5 // 结束
)
type JoinPlayer struct {
UserId string `json:"user_id"`
Name string `json:"name"` // 昵称
Photo *Photo `json:"photo,omitempty"` // 头像
Vip bool `json:"vip"` //
CoinLv int `json:"coinlv"` // 财富等级
CharmLv int `json:"charmlv"` // 魅力值
VipLvl int `json:"viplvl"` // vip等级
JoinAt int64 `json:"join_at"` // 加入时间
}
// 游戏表结构
type Finger struct {
Id int64 `json:"id"`
Ante int32 `json:"ante" xorm:"notnull default 0"` // 赌注(金豆)
Winer int64 `json:"winer" xorm:"notnull index default 0"` // 胜利者
Loser int64 `json:"loser" xorm:"notnull index default 0"` // 失败者
Result EFingerResult `json:"result" xorm:"notnull default 0"` // 对局结果
State EFingerState `json:"state" xorm:"notnull default 1"` // 本局状态
Hold int32 `json:"hold" xorm:"notnull default 0"` // 连胜数
Roboter int64 `json:"roboter" xorm:"notnull default 0"` // 机器人Id
Detail []string `json:"detail" xorm:"json"` // 明细
CreatedAt int64 `json:"at" xorm:"notnull"`
}
func (this *Finger) TableName() string { return "game_finger" }</code></pre>
<h1>游戏信息</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">/v1/room/fingerInfo</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code class="language-go">// 入参 无
// 出参
type FingerInfo struct {
Ante int32 `json:"ante"` // 赌注[配置字段]
StageDurt int32 `json:"durt"` // 每阶段时间[配置字段]
BoutId int64 `json:"boutId"` // 当前对局Id(如果非0则表示当前有未结束的对局,需要跟着调用fingerDxxw接口)
BoutCount int32 `json:"boutCount"` // 游戏局数
TieCount int32 `json:"tieCount"` // 平场
WinCount int32 `json:"winCount"` // 胜场
WinRate string `json:"winRate"` // 胜率
WinHold int32 `json:"winHold"` // 最高连胜次数
Queued int32 `json:"queued"` // 是否在队列中
}</code></pre>
<h1>游戏状态</h1>
<p><em>断线续玩时用于恢复游戏状态</em></p>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">/v1/room/fingerDxxw</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code>// 入参
boutId int64 // 对局id
// 出参
type Finger struct {
BoutId int64 `json:"BoutId"` // 对局Id
Ante int32 `json:"ante"` // 赌注
Players []*JoinPlayer `json:"players"` // 成员
Stage int32 `json:"stage"` // 当前这一把(共3把)
StageAt int64 `json:"stageAt"` // 当前这一把的开始时间
StageRemain int32 `json:"stageRemain"` // 当前这一把的剩余时间(s)
Shapes []string `json:"shapes"` // 当前这一把成员手指形状
Rebouter int64 `json:"rebouter"` // 发起再战的用户
State int32 `json:"state"` // 状态(参见枚举)
CreatedAt int64 `json:"at"` // 游戏开始时间
Records []*FingerStageRecord `json:"records,omitempty"` // 对把记录(当没数据时,此字段不存在)
}
type FingerStageRecord struct {
Stage int32 `json:"stage"` // 第几把(共三把,从1开始)
StageAt int64 `json:"stageAt"` // 第几把开始时间
Shapes []string `json:"fingers"` // 成员手指形状
Winer int64 `json:"winer"` // 谁赢
}</code></pre>
<h1>游戏匹配</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">/v1/room/fingerMatch</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code class="language-go">// 入参
boutId int // 如果是结果页 换个对手时 则把当前对局的id赋值
// 出参
ok bool
货币不足: CCY_LOW</code></pre>
<h1>离开游戏</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">/v1/room/fingerLeave</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code class="language-go">// 入参 无
boutId int64
// 出参
ok bool</code></pre>
<h1>选择手势</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">/v1/room/fingerAction</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code class="language-go">// 入参
boutId int64 // 对局ID
shape string // 手形 仅限于枚举内定义的
// 出参
bool ok </code></pre>
<h1>请求再战</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">/v1/room/fingerRebout</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code class="language-go">// 入参 无
boutId int64 // 对局ID
// 出参
当返回err为: NIL_RETURN 时,客户端自行返回首页或者什么都不做(容错处理)
</code></pre>
<h1>应答再战</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">/v1/room/fingerConfirm</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code class="language-go">// 入参 无
boutId int64 // 对局ID
// 出参
当返回err为: NIL_RETURN,客户端自行返回首页或者什么都不做(容错处理)</code></pre>
<h1>推送-本局最终结果</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">tcp_pushId = -501</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code>tcp_pushId = -501
struct {
BoutId int64 `json:"boutId"` //
State int32 `json:"state"` // 当前局状态
Winner string `json:"winner"` // 本局谁赢
Hold int32 `json:"hold"` // 当前连胜
Score string `json:"score"` // 比分
Remain int `json:"remain"` // 协商时间[用做配置]
}</code></pre>
<h1>推送-本局阶段结果</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">tcp_pushId = -502</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code>tcp_pushId = -502
struct {
BoutId int64 `json:"boutId"` //
Stage int32 `json:"stage"` // 当前这一把(共3把)
PlayerIds []string `json:"playerIds"` // 当前这一把成员Ids
Shapes []string `json:"shapes"` // 当前这一把成员手指形状
Winner string `json:"winner"` // 当前这一把谁赢(空:表示平)
}</code></pre>
<h1>推送-用户离开事件</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">tcp_pushId = -503</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code>tcp_pushId = -503
struct {
BoutId int64 `json:"boutId"` //
PlayerId string `json:"playerId"`
Losed bool `json:"losed"` // 是否投降
}</code></pre>
<h1>推送-游戏匹配完成</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">tcp_pushId = -504</td>
<td style="text-align: left;">无</td>
</tr>
</tbody>
</table>
<pre><code>tcp_pushId = -504
struct {
BoutId int64 `json:"boutId"` //
Players []*proto.JoinPlayer `json:"players"` // 成员
Stage int32 `json:"stage"` // 当前这一把(共3把)
StageAt int64 `json:"stageAt"` // 当前这一把的开始时间
StageRemain int32 `json:"stageRemain"` // 当前这一把的剩余时间(s)
State int32 `json:"state"` // 状态(参见枚举)
}</code></pre>
<h1>推送-用户出拳事件</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">tcp_pushId = -505</td>
<td style="text-align: left;">此推送, 对局双方都会收到</td>
</tr>
</tbody>
</table>
<pre><code>tcp_pushId = -505
struct {
BoutId int64 `json:"boutId"` //
PlayerId string `json:"playerId"`
}</code></pre>
<h1>推送-用户请求再战事件</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">tcp_pushId = -506</td>
<td style="text-align: left;">只推送对方</td>
</tr>
</tbody>
</table>
<pre><code>tcp_pushId = -506
struct {
BoutId int64 `json:"boutId"` //
PlayerId string `json:"playerId"`
}</code></pre>
<h1>推送-通知本局解散结束</h1>
<table>
<thead>
<tr>
<th style="text-align: left;">接口名</th>
<th style="text-align: left;">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">tcp_pushId = -507</td>
<td style="text-align: left;"></td>
</tr>
</tbody>
</table>
<pre><code>tcp_pushId = -507
struct {
BoutId int64 `json:"boutId"` //
}</code></pre>