Scalable Distributed Game Server Engine with Hot Swapping in Golang

Overview

GoWorld

Scalable Distributed Game Server Engine with Hot Reload in Golang

GoDoc Build Status Go Report Card codecov ApacheLicense


中文资料

中文文档
游戏服务器介绍
目录结构说明
使用GoWorld轻松实现分布式聊天服务器

游戏服务端开源引擎GoWorld教程

1.安装和运行
2.Unity示例双端联调
3.手把手写一个聊天室
4.多个频道的聊天室
5.登录注册和存储
6.移动同步和AOI
7.源码解析之启动流程和热更新
8.码解析之gate
9.源码解析之dispatcher
10.源码解析之entity


欢迎加入Go服务端开发交流群:662182346


Features

  • Spaces & Entities: manage multiple spaces and entities with AOI support
  • Distributed: increase server capacity by using more machines
  • Hot-Swappable: update game logic by restarting server process
  • Multiple Communication Protocols: supports TCP, KCP and WebSocket
  • Traffic Compression & Encryption: traffic between clients and servers can be compressed and encrypted

Architecture

GoWorld Architecture

Introduction

GoWorld server adopts an entity framework, in which entities represent all players, monsters, NPCs. Entities in the same space can visit each other directly by calling methods or access attributes. Entities in different spaces can call each over using RPC.

A GoWorld server consists of one dispatcher, one or more games and one or more gates. The gates are responsible for handling client connections and receive/send packets from/to clients. The games manages all entities and runs all game logic. The dispatcher is responsible for redirecting packets among games and between games and gates.

The game processes are hot-swappable. We can swap a game by sending SIGHUP to the process and restart the process with -restore parameter to bring game back to work but with the latest executable image. This feature enables updating server-side logic or fixing server bugs transparently without significant interference of online players.

Installing GoWorld

GoWorld requries Go 1.11+ to install.

go get github.com/xiaonanln/goworld/cmd/...

Manage GoWorld Servers

Use command goworld to build, start, stop and reload game servers.

Build Example Chatroom Server:

$ goworld build examples/chatroom_demo

Start Example Chatroom Server: (dispatcher -> game -> gate)

$ goworld start examples/chatroom_demo

Stop Game Server (gate -> game -> dispatcher):

$ goworld stop examples/chatroom_demo

Reload Game Servers:

$ goworld reload examples/chatroom_demo

Reload will reboot game processes with the current executable while preserving all game server states. However, it does not work on Windows.

List Server Processes:

$ goworld status examples/chatroom_demo
> 1 dispatcher running, 1/1 gates running, 1/1 games (examples/chatroom_demo) running
> 	2763      dispatcher      /home/ubuntu/go/src/github.com/xiaonanln/goworld/components/dispatcher/dispatcher -dispid 1
> 	2770      chatroom_demo   /home/ubuntu/go/src/github.com/xiaonanln/goworld/examples/chatroom_demo/chatroom_demo -gid 1
> 	2779      gate            /home/ubuntu/go/src/github.com/xiaonanln/goworld/components/gate/gate -gid 1

Demos

Chatroom Demo

The chatroom demo is a simple implementation of chatroom server and client. It illustrates how GoWorld can also be used for games which don't divide players by spaces.

The chatroom demo provides following features:

  • register & login
  • send chat message
  • switch chatrooms

Build Server:

goworld build examples/chatroom_demo

Run Server:

goworld start examples/chatroom_demo

Chatroom Demo Client:

Chatroom demo client implements the client-server protocol in Javascript.
The client for chatroom demo is hosted at github.com/xiaonanln/goworld-chatroom-demo-client. The project was created and built in Cocos Creater 1.5.

Unity Demo

Unity Demo is a simple multiple player monster shooting game to show how spaces and entities of GoWorld can be used to create multiple player online games.

  • register & login
  • move players in space
  • summon monsters
  • player shoot monsters
  • monsters attack players

Developing features:

  • Hit effects
  • Players migrate among multiple spaces
  • Server side map navigation

Build Server:

goworld build examples/unity_demo

Run Server:

goworld start examples/unity_demo

Unity Demo Client:

Unity demo client implements the client-server protocol in C#. The client for unity demo is hosted at https://github.com/xiaonanln/goworld-unity-demo. The project was created and built in Unity 2017.1.

You can try the demo by downloading GoWorldUnityDemo.zip. The demo connects to a goworld server on Huawei Cloud instance.

Issues
  • 热重启的性能如何?

    热重启的性能如何?

    有没有测试过一个进程的entity数据量和热重启花费时间的关系,顿卡时间有多长

    opened by xuxbuptisc 12
  • go get dependency error

    go get dependency error

    $ go get github.com/xiaonanln/goworld
    # cd .; git clone https://gopkg.in/eapache/queue.v1 
    fatal: unable to access 'https://gopkg.in/eapache/queue.v1/': Unknown SSL protocol error in connection to gopkg.in:-9838
    package gopkg.in/eapache/queue.v1: exit status 128
    fatal: unable to access 'https://gopkg.in/ini.v1/': Unknown SSL protocol error in connection to gopkg.in:-9838
    package gopkg.in/ini.v1: exit status 128
    # cd .; git clone https://gopkg.in/vmihailenco/msgpack.v2 
    fatal: unable to access 'https://gopkg.in/vmihailenco/msgpack.v2/': Unknown SSL protocol error in connection to gopkg.in:-9838
    package gopkg.in/vmihailenco/msgpack.v2: exit status 128
    # cd .; git clone https://gopkg.in/natefinch/lumberjack.v2 
    fatal: unable to access 'https://gopkg.in/natefinch/lumberjack.v2/': Unknown SSL protocol error in connection to gopkg.in:-9838
    package gopkg.in/natefinch/lumberjack.v2: exit status 128
    
    opened by bopjiang 10
  • 这种架构有点不好,中心分发器如果挂了,或者满连了怎么办呢??

    这种架构有点不好,中心分发器如果挂了,或者满连了怎么办呢??

    最少破坏了分布式一半以上的优雅性

    question 
    opened by ice-ice 8
  • Support Google Protobuf 支持protobuf

    Support Google Protobuf 支持protobuf

    help wanted 
    opened by xiaonanln 7
  • [unity-demo] Player position not getting set on the server

    [unity-demo] Player position not getting set on the server

    I tried running the unity demo today and it works fine until it doesn't: The player positions does not seem to sync with the server quite right. The packet arrives, but at the wrong entity.

    Somehow during the lifecycle the entity.syncingFromClient property is returning false as the player entity changes (even though the ID stays the same). Furthermore, the player entity seems to get added twice, which probably means we load the same player twice, but don't initialize them correctly - and thus overwrite the existing copy since it's a map.

    opened by spaceemotion 7
  • 【bug】修复迁移目的位置错误bug

    【bug】修复迁移目的位置错误bug

    1. 修复迁移目的位置错误bug
    2. 代码优化
    bug comp: entity 
    opened by zengjiwen 6
  • Update to use dep

    Update to use dep

    The dep release link should be correct for travis but should be checked

    opened by SonarBeserk 5
  • Project directory structure

    Project directory structure

    As I understand you project correctly - it is a framework. So you don't need to have the framework inside your own project, but here I found limitation: project source code should be inside the framework dir. Example: I created my project in ~/test/ I installed goworld framework, installed all deps. goworld with all deps stored in GOPATH, which is different as my project dir. So when I want to build my test project I expect behavior like: goworld build ./test But got:

    • goworld directory found: $GOPATH/src/github.com/xiaonanln/goworld
    • server directory is $GOPATH/src/github.com/xiaonanln/goworld/test Is that behavior is correct? Or what I did wrong?

    Also to cheating that behavior I add symlink inside $GOPATH/src/github.com/xiaonanln/goworld/test to my $HOME/test dir. Building\Starting processes fine, but on stopping - goworld can't find game instance and doesn't stop it and doesn't throw any error.

    opened by KonstantinKuklin 4
  • Architecture Image is a 404

    Architecture Image is a 404

    The architecture image in the readme is a dead link.

    opened by SonarBeserk 4
  • v0.1

    v0.1

    Version v0.1

    • Basic functionalities: entity, attributes,
    • TCP, KCP, WEBSOCKET
    • Reload
    • ext: db/gwmongo, pubsub, msgbox
    • strip useless code
    opened by xiaonanln 4
  • 全局逻辑设计决策

    全局逻辑设计决策

    请问作者,goworld为什么把全局逻辑分散在各个game里,这样的设计与把全局逻辑设计为单独的全局进程集群相比有什么优势呢? @xiaonanln

    opened by zengjiwen 0
  • 一定得linux环境吗?Windows Demo跑不通啊?

    一定得linux环境吗?Windows Demo跑不通啊?

    一开始报gameid的错,把他改成1后又报这个错。

    Connect to dispatcher1 failed: dial tcp 127.0.0.1:13001: connectex: No connection could be made because the target machine actively refused it.

    opened by mogebingxue 0
  • 不维护了吗?库都拉不齐,能不能改go mod啊

    不维护了吗?库都拉不齐,能不能改go mod啊

    不维护了吗?库都拉不齐,能不能改go mod啊

    opened by jageros 5
  • can not install goworld,win10/go version go1.13.4 windows/amd64

    can not install goworld,win10/go version go1.13.4 windows/amd64

    C:\Users\86186>go get github.com/xiaonanln/goworld/cmd/... go: finding golang.org/x/sys latest go: finding golang.org/x/net latest go: finding github.com/StackExchange/wmi latest go: finding github.com/kardianos/osext latest

    #github.com/xiaonanln/goworld/cmd/goworld/process

    go\pkg\mod\github.com\xiaonanln\[email protected]\cmd\goworld\process\process_win.go:12:37: cannot use windows.Signal(sig) (type windows.Signal) as type syscall.Signal in argument to p.Process.SendSignal

    C:\Users\86186>go get github.com/xiaonanln/goworld go: finding golang.org/x/net latest go: finding gopkg.in/mgo.v2 latest go: finding github.com/StackExchange/wmi latest go: finding github.com/kardianos/osext latest #github.com/xiaonanln/goworld/engine/kvdb/backend/kvdbrediscluster go\pkg\mod\github.com\xiaonanln\[email protected]\engine\kvdb\backend\kvdbrediscluster\kvdb_redis_cluster.go:36:3: cannot use c (type redis.Cluster) as type *redis.Cluster in field value: *redis.Cluster is pointer to interface, not interface go\pkg\mod\github.com\xiaonanln\[email protected]\engine\kvdb\backend\kvdbrediscluster\kvdb_redis_cluster.go:44:20: db.c.Do undefined (type *redis.Cluster is pointer to interface, not interface) go\pkg\mod\github.com\xiaonanln\[email protected]\engine\kvdb\backend\kvdbrediscluster\kvdb_redis_cluster.go:81:16: db.c.Do undefined (type *redis.Cluster is pointer to interface, not interface) go\pkg\mod\github.com\xiaonanln\[email protected]\engine\kvdb\backend\kvdbrediscluster\kvdb_redis_cluster.go:92:16: db.c.Do undefined (type *redis.Cluster is pointer to interface, not interface) go\pkg\mod\github.com\xiaonanln\[email protected]\engine\kvdb\backend\kvdbrediscluster\kvdb_redis_cluster.go:121:6: db.c.Close undefined (type *redis.Cluster is pointer to interface, not interface) #github.com/xiaonanln/goworld/engine/storage/backend/redis_cluster go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:39:3: cannot use c (type redis.Cluster) as type *redis.Cluster in field value: *redis.Cluster is pointer to interface, not interface go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:56:24: not enough arguments in call to redis.Values go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:56:29: es.c.Do undefined (type *redis.Cluster is pointer to interface, not interface) go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:77:24: not enough arguments in call to redis.Values go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:77:29: es.c.Do undefined (type *redis.Cluster is pointer to interface, not interface) go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:95:15: es.c.Do undefined (type *redis.Cluster is pointer to interface, not interface) go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:100:23: not enough arguments in call to redis.Bytes go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:100:28: es.c.Do undefined (type *redis.Cluster is pointer to interface, not interface) go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:113:27: not enough arguments in call to redis.Bool go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:113:32: es.c.Do undefined (type *redis.Cluster is pointer to interface, not interface) go\pkg\mod\github.com\xiaonanln\[email protected]\engine\storage\backend\redis_cluster\entity_storage_redis_cluster.go:113:27: too many errors

    opened by evehal 0
  • add test_game stress test

    add test_game stress test

    opened by xiaonanln 1
  • Samples does not work.

    Samples does not work.

    There's a lot of fatal section gate1 has unknown key: http_addr when call goworld start because of goworld.ini config file. Still got an error ! start dispatcher failed, see dispatcher.log for error: wait started tag timeout After fixed it, but dispatcher.log is empty.

    opened by glight2000 1
  • QQ群号是错的,不能进群,求修复

    QQ群号是错的,不能进群,求修复

    QQ群号是错的,不能进群,求修复

    opened by suixin567 0
  • 在game和gate之间加入Dispatcher主要出于什么设计目的?以及主要解决什么问题?

    在game和gate之间加入Dispatcher主要出于什么设计目的?以及主要解决什么问题?

    我看了博客和文档,没有指出这么做的原因。希望作者能在百忙之中解答下,非常感谢, @xiaonanln

    opened by mars315 1
  • move workspace out of goworld directory

    move workspace out of goworld directory

    This PR serves as an early preview, and fire up the talk about the subject.

    Currently all documentations and the goworld build tool suggest working directly inside the goworld repo directory. I've started to modifying the build tool to support Go work flow and directory structure.

    So far I have modify the build process to follow go module rules. It now supports building projects outside of the goworld directory. Further, I can make customization possible to gate, dispatcher, and game. Making them all can live outside of goworld directory. So it'll be possible for others to just use this package as a dependency, and customize the actual work flow as they want.

    However, as the imports are hard-linked to the original repo, I have no way of further testing the whole process. I've tried copying the chat demo from examples directory. Place it in various directories, inside and outside of GOPATH. It seems the building process goes fine. Until I actually add the go.mod file to the demo. Which rquires the v0.1.6 version of the original goworld. And that version doesn't work well with redis cluster v1. I've tried switching to a commit from master with no success.

    Please share your thoughts regarding my approach. More importantly, do you think it's necessary to make this package usable as pure dependency, instead of working directly inside it?

    opened by eidng8 0
