1 Star 1 Fork 18

Luokery / NFShmServer

forked from xiaoyi445 / old_NFShmServer 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

简体中文

当前版本: v1.0.0

nfshmserver

NFShmServer 是一个使用C++开发的轻量级,敏捷型,弹性的,分布式的共享内存的插件开发框架, 让你更快更简单的开发服务端应用. 部分思路来自UE4和Ogre.(当前主要用在游戏领域) 我写的开源架构,前几年开源过,后来自己做项目,又没开源了,现在没搞项目了,加上修改了2年了,打算重新开源

License GitHub stars GitHub issues GitHub code size in bytes
SonarCloud codecov QQ Group Discord 996.icu

Copyright © [NFShmServer]
GitHub: https://github.com/yigao/NFShmServer

码云: https://gitee.com/xiaoyi445_admin/NFShmServer

QQ 群: 点击加群762414765

CI master分支 develop分支
Github Actions Github Action Github Action

特性

  • 可以做到分布式架构不需要修改任何源码的情况下,做到单进程运行,加快平时的服务器开发。分布式运行只需要程序启动是参数修改即可
  • C++热更,服务器崩溃后重启,玩家无感知,无影响,不丢任何物价数据,甚至连内网协议数据都不会有丢失,游戏数据均放在共享内存里,共享内存架构经过很多MMO大项目验证无问题,内网通讯采用共享内存通讯的话,服务器异常时,玩家协议数据不会丢失。如果你水平足够的话,理论上还可以做到服务器不重启so热更,当然不建议你这么做。
  • 服务器游戏配置数据,从excel到共享内存代码,到sql语句,只需定义一个protobuf结构,就可以生成大量有用代码,你可以用这个protobuf结构去读取excel数据,生成对应的共享内存结构类,来存放数据,也可以生成sql数据,把excel表导入到数据库,不需要修改源码,可以从本地文件读取excel数据,可以直接从数据库读取配置。
  • 玩家个人数据,只需定义一个protobuf结构,自动生成共享内存数据,sql数据,通过protobuf发射来完成mysql数据的存取,无需你自己写sql语句。
  • 类似腾讯内部服务器,每一个服务器进程都有一个独立的类似网络IP的ID,来代表这个服务器,你不需要知道任何一个服务器进程部署在哪里,只要知道这个服务器的独立ID,就可以相互通讯
  • 友好的日志控制,你可以单独控制,一个小模块的日志,甚至一个玩家的日志
  • 跨平台(Windows, Linux, MacOS)
  • 高可用的系统架构
  • 高并发和高性能的网络模块
  • 配套的 U3D 客户端,一个捕鱼项目,暂时没有上传
  • 丰富的插件(DB, script, HTTP, WebSocket 等)

Dependencies

  • libevent
  • spdlog
  • google protobuf
  • hiredis
  • rapidjson
  • concurrentqueue
  • RapidXML
  • LuaIntf
  • navigation
  • lua
  • mysql
  • mysqlpp
  • curl
  • evpp
  • openssl
  • theron
  • zookeeper

linux centos 安装可能需要的环境:

  • sudo apt-get install g++
  • sudo apt-get install cmake
  • sudo apt-get install automake
  • sudo apt-get install zip unzip

(非必须,除非你要修改excel,或修改proto文件)安装Excel工具, 需要安装protobuf python模块, xlrd python模块

Supported Compilers

  • GCC >= 7 (Tested on Centos 7)
  • MSVC >= VS2017 (Tested on Win10)

Build and Install

FOR WINDOWS, MSVC >= 2017

  1. Git pull all source
  2. Build the solution
  3. Run the binary file by Install/Bin/Debug/rund_allserver.bat
  4. win上采用的静态编译方式,而不是动态加载so/dll文件,只共大家平时开发用,会把所有的程序都打包的到NFPluginLoader, 然后通过配置文件来选择不同的程序运行,配置和在linux上的配置一样,到不用改动.

