Golang makes a game server for the landlord [7]: some thoughts on servers and protocols

When a client comes over, it must first verify its own identity (check in its own account system), and after the verification, the data is temporarily stored in the central server

The client enters Doudizhu’s server at this time,  

At this time, the client will first communicate with the Doudizhu server.

" Hello server, what version are you? How many people are there now? "

" I am Doudizhu server, my version is 1.0, I have XX tables in it now. There are XX people "

" Can you tell me about the first 100 tables?"

"The first 100 tables are as follows: 3 people at the first table have started the game, 3 people at the second table, have started the game, .... 1 person at the 50th table, waiting "

" Server, I want to join table XXX/server, can you help me quickly find an empty seat? "

" Okay, it has been arranged for you to do it at table XXX. The situation in table XXX is like this "

" A new player comes in "

" Another new player comes in "

"The game officially starts now "

" Your hand is XXXXX "

" Do you want to call the landlord? "

" Call the landlord "

" The situation of other people grabbing landlords is like this "

"The final landlord is XXX "

"The game has officially started, please play the cards "

" I passed "

" Ok, the cards played by others are "

"The game is over, how much money did you get "

" I want to play/not play anymore "

 

The above is almost all the protocols used in the game

First, we simply define an agreement

The protocol is divided into requests from the client to the server. The server replies to the client, one question and one answer, this structure Request Respone,   and the server actively broadcasts this structure to the client BoardCast

Use pb to simply define a protocol first, golang using json is simply cheating

syntax = "proto2";
package ddzpb;

// 斗地主协议

// "服务器你好, 请问你是什么版本的?  你里面现在大概有多少人?"
message TGetServerInfoReq
{
    // 空包
}

//"我是斗地主服务器,  我的版本是1.0,  我现在里面有XX个桌子. 有XX个人"
message TGetServerInfoRsp
{
    optional string Version     = 1; // 版本号
    optional int32 TableCount   = 2; // 桌子数量
    optional int32 PlayerCount  = 3; // 玩家数量
}



//"可以告诉我前100个桌子的情况吗?"
message TGetTableInfoReq
{
    optional int32 TableFrom = 1; // 从哪个桌子开始
    optional int32 TableCount = 2; // 发送多少个桌子的数据
}

// 桌子的信息
message TTableInfo
{
    optional int32 Status = 1; // 桌子状态, 已经开始, 或者还没开始
    optional int32 PlayerCount = 2; // 里面有多少人
}


// "前100个桌子的情况分别是 : 第1个桌子 3个人已经开始游戏,  第2个桌子3个人, 已经开始游戏,  .... 第50个桌子1个人, 正在等待中"
message TGetTableInfoRsp
{
    optional int32 TableCount = 1;
    repeated TTableInfo TableInfos = 2;
}

//"服务器, 我想加入XXX号桌子 /  服务器, 帮我快速找一个空位座下吧?"
message TJoinTableReq
{
    optional int32 TableIndex = 1;  // 需要加入的桌子编号, 不填就快速加入
}

///"好的, 已经安排你做在XXX号桌子. XXX号桌子里面的情况是这样的"
message TJoinTableRsp
{
    optional string ErrorMsg = 1;
    optional string ErrorCode = 2;

    optional TTableInfo TableInfo = 3;
}

// 玩家信息
message TPlayerInfo
{

}



//"有一个新玩家进来"
// "又有一个新玩家进来"
message TPlayerComeInBc
{
    optional int32 Status = 1;
    optional TPlayerInfo PlayerInfo = 2;
}

//"游戏现在正式开始"
message TGameStartBc
{
    optional int32 Position = 1; // 你的桌位是

}

// "你们的手牌是 XXXXX"
message TDealCardBc
{
    optional int32 CardCount = 1; // 你的手牌数量是
    repeated int32 CardValue = 2; // 手牌的数值是
}

//"请问你要叫地主吗?"
message TCallDZBc
{
    optional int32 DZPosition = 1; // 地主当前的位置
    // 后面可能会加上什么明牌啊,, 或者当前倍数之类的扩展
}

// 叫地主"
message TCallDZReq
{
    optional int32 CallDZ = 1; // 叫地主的结果  1 叫地主  2明牌叫地主  其他不叫
}

// 叫地主的结果..     同时广播其他人叫地主的情况 TCallDZBc
message TCallDZRsp
{
    optional string ErrorMsg = 1;
    optional string ErrorCode = 2;
}


//"游戏正式开始, 请出牌"
message TOutCardBc
{
    optional int32 Position         = 1; // 轮到当前某个位置的玩家进行出牌
    optional int32 StartPosition    = 2; // 本轮开始的玩家的位置
    optional int32 LargePosition    = 3; // 本轮目前最大牌的玩家位置(也就是上一个出过牌的人)
    optional int32 Round            = 4; // 轮次是
    optional int32 Hand             = 5; // 手次是

    optional int32 CardType         = 6; // 已经出的牌的类型是
    optional int32 CardPoint        = 7; // 已经出的牌的点数是

    optional int32 OutCount         = 8; // 上一次出牌的牌的数量
    repeated int32 OutCards         = 9; // 上一次出牌的牌的具体内容
}

// 我过, 我要出对三
message TOutCardReq
{
    optional int32 Status           = 1; // 状态,   其实可以不要
    optional int32 OutCount         = 2; // 上一次出牌的牌的数量
    repeated int32 OutCards         = 3; // 上一次出牌的牌的具体内容
}

// 同时广播其他人叫地主的情况 TCallDZBc
message TOutCardRsp
{
    optional string ErrorMsg    = 1;
    optional string ErrorCode   = 2;
}

// 游戏结束
message TGameOverBc
{
    optional int32 WinnerPosition = 1; // 胜利者的位置
    // 其他的倍数信息


    // 最终卡牌
    message TEndingCard
    {
        optional int32 Position     = 1; // 剩余牌的位置
        optional int32 LeftCount    = 2; // 剩余牌的数量
        optional int32 LeftCards    = 3; // 剩余的卡牌的具体内容
    }

    repeated TEndingCard EndingCards = 7;


    optional int32 OutCount         = 8; // 上一次出牌的牌的数量
    repeated int32 OutCards         = 9; // 上一次出牌的牌的具体内容
}

 

 

 

Guess you like

Origin blog.csdn.net/warrially/article/details/88646740