get All Users In a Zone
-
- Posts: 32
- Joined: 09 Feb 2006, 12:12
get All Users In a Zone
hi,
is there any simple way to get a list of all the users in a zone, regardless of which room they are in. i know one way is to get the list of rooms and then the list of users. but a simpler way to keep track would be nice.
best regards
is there any simple way to get a list of all the users in a zone, regardless of which room they are in. i know one way is to get the list of rooms and then the list of users. but a simpler way to keep track would be nice.
best regards
No, there isn't a direct method to do so.
However you cycle through all the available rooms in the Zone and call the getAllUsers() method, which returns an array of users.
The array returned is not an Actionscript array, but a Java array.
This doesn't change things too much, but a Java array does not provide any of the typical AS array (join, push, pop, sort ...)
Alternatively you could try this:
there's an undocumented Zone method called getAllUsersInZone()
(The reason why it is "hidden" is because it works well in Java and returns Java objects.)
The method returns a java.util.LinkedList filled with all SocketChannels of all users in the Zone.
With this code you could quickly create the full list of users in Actionscript:
I haven't tested it, but it should work.
However you cycle through all the available rooms in the Zone and call the getAllUsers() method, which returns an array of users.
The array returned is not an Actionscript array, but a Java array.
This doesn't change things too much, but a Java array does not provide any of the typical AS array (join, push, pop, sort ...)
Alternatively you could try this:
there's an undocumented Zone method called getAllUsersInZone()
(The reason why it is "hidden" is because it works well in Java and returns Java objects.)
The method returns a java.util.LinkedList filled with all SocketChannels of all users in the Zone.
With this code you could quickly create the full list of users in Actionscript:
Code: Select all
function getAllUsersInZone()
{
// Grab current extension zone
var zone = _server.getCurrentZone()
// Get the java list of socket channels
var listOfChannels = zone.getAllUsersInZone()
// the list of users
var allUsers = []
var socketChan = null
for (var i = 0; i < listOfChannels.size(); i++)
{
socketChan = listOfChannels.get(i)
allUsers.push( _server.getUserByChannel( socketChan ) )
}
return allUsers
}
I haven't tested it, but it should work.
-
- Posts: 32
- Joined: 09 Feb 2006, 12:12
interesting,
im actually trying to do this on the client side, can u plz help me out with my code or suggest me a simpler way, here is what ive written but it seems that it does not enter the for(var i in userList), please correct me where im worng:
Im getting the item.ID from a datagrid of rooms list. This piece of code is very similar to the one used in sfsTris to get the usersList of the currently active room
im actually trying to do this on the client side, can u plz help me out with my code or suggest me a simpler way, here is what ive written but it seems that it does not enter the for(var i in userList), please correct me where im worng:
Code: Select all
function fillUpUserList() {
for (var i1:Number = 0; i1<roomList_lb.length; i1++) {
var item:Object = roomList_lb.getItemAt(i1);
trace("item.ID: "+item.ID);
thisRoom = smartfox.getRoom(item.ID);
var userList = thisRoom.getUserList();
trace("User Count: "+thisRoom.getUserCount());
trace("User List: "+userList);
for (var i in userList) {
trace("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
var user:User = userList[i];
var uName:String = user.getName();
var uId:Number = user.getId();
if (uId != smartfox.myUserId) {
userList_lb.addItem(user.getVariable("firstName")+" "+user.getVariable("lastName"), uId);
}
}
}
}
Im getting the item.ID from a datagrid of rooms list. This piece of code is very similar to the one used in sfsTris to get the usersList of the currently active room
getAllUsersinZone
Hy,
please help me, I am a SmartFoxServer-Newbie...
I am looking for a Function like "getAllUsersinZone" so I need to List all logged-in Users from a Zone.
What should I do to get a complete Userlist with this function?
I am programming with AS2 using the "RoomVariables Example" with the Pro-Version.
Please help me.
Thanks and Greetings,
Thorsten
please help me, I am a SmartFoxServer-Newbie...
I am looking for a Function like "getAllUsersinZone" so I need to List all logged-in Users from a Zone.
What should I do to get a complete Userlist with this function?
I am programming with AS2 using the "RoomVariables Example" with the Pro-Version.
Please help me.
Thanks and Greetings,
Thorsten
Hello again,
in the documentation I have found an AS-Template for Extensions.
These has four Blocks:
- init
- destroy
- handleRequest
- handleInternalEvent
The Function "getAllUsersInZone()" seems to be called from the Client and gave "allUsers" back.
Should I wrote the complete Function in the Block "init" or in "handleRequest". Or should I split the Function. What should I do in my FLA-File to call the Function (except "var extensionName:String = "getAllUsersInZone"")?
Please help me and give response.
Thank you and greetings from Germany.
Thorsten
in the documentation I have found an AS-Template for Extensions.
These has four Blocks:
- init
- destroy
- handleRequest
- handleInternalEvent
The Function "getAllUsersInZone()" seems to be called from the Client and gave "allUsers" back.
Should I wrote the complete Function in the Block "init" or in "handleRequest". Or should I split the Function. What should I do in my FLA-File to call the Function (except "var extensionName:String = "getAllUsersInZone"")?
Please help me and give response.
Thank you and greetings from Germany.
Thorsten
Hello!
I am stepping forward so I am getting some input from the Server by this function now.
But the responded users from the server are looking not very representative to put in my Flash-Application:
it.gotoandplay.smartfoxserver.data.User@36eb66
it.gotoandplay.smartfoxserver.data.User@1988f4b
Can you show me a way to format the users like:
Username1
Username2
Best regards,
Thorsten (from Cologne, Germany)
I am stepping forward so I am getting some input from the Server by this function now.
But the responded users from the server are looking not very representative to put in my Flash-Application:
it.gotoandplay.smartfoxserver.data.User@36eb66
it.gotoandplay.smartfoxserver.data.User@1988f4b
Can you show me a way to format the users like:
Username1
Username2
Best regards,
Thorsten (from Cologne, Germany)
Lapo wrote:Code: Select all
function getAllUsersInZone()
{
//...
}
I haven't tested it, but it should work.
It works, but I get a warning: Error in extension: TypeError: Cannot find function getChannel. Internal: -1012
How can I fix this msg?
Thanks anyway.
Thanks!
Lapo wrote:No, there isn't a direct method to do so.
However you cycle through all the available rooms in the Zone and call the getAllUsers() method, which returns an array of users.
The array returned is not an Actionscript array, but a Java array.
This doesn't change things too much, but a Java array does not provide any of the typical AS array (join, push, pop, sort ...)
Alternatively you could try this:
there's an undocumented Zone method called getAllUsersInZone()
(The reason why it is "hidden" is because it works well in Java and returns Java objects.)
The method returns a java.util.LinkedList filled with all SocketChannels of all users in the Zone.
With this code you could quickly create the full list of users in Actionscript:Code: Select all
function getAllUsersInZone()
{
// Grab current extension zone
var zone = _server.getCurrentZone()
// Get the java list of socket channels
var listOfChannels = zone.getAllUsersInZone()
// the list of users
var allUsers = []
var socketChan = null
for (var i = 0; i < listOfChannels.size(); i++)
{
socketChan = listOfChannels.get(i)
allUsers.push( _server.getUserByChannel( socketChan ) )
}
return allUsers
}
I haven't tested it, but it should work.
Mind posting a java version of that?
Here we go:
There's a little mix of generic collections and non-generic collections. This is due to the fact that SFS was started before Java 5 was out.
Next major update will be fully Java 5+ compliant
Code: Select all
ExtensionHelper helper = ExtensionHelper.getInstance();
public List<Users> getAllUsersInZone()
{
// Grab current extension zone
Zone zone = helper.getZone(this.getOwnerZone());
// Get the java list of socket channels
List listOfChannels = zone.getAllUsersInZone();
// the list of users
List<Users> allUsers = new ArrayList<Users>();
SocketChannel socketChan;
for (Object obj : listOfChannels)
{
socketChan = (SocketChannel) obj;
allUsers.push( helper.getUserByChannel(socketChan) );
}
return allUsers
}
There's a little mix of generic collections and non-generic collections. This is due to the fact that SFS was started before Java 5 was out.
Next major update will be fully Java 5+ compliant
Jipii wrote:It works, but I get a warning: Error in extension: TypeError: Cannot find function getChannel. Internal: -1012
How can I fix this msg?
Thanks anyway.
Lapo wrote:Can you please show the code you are using?
I used the same code you posted for server side .as above.
With this code you could quickly create the full list of users in Actionscript:Code: Select all
function getAllUsersInZone()
{
// Grab current extension zone
var zone = _server.getCurrentZone()
// Get the java list of socket channels
var listOfChannels = zone.getAllUsersInZone()
// the list of users
var allUsers = []
var socketChan = null
for (var i = 0; i < listOfChannels.size(); i++)
{
socketChan = listOfChannels.get(i)
allUsers.push( _server.getUserByChannel( socketChan ) )
}
return allUsers
}
Thanks!
Return to “Server Side Extension Development”
Who is online
Users browsing this forum: No registered users and 27 guests