Game Server Source code overview
Tutorial Source code :
This class has 2 parts.the first part will invoke the WebSocket HandShake mechanism that send confirmation back to the client so the connection will be upgraded to open TCP socket connection .
The second part will handle the WebSocket Request and decode the incoming text to massage text for the Game Server to handle.
- Lines 14 - 23 : this is the WebSocket Handshak , remember the WebSocket dialog sequence between the client and the server performed in this order :
A .the client send HTTP request to see if the server support WebSocket
and inform the server the future connection type is WebSocket ,
B. if confirmed by the server the connection is UPGRADED to TCP open connection between the client and the server ,
- Lines 28 - 29: the incoming request from the client as string.
- Line 32: send the string to Game Event Handler , which is a object that handle events and according to the event type it constructing and sending the response's back to the clients.
- Lines 35 - 44 : handle the response and send them back to the clients which are connected .
- Lines 55 - 58 : write the actual WebSocket Frame to the open connection channel.
WebSocket Frame is encapsolated Netty object that handle WebSocket data .
this is helper function which using the player Channel member to send the data .
This class Is the "glue" that connects all the game logic It holds the Cards Map.
And the players map container and the response dispatcher.
and it should also have the Game event Handler which will be done in the next version .
- Line 3 : array of the cards. those are the key names of the game cards are sorted by order.
- Line 5 : the map which maps between the cards names and the cards key names.
- Line 6 : the players container from type Ordered Map . the key set by the order the player login.
- Line 7: is the deck of cards in between the players,where each player show its cards in its turn.
- Lines 17-18:shuffle the cards .
- The rest are just simple small helper functions and getters and setters that are self explanatory.
Next we going to analize the game logic continue to the next post :
Multiplayer Card Game using WebSockets,Java Netty Server ,Cocos2d-x-HTML5 - Part 4