Forum Multiplayer Check if roomID is taken?

Discussion and help relating to the PlayerIO Multiplayer API.

Check if roomID is taken?

Postby DJamieson » June 5th, 2010, 9:19 pm

Is there any way (short of attempting to connect) to check if a roomID is in use? (I don't believe listrooms is useful in this instance, as it won't return hidden rooms).
DJamieson
 
Posts: 29
Joined: March 4th, 2010, 5:43 pm

Re: Check if roomID is taken?

Postby Oliver » June 7th, 2010, 10:58 am

Hi,

Nope, there is no way to check if a roomid is used by a hidden room.

What are you trying to accomplish?

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Check if roomID is taken?

Postby DJamieson » June 7th, 2010, 11:07 am

I was trying to set up some code that basically said:

x = Random 1-100000
CreateRoom with ID = x

I actually realised shortly after posting this that it was possible to just create a failstate in which if the room wasnt created due to a room with the same ID already existing, I could try again with a new randomly generated ID.

Purely from a speculative point of view (Im completely unaware how the netcode works) it may have been more efficient for both me and your servers if I could ping a quick message saying "does room ID X exist", rather than sending all the information necessary to create a room, and it failing on your end.
DJamieson
 
Posts: 29
Joined: March 4th, 2010, 5:43 pm

Re: Check if roomID is taken?

Postby Oliver » June 7th, 2010, 11:12 am

You can use null as the room id for the createRoom() method (not the createJoinRoom() method), and then you'll get a new room id generated by the webservice.

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Check if roomID is taken?

Postby Benjaminsen » June 7th, 2010, 11:13 am

A quick side note, if you parse null as the roomid on createRoom the system will automatically generate a random room id guaranteed to be unique.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Check if roomID is taken?

Postby DJamieson » June 7th, 2010, 11:25 am

Aye, I was aware of that, but I set up private rooms and I wanted roomIDs to be easy for users to type (a 6 digit code) rather than the null generation which was 20-odd mixed characters.
DJamieson
 
Posts: 29
Joined: March 4th, 2010, 5:43 pm

Re: Check if roomID is taken?

Postby Benjaminsen » June 7th, 2010, 11:38 am

DJamieson wrote:Aye, I was aware of that, but I set up private rooms and I wanted roomIDs to be easy for users to type (a 6 digit code) rather than the null generation which was 20-odd mixed characters.


Fair point. I had the same issue with EverybodyEdits and in the end build a system where people could link directly to rooms, thus ensuring that people don't have to type it in. Yes I am aware that EE does not have truly private rooms, but it would be an easy matter of simply not listing such in the lobby.

/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Check if roomID is taken?

Postby Oliver » June 7th, 2010, 11:43 am

Aye, I was aware of that, but I set up private rooms and I wanted roomIDs to be easy for users to type (a 6 digit code) rather than the null generation which was 20-odd mixed characters.


Generate a random id of length 6, try to create the room. If it fails, generate new id of length 7, try to create room, etc, for maybe max 5 retries.

That should put you totally in the clear, and 99% will never fail the first test.

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Check if roomID is taken?

Postby DJamieson » June 7th, 2010, 12:05 pm

That sounds like a good idea, actually.

While my code currently works, I still feel the option I've taken (code below) is a little... messy? Perhaps its just my own personal programming style, but expecting fails (and comparing strings) just doesn't make me entirely happy.

If you chaps know of a better way of doing it, I'd appreciate comments. (Also, Im not sure where the the error String comes from; if its external code, and someone changes the string, it'd break things)

(note: attemptToConnect simply randomises an ID and attempts to create a room. If the creation fails, roomError is the callback function for that.)

Code: Select all
      private function roomError(error:String):void {
         if (error == "Error: You are unable to create room because there is already a room with the specified id") {
            timeToFail++;
            if (timeToFail < 100) {
               attemptToConnect();
            }
            else {
               trace("Too many attempts to connect. Dropping.");
            }
         }
      }
DJamieson
 
Posts: 29
Joined: March 4th, 2010, 5:43 pm

Re: Check if roomID is taken?

Postby Oliver » June 7th, 2010, 12:19 pm

Hey,

The actual type of the thing being sent to the error callback is "PlayerIOError" and should be able to check if it's PlayerIOError.RoomAlreadyExists

http://playerio.com/documentation/refer ... eadyExists

(i'm not an as3 guy, so i'm not sure exactly how...)

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Check if roomID is taken?

Postby DJamieson » June 7th, 2010, 1:08 pm

Ah, didnt realise that.

Code: Select all
      private function roomError(error:PlayerIOError):void {
         if (error.errorID == 15) {


Is working fine, and seems a lot more stable than string checking.

Many thanks for that.
DJamieson
 
Posts: 29
Joined: March 4th, 2010, 5:43 pm

Re: Check if roomID is taken?

Postby Oliver » June 7th, 2010, 2:43 pm

I think you can make that

Code: Select all
if(error.errorID == PlayerIOError.RoomAlreadyExists.errorId){


( i think )

- oOliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Check if roomID is taken?

Postby DJamieson » June 7th, 2010, 2:57 pm

You would be correct. Once again, my thanks.
DJamieson
 
Posts: 29
Joined: March 4th, 2010, 5:43 pm


Return to Multiplayer