Forum C# AllowUserJoin

AllowUserJoin

Postby highondota » May 27th, 2011, 6:24 pm

Used the same code from the Multiplayer->Serverside Code Tutorial page
Code: Select all
public override bool AllowUserJoin(MyPlayer player) {
   int maxplayers; //Default
   //Parse roomdata
   if (!int.TryParse(RoomData["maxplayers"], out maxplayers)) {
      maxplayers = 4; //Default
   }
   //Check if there's room for this player.
   if (Players.Count < maxplayers - 1) {
      return true;
   }
   return false;
}

and i get a KeyNotFoundException Error for maxplayers with the following message:
The given key was not present in the dictionary.

PlayerIO Version is 2.2.2 and am connecting to the server using the NewGame file. Please Advise.
highondota
 
Posts: 5
Joined: February 7th, 2011, 2:45 pm

Re: AllowUserJoin

Postby Henrik » May 28th, 2011, 12:41 pm

The error message says that there's no property called "maxplayers" in the room data. Are you setting this property when you create the room?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: AllowUserJoin

Postby highondota » May 29th, 2011, 7:12 am

No I have not set its properties, should it be done in GameStarted() and if so how?

The same code worked in versions prior to 2.2 ie. 2.1 and below it worked perfectly but now it gives that error.

The workaround used currently is: (this is because I only need 2 players in a room at any given moment)
Code: Select all
public override bool AllowUserJoin(Player player)
        {
            if (PlayerCount == 2)
                return false;

            return true;
        }
highondota
 
Posts: 5
Joined: February 7th, 2011, 2:45 pm

Re: AllowUserJoin

Postby Henrik » May 29th, 2011, 9:17 am

highondota wrote:No I have not set its properties, should it be done in GameStarted() and if so how?


You can do it either when you create the room from the client, or anytime at the server.

http://playerio.com/documentation/refer ... createRoom
http://playerio.com/documentation/refer ... e#RoomData

highondota wrote:The same code worked in versions prior to 2.2 ie. 2.1 and below it worked perfectly but now it gives that error.


It did? It shouldn't, so it's good that it doesn't work anymore. :-)
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to C#