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 first

go run ./cmd/server/server.go

and run as many client as you want (kidding, go easy :) ).

go run ./cmd/client/client.go

Folder Structure and Packages:

Package Folder Description
server /server Server is main package of this project it contains the code for matching (TCP) and connection(UDP)
client /client Client is an abstract representation of player.
config /config Config package holds the server configurations such as connection information, game size etc.
frame /frame Frame package is a data frame package. It designed and developed just for this project and It is a serializer for a game events. A detailed frame information is in below. frame contains 3 section.first is the header, it holds the important information about this frame such as gameID, clientID and number of event.second section is events. Event is a basic information packets. it holds a eventID and a data part.last section is for time stamp.
simulator /simulator Simulator simulates a pseudo client events and it listens for certain events like game over.
test /simulator There is only one test in this project and it controls the frame marshal and unmarshal functions.
utils /utils utils has general utility functions and the most important part is encoding and decoding functions. they are crucial for frame package.
cmd /cmd cmd folder has 2 subfolder named server and client. Those packages can run by themselves to simulate a game server/client environment. there is a demonstration of client and server.

Frame in Detail

|------------------------------------|-----------------------------------------|-----------|
|                header              |                events...                |  time     |
|------------------------------------|------------------------------------------------------
|clientID | gameID | number of event | eventID  |  data | eventID  |  data |...| timeStamp |
|------------------------------------|------------------------------------------------------
|  2byte  | 2byte  |     1byte       |   1byte  | 4byte |   1byte  | 4byte |...|   8byte   |
|  16bit  | 16bit  |     8bit        |   8bit   | 32bit |   8bit   | 32bit |...|   64bit   |
|------------------------------------|-----------------------------------------|-----------|

Server and client communication demonstration

Server Work Flow

Game Matcher

Mather is using TCP connections to receive game requests.

After a game request has arrived matcher is adding that user to a queue. if there are enough participant in the queue, matcher groups them under a gameID and attaches this group to the gameList.

After adding group to the gameList it removes players from the gameQueue and closes their TCP connections.

*Game size can be change from /config directory.

Game Routine

Game routine listens UDP packets. First it needs a register request from client. And receives a response with gameID and clientID.

When register arrive game routine start to reads and process incoming data and send back to clients.

*Game routine is schedules a dummy game over routine to test if games are lasting properly. Max and min game times are configurable from /config directory.

Client Game Request

Client sends an initial message that contains a "token" if token is valid (and there are enough participant to create a game of course) server responds it with a gameID and clientID.

Client uses those information to send a initial UDP register message.

Client waits for game started event and send a pseudo random events to the server.

When game over event has arrived client ends its process.

*event sending and receiving functions are not serial functions. they are running concurrently

Flow charts

Notes

  • To avoid ip:port collision event, all clients opens their UDP listen port differently. for example client 3's UDP port is 9093(9090+3)

  • There is also a dummy non-functional authentication system. it is like a placeholder for better authentication and authorization systems.

  • There is an easy interrupt handle for client and server. If client receives an interrupt (SIGINT, SIGTERN or SIGQUIT) it sends a disconnected event to server and server broadcasts a game over event to all players. Likewise If server interrupted it send the same game over event to all players in all games.

Similar Resources

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

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

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

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
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 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
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 framework in golang for game server or app server
a framework in golang for game server or app server

einx a framework in golang for game server or app server. a example server for einx (https://github.com/Cyinx/game_server_einx) Features User-Friendly

Dec 8, 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