Giter Site home page Giter Site logo

anarqz / distributed-golang-game-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danie1lin/distributed-golang-game-server

0.0 1.0 0.0 21.7 MB

A distributed game server made with Golang

License: MIT License

Shell 0.13% Go 99.42% Dockerfile 0.45%

distributed-golang-game-server's Introduction

Golang Distributed Game Server

Go Report Card CircleCI Gitter

Motivation

At first, I just want to learn Golang.I started to think about which is the best way? Because the concurrency mechanisms of Golang is very powerful, I choose online game to verify if I can use Golang to make a efficient game server.For me, this is the first time I make this such hard project. I have to learn Unity, Golang, C# At a time. I am glad that I still have full passion to this project and I never give up.

Tech/framework used

  • golang
  • gRPC
  • Kubernetes
  • Protobuf

Features

  • CrossPlatform - Message packet use protobuf which is light, fast, crossplatform.
  • Autoscaling - controller is written with go-client ,you can wirte the strategy to autoscale dedicated game server by your own.
  • Lightweight - The image of dedicated game server is less than 40MB.

Architecture

Agent server :

  • match players to join other player's room or create own room
  • control the amount of gameplay server and load balancing. when the amountof a gameplay server's connections exceed maxium connections it should have, agent will create a new pod run gameplay server.

Gameplay Server :

  • After players are matched successfully ,these players will get the gameplay server's ip and token,and player can start to play.

Packet Validating

In the branch master, I use ODE to simulate the physics on server.It is the most safe way to keep game fair.However, I found the memory server use is too much for me, Because I don't have money to maintance the server. So I started to design a way to let client validate packet and simulate physics separatly to reduce the heavy load on the server. I just complete the entities can attack each others so far. I will start to design aftewards:

  • The validation part preventing form players cheating
  • The interface connecting a physics simulator

Installation

  • Server : Two Way to run server:

    • Run distributed server using Kubernete cluster
      1. Use Kops to install kubernete on AWS
      2. Create cluster
      3. Install Mongodb
      4. edit setupEnv.sh with your setting and bash setupEnv.sh
      5. go run main.go --type=agent on your local machine (Must on Where you install Kops)
    • Run Standalone Server on local machine
      1. Install Mongodb
      2. edit setupEnv.sh( DONT_USE_KUBE = true )with your setting and bash setupEnv.sh
      3. go run main.go --type=standalone on your local machine
  • Client :

    • Download this project
    • You can run in Unity Editor by open the Prestart.scene as first scene.
    • If you want to test with mutliplayer you can try build Andorid apk because it is likely to be builded successfully.

    DEMO

How to use?

If you want to make your own game by modifying this project, I am pleasured. You can throught these step to make it work.

Modify The msg/message.proto

  1. Change the GameFrame message in proto buff.
  2. Run './update.sh' in 'msg/'
  3. unzip message.zip under 'Asset/gameServer/proto' in the Unity Project.

Create Your Game Logic

  1. add your handler to "gameServer/game/session/room.go": func (r *Room) Run()
  2. modify the UpdateFrame fuction to handle packets design by yourself. then,Data Flow to Entity to render the change of entity's properties.

The file structure:

  • agent
    • session
      • room.go
      • session.go
      • kubernetes.go
  • game
    • room.go
    • session.go
    • kubernetes.go
  • msg Use Protobuf to define package and RPC service interface
  • uuid generate different IDs of objects that can be call with reflection
  • user
    • UserManager
    • User
  • storage Use mongoDB to storage user infomation

Support me

Buy Me A Coffee

distributed-golang-game-server's People

Contributors

danie1lin avatar

Watchers

James Cloos 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.