Git Product home page Git Product logo

swordlegend / distributed-architecture-of-moba-game-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zerlenzhang/distributed-architecture-of-moba-game-server

0.0 1.0 0.0 725.65 MB

探索高并发、高Cpu利用率的分布式服务器以及帧同步框架

License: The Unlicense

C 21.03% C++ 65.39% Makefile 0.42% JavaScript 0.08% Shell 0.04% Batchfile 0.01% Pascal 0.01% Objective-C 1.00% Lua 0.58% C# 10.69% Smalltalk 0.02% XSLT 0.62% TSQL 0.03% ShaderLab 0.06%

distributed-architecture-of-moba-game-server's Introduction

探索高并发,高CPU利用率的分布式服务器架构

采用C,C++开发底层逻辑,从底层支持Mysql,Redis数据库,支持分布式设计,

大量采用异步操作提高CPU利用率,未来会加入Linux系统支持,实现跨平台

核心原理

1、采用libuv处理各种各样的异步操作,文件io,tcp,udp,工作队列,计时器等

2、Session和Service的解耦和设计

3、内置Lua虚拟机,并导出大量接口,支持纯Lua语言开发以及C++,Lua混合开发。

核心模块架构

Image text

其他功能

1、CmdPackage的body支持Json和Protobuf

2、内部支持链接MySql和Redis数据库

3、异步日志持久化

优化

1、大量使用对象池,避免内存碎片化

样板工程:分布式帧同步的纯Lua游戏服务器

Image text 目前实现的功能:

1、基础:登陆、编辑用户信息、游客登陆、游客账号升级、每日签到

2、Moba:玩家匹配、房间的各种功能、机器人玩家快速组队

3、帧同步:帧同步下的角色移动控制,塔的攻击,子弹的飞行和伤害

快速启动

1、在MobaServer.exe 同目录下 2、创建Server.lua,添加如下代码

Debug.LogInit("ServerLogs","server",true);
Netbus.TcpListen(8900,
function(s)      
    
        local ip,port = Session.GetAddress(s);
   
        print("new client come ["..ip..":"..port.."]");
 
   end);
print("Server tcp listen at 8900");

3、创建ServerBat.bat,记事本打开并添加如下内容

【添加Lua搜索路径,Lua启动脚本相对路径(相对搜索路径)】
MobaServer.exe ./ Server.lua

4、创建Client.lua,添加如下代码

Debug.LogInit("ClientLogs","client",true);
Netbus.TcpConnect("127.0.0.1",8900,
		--链接成功的回调
        function(session)
            if session then
                print("succeed to connect to [127.0.0.1:8900]");
                
                return;
            end
            print("failed to connect to [127.0.0.1:8900]")
        end);

5、创建ClientBat.bat,记事本打开添加如下内容

MobaServer.exe ./ Client.lua

6、先运行ServerBat,在运行ClientBat

导出的LuaAPI

详见Wiki

distributed-architecture-of-moba-game-server's People

Contributors

zerlenzhang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.