Advertisement
Guest User

Habbo Hotel Login Handler Class v0.7

a guest
Jun 20th, 2024
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.76 KB | Source Code | 0 0
  1. --Login
  2. --Handler
  3. --v.0.7
  4.  
  5.  
  6. --| public:
  7. --| construct
  8. --| deconstruct
  9. --| private
  10. --| handleDisconnect
  11. --| handleHello
  12. --| handleSessionParameters
  13. --| handleSecretKey
  14. --| handleRights
  15. --| handleLoginOK
  16. --| handleUserObj
  17. --| handleAdv
  18. --| handleErr
  19. --| handleUserBanned
  20. --| handleRegistrationOK
  21. --| handleEPSnotify
  22. --| handleSystembroadcast
  23. --| handleChecksum
  24. --| handleModAlert
  25. --| handleAvailableBadges
  26. --| handleTickets
  27. --| handleNoTickets
  28. --| handleTicketsBuy
  29. --| regMsgList
  30.  
  31.  
  32. -- Public methods: -- -- -- -- -- -- -- -- -- -- --//
  33.  
  34.  
  35. -- Constructor.
  36.  
  37. on construct(me)
  38.  
  39. return(me.regMsgList(TRUE))
  40.  
  41. end
  42.  
  43.  
  44. -- Deconstruct.
  45.  
  46. on deconstruct(me)
  47.  
  48. return(me.regMsgList(FALSE))
  49.  
  50. end
  51.  
  52.  
  53. -- Private methods: -- -- -- -- -- -- -- -- -- -- --//
  54.  
  55.  
  56. -- Note! Multipurpose message handler split into multiple handlers
  57.  
  58. on handleDisconnect(me, tMsg)
  59.  
  60. error(me, "Connection was disconnected:" && tMsg.connection.getID(), #handleMsg)
  61. return(me.getInterface().showDisconnect())
  62.  
  63. end
  64.  
  65.  
  66. -- handles Hello message
  67.  
  68. on handleHello(me, tMsg)
  69.  
  70. tMsg.connection.send("GET_SESSION_PARAMETERS")
  71.  
  72. end
  73.  
  74.  
  75. -- Handles the session parameter flags
  76.  
  77. on handleSessionParameters(me, tMsg)
  78.  
  79. -- Parse id-value pairs...
  80. tPairsCount = tMsg.connection.getIntFrom()
  81.  
  82.  
  83. if integerP(tPairsCount) then
  84. if tPairsCount > 0 then
  85.  
  86. repeat with i = 1 to tPairsCount
  87.  
  88. tID = tMsg.connection.getIntFrom()
  89. tValue = tMsg.connection.getIntFrom()
  90.  
  91.  
  92. tSession = getObject(#session)
  93.  
  94. case(tID) of
  95.  
  96. 0: -- Coppa flag, at least registration needs that information
  97. tSession.set("conf_coppa", (tValue>0))
  98. tSession.set("conf_strong_coppa_required", (tValue>1)) --Strong COPPA
  99.  
  100.  
  101. 1: -- Voucher flag
  102. tSession.set("conf_voucher", (tValue>0))
  103.  
  104.  
  105. 2: -- Is parent email required in registration
  106. tSession.set("conf_parent_email_request", (tValue>0))
  107.  
  108.  
  109. 3: -- Is parent email required in re-registration (forced registration)
  110. tSession.set("conf_parent_email_request_reregistration", (tValue>0))
  111.  
  112. 4: -- Is parent email required in re-registration (forced registration)
  113. tSession.set("conf_allow_direct_mail", (tValue>0))
  114.  
  115. end case
  116.  
  117. end repeat
  118. end if
  119. end if
  120.  
  121. -- seemdfnd version check message
  122. tMsg.connection.send("CHK_VERSION", [#short:getIntVariable("client.version.id")])
  123.  
  124. end
  125.  
  126.  
  127.  
  128. on handleSecretKey(me, tMsg)
  129.  
  130. tKey = secretDecode(tMsg.content)
  131. tMsg.connection.setDecoder(createObject(#temp, getClassVariable("connection.decoder.class")))
  132. tMsg.connection.getDecoder().setKey(tKey)
  133. tMsg.connection.setEncryption(TRUE)
  134.  
  135. -- Remove problem helper object...
  136.  
  137. if(objectExists("nav_problem_obj")) then
  138. removeObject("nav_problem_obj")
  139. end if
  140.  
  141. -- Perform login if everything is ok...
  142.  
  143. if(me.getComponent().isOkToLogin()) then
  144.  
  145. tUserName = getObject(#session).get(#username)
  146. tPassWord = getObject(#session).get(#password)
  147.  
  148. -- Validate user's name and password...
  149.  
  150. if(not stringP(tUserName)) or (not stringP(tPassWord)) then
  151. return(removeConnection(tMsg.connection.getID()))
  152. end if
  153.  
  154. if(tUserName = EMPTY) or (tPassWord = EMPTY) then
  155. return(removeConnection(tMsg.connection.getID()))
  156. end if
  157.  
  158. -- Send unique ID and perform login...
  159.  
  160. tMsg.connection.send("SET_UID", [#string:getMachineID()])
  161. tMsg.connection.send("TRY_LOGIN", [#string:tUserName, #string:tPassWord])
  162.  
  163. end if
  164.  
  165. end
  166.  
  167.  
  168.  
  169. on handlePing(me, tMsg)
  170.  
  171. -- Reply with a PONG
  172. tMsg.connection.send("PONG")
  173.  
  174. end
  175.  
  176.  
  177.  
  178. on handleRegistrationOK(me, tMsg)
  179.  
  180. tUserName = getObject(#session).get(#username)
  181. tPassWord = getObject(#session).get(#password)
  182.  
  183. -- Validate user's name and password...
  184.  
  185. if(not stringP(tUserName)) or (not stringP(tPassWord)) then
  186. return(removeConnection(tMsg.connection.getID()))
  187. end if
  188.  
  189. if(tUserName = EMPTY) or (tPassWord = EMPTY) then
  190. return(removeConnection(tMsg.connection.getID()))
  191. end if
  192.  
  193. -- Send unique ID and perform login...
  194.  
  195. tMsg.connection.send("SET_UID", [#string:getMachineID()])
  196. tMsg.connection.send("TRY_LOGIN", [#string:tUserName, #string:tPassWord])
  197.  
  198. end
  199.  
  200.  
  201. on handleLoginOK(me, tMsg)
  202.  
  203. tMsg.connection.send("GET_INFO")
  204. tMsg.connection.send("GET_CREDITS")
  205. tMsg.connection.send("GETAVAILABLEBADGES")
  206.  
  207. -- Set session variable that user has logged in\
  208. (used to distinguish update/registration)
  209.  
  210. if (objectExists(#session)) then
  211. getObject(#session).set("userLoggedIn", true)
  212. end if
  213.  
  214. -- Create a debug tool
  215.  
  216. if not(objectExists("loggertool")) then
  217.  
  218. if(memberExists("Debug System Class")) then
  219. createObject("loggertool", "Debug System Class")
  220. -- Check if the debug tool must be inited
  221.  
  222. if (getIntVariable("client.debug.window", 0) = 3) then
  223. -- Open debug due to debug level
  224. getObject("loggertool").initDebug()
  225. else
  226. -- Check user settings for auto startup
  227. getObject("loggertool").tryAutoStart()
  228. end if
  229.  
  230. end if
  231. end if
  232.  
  233. end
  234.  
  235.  
  236. on handleUserObj(me,tMsg)
  237.  
  238. tUser = [:]
  239. tDelim = the itemDelimiter
  240. the itemDelimiter = "="
  241.  
  242. -- Parse key-value pairs...
  243.  
  244. repeat with i = 1 to tMsg.content.line.count
  245. tLine = tMsg.content.line[i]
  246. tUser[tLine.item[1]] = tLine.item[2..tLine.item.count]
  247. end repeat
  248.  
  249. -- Validate character's sex...
  250.  
  251. if(not voidP(tUser["sex"])) then
  252. if(tUser["sex"] contains "F") or (tUser["sex"] contains "f") then
  253. tUser["sex"] = "F"
  254. else
  255. tUser["sex"] = "M"
  256. end if
  257. end if
  258.  
  259. -- Parse character's figure data...(TODO: REFACTORE!!!)
  260.  
  261.  
  262. if objectExists("Figure_System") then
  263. tUser["figure"] = getObject("Figure_System").parseFigure(tUser["figure"], tUser["sex"], "user", "USEROBJECT")
  264. end if
  265.  
  266. the itemDelimiter = tDelim
  267. tSession = getObject(#session)
  268.  
  269. -- Save character data to session object...
  270.  
  271. repeat with i = 1 to tUser.count
  272. tSession.set("user_" & tUser.getPropAt(i), tUser[i])
  273. end repeat
  274.  
  275. -- IMPORTANT: Replace '#username' with case sensitive 'user_name'!!!
  276.  
  277. tSession.set(#username, tSession.get("user_name"))
  278. tSession.set("user_password", tSession.get(#password))
  279.  
  280. -- Tell everyone about updated figure data...
  281.  
  282. executeMessage(#updateFigureData)
  283.  
  284. -- Save valid quick login data...
  285.  
  286. if(getObject(#session).exists("user_logged")) then
  287. return()
  288. else
  289. getObject(#session).set("user_logged", TRUE)
  290. end if
  291.  
  292. if(getIntVariable("quickLogin", FALSE)) and (the runMode contains "Author") then
  293. setPref(getVariable("fuse.project.id", "fusepref"), string([getObject(#session).get(#username), getObject(#session).get(#password)]))
  294. me.getInterface().hideLogin()
  295. else
  296. me.getInterface().showUserFound()
  297. end if
  298.  
  299. -- Tell everyone about succesfull login...
  300.  
  301. executeMessage(#userlogin, "userLogin")
  302.  
  303. end
  304.  
  305.  
  306. on handleUserBanned(me,tMsg)
  307.  
  308. tBanMsg = getText("Alert_YouAreBanned") &RETURN& tMsg.content
  309. executeMessage(#openGeneralDialog, #ban, [#id:"BannWarning", #title:"Alert_YouAreBanned_T", #msg:tBanMsg, #modal:TRUE])
  310. removeConnection(tMsg.connection.getID())
  311.  
  312. end
  313.  
  314.  
  315. on handleEPSnotify(me,tMsg)
  316.  
  317. tType = EMPTY
  318. tData = EMPTY
  319. tDelim = the itemDelimiter
  320. the itemDelimiter = "="
  321.  
  322. repeat with f = 1 to tMsg.content.line.count
  323. tProp = tMsg.content.line[f].item[1]
  324. tDesc = tMsg.content.line[f].item[2]
  325. case(tProp) of
  326. "t": tType = integer(tDesc)
  327. "p": tData = tDesc
  328. end case
  329. end repeat
  330.  
  331. the itemDelimiter = tDelim
  332.  
  333. -- TODO: Remove this from here!! -- -- -- -- -- --
  334.  
  335. case(tType) of
  336.  
  337. 580: -- Time for the language test...
  338.  
  339. if(not createObject("lang_test", "CLangTest")) then
  340. return(error(me, "Failed to init lang tester!", #handle_eps_notify))
  341. else
  342. return(getObject("lang_test").setWord(tData))
  343. end if
  344. end case
  345.  
  346. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  347.  
  348. executeMessage(#notify, tType, tData, tMsg.connection.getID())
  349.  
  350. end
  351.  
  352.  
  353. on handleSystemBroadcast(me,tMsg)
  354.  
  355. tMsg = tMsg[#content]
  356. tMsg = replaceChunks(tMsg, "\r", RETURN)
  357. tMsg = replaceChunks(tMsg, "<br>", RETURN)
  358. executeMessage(#alert, [#msg:tMsg])
  359. the keyboardFocusSprite = 0
  360.  
  361. end
  362.  
  363.  
  364. on handleCheckSum(me,tMsg)
  365.  
  366. getObject(#session).set("user_checksum", tMsg.content)
  367.  
  368. end
  369.  
  370.  
  371. -- Receives list of available badges for user
  372.  
  373. on handleAvailableBadges(me, tMsg)
  374.  
  375. tBadgeList = []
  376. tNumber = tMsg.connection.getIntFrom()
  377.  
  378. repeat with i = 1 to tNumber
  379. tBadgeID = tMsg.connection.getStrFrom()
  380. tBadgeList.add(tBadgeID)
  381. end repeat
  382.  
  383. tChosenBadge = tMsg.connection.getIntFrom()
  384. tVisible = tMsg.connection.getIntFrom()
  385.  
  386. -- List index comes from server as \
  387. java-index, convert to Lingo-index:
  388.  
  389. tChosenBadge = tChosenBadge + 1
  390.  
  391. if(tChosenBadge < 1) then tChosenBadge = 1
  392.  
  393. getObject("session").set("available_badges", tBadgeList)
  394. getObject("session").set("chosen_badge_index", tChosenBadge)
  395. getObject("session").set("badge_visible" , tVisible)
  396.  
  397. end
  398.  
  399.  
  400. -- Receives user rights, stores to session.
  401.  
  402. on handleRights(me, tMsg)
  403.  
  404. tSession = getObject(#session)
  405.  
  406. -- Possible earlier user rights are removed.
  407.  
  408. tSession.set("user_rights", [])
  409.  
  410.  
  411. tRights = tSession.get("user_rights")
  412.  
  413. tPrivilegeFound = TRUE
  414.  
  415. repeat while tPrivilegeFound = TRUE
  416. tPrivilege = tMsg.connection.getStrFrom()
  417. if(tPrivilege = VOID or tPrivilege = "") then
  418. tPrivilegeFound = FALSE
  419. else
  420. tRights.add(tPrivilege)
  421. end if
  422. end repeat
  423.  
  424. return(TRUE)
  425.  
  426. end
  427.  
  428. -- Handles error messages.
  429.  
  430. on handleErr(me, tMsg)
  431.  
  432. error(me, "Error from server:" && tMsg.content, #handle_error)
  433.  
  434. if(tMsg.content contains "login incorrect") then
  435.  
  436. -- Handle failed login...
  437.  
  438. removeConnection(tMsg.connection.getID())
  439. me.getComponent().setaProp(#pOkToLogin, FALSE)
  440.  
  441. if(getObject(#session).exists("failed_password")) then
  442. openNetPage(getText("login_forgottenPassword_url"))
  443. --me.getInterface().showForgottenPW() --RELOCATED TO AN EXTERNAL WEBPAGE
  444. me.getInterface().showLogin()
  445. return FALSE
  446. else
  447. getObject(#session).set("failed_password", TRUE)
  448. me.getInterface().showLogin()
  449. executeMessage(#alert, [#msg:"Alert_WrongNameOrPassword"])
  450. end if
  451.  
  452.  
  453. else if(tMsg.content contains "mod_warn") then
  454.  
  455. -- User received hobba warning...
  456.  
  457. tDelim = the itemDelimiter
  458. the itemDelimiter = "/"
  459. tTextStr = tMsg.content.item[2..tMsg.content.item.count]
  460. the itemDelimiter = tDelim
  461. executeMessage(#alert, [#title:"alert_warning", #msg:tTextStr])
  462.  
  463. else if(tMsg.content contains "Version not correct") then
  464.  
  465. executeMessage(#alert, [#msg:"Old client version!!!"])
  466.  
  467. end if
  468.  
  469. return(TRUE)
  470.  
  471. end
  472.  
  473.  
  474. -- Displays the moderator alert message to the user
  475.  
  476. on handleModAlert(me, tMsg)
  477.  
  478. if (not voidP(tMsg.content)) then
  479. executeMessage(#alert, [#title:"alert_warning", #msg:tMsg.content])
  480.  
  481. else
  482. error(me, "Error in moderator alert:" && tMsg.content, #handleModAlert)
  483.  
  484. end if
  485.  
  486. end
  487.  
  488. -- Server sends updated amount of game tickets.
  489.  
  490. on handleTickets(me,tMsg)
  491.  
  492. getObject(#session).set("user_ph_tickets", integer(tMsg.content.word[1]))
  493. return(TRUE)
  494.  
  495. end
  496.  
  497.  
  498. -- User has bought game tickets OR someone \
  499. has bought them as gift.
  500.  
  501. on handleTicketsBuy(me,tMsg)
  502.  
  503. tTicketsNow = tMsg.content.word[1]
  504. getObject(#session).set("user_ph_tickets", integer(tTicketsNow))
  505.  
  506. return(TRUE)
  507.  
  508. end
  509.  
  510.  
  511. -- User tried to go to some game having no \
  512. game tickets.
  513.  
  514. on handleNoTickets(me,tMsg)
  515.  
  516. executeMessage(#show_ticketwindow)
  517. return(TRUE)
  518.  
  519. end
  520.  
  521.  
  522. -- Registers message listeners & commands.
  523.  
  524. on regMsgList(me, tBool)
  525.  
  526. tMsgs = [:]
  527. tMsgs.setaProp( -1, #handleDisconnect )
  528. tMsgs.setaProp( 0, #handleHello )
  529. tMsgs.setaProp( 1, #handleSecretKey )
  530. tMsgs.setaProp( 2, #handleRights )
  531. tMsgs.setaProp( 3, #handleLoginOK )
  532. tMsgs.setaProp( 5, #handleUserObj )
  533. tMsgs.setaProp( 33, #handleErr )
  534. tMsgs.setaProp( 35, #handleUserBanned )
  535. tMsgs.setaProp( 50, #handlePing )
  536. tMsgs.setaProp( 51, #handleRegistrationOK )
  537. tMsgs.setaProp( 52, #handleEPSnotify)
  538. tMsgs.setaProp( 72, #handleTickets )
  539. tMsgs.setaProp( 73, #handleNoTickets )
  540. tMsgs.setaProp( 124, #handleTicketsBuy )
  541. tMsgs.setaProp( 139, #handleSystembroadcast )
  542. tMsgs.setaProp( 141, #handleChecksum)
  543. tMsgs.setaProp( 161, #handleModAlert )
  544. tMsgs.setaProp( 229, #handleAvailableBadges )
  545. tMsgs.setaProp( 257, #handleSessionParameters )
  546.  
  547.  
  548. tCmds = [:]
  549. tCmds.setaProp( "TRY_LOGIN", 4) -- <#string> name, <#string> pass
  550. tCmds.setaProp( "CHK_VERSION", 5) -- <#short> version
  551. tCmds.setaProp( "SET_UID", 6) -- <#string> id
  552. tCmds.setaProp( "GET_INFO", 7) -- <#void> -
  553. tCmds.setaProp( "GET_CREDITS", 8) -- <#void> -
  554. tCmds.setaProp( "GET_PASSWORD", 47) -- <#string> name, <#string> email
  555. tCmds.setaProp( "LANGCHECK", 58) -- <#string> word / TODO: Move this to 'CLangCheck'!!!
  556. tCmds.setaProp( "BTCKS", 105)
  557. tCmds.setaProp( "GETAVAILABLEBADGES", 157) -- <#void>
  558. tCmds.setaProp( "GET_SESSION_PARAMETERS", 181)
  559. tCmds.setaProp( "PONG", 196) -- <#void>
  560.  
  561.  
  562. tConn = getVariable("connection.info.id", #info)
  563.  
  564. if(tBool) then
  565. registerListener(tConn, me.getID(), tMsgs)
  566. registerCommands(tConn, me.getID(), tCmds)
  567. else
  568. unregisterListener(tConn, me.getID(), tMsgs)
  569. unregisterCommands(tConn, me.getID(), tCmds)
  570. end if
  571.  
  572. return(TRUE)
  573.  
  574. end
  575.  
  576.  
  577. -- End of file. -- -- -- -- -- -- -- -- -- -- -- --//
  578.  
  579. --Login Handler Class
  580. --Antti Kaseva
  581.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement