+ Reply to Thread
Results 1 to 7 of 7

Thread: Creating persistent rooms with plugins

Hybrid View

  1. #1
    Member
    Join Date
    Nov 2005
    Posts
    67
    Thanks
    4
    Thanked 2 Times in 1 Post

    Creating persistent rooms with plugins

    Could you provide us with an example showing how to create persistent rooms with server-level plugins.

    I have a server-level plugin calling the following method in that plugin's init method without success.

    Code:
    private void createNewRoom()
        {
        	RoomConfiguration rc = new RoomConfiguration();
        	
        	rc.setName("PersistentRoom_0");
        	rc.setCapacity(10);
        	rc.setDescription("My sweet room");
        	rc.setHidden(false);
        	rc.setFloodingFilterSpecified(false);
        	rc.setUsingFloodingFilter(false);
        	rc.setLanguageFilterSpecified(false);
        	rc.setUsingLanguageFilter(false);
        	rc.setNonOperatorUpdateAllowed(true);
        	rc.setNonOperatorVariableUpdateAllowed(true);
        	rc.setPersistent(true);
        	rc.setPassword("");
        	
        	List <UserConfig> userConfigs = new ArrayList<UserConfig>();
    
        	RoomResponse rr = getApi().createRoom(0, rc, userConfigs);
        	System.out.println(rr.getStatus());
        	System.out.println(rr.isSuccess());
        }

  2. #2
    Electrotank jobem's Avatar
    Join Date
    Apr 2004
    Posts
    996
    Thanks
    0
    Thanked 24 Times in 17 Posts

    Hi,

    What isn't working? ElectroServer would give you an error if you did something wrong.

    Here is some code I used (before the game manager existed) to create a room, associate a plugin to it, and shove some users into it. It is not persistent but adding the setPersistent(true) call will make it persistent.

    Code:
    function newGame(gameTypeOb, userIds, gameProperties) {
    	var responseOb = new EsObject();
    	responseOb.setString("Action", "CreateGameResponse");
    	//importPackage(com.electrotank.electroserver4.extensions.api.value);
    	importPackage(java.util);
    	/*
    	* Create object that describes the room to be created
    	*/
    	var gameId = nextGameId();
    	var roomConfig = new RoomConfiguration();
    	roomConfig.setName("Game"+gameId.toString());
    	roomConfig.setCapacity(-1);
    	//Define the plugin
    	var plug = new ExtensionComponentConfiguration();
    	plug.getVariables().setEsObject("GameProperties", gameProperties);
    	plug.getVariables().setString("GameManagerExtensionName", "GameManager");
    	plug.getVariables().setString("GameManagerPluginName", "GameManager");
    	plug.getVariables().setString("GameId", gameId);
    	plug.getVariables().setString("GameType", gameTypeOb.gameType);
    	plug.getVariables().setString("PluginName", gameTypeOb.gameType);
    	plug.setExtensionName(gameTypeOb.extensionName);//Extension name
    	plug.setHandle(gameTypeOb.pluginName);//Defined name of the plugin in the extensions XML
    	plug.setName(gameTypeOb.gameType);//Instance name of plugin
    	roomConfig.addPlugin(plug);
    	/*
    	* Prep users to go into the room
    	*/
    	var users = new ArrayList();
    	for (var i=0;i<userIds.length;++i) {
    		var userConfig = new UserConfig();
    		//userConfig.setUserId(userIds[ i ]);
    		userConfig.setUserName(userIds[ i ]);
    		users.add(userConfig);
    	}
    	//
    	//var zoneId = 0;
    	//Attempt the room creation. Capture the response
    	var joinExistingZone = true;
    	var zoneName = gameTypeOb.pluginName;
    	var result = getApi().createRoomInNamedZone(zoneName, joinExistingZone, roomConfig, users);
    	//var result = getApi().createRoom(zoneId, roomConfig, users);
    	responseOb.setBoolean("IsSuccess", result.isSuccess());
    	if (!result.isSuccess()) {
    		trace("Failed to create room");
    		var errors = result.getErrors();
    		trace("Errors.length: "+errors.size());
    		var errorArr = new Array();
    		for (var i=0;i<errors.size();++i) {
    			var error = errors.get(i);
    			trace("Error: "+error);
    			errorArr.push(errors.get(i));
    		}
    		responseOb.setStringArray("Errors", errorArr);
    	} else {
    		responseOb.setString("GameId", gameId);
    		responseOb.setInteger("ZoneId", result.getZoneId());
    		responseOb.setInteger("RoomId", result.getRoomId());
    	}
    	
    	sendToUser(userIds[0], responseOb);
    }
    ------
    Jobe Makar
    @jobemakar
    http://www.electrotank.com

    YouTube ElectroServer video tutorials
    http://www.youtube.com/user/ElectrotankInc

  3. #3
    Member
    Join Date
    Nov 2005
    Posts
    67
    Thanks
    4
    Thanked 2 Times in 1 Post
    I try to use a server-level plugin to setup a list of persistent rooms when the server frist started.

    I think the problem is that I need to pass in a list of users. But when the server first started there is no user around.

    Basically I want to be able to setup a list of persistent rooms without using the web admin.

    Is there a way to create persistent rooms with an empty userList?

  4. #4
    Electrotank
    Join Date
    Apr 2004
    Posts
    623
    Thanks
    0
    Thanked 5 Times in 5 Posts
    The "empty user list bug" was actually a bug in ES 4.0.0 and possibly 4.0.1. It's now fixed, what version are you using?

  5. #5
    Member
    Join Date
    Nov 2005
    Posts
    67
    Thanks
    4
    Thanked 2 Times in 1 Post

    I use version 4.0.2.

    The only way to have my room creation code posted above works is to pass in a non-empty user list.

    So either I miss something or the "empty user list bug" as you called it still exists.

  6. #6
    Electrotank
    Join Date
    Apr 2004
    Posts
    623
    Thanks
    0
    Thanked 5 Times in 5 Posts
    We will look into it again but I know it was tested quite heavily and should be working.

  7. #7
    Member
    Join Date
    Nov 2005
    Posts
    67
    Thanks
    4
    Thanked 2 Times in 1 Post
    After investigating futher into this issue I've found out that creating rooms, persistent or not, with server-side plugins indeed doesn't require a non-empty user list. But it does require the zone to exist for the room to be successfully created.

    So the solution is to use createRoomInNamedZone method instead of createRoom method.

    At first glance I thought createRoomInNamedZone method is for creating rooms in an existing zone only but actually it is the opposite.

    Now I don't have to use Web Admin to create persistent rooms any more.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts