Forum C# Too many players joining?

Too many players joining?

Postby DJamieson » April 4th, 2010, 8:22 pm

So, Ive set up a basic multiplayer game, which allows 4 players to join. The problem Im having is that theres no way (as far as I can see) to prevent further players joining. (Im discounting making the room invisible, which due to lag isnt an effective method of dealing with it)

What there is, as far as I can see, is a join method in the C#, which I have:
Code: Select all
        public override bool AllowUserJoin(Player player)
        {
            Console.WriteLine("This is player"+PlayerCount);
            if (PlayerCount == 4)
            {
                return false;
            }
            return base.AllowUserJoin(player);
        }

Which sortof works: it allows a player to join, but immediately kicks them.
However, in my AS code, I have

Code: Select all
      private function handleJoin(c:Connection):void{
         trace("Successfully connected to the multiplayer server");
                }

      private function handleError(error:PlayerIOError):void{
         trace("Got", error);
      }


Joining a "full game" will always count as a successful join, even if the player is immediately kicked.

It seems to me that a failed join should count as an error, with an appropriate error message. As it is, I have the player join the game, see if they are kicked, and if so remove them again, which seems messsy.

Is there a better way for me to do this?
DJamieson
 
Posts: 29
Joined: March 4th, 2010, 5:43 pm

Re: Too many players joining?

Postby fox1980 » April 6th, 2010, 12:51 am

Hello DJamieson,

I'm also new to these boards and only been messing with PLayerio for a couple of days, so sorry if my post is incomplete.
I also ran into this "problem" and what i did was check if the room was full on the server and if so, send a message back to the client. Using your code it would be something like this:

Code: Select all
public override bool AllowUserJoin(Player player)
        {
            Console.WriteLine("This is player"+PlayerCount);
            if (PlayerCount == 4)
            {
                player.Send("Full");
                return false;
            }
            return base.AllowUserJoin(player);
        }


Then you write an AS3 function to handle "Full" message. Try to join another room, alert the user, whatever you want to happen when the room is full.
fox1980
 
Posts: 206
Joined: April 1st, 2010, 10:39 pm

Re: Too many players joining?

Postby DJamieson » April 6th, 2010, 7:32 am

Many thanks fox, I'll give that a try just now. The docs say that Broadcast doesn't work for players at this stage, so I had assumed send wouldn't either.

At either rate, I still feel that it'd be better for the failed join to count as an error rather than a successful join, but I'll work with what I have.
DJamieson
 
Posts: 29
Joined: March 4th, 2010, 5:43 pm

Re: Too many players joining?

Postby fatezero » April 6th, 2010, 8:37 am

Well, I'm not sure if this helps, but another approach is to use BasePlayer::Disconnect() and then listen for it with Connection::addDisconnectHandler in your AS3 script. So you don't lose out on disconnect-listening functionality, you'd probably want to have two disconnect functions; one for "room too full", and then a traditional disconnect func. That way you can add the disconnect handler with the "room too full" function pre-joining a room, remove it afterwards, and then use the traditional disconnect func.

Just another way to handle it, I guess.
fatezero
 
Posts: 3
Joined: March 31st, 2010, 11:02 pm


Return to C#