Page 1 of 1

Banned users and customLogin

Posted: 04 May 2009, 22:11
by 2morrowMan
SmartFoxServer PRO 1.6.6 Trial.

Server side config.xml (customLogin="true"):

Code: Select all

<Zone name="avatarZone" maxUsers="10" emptyNames="false" customLogin="true" >
			<Rooms>
				<Room name="Main Area" maxUsers="10" isPrivate="false" isTemp="false" autoJoin="true" uCountUpdate="true" />
			</Rooms>
			
			<Extensions>
				<extension name="Avatar"  className="Avatar.as" type="script" /> 
			</Extensions>
		</Zone>
Extention Avatar.as:

Code: Select all

function init()
{
	userList = new Object();
	userList["alex"] = "somePass";
}

function handleInternalEvent(evt)
{
	if (evt.name == "loginRequest")
	{
		var error = "";
		var nick = evt.nick.toLowerCase(); // << the nickname is NOT case sensitive
		var pass = evt.pass;
		var chan = evt.chan;
		
		if (userList[nick] != pass)
		{
			error = "Login failed!";
		}
		else
		{
			var obj = _server.loginUser(nick, pass, chan);
			
			if (obj.success == false)
				error = obj.error;
		}
		
		var response = new Object();
		if (error == "")
		{
			response._cmd = "login";
			response.name = nick;
		}
		else
		{
			response._cmd = "login";
			response.err = error;
		}
		
		_server.sendResponse(response, -1, null, chan);
	}
}
Client side:
Login in lower case:

Code: Select all

sfs.addEventListener(SFSEvent.onExtensionResponse, onExtensionResponse);
sfs.addEventListener(SFSEvent.onLogin, onLogin);
sfs.login("avatarZone", "alex", "somePass");
If user alex is not banned login is successful and response handled with onExtensionResponse(). OK.
If user alex is banned login is FAILED and response handled with onLogin(). Why with onLogin()? Why handleInternalEvent() didn't process this request ?
var obj = _server.loginUser(nick, pass, chan);
obj.success = false and obj.error should contain message "You have been banned!", right?

Login with upper case:

Code: Select all

sfs.addEventListener(SFSEvent.onExtensionResponse, onExtensionResponse);
sfs.addEventListener(SFSEvent.onLogin, onLogin);
sfs.login("avatarZone", "Alex", "somePass");
If user alex is not banned login is successful and response handled with onExtensionResponse(). OK.
If user alex(not Alex) is banned login ( _server.loginUser(nick, pass, chan); ) is successful(why?) and response handled with onExtensionResponse().

Posted: 13 May 2009, 13:01
by Lapo
Before your extension takes control over the login process the server applies a number of checks such as verifying if the user is already logged or if he's banned. If so it sends back an alert to the client via the regular onLogin event.
You might want to handle that event (only failures) if you use banning.

I think this is an inconsistency, so I am taking notes and adding it to the todo list for a future update.