Releases(v0.1.6)
Owner
Nan Lin
Software Engineer
Nan Lin
chess package for go

chess Introduction chess is a set of go packages which provide common chess utilities such as move generation, turn management, checkmate detection, P

Logan Spears 295 Jul 3, 2021
Web-based Cloud Gaming service for Retro Game

CloudRetro provides an open-source cloud gaming platform for retro games. It started as an experiment for testing cloud gaming performance with WebRTC and libretro, and now it aims to deliver the most modern and convenient gaming experience through the technology.

giongto35 1.5k Jul 23, 2021
Go 3D Game Engine

G3N - Go 3D Game Engine G3N (pronounced "gen") is an OpenGL 3D Game Engine written in Go. It can be used to write cross-platform Go applications that

G3N - Go 3D Game Engine Repositories 1.5k Jul 23, 2021
This is a "simple" game server. Main functionalities are matching and establishing a connection between players

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

eco 4 Jul 7, 2021
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

Nan Lin 1.9k Jul 25, 2021
♛♔ Play chess against UCI engines in your terminal.

uchess ♛♔ Play chess in your terminal. Introduction uchess is an interactive terminal chess client designed to allow gameplay and move analysis in con

Travis Whitton 30 Jul 11, 2021
Snake game implemented in golang

little_pineapple(Snake game implemented in golang) 贪吃蛇golang实现 Snake game implemented in golang 数据结构:链表&数组 Data structures used: linked list&array 使用方

