Advertisement
EvilHero90

TFS 1.x Account Manager by Evil Hero

May 23rd, 2016
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 33.36 KB | None | 0 0
  1. ---------------------------------------------------------------
  2. --                      ONLY EDIT HERE !                     --
  3. ---------------------------------------------------------------
  4. accountManagerConfig =
  5. {
  6.     enabled = true, -- true = You can use the account manager, false = You cannot use the account manager.
  7.     maxCharacters = 10, -- means how much characters each account can have at max.
  8.     kickWithSameIP = true, -- false = if there are more account managers online with the same IP it wont kick them, true = It'll allow only a set ammount of account managers to be logged in with the same IP at once.
  9.     kickAtAmmount = 2, -- this only take in place if "kickWithSameIP" = true; 2 = only two account managers can be logged in with the same IP at once.
  10.     canchooseVoc = true, -- true = your player can choose which voc he wants for his char (start at lvl 8), false = you have no voc and start at lvl 1.
  11.     townID = 1, -- which town the player will be at first login.
  12.     blockedNames = {"GM","GOD","CM","Community Manager","Tutor"}, -- insert all patterns in here for names which you find not appropriate.
  13.     voc = -- put all the starting vocations in here, with the correct id of them.
  14.     {
  15.         [1] = "sorcerer",
  16.         [2] = "druid",
  17.         [3] = "paladin",
  18.         [4] = "knight"
  19.     },
  20.     startDest = -- destination where the account manager spawns at (I recommend a place where he is alone and no other players can go to)
  21.     {
  22.         x = 880,
  23.         y = 1440,
  24.         z = 7
  25.     },
  26.     gender = -- put in here if you have more genders (sex) in your server.
  27.     {
  28.         [0] = "female",
  29.         [1] = "male"
  30.     }
  31. }
  32. ---------------------------------------------------------------
  33. ---------------------------------------------------------------
  34.  
  35. AccountManager = {
  36.     __index = AccountManager,
  37.     existingAccountNames = {},
  38.     existingCharacterNames = {},
  39.     encryptionKey = {}
  40. }
  41.  
  42. setmetatable(AccountManager, {
  43.     __call =
  44.     function(self, id)
  45.         if not self[id] then
  46.             self[id] = {__index = AccountManager, __gc = function(self, id) print("collected Account Class: ".. id) end, state = 0}
  47.             setmetatable(self[id], self[id])
  48.             return self[id]
  49.         else
  50.             return self[id]
  51.         end
  52.     end,
  53.     __gc =
  54.     function(self, id)
  55.         print("collected Account Class: ".. id)
  56.     end
  57. })
  58.  
  59. function Player.sendTextToClient(self, text, author, channelId, chType)
  60.     local network = NetworkMessage()
  61.     network:addByte(0xAA)
  62.     network:addU32(0x00)
  63.     network:addString(author)
  64.     network:addU16(0x00)
  65.     network:addByte(chType)
  66.     network:addU16(channelId)
  67.     network:addString(text)
  68.     network:sendToPlayer(self)
  69.     network:reset()
  70. end
  71.  
  72. function Player.sendTextToLocalChat(self, mClass, text)
  73.     local network = NetworkMessage()
  74.     network:addByte(0xB4)
  75.     network:addByte(mClass)
  76.     network:addString(text)
  77.     network:sendToPlayer(self)
  78.     network:reset()
  79. end
  80.  
  81. function Player.checkCharacterListSize(self)
  82.     local res = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = '".. self:getName() .."'")
  83.     if res then
  84.         accId = result.getDataInt(res, "account_id")
  85.     end
  86.     result.free(res)
  87.     local res = db.storeQuery("SELECT COUNT(*) as row FROM `players` WHERE `account_id` = ".. accId .."")
  88.     if res then
  89.         count = result.getDataInt(res, "row")
  90.     end
  91.     result.free(res)
  92.     return count
  93. end
  94.  
  95. function generateEncryptionKey()
  96.     local key = {}
  97.     repeat
  98.         local n = math.random(string.byte("A"), string.byte("z"))
  99.         if isInArray({91,92,93,94,95,96}, n) or isInArray(key, string.char(n)) then
  100.             repeat
  101.                 n = math.random(string.byte("A"), string.byte("z"))
  102.             until not isInArray({91,92,93,94,95,96}, n) and not isInArray(key, string.char(n))
  103.         end
  104.         table.insert(key, string.char(n))
  105.     until #key == 9
  106.     return key
  107. end
  108.  
  109. function saveEncryptionKey()
  110.     local key = generateEncryptionKey()
  111.     db.query("CREATE TABLE IF NOT EXISTS `recovery_key` (`id` tinyint(1) NOT NULL,`key1` varchar(1) NOT NULL,`key2` varchar(1) NOT NULL,`key3` varchar(1) NOT NULL,`key4` varchar(1) NOT NULL,`key5` varchar(1) NOT NULL,`key6` varchar(1) NOT NULL,`key7` varchar(1) NOT NULL,`key8` varchar(1) NOT NULL,`key9` varchar(1) NOT NULL,UNIQUE KEY (`id`)) ENGINE=InnoDB;")
  112.     local res = db.storeQuery("SELECT * FROM `recovery_key` WHERE `id` = 1")
  113.     if not res then
  114.         db.query("INSERT INTO `recovery_key`(`id`, `key1`, `key2`, `key3`, `key4`, `key5`, `key6`, `key7`, `key8`, `key9`) VALUES (1,'".. key[1] .."','".. key[2] .."','".. key[3] .."','".. key[4] .."','".. key[5] .."','".. key[6] .."','".. key[7] .."','".. key[8] .."','".. key[9] .."')")
  115.     end
  116.     result.free(res)
  117. end
  118.  
  119. function loadEncryptionKey()
  120.     local res = db.storeQuery("SELECT `key1`, `key2`, `key3`, `key4`, `key5`, `key6`, `key7`, `key8`, `key9` FROM `recovery_key` WHERE `id` = 1")
  121.     local keys = {"key1","key2","key3","key4","key5","key6","key7","key8","key9"}
  122.     local encrypt = {}
  123.     if res then
  124.         for k, v in pairs(keys) do
  125.             table.insert(encrypt, result.getDataString(res, v))
  126.         end
  127.     end
  128.     result.free()
  129.     return encrypt
  130. end
  131.    
  132. function kickPlayer(cid)
  133. local player = Player(cid)
  134.     if player then
  135.         player:remove()
  136.     end
  137. end
  138.  
  139. AccountManager.createRecoveryKey = function(self)
  140.     local key = ""
  141.     local seq1 = math.random(3,9)
  142.     math.randomseed(os.time()*os.time())
  143.     local seq2 = math.random(3,9)
  144.     key = tostring(math.floor((seq1 ^ seq2)))
  145.     key = key .."".. encryptionKey[seq1] .."".. encryptionKey[seq2]
  146.     repeat
  147.         local rnd = math.random(0,9)
  148.         key = key .."".. tostring(rnd)
  149.     until string.len(key) >= 15
  150.     return self.mask.recKey = key
  151. end
  152.  
  153. AccountManager.isValidRecoveryKeySequence = function(self)     
  154.     local gKey = ""
  155.     local t = {}; local p = {}; q = ""
  156.     if string.find(self.mask.recKey, "%a") then
  157.         local a = string.find(self.mask.recKey, "%a")
  158.         local z = ""
  159.         for i = 1, a-1 do
  160.             local c = self.mask.recKey:sub(i,i)
  161.             q = q .."".. c
  162.         end
  163.         for i = a, a+1 do
  164.             local c = self.mask.recKey:sub(i,i)
  165.             table.insert(t, c)
  166.         end
  167.         if not isInArray(self.encryptionKey, t[1]) or not isInArray(self.encryptionKey, t[2]) then
  168.             return false
  169.         end
  170.         for y, x in pairs(t) do
  171.             for k, v in pairs(self.encryptionKey) do
  172.                 if x == v then
  173.                     table.insert(p, k)
  174.                 end
  175.             end
  176.         end
  177.         gKey = math.floor((p[1] ^ p[2])) .."".. t[1] .."".. t[2]
  178.         if string.find(self.mask.recKey, gKey) then
  179.             return true
  180.         end
  181.     end
  182.     return false
  183. end
  184.  
  185. AccountManager.createAccountMask = function(self)
  186.     self.mask = {}
  187.         self.mask.accName = ""
  188.         self.mask.accPassword = ""
  189.         self.mask.accPinCode = -1
  190.         self.mask.accEmail = ""
  191.         self.mask.recKey = ""
  192.         self.mask.charName = ""
  193.         self.mask.charVoc = -1
  194.         self.mask.charLevel = -1
  195.         self.mask.charGender = -1
  196. end
  197.  
  198. AccountManager.createRecoverAccountMask = function(self)
  199.     self.mask = {}
  200.         self.mask.accName = ""
  201.         self.mask.email = ""
  202.         self.mask.accPassword = ""
  203.         self.mask.recKey = ""
  204. end
  205.  
  206. AccountManager.createCharacterMask = function(self)
  207.     self.mask = {}
  208.         self.mask.charName = ""
  209.         self.mask.charVoc = -1
  210.         self.mask.charLevel = -1
  211.         self.mask.charGender = -1
  212. end
  213.  
  214. AccountManager.createChangePasswordMask = function(self)
  215.     self.mask = {}
  216.         self.mask.accId = -1
  217.         self.mask.accPinCode = ""
  218.         self.mask.newPassword = ""
  219. end
  220.  
  221. AccountManager.createChangeEmailMask = function(self)
  222.     self.mask = {}
  223.         self.mask.accId = -1
  224.         self.mask.accPinCode = ""
  225.         self.mask.newEmail = ""
  226. end
  227.  
  228. AccountManager.clearMask = function(self)
  229.     self.mask = nil
  230.     self state = 0
  231. end
  232.  
  233. AccountManager.verifyAccountMask = function(self)
  234.     local ret = true
  235.     for k, v in pairs(self.mask) do
  236.         if type(v) == "string" then
  237.             if v == "" then
  238.                 ret = false
  239.             end
  240.         elseif type(v) == "number" then
  241.             if v == -1 then
  242.                 ret = false
  243.             end
  244.         end
  245.     end
  246.     if isInArray(self.existingAccountNames, self.mask.accName) then
  247.         ret = false
  248.     elseif isInArray(self.existingCharacterNames, self.mask.charName) then
  249.         ret = false
  250.     end
  251.     return ret
  252. end
  253.  
  254. AccountManager.verifyRecoverAccountMask = function(self)
  255.     local ret = true
  256.     if not isInArray(self.existingAccountNames, self.mask.accName) then
  257.         return false
  258.     end
  259.     for k, v in pairs(self.mask) do
  260.         if v == "" then
  261.             ret = false
  262.         end
  263.     end
  264.     return ret
  265. end
  266.  
  267. AccountManager.verifyCharacterMask = function(self)
  268.     local ret = true
  269.     for k, v in pairs(self.mask) do
  270.         if type(v) == "string" then
  271.             if v == "" then
  272.                 ret = false
  273.             end
  274.         elseif type(v) == "number" then
  275.             if v == -1 then
  276.                 ret = false
  277.             end
  278.         end
  279.     end
  280.     if isInArray(self.existingCharacterNames, self.mask.charName) then
  281.         ret = false
  282.     end
  283.     return ret
  284. end
  285.  
  286. AccountManager.verifyChangePasswordMask = function(self)
  287.     local ret = true
  288.     for k, v in pairs(self.mask) do
  289.         if type(v) == "string" then
  290.             if v == "" then
  291.                 ret = false
  292.             end
  293.         elseif type(v) == "number" then
  294.             if v == -1 then
  295.                 ret = false
  296.             end
  297.         end
  298.     end
  299.     return ret
  300. end
  301.  
  302. AccountManager.verifyChangeEmailMask = function(self)
  303.     local ret = true
  304.     for k, v in pairs(self.mask) do
  305.         if type(v) == "string" then
  306.             if v == "" then
  307.                 ret = false
  308.             end
  309.         elseif type(v) == "number" then
  310.             if v == -1 then
  311.                 ret = false
  312.             end
  313.         end
  314.     end
  315.     return ret
  316. end
  317.  
  318. AccountManager.createAccount = function(self, player)
  319.     if not self:verifyAccountMask() then
  320.         player:sendTextToClient("There has been an error in verifying the Account details, Account creating has been terminated, you will be logged out in 5 seconds", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  321.         addEvent(kickPlayer, 1000*5, player:getId())
  322.         self:clearMask()
  323.         return false
  324.     end
  325.     db.query("INSERT INTO `accounts`(`name`, `password`, `type`, `premdays`, `lastday`, `email`, `creation`, `recovery_key`, `pin_code`) VALUES ('".. self.mask.accName .."', '".. self.mask.accPassword .."', 0, 0, 0, '".. self.mask.email .."', ".. os.time() ..", '".. self.mask.recKey .."', '".. self.mask.pinCode .."')")
  326.     table.insert(self.existingAccountNames, self.mask.accName)
  327.     local pid = db.storeQuery("SELECT `id` FROM `accounts` WHERE `name` = '".. self.mask.accName .."'")
  328.     local res = 0
  329.     local exp = level == 1 and 0 or 4200
  330.     local lookType = gender == 0 and 136 or 128
  331.     if pid then
  332.         res = result.getDataInt(pid, "id")
  333.         local player = db.query("INSERT INTO `players`(`name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `skull`, `skulltime`, `lastlogout`, `blessings`, `onlinetime`, `deletion`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`) VALUES ('".. self.mask.charName .."',1,".. res ..",".. self.mask.level ..",".. self.mask.charVoc ..",185,185,".. exp ..",68,76,78,58,".. lookType.. ",0,0,40,40,0,100,".. accountManagerConfig.townID ..",".. accountManagerConfig.startDest.x ..",".. accountManagerConfig.startDest.y ..",".. accountManagerConfig.startDest.z ..",0,435,".. self.mask.gender ..",0,0,1,0,0,0,0,0,0,0,43200,-1,2520,10,0,10,0,10,0,10,0,10,0,10,0,10,0)")
  334.         table.insert(self.existingCharacterNames, self.mask.charName)
  335.     end
  336.     result.free(pid)
  337.     return true
  338. end
  339.  
  340. AccountManager.createCharacter = function(self, player)
  341.     if not self:verifyCharacterMask() then
  342.         player:sendTextToClient("There has been an error in verifying the Character details, Character creating has been terminated", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  343.         self:clearMask()
  344.         return false
  345.     end
  346.     local pid = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = '".. player:getName() .."'")
  347.     local res = 0
  348.     local exp = level == 1 and 0 or 4200
  349.     local lookType = gender == 0 and 136 or 128
  350.     if pid then
  351.         res = result.getDataInt(pid, "account_id")
  352.         db.query("INSERT INTO `players`(`name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `skull`, `skulltime`, `lastlogout`, `blessings`, `onlinetime`, `deletion`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`) VALUES ('".. self.mask.charName .."',1,".. res ..",".. self.mask.level ..",".. self.mask.charVoc ..",185,185,".. exp ..",68,76,78,58,".. lookType.. ",0,0,40,40,0,100,".. accountManagerConfig.townID ..",".. accountManagerConfig.startDest.x ..",".. accountManagerConfig.startDest.y ..",".. accountManagerConfig.startDest.z ..",0,435,".. self.mask.gender ..",0,0,1,0,0,0,0,0,0,0,43200,-1,2520,10,0,10,0,10,0,10,0,10,0,10,0,10,0)")
  353.         table.insert(self.existingCharacterNames, self.mask.charName)
  354.     end
  355.     result.free(pid)
  356.     return true
  357. end
  358.  
  359. AccountManager.changePassword = function (self, player)
  360.     if not self:verifyChangePasswordMask() then
  361.         player:sendTextToClient("There has been an error in verifying the change Password details, change Password has been terminated", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  362.         self:clearMask()
  363.         return false
  364.     end
  365.     local res = db.query("UPDATE `accounts` SET `password` = '".. self.mask.newPassword .."' WHERE `id` = ".. self.mask.accId .."")
  366.     return res and true or false
  367. end
  368.  
  369. AccountManager.changeAccountPassword = function(self, player)
  370.     if not self:verifyRecoverAccountMask() then
  371.         player:sendTextToClient("There has been an error in verifying the Recover Account details, Recover Account has been terminated, you will be logged out in 5 seconds", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  372.         addEvent(kickPlayer, 1000*5, player:getId())
  373.         self:clearMask()
  374.         return false
  375.     end
  376.     db.query("UPDATE `accounts` SET `password` = '".. self.mask.accPassword .."' WHERE `name` = '".. self.mask.accName .."'")
  377.     return true
  378. end
  379.  
  380. AccountManager.changeEmail = function(self, player)
  381.     if not self:verifyChangeEmailMask() then
  382.         player:sendTextToClient("There has been an error in verifying the change Email details, change Email has been terminated", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  383.         self:clearMask()
  384.         return false
  385.     end
  386.     local res = db.query("UPDATE `accounts` SET `email` = '".. self.mask.newEmail .."' WHERE `id` = ".. self.mask.accId .."")
  387.     return res and true or false
  388. end
  389.  
  390. function string:findDoubleSpace()
  391.     local t = {}
  392.     local i = 0
  393.     while true do
  394.         i = string.find(self, " ", i+1)
  395.         if i == nil then break end
  396.         table.insert(t, i)
  397.     end
  398.     local ret = false
  399.     local f = {}
  400.     local j = 0
  401.     for k, v in ipairs(t) do
  402.         if k == 1 then
  403.             j = v
  404.         end
  405.         if k > 1 and k <= #t then
  406.             if (j+1) == v then
  407.                 table.insert(f, {j,v})
  408.                 ret = true
  409.             end
  410.             j = v
  411.         end
  412.     end
  413.     return ret and f or ret
  414. end
  415.  
  416. AccountManager.validateCharacterName = function(self, player, message)
  417.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  418.     if string.find(message, ("[%a%s]")) and not message:findDoubleSpace() and not message:find(" ", message:len()) then
  419.         for i = 1,#accountManagerConfig.blockedNames do
  420.             if string.find(message, accountManagerConfig.blockedNames[i]) then
  421.                 player:sendTextToClient("This Character Name consists of illegal parts (ex: GOD / GM / CM), choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  422.                 return
  423.             end
  424.         end
  425.         if string.len(message) >= 3 and string.len(message) <= 15 then
  426.             if not isInArray(self.existingCharacterNames, message) then
  427.                 self.mask.charName = message
  428.                 player:sendTextToClient("Character Name accepted, please choose your Gender.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  429.                 player:sendTextToClient("Gender: male or female", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  430.                 self.state = self.state + 1
  431.             else
  432.                 player:sendTextToClient("This Character Name already exists, please choose another.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  433.             end
  434.         else
  435.             player:sendTextToClient("This Character Name is either to short or to long (min = 3, max = 15)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  436.         end
  437.     else
  438.         player:sendTextToClient("This Character Name consists of illegal characters, only letters and single type spaces are accepted, choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  439.     end
  440. end
  441.  
  442. AccountManager.validateAccountName = function(self, player, message)
  443.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  444.     if message:match("%w") then
  445.         if string.len(message) >= 5 and string.len(message) <= 15 then
  446.             if not isInArray(self.existingAccountNames, message) then
  447.                 self.mask.accName = message
  448.                 player:sendTextToClient("Account Name accepted, please choose your Password.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  449.                 self.state = self.state + 1
  450.             else
  451.                 player:sendTextToClient("This Account Name already exists, please choose another.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  452.             end
  453.         else
  454.             player:sendTextToClient("This Account Name is either to short or to long (min = 5, max = 15)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  455.         end
  456.     else
  457.         player:sendTextToClient("Account Name consists of illegal characters, only alphanumeric Account Names are accepted, choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  458.     end
  459. end
  460.  
  461. AccountManager.validateAccountPassword = function(self, player, message)
  462.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  463.     if message:match("%w") then
  464.         if string.len(message) >= 5 and string.len(message) <= 15 then
  465.             self.mask.accPassword = transformToSha1(message)
  466.             player:sendTextToClient("Account Password accepted, please tell me your Account Pin Code.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  467.             player:sendTextToClient("NOTE: Pin Code is a 4 digit code, which needs to be entered upon password change / email change / character creation & deletion", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  468.             self.state = self.state + 1
  469.         else
  470.             player:sendTextToClient("This Account Password is either to short or to long (min = 5, max = 15)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  471.         end
  472.     else
  473.         player:sendTextToClient("Account Password consists of illegal characters, only alphanumeric Account Passwords are accepted, choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  474.     end
  475. end
  476.  
  477. AccountManager.validateAccountPinCode = function(self, player, message)
  478.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  479.     if message:match("%d") then
  480.         if message:len() == 4 then
  481.             self.mask.accPinCode = transformToSha1(message)
  482.             player:sendTextToClient("Account Pin Code accepted, please tell me your email.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  483.             self.state = self.state + 1
  484.         else
  485.             player:sendTextToClient("This Account Pin Code is either to short or to long (exactly 4 digits)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  486.         end
  487.     else
  488.         player:sendTextToClient("Account Pin Code consists of illegal characters, only digits are accepted, choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  489.     end
  490. end
  491.  
  492. AccountManager.validateAccountEmail = function(self, player, message)
  493.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  494.     if message:match("[%w@._-]") and string.find(message, "[@.]") then
  495.         if string.len(message) >= 7 and string.len(message) <= 25 then
  496.             self.mask.accEmail = message
  497.             player:sendTextToClient("Account email accepted, please choose your Character Name.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  498.             self.state = self.state + 1
  499.         else
  500.             player:sendTextToClient("This email is either to short or to long (min = 7, max = 25)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  501.         end
  502.     else
  503.         player:sendTextToClient("Account email consists of illegal characters, only alphanumeric & [@ . - _] are accepted ex(test@test.net), choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  504.     end
  505. end
  506.  
  507. AccountManager.validateCharacterGender = function(self, player, message)
  508.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  509.     for k, v in pairs(accountManagerConfig.gender) do
  510.         if v == message:lower() then
  511.             self.mask.charGender = k
  512.         end
  513.     end
  514.     if self.mask.charGender == "" then
  515.         player:sendTextToClient("This Gender does not exist, please choose another.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  516.         return false
  517.     end
  518.     if accountManagerConfig.canchooseVoc then
  519.         player:sendTextToClient("A ".. message .." it is, please choose your Vocation.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  520.         local str = accountManagerConfig.voc[1]
  521.         local begin = true
  522.         for i = 2, #accountManagerConfig.voc do
  523.             str = str.." | ".. accountManagerConfig.voc[i]
  524.         end
  525.         player:sendTextToClient("Vocations: ".. str, "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  526.         self.state = self.state + 1
  527.     else
  528.         self.mask.charLevel = 1
  529.         self.mask.charVoc = 0
  530.         if self.create == "account" then
  531.             self:createRecoveryKey()
  532.             if self:createAccount(player) then
  533.                 player:sendTextToClient("Account and Character have successfully been created.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  534.                 player:sendTextToClient("IMPORTANT! write down your Recovery Key, you need it in order to retrieve an Account where you lost your Password.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  535.                 player:sendTextToClient('> "'.. self.mask.recKey ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  536.                 player:sendTextToClient("Your Account has been created, you can login now.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  537.                 self:clearMask()
  538.             end
  539.         else
  540.             if self:createCharacter(player) then
  541.                 player:sendTextToClient("Character has successfully been created.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  542.                 self:clearMask()
  543.             end
  544.         end
  545.     end
  546. end
  547.  
  548. AccountManager.validateCharacterVocation = function(self, player, message)
  549.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  550.     for k, v in pairs(accountManagerConfig.voc) do
  551.         if v == message:lower() then
  552.             self.mask.charVoc = k
  553.             self.mask.charLevel = 8
  554.         end
  555.     end
  556.     if self.mask.charVoc == "" then
  557.         player:sendTextToClient("This Vocation does not exist, please choose another.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  558.         return false
  559.     end
  560.     if self.create == "account" then
  561.         self:createRecoveryKey()
  562.         if self:createAccount(player) then
  563.             player:sendTextToClient("Account and Character have successfully been created.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  564.             player:sendTextToClient("IMPORTANT! write down your Recovery Key, you need it in order to retrieve an Account where you lost your Password.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  565.             player:sendTextToClient('> "'.. self.mask.recKey ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  566.             player:sendTextToClient("Your Account has been created, you can login now.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  567.             self:clearMask()
  568.         end
  569.     else
  570.         if self:createCharacter(player) then
  571.             player:sendTextToClient("Character has successfully been created.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  572.             self:clearMask()
  573.         end
  574.     end
  575. end
  576.  
  577. AccountManager.validateRecoverAccountName = function(self, player, message)
  578.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  579.     if isInArray(self.existingAccountNames, message) then
  580.         self.mask.accName = message
  581.         player:sendTextToClient("Account Name verified, please tell me the Recovery Key.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  582.         self.state = self.state + 1
  583.     else
  584.         -- kicking the player to avoid looping account names to fish them out.
  585.         player:sendTextToClient("This Account Name does not exist, you will be logged out in 5 seconds.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  586.         self:clearMask()
  587.         addEvent(kickPlayer, 1000*5, player:getId())
  588.     end
  589. end
  590.  
  591. AccountManager.validateRecoveryKey = function(self, player, message)
  592.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  593.     self.mask.recKey = message
  594.     if self:isValidRecoveryKeySequence() then
  595.         local res = db.storeQuery("SELECT `email`, `recovery_key` FROM `accounts` WHERE `name` = '".. self.mask.accName .."'")
  596.         if res then
  597.             self.mask.email = result.getDataString(res, "email")
  598.             self.mask.recKey = result.getDataString(res, "recovery_key")
  599.         end
  600.         result.free(res)
  601.         if string.find(message, self.mask.recKey) then
  602.             player:sendTextToClient("Account Recovery Key verified, please tell me the email.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  603.             self.state = self.state + 1
  604.         else
  605.             -- kicking the player to avoid looping account emails to fish them out.
  606.             player:sendTextToClient("The Recovery Key does not match with the Account Name, you will be logged out in 5 seconds.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  607.             self:clearMask()
  608.             addEvent(kickPlayer, 1000*5, player:getId())
  609.         end
  610.     else
  611.         -- kicking the player to avoid looping account emails to fish them out.
  612.         player:sendTextToClient("This key is not valid, you will be logged out in 5 seconds.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  613.         self:clearMask()
  614.         addEvent(kickPlayer, 1000*5, player:getId())
  615.     end
  616. end
  617.  
  618. AccountManager.validateRecoveryEmail = function(self, player, message)
  619.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  620.     if string.find(message, self.mask.email) then
  621.         player:sendTextToClient("Account Email verified, please tell me the new password for the Account.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  622.         self.state = self.state + 1
  623.     else
  624.         -- kicking the player to avoid looping account emails to fish them out.
  625.         player:sendTextToClient("The email does not match with the Account Name, you will be logged out in 5 seconds.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  626.         self:clearMask()
  627.         addEvent(kickPlayer, 1000*5, player:getId())
  628.     end
  629. end
  630.  
  631. AccountManager.validateRecoveryChangePassword = function(self, player)
  632.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  633.     if message:match("%w") then
  634.         if string.len(message) >= 5 and string.len(message) <= 15 then
  635.             self.mask.accPassword = transformToSha1(message)
  636.             if self:changeAccountPassword(player) then
  637.                 player:sendTextToClient("Account Password has been changed.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  638.             end
  639.             self:clearMask()
  640.         else
  641.             player:sendTextToClient("This Account Password is either to short or to long (min = 5, max = 15)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  642.         end
  643.     else
  644.         player:sendTextToClient("Account Password consists of illegal characters, only alphanumeric Account Passwords are accepted, choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  645.     end
  646. end
  647.  
  648. AccountManager.validateCheckAccountPinCode(player, message)
  649.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  650.     if message:match("%d") then
  651.         if message:len() == 4 then
  652.             -- we don't want to execute the query a few times if we fetched it already and the player tries a second time.
  653.             if self.mask.accId == -1 then
  654.                 local res = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = '".. player:getName() .."'")
  655.                 if res then
  656.                     self.mask.accId = result.getDataInt(res, "account_id")
  657.                 end
  658.                 result.free(res)
  659.                 local res = db.storeQuery("SELECT `pin_code` FROM `accounts` WHERE `id` = ".. self.mask.accId .."")
  660.                 if res then
  661.                     self.mask.accPinCode = result.getDataString(res, "pin_code")
  662.                 end
  663.                 result.free(res)
  664.             end
  665.             if self.mask.accPinCode == transformToSha1(message) then
  666.                 if self.create == "password" then
  667.                     self.state = self.state + 1
  668.                     player:sendTextToClient("Account Pin Code has been verified, please tell me your new Password.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  669.                 else
  670.                     self.state = self.state + 1
  671.                     player:sendTextToClient("Account Pin Code has been verified, please tell me your new Email.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  672.                 end
  673.             else
  674.                 player:sendTextToClient("Account Pin Code does not match, please try again.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  675.             end
  676.         else
  677.             player:sendTextToClient("This Account Pin Code is either to short or to long (exactly 4 digits)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  678.         end
  679.     else
  680.         player:sendTextToClient("Account Pin Code is malformed.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  681.     end
  682. end
  683.  
  684. AccountManager.validateChangeAccountPassword = function(self, player, message)
  685.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  686.     if message:match("%w") then
  687.         if string.len(message) >= 5 and string.len(message) <= 15 then
  688.             self.mask.newPassword = transformToSha1(message)
  689.             if self:changePassword(player) then
  690.                 player:sendTextToClient("Password has successfully been changed.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  691.                 self:clearMask()
  692.             end
  693.         else
  694.             player:sendTextToClient("This Account Password is either to short or to long (min = 5, max = 15)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  695.         end
  696.     else
  697.         player:sendTextToClient("Account Password consists of illegal characters, only alphanumeric Account Passwords are accepted, choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  698.     end
  699. end
  700.  
  701. AccountManager.validateChangeAccountEmail = function(self, player)
  702.     player:sendTextToClient('> "'.. message ..'"', "Account Manager", 9, TALKTYPE_CHANNEL_O)
  703.     if message:match("[%w@._-]") and string.find(message, "[@.]") then
  704.         if message:len() >= 7 and message:len() <= 25 then
  705.             self.mask.newEmail = message
  706.             if self:changeEmail(player) then
  707.                 player:sendTextToClient("Account email has successfully been changed.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  708.                 self:clearMask()
  709.             end
  710.         else
  711.             player:sendTextToClient("This email is either to short or to long (min = 7, max = 25)", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  712.         end
  713.     else
  714.         player:sendTextToClient("Account email consists of illegal characters, only alphanumeric & [@ . - _] are accepted ex(test@test.net), choose another please.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  715.     end
  716. end
  717.    
  718. function handleAccountManagerLogin(player)
  719.     if player:getName() == "Account Manager" then
  720.         if accountManagerConfig.kickWithSameIP then
  721.             local players = Game.getPlayers()
  722.             local t = {}
  723.             for k,v in pairs(players) do
  724.                 if v:getName() == "Account Manager" then
  725.                     if v:getIp() == player:getIp() then
  726.                         table.insert(t, v:getId())
  727.                     end
  728.                 end
  729.             end
  730.             if #t > accountManagerConfig.kickAtAmmount then
  731.                 player:disconnectWithReason("There are to much Account Managers online with this IP")
  732.                 return false
  733.             end
  734.         end
  735.         if not accountManagerConfig.enabled then
  736.             player:disconnectWithReason("Account Manager is disabled")
  737.             return false
  738.         end
  739.         local str = "\n-----------------------------------\n"
  740.         str = str .."-->             Account Manager ALPHA                 <--\n"
  741.         str = str .."-->       Author: Evil Hero @ otland.net            <--\n"
  742.         str = str .."-----------------------------------"
  743.         player:sendTextToLocalChat(MESSAGE_STATUS_CONSOLE_BLUE, str)
  744.         player:sendTextToLocalChat(MESSAGE_STATUS_CONSOLE_BLUE, "You need to talk in the 'Account Manager' chat channel")
  745.         player:openChannel(9)
  746.         player:sendTextToClient("write 'info' if you need help.", "Account Manager", 9, TALKTYPE_CHANNEL_R1)
  747.     end
  748.     return true
  749. end
  750.  
  751. function handleAccountManagerStartup()
  752.     if accountManagerConfig.enabled then
  753.         -- Fetch all already existing Account Names from the database for the Account Manager
  754.         local resultId = db.storeQuery("SELECT `name` FROM `accounts`")
  755.         if resultId then
  756.             repeat
  757.                 local name = result.getDataString(resultId, "name")
  758.                 table.insert(AccountManager.existingAccountNames, name)
  759.             until not result.next(resultId)
  760.             result.free(resultId)
  761.         end
  762.    
  763.         -- Fetch all already existing Character Names from the database for the Account Manager
  764.         local resultId = db.storeQuery("SELECT `name` FROM `players`")
  765.         if resultId then
  766.             repeat
  767.                 local name = result.getDataString(resultId, "name")
  768.                 table.insert(AccountManager.existingCharacterNames, name)
  769.             until not result.next(resultId)
  770.             result.free(resultId)
  771.         end
  772.         math.randomseed(os.mtime())
  773.         saveEncryptionKey()
  774.         AccountManager.encryptionKey = loadEncryptionKey()
  775.     end
  776. end
  777.  
  778. function handleAccountManagerParsePacket(player, packet)
  779.     if accountManagerConfig.enabled then
  780.         if player:getName() == "Account Manager" then
  781.             local p = {0xCB,0xA2,100,101,102,103,104,0xE6,0xE8,0x78,0xD4,0x7D,0x82,0x7F,0x83,0x84,0x85,0x9A,0xA1,0xA3,0xA4,0xAA,0xAB,0xD2,0xD3,0xDC,0xF0,0xF1,0xF5,0xF6,0xF9}
  782.             if isInArray(p, packet) then
  783.                 return false
  784.             end
  785.         end
  786.     end
  787.     return true
  788. end
  789.  
  790. function handleAccountManagerMove(player, creature)
  791.     if accountManagerConfig.enabled then
  792.         if player:getName() == "Account Manager" or creature:getName() == "Account Manager" then
  793.             return false
  794.         end
  795.     end
  796.     return true
  797. end
  798.  
  799. function handleAccountManagerTradeRequest(player, creature)
  800.     if accountManagerConfig.enabled then
  801.         if player:getName() == "Account Manager" or creature:getName() == "Account Manager" then
  802.             return false
  803.         end
  804.     end
  805.     return true
  806. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement