gogs: Golang Game Server Framework
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.
TODO
- Support metrics
- Support generate Unity C# SDK
- Support generate JS 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
edit your proto, add the game message, then generate the code
gogs go -f data.proto
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
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.
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
Bump github.com/pion/datachannel from 1.5.2 to 1.5.5
Bumps github.com/pion/datachannel from 1.5.2 to 1.5.5.
Release notes
Sourced from github.com/pion/datachannel's releases.
Commits
17674f6
Update module github.com/pion/sctp to v1.8.5a3f491f
Update module github.com/pion/sctp to v1.8.490f6b24
Extract SetReadDeadline from Reader to fix back compat6d03d00
Add SetReadDeadline1a83011
Update module github.com/pion/transport to v0.13.1ce89fff
Update CI configs to v0.7.10335abec
Update CI configs to v0.7.95c78292
Update CI configs to v0.7.8f8a03b2
Update CI configs to v0.7.5212d451
Update CI configs to v0.7.3Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump github.com/spf13/cobra from 1.6.0 to 1.6.1
Bumps github.com/spf13/cobra from 1.6.0 to 1.6.1.
Release notes
Sourced from github.com/spf13/cobra's releases.
Commits
b43be99
Check for group presence after full initialization (#1839) (#1841)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump github.com/pterm/pterm from 0.12.50 to 0.12.51
Bumps github.com/pterm/pterm from 0.12.50 to 0.12.51.
Release notes
Sourced from github.com/pterm/pterm's releases.
Changelog
Sourced from github.com/pterm/pterm's changelog.
Commits
cd598d2
Merge pull request #426 from sephiroth74/feature/option_style22f4f96
docs: autoupdate6347b39
Merge pull request #425 from adombeck/master5cf48e5
fix: Make sure the confirm printer can clean up after Ctrl+Ca331e6f
use correct style for search text223fd94
render menu with correct styleDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump github.com/gin-gonic/gin from 1.8.1 to 1.8.2
Bumps github.com/gin-gonic/gin from 1.8.1 to 1.8.2.
Release notes
Sourced from github.com/gin-gonic/gin's releases.
Changelog
Sourced from github.com/gin-gonic/gin's changelog.
Commits
6a2a260
Fix the GO-2022-1144 vulnerability (#3432)f38c9c8
docs(readme): release v1.8.2 version (#3420)0c2a691
fix(engine): missing route params for CreateTestContext (#2778) (#2803)e305e21
fix(route): redirectSlash bug (#3227)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump github.com/pion/webrtc/v3 from 3.1.49 to 3.1.50
Bumps github.com/pion/webrtc/v3 from 3.1.49 to 3.1.50.
Release notes
Sourced from github.com/pion/webrtc/v3's releases.
Commits
1c20cd4
Update datachannel and sctp to latest720d9b0
Update module github.com/pion/transport to v0.14.16a5997b
Update module golang.org/x/net to v0.3.0Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump github.com/bytedance/sonic from 1.5.0 to 1.6.0
Bumps github.com/bytedance/sonic from 1.5.0 to 1.6.0.
Release notes
Sourced from github.com/bytedance/sonic's releases.
Commits
01c0d36
feat: reformat print error example and clarify v1.6.0 example (#332)dda5da9
fix: support decode json-encoded base64 in JIT (#329)518110b
feat:(decoder) clear memory when decoding failed (#320)02fe882
feat:(decoder) support skip mismatche-typed value (#325)2866800
optimize type assertion (#324)78c2ade
fix: readme typos (#323)6deed01
opt: reduce memory pool size (#302)3e6f839
fix iterator traversal empty object panic (#314)b52e528
feat: add dummy implementation ofpretouch()
for!amd64
arch (#306)56e81a6
fix: use sse instead of sse4 (#305)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump github.com/emicklei/proto from 1.11.0 to 1.11.1
Bumps github.com/emicklei/proto from 1.11.0 to 1.11.1.
Changelog
Sourced from github.com/emicklei/proto's changelog.
Commits
79ae249
update hist8ace023
add missing Doc method for MapField, so it implements DocumentedDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump go.uber.org/zap from 1.23.0 to 1.24.0
Bumps go.uber.org/zap from 1.23.0 to 1.24.0.
Release notes
Sourced from go.uber.org/zap's releases.
Changelog
Sourced from go.uber.org/zap's changelog.
Commits
a55bdc3
Release v1.24.0 (#1208)ed5598a
Use ReplaceAll instead of Replace with -1 pos arg (#1195)da406e3
Chore: Fix deprecation docs and links (#1193)9b86a50
SugaredLogger: Turn error into zap.Error (#1185)9137e0e
go.mod: Bump go directive to 1.19 (#1181)7cabba7
Open absolute paths as files, limited Windows support (#1159)7681a0a
Export objectMarshalerPtr (#1171)9abd14b
chore: remove duplicate word in comments (#1169)eae3743
Logger, SugaredLogger: Add Level method (#1148)0d6a75b
tests: assert.Error/Contains => assert.ErrorContains (#1158)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump github.com/pion/webrtc/v3 from 3.1.48 to 3.1.49
Bumps github.com/pion/webrtc/v3 from 3.1.48 to 3.1.49.
Release notes
Sourced from github.com/pion/webrtc/v3's releases.
Commits
c75da54
Add EnableLoopbackCandidate flag5faad1e
Update module github.com/pion/ice/v2 to v2.2.122ebf9c6
Fix docs typo1365b0a
Update CI configs to v0.8.1Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)Bump github.com/tidwall/gjson from 1.14.3 to 1.14.4
Bumps github.com/tidwall/gjson from 1.14.3 to 1.14.4.
Commits
e14b8d3
Add testf37cc44
Merge pull request #301 from svher/master1ed0d85
bug fix0fc8539
Merge pull request #299 from bashery/master25df3e6
uint64Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)