• Advertisement
Sign in to follow this  

Network server for a turn-based strategy game

This topic is 2258 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

Hello Gamedev'ers,

I recently started coding a simple multiplayer turn-based strategy game.
My tools of choice (for now) are C#, XNA for Windows, Lidgren Network and MSSQL.

Now, I haven't done any multiplayer stuff since experimenting with DirectPlay last millenium,
so I sat down and drew some pseudocode how I imagine the game server would work.

I'm starting coding it right now, and it would be of great value to me if you wanted to look at my pseudocode, to see if something is horribly wrong or give general feedback.

Thank you in advance.

Best regards,
Daniel Molnar

********************************************************
Pseudocode for the GameServer application below:

********************************************************


////
enum GameServerStates
{
Error = 0,
Initializing,
WaitingForPlayerSelectBaseTile,
WaitingForPlayerMove,
GameOver
etc.
}

////
enum DataMessageTypes
{
Error = 0,
PlayerLogin,
StartNewGame,
MovementUpdate,
SelectedBaseTile,
AttackUpdate,
RequestFullClientSync,
SendFullClientSync,
PlayerChat,
etc
}

//// the main GameServer class
class GameServer
{
start Lidgren server with DAL.LoadConfiguration();

Loop forever:

for each incoming message
{
read [GameId] from Message and send it to the specific game instance
Game[GameId].HandleMessage();
}

for each active Game instance
{
//do special and timed events for all active games
Game.SendTimedUpdateOrWhatever();

if (Game.ServerState == GameOver)
{
game.ShootFireworksAndStuffAndThenDisconnectOrWhatever();
DAL.SaveGameDetails();
}

}

}

//// one class instance per active game
Game
{
int myGameId;
GameServerStates myGameServerState;
List<Player> ConnectedClients;

HandleMessage(DataMessage)
{
switch(DataMessage.DataMessageTypes)
{
case DataMessageType.MovementUpdate:
//do movement update server logic
//send relevant messages back to all clients
break:

case etc etc (do relevant server updates for each DataMessageType)
}
}
}

////connects to a MS SQL Server with LINQ
GameServer.DAL
{

//Server configuration, ip address, port, etc. is read from the database
LoadConfiguration();

//when a game is finished/paused/cancelled, the details are flushed to the database: game id, players, result, etc.
SaveGameDetails();

//Bring back a saved/unfinished game from the db
LoadGameDetails();

//read statistics (high-score lists, etc.) from db
LoadStatistics();

//simplest possible login: username and password (password only needed if you want to "register" your username)
LoginPlayer();

EtcEtcDBrelatedstuff();
}

Share this post


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

  • Advertisement