Page 1 of 1

Extension going to the same user ?

Posted: 15 Apr 2011, 07:16
by GolceaVlad
Hi Guys,

I'm in the testing phase of my particularised database chat.

So here is my problem :
Every time a user enters my room, I send the server a request from everyone in the room, to get his data -= avatar, level, id, etc. =- .

[code]
// getting the name
var params:Object = new Object();
params.name = e.params.user.getName();
params.roomId = Assets.CLIENT.activeRoomId;

// sending the user info to the server so I can get their avatar and level from the db Assets.CLIENT.sendXtMessage(_xt,"ser",params,SmartFoxClient.XTMSG_TYPE_JSON);
[/code]

The problem is that when I have multiple users in the room, all the extension requests from them return to the first user.
This is the code on the server :
[code]
// Someone else Enters the Room
if (cmd == "ser")
{
var zone = _server.getCurrentZone()
var rooms = zone.getRooms()
var response = {}
response._cmd = "ser"

// looking in the database for the users level and avatar based on the name
var sql = "SELECT * FROM users WHERE username="
sql += "'" + params.name + "'"

var queryRes = dbase.executeQuery(sql)
var crtRow = queryRes.get(0)

response.user = crtRow.getItem("username")
response.avatar = crtRow.getItem("avatar")
response.level = crtRow.getItem("level")

// getting the id for this user
response.info = rooms[params.roomId-1].getAllUsers()
for(var i = response.info.length-1 ; i > -1 ; i--)
{
var user = response.info[i]
if(user.getName() == params.name)
{
response.id = user.getUserId()
}
}

_server.sendResponse(response, -1, null, [user])
}
[/code]

Any clue why the extension is caught by the same user all the time ?

Posted: 15 Apr 2011, 07:50
by rjgtav
Well, maybe because you're sending the response only to the user: _server.sendResponse(response, -1, null, [user]). If you trace (user.getName()), does it return the name of the user that you want to send the response?