Change maxU after room creation
Change maxU after room creation
Is it possible to change the maximum user count (maxU) for a room after it's creation?
I have multiple game lobby rooms that's structured like this in the zone extension:
The lobby’s are stored in a database and gets loaded at server init. I can also add/remove lobbies at runtime without having to restart the server. But if I want to change the properties of a lobby room (shouldn’t need to do that very often), I will need to restart the server. Not a big deal really, I can work around the problem by storing a variable for the maximum users and do my own checking for room full when user is logging in.
As for how it should work, the room class could have a member function setMaxUsers(num). But when I think about it a lot of problems arise. What will happen if you set the maxU to a value lower then the current user count? Just kicking out random people is not such a good idea, so it should let them stay, but not let anymore users in until the user count is below maxU again.
I don’t think many would find this useful though, and it would just confuse beginners when they are browsing through the documentation. So maybe it's just best to let it be.
Code: Select all
lobbyList[lobbyKey].gameList[gameKey]
The lobby’s are stored in a database and gets loaded at server init. I can also add/remove lobbies at runtime without having to restart the server. But if I want to change the properties of a lobby room (shouldn’t need to do that very often), I will need to restart the server. Not a big deal really, I can work around the problem by storing a variable for the maximum users and do my own checking for room full when user is logging in.
As for how it should work, the room class could have a member function setMaxUsers(num). But when I think about it a lot of problems arise. What will happen if you set the maxU to a value lower then the current user count? Just kicking out random people is not such a good idea, so it should let them stay, but not let anymore users in until the user count is below maxU again.
I don’t think many would find this useful though, and it would just confuse beginners when they are browsing through the documentation. So maybe it's just best to let it be.
Xelius wrote:As for how it should work, the room class could have a member function setMaxUsers(num).
There is setMaxSpectators(int s) method of the Room class in the java API. I don't know how it works - I haven't try it.
Xelius wrote:But when I think about it a lot of problems arise. What will happen if you set the maxU to a value lower then the current user count? Just kicking out random people is not such a good idea, so it should let them stay, but not let anymore users in until the user count is below maxU again.
This problem arise too if you try to make your own check. I suppose the best is just not kick anyone. So if there is 100 users in the room and you change the max user to 50 you for me the best solution is when the server not allowing someone to join if in the room are 50 or more users, but not kicking anyone. Soon or later the room will reach the number of 50 users.
nay, you can use it from AS too but we don't recommend it.
That method is used internally by the server. You don't get any notification about a change in the number of the spectator and if you alter it at runtime, setting that number < real number of spectators, it could lead to unexpected behaviors
Dynamically shrinking/enlarging rooms at runtime is pretty complex and creates various problems.. for example, what happens if you shrink the room? Which users are kicked? and how?
Probably you should only be allowed grow the room capacity.
That method is used internally by the server. You don't get any notification about a change in the number of the spectator and if you alter it at runtime, setting that number < real number of spectators, it could lead to unexpected behaviors
Dynamically shrinking/enlarging rooms at runtime is pretty complex and creates various problems.. for example, what happens if you shrink the room? Which users are kicked? and how?
Probably you should only be allowed grow the room capacity.
Lapo wrote:Dynamically shrinking/enlarging rooms at runtime is pretty complex and creates various problems.. for example, what happens if you shrink the room? Which users are kicked? and how?
Probably you should only be allowed grow the room capacity.
You don't need to kick anybody. I'll try to explain it better. Let's say that there is maxUser limit 3. In room Q there is users A,B and C.
If we set the limit to 2 what we can do?
- *To kick all users
*To kick random user
*To kick C, because it's the last user that enter the room
*Or just do nothing. If user D want to join we'll say -"No room for you in this room ". If user C leave and D want to join again we'll say "No room for you in this room " since there 2 user already in the room. If user B leave then we'll have one user and D can join. This solution doesn't shrinks the number of user immediately, but since new user can't join and the existing will no stay there forever, soon or later will shrink the number of users. May be it's not the best possible but it's good approach(I think the best one of this I suggest).
Anyway I think it's not a good practice to change the maxUsers at run time. But if someone have a reason to do it - it can do it and it can do it without kick anybody.
Last edited by patso on 21 Mar 2007, 09:27, edited 1 time in total.
*To kick all users
This way it's just like creating a new room
*To kick random user
doesn't make much sense
To kick C, because it's the last user that enter the room
mmm... I honestly don't like the idea of shrinking a room at runtime. It would also be very difficult to find a "generic" logic that satisfies many different needs.
The best ides is probably the one you last suggested, no one gets kicked but new people will fail to join until a number of users get out of the room and free up some slots
Lapo wrote:*To kick all users
This way it's just like creating a new room
Not exactly. For example the persistent room variables will stay(or at least I think so). Anyway I think creating new room is better idea than kick all users since it's more "clear" solution and the chance to something gone wrong is less.
Lapo wrote:The best ides is probably the one you last suggested, no one gets kicked but new people will fail to join until a number of users get out of the room and free up some slots
Yes I mean this too. May the "It's not the best" makes some confusion - I mean that this is little dirty solution since it doesn't shrink the room immediately and of this point of view maybe it's not the best possible. I edit my post to clear that confusion.
I think changing Max users at run time is useful for my case.
The reason why..
Host makes room, say.. "myGame" with max users of 20..
Host goes into waiting room..
5 players joined the room..
14 slots avaiable still - no one else joined for a while. Host can start the game anytime, so he decides to do so. He starts the game and fill the rest of slots with CPU users (I found a different way to make fake users without using socket connection). Now the game is starting...
Game started, and in game search window: It says: myGame (6/20) "blah blah" - Users thinks: Well, there's fourteen avaiable slots still, I guess I could join. And he joins, and he experience strange things...
So, I don't want this to happen. To fix this, when the host starts the game, server recieves the request then change the max users to the number of players currently in the room.
So therefore: in game search window: myGame (6/6) "blah blah"
Ah, so the room is full. Cannot join.
If this isn't possible. Then how can you make: myGame (6/20) to myGame(20/20) ? The first "20", what is it based on? The length of the users array? and where is it stored?
Also, is it possible to write your own code for server side? i.e. function getMaxUsers() as i want to make my own functions..
thanks
The reason why..
Host makes room, say.. "myGame" with max users of 20..
Host goes into waiting room..
5 players joined the room..
14 slots avaiable still - no one else joined for a while. Host can start the game anytime, so he decides to do so. He starts the game and fill the rest of slots with CPU users (I found a different way to make fake users without using socket connection). Now the game is starting...
Game started, and in game search window: It says: myGame (6/20) "blah blah" - Users thinks: Well, there's fourteen avaiable slots still, I guess I could join. And he joins, and he experience strange things...
So, I don't want this to happen. To fix this, when the host starts the game, server recieves the request then change the max users to the number of players currently in the room.
So therefore: in game search window: myGame (6/6) "blah blah"
Ah, so the room is full. Cannot join.
If this isn't possible. Then how can you make: myGame (6/20) to myGame(20/20) ? The first "20", what is it based on? The length of the users array? and where is it stored?
Also, is it possible to write your own code for server side? i.e. function getMaxUsers() as i want to make my own functions..
thanks
Heya-
So as for how to work resizing a room at runtime.
Could you not just have the function change the number, then raise a ROOM_SIZE_CHANGED event which could be responded to via extensions allowing each person to implement there own strategy for removal of players if needed?
Sounds like the best aproach to me.
_-Menser-_
So as for how to work resizing a room at runtime.
Could you not just have the function change the number, then raise a ROOM_SIZE_CHANGED event which could be responded to via extensions allowing each person to implement there own strategy for removal of players if needed?
Sounds like the best aproach to me.
_-Menser-_
Return to “SmartFoxServer 1.x Discussions and Help”
Who is online
Users browsing this forum: No registered users and 57 guests