Game room is not removed when empty

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

Moderators: Lapo, Bax

grhwood
Posts: 116
Joined: 15 Mar 2011, 04:43

Game room is not removed when empty

Postby grhwood » 21 Mar 2011, 03:03

Hi,

I use my extension to create room on server side by using the SFSApi#createRoom method.
The docs said that game rooms are removed when empty,but it is still there.

Thank you.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 21 Mar 2011, 09:04

Please show the code you use to create the room.
Paolo Bax
The SmartFoxServer Team
cowieaaron
Posts: 15
Joined: 02 Mar 2011, 14:12

Same issue

Postby cowieaaron » 23 Mar 2011, 12:52

Hi, I'm also having this issue.
Below is my code for creating games.

Games show up in other clients as having no participants, yet they still exist until a server restart.

Code: Select all

package RTS;

import com.smartfoxserver.v2.SmartFoxServer;
import com.smartfoxserver.v2.annotations.Instantiation;
import com.smartfoxserver.v2.annotations.Instantiation.InstantiationMode;
import com.smartfoxserver.v2.api.CreateRoomSettings.RoomExtensionSettings;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.SFSRoomRemoveMode;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.exceptions.SFSCreateRoomException;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import com.smartfoxserver.v2.game.CreateSFSGameSettings;

@Instantiation(InstantiationMode.SINGLE_INSTANCE)
public class NewGame extends BaseClientRequestHandler {
   
   public NewGame() {
      
   }

   @Override
   public void handleClientRequest(User sender, ISFSObject params) {
      ServerExtension server = (ServerExtension)(this.getParentExtension());
      SmartFoxServer sfs = SmartFoxServer.getInstance();
      String gameName = params.getUtfString("game_name");
      
      trace("Creating new game: "+gameName+"\n");
      
      //Create new game room
      CreateSFSGameSettings settings = getGameSettings(gameName);
      ISFSObject msg = SFSObject.newInstance();
      msg.putBool("status", true);
      Room game;
      try {
         //Create Game
         game = sfs.getAPIManager().getGameApi().createGame(server.getParentZone(), settings, sender);
         msg.putUtfString("game_room", game.getName());
         server.addGame(game);
      } catch (SFSCreateRoomException e) {
         trace("Error: Game could not be created."+e.getMessage());
         msg.putBool("status", false);
         e.printStackTrace();
      }
      
      send("newGameResponse", msg, sender);
   }
   
   private CreateSFSGameSettings getGameSettings(String name){
      RoomExtensionSettings gameExtensionSettings = new RoomExtensionSettings("RTSServer","RTS.GameExtension");
      CreateSFSGameSettings settings = new CreateSFSGameSettings();
      settings.setName(name);
      settings.setGroupId("games");
      settings.setGame(true);
      settings.setGamePublic(true);
      settings.setMinPlayersToStartGame(1);
      settings.setMaxUsers(10);
      settings.setMaxSpectators(20);
      settings.setMinPlayersToStartGame(1);
      settings.setMaxVariablesAllowed(10);
      settings.setAutoRemoveMode(SFSRoomRemoveMode.WHEN_EMPTY);
      settings.setExtension(gameExtensionSettings);
      return settings;
   }
}
cowieaaron
Posts: 15
Joined: 02 Mar 2011, 14:12

Oops nvm

Postby cowieaaron » 23 Mar 2011, 13:41

Figured it out.

I hadn't done

Code: Select all

settings.setDynamic(true);


Its weird that these things don't have sensible defaults (considering this is a game room).

For anyone interested,

Code: Select all

trace(game.getDump())
is a handy way to check everything is set correctly (outputs to server log).

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 76 guests