allow duplicate username

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

giorgio79
Posts: 40
Joined: 14 Dec 2007, 19:32

allow duplicate username

Postby giorgio79 » 22 Dec 2007, 16:00

Hello,

For Usernames I will be using people's realnames, hence it can occur that they have idential names, such as

two "John Bigs" log in at the same time.

How could I allow this?

It is enough for me if the userid is unique :)

tHanks,
Giorgio
giorgio79
Posts: 40
Joined: 14 Dec 2007, 19:32

Postby giorgio79 » 22 Dec 2007, 16:35

I found this meanwhile
viewtopic.php?p=8358&highlight=&sid=fd9e61205dc1c3ad81a836c53dc7bf24#8358

I guess I will login users with their unique user ids from the db, and add a user variable for display name.

I see you argue that identical names are bad practice, but not in all cases...In my case, it is not an option not to display real names, which lets face it, can be duplicates...
giorgio79
Posts: 40
Joined: 14 Dec 2007, 19:32

Postby giorgio79 » 22 Dec 2007, 18:26

In researching this topic, I found a few posts.

Some suggest using the setuservariables, and at another place I found this
user.properties.put (myvar, myvar value)


viewtopic.php?t=1159&highlight=setuservariables

what would be the difference between setuservariables and user.properties.put?

PS
hmmm, I just found a third method described in chapter 7 which suggests using sendObject method, but that is for frequently changing data like user moves. I guess this is a new method, because in the Avatar chat example, setUserProperties is used to send across user moves. Please correct me if I am wrong, or help me understand these
Kicksome
Posts: 52
Joined: 01 Sep 2007, 02:25
Contact:

Postby Kicksome » 22 Dec 2007, 18:58

Set User Variables can be broadcast to all people in the room.

If you use user.properties.put (myvar, myvar value) it attaches the values on the server side. you have to be using room extensions for it to be any use. If you're using only client side - then you have to use set user variables.

So you could do user.properties.put ("realname", realnamevar) and anything else you wanted to tie to that person's userid.

We only use user.properties.put (myvar, myvar value) since we handle everything on the server.
giorgio79
Posts: 40
Joined: 14 Dec 2007, 19:32

Postby giorgio79 » 22 Dec 2007, 20:00

Hello Kicksome,

Thanks for responding :)

Very nice site you go there :)

As of the user variables:

I do plan on doing some server stuff, like saving a score, but given that I have:
1. the database id as the login name which is passed to the server by default :)
2. the username as a client property via setuservariables.

Therefore, I wont need to use the user.properties methods for handling the username as I understand:)

Thanks for the help.

I hope my understanding is correct now.
giorgio79
Posts: 40
Joined: 14 Dec 2007, 19:32

Postby giorgio79 » 25 Dec 2007, 14:58

Hello Guys,

Merry Christmas.

I made some progress with the setuservariables.

I have a little issue though.

When a new user enters the room, his displayname is not broadcasted to the other clients, hence in the other clients in the userlist it says undefined name. All else works, even in the chat the duplicate names are displayed properly. Could you help me out? Here is the code:

The way I tested it was just fired up 2 instances of the modded simplechat swf and logged in with different logins. The displayname should be the same though:

Code: Select all

smartfox.onJoinRoom = function(roomObj:Room)
{
   // MY MOD
   var displayName = "Giorgio"
   // save new variables
   smartfox.setUserVariables({displayName:displayName})
            
   var userList:Object   = roomObj.getUserList()
   
   // Clear text area
   chat_txt.htmlText = ""
   
   // Clear current list
   userList_lb.removeAll()
   
   for (var i:String in userList)
   {
      var user:User = userList[i]
      // MY MOD  Change Name Here   
      var uVars:Object = user.getVariables()
      userList_lb.addItem(uVars.displayName, user.getId())
   }
   
   // Sort names
   userList_lb.sortItemsBy("label", "ASC")
   
   chat_txt.htmlText += "<font color='#cc0000'>>> Room [ " + roomObj.getName() + " ] joined</font>";
}


//----------------------------------------------------------
// Handles a new user entering the room
//----------------------------------------------------------
smartfox.onUserEnterRoom = function(fromRoom:Number, user:User)
{
   // MY MOD  Change Name Here   
   var uVars:Object = user.getVariables()
   userList_lb.addItem(uVars.displayName, user.getId())
   
   // Sort names
   userList_lb.sortItemsBy("label", "ASC")
}



//----------------------------------------------------------
// Handles a new user leaving the room
//----------------------------------------------------------
smartfox.onUserLeaveRoom = function(fromRoom:Number, usrId:Number)
{   
   for (var i:Number = 0; i < userList_lb.getLength(); i++)
   {
      var item:Object = userList_lb.getItemAt(i)
      
      if (item.data == usrId)
      {
         var usrName:String = item.label
         userList_lb.removeItemAt(i)
         break
      }
   }
   
   // Sort names
   userList_lb.sortItemsBy("label", "ASC")
   
   chat_txt.htmlText += "<font color='#cc0000'>>> User [ " + usrName + " ] left the room.</font>";
}




//----------------------------------------------------------
// Handles a public message
//----------------------------------------------------------
smartfox.onPublicMessage = function(msg:String, user:User)
{
   // MY MOD getusername
   var uVars:Object = user.getVariables()
   chat_txt.htmlText += "<b>[ " + uVars.displayName + " ]:</b> " + msg
   main_sb.setScrollPosition(chat_txt.maxscroll)
}
giorgio79
Posts: 40
Joined: 14 Dec 2007, 19:32

Postby giorgio79 » 25 Dec 2007, 19:29

Yay, I solved it

I was trying to setuservariables after joining the room aarrggh :)


These helped:

viewtopic.php?t=34&highlight=onuserenterroom

viewtopic.php?t=2090&highlight=onuserenterroom

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 35 guests