need help in _server.loginUser()

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
samyphp
Posts: 55
Joined: 26 Mar 2008, 05:25
Location: Chennai - India

need help in _server.loginUser()

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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.
Lapo
--
gotoAndPlay()
...addicted to flash games
samyphp
Posts: 55
Joined: 26 Mar 2008, 05:25
Location: Chennai - India

thanks

Post by samyphp »

Hi lapo,
thanks for ur reply... :)
this is very useful for me :D
kuttoosan
Posts: 8
Joined: 25 Oct 2010, 10:01

Username is already taken

Post 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.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

@kuttoosan, do you know the exact reason why the user can't log in? Any feedback / response from the server?
Smartfox's forum is my daily newspaper.
kuttoosan
Posts: 8
Joined: 25 Oct 2010, 10:01

Post by kuttoosan »

Hi BigFish,

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

Thanks
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

_server.loginUser(nick, pass, chan, true) should work. Where and when are you calling that method from?
Smartfox's forum is my daily newspaper.
kuttoosan
Posts: 8
Joined: 25 Oct 2010, 10:01

Post 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);
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post 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.
Smartfox's forum is my daily newspaper.
kuttoosan
Posts: 8
Joined: 25 Oct 2010, 10:01

Post by kuttoosan »

Thanks a lot BigFIsh..
I shall try with _server.logoutUser.

My SFS console says its 1.6.6...
kuttoosan
Posts: 8
Joined: 25 Oct 2010, 10:01

Post 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..
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post 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.
Smartfox's forum is my daily newspaper.
kuttoosan
Posts: 8
Joined: 25 Oct 2010, 10:01

Post 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
gbala
Posts: 15
Joined: 13 Apr 2009, 14:05

Post by gbala »

Hi,
can any one help in the same issue.
I am also having the same issue what kuttoosan has.

Thanks,
Bala
Post Reply