FOR LINUX(UBUNTU, CENTOS) ---- please use administrator(or sudo) to do these:

  1. Git pull all source
  2. Run build_dynamic_debug.sh to build Debug of NFShmServer
  3. Run build_dynamic_release.sh to build Release of NFShmServer
  4. Run the server, 分几种情况执行:
    • 根据使用master服务器来做分布式还是使用zookpeer,需要先配置好zookpeer,分几种种执行方式:
    • 如果你想把所有的分布式进程放到一个进程一个线程里执行的话,只要是方便调试:
    • 内网使用TCP通信,master服务器来做分布式:./NFPluginLoader --Server=AllServer --ID=1.1.1.1 --Config=../../Config --Plugin=../../TcpPlugin --restart
    • 内网使用Bus通信,master服务器来做分布式:./NFPluginLoader --Server=AllServer --ID=1.1.1.1 --Config=../../Config --Plugin=../../BusPlugin --restart
    • 内网使用TCP通信,zookpeer服务器来做分布式:./NFPluginLoader --Server=AllServer --ID=1.1.1.1 --Config=../../Config --Plugin=../../TcpPlugin_Zookpeer --restart
    • 内网使用Bus通信,zookpeer服务器来做分布式:./NFPluginLoader --Server=AllServer --ID=1.1.1.1 --Config=../../Config --Plugin=../../BusPlugin_Zookpeer --restart
    • 如果你想分布式执行:
    • 内网使用TCP通信,master服务器来做分布式:执行脚本CreateScript.sh或CreateScript_TcpPlugin.sh,会生成Start.sh,Stop.sh,ReStart.sh,Alllog.sh等脚本,执行Start.sh,会一个一个启动服务器,执行Alllog.sh可以查看所有服务器的日志。
    • 内网使用Bus通信,master服务器来做分布式:执行脚本CreateScript_BusPlugin.sh,会生成Start.sh,Stop.sh,ReStart.sh,Alllog.sh等脚本,执行Start.sh,会一个一个启动服务器,执行Alllog.sh可以查看所有服务器的日志。
    • 内网使用TCP通信,zookpeer服务器来做分布式:执行脚本CreateScript_TcpPlugin_Zookpeer.sh,会生成Start.sh,Stop.sh,ReStart.sh,Alllog.sh等脚本,执行Start.sh,会一个一个启动服务器,执行Alllog.sh可以查看所有服务器的日志。
    • 内网使用Bus通信,zookpeer服务器来做分布式:执行脚本CreateScript_BusPlugin_Zookpeer.sh,会生成Start.sh,Stop.sh,ReStart.sh,Alllog.sh等脚本,执行Start.sh,会一个一个启动服务器,执行Alllog.sh可以查看所有服务器的日志。

Tutorial && Documents

https://github.com/yigao/NFShmServer/wiki

客户端下载,客户端代码还在整理,后面会开源,现在有一个捕鱼apk,可以玩玩

game.apk

服务器架构

进程架构:

App Architecture

单物理机服务器架构:

单物理机服务器架构

多物理机服务器架构:

多物理机服务器架构

服务器架构说明:

  • 所有的服务器都要链接master服务器,可以选择使用master服务器作为命名服务器,也可以选用zookeeper作为命名服务器,只需修改下配置即可
  • 每一个服务器都有一个类似IP地址的ID,作为唯一ID,比如master服务器ID是1.1.1.1, worldserver服务器ID是15.100.3.1, 服务器之间相互通讯,不需要知道对方部署在哪一台物理机上,只需要知道对方的唯一ID,就可以相互通讯
  • 每一个单独的物理机上都有一个NFRouteAgentServer路由代理服务器,用来在这个物理机上实现内网通讯以及和别的物理机通讯,一个NFProxyAgentServer网关代理服务器,用来链接网关,实现对外部(客户端)通讯
  • 物理机
  • 逻辑服务器比如LoginServer,LogicServer,GameServer,WorldServer,SnsServer,StoreServer, 相互之间不连接,同一个物理机上全部链接同一个NFRouteAgentServer路由代理服务器,并把自己的唯一ID注册到这个NFRouteAgentServer上, 来实现相互通讯,比如LoginServer发消息给WorldServer, LoginServer和WorldServer之间相互不连接,LoginServer需要把消息先发给NFRouteAgentServer, NFRouteAgentServer再把消息转发给WorldServer。
  • NFRouteAgentServer路由代理服务器通过链接NFRouteServer服务器来实现相互链接,NFRouteAgentServer路由代理服务器会把自己下面的逻辑服务器信息发给NFRouteServer服务器,来实现分布跨物理机通讯。在不同物理机之间的服务器通讯需要NFRouteServer服务器,比如LoginServer给不在同一个物理机上的WorldServer发消息,LoginServer需要把消息先发给同一台物理机上的NFRouteAgentServer, NFRouteAgentServer再把消息转发给NFRouteServer, NFRouteServer在吧消息转发给和WorldServer同一个物理机的NFRouteAgentServer, NFRouteAgentServer再把消息转发给WorldServer
  • 客户端只链接NFProxyServer, 发消息给逻辑服务器,NFProxyServer会把消息转发给逻辑服务器链接的NFProxyAgentServer代理服务器,NFProxyAgentServer代理服务器在吧消息转发给逻辑服务器, 同理逻辑服务器发消息给客户端,需要先通过NFProxyAgentServer代理服务器, NFProxyAgentServer代理服务器在发消息转发给NFProxyServer, NFProxyServer在发给客户端

一些很赞的项目

PSS

  • 作者: freeeyes
  • 描述: 基于插件的跨平台网络服务器框架

ARK

  • 作者: NickYang1988
  • 描述: 基于插件的跨平台网络服务器框架

NoahGameFrame

  • 作者: ketoo
  • 描述: 基于插件的跨平台网络服务器框架
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

C++共享内存开源服务器 展开 收起
C++
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/li/NFShmServer.git
git@gitee.com:li/NFShmServer.git
li
NFShmServer
NFShmServer
master

搜索帮助