Page 1 of 1

need help in _server.loginUser()

Posted: 16 Mar 2009, 07:56
by samyphp
Hi lapo,

var obj = _server.loginUser(nick, pass, chan)

i know the method loginUser returns obj.success and obj.error
i want to know more about this method.
i want to know if the obj.error is This user name is already taken., can we take the old user object or old user object id...? if yes means, tell me how..? also if u can means give me an example....

if u want more details on this query, am ready to give.

thanks,
Palanisamy

Posted: 16 Mar 2009, 16:43
by Lapo
No, but you can use the additional 4th parameter called forceLogin and available since SFS 1.6.5
This allows you to force the old user out and let the new one in.

thanks

Posted: 17 Mar 2009, 03:53
by samyphp
Hi lapo,
thanks for ur reply... :)
this is very useful for me :D

Username is already taken

Posted: 25 Oct 2010, 10:08
by kuttoosan
Hi,

My sfs version is SmartfoxServer Pro ver 1.6.6

I've tried using _server.loginUser(nick, pass, chan, true), but still the user is not able to login.

I've also used, _server.disconnectUser(_server.getUserById(nick)) in kick user

please help me solve this problem.

Posted: 25 Oct 2010, 20:15
by BigFIsh
@kuttoosan, do you know the exact reason why the user can't log in? Any feedback / response from the server?

Posted: 26 Oct 2010, 04:13
by kuttoosan
Hi BigFish,

The response from the server is "The username is already taken".

Thanks

Posted: 26 Oct 2010, 05:09
by BigFIsh
_server.loginUser(nick, pass, chan, true) should work. Where and when are you calling that method from?

Posted: 26 Oct 2010, 10:37
by kuttoosan
:( :( It's not working for me...
From 'handleinternalevent' am passing nick, chan and pass to a function, loginCustomUser(nick, pass, chan).
And inside the function am calling:
var obj = _server.loginUser(nick, pass, chan, true);

Posted: 26 Oct 2010, 17:45
by BigFIsh
Strange..

So, if you do something like this:

var obj = _server.loginUser(nick, pass, chan, true);

does obj.error also traces out "The username is already taken" ?

Are you positive that your server is at least 1.6.3? Does your SFS console indicate this?

Lastely, you could try _server.logoutUser prior to using _server.loginUser.

Posted: 27 Oct 2010, 04:19
by kuttoosan
Thanks a lot BigFIsh..
I shall try with _server.logoutUser.

My SFS console says its 1.6.6...

Posted: 01 Dec 2010, 08:19
by kuttoosan
Hi BigFIsh,

Need your help again. Am not getting the force login right.

Below is the entire code which is being used for the custom login.

function handleInternalEvent(evt)
{
if (evt.name == "loginRequest")
{
var error = "";
var nick = evt.nick
var pass = evt.pass
var chan = evt.chan

if(pass == "common")
{
// Check login
if (listByname[nick])
{
var response = new Object()

response._cmd = "loginKO";
error = "this user is already loged in from another computer";
response.err = error;
response.status = 404;
response.username = nick;

_server.sendResponse(response, -1, null, chan);

}
else
{
loginCustomUser(nick, pass, chan);
}
}
else
{
debugtrace(" == = [kickUser]"+nick+ listByname[nick]);
if(listByname[nick])
{
_server.disconnectUser(listByname[nick]);
}
else
{
_server.disconnectUser(_server.getUserById(nick));
_server.logoutUser(_server.getUserById(nick));
}

response = new Object()
response._cmd = "kickUserOK";
_server.sendResponse(response, -1, null, chan);
}
}
}


function loginCustomUser(nick, pass, chan)
{
var error = "";
var obj = _server.loginUser(nick, pass, chan, true);

if (obj.success == false)
error = obj.error
else
{
var u = _server.instance.getUserByChannel(chan)
}

var response = new Object()

if (error == "")
{
response._cmd = "loginOK";
if(u != null)
{
response.uid = u.getUserId()
response.uname = u.getName();
}
else
{
response.uid = null;
response.uname = null;
}
}
else
{
response._cmd = "loginKO"
response.err = error;
response.status = 404;
}

_server.sendResponse(response, -1, null, chan);

}

Please check this and let me know whether am doing something wrong.

The lines of code,
_server.disconnectUser(_server.getUserById(nick));
_server.logoutUser(_server.getUserById(nick));
will not work correctly since nick is a string variable and the both the functions except int. :(

Please help me solve this issue..

Posted: 01 Dec 2010, 18:00
by BigFIsh
P.s. use the

Code: Select all

 to format the code, because it's quite difficult to read without.

Have you tried zone.getUserByName() ?

Firstly, you should test if the user is null before disconnecting/logging the user out.

Posted: 02 Dec 2010, 04:43
by kuttoosan

Code: Select all

function handleInternalEvent(evt) 
{ 
	if (evt.name == "loginRequest") 
	{ 
		var error = ""; 
		var nick = evt.nick 
		var pass = evt.pass 
		var chan = evt.chan 
		
		if(pass == "common") 
		{ 
			// Check login 
			if (listByname[nick]) 
			{ 
				var response = new Object() 
				
				response._cmd = "loginKO"; 
				error = "this user is already loged in from another computer"; 
				response.err = error; 
				response.status = 404; 
				response.username = nick; 
				
				_server.sendResponse(response, -1, null, chan); 
			} 
			else 
			{ 
				loginCustomUser(nick, pass, chan); 
			} 
		} 
		else 
		{ 
			debugtrace(" == = [kickUser]"+nick+ listByname[nick]); 
			if(listByname[nick]) 
			{ 
				_server.disconnectUser(listByname[nick]); 
			} 
			else 
			{ 
				_server.disconnectUser(_server.getUserById(nick)); 
				_server.logoutUser(_server.getUserById(nick)); 
			} 
			
			response = new Object() 
			response._cmd = "kickUserOK"; 
			_server.sendResponse(response, -1, null, chan); 
		} 
	} 
} 


function loginCustomUser(nick, pass, chan) 
{ 
	var error = ""; 
	var obj = _server.loginUser(nick, pass, chan, true); 
	
	if (obj.success == false) 
		error = obj.error 
	else 
	{ 
		var u = _server.instance.getUserByChannel(chan) 
	} 
	
	var response = new Object() 
	
	if (error == "") 
	{ 
		response._cmd = "loginOK"; 
		if(u != null) 
		{ 
			response.uid = u.getUserId() 
			response.uname = u.getName(); 
		} 
		else 
		{ 
			response.uid = null; 
			response.uname = null; 
		} 
	} 
	else 
	{ 
		response._cmd = "loginKO" 
		response.err = error; 
		response.status = 404; 
	} 
	
	_server.sendResponse(response, -1, null, chan); 

} 
BigFIsh... I've put the code in the correct format..
I've not tried zone.getUserByName()
Shall try that also.

Thanks

Posted: 27 Jan 2011, 07:54
by gbala
Hi,
can any one help in the same issue.
I am also having the same issue what kuttoosan has.

Thanks,
Bala