Jump to content

  • Log In with Google      Sign In   
  • Create Account


Network server for a turn-based strategy game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Murmix   Members   -  Reputation: 154

Like
0Likes
Like

Posted 18 November 2011 - 04:08 AM

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();
}


Daniel Molnar
MCTS: MS SQL 2008 and .NET Framework 4
daniel@murmix.com

Murmixsoft
http://www.murmix.com

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS