Jump to content

Help me pls


Traken

Recommended Posts

Good morning, my mistake is the following.

ERROR: players/main.lua:468: attempt to call global 'sha1' (a nil value)

And according to the console, the error comes from this line.

local info = exports.sql:query_assoc_single( "SELECT CONCAT(SHA1(CONCAT(username, '%s')),SHA1(CONCAT(salt, SHA1(CONCAT('%s',SHA1(CONCAT(salt, SHA1(CONCAT(username, SHA1(password)))))))))) AS token FROM wcf1_user WHERE `username` = '%s' AND password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, '" .. sha1(password) .. "'))))", getPlayerHash( source ), getPlayerHash( source ), username )

Well, the fact is that looking, I found a post which said that I downloaded the following.

------------------------------------------------------------------------------------
--- SHA-1 secure hash computation, and HMAC-SHA1 signature computation in Lua (5.1)
---
--- Based on code originally by Jeffrey Friedl (http://regex.info/blog/lua/sha1)
--- And modified by Eike Decker - (http://cube3d.de/uploads/Main/sha1.txt)
+local sha1 = {
+  _VERSION     = "sha.lua 0.5.0",
+  _URL         = "https://github.com/kikito/sha.lua",
+  _DESCRIPTION = [[
+   SHA-1 secure hash computation, and HMAC-SHA1 signature computation in Lua (5.1)
+   Based on code originally by Jeffrey Friedl (http://regex.info/blog/lua/sha1)
+   And modified by Eike Decker - (http://cube3d.de/uploads/Main/sha1.txt)
+  ]],
+  _LICENSE = [[
+    MIT LICENSE
+
+    Copyright (c) 2013 Enrique García Cota + Eike Decker + Jeffrey Friedl
+
+    Permission is hereby granted, free of charge, to any person obtaining a
+    copy of this software and associated documentation files (the
+    "Software"), to deal in the Software without restriction, including
+    without limitation the rights to use, copy, modify, merge, publish,
+    distribute, sublicense, and/or sell copies of the Software, and to
+    permit persons to whom the Software is furnished to do so, subject to
+    the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+  ]]
+}
+
 -----------------------------------------------------------------------------------
 
 -- loading this file (takes a while but grants a boost of factor 13)
 @@ -157,10 +186,10 @@ for i=0,0xff do
   xor_with_0x36[char(i)] = char(bxor(i,0x36))
 end
 
----------------------------------------------------------------------------------
+-----------------------------------------------------------------------------
 
 -- calculating the SHA1 for some text
-local function sha1(msg)
+function sha1.sha1(msg)
   local H0,H1,H2,H3,H4 = 0x67452301,0xEFCDAB89,0x98BADCFE,0x10325476,0xC3D2E1F0
   local msg_len_in_bits = #msg * 8
 
 @@ -240,33 +269,29 @@ local function sha1(msg)
   return f(H0) .. f(H1) .. f(H2) .. f(H3) .. f(H4)
 end
 
-local function sha1_binary(msg)
-  return hex_to_binary(sha1(msg))
+
+function sha1.binary(msg)
+  return hex_to_binary(sha1.sha1(msg))
 end
 
-local function sha1_hmac(key, text)
+function sha1.hmac(key, text)
   assert(type(key)  == 'string', "key passed to sha1.hmac should be a string")
   assert(type(text) == 'string', "text passed to sha1.hmac should be a string")
 
   if #key > BLOCK_SIZE then
-    key = sha1_binary(key)
+    key = sha1.binary(key)
   end
 
   local key_xord_with_0x36 = key:gsub('.', xor_with_0x36) .. string.rep(string.char(0x36), BLOCK_SIZE - #key)
   local key_xord_with_0x5c = key:gsub('.', xor_with_0x5c) .. string.rep(string.char(0x5c), BLOCK_SIZE - #key)
 
-  return sha1(key_xord_with_0x5c .. sha1_binary(key_xord_with_0x36 .. text))
+  return sha1.sha1(key_xord_with_0x5c .. sha1.binary(key_xord_with_0x36 .. text))
 end
 
-local function sha1_hmac_binary(key, text)
-  return hex_to_binary(sha1_hmac(key, text))
+function sha1.hmac_binary(key, text)
+  return hex_to_binary(sha1.hmac(key, text))
 end
 
-return setmetatable({
-  sha1        = sha1,
-  binary      = sha1_binary,
-  hmac        = sha1_hmac,
-  hmac_binary = sha1_hmac_binary
-}, {
-  __call = function(_,msg) return sha1(msg) end
-})
+setmetatable(sha1, {__call = function(_,msg) return sha1.sha1(msg) end })
+
+return sha1

Very good, downloaded, but now where do I put it? How do I link the file so I can read it?

Thank you very much and I await your response.

Link to comment
  • Moderators

I really hope you didn't copy the Github comments with it. Because the code you posted contains them, if so try to copy the raw format of it.

Raw format: https://raw.githubusercontent.com/kikito/sha1.lua/master/sha1.lua

Replace:(it is in your code, seek and find)

sha1(password)

 

With:

sha1.sha1(password)

 

 

Make sure to check if the code you download is working. :

Edited by IIYAMA
Link to comment

Thank you very much for your response, I just replaced the code for what happened to me, and the error remained the same, thank you.

 

Could you tell me where I have to put the "sha1.lua" folder, taking into account that my server is paradise?

Edited by Traken
Link to comment
  • Moderators

ONLY the file " sha1.lua", not a folder.

Just put it in the root/top layer of the resource where you are going to using this sha1 function.

 

Then open the meta.xml of the resource. (which is also in the root/top layer)

And add there between the meta tags: <meta>HERE</meta>

This:

<script src="sha1.lua" />

 

Link to comment

The error remains the same, I'm going to pass all my meta folder to check if it is well placed.
 

<!--
Copyright (c) 2010 MTA: Paradise

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<meta>
    <info author="mabako" name="Player Manager" version="1.0"/>
    
    <script src="main.lua"/>
    <script src="sha1.lua" />
    <script src="main_c.lua" type="client"/>
    
    <!-- Returns all groups the player is in, starting with the one with the highest priority.
        parameters:
            (player) the player whom to return the groups of.
        returns:
            (table) all groups the player is in, an empty table if none.
    -->
    <export function="getGroups"/>
    
    <!-- Returns the ID of the character the player is currently logged in as.
        parameters:
            (player) the player to get the character's ID of.
        returns:
            (number) the character ID if successful, (bool) false otherwise.
    -->
    <export function="getCharacterID"/>
    
    <!-- Returns the name that's assigned to a character ID.
        parameters:
            (number) Character ID you want to get the name from
        returns:
            (string) Character name if successful, (bool) false otherwise.
    -->
    <export function="getCharacterName"/>
    
    <!-- (server) Returns true if the player is logged in.
        parameters:
            (player) the player to check.
        returns:
            (bool) true if the player is logged in, false otherwise.
    -->
    <export function="isLoggedIn"/>
    
    <!-- (client) Returns true if the local player is logged in.
        returns:
            (bool) true if the local player is logged in, false otherwise.
    -->
    <export function="isLoggedIn" type="client"/>
    
    <!-- Returns true if the player is logged in.
        parameters:
            (player) the player to check.
        returns:
            (bool) true if he's logged in into any user, (bool) false otherwise.
    -->
    <export function="getUserID"/>
    
    <!-- Returns true if the player is logged in.
        parameters:
            (player) the player to check.
        returns:
            (bool) true if he's logged in into any user, (bool) false otherwise.
    -->
    <export function="getUserName"/>
    
    <!-- -- -->
    
    <!-- sets the money value for a player.
        parameters:
            (player) the player to set the money for.
            (number) the amount of money the player now should have.
        returns:
            (bool) true if successful, false otherwise.
    -->
    <export function="setMoney"/>
    
    <!-- gives the player money.
        parameters:
            (player) the player to give the money to.
            (number) the amount of money you want to give to the player.
        returns:
            (bool) true if successful, false otherwise.
    -->
    <export function="giveMoney"/>
    
    <!-- takes money from a player.
        parameters:
            (player) the player to take the money from.
            (number) the amount of money to take from the player.
        returns:
            (bool) true if successful, false otherwise (e.g. if the player does not have enough money).
    -->
    <export function="takeMoney"/>
    
    <!-- retrieves the amount of money a player has
        parameters:
            (player) the player to set the money for.
        returns:
            (number) the amount of money a player has, 0 if he/she isn't logged in.
    -->
    <export function="getMoney"/>
    
    <!-- -- -->
    
    <!-- Creates a new character.
        parameters:
            (player) the player who the new character will belong to.
            (string) name - the name of the character.
            (number) skin - the character's skin. See http://wiki.multitheftauto.com/wiki/All_Skins_Page for a list of skins.
        returns:
            (bool) true if the character was created, false otherwise (such as: a character with that name already exists)
    -->
    <export function="createCharacter"/>
    
    <!-- sends the player an updated character list
        parameters:
            (player) player of whom to reload the char list
        returns:
            (bool) true if successful, false otherwise.
    -->
    <export function="updateCharacters"/>
    
    <!-- (client) Function that is called whenever you select a char from the chararcter selection.
        parameters:
            (number) character id - the char ID you want to spawn as.
            (string) name - the name of the character, only used to check if it's not the one you're currently playing as.
    -->
    <export function="selectCharacter" type="client"/>
    
    <!-- Updates the text and color of a player's nametag.
        parameters:
            (player) player to update the nametag of.
        returns:
            (bool) true if successful, false otherwise.
    -->
    <export function="updateNametag"/>
    
    <!-- Returns the player's current job.
        parameters:
            (player) player to check.
        returns:
            (string) job (e.g. 'taxi') or (nil) if none.
    -->
    <export function="getJob"/>
    
    <!-- Sets a player's job.
        parameters:
            (player) player to set the job of.
            (string) job (e.g. 'taxi') or (nil) if none.
        returns:
            (bool) true if successful, false otherwise.
    -->
    <export function="setJob"/>
    
    <!-- Gets a user option (globally for that user - not per character).
        parameters:
            (player) player to get the option from.
            (string) name of the option.
        returns:
            the option if successful, (nil) otherwise.
    -->
    <export function="getOption"/>
    
    <!-- Sets a user option (globally for that user - not per character).
        parameters:
            (player) player to set the option for.
            (string) name of the option.
            (string/number/bool/nil) value of the option.
        returns:
            (bool) true if successful, false otherwise.
    -->
    <export function="setOption"/>
    
    <script src="registration.lua"/>
    
    <script src="ids.lua"/>
    
    <!-- resolves an ID/name/name part into a player element
        parameters:
            (player) the player who wants to resolve the ID. It'll show "Not logged in" etc. messages to this player. (nil) to show no messages.
            (number) player id or (string) full player name or (string) part of player name
            (bool) ignore login state - if this is set to true, even a not logged in player might be returned (/kick uses this, for example), if set to false an error message will show if the player is not logged in. Default: false.
        returns:
            (player) The player matching your search if exactly one player is found, (nil) otherwise.
    -->
    <export function="getFromName"/>
    
    <!-- retrieves the ID of a player within the range from 1 to (max. number of slots).
        parameters:
            (player) player id of whom to get the ID.
        returns:
            (number) the ID of the player, (nil) if no ID is assigned.
    -->
    <export function="getID"/>
    
    <include resource="sql"/>
    <include resource="gui"/>
    
    <!-- Skin Images -->
    <file src="images/skins/-1.png"/>
    <file src="images/skins/-2.png"/>
    <file src="images/skins/0.png"/>
    <file src="images/skins/7.png"/>
    <file src="images/skins/9.png"/>
    <file src="images/skins/10.png"/>
    <file src="images/skins/11.png"/>
    <file src="images/skins/12.png"/>
    <file src="images/skins/13.png"/>
    <file src="images/skins/14.png"/>
    <file src="images/skins/15.png"/>
    <file src="images/skins/16.png"/>
    <file src="images/skins/17.png"/>
    <file src="images/skins/18.png"/>
    <file src="images/skins/19.png"/>
    <file src="images/skins/20.png"/>
    <file src="images/skins/21.png"/>
    <file src="images/skins/22.png"/>
    <file src="images/skins/23.png"/>
    <file src="images/skins/24.png"/>
    <file src="images/skins/25.png"/>
    <file src="images/skins/26.png"/>
    <file src="images/skins/27.png"/>
    <file src="images/skins/28.png"/>
    <file src="images/skins/29.png"/>
    <file src="images/skins/30.png"/>
    <file src="images/skins/31.png"/>
    <file src="images/skins/32.png"/>
    <file src="images/skins/33.png"/>
    <file src="images/skins/34.png"/>
    <file src="images/skins/35.png"/>
    <file src="images/skins/36.png"/>
    <file src="images/skins/37.png"/>
    <file src="images/skins/38.png"/>
    <file src="images/skins/39.png"/>
    <file src="images/skins/40.png"/>
    <file src="images/skins/41.png"/>
    <file src="images/skins/43.png"/>
    <file src="images/skins/44.png"/>
    <file src="images/skins/45.png"/>
    <file src="images/skins/46.png"/>
    <file src="images/skins/47.png"/>
    <file src="images/skins/48.png"/>
    <file src="images/skins/49.png"/>
    <file src="images/skins/50.png"/>
    <file src="images/skins/51.png"/>
    <file src="images/skins/52.png"/>
    <file src="images/skins/53.png"/>
    <file src="images/skins/54.png"/>
    <file src="images/skins/55.png"/>
    <file src="images/skins/56.png"/>
    <file src="images/skins/57.png"/>
    <file src="images/skins/58.png"/>
    <file src="images/skins/59.png"/>
    <file src="images/skins/60.png"/>
    <file src="images/skins/61.png"/>
    <file src="images/skins/62.png"/>
    <file src="images/skins/63.png"/>
    <file src="images/skins/64.png"/>
    <file src="images/skins/66.png"/>
    <file src="images/skins/67.png"/>
    <file src="images/skins/68.png"/>
    <file src="images/skins/69.png"/>
    <file src="images/skins/70.png"/>
    <file src="images/skins/71.png"/>
    <file src="images/skins/72.png"/>
    <file src="images/skins/73.png"/>
    <file src="images/skins/75.png"/>
    <file src="images/skins/76.png"/>
    <file src="images/skins/77.png"/>
    <file src="images/skins/78.png"/>
    <file src="images/skins/79.png"/>
    <file src="images/skins/80.png"/>
    <file src="images/skins/81.png"/>
    <file src="images/skins/82.png"/>
    <file src="images/skins/83.png"/>
    <file src="images/skins/84.png"/>
    <file src="images/skins/85.png"/>
    <file src="images/skins/87.png"/>
    <file src="images/skins/88.png"/>
    <file src="images/skins/89.png"/>
    <file src="images/skins/90.png"/>
    <file src="images/skins/91.png"/>
    <file src="images/skins/92.png"/>
    <file src="images/skins/93.png"/>
    <file src="images/skins/94.png"/>
    <file src="images/skins/95.png"/>
    <file src="images/skins/96.png"/>
    <file src="images/skins/97.png"/>
    <file src="images/skins/98.png"/>
    <file src="images/skins/99.png"/>
    <file src="images/skins/100.png"/>
    <file src="images/skins/101.png"/>
    <file src="images/skins/102.png"/>
    <file src="images/skins/103.png"/>
    <file src="images/skins/104.png"/>
    <file src="images/skins/105.png"/>
    <file src="images/skins/106.png"/>
    <file src="images/skins/107.png"/>
    <file src="images/skins/108.png"/>
    <file src="images/skins/109.png"/>
    <file src="images/skins/110.png"/>
    <file src="images/skins/111.png"/>
    <file src="images/skins/112.png"/>
    <file src="images/skins/113.png"/>
    <file src="images/skins/114.png"/>
    <file src="images/skins/115.png"/>
    <file src="images/skins/116.png"/>
    <file src="images/skins/117.png"/>
    <file src="images/skins/118.png"/>
    <file src="images/skins/120.png"/>
    <file src="images/skins/121.png"/>
    <file src="images/skins/122.png"/>
    <file src="images/skins/123.png"/>
    <file src="images/skins/124.png"/>
    <file src="images/skins/125.png"/>
    <file src="images/skins/126.png"/>
    <file src="images/skins/127.png"/>
    <file src="images/skins/128.png"/>
    <file src="images/skins/129.png"/>
    <file src="images/skins/130.png"/>
    <file src="images/skins/131.png"/>
    <file src="images/skins/132.png"/>
    <file src="images/skins/133.png"/>
    <file src="images/skins/134.png"/>
    <file src="images/skins/135.png"/>
    <file src="images/skins/136.png"/>
    <file src="images/skins/137.png"/>
    <file src="images/skins/138.png"/>
    <file src="images/skins/139.png"/>
    <file src="images/skins/140.png"/>
    <file src="images/skins/141.png"/>
    <file src="images/skins/142.png"/>
    <file src="images/skins/143.png"/>
    <file src="images/skins/144.png"/>
    <file src="images/skins/145.png"/>
    <file src="images/skins/146.png"/>
    <file src="images/skins/147.png"/>
    <file src="images/skins/148.png"/>
    <file src="images/skins/150.png"/>
    <file src="images/skins/151.png"/>
    <file src="images/skins/152.png"/>
    <file src="images/skins/153.png"/>
    <file src="images/skins/154.png"/>
    <file src="images/skins/155.png"/>
    <file src="images/skins/156.png"/>
    <file src="images/skins/157.png"/>
    <file src="images/skins/158.png"/>
    <file src="images/skins/159.png"/>
    <file src="images/skins/160.png"/>
    <file src="images/skins/161.png"/>
    <file src="images/skins/162.png"/>
    <file src="images/skins/163.png"/>
    <file src="images/skins/164.png"/>
    <file src="images/skins/165.png"/>
    <file src="images/skins/166.png"/>
    <file src="images/skins/167.png"/>
    <file src="images/skins/168.png"/>
    <file src="images/skins/169.png"/>
    <file src="images/skins/170.png"/>
    <file src="images/skins/171.png"/>
    <file src="images/skins/172.png"/>
    <file src="images/skins/173.png"/>
    <file src="images/skins/174.png"/>
    <file src="images/skins/175.png"/>
    <file src="images/skins/176.png"/>
    <file src="images/skins/177.png"/>
    <file src="images/skins/178.png"/>
    <file src="images/skins/179.png"/>
    <file src="images/skins/180.png"/>
    <file src="images/skins/181.png"/>
    <file src="images/skins/182.png"/>
    <file src="images/skins/183.png"/>
    <file src="images/skins/184.png"/>
    <file src="images/skins/185.png"/>
    <file src="images/skins/186.png"/>
    <file src="images/skins/187.png"/>
    <file src="images/skins/188.png"/>
    <file src="images/skins/189.png"/>
    <file src="images/skins/190.png"/>
    <file src="images/skins/191.png"/>
    <file src="images/skins/192.png"/>
    <file src="images/skins/193.png"/>
    <file src="images/skins/194.png"/>
    <file src="images/skins/195.png"/>
    <file src="images/skins/196.png"/>
    <file src="images/skins/197.png"/>
    <file src="images/skins/198.png"/>
    <file src="images/skins/199.png"/>
    <file src="images/skins/200.png"/>
    <file src="images/skins/201.png"/>
    <file src="images/skins/202.png"/>
    <file src="images/skins/203.png"/>
    <file src="images/skins/204.png"/>
    <file src="images/skins/205.png"/>
    <file src="images/skins/206.png"/>
    <file src="images/skins/207.png"/>
    <file src="images/skins/209.png"/>
    <file src="images/skins/210.png"/>
    <file src="images/skins/211.png"/>
    <file src="images/skins/212.png"/>
    <file src="images/skins/213.png"/>
    <file src="images/skins/214.png"/>
    <file src="images/skins/215.png"/>
    <file src="images/skins/216.png"/>
    <file src="images/skins/217.png"/>
    <file src="images/skins/218.png"/>
    <file src="images/skins/219.png"/>
    <file src="images/skins/220.png"/>
    <file src="images/skins/221.png"/>
    <file src="images/skins/222.png"/>
    <file src="images/skins/223.png"/>
    <file src="images/skins/224.png"/>
    <file src="images/skins/225.png"/>
    <file src="images/skins/226.png"/>
    <file src="images/skins/227.png"/>
    <file src="images/skins/228.png"/>
    <file src="images/skins/229.png"/>
    <file src="images/skins/230.png"/>
    <file src="images/skins/231.png"/>
    <file src="images/skins/232.png"/>
    <file src="images/skins/233.png"/>
    <file src="images/skins/234.png"/>
    <file src="images/skins/235.png"/>
    <file src="images/skins/236.png"/>
    <file src="images/skins/237.png"/>
    <file src="images/skins/238.png"/>
    <file src="images/skins/239.png"/>
    <file src="images/skins/240.png"/>
    <file src="images/skins/241.png"/>
    <file src="images/skins/242.png"/>
    <file src="images/skins/243.png"/>
    <file src="images/skins/244.png"/>
    <file src="images/skins/245.png"/>
    <file src="images/skins/246.png"/>
    <file src="images/skins/247.png"/>
    <file src="images/skins/248.png"/>
    <file src="images/skins/249.png"/>
    <file src="images/skins/250.png"/>
    <file src="images/skins/251.png"/>
    <file src="images/skins/252.png"/>
    <file src="images/skins/253.png"/>
    <file src="images/skins/254.png"/>
    <file src="images/skins/255.png"/>
    <file src="images/skins/256.png"/>
    <file src="images/skins/257.png"/>
    <file src="images/skins/258.png"/>
    <file src="images/skins/259.png"/>
    <file src="images/skins/260.png"/>
    <file src="images/skins/261.png"/>
    <file src="images/skins/262.png"/>
    <file src="images/skins/263.png"/>
    <file src="images/skins/264.png"/>
    <file src="images/skins/274.png"/>
    <file src="images/skins/275.png"/>
    <file src="images/skins/276.png"/>
    <file src="images/skins/277.png"/>
    <file src="images/skins/278.png"/>
    <file src="images/skins/279.png"/>
    <file src="images/skins/280.png"/>
    <file src="images/skins/281.png"/>
    <file src="images/skins/282.png"/>
    <file src="images/skins/283.png"/>
    <file src="images/skins/284.png"/>
    <file src="images/skins/285.png"/>
    <file src="images/skins/286.png"/>
    <file src="images/skins/287.png"/>
    <file src="images/skins/288.png"/>
    
    <script src="skins.lua"/>
    <script src="skins.lua" type="client"/>
    
    <!-- Returns a table of all valid skins.
        returns: table with skins.
    -->
    <export function="getSkins"/>
    <export function="getSkins" type="client"/>
    
    <!-- Checks if a skin is valid.
        parameters:
            (number) skin ID - the skin to check.
        returns:
            (bool) true if the skin is valid, false otherwise.
    -->
    <export function="isValidSkin"/>
    <export function="isValidSkin" type="client"/>
    
    <!-- Returns a table with the details of a skin.
            (number) skin ID - the skin to check.
        returns:
            (table) with two fields:
                (string) gender: male/female
                (string) color: white/black
    -->
    <export function="getSkinDetails"/>
    <export function="getSkinDetails" type="client"/>
    
    <script src="respawn.lua"/>
    <script src="respawn_c.lua" type="client"/>
    
    <script src="afk.lua"/>
    <script src="afk_c.lua" type="client"/>
    
    <script src="tutorial_c.lua" type="client"/>
    
    <script src="pay.lua"/>
    
    
    <script src="language_g.lua"/>
    <script src="language_g.lua" type="client"/>
    <script src="language.lua"/>
    
    <!-- Returns a { language name, shortcut } table for all languages
        returns:
            (table) with all languages
    -->
    <export function="getLanguages"/>
    <export function="getLanguages" type="client"/>
    
    <!-- Returns whetever a flag is valid.
        parameters:
            (string) flag.
        returns:
            (bool) true if valid, false otherwise.
    -->
    <export function="isValidLanguage"/>
    <export function="isValidLanguage" type="client"/>
    
    <!-- Returns the full name of a language.
        parameters:
            (string) flag.
        returns:
            (string) full name if valid, (bool) false otherwise.
    -->
    <export function="getLanguageName"/>
    <export function="getLanguageName" type="client"/>
    
    <!-- Returns the player's current language.
        parameters:
            (player) the player to retrieve the language of.
        returns:
            (string) language's flag if any, (nil) otherwise.
    -->
    <export function="getCurrentLanguage"/>
    
    <!-- Returns the player's skill for a language.
        parameters:
            (player) the player to retrieve the language skill from.
            (string) language to get the skill from.
        returns:
            (number) 0-1000 for any skill, (false) if he doesn't speak the language.
    -->
    <export function="getLanguageSkill"/>
    
    <!-- Increases a player's language skill.
        parameters:
            (player) the player to increase the language skill for.
            (string) language to increase the skill for.
        returns:
            (bool) true if successful, false otherwise.
    -->
    <export function="increaseLanguageSkill"/>
    
    <!-- Learn a player a language.
        parameters:
            (player) the player to learn the language.
            (string) language to learn.
        returns:
            (bool) true if successful, false otherwise.
            (number) error code if failed.
                1 - Invalid Language.
                2 - Player does speak the language already.
                3 - Player exceeded maximum amount of languages.
                4 - MySQL-Error.
    -->
    <export function="learnLanguage"/>
    
    <file src="images/flags/ar.png"/>
    <file src="images/flags/cn.png"/>
    <file src="images/flags/de.png"/>
    <file src="images/flags/en.png"/>
    <file src="images/flags/es.png"/>
    <file src="images/flags/fi.png"/>
    <file src="images/flags/fr.png"/>
    <file src="images/flags/gr.png"/>
    <file src="images/flags/in.png"/>
    <file src="images/flags/il.png"/>
    <file src="images/flags/it.png"/>
    <file src="images/flags/jp.png"/>
    <file src="images/flags/kr.png"/>
    <file src="images/flags/ma.png"/>
    <file src="images/flags/nl.png"/>
    <file src="images/flags/pl.png"/>
    <file src="images/flags/pt.png"/>
    <file src="images/flags/ru.png"/>
    <file src="images/flags/se.png"/>
    <file src="images/flags/vn.png"/>
</meta>

(https://gyazo.com/7814be2f591545e9b8e79190caa22859) This is a photo from the sha1.lua folder. 

And this is what is inside,

 

local sha1 = {
  _VERSION     = "sha.lua 0.5.0",
  _URL         = "https://github.com/kikito/sha.lua",
  _DESCRIPTION = [[
   SHA-1 secure hash computation, and HMAC-SHA1 signature computation in Lua (5.1)
   Based on code originally by Jeffrey Friedl (http://regex.info/blog/lua/sha1)
   And modified by Eike Decker - (http://cube3d.de/uploads/Main/sha1.txt)
  ]],
  _LICENSE = [[
    MIT LICENSE

    Copyright (c) 2013 Enrique García Cota + Eike Decker + Jeffrey Friedl

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be included
    in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  ]]
}

-----------------------------------------------------------------------------------

-- loading this file (takes a while but grants a boost of factor 13)
local PRELOAD_CACHE = true

local BLOCK_SIZE = 64 -- 512 bits

-- local storing of global functions (minor speedup)
local floor,modf = math.floor,math.modf
local char,format,rep = string.char,string.format,string.rep

-- merge 4 bytes to an 32 bit word
local function bytes_to_w32(a,b,c,d) return a*0x1000000+b*0x10000+c*0x100+d end
-- split a 32 bit word into four 8 bit numbers
local function w32_to_bytes(i)
  return floor(i/0x1000000)%0x100,floor(i/0x10000)%0x100,floor(i/0x100)%0x100,i%0x100
end

-- shift the bits of a 32 bit word. Don't use negative values for "bits"
local function w32_rot(bits,a)
  local b2 = 2^(32-bits)
  local a,b = modf(a/b2)
  return a+b*b2*(2^(bits))
end

-- caching function for functions that accept 2 arguments, both of values between
-- 0 and 255. The function to be cached is passed, all values are calculated
-- during loading and a function is returned that returns the cached values (only)
local function cache2arg(fn)
  if not PRELOAD_CACHE then return fn end
  local lut = {}
  for i=0,0xffff do
    local a,b = floor(i/0x100),i%0x100
    lut[i] = fn(a,b)
  end
  return function(a,b)
    return lut[a*0x100+b]
  end
end

-- splits an 8-bit number into 8 bits, returning all 8 bits as booleans
local function byte_to_bits(b)
  local b = function(n)
    local b = floor(b/n)
    return b%2==1
  end
  return b(1),b(2),b(4),b(8),b(16),b(32),b(64),b(128)
end

-- builds an 8bit number from 8 booleans
local function bits_to_byte(a,b,c,d,e,f,g,h)
  local function n(b,x) return b and x or 0 end
  return n(a,1)+n(b,2)+n(c,4)+n(d,8)+n(e,16)+n(f,32)+n(g,64)+n(h,128)
end

-- bitwise "and" function for 2 8bit number
local band = cache2arg (function(a,b)
  local A,B,C,D,E,F,G,H = byte_to_bits(b)
  local a,b,c,d,e,f,g,h = byte_to_bits(a)
  return bits_to_byte(
    A and a, B and b, C and c, D and d,
    E and e, F and f, G and g, H and h)
end)

-- bitwise "or" function for 2 8bit numbers
local bor = cache2arg(function(a,b)
  local A,B,C,D,E,F,G,H = byte_to_bits(b)
  local a,b,c,d,e,f,g,h = byte_to_bits(a)
  return bits_to_byte(
    A or a, B or b, C or c, D or d,
    E or e, F or f, G or g, H or h)
end)

-- bitwise "xor" function for 2 8bit numbers
local bxor = cache2arg(function(a,b)
  local A,B,C,D,E,F,G,H = byte_to_bits(b)
  local a,b,c,d,e,f,g,h = byte_to_bits(a)
  return bits_to_byte(
    A ~= a, B ~= b, C ~= c, D ~= d,
    E ~= e, F ~= f, G ~= g, H ~= h)
end)

-- bitwise complement for one 8bit number
local function bnot(x)
  return 255-(x % 256)
end

-- creates a function to combine to 32bit numbers using an 8bit combination function
local function w32_comb(fn)
  return function(a,b)
    local aa,ab,ac,ad = w32_to_bytes(a)
    local ba,bb,bc,bd = w32_to_bytes(b)
    return bytes_to_w32(fn(aa,ba),fn(ab,bb),fn(ac,bc),fn(ad,bd))
  end
end

-- create functions for and, xor and or, all for 2 32bit numbers
local w32_and = w32_comb(band)
local w32_xor = w32_comb(bxor)
local w32_or = w32_comb(bor)

-- xor function that may receive a variable number of arguments
local function w32_xor_n(a,...)
  local aa,ab,ac,ad = w32_to_bytes(a)
  for i=1,select('#',...) do
    local ba,bb,bc,bd = w32_to_bytes(select(i,...))
    aa,ab,ac,ad = bxor(aa,ba),bxor(ab,bb),bxor(ac,bc),bxor(ad,bd)
  end
  return bytes_to_w32(aa,ab,ac,ad)
end

-- combining 3 32bit numbers through binary "or" operation
local function w32_or3(a,b,c)
  local aa,ab,ac,ad = w32_to_bytes(a)
  local ba,bb,bc,bd = w32_to_bytes(b)
  local ca,cb,cc,cd = w32_to_bytes(c)
  return bytes_to_w32(
    bor(aa,bor(ba,ca)), bor(ab,bor(bb,cb)), bor(ac,bor(bc,cc)), bor(ad,bor(bd,cd))
  )
end

-- binary complement for 32bit numbers
local function w32_not(a)
  return 4294967295-(a % 4294967296)
end

-- adding 2 32bit numbers, cutting off the remainder on 33th bit
local function w32_add(a,b) return (a+b) % 4294967296 end

-- adding n 32bit numbers, cutting off the remainder (again)
local function w32_add_n(a,...)
  for i=1,select('#',...) do
    a = (a+select(i,...)) % 4294967296
  end
  return a
end
-- converting the number to a hexadecimal string
local function w32_to_hexstring(w) return format("%08x",w) end

local function hex_to_binary(hex)
  return hex:gsub('..', function(hexval)
    return string.char(tonumber(hexval, 16))
  end)
end

-- building the lookuptables ahead of time (instead of littering the source code
-- with precalculated values)
local xor_with_0x5c = {}
local xor_with_0x36 = {}
for i=0,0xff do
  xor_with_0x5c[char(i)] = char(bxor(i,0x5c))
  xor_with_0x36[char(i)] = char(bxor(i,0x36))
end

-----------------------------------------------------------------------------

-- calculating the SHA1 for some text
function sha1.sha1(msg)
  local H0,H1,H2,H3,H4 = 0x67452301,0xEFCDAB89,0x98BADCFE,0x10325476,0xC3D2E1F0
  local msg_len_in_bits = #msg * 8

  local first_append = char(0x80) -- append a '1' bit plus seven '0' bits

  local non_zero_message_bytes = #msg +1 +8 -- the +1 is the appended bit 1, the +8 are for the final appended length
  local current_mod = non_zero_message_bytes % 64
  local second_append = current_mod>0 and rep(char(0), 64 - current_mod) or ""

  -- now to append the length as a 64-bit number.
  local B1, R1 = modf(msg_len_in_bits  / 0x01000000)
  local B2, R2 = modf( 0x01000000 * R1 / 0x00010000)
  local B3, R3 = modf( 0x00010000 * R2 / 0x00000100)
  local B4    = 0x00000100 * R3

  local L64 = char( 0) .. char( 0) .. char( 0) .. char( 0) -- high 32 bits
        .. char(B1) .. char(B2) .. char(B3) .. char(B4) --  low 32 bits

  msg = msg .. first_append .. second_append .. L64

  assert(#msg % 64 == 0)

  local chunks = #msg / 64

  local W = { }
  local start, A, B, C, D, E, f, K, TEMP
  local chunk = 0

  while chunk < chunks do
    --
    -- break chunk up into W[0] through W[15]
    --
    start,chunk = chunk * 64 + 1,chunk + 1

    for t = 0, 15 do
      W[t] = bytes_to_w32(msg:byte(start, start + 3))
      start = start + 4
    end

    --
    -- build W[16] through W[79]
    --
    for t = 16, 79 do
      -- For t = 16 to 79 let Wt = S1(Wt-3 XOR Wt-8 XOR Wt-14 XOR Wt-16).
      W[t] = w32_rot(1, w32_xor_n(W[t-3], W[t-8], W[t-14], W[t-16]))
    end

    A,B,C,D,E = H0,H1,H2,H3,H4

    for t = 0, 79 do
      if t <= 19 then
        -- (B AND C) OR ((NOT B) AND D)
        f = w32_or(w32_and(B, C), w32_and(w32_not(B), D))
        K = 0x5A827999
      elseif t <= 39 then
        -- B XOR C XOR D
        f = w32_xor_n(B, C, D)
        K = 0x6ED9EBA1
      elseif t <= 59 then
        -- (B AND C) OR (B AND D) OR (C AND D
        f = w32_or3(w32_and(B, C), w32_and(B, D), w32_and(C, D))
        K = 0x8F1BBCDC
      else
        -- B XOR C XOR D
        f = w32_xor_n(B, C, D)
        K = 0xCA62C1D6
      end

      -- TEMP = S5(A) + ft(B,C,D) + E + Wt + Kt;
      A,B,C,D,E = w32_add_n(w32_rot(5, A), f, E, W[t], K),
        A, w32_rot(30, B), C, D
    end
    -- Let H0 = H0 + A, H1 = H1 + B, H2 = H2 + C, H3 = H3 + D, H4 = H4 + E.
    H0,H1,H2,H3,H4 = w32_add(H0, A),w32_add(H1, B),w32_add(H2, C),w32_add(H3, D),w32_add(H4, E)
  end
  local f = w32_to_hexstring
  return f(H0) .. f(H1) .. f(H2) .. f(H3) .. f(H4)
end


function sha1.binary(msg)
  return hex_to_binary(sha1.sha1(msg))
end

function sha1.hmac(key, text)
  assert(type(key)  == 'string', "key passed to sha1.hmac should be a string")
  assert(type(text) == 'string', "text passed to sha1.hmac should be a string")

  if #key > BLOCK_SIZE then
    key = sha1.binary(key)
  end

  local key_xord_with_0x36 = key:gsub('.', xor_with_0x36) .. string.rep(string.char(0x36), BLOCK_SIZE - #key)
  local key_xord_with_0x5c = key:gsub('.', xor_with_0x5c) .. string.rep(string.char(0x5c), BLOCK_SIZE - #key)

  return sha1.sha1(key_xord_with_0x5c .. sha1.binary(key_xord_with_0x36 .. text))
end

function sha1.hmac_binary(key, text)
  return hex_to_binary(sha1.hmac(key, text))
end

setmetatable(sha1, {__call = function(_,msg) return sha1.sha1(msg) end })

return sha1

 

Really, I feel the discomfort

Edited by Traken
Link to comment
  • MTA Team

This particular function, which you copied from GitHub, is already given to you through the MTA functions. I gave you the link to the wiki and a little example function call how to do it, where did you get stuck? I mean, you only have to call the function hash with the first parameter being the algorithm as a string, in your case it should be "sha1", and the second parameter the to-be-hashed string. In your code you did sha1(password), replace it with hash("sha1", password). Work done and you don't have to include any third-party code to your resource.

Edited by Necktrox
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...