Python Extension: CallBack a Error to variable.

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

Moderators: Lapo, Bax

Post Reply
Hanza-Ru
Posts: 1
Joined: 14 Sep 2010, 17:28
Location: BR

Python Extension: CallBack a Error to variable.

Post by Hanza-Ru »

Hello, I built a script based on loginExemple.as, and successfully, the
client was able to log into the room through the extension.

But, as mentioned by the documents of smartfox, can sometimes occur
drop network by the client side and for a few minutes, he
unable to connect to the server (Error: User is already
connected.).

I know where this error happens in this part of scrypt:

Code: Select all

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

if (obj.success == false){
     error = obj.error
}
then I would know how to create this part in python.
below, my extension with "TODO:".

Code: Select all

#LoginSFS Extension.
#Created by Hanza-Ru

userList = {}

def init():
    userList["Hanza-Ru"] = "J4669308"
    userList["jerry"] 	= "jerry"
    userList["smart"] 	= "fox"

def destroy():
    _server.trace("Python extension stopping")

def handleRequest(cmd, params, who, roomId, protocol):
    pass

def handleInternalEvent(evt):
    evtName = evt.getEventName()
    
    if evtName == "loginRequest":
        error = ""
        nick = evt.getParam('nick')
        password = evt.getParam('pass')
        chan = evt.getObject('chan')
        
        _server.trace("LoginResquest: " + nick + " : " + password ) #" : " + string(chan))
        if (userList[nick] != password):
            error = "Authentication failed"
            _server.trace("Authentication failed")
        else:
            _server.loginUser(nick, password, chan)
            #TODO: Traceback error on Login and put error messeger in 
            #error variable.
        #Sends Response
        r = {}
        if (error == ""):
            r['_cmd'] = "logON"
        else:
            r['_cmd'] = "logERR"
            r['_err'] = error
        _server.sendResponse(r, -1, None, chan)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

You will need to catch a possible LoginException.
An example (not tested, just going by memory) could be this

Code: Select all

from it.gotoandplay.smartfoxserver.exceptions import LoginException

try:
  _server.loginUser(....)
  ...
except LoginException, message:
  #your error handling code here
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply