Jump to content
  • Advertisement
Sign in to follow this  
crancran

Game Server Approach Advice

This topic is 3332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The Game Server model I am trying to design must be flexible enough that it will enable me to host various different types of card games, whether it would be poker, blackjack, etc. CGame Represents a game CGameIO Wrapper to my IO completion port system CGameMessage Byte Buffer used for sending/reading data on the socket CGameSession Connected Session CGameServer Game server When a client connects with the game server, the IO completion port system invokes methods in the CGameIO object that instantiate a CGameSession object, associate this session to the completion port and waits for IO. When the client transmits a message to the game server, the CGameIO parses the incoming data and if its known, it creates a CGameMessage object that contains the byte buffer of data read from the socket. Then this method invokes the following method on the session object BOOL CGameSession::HandleMessage(CGameMessage* pMessage) There are certain actions that the session handles directly which doesn't need to handed off to any other object, such as authentication and retrieving basic game information such as what games are available to be played. Therefore, the session object has: BOOL CGameSession::HandleAuthSession(CGameMessage* pMessage); BOOL CGameSession::HandleLogout(CGameMessage* pMessage); BOOL CGameSession::HandleChallenge(CGameMessage* pMessage); BOOL CGameSession::HandleSendChallenge(CGameMessage* pMessage); I also included one additional method called BOOL CGameSession::HandleGameMessage(CGameMessage* pMessage); Inside the HandleMessage() method, there is a very large switch that looks at the message type code that is in the game message object and if its anything that the session wants to process, it then calls the appropriate HandleXX methods. If the message type code is one which should be dispatched to a game object, the HandleGameMessage is invoked. All the HandleGameMessage() method does is: void CGameSession::HandleGameMessage(CGameMessage* pMessage) { *pMessage >> dwGameId; CGame* pGame = m_pGameServer->GetGameById(dwGameId); if(!pGame) return; pGame->ProcessMessage(this, pMessage); } And again this leads me to the same type of model in my CGame object where I have a big switch in my ProcessMessage() method based on the message type code which the client sent which invokes the appropriate HandleXX Method. Now right now I have decided to keep the CGame object simple and only implement a simple Poker game inside the class. But idea here is that CGame would be an abstract class long term with various game objects derived from it. Is this a good way to handle dispatching these messages from a remote client to parts of the game system or is there a better way to handle it? One thing to keep in mind is the entire execution from when a message is parsed and read off the socket and then passed from CGameIO to CGameSession and finally to the CGame object is all done inside that worker thread's execution. The worker threads need to be fast and efficient or else the IO completion port model takes a hit. So I've even thought about simply queuing incoming messages at either the CGameSession or CGame level. Is there any benefit in this? Any help is greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
This seems like a decent approach to me, I would approach the problem quite similarly. In regards to queueing, you probably won't specifically have to queue messages as network packets themselves will be queued on the network card and made available to you through an API. Just call HandleGameMessage() once for each message (I won't say packet as a message could consist of multiple packets).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!