Learn about the Guest login process through server logs and client packet capture

series

  1. Cloud native project practice DevOps(GitOps)+K8S+BPF+SRE, from 0 to 1 using Golang to develop production-grade Mahjong game server — Part 1
  2. 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 architectureunderstandMahjong ServerBusiness – >Nano Distributed Game Server + Micro serviceTransformation.
  • 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) :nanoThe functionality of an application is loosely coupledComponentMade up of eachComponentComplete some features.
  • Handler: It is defined inComponentTo handle specific business logic.
  • Routing (Route) : Used to identify aThe specific serviceOr 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) :GroupYou can view it as aSessionFor scenarios where push messages need to be broadcast.
  • Request (RequestResponse (),Response), notify (Notify), push (Push) :NanoFour 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.

forNanoEnable 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:

  1. /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
  1. /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:

  1. Message={ Request Manager.Login }
  2. 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