Multiplayer Server: Turn Based Game Server

  

The Turn Based server code that comes with this plugin is a room type used to enforce taking turns in a game similar to words with friends or a players' turn in a poker game. This server can enforce a time limit for players to submit their move and notify each connected player of who's turn it is. The players position or turn order can also be passed to this server as keywords. The timer limit property is called "TimeLimit" and it is passed as apart of the Room data when connecting to a room. It is a number value in milliseconds. To enforce a 30 second turn limit pass a value of 30000. To specify a players' turn order pass the "TurnOrder" property with a zero index value along with the player properties when connecting to a room. The first player in line would be a value of 0. When the players' time is up the server will dispatch the "PlayerTurn" event to notify everyone that it is another players' turn and it will cut off communications from all other players. Only the player who's turn it is can send messages to the other players.

This server type can also enforce a maximum amount of players that can connect to it by passing the "MaxPlayers" property along with the room data when connecting to it. This property name is case sensitive.

Event Descriptions

There are a number of unique events that get fired from this server with or without information attached.

"PlayerTurn" - This event is fired when the current players' turn has changed. The players username will be sent along with this event. The "RoomEntered" event is fired with the current logged in players' username when a player enters the room so you could store that and compare values with the username returned in this event to identify if it is the current players' turn to send message. Remember any messages sent when it is not the current players' turn will be ignored by the server anyway.

"PlayerMove" - Send this message to the server to notify the server that the current player has submitted their move and it is now someone else's turn. If this event is not fired before the time limit is reached, if there is one, then the server will automatically advance the turn to the next player.

"StartMatch" - This message is fired by the server when the room has 2 or more players. The game is considered started and the timer begins.

"RoomEntered" - This event is fired once the player connecting to the room as successfully entered the room and it also returns the current logged in players' username. This is great for knowing which player is the current player when looking through the player list that is returned from the server.

"PlayerList" - This event will return a list of all the players currently connected to the room. Every time a player enters or leaves the room this event gets fired from the server. Use a List Data component to store the list of player usernames that gets returned with this event.

"PlayerJoined" - This event gets fired to all the other players already connected to a room when a new player joins. This is how you will know if you need to create a new object on all the other players' screen if a new player joins, for example a poker table with a new player that joins. The new players username is passed with this event. Keep in mind that only the other players in the room will receive this event not the new player connecting. You will notice in multiplayer tile demo that this event is listened to so that all existing player pieces can tell the new player that they already exist and pass the new player their current state. This is a good way to update the new player of the current state of the game.

"PlayerLeft" - This event gets fired when a player leaves the room.

Room Type name - "TurnBasedServer"

**Note: For events that only return one value make sure to only pass a Data container with one property. Remember all properties are sorted alphabetically when a message is received and then all values are applied to the list of properties on the Data Container component. This is a limitation with the multiplayer server. It does not allow us to send the key names of the property values to the server so we have to sort then to identify which property matches up when the message is received.

Follow Us For Updates