null 7 Aug 17, 2020
Snake game made in Go! 🐍

Snake This is a Terminal based snake game made by tristangoossens. Please star this repository to help my first big project grow! Documentation can be

Tristan Goossens 294 Jul 18, 2021
🕹️ A basic gameboy emulator with terminal "Cloud Gaming" support

Gameboy.Live ??️ Gameboy.Live is a Gameboy emulator written in go for learning purposes. You can simply play Gameboy games on your desktop: Or, "Cloud

AaronLiu 4.2k Jul 26, 2021
Terminal-based game engine for Go, built on top of Termbox

Termloop Termloop is a pure Go game engine for the terminal, built on top of the excellent Termbox. It provides a simple render loop for building game

Joel Auterson 1.2k Jul 18, 2021
An open source re-implementation of Diablo 2

OpenDiablo2 Join us on Discord! Development Live stream Support us on Patreon We are also working on a toolset: https://github.com/OpenDiablo2/HellSpa

OpenDiablo2 9.6k Jul 26, 2021
Engo is an open-source 2D game engine written in Go.

Engo A cross-platform game engine written in Go following an interpretation of the Entity Component System paradigm. Engo is currently compilable for

Engo 1.4k Jul 26, 2021
A 2D ARPG game engine.

Abyss Engine is an ARPG game engine in the same vein of the 2000's games, and supports playing games similar to Diablo 2. The engine is written in golang and is cross platform. This engine does not ship with game specific files, and will require a game's assets in order to run.

OpenDiablo2 29 Jul 19, 2021
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

GoogleForGames 3.9k Jul 17, 2021