Stuck Room

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
ekrem5353
Posts: 118
Joined: 10 Dec 2015, 15:50

Stuck Room

Postby ekrem5353 » 25 Sep 2017, 12:39

Hey,

I am using SmartFox version 2.11. when the game room stuck I see it on the zone monitor but whe I click monitor selection
it says room being monitored is no more available on the server, please select another one

users continue playing the game

Code: Select all

 Room room = zone.getRoomByName(roomName);  this returns null but
 
  if(room == null) {
            MatchExpression playNow = new MatchExpression(RoomProperties.IS_GAME, BoolMatch.EQUALS, true)
                    .and(RoomProperties.NAME, StringMatch.EQUALS,roomName);
            List<Room> roomList = getApi().findRooms(zone.getRoomList(),playNow, 0);
            if(roomList != null && roomList.size() > 0) {
                room = roomList.get(0);
            }
        }




this way I can find the room.

I thought this might be usefull information for you

thanks
User avatar
ekrem5353
Posts: 118
Joined: 10 Dec 2015, 15:50

Re: Stuck Room

Postby ekrem5353 » 25 Sep 2017, 13:51

I also added some new code we had RoomVariable
this isnt exact code but it is something like that when user sent join room request handler

we change these slot infos put its name there. when user leaves the room, we remove these info but problem happens when things happened concurrently so I used a lock object in ZoneExtension like Object slotChangeInfoLock = new Object();


Code: Select all

synchronized(zoneExtension.slotChangeInfoLock) {
SFSObject slotInfo = new SFSObject();
slotInfo.putUtfString(

like RoomVariable roomVar =new RoomVariable("slot1", slotInfo);   
}


when user send join room request before I change room variable I used synchronized part it seems stuck room thing increased but I am not hundred percent sure.

Thanks
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Stuck Room

Postby Lapo » 26 Sep 2017, 13:17

Sorry but the code above doesn't look right, after the putUtfString( it doesn't make sense anymore.

Why do you need do synchronize the creation of an SFSObject? There's no need to do that.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
ekrem5353
Posts: 118
Joined: 10 Dec 2015, 15:50

Re: Stuck Room

Postby ekrem5353 » 26 Sep 2017, 14:16

hi
I didnt want to bother you with too much code


actual code...



Code: Select all

// User sends which slot he or she wants to sit
public class JoinRoomExtReq extends BaseClientRequestHandler {

     @Override
    public void handleClientRequest(User user, ISFSObject obj) {
         String roomName = obj.getUtfString("roomId");
        boolean isSpectator = obj.getBool("isSpectator");
        obj.getInt("slotId")


*********alot of code here***

synchronized (zoneExt.slotSetLock) {

              RoomVariable rv = room.getVariable(GlobalStrings.SLOT + slotId);
              if (rv.getSFSObjectValue().getUtfString(GlobalStrings.USER_NAME) == null) {

                  boolean hasJoinedSlot = gco.roomVariableSetter(user, room, slotId, getParentExtension(), false, false);
                  try {
                      if (!hasJoinedSlot) {
                          return;
                      }
                      getApi().joinRoom(user, room, null, isSpectator, null);

                  } catch (SFSJoinRoomException ex) {
                      trace(user.getName(), ExtensionLogLevel.ERROR, ex);
                  }
              } else {

                  String userName = rv.getSFSObjectValue().getUtfString(GlobalStrings.USER_NAME);
       
                  User potentialRobot = room.getUserByName(userName);
                  if (potentialRobot != null && potentialRobot.isNpc()) {

                      new GlobalClientOperations().roomVariableSetter(potentialRobot, room, slotId, getParentExtension(), true, false); 
                      getApi().disconnectUser(potentialRobot);
                      try {

                          boolean hasJoinedSlot = gco.roomVariableSetter(user, room, slotId, getParentExtension(), false, false); 
                          if (!hasJoinedSlot) {
                              return;
                          }
                          getApi().joinRoom(user, room, null, false, null);
                      } catch (Exception ex) {
                          gco.roomVariableSetter(user, room, slotId, getParentExtension(), true, false);
                          trace(ExtensionLogLevel.ERROR, ex);
                      }
                  }

              }
          }



and RoomVariable setter


Code: Select all

public boolean roomVariableSetter(User user, Room room, int slotNo, SFSExtension ext, boolean isNull, boolean isPause) {

            /**
             * When a user join the room the user screenName and photo should be
             * added to the user slot.
             */
            ISFSObject obj = SFSObject.newInstance();

            if (isNull) {
                obj.putNull(GlobalStrings.USER_NAME);
            } else {

                obj.putUtfString(GlobalStrings.USER_NAME, user.getName());
   
            }
            obj.putBool(GlobalStrings.IS_PAUSE, isPause);
            obj.putInt(GlobalStrings.SLOT_ID, slotNo);

            RoomVariable roomVar = new SFSRoomVariable(GlobalStrings.SLOT + slotNo, obj);
            roomVar.setPrivate(true);
            roomVar.setGlobal(true);

            List<RoomVariable> list = new ArrayList<>();
            list.add(roomVar);

            ext.getApi().setRoomVariables(user, room, list);

        return true;
    }


When user leave event happens variablesetter gets called again and Room variable changes but before this event happens if someone else cals joinRoomReq it might write over it..


Thanks

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 80 guests