Page 1 of 1

A probelm with sorting rooms list after zone.getRooms()

Posted: 11 Nov 2010, 08:04
by yuvallahav
Hello.

I've been trying to work this out, but can't seem to find the right way to do what I need...
Lets say I want to send me newly logged client a list of the last 10 rooms to be created.
When I ask the zone for the rooms list, using, of course, zone.getRooms(), the list returned in not in order of the rooms by the time of their creation.
Since sortOn is not supported on the server, meaning I can't sort the rooms (all dynamic rooms) by their id, and I can't sort to the correct order using simple sort after, for example, converting the data into strings, since room_id_10 will come before room_id_2, or even, should I try 10_room, it will still come before 2_room, what can you suggest to make this kind of sort work, or is there some kind of command I'm missing or some parameters I could pass the getRooms function to give me back the rooms by order??

Thanks.

Yuval Lahav.

Posted: 11 Nov 2010, 19:46
by BigFIsh
As far as I recall, I don't think there's a such feature that sorts the room by a parameter. You could easily create a custom function to do so.

i.e. loop through each room, and add to an array by its id - then select the last 10 elements of the array. Then you send the room list by using helper.sendCustomRoomList method (for java) or _server.sendGenericMessage method to send your own xml message to fake a room list. More info can be found in the docs.

Posted: 11 Nov 2010, 19:51
by yuvallahav
Well, I don't think that would help much, since creating an array and using the ID of the room as the index would create a really big and long array (as the server works through the day, creating and killing off rooms, they ID's get to the 10,000nd's, and then, taking the last 10 would not be that good too as rooms are created and killed off all the time, so I would have to work to eliminate the empty spaces, and to do all of that, over and over and over again for each user who logs in, just to see the last 10 rooms created, for about 5000 clients, and 5000 connections, seems to me it will take a lot of the server processing power, let alone delay it will create on the server, let alone number of messages I want to cut down....

I'll find something out, I'm sure... I hope...

Posted: 12 Nov 2010, 00:04
by BigFIsh
Then why not store the last ten rooms as an array in your zone extension then? i.e. capture the newRoom internal event and 'push' it to the local array, and if the array length extends 10 the shift the first one out. I'm sure you can figure something out.

Posted: 12 Nov 2010, 07:40
by yuvallahav
I might just do that... if I knew how to capture the internal addroom event...

Yuval Lahav.