Game Background: The room category multiplayer online battle game
Server Function: non-battle fighting communication means for communicating +
Development Environment: golang + protobuf + logrus + mongodb
Project Address: https://github.com/iwangyao/DemoServer
Takeaways
A. Server open
2. Each coroutine connection with the client, the client message cycle time, using a message obtained by the message processing center processing
3. Write a simple client to connect test
II. Communication Protocol Model
1. The protocol is divided into three layers: the message type, message commands the second layer, the third layer message body
2. Protocol codec: encoding, message type Int32, Int32 command message, the message body protobuf encoding, together with agreement in front of length coding; decoding, protobuf determining the type of the message body and message command according to the type, use the appropriate decoding method .
3. Test, the client will need to test coded message sent to the server, the server decodes
III. Module division
1. Log: opening the client each time a new transmission uuid (device id), whether there is a corresponding server according to the user id uuid check the database, users Id is returned, not the new one entry, the new user id back to the client
2. Match: Use a matching room management information matches, the client sends a request message match, the server will be added to the client information matches the room, each request in a separate Goroutine, in order to avoid excessive players simultaneously enter a multiplayer matching room, the player is added to match the room, lock control, and then complete the unlock.
3. Combat: Battle using a frame synchronization, each player will be sent to the operation information, player information collected after the Qi, then broadcast, in order to avoid a player lead the entire fight card players have to wait, set the timeout to direct broadcasting.