Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制

thrift官方文档
Apache Thrift - Homehttps://thrift.apache.org/

我的Git仓库
文件 · master · Knight bit / thrift_lesson · GitLab (acwing.com)Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片
https://git.acwing.com/knight/thrift_lesson/-/tree/master


注意:不会事无巨细,只是记录一下大致的流程,感悟
目录
第一天: 实现匹配的客户端(game)和服务端(match_system)
总结:
第一天: 实现匹配的客户端(game)和服务端(match_system)

thrift_lesson/thift/match.thrift
创建两个接口 添加用户add_user和删除用户remove_user

i32 add_user(1: User user, 2: string info), i32 remove_user(1: User user, 2: string info),



实现match_system服务端
thrift_lesson/match_system/src文件夹下
thrift -r --gen cpp ../../thrift/match.thrift


由此自动生成了一些接口相关的代码,非常nice, 真正需要我们实现的是具体业务
Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片


例如:Match_server.skeleton.cpp
Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片

把gen-cpp改名为match_server(因为我们还要实现save_data的client端)
Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片



把Match_server.skeleton.cpp重命名为main.cpp,移到src文件夹下
Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片


先添加返回值(先编译通过再逐步添加)
Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片

记得修改头文件的路径Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片


编译,链接(需要用到thrift的动态链接库,加上-lthrift)
g++ -c main.cpp g++ *.o -o main -lthrift



同理完成game部分(Python),具体代码参见git...


接下来先运行服务端,(我们在main.cpp加入了简单的输出,为了在这里能够直观看出效果)
Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片

然后运行客户端(即游戏), 可见服务端立刻有了"add_user"的响应,每执行一次都会有对应的响应, perfect!
Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片



git提交一下
总结: 今天主要实现结构如下, 实现了客户端添加玩家时(add user)服务端进项响应, 主要收获是体会到了thrift在跨语言开发上的便捷
Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片


Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
文章图片

【Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制】

    推荐阅读