gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Wireless Problems(liblobby and rooms)(SOLVED)

#143944 - yellowstar - Sat Oct 27, 2007 5:52 pm

I am having troubles with wireless and rooms.

The host isn't detecting the clients,
once joined.(it was doing this even before the client
started having problems.)

The Client isn't detecting
the host.(It was detecting it before,
but now it won't)

For the client I'm using the following line of code
to get the host of a room.
(I was looking for something like LOBBY_GetUserByRoom,
but I found the below)
Code:

user=LOBBY_GetRoomUserBySlot(room,0);


Please help with my sprites problem.
This game can't be finished untill
it is solved.

Code:

void UserInfoCallback(LPLOBBY_USER user, unsigned long reason)
{

 if(host && !started && search_user==NULL)//This function would be called,
 //even after the game goes to game.cpp
 {
  if(user==LOBBY_GetUserByID(USERID_MYSELF))
  return;//Stop the host from detecting itself.
 
  if(reason == USERINFO_REASON_ROOMCHANGE)
  {
   if(LOBBY_GetRoomByUser(user)==LOBBY_GetRoomByID(ROOMID_MYROOM))
   {
   search_user=user;
   }
  }
 }

}

LPLOBBY_ROOM QueryRooms()//Search through all the rooms,
//and return a room for this game.
{
unsigned short i=0;
LPLOBBY_ROOM cur_room;

   while(1)
   {
   cur_room = LOBBY_GetRoomByID(i);
   
   if(cur_room==NULL)return NULL;
   
   i++;
   
   if(LOBBY_GetRoomGameCode(cur_room)!=GAMECODE)continue;
   //skip
   
   //if(LOBBY_GetRoomVersion(cur_room)!=VERSION)continue;
   //skip
   //Commented out because of minor bug in above function.
   //(returns gamecode instead of version)
   
   if(LOBBY_GetUsercountInRoom(cur_room)>=
   LOBBY_GetMaxUsercountInRoom(cur_room) )
   continue;//When room is full, skip it.
   
   break;
   
   }
   
   return cur_room;
}

LPLOBBY_USER FindRooms()
{
LPLOBBY_ROOM room;
LPLOBBY_USER user=NULL;

 if(!host)
 {
 room=QueryRooms();
  if(room==NULL)
  {
   for(int i=0;i<=10;i++)
   {
   room=QueryRooms();
   
   if(room!=NULL)
   break;
   }
  }
 
 if(room!=NULL)
 user=LOBBY_GetRoomUserBySlot(room,0);
 }
 
 if(host)
 {
  if(search_user!=NULL)
  user=search_user;
 }

return user;
}

void FindPlayers()//This function finds other players to play with.
{
LPLOBBY_USER found_user=NULL;
LPLOBBY_ROOM found_room=NULL;
bool found=false;

if(host)LOBBY_CreateRoom("GoPongRoom",2,GAMECODE,VERSION);

   while (1)
   {
      
      scanKeys() ;
      
      DebugPrint();
      
      found_user=FindRooms();
      
      if(found_user!=NULL)
      {
      
         if(!host)
         {
         found_room = LOBBY_GetRoomByUser(found_user);
         
         LOBBY_JoinRoom(found_room);
         
         while(1)
         {
         if(
         LOBBY_GetRoomUserBySlot(
         LOBBY_GetRoomByID(ROOMID_MYROOM),1)==LOBBY_GetUserByID(USERID_MYSELF))
         break;
         }
         
         }
         
         if(host)
         {
         
         
         
         }
         
         found=true;
      
      }
      
      if(found)
      {
      player = found_user;
      //DoStuff


EDIT:
I solved it. I rewrote the whole game, and the connecting code,
and now it works. I'm now having problems with the game now...


Last edited by yellowstar on Mon Dec 24, 2007 12:18 am; edited 4 times in total

#143953 - Mighty Max - Sat Oct 27, 2007 7:56 pm

I just noticed, i left a change in the lobby code, that i didn't want to.
It doesn't matter as long as client and host are compiled against the same lobby version. (Otherwise they might use different channels)

If this is the problem, do a make clean & make and copy the same version to each NDS.
_________________
GBAMP Multiboot

#143954 - yellowstar - Sat Oct 27, 2007 8:06 pm

The Host and Client are in the same NDS.(At the start
of the game, it asks wether the player wants to be a host or client)

#143958 - Mighty Max - Sat Oct 27, 2007 8:22 pm

Now after reading through your code:

- make sure search_user is volatile. But better here: check the users which are within the room: LOBBY_GetRoomUserBySlot(LOBBY_GetRoomByID(ROOMID_MYROOM),1)

- You are iterating through all room's exactly once. If the room was not recognized yet at this call, you will call LOBBY_GetRoomUserBySlot & LOBBY_JoinRoom with a NULL value, causing no action. And you will still flag found=true;

- You can only assume a succeeded roomjoin, when LOBBY_GetRoomByID(ROOMID_MYROOM) returns non-0. (Which is not set instatntly after the join, but when the room owner replies to the join request)
_________________
GBAMP Multiboot

#143960 - yellowstar - Sat Oct 27, 2007 8:40 pm

I can't test the above right now.
(The computer which has this project on it
is being used right now.)

Mighty Max wrote:

- You can only assume a succeeded roomjoin, when LOBBY_GetRoomByID(ROOMID_MYROOM) returns non-0. (Which is not set instatntly after the join, but when the room owner replies to the join request)


When does the host reply to the join request?

Is it handled by the lib,
or does it happen when the host sends a
message to the client?(whom just joined?)

#143961 - Mighty Max - Sat Oct 27, 2007 8:45 pm

yellowstar wrote:

When does the host reply to the join request?


The host will on receive try to put the new user into the room.
The host then sends a userinfo to all users. If one of the userslots in this info changed relative to the cached info on the client DS, the roomjoin is recognized and a userinfo callback triggered.
_________________
GBAMP Multiboot

#143964 - yellowstar - Sat Oct 27, 2007 9:34 pm

I tried the above,
but both the host and client still
do the same thing.

#143965 - Mighty Max - Sat Oct 27, 2007 9:41 pm

Try outputting the userinfo callbacks, to check whether they really don't see each other/the rooms or just the logic is screwed.
_________________
GBAMP Multiboot

#143967 - yellowstar - Sat Oct 27, 2007 9:56 pm

I did that.

The host outputed the callback data correctly,
while the client didn't output anything.

The host reconizes the other player.(for the players,
not the rooms)
It detects that it,(the host, which is this DS)
changed its room.
It detected that the other player
had a timeout.(that was probably when I
turned that DS off.)

#143968 - yellowstar - Sat Oct 27, 2007 10:22 pm

The client is saving the debug data
correctly now.

It is only detecting the other player,(only for the player stuff,
not the rooms)
and a timeout for that player.(probably caused when
I turned that DS off.)

#143969 - Mighty Max - Sat Oct 27, 2007 10:23 pm

Well chances are that the client crashes.

And if you are still trying to get a room of a null user, this will be the case. (There are a lot of functions which needs more parameter checking)
_________________
GBAMP Multiboot

#143971 - yellowstar - Sat Oct 27, 2007 10:34 pm

I have updated the source in the first post.

#143974 - Mighty Max - Sat Oct 27, 2007 10:58 pm

You are now waiting for the user beeing part of the room, before attempting to join the room.

It is hard to read without proper formating, and the break/continue constructs doesn't help either ;)

PS: don't forget that the LOBBY_Update has to be called. If you use the above function within an IRQ (IE=0) and busy-wait for the join, it will most likely never continue, as there is no IPC-Filling, WIFI-Resending, etc going on.
_________________
GBAMP Multiboot

#143980 - yellowstar - Sat Oct 27, 2007 11:48 pm

I have updated the source.

No,
it's not be being called from an IRQ.
(it's being called from main.)

#144005 - yellowstar - Sun Oct 28, 2007 3:36 am

I have found from my tests
that the host is crashing.
But, according to those tests,
the client isn't crashing.

I had a debug file created on
startup,
and in the VBlank IRQ,
I would have it print the value
of a var,
which would be flipped
after the print.

When the var wouldn't change,
that meant it crashed.