Error in my login extension

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

Moderators: Lapo, Bax

Post Reply
WoWoX
Posts: 16
Joined: 18 May 2013, 13:25

Error in my login extension

Post by WoWoX »

Hello,
I am using a java login extension along with the avatarchat example to login to the avatarchat with a username and password.
The login is working, but my avatar does not appear when it goes to the chat frame, and the exit + send buttons do nothing.

Here is the onextensionresponse code I have added to the actionscript.

Code: Select all

public function onExtensionResponse(evt:SFSEvent):void
{
	var params:Object = evt.params.dataObj
	var cmd:String = params._cmd
	
	if (cmd == "logOK")
	{
		sfs.myUserId = params.id
		sfs.myUserName = params.name
		
		trace("login success")
	}
	else if (cmd == "logKO")
	{
		trace("authentication failed: " + params.err)
	}
}



And here's my extension code (I am 99% sure the error is that I'm missing something in the client side).:

Code: Select all

	 boolean checkCredentials(String name, String pass)
	 {
	 	boolean result = false;
	 	
	 	// Escape quotes on passed data
	 	name = SmartFoxLib.escapeQuotes(name);
	 	pass = SmartFoxLib.escapeQuotes(pass);
	 	String q = "'";
	 	// SQL statement to execute
	 	String sql = "SELECT name,login_key,mod_level,ip FROM users WHERE name = " + q + name + q;
	 	
	 	// Execute the SQL statement
	 	ArrayList queryRes = db.executeQuery(sql);
	 		
	 	// If record was found exist...
	 	if (queryRes != null && queryRes.size() > 0)
	 	{
	 		DataRow dr = (DataRow) queryRes.get(0);
	 		System.out.println(dr);
	 		String lk = dr.getItem("login_key");
	 		
	 		
	 		if(lk.equals(pass))
	 		{
	 		result = true;
	 		}
	 		
	 	}	
	 		
	 	return result;
	 }
	
public void handleInternalEvent(InternalEventObject evt)
	{
		 String evtName = evt.getEventName();

		 
		if(evtName.equals("loginRequest"))
		{
			
			boolean ok = false;
			User newUser = null;
			
			ActionscriptObject res = new ActionscriptObject();
			String nick = evt.getParam("nick");
			String pass = evt.getParam("pass");
			
			SocketChannel chan = (SocketChannel) evt.getObject("chan");
			
			ok = checkCredentials(nick, pass);
			
			if (ok)
			{
				try
				{
					Zone z0n3 = helper.getZone(this.getOwnerZone());
					String currentZone = z0n3.getName();
					
					newUser = helper.canLogin(nick, pass, chan, currentZone);
					//newUser = helper.canLogin(nick, pass, chan, currentZone);
					res.put("_cmd", "logOK");
					res.put("id", String.valueOf(newUser.getUserId()));
					res.put("name", newUser.getName());

					ok = true;
				}
				
				catch (LoginException le)
				{
					this.trace("Could not login user: " + nick);

					res.put("_cmd", "logKO");
					res.put("err", le.getMessage());
				}
			}
			else
			{
				res.put("_cmd", "logKO");
				res.put("err", "Sorry, invalid credentials.");
			}
			LinkedList ll = new LinkedList();
			ll.add(chan);

			sendResponse(res, -1, null, ll);
			if (ok)
				helper.sendRoomList(chan);
		}
		
		
		
			
				}




Like I said, I'm pretty sure the issue is that I'm missing something in the client side. Could someone help me with this?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Error in my login extension

Post by Lapo »

WoWoX wrote:The login is working, but my avatar does not appear when it goes to the chat frame, and the exit + send buttons do nothing.
If the login works then you should investigate the code that displays your avatar. The problem is not the login.
Lapo
--
gotoAndPlay()
...addicted to flash games
WoWoX
Posts: 16
Joined: 18 May 2013, 13:25

Re: Error in my login extension

Post by WoWoX »

Lapo wrote:
WoWoX wrote:The login is working, but my avatar does not appear when it goes to the chat frame, and the exit + send buttons do nothing.
If the login works then you should investigate the code that displays your avatar. The problem is not the login.
I have not modified the avatar chat example at all, besides adding the onExtensionResponse. It worked fine before adding the extension.


EDIT:

When I have the following code in the .fla, I get the compiler error "Attribute used outside class."

Code: Select all

public function onExtensionResponse(evt:SFSEvent):void
{
	var params:Object = evt.params.dataObj
	var cmd:String = params._cmd
	
	if (cmd == "logOK")
	{
		sfs.myUserId = params.id
		
		
		sfs.myUserName = params.name
		
		trace("login success")
	}
	else if (cmd == "logKO")
	{
		trace("authentication failed: " + params.err)
	}
}

When I remove this entire function and login with the username "wowox," it logs me in and I see an avatar named wowox, but I am a 2nd avatar named "undefined." The server recognizes me as wowox in the admintool, but on the clientside I am an avatar called "undefined" and there is what looks like a ghost avatar named "wowox."
WoWoX
Posts: 16
Joined: 18 May 2013, 13:25

Re: Error in my login extension

Post by WoWoX »

I used one of rjgtavs .fla files he posted in a thread to resolve a similar issue, and it fixed my problem.
Post Reply