A Game Server Skeleton in golang.

A game server skeleton implemented with golang.

Architecture

注意(NOTICE)

欢迎加入QQ群: 459420581 (Gopher成都,讨论一切与go有关的话题)

gonet/2

gonet1已停止维护(I no longer maintain this, please move forward to http://github.com/gonet2 )

建议移步至新架构: http://gonet2.github.io

部署:

  • Game Server(GS):
    玩家直接连接GS, 处理玩家逻辑,并与 HUB/SS 通信,GS存在若干个。
    (Players connect directly to GS(s) and process, GS(s) will communication with HUB)

  • Hub Server(HUB):
    若干个GS 连接到一个HUB, 只存在一个HUB,维护基础的全局信息,以及 GS<--->GS 的消息转发.
    (packet forwarding)

  • Stats Server(SS):
    统计服务器,根据玩家的行为,记录策划需要的数据,以便于后期统计。
    统计属于事后分析,数据量较大,性能需求不同, 故单独列为一个服务器。

通信原则:

  1. GS到HUB/SS的通信,都是Call同步调用,即GS必须等待ACK。
  2. HUB到GS的通信,只有forward数据包。
  3. 单播消息在玩家离线时会存入db, 登录后的启动过程 GS 直接读取db,并forward给玩家goroutine。(持久化)
  4. 多播消息会发送给所有的在线玩家(非持久化)
  5. 广播消息会发送给所有的在线玩家(非持久化)

服务器状态一致性

  1. GS节点可以单独重启
  2. HUB 重启后,GS必须全部重启
  3. SS 可随意重启,不影响业务

安装先决条件:

  1. 确保安装好graphviz, gawk
  2. 确保安装好mongodb
  3. 确保config.ini中的mongo_xxxx配置正确
  4. export GOPATH='当前目录'

安装:

  • xtaci@ubuntu:~$ git clone https://github.com/xtaci/gonet
  • xtaci@ubuntu:~$ cd gonet
  • xtaci@ubuntu:/gonet$ export GOPATH=/gonet
  • xtaci@ubuntu:~/gonet$ go get gopkg.in/mgo.v2
  • xtaci@ubuntu:~/gonet$ make
  • xtaci@ubuntu:~/gonet$ ./start-test.sh

####支持此项目 ( Donations ) :
donate
欢迎使用支付宝扫描上面的二维码,对该项目进行捐赠。捐赠款项将用于持续优化补全及完善。

Owner
xtaci
自心取自心,非幻成幻法。
xtaci
Comments
  • 请问 size := int(header[0])<<8 | int(header[1]) 怎么理解?

    请问 size := int(header[0])<<8 | int(header[1]) 怎么理解?

    你好 最近学习golang 我也做游戏的 发现你的 框架不错 想学习下 却看不懂下面这段代码 能否有空帮我解惑下,谢谢

    header := make([]byte, 2) size := int(header[0])<<8 | int(header[1]) 请问 size := int(header[0])<<8 | int(header[1]) 怎么理解?

  • 调用逻辑处理的方式

    调用逻辑处理的方式

    //log.Printf("code:%v\n", b)
    handle := protos.ProtoHandler[b]
    ret := handle(sess, reader)
    
    var ProtoHandler map[uint16]func(*Session, *packet.Packet) []byte = map[uint16]func(*Session, *packet.Packet) []byte{
    0: P_heart_beat_req,
    1: P_user_login_req,
    }
    

    没有办法做到

    //log.Printf("code:%v\n", b)
    no := "P_"+strconv.itoa(b)
    ret := protos.no(sess, reader)
    

    这种模式?

  • 能不能加个flash 安全策略的访问逻辑呢?

    能不能加个flash 安全策略的访问逻辑呢?

    我查遍了网上的资料 都没查到as3 socket 链接 go 的 安全策略

    我实现了出现一些问题 for { // header n, err := io.ReadFull(conn, header) log.Println("header:", header) if (string(header) == "<p") { log.Println("string header:", string(header)) r := bufio.NewReader(conn) otherHeader, err := r.ReadString('\x00') if err != nil { if err != io.EOF { log.Println(err) } return } log.Printf("otherHeader", string(otherHeader)) data := []byte("") ch <- data } else { if n == 0 && err == io.EOF { break } else if err != nil { log.Println("error receiving header:", err) break } size := binary.BigEndian.Uint16(header) log.Println("Game Receive Size.", size) data := make([]byte, size) n, err = io.ReadFull(conn, data) log.Println("Game Receive Data.", string(data)) if err != nil { log.Println("error receiving msg:", err) break } ch <- data } }

    [GS]2013/07/08 22:43:32 header: [60 112]
    [GS]2013/07/08 22:43:32 string header: <p
    [GS]2013/07/08 22:43:32 otherHeader%!(EXTRA string=olicy-file-request/>)
    [GS]2013/07/08 22:43:32 Sent policy file to xxxx.xx.xxx.xx:50149
    [GS]2013/07/08 22:43:32 header: [60 112]
    [GS]2013/07/08 22:43:32 string header: <p
    

    不知道您有没有空 把flash安全策略 集成到你的这个gonet框架中哈 谢谢

  • gonet1 design document

    gonet1 design document

    Hi there, no idea if it's possible for you, but it would be awesome if someone (or you) could provide an english translation of the readme....

    Sorry that I can't request this in chinese!

    謝謝

  • 安装过程misc/alg/dos报错

    安装过程misc/alg/dos报错

    misc/alg/dos

    src/misc/alg/dos/dos.go:147: n.id undefined (type *Node has no field or method id) src/misc/alg/dos/dos.go:147: pred.id undefined (type *Node has no field or method id)

    这个行看了下好像是不需要的

  • 为什么HUB重启后,GS必须全部重启?已经数据持久化问题

    为什么HUB重启后,GS必须全部重启?已经数据持久化问题

    1.服务器状态一致性 2.HUB重启后,GS必须全部重启 这里想问下为什么GServer也要重启是由于GServer和hub服务器之间的数据同步问题还是由于hub_client缺少断线重连(我见hub_client中做了连接失败5秒重连),go刚接触还比较陌生。 2.所有的玩家数据都是保存在内存中的?使用mgdb存储json文件(玩家数据等信息)来做数据的持久化?如果是全部保存在内存中是否担心机器故障导致玩家数据丢失,不知道在这方面怎么处理的,是否像leveldb的处理一样在数据写入到内存中时先以AOF文件的形式保存到磁盘上,这样即使突然的机器故障也可以中AOF文件中回复过来。 谢谢

  • timer

    timer

    今天看了下这个定时器的实现 1.精度为0.1s ? 2.这里设置16级的原因是不是当有超时事件发生时,将它们根据超时时间放入不同优先级的容器中,然后根据优先级进行处理。实际上就是按照到时时间依次处理?不知道我的理解对不对?如果是这样的话为什么不直接用一个队列先超时先压入?没搞懂这里分了16级的原因,请教下。

    谢谢

  • `sess` isn't initialized in `agent/buffer.go` when `NewBuffer` is called

    `sess` isn't initialized in `agent/buffer.go` when `NewBuffer` is called

    A cool game server framework. Thanks!

    In agent/buffer.go, NewBuffer doesn't initialize the member variable sess, and the type of sess is not a Session pointer. Or maybe I am wrong.

  • 能不能解释下 len(buf.pending) < buf.max  这个含义?

    能不能解释下 len(buf.pending) < buf.max 这个含义?

    type Buffer struct { ctrl chan bool // receive exit signal pending chan []byte // pending Packet max int // max queue size conn net.Conn // connection } 我在看代码的时候 不明白 peding 是 []byte

    const ( DEFAULT_QUEUE_SIZE = 5 ) max = DEFAULT_QUEUE_SIZE len(buf.pending) 和 buf.max

    是计算 如果超过5个 chan []byte 这种数据包 就丢弃?

Arkanoid game in Go using Ebiten game engine with ECS.
Arkanoid game in Go using Ebiten game engine with ECS.

Arkanoid-go Arkanoid game in Go using Ebiten game engine with ECS. You must have Git LFS installed when cloning the repository to download assets. See

Oct 9, 2022
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
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
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