Giter Club home page Giter Club logo

gogs's Introduction

gogs: Golang Game Server Framework

version codecov GitHub issues GitHub Workflow Status GitHub Release Date GitHub last commit goversion license GitHub top language

gogs is a simple, fast and lightweight game server framework written in golang. It is designed to be easy to use and easy to extend. It will generate logic code from protobuf files, and you can use it to develop your game server. It's also a good starting point for you to learn golang. It supports websocket and webrtc datachannel.

Untiy Meta City Demo Online


TODO

  • Support metrics
  • Support generate Unity C# SDK
  • Support generate JS SDK
  • Support generate Golang SDK
  • Support Remote call
  • Support tracing
  • Support gogs generate docker file
  • Support gogs generate k8s yaml
  • Support custom game packet protocol
  • Support kubegame controller, create game pod with api
  • Add more examples
  • Add more tests
  • Add more documentation
  • Test coverage reaches 80%
  • k8s friendly, hot reload?

Getting Started

Prerequisites

Init your project

install the gogs

go install github.com/metagogs/gogs/tools/[email protected]

init project

mkdir yourgame
cd yourgame
gogs init -p yourgame

Flags:
 -p your go package name

edit your proto, add the game message, then generate the code

gogs go -f data.proto

Flags:
 -f proto file path

run your game server

go mod tidy
go run main.go

Generated Project

internal/
    logic/
        baseworld/
            bind_user_logic.go
    server/
        server.go
    svc/
        service_context.go
model/
    data.ep.go
    data.pb.go
config.yaml     
data.proto      
main.go

Generated Unity C# Code

this will generate a unity code, you can use it to test your game server. And you need use the Unity Protobuf to run the code.

 gogs csharp -f data.proto

 Flags:
 -f proto file path
 -g generate unity c# gogs library, you should use it when you generate code first time

Deployment

gogo docker // generate Dockerfile

go run main --deployment // generate k8s yaml
--svc use service to expose your game server not hostport
--name your game server name
--namepsace your k8s namespace

How to encode/decode the message

Packet Protocol

gogs uses 8 bytes as the protocol header

protocol header = flag + version + action index + message data length

0     byte  flag         8bit    protocol flag, awalys 0x7E 
1     byte  version      5bit    protocel version
            encodeType   3bit    protocel encode type
2     byte  packetType   2bit    packet message type 1 system 2 server
            component    6bit    message component index
3.4   byte  action       16bit   message action index
5.6.7 byte  length       24bit   message length

What is the action index

action index = packetType + component index + action index

// @gogs:Components
message Components {
    BaseWorld BaseWorld = 1; // 1 is the component index
}

message BaseWorld {
    BindUser BindUser = 1; // 1 is the action index

    BindSuccess BindSuccess = 2; // 2 is the action index
}
message BindUser {
    string uid = 1;
}


// @gogs:ServerMessage
message BindSuccess {
}

like this proto, the BindUser and BindSuccess is the message comunication between client and server

BindUser action index = packetType <<22 | component <<16 | action = 2 << 22 | 1 << 16 | 1 = 0x810001

BindSuccess action index = packetType <<22 | component <<16 | action = 2 << 22 | 1 << 16 | 2 = 0x810002

Packet encode & decode

gogs has three encode&decode types - encodeType in protocol header

  • 0 json encode&decode without protocol header
  • 1 json encode&decode with protocol header
  • 2 protobuf encode&decode with protocol header

Packet message

message with encode type 0 (json without protocol header)

message = JSON binary data

gogs retrieves the action index from the message, then gets the filed type and decodes the message, finally it calls the logic function. The json message without protocol header should add a filed named action, the value is the filed name

{
	"action": "BindUser",
	"uid": "123"
}
app.UseDefaultEncodeJSONWithHeader()

message with encode type 1 (json with protocol header)

message = 8 bytes protocol header + JSON binary data

app.UseDefaultEncodeJSON()

message with encode type 2 (protobuf with protocol header)

message = 8 bytes protocol header + protobuf binary data

app.UseDefaultEncodeProto()

Contributing

Running the gogs tests

make test

This command will run both unit and e2e tests.

Demo

License

Apache License Version 2.0

gogs's People

Contributors

dependabot[bot] avatar dicyroll avatar szpnygo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gogs's Issues

Should I change the repo name?

gogs is a famous project name.

Should I change the repo name?

If you think the name should be changed, please give me some advice. or you think it's ok

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.