Python Extension: CallBack a Error to variable.
Posted: 14 Sep 2010, 17:54
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:
then I would know how to create this part in python.
below, my extension with "TODO:".
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
}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)