Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Login
- --Handler
- --v.0.7
- --| public:
- --| construct
- --| deconstruct
- --| private
- --| handleDisconnect
- --| handleHello
- --| handleSessionParameters
- --| handleSecretKey
- --| handleRights
- --| handleLoginOK
- --| handleUserObj
- --| handleAdv
- --| handleErr
- --| handleUserBanned
- --| handleRegistrationOK
- --| handleEPSnotify
- --| handleSystembroadcast
- --| handleChecksum
- --| handleModAlert
- --| handleAvailableBadges
- --| handleTickets
- --| handleNoTickets
- --| handleTicketsBuy
- --| regMsgList
- -- Public methods: -- -- -- -- -- -- -- -- -- -- --//
- -- Constructor.
- on construct(me)
- return(me.regMsgList(TRUE))
- end
- -- Deconstruct.
- on deconstruct(me)
- return(me.regMsgList(FALSE))
- end
- -- Private methods: -- -- -- -- -- -- -- -- -- -- --//
- -- Note! Multipurpose message handler split into multiple handlers
- on handleDisconnect(me, tMsg)
- error(me, "Connection was disconnected:" && tMsg.connection.getID(), #handleMsg)
- return(me.getInterface().showDisconnect())
- end
- -- handles Hello message
- on handleHello(me, tMsg)
- tMsg.connection.send("GET_SESSION_PARAMETERS")
- end
- -- Handles the session parameter flags
- on handleSessionParameters(me, tMsg)
- -- Parse id-value pairs...
- tPairsCount = tMsg.connection.getIntFrom()
- if integerP(tPairsCount) then
- if tPairsCount > 0 then
- repeat with i = 1 to tPairsCount
- tID = tMsg.connection.getIntFrom()
- tValue = tMsg.connection.getIntFrom()
- tSession = getObject(#session)
- case(tID) of
- 0: -- Coppa flag, at least registration needs that information
- tSession.set("conf_coppa", (tValue>0))
- tSession.set("conf_strong_coppa_required", (tValue>1)) --Strong COPPA
- 1: -- Voucher flag
- tSession.set("conf_voucher", (tValue>0))
- 2: -- Is parent email required in registration
- tSession.set("conf_parent_email_request", (tValue>0))
- 3: -- Is parent email required in re-registration (forced registration)
- tSession.set("conf_parent_email_request_reregistration", (tValue>0))
- 4: -- Is parent email required in re-registration (forced registration)
- tSession.set("conf_allow_direct_mail", (tValue>0))
- end case
- end repeat
- end if
- end if
- -- seemdfnd version check message
- tMsg.connection.send("CHK_VERSION", [#short:getIntVariable("client.version.id")])
- end
- on handleSecretKey(me, tMsg)
- tKey = secretDecode(tMsg.content)
- tMsg.connection.setDecoder(createObject(#temp, getClassVariable("connection.decoder.class")))
- tMsg.connection.getDecoder().setKey(tKey)
- tMsg.connection.setEncryption(TRUE)
- -- Remove problem helper object...
- if(objectExists("nav_problem_obj")) then
- removeObject("nav_problem_obj")
- end if
- -- Perform login if everything is ok...
- if(me.getComponent().isOkToLogin()) then
- tUserName = getObject(#session).get(#username)
- tPassWord = getObject(#session).get(#password)
- -- Validate user's name and password...
- if(not stringP(tUserName)) or (not stringP(tPassWord)) then
- return(removeConnection(tMsg.connection.getID()))
- end if
- if(tUserName = EMPTY) or (tPassWord = EMPTY) then
- return(removeConnection(tMsg.connection.getID()))
- end if
- -- Send unique ID and perform login...
- tMsg.connection.send("SET_UID", [#string:getMachineID()])
- tMsg.connection.send("TRY_LOGIN", [#string:tUserName, #string:tPassWord])
- end if
- end
- on handlePing(me, tMsg)
- -- Reply with a PONG
- tMsg.connection.send("PONG")
- end
- on handleRegistrationOK(me, tMsg)
- tUserName = getObject(#session).get(#username)
- tPassWord = getObject(#session).get(#password)
- -- Validate user's name and password...
- if(not stringP(tUserName)) or (not stringP(tPassWord)) then
- return(removeConnection(tMsg.connection.getID()))
- end if
- if(tUserName = EMPTY) or (tPassWord = EMPTY) then
- return(removeConnection(tMsg.connection.getID()))
- end if
- -- Send unique ID and perform login...
- tMsg.connection.send("SET_UID", [#string:getMachineID()])
- tMsg.connection.send("TRY_LOGIN", [#string:tUserName, #string:tPassWord])
- end
- on handleLoginOK(me, tMsg)
- tMsg.connection.send("GET_INFO")
- tMsg.connection.send("GET_CREDITS")
- tMsg.connection.send("GETAVAILABLEBADGES")
- -- Set session variable that user has logged in\
- (used to distinguish update/registration)
- if (objectExists(#session)) then
- getObject(#session).set("userLoggedIn", true)
- end if
- -- Create a debug tool
- if not(objectExists("loggertool")) then
- if(memberExists("Debug System Class")) then
- createObject("loggertool", "Debug System Class")
- -- Check if the debug tool must be inited
- if (getIntVariable("client.debug.window", 0) = 3) then
- -- Open debug due to debug level
- getObject("loggertool").initDebug()
- else
- -- Check user settings for auto startup
- getObject("loggertool").tryAutoStart()
- end if
- end if
- end if
- end
- on handleUserObj(me,tMsg)
- tUser = [:]
- tDelim = the itemDelimiter
- the itemDelimiter = "="
- -- Parse key-value pairs...
- repeat with i = 1 to tMsg.content.line.count
- tLine = tMsg.content.line[i]
- tUser[tLine.item[1]] = tLine.item[2..tLine.item.count]
- end repeat
- -- Validate character's sex...
- if(not voidP(tUser["sex"])) then
- if(tUser["sex"] contains "F") or (tUser["sex"] contains "f") then
- tUser["sex"] = "F"
- else
- tUser["sex"] = "M"
- end if
- end if
- -- Parse character's figure data...(TODO: REFACTORE!!!)
- if objectExists("Figure_System") then
- tUser["figure"] = getObject("Figure_System").parseFigure(tUser["figure"], tUser["sex"], "user", "USEROBJECT")
- end if
- the itemDelimiter = tDelim
- tSession = getObject(#session)
- -- Save character data to session object...
- repeat with i = 1 to tUser.count
- tSession.set("user_" & tUser.getPropAt(i), tUser[i])
- end repeat
- -- IMPORTANT: Replace '#username' with case sensitive 'user_name'!!!
- tSession.set(#username, tSession.get("user_name"))
- tSession.set("user_password", tSession.get(#password))
- -- Tell everyone about updated figure data...
- executeMessage(#updateFigureData)
- -- Save valid quick login data...
- if(getObject(#session).exists("user_logged")) then
- return()
- else
- getObject(#session).set("user_logged", TRUE)
- end if
- if(getIntVariable("quickLogin", FALSE)) and (the runMode contains "Author") then
- setPref(getVariable("fuse.project.id", "fusepref"), string([getObject(#session).get(#username), getObject(#session).get(#password)]))
- me.getInterface().hideLogin()
- else
- me.getInterface().showUserFound()
- end if
- -- Tell everyone about succesfull login...
- executeMessage(#userlogin, "userLogin")
- end
- on handleUserBanned(me,tMsg)
- tBanMsg = getText("Alert_YouAreBanned") &RETURN& tMsg.content
- executeMessage(#openGeneralDialog, #ban, [#id:"BannWarning", #title:"Alert_YouAreBanned_T", #msg:tBanMsg, #modal:TRUE])
- removeConnection(tMsg.connection.getID())
- end
- on handleEPSnotify(me,tMsg)
- tType = EMPTY
- tData = EMPTY
- tDelim = the itemDelimiter
- the itemDelimiter = "="
- repeat with f = 1 to tMsg.content.line.count
- tProp = tMsg.content.line[f].item[1]
- tDesc = tMsg.content.line[f].item[2]
- case(tProp) of
- "t": tType = integer(tDesc)
- "p": tData = tDesc
- end case
- end repeat
- the itemDelimiter = tDelim
- -- TODO: Remove this from here!! -- -- -- -- -- --
- case(tType) of
- 580: -- Time for the language test...
- if(not createObject("lang_test", "CLangTest")) then
- return(error(me, "Failed to init lang tester!", #handle_eps_notify))
- else
- return(getObject("lang_test").setWord(tData))
- end if
- end case
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- executeMessage(#notify, tType, tData, tMsg.connection.getID())
- end
- on handleSystemBroadcast(me,tMsg)
- tMsg = tMsg[#content]
- tMsg = replaceChunks(tMsg, "\r", RETURN)
- tMsg = replaceChunks(tMsg, "<br>", RETURN)
- executeMessage(#alert, [#msg:tMsg])
- the keyboardFocusSprite = 0
- end
- on handleCheckSum(me,tMsg)
- getObject(#session).set("user_checksum", tMsg.content)
- end
- -- Receives list of available badges for user
- on handleAvailableBadges(me, tMsg)
- tBadgeList = []
- tNumber = tMsg.connection.getIntFrom()
- repeat with i = 1 to tNumber
- tBadgeID = tMsg.connection.getStrFrom()
- tBadgeList.add(tBadgeID)
- end repeat
- tChosenBadge = tMsg.connection.getIntFrom()
- tVisible = tMsg.connection.getIntFrom()
- -- List index comes from server as \
- java-index, convert to Lingo-index:
- tChosenBadge = tChosenBadge + 1
- if(tChosenBadge < 1) then tChosenBadge = 1
- getObject("session").set("available_badges", tBadgeList)
- getObject("session").set("chosen_badge_index", tChosenBadge)
- getObject("session").set("badge_visible" , tVisible)
- end
- -- Receives user rights, stores to session.
- on handleRights(me, tMsg)
- tSession = getObject(#session)
- -- Possible earlier user rights are removed.
- tSession.set("user_rights", [])
- tRights = tSession.get("user_rights")
- tPrivilegeFound = TRUE
- repeat while tPrivilegeFound = TRUE
- tPrivilege = tMsg.connection.getStrFrom()
- if(tPrivilege = VOID or tPrivilege = "") then
- tPrivilegeFound = FALSE
- else
- tRights.add(tPrivilege)
- end if
- end repeat
- return(TRUE)
- end
- -- Handles error messages.
- on handleErr(me, tMsg)
- error(me, "Error from server:" && tMsg.content, #handle_error)
- if(tMsg.content contains "login incorrect") then
- -- Handle failed login...
- removeConnection(tMsg.connection.getID())
- me.getComponent().setaProp(#pOkToLogin, FALSE)
- if(getObject(#session).exists("failed_password")) then
- openNetPage(getText("login_forgottenPassword_url"))
- --me.getInterface().showForgottenPW() --RELOCATED TO AN EXTERNAL WEBPAGE
- me.getInterface().showLogin()
- return FALSE
- else
- getObject(#session).set("failed_password", TRUE)
- me.getInterface().showLogin()
- executeMessage(#alert, [#msg:"Alert_WrongNameOrPassword"])
- end if
- else if(tMsg.content contains "mod_warn") then
- -- User received hobba warning...
- tDelim = the itemDelimiter
- the itemDelimiter = "/"
- tTextStr = tMsg.content.item[2..tMsg.content.item.count]
- the itemDelimiter = tDelim
- executeMessage(#alert, [#title:"alert_warning", #msg:tTextStr])
- else if(tMsg.content contains "Version not correct") then
- executeMessage(#alert, [#msg:"Old client version!!!"])
- end if
- return(TRUE)
- end
- -- Displays the moderator alert message to the user
- on handleModAlert(me, tMsg)
- if (not voidP(tMsg.content)) then
- executeMessage(#alert, [#title:"alert_warning", #msg:tMsg.content])
- else
- error(me, "Error in moderator alert:" && tMsg.content, #handleModAlert)
- end if
- end
- -- Server sends updated amount of game tickets.
- on handleTickets(me,tMsg)
- getObject(#session).set("user_ph_tickets", integer(tMsg.content.word[1]))
- return(TRUE)
- end
- -- User has bought game tickets OR someone \
- has bought them as gift.
- on handleTicketsBuy(me,tMsg)
- tTicketsNow = tMsg.content.word[1]
- getObject(#session).set("user_ph_tickets", integer(tTicketsNow))
- return(TRUE)
- end
- -- User tried to go to some game having no \
- game tickets.
- on handleNoTickets(me,tMsg)
- executeMessage(#show_ticketwindow)
- return(TRUE)
- end
- -- Registers message listeners & commands.
- on regMsgList(me, tBool)
- tMsgs = [:]
- tMsgs.setaProp( -1, #handleDisconnect )
- tMsgs.setaProp( 0, #handleHello )
- tMsgs.setaProp( 1, #handleSecretKey )
- tMsgs.setaProp( 2, #handleRights )
- tMsgs.setaProp( 3, #handleLoginOK )
- tMsgs.setaProp( 5, #handleUserObj )
- tMsgs.setaProp( 33, #handleErr )
- tMsgs.setaProp( 35, #handleUserBanned )
- tMsgs.setaProp( 50, #handlePing )
- tMsgs.setaProp( 51, #handleRegistrationOK )
- tMsgs.setaProp( 52, #handleEPSnotify)
- tMsgs.setaProp( 72, #handleTickets )
- tMsgs.setaProp( 73, #handleNoTickets )
- tMsgs.setaProp( 124, #handleTicketsBuy )
- tMsgs.setaProp( 139, #handleSystembroadcast )
- tMsgs.setaProp( 141, #handleChecksum)
- tMsgs.setaProp( 161, #handleModAlert )
- tMsgs.setaProp( 229, #handleAvailableBadges )
- tMsgs.setaProp( 257, #handleSessionParameters )
- tCmds = [:]
- tCmds.setaProp( "TRY_LOGIN", 4) -- <#string> name, <#string> pass
- tCmds.setaProp( "CHK_VERSION", 5) -- <#short> version
- tCmds.setaProp( "SET_UID", 6) -- <#string> id
- tCmds.setaProp( "GET_INFO", 7) -- <#void> -
- tCmds.setaProp( "GET_CREDITS", 8) -- <#void> -
- tCmds.setaProp( "GET_PASSWORD", 47) -- <#string> name, <#string> email
- tCmds.setaProp( "LANGCHECK", 58) -- <#string> word / TODO: Move this to 'CLangCheck'!!!
- tCmds.setaProp( "BTCKS", 105)
- tCmds.setaProp( "GETAVAILABLEBADGES", 157) -- <#void>
- tCmds.setaProp( "GET_SESSION_PARAMETERS", 181)
- tCmds.setaProp( "PONG", 196) -- <#void>
- tConn = getVariable("connection.info.id", #info)
- if(tBool) then
- registerListener(tConn, me.getID(), tMsgs)
- registerCommands(tConn, me.getID(), tCmds)
- else
- unregisterListener(tConn, me.getID(), tMsgs)
- unregisterCommands(tConn, me.getID(), tCmds)
- end if
- return(TRUE)
- end
- -- End of file. -- -- -- -- -- -- -- -- -- -- -- --//
- --Login Handler Class
- --Antti Kaseva
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement