{"id":25016402,"url":"https://github.com/jxy918/swoole-game-framework","last_synced_at":"2025-04-13T00:35:35.848Z","repository":{"id":57003544,"uuid":"203518512","full_name":"jxy918/swoole-game-framework","owner":"jxy918","description":"swoole 游戏开发框架使用范例","archived":false,"fork":false,"pushed_at":"2019-10-24T08:49:12.000Z","size":307,"stargazers_count":8,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T00:35:27.580Z","etag":null,"topics":["h5game","php","swoft","swoole","swoole-game"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jxy918.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-21T06:12:29.000Z","updated_at":"2024-04-10T03:44:48.000Z","dependencies_parsed_at":"2022-08-21T12:10:51.199Z","dependency_job_id":null,"html_url":"https://github.com/jxy918/swoole-game-framework","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxy918%2Fswoole-game-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxy918%2Fswoole-game-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxy918%2Fswoole-game-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxy918%2Fswoole-game-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jxy918","download_url":"https://codeload.github.com/jxy918/swoole-game-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650452,"owners_count":21139671,"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":["h5game","php","swoft","swoole","swoole-game"],"created_at":"2025-02-05T09:29:26.220Z","updated_at":"2025-04-13T00:35:35.821Z","avatar_url":"https://github.com/jxy918.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swoole-game-framework\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/jxy918/swoole-game-framework.svg)](https://packagist.org/packages/jxy918/swoole-game-framework)\n[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/)\n[![Swoft Doc](https://img.shields.io/badge/docs-passing-green.svg?maxAge=2592000)](https://www.swoft.org/docs)\n\n* 基于Swoole扩展开游戏服务器框架\n* 基于 **[swoole-game](https://github.com/jxy918/swoole-game)** 框架怎么安装使用\n* 基于swoft框架实现的另一版本：**[swoft-game](https://github.com/jxy918/swoft-game)**\n* 想关注更多游戏开发可以关注swoft-ddz斗地主：**[swoft-ddz](https://github.com/jxy918/swoft-ddz)**\n\n### 一，概述\n\n* 该框架主要用于开发游戏服务器，简化游戏前后端开发，框架主要实现了前后端，封包解包，协议解析，压缩，粘包，路由等功能，代码示例为h5游戏。\n* 框架比较简单, 几乎不依赖外部源码库, 方便阅读和使用。\n* 基本实现框架功能, 框架组件还不完善, 自己用到什么组件可以方便集成进来。 \n\n### 二，环境依赖\n\n\u003e需要支持高版本swoole, 环境可以自行编译, 为了方便大家使用, 可以使用根目录提供的Dockerfile文件构建环境\n    \n* php 7.1及以上  \n* swoole 1.9以上版本\n* msgpack \n* protobuf 选择使用\n\n### 三,安装和使用\n\n```\ncomposer install\n```\n \n\n### 四，特性\n\n* 对websocket,http,tcp协议进行封装，异步处理任务\n* 实现前后端二进制封包解包，采用的是msgpack扩展，msgpack对数据进行了压缩，并实现粘包处理, 服务器加入了protobuf支付，tcp有测试例子\n* 数据采用固定包头，包头4个字节存包体长度，包体前2个字节分别为cmd(主命令字)，scmd(子命令字)，后面为包体内容\n* 采用策略模式解耦游戏中的每个协议逻辑\n* 实现定义游戏开发cmd(主命令字)和scmd(子命令字)定义，cmd和scmd主要用来路由到游戏协议逻辑处理\n* 代码里有个JokerPoker类是一个款小游戏算法类，是一个示例，如示例图1,2,3,4\n* 代码主要是用框架实现小游戏JokerPoker例子，服务端代码开源，客户端代码暂不开源，但是提供客户端交互测试工具，见示例图5。\n* 可以方便的把JokerPoker范例去除，只使用框架功能定制开发开发自己的游戏功能\n\n\n\u003e 备注：注意此范例数字都是默认值， 未用到存储， 运行不需要数据库，数据库配置只是测试操作数据库用\n   \n### 五，开始使用\n\n\n* 2，目录说明：\n\n```\nsrc/bin 服务启动目录\nsrc/app 游戏协议逻辑处理代码\nsrc/conf 相关配置目录\n./log  日志目录\n./client 客户端交互测试工具\n``` \n         \n* 3，进入bin目录，启动服务器 ：\n\n```\n./game  start   启动服务 \n./game  stop    关闭服务 \n./game  reload   服务重载， 优雅载入， 不需要启动服务， 可以载入所修改的逻辑\n\n``` \n\n\u003e也可以直接用php命令行启动, 但是请确认启动之前， 杀死所有相关进程\n\n```\nphp run.php\n\n``` \n\n* 4，如果开启http服务器，其实websocket和http是同时开启的， 如果不想混在一起可以单独开启监听端口，http测试例子代码如下浏览器访问：\n\n```\nhttp://[ip]:[port]/HttpTest?aaa=bbb\u0026ccc=ddd\n\n```\n\n* 5，如果开启了tcp服务器，测试例子在client目录下， 注意例子采用了protobuf，请安装，也可以改成msgpack，请自行修改\nphp执行一下就可以看到结果：\n\n```\nphp tcp_client.php\n\n```\n\n* 6 ，H5游戏客户端代码由于公司限制，暂不开放， 但是提供了一个客户端交互测试工具，直接把client目录放入web服务器， 修改客服端配置文件配置websocket链接就能运行。\n\n\n### 六，示例图\n\n![游戏demo1](images/demo1.jpg)\n![游戏demo2](images/demo2.jpg)\n![游戏demo3](images/demo3.png)\n![游戏demo4](images/demo4.jpg)\n![客户端交互测试工具](images/demo5.png)    \n\n### 七，联系方式\n\n* qq：251413215, 加qq请输入验证消息：swoole-game\n\n### 八，备注\n\n* 根目录增加docker运行环境(Dockerfile)， 可以直接执行下面的命令，创建镜像php_swoole, 环境增加php-protobuf支持 \n\n```\ndocker build -t php_swoole .\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjxy918%2Fswoole-game-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjxy918%2Fswoole-game-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjxy918%2Fswoole-game-framework/lists"}