Learn about the Guest login process through server logs and client packet capture
series
- Cloud native project practice DevOps(GitOps)+K8S+BPF+SRE, from 0 to 1 using Golang to develop production-grade Mahjong game server — Part 1
- Cloud native project practice DevOps(GitOps)+K8S+BPF+SRE, from 0 to 1 using Golang to develop production-grade Mahjong game server — Part 2
introduce
This will be a complete, fully implemented Golang game server development tutorial series for DevOps/GitOps and cloud processes on Kubernetes.
This series of tutorials is a complete teardown of the open source Nanoserver project, designed to help you get started on the Golang server backend. Understand the essence of Golang development through practice — Share memory by communication.
The project may also involve work on Linux performance tuning (BPF related tools) and system assurance (SRE).
Step By Step development Mahjong Server
Monomer architecture
understandMahjong Server
Business – >Nano Distributed Game Server
+Micro service
Transformation.- Demo: go – mahjong – server
Analysis of visitor login service
Guest login is mainly used to develop and debug programs.
Review the Nano framework
For a quick start on Nano Game Server, please refer to my previous post -> 5 Minutes to start Nano Game Server framework
The Nano term
- Components (
Component
) :nano
The functionality of an application is loosely coupledComponent
Made up of eachComponent
Complete some features. Handler
: It is defined inComponent
To handle specific business logic.- Routing (
Route
) : Used to identify aThe specific service
Or the client receives the message pushed by the serverlocation
. - Session (
Session
) : After the client connects to the server, a session is established to hold some context information during the connection. The connection is released after disconnection. - Group (
Group
) :Group
You can view it as aSession
For scenarios where push messages need to be broadcast. - Request (
Request
Response (),Response
), notify (Notify
), push (Push
) :Nano
Four message types in.
The life cycle of Nano components
type DemoComponent struct{}
func (c *DemoComponent) Init(a) {}
func (c *DemoComponent) AfterInit(a) {}
func (c *DemoComponent) BeforeShutdown(a) {}
func (c *DemoComponent) Shutdown(a) {}
Copy the code
Init
: will be called when the component is initialized.AfterInit
: will be called after the component is initialized.BeforeShutdown
: will be called before the component is destroyed.Shutdown
: is called when the component is destroyed.
The entire component life cycle seems very clear.
forNano
Enable Debug mode for Game Server
Internal /game/game.go, I added nano.withdebugMode ()
nano.Listen(addr,
nano.WithPipeline(pip),
nano.WithHeartbeatInterval(time.Duration(heartbeat)*time.Second),
nano.WithLogger(log.WithField("component"."nano")),
nano.WithSerializer(json.NewSerializer()),
nano.WithComponents(comps),
nano.WithDebugMode(),
)
Copy the code
Start the game server and view its startup log
This is mainly to understand what games are registered when Nano Server is started 🎮 business logic.
The current server is running in Singleton mode. Nano can also run as a distributed system, it has a small built-in distributed system design (learn its architecture, get started with distributed system development).
From the log, we can clearly see that Nano has registered three components Manager, DeskManager and ClubManager, which are used to manage all the game 🎮 business logic.
Manager (Handlers) :
- Manager.CheckOrder
- Manager.Login
DeskManager (Handlers) :
- DeskManager.DissolveStatus
- DeskManager.QiPaiFinished
- DeskManager.VoiceMessage
- DeskManager.ClientInitCompleted
- DeskManager.Exit
- DeskManager.OpChoose
- DeskManager.Ready
- DeskManager.UnCompleteDesk
- DeskManager.DingQue
- DeskManager.Dissolve
- DeskManager.Join
- DeskManager.ReJoin
- DeskManager.RecordingVoice
- DeskManager.Resume
- DeskManager.CreateDesk
- DeskManager.Pause
- DeskManager.ReConnect
- DeskManager.ReEnter
ClubManager(Handlers):
- ClubManager.ApplyClub
Analyze Nano Debug logs and Charles captures
How do I proxy apis to local Nanoserver and capture HTTP requests? -> < p style = “max-width: 100%; clear: both
Charles API capture
We can clearly see that this operation calls two apis:
/v1/user/login/query
-> Check whether the function is enabledGuest login
POST http://192.168.31.125:12307/v1/user/login/query HTTP / 1.1 the content-type: application/json {"channelId": "konglai"."appId": "konglai"
}
Copy the code
/v1/user/login/guest
-> Perform visitor login
POST http://192.168.31.125:12307/v1/user/login/guest HTTP / 1.1 the content-type: application/json {"channelId": "konglai"."appId": "konglai"."imei": "c0a4ce912c48a3d0b17b59e6b97f1dca"
}
Copy the code
Server Debug logs are generated
We see the following key information output by Nano Server:
Message={ Request Manager.Login }
Message={ Request DeskManger.UnCompleteDesk}
According to the Game Server address 192.168.31.125:33251 returned by Web API(v1/user/login/guest), the client made socket connection and communicated with Nano Game Server.
For a quick start on the Nano protocol, you can see: 3 minutes to understand the Nano protocol (including memory brain map).
Finally, a sentence describes the business process
The user clicks the login button -> Query whether the server has enabled Guest login -> (If enabled?) Log in to the visitor -> get the game server address -> Connect to the game server -> (successful connection?) Enter the game hall
The detailed business and code logic of the login process will be discussed in detail in the next article.
I am weishao wechat: uuhells123 public number: hackers afternoon tea add my wechat (mutual learning exchange), pay attention to the public number (for more learning materials ~)Copy the code