Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 16/03/20 in all areas

  1. اخباركم ان شاء الله بخير سويت مود جديد و حبيت اعرضه عليكم عشان الاقتراحات و النقد الإيجابي المهم اترككم معى الصور ملاحظة السكربت موجه للحياة الوقعية و حرب العصابات و حتى الهجولة طريقة نثل البيانات mysql + xml :PIS:
    2 points
  2. Sim é possível use setWorldSoundEnabled
    2 points
  3. شرح بعض الوضائف التي تم اضافتها حديثا في لعبة MULTI THEFT AUTO: SAN os.clock() الوقت المستخدم من قبل اللعبة (CPU) تقوم هذه الوظيفة بإعادة رقم من وحدة المعالجة المركزية على سبيل المثال local x = os.clock() ---- كمتغير لحفض وقت المستخدم من الوحة المركزية (x) وضع print(string.format("elapsed time: %.2f\n",x/360 )) --- (x) طباعة في (الدي بق) قيمة المتغير --[[OUT PUT elapsed time: 23.46 ]] os.date(format [, time]]) تقوم هذه الوظيفة بإرجاع سلسة او جدول يحتوي على التاريخ و الوقت ، منسق و وفقا لتنسيق السلسلة المحددة _______________ | | | TABLE TIME | |_______________| | KEY | VALUE | |_______|______ | | hour | 23 | | min | 42 | | wday | 07 | | day | 07 | | month | 03 | | year | 2020 | | sec | 57 | | yday | 67 | |_______________| ex 1 : for k, v in pairs(os.date("!*t")) do outputConsole(k .." : ".. v) end -- OR table.foreach(os.date("*t"),print) --[[ OUTPUT hour : 22 min : 53 wday : 7 day : 7 month : 3 year : 2020 sec : 54 yday : 67 ex 2 : print("(1) ==>",os.date()) --- (2) print("(2) ==>",os.date("%d.%m.%Y")) --- (1) --[[OUT PUT : (1) ==> Sat Mar 7 23:59:53 2020 (2) ==> 07.03.2020 os.difftime(t2, t1) (t1) و (t2) تقوم هذه الوظيفة بحساب الفرق بالثواني بين ex : t1 = os.time() --- make time system with seconds -- wait a little while then type.... os.difftime(os.time(), t1) --- OUTPUT : 31 os.difftime(os.time(), t1) --- OUTPUT : 38 والسلام عليكم ورحمة الله تعالى وبركته ان شاء الله يكون واضح و مفهوم بالتوفيق (:PiS
    1 point
  4. Utilize o Evento "onClientResourceStart" do lado do client-side : addEventHandler("onClientResourceStart", resourceRoot, function() -- Adicione o Script ... end)
    1 point
  5. السلام عليكم ورحمة الله وبركاته سكربت قميل ومتعوب عليه .. بس لو تسويه يروح على مكان ويكون فيه بيد يكون افضل .. بيصير مثل واقعي , عموما بلتوفيق سكربت ممتاز ومتعوب عليه
    1 point
  6. Because putting 'p' at the right spot into the parantheses of the command-handlers is the only way to request the player that executed said command handler. If you don't specify the p then you tell Lua that you don't care about p and then you cannot possibly expect p to be defined in any way. What majqq said is 100% correct. Let me clarify by adding that getPlayerAccount does never return "true", it is only possible that it returns "false" in certain conditions. And you never want it to return "false" so check the argument before calling getPlayerAccount with invalid things!
    1 point
  7. All you should do is get new look at coordinates -> send to server -> sync to others clients but remember; dont try to destroy your server's network --serverside addEvent('syncLookAt', true) addEventHandler('syncLookAt', root, function(x,y,z) triggerLatentClientEvent("setLookAt", 30000, false, client, x,y,z) -- triggerClientEvent("setLookAt", client, x,y,z) end) --clientside local screenW, screenH = guiGetScreenSize() setTimer(function() local x,y,z = getWorldFromScreenPosition(screenW*0.5, screenH*0.5, 10) triggerLatentServerEvent("syncLookAt", 30000, false, localPlayer, x,y,z) -- triggerServerEvent("syncLookAt", localPlayer, x,y,z) end, 200, 0) addEvent('setLookAt', true) addEventHandler('setLookAt', root, function(x,y,z) setPedLookAt(source, x,y,z) end)
    1 point
  8. That's correct, it's either true or false. p isn't defined in your code. Test this piece of example code, you should understand after typing /testcmd (server-side code) function myCommand(player, cmd) outputChatBox("player: "..inspect(player).." cmd: "..inspect(cmd)) end addCommandHandler("testcmd", myCommand)
    1 point
  9. Good question. I don't know. A release like 1.6 should probably be pretty big. And we have lots of management decisions to make (relating to software update processes, branch processes, etc). So more time is needed. I'd guess before the summer?
    1 point
  10. I looked at your error log and saw that the getPlayerAccount function did receive a nil as first argument. Then after checking your script I realized that p was nil. Finally I tried to search for p in your script and could not find it's definition, thus the error. Now that the error was known, I tried to repair your script. Since I know that Warning1 is a command-handler in my experience a typical error is forgetting to allocate or misnaming the function parameters in the command-handler signature, like the player. This repair was confirmed by the getPlayerAccount function, which expects a player as first argument. What majqq has described is very similar to what I'd do. He did check the wiki to find that getPlayerAccount returns false because the first argument was invalid. I think this is a good idea. Obviously the "anything can go there" assumption is wrong. A command-handler has this very specific signature: void commandHandler(player, cmdName, arg1, arg2, ...) But looking at your first script where you wrote... local function loopVehicles(p) I am pretty sure that you knew that, but you still ... forgot to write it correctly for the "Warning1" function. No idea where this error came from
    1 point
  11. Due of error codes, it's easy. Function expects element (mostly stored in variable or as parameter), your p is nil. Similar case, but this time you got boolean (false), let's check what returns getPlayerAccount: Your variable p was nil, and therefore function returned false on it's failure.
    1 point
  12. UPDATE: -Added 5150 to moderators team -Players can no longer switch weapons while cursor is showing or a window is open -Fixed a bug that killed a player when climbing a tower in [TDM] Poland -Fixed a bug that disabled collisions of the player with an aircraft when he left the plane for any reason -Fixed a bug that prevented damage from occuring when firing at a submarine with large caliber shells -Fixed a bug that prevented the player from entering a submarine when it has low health -Fixed a bug that prevented a submarine from sinking when it got rammed by a ship -Fixed an exploit that created no noise when jumping -Vehicles do now automatically apply the handbrake as soon as the engine gets turn off
    1 point
  13. Introduction Properly handling your user's credentials (username and password) is very important, this guide gives detailed information and code samples on how to (properly) implement an account "system". This guide assumes you are not using MTA's built in accounts. Disclaimer: Any code shown in this tutorial is purely for illustrative purposes, and is not finished code, you should use it as a guideline, not a solution. Content The following topics will be discussed in this tutorial: How to hash and salt passwords (register) How to validate a hashed password (login) How to add "remember-me" functionality How to offer password recovery How to migrate from an older hashing algorithm, to a newer one Using a password policy (Extra) How to handle database leaks (Extra) What even is hashing and salting? For the purpose of this tutorial we expect a database structure which is somewhat similar to this: How to hash and salt passwords When you have a user register on your service, that user expects of you to keep their password safe. Whilst it is generally bad practice to use the same password for multiple services there are many users that still do so. Because of this it's crucial that you save the user's passwords in a way that an attacker will be unable to find out the original password the user typed. This includes if they have full access to your database. In order to do this we do what is called "Password hashing" When a user registers, your server receives the user's intended username, (email) and password. Before you save that password to the database you have to hash and salt this, luckily MTA has a function that takes care of this. If you wish to know more about what exactly it does, there's more information at the end of this tutorial. In order to hash this password you use the passwordHash function. This function is relatively slow (by design), so it is highly recommended you pass a callback to this function, so your entire script doesn't wait for it to complete. https://wiki.multitheftauto.com/wiki/PasswordHash local mysqlHandle -- we're assuming this value is set somewhere else in code function register(username, email, password) local player = client passwordHash(password, "bcrypt", {}, function(hashedPassword) -- callback function for hashing the password local handle = dbQuery(function(handle) -- callback function for storing the user in the database if (handle) then triggerClientEvent(player, "registrationSuccess") -- inform the user that registration was successful else triggerClientEvent(player, "registrationFailed") end end,mysqlHandle, "INSERT INTO users (email, username, password) VALUES (?, ?, ?)", email, username, hashedPassword) end) end addEvent("passwordTutorial:register", true) addEventHandler("passwordTutorial:register", getRootElement(), register) How to validate a hashed password Once you've saved the hashed password to your database you need to do a little bit of additional work when authenticating the user. Luckily MTA offers a passwordVerify() function, which is the counterpart of the previously discussed passwordHash(). What this function does it basically hashes the password in the same way, resulting in the same output hash. https://wiki.multitheftauto.com/wiki/passwordVerify In order to get the account the user is trying to log in to you have to do a query for an account which has the user submitted username, and of which the password matches through passwordVerify. PasswordVerify is also a relatively slow function, thus you should use a callback. function login(username, password) local player = client dbQuery(function (handle) -- callback for the query selecting the user by username local results = dbPoll(handle, -1) if (#results == 0) then triggerClientEvent(player, "loginFailed") return end passwordVerify(password, results[1].password, {}, function(matches) -- callback function for the password verify if (matches) then -- Do anything you wish with the database result to log the player in with the rest of your scripts triggerClientEvent(player, "loginSuccess") else triggerClientEvent(player, "loginFailed") end end) end, mysqlHandle, "SELECT * FROM users WHERE username = ?", username) end addEvent("passwordTutorial:login", true) addEventHandler("passwordTutorial:login", getRootElement(), login) How to add "remember me" functionality When users on your server log in, they often do not want to have to enter their username and password every time they want to log in. In order to satisfy this need you can implement a "remember me" function. What I've seen happen in the past, is people would store the user's password (encrypted) on the client. This is NOT safe, and should never be done! In order to properly use remember me functionality what you would do is upon login in, generate a random string. The longer the better. This random string is what we call an access token. You would then allow the user to log in with such an access token, preferably only once generating a new access token each time one is used. To implement this you would generate that token every time the user logs in, whilst they have "remember me" enabled. You will have to save this token in your database alongside your user. For extra security you could also store the user's serial alongside the access token, you can then validate that the access token is being used from the same device. https://wiki.multitheftauto.com/wiki/Filepath function login(username, password) -- This code should be put in the callback to the dbQuery function, but to keep the example clean that's not shown here if (rememberMe) then local token = generateRandomToken() dbQuery(mysqlHandle, "INSERT INTO access_tokens (user_id, token) VALUES (?, ?)", results[1].id, token) triggerClientEvent(player, "loginSuccess", token) end end function rememberMeLogin(username, accessToken) -- this function handles a user's login attempt dbQuery(function(handle) local result = dbPoll(handle, -1) if (#result == 0) then triggerClientEvent(player, "loginFailed") else -- Do anything you wish with the database result to log the player in with the rest of your scripts triggerClientEvent(player, "loginSuccess") end end,mysqlHandle, "SELECT users.* FROM access_tokens JOIN users ON users.id = access_tokens.user_id WHERE users.username = ?", username) end addEvent("passwordTutorial:loginRememberMe", true) addEventHandler("passwordTutorial:loginRememberMe", getRootElement(), login) How to offer password recovery Offering password recovery requires a little bit more than just your MTA server. Generally password recovery is done with emails. So you would need access to an email server / service which you can use to send an email from an HTTP request. (Like you can do with fetchRemote()). When a user requests a password reset, have them enter the email you registered with. You then fetch a user from the database with this email address. You would then store a password recovery token for this user. This token, just like the remember me token, is a random string. Ideally, you would send the user a link with a password reset form that goes to a webpage where the user can reset their password. You could do this with an external service, like a webserver. Or you could use MTA's Resource web access for it, but if you do make sure you handle permissions properly for anything else that uses this. However another option would be to have the user copy paste the generated token from the email into you server's login window. Which of the two solutions you pick is up to you, my personal preference goes to the one with the link in the email. But in either case the server side logic is the same. When the user attempts to perform password recovery, verify that the token they give you belongs to a user, and then change the password to the newly requested password. Make sure you hash this password the same way you do in your login. function requestPasswordRecovery(email) dbQuery(function (handle)) local result = dbPoll(handle, -1) if (#result == 0) then triggerClientEvent(player, "passwordTutorial:passwordRecoveryRequestFailed") else local token = generateRandomToken() dbExec(mysqlHandle, "UPDATE user_data SET recovery_token = ?", token) -- mail the token to the user, mail implementation depends on the mail server/service you use triggerClientEvent(player, "passwordTutorial:passwordRecoveryRequestSuccess") end end, mysqlHandle, "SELECT * FROM users WHERE email = ?", email) end function recoverPassword(recoveryToken, password) dbQuery(function (handle) local result = dbPoll(handle, -1) if (#result == 0) then -- this is only valid if you have the user request password recovery from ingame triggerClientEvent(player, "passwordTutorial:passwordRecoveryFailed") else passwordHash(password, "bcrypt", {}, function(hashedPassword) -- callback function for hashing the password local handle = dbExec(function(handle) -- callback function for storing the new password in the database if (handle) then -- this is only valid if you have the user request password recovery from ingame triggerClientEvent(player, "passwordTutorial:passwordRecoverySuccess") -- inform the user that registration was successful else -- this is only valid if you have the user request password recovery from ingame triggerClientEvent(player, "passwordTutorial:passwordRecoveryFailed") end end,mysqlHandle, "UPDATE user_data SET password = ? WHERE recovery_token = ?", username, recoveryToken) end) end end, "SELECT * FROM users WHERE recovery_token = ?", recoveryToken) end Besides changing the password, it's important you also delete any access tokens that user might have if you're using remember me functionality. It is also good practice to make recovery tokens expiry after a certain amount of times, and not allow a recovery token to be created whilst one is already in progress. This prevents a user from sending a large number of emails from your service. How to migrate from an older hashing algorithm, to a newer one Maybe after reading this topic you realise that your password security is not what it should be. So you want to change your old password hashing / validation logic to the ones explained in this topic. And due to the nature that hashes can not be "unhashed", you can't simply migrate your passwords over. So in order to migrate the passwords what you have to do is when a user logs in, first validate their password with the old hashing algorithm. If this matches, then hash (and salt) it with your new hashing algorithm and save it in your database. Make sure to delete the old password otherwise your password security is not any better than before. Using a password policy Passwords policies are important to prevent your users from picking a password that is too easily cracked / brute forced. Many password policies come in the form of "Must have at least one capital letter, one digit and one number". But that discards that fact that the best way to make your password more difficult to crack, is making your password longer. So in the code snippet below is a function that measures the 'search space' of a password. The search space of a password is the amount of possible passwords there are with a certain combination of characters. In order to use this, you would have to set a minimum password search space when a user registers for an account. This minimum is up for you to set, but be reasonable, you shouldn't expect a user's password to be impossible to remember / create. I recommend playing with the function a bit to see what values you get out of it, and pick something you believe is sensible. function getPasswordSearchSpace(password) local lowerCase = password:find("%l") and 26 or 0 local upperCase = password:find("%u") and 26 or 0 local digits = password:find("%d") and 10 or 0 local symbols = password:find("%W") and 32 or 0 local length = password:len() return (lowerCase + upperCase + digits + symbols) ^ length end -- The below function calls are to indicate the difference in search space for a set of passwords print(getPasswordSearchSpace("a")) print(getPasswordSearchSpace("abc")) print(getPasswordSearchSpace("Abc")) print(getPasswordSearchSpace("Ab!")) print(getPasswordSearchSpace("Ab!0")) print(getPasswordSearchSpace("Mu#9A0h.")) print(getPasswordSearchSpace("This is a demonstration of how easy an incredibly strong password is to remember")) How to handle database leaks If you have reason to believe that your database has been leaked or otherwise compromised, it is important that your first course of action is removing any access tokens stored in your database. Once you have done that you have to inform your users. Whilst when properly hashed and salted it's extremely difficult / time consuming to find out a user's password it is still a possibility. So you should inform your users of the breach, tell them that their passwords were properly hashed, and they do not need to fear for their passwords immediately. However you should suggest to your users that they change their password either way, just in case. What even is hashing and salting? Hashing has been brought up several times in this tutorial, whilst you do not need to know what it is / does, you might be interested in knowing regardless. I won't be going too far in depth as I simply do not have the knowledge, but the basic idea of hashing is this: When you hash anything, you turn it into a string of characters (or other value) that has no relation to the original input, other than when you hash the original input again, it will always generate the same hash. For example, when you hash the string 'banana' using the sha512 hashing algorithm, it will always yield the output: "F8E3183D38E6C51889582CB260AB825252F395B4AC8FB0E6B13E9A71F7C10A80D5301E4A949F2783CB0C20205F1D850F87045F4420AD2271C8FD5F0CD8944BE3" Now hashing can not be reverted, you can not "unhash" a hash, so in order to verify someone's password you hash it again, and see if the two hashes are the exact same. Now this is great, passwords are safely stored. However there is still more to do, salting. Salting is adding some random data to your password prior to hashing it. This prevents when two users (on the same service, or on others) have the same password, that their hashes are also the same. Meaning if one password is compromised, the other password is not. It is important that a salt is random for every user in your application, not one salt for your entire application. Now you might think we didn't do any salting in the code / tutorial above. This is not true, we just didn't do it ourselves. MTA's passwordHash function actually hashes the passwords and salts it, this salt is then stored in the output hash it self, just before the actual password hash. In the case of bcrypt it actually stores a little bit more info in the resulting hash, but you need not worry about that.
    1 point
×
×
  • Create New...