game server by golang

使用golang开发的框架


How to use ?

Features

kernel使用channel 和 goroutine 模拟的Actor模式

  • 使用channel 模拟的消息队列
  • kernel.Context内部实现了一个链表,用于发起call的时候,由于自身channel满,导致双向阻塞
    • 后续需要改成环形队列,减少一些垃圾的产生

乞丐版otp框架,核心package:kernel

  • 提供了简略版的supervisor
  • 提供类型gen_server的进程回调
  • 内置logger模块
  • 支持名字注册(local)
  • 支持进程link
  • 内置全局定时器timer
  • 内置简略控制web api

框架提供一种热更新方案

  • 详情请参考hotfix相关代码
  • how to use?
    • 参考hotfix/20210119/20210119.go编写更新代码,编译通过后
      ##本地网络执行网络请求,浏览器中也可以
          
      curl "http://127.0.0.1:3000/reload?mod=20210119"
  • 其中reload的逻辑由main.go中的func reload(w http.ResponseWriter, req *http.Request)提供

内置mysql支持

  • 引用如下代码开始使用
        import (
        "github.com/liangmanlin/gootp/db"
        )
    
        tabSlice := []*db.TabDef{
            {Name: "account", DataStruct: &global.Account{}, Pkey: []string{"Account"}, Keys: []string{"AgentID"}},
        }
        db.Env.DBConfig = db.Config{Host: "127.0.0.1", Port: 3306, User: "root", PWD: "123456"}
    
        db.Start(tabSlice, "dbName", "logDbName")

内置一种定长协议

  • 定义文件:global/pb_def.go

      type LoginTosLogin struct { // router:LoginLogin
        Account string
      }
    
      type LoginTocLogin struct {
        ID   int32
        Name string
        F    float32
        M    map[int32]int32
        S    []string
      }
  • 核心实现package:github.com/liangmanlin/gootp/gate/pb

  • 辅助工具:tool/pbBuild

  • router是工具生成的,仅仅提供路由到player包的函数

  • 目前可以导出lua代码直接使用(仅支持lua5.3及以上版本)

    • 使用如下脚本到处lua代码
        %% 假设在game目录
        tool\bin\pbBuild.exe -f ./global/pb_def.go -c client
  • 项目内 require 所有导出文件;接着可以如下:

        local function test()
            local tos = LoginTosLogin()
            local sendBuf = tos.encode()
            -- 然后你可以同网络发送这个sendBuf到服务器
    
            -- 假设接收到服务器发来的数据
            local recBuff
            ---@type LoginTocLogin
            local proto,protoID = ProtoDecode(recBuff)
            -- proto即为解析到的对象
            local a = proto.F
        end

框架内置一个网关:gate

  • 通过如下方式启动

      import "github.com/liangmanlin/gootp/gate"
    
      gate.Start(name string, handler *kernel.Actor, port int, opt ...interface{})
      
  • 建议结合内置的定长协议使用

2021.1.28 添加分布式多节点支持

  • 目前不支持在windows中运行多节点

  • Pid支持跨节点传输

    • 你可以往另外一个节点发送一个本地pid,然后在那个节点上调用callcast
  • 向一个远程节点发送数据需要先定义协议,例如:

        import "game/node"
        // 目前尚未找到一种可以直接发送对象的办法,所以这个是一种妥协
        // 即使使用grpc,也是要定义一个proto,所以依然选择使用内置协议,减少一层转换
        nodeProto := []interface{}{&global.TestCall{},&global.StrArgs{},&global.RpcStrResult{}}
        Cookie := "6d27544c07937e4a7fab8123291cc4df"
        nodename := "[email protected]"
        node.Start(nodename, Cookie, nodeProto)
  • 支持RpcCall

    • 目前是单线程执行的,如果执行的函数会阻塞,尽量不要使用
    • 需要自行调用node.RpcRegister(fun string,function RpcFunc)注册

2021.2.23 添加excel配置文件支持

  • 具体使用参考 Excel/Effect.xlsm 配置文件

    • 如需导出配置,请双击 Excel/_打包单个配置.bat
  • 支持热更新配置

  ## 以热更Effect配置为例
  curl "http://127.0.0.1:3000/reload_config?name=Effect"

2021.4.1 抽离大部分公共代码到一个代码仓库,命名为 gootp

  • 同时移除原来使用一个函数对象结构体的做法,直接使用包的全局变量代替导出函数, 这样也可以达到热更新的目的,并且代码编写会轻松一点

Problem

  • 为了热更新,框架使用起来比较繁琐,期待有人提出更好的优化方案

    • 为了热更新,框架使用大量全局变量、函数指针,会降低函数的执行效率
  • gate 的实现是直接使用net包实现的,为了异步接收数据,开启了一个goroutine,后续是优化方向

