GOWOG is a multiplayer web game written in Golang. Thanks to Golang, the server can handle a large number of players concurrently.
Southeast Asia region (Vietnam, Singapore, Malaysia ...)
Due to the cost of hosting. The server is hosted only on SEA.
As the server, client and messages are decoupled, it is easy to communicate with backend. Below is my AI agent written in Python that learns to interact with environment. This experiment is to find a path in a maze using neuroevolution
https://www.youtube.com/watch?v=pWbb1m91mhU
The implementation is at gowog/ai
You can try the game on local by running ./run_local.sh
. It will build a docker environment and run the game on port 8080.
Open the browser "localhost:8080"
The game contains two part: Server and Client. Server uses Golang and Client uses Node.JS and Phaser game engine.
Install Golang https://golang.org/doc/install
Install dependencies
go get github.com/gorilla/websocket
go get github.com/golang/protobuf/protoc-gen-go
go get github.com/pkg/profile
Run the server. The server will listen at port 8080.
Go to gowog folder
go run server/cmd/server/*
Install NodeJS https://nodejs.org/en/download/
Go to gowog/client folder
Install dependencies
npm install
Run the client. The client will listen at port 3000. env.HOST_IP is the IP of gowog server which is localhost:8080 now.
npm run dev -- --env.HOST_IP=localhost:8080
Open the browser "localhost:3000"
Note:
In development we run client on port 3000 and server on port 8080 separately.
In production and docker environment, the client is built and golang server will return client page on the same port 8080. Therefore, if we run docker environment, the game will start at "localhost:8080" in browser.
Communication packages between server and client is based on protobuf. Install protoc for protobuf generate.
Everytime you change package singature in /sertver/message.proto. Run
-
go to
gowog/server
-
/generate.sh
Building a massively multiplayer game is very difficult and it's currently overlooked. You have to ensure the latency is acceptable, handle shared states concurrently and allow it to scale vertically. Golang provides a very elegant concept to handle concurrency with goroutine and channel.
The gameplay is mainly for demonstration purpose. My goal is to keep the game simple as current and scale number of players vertically while maintaining good latency (< 100ms). I welcome all of your ideas to make the game more scalable.
However, I'm still open to Graphic improvement and client codebase refactor. I would love to see some particles burst or glow, motion effects. Remember that different people have different perspective on how the game should look, so we need full consensus before making ui change.
To optimize package size, we need to compress it into binary. Protobuf offers fast language-neutral serialization and deserilization, so Golang server can communicate with JS client in an optimal way.
We can consider faster serilization format like Cap'n Proto or FlatBuffers.
In my opinion, room-based is less challenging because each room is totally separated from each other and we can scale the game easier by adding more instances. This repo is to illustrate how many players the game can serve on one multi-core single machine.
And of course my ultimate goal is to make the non room-based game scale vertically by adding more instances.
I'm looking forward to have your contribution to GOWOG, which can help the game smoother and more scalable. If you have any ideas to improve game performance, please discuss in this issue Discussion.
I also welcome frontend improvement like codebase reorganization, performance enhancement. In the case you want to improve the UI, please create an issue to show the new design so we can make an agreement on that.
As my desire is to utilize Golang concurrency paradigm to achieve smooth gaming experience with massive number of players, I will keep the gameplay simple. Player can move around and shoot each other. Any gameplay changes are not accepted.
https://github.com/gorilla/websocke/blob/master/examples/chat
https://github.com/RenaudROHLINGER/phaser-es6-webpack
https://github.com/huytd/agar.io-clone (My inspiration)
Nguyen Huu Thanh
https://www.linkedin.com/in/huuthanhnguyen/