{"id":20734403,"url":"https://github.com/byebyebruce/lockstepserver","last_synced_at":"2025-04-05T17:04:30.361Z","repository":{"id":37711989,"uuid":"150821948","full_name":"byebyebruce/lockstepserver","owner":"byebyebruce","description":"golang版帧同步服务器","archived":false,"fork":false,"pushed_at":"2022-03-17T05:35:18.000Z","size":102,"stargazers_count":389,"open_issues_count":8,"forks_count":127,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-29T16:04:00.588Z","etag":null,"topics":["game","golang","kcp","lockstep","protobuf","pvp","room"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/byebyebruce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-29T03:45:55.000Z","updated_at":"2025-03-27T12:17:38.000Z","dependencies_parsed_at":"2022-07-07T04:01:37.956Z","dependency_job_id":null,"html_url":"https://github.com/byebyebruce/lockstepserver","commit_stats":null,"previous_names":["bailu1901/lockstepserver"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byebyebruce%2Flockstepserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byebyebruce%2Flockstepserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byebyebruce%2Flockstepserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byebyebruce%2Flockstepserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/byebyebruce","download_url":"https://codeload.github.com/byebyebruce/lockstepserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369953,"owners_count":20927928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game","golang","kcp","lockstep","protobuf","pvp","room"],"created_at":"2024-11-17T05:30:25.527Z","updated_at":"2025-04-05T17:04:30.335Z","avatar_url":"https://github.com/byebyebruce.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Lock Step Server\n\n[![GoDoc](https://godoc.org/github.com/byebyebruce/lockstepserver?status.png)](https://godoc.org/github.com/byebyebruce/lockstepserver)\n[![Build Status](https://travis-ci.org/bailu1901/lockstepserver.svg?branch=master)](https://travis-ci.org/byebyebruce/lockstepserver)\n[![Go Report](https://goreportcard.com/badge/github.com/byebyebruce/lockstepserver)](https://goreportcard.com/report/github.com/byebyebruce/lockstepserver)\n\n_**用golang写的帧同步服务器，目标是作为一个可以横向扩展，完全脱离玩法逻辑的帧同步服务器。**_\n\n### 特性\n* 采用KCP(可根据需求改成其他协议)作为网络底层\n* 采用帧同步方式\n* protobuf作为传输协议\n* 支持断线重连\n\n\n### 运行example server\n1. 启动server `go run cmd/example_server/main.go`\n1. 创建房间：\n\t* 方法1. 浏览器打开 http://localhost 点创建\n\t* 方法2. 命令 `sh cmd/example_client/create_room.sh`\n\n### 运行example client\n1. 启动1号客户端 `go run cmd/example_client/main.go -room=1 -id=1`\n1. 启动2号客户端 `go run cmd/example_client/main.go -room=1 -id=2`\n\n### 网络层\n* 初始化网络层，使用的[kcp-go](https://github.com/xtaci/kcp-go)，可以根据需求切换成其他的\n* 消息包格式\n\t```\n\t|-----------------------------message-----------------------------------------|\n\t|----------------------Header------------------|------------Body--------------|\n\t|------Body Length-------|--------Msg ID-------|------------Body--------------|\n\t|---------uint16---------|---------uint8-------|------------bytes-------------|\n\t|-----------2------------|----------1----------|-----------len(Body)----------|\n\t```\n\n### 客户端接入流程  \n[**proto文件**](pb/message.proto)\n\n\t\n* 消息流程  \n\t1. 客户端发送第一个连接的消息包  \n\t\tC-\u003eS: `MSG_Connect \u0026 C2S_ConnectMsg`\n\t1. 服务端给返回连接结果  \n\t\tS-\u003eC: `MSG_Connect \u0026 S2C_ConnectMsg`\n\t1. 如果2返回ok，客户端向服务端发送进入房间消息  \n\t\tC-\u003eS: `MSG_JoinRoom`\n\t1. 服务端返回进入房间消息  \n\t\tS-\u003eC: `MSG_Connect \u0026 S2C_JoinRoomMsg`\n\t1. 客户端这时进入读条，并广播读条进度，其他客户端收到广播读条进度  \n\t\tC-\u003eS: `MSG_Progress \u0026 C2S_ProgressMsg`  \n\t\tS-\u003eC: `MSG_Progress \u0026 S2C_ProgressMsg`  **注：广播者收不到这个消息**\n\t1. 客户端告诉服务端自己已经准备好  \n\t\tC-\u003eS: `MSG_Ready`  \n\t\tS-\u003eC: `MSG_Ready`  \n\t1. 当所有客户端都已经准备好，服务端广播开始  \n\t\tS-\u003eC: `MSG_Start`  \n\t1. 客户端可以进入游戏状态，客户端不停的向服务端发送操作，服务端不停的广播帧数据  \n\t\t∞ C-\u003eS: `MSG_Input \u0026 C2S_InputMsg`  \n\t\t∞ S-\u003eC: `MSG_Frame \u0026 S2C_FrameMsg`  \n\t1. 当客户端游戏逻辑结束告诉服务端自己结束  \n\t\tC-\u003eS: `MSG_Result \u0026 C2S_ResultMsg`  \n\t\tS-\u003eC: `MSG_Result`  \n\t1. 当客户端收到`MSG_Result`或者`MSG_Close`客户端断开网络连接进入其他流程  \n\t\t**注：客户端收到MSG_Result表示服务端已经收到并处理的客户端发来的结果**  \n\t\t**注：客户端收到MSG_Close表示服务端房间已经关闭，客户端如果游戏流程没完也要强制退出**\n\n\n\n### 断线重连\n\n* 客户端只要发 C-\u003eS: `MSG_Connect \u0026 C2S_ConnectMsg` **(前提是当前游戏房间还存在)**即可进入房间，服务端会把之前的帧分批次发给客户端。(这里可以考虑改成客户端请求缺失的帧)\n\n\n\n### 客户端工程\n[https://github.com/byebyebruce/lockstep-client-unity](https://github.com/byebyebruce/lockstep-client-unity)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyebyebruce%2Flockstepserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyebyebruce%2Flockstepserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyebyebruce%2Flockstepserver/lists"}