Future

  • db添加缓存
  • 考虑console使用nc进行交互界面,移除http server的单向弱交互
Similar Resources

Lightweight, facility, high performance golang based game server framework

Lightweight, facility, high performance golang based game server framework

Nano Nano is an easy to use, fast, lightweight game server networking library for Go. It provides a core network architecture and a series of tools an

Jan 1, 2023

game server by golang

使用golang开发的框架 How to use ? 参考 main.go Features kernel使用channel 和 goroutine 模拟的Actor模式 使用channel 模拟的消息队列 kernel.Context内部实现了一个链表,用于发起call的时候,由于自身channe

Dec 27, 2022

Scalable game server framework with clustering support and client libraries for iOS, Android, Unity and others through the C SDK.

pitaya Pitaya is an simple, fast and lightweight game server framework with clustering support and client libraries for iOS, Android, Unity and others

Jan 2, 2023

Dedicated Game Server Hosting and Scaling for Multiplayer Games on Kubernetes

Dedicated Game Server Hosting and Scaling for Multiplayer Games on Kubernetes

Agones is a library for hosting, running and scaling dedicated game servers on Kubernetes. Agones, is derived from the Greek word agōn which roughly t

Jan 6, 2023

A game server side framework with both web API and realtime communication.

HAYABUSA Framework Hayabusa is a server side framework for Japan-like social games. Easy to understand and use for beginners Powerful controller, flex

May 21, 2022

This is a "simple" game server. Main functionalities are matching and establishing a connection between players

This is a

Game Server This is a "simple" game server. Main functionalities are matching and establishing a connection between players How to Run? run the server

Aug 28, 2022

Backend server for a tic-tac-toe game. frontend is a simple .md file.

Backend server for a tic-tac-toe game. frontend is a simple .md file.

Nov 20, 2022

A lightweight and efficient messaging gateway server for distributed game servers, written in Go.

Overview channeld is an open source, light-weight and efficient messaging gateway server designed for distributed game servers (typically MMO) and oth

Aug 8, 2022

Online multiplayer board game server written in Go, using WebSockets.

BfH Server The Battle for Hermannia is a board game created as a gift by the father of hermannm, a developer of this project. This digital edition of

Nov 7, 2022
Comments
  • 热更新问题探讨

    热更新问题探讨

    我觉得代码不需要适配热更新,在入口做限制就行了. 比如nginx 中有2个upsteam[a,b] 先停掉a去更新a ,a启动成功后再启用a,停掉b,再更新b. 再启用b 用了k8s后 就不用改nginx了, 直接自带无感知更新了. 我是做web的 没做过游戏的,上面是我们无感知中断方案. 但我们有im系统也是长链接 跟游戏应该差不多, 我是一次给客户端发2个服务地址一个主a一个备b 要更新主a的时候发个消息给客户端 让客户端切换到备b,同时a不断,b连接成功后断开a.这样消息都不会丢. 给3秒超时 如果主a的连接还有没断的 直接让客户端自己做断线重连. 大概是这个逻辑

AircraftWar - a game powered by Go+ spx game engine
AircraftWar - a game powered by Go+ spx game engine

AircraftWar - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download thi

Jan 5, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
MazePlay - a game powered by Go+ spx game engine
MazePlay - a game powered by Go+ spx game engine

MazePlay - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this g

Dec 16, 2021
A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy!
A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy!

galactic-asteroid-belt Overview A simple game that I created with Ebiten game library as a way to teach myself Go. Enjoy! Run To run, you will need Go

Dec 2, 2021
RundQuiz-Game - This is a Go exercise that implements and builds a quiz game from a list of math questions in a CSV file.

Go RundQuiz Game Exercise details This exercise is broken into two parts to help simplify the process of explaining it as well as to make it easier to

Jan 5, 2022
Simple 2D game to teach myself various things about game development and ECS, etc

2d-grass-game I really don't know what to name this game. Its a big grass field, and its in 2d so....2D Grass game This is a simple 2D game to teach m

Jan 17, 2022
A Game Server Skeleton in golang.
A Game Server Skeleton in golang.

A game server skeleton implemented with golang. 注意(NOTICE) 欢迎加入QQ群: 459420581 (Gopher成都,讨论一切与go有关的话题) gonet/2 gonet1已停止维护(I no longer maintain this, p

Dec 26, 2022
Scalable Distributed Game Server Engine with Hot Swapping in Golang
Scalable Distributed Game Server Engine with Hot Swapping in Golang

GoWorld Scalable Distributed Game Server Engine with Hot Reload in Golang Features Architecture Introduction Get GoWorld Manage GoWorld Servers Demos

Dec 25, 2022
A game server framework in Go (golang)

Leaf A pragmatic game server framework in Go (golang). Features Extremely easy to use Reliable Multicore support Modularity Community QQ 群:376389675 D

Jan 2, 2023