Backend Server === # 架構 ![workflow](https://i.imgur.com/cC5c1qU.png) :::info - **Gateway:** 1. 用於與Frontend建立長連接、心跳檢測、配發牌桌等功能 2. 透過websocket與客戶端建立通信 3. MQTT通訊協定,與Frontend發送訊息 4. Frontend請求的路由工作 - **Game Server:** 1. 創建玩家模組提供給玩家加入 2. 建構遊戲邏輯並管理該模塊生命週期 3. 加入暫存器機制分批處理模塊接收動作 ::: ## 細部架構及框架說明 ![後端技術框架結構](https://i.imgur.com/Vg86eiZ.png) --- # Client & Server 交互流程 ```sequence participant Client Client->Gateway: HD_Login \n 玩家登入 Gateway->Client: 返回登入結果 Client->GameServer: HD_JoinRoom\n加入列隊 GameServer->Client: 返回結果 Note over Gateway: 執行配桌動作\n step1.Player/Matching\n step2.Create Table\n step3.Sitdown\n step4.Create Bot\n GameServer->Bot: RPC通知Bot模組\n創建陪打機器人 ``` ---- ```sequence GameServer->Client: 告知玩家GameServer節點編號 GameServer->Client: 告知玩家已經坐下 Note over Client,GameServer: 按遊戲流程持續動作\n... GameServer->Client: 推播牌局結算封包 Client->GameServer: 退出牌桌 Client --> Gateway: Disconnect ``` --- # Server & Bot 交互流程 ```sequence participant GameServer GameServer->Redis: LPUSH Bot Info to Redis Bot->Redis: 找尋等待被創建的 bot_account_list Redis->Bot: 返回搜尋結果 Note over Bot,Redis: 不斷嘗試直到取到資料為止 Note right of Bot: step1.建立新執行緒\nstep2.建構Bot\nstep3.初始化Bot\nstep4.開始演出腳本 ``` ---- ```sequence Bot->Gateway: HD_BotLogin\nBot專屬登入通道 Bot->GameServer: HD_AIPlayerGetTable\nBot專屬配桌方式 Bot->GameServer: 按遊戲流程持續動作... GameServer->Bot: 按遊戲流程持續動作... GameServer->Bot: {GameName}/OnSettlement\n推播牌局結算封包 Bot->GameServer: HD_Exit\nBot退出牌桌 Note right of Bot: step1.中斷連線\nstep2.停止演出腳本\nstep3.結束執行緒 ``` --- # 第三方套件 - [Nats](https://github.com/nats-io/go-nats) - [Consul](http://18.162.104.206:8500/ui/ke-dc/services) - [kibana](https://www.elastic.co/cn/products/kibana) ---- # gRPC ![gRPC](https://i.imgur.com/V5IC473.png) --- ### Consul ![Consul](https://i.imgur.com/nxTzRlf.png) ![Consul connect](https://www.datocms-assets.com/2885/1529562862-segmentationafter.gif) ![VPC](https://i.imgur.com/4sk0Glx.png) --- ###### tags: `HonorServer` `Documentation`