NanoBob

Members
  • Content Count

    26
  • Joined

  • Last visited

  • Days Won

    1

NanoBob last won the day on November 28 2018

NanoBob had the most liked content!

Community Reputation

19 Decent

About NanoBob

  • Rank
    Advanced Member

Details

  • Occupation
    SAES:RPG Development manager

Recent Profile Visitors

699 profile views
  1. NanoBob

    Slipe - C# for MTA

    The Slipe CLI tool has been updated today. New features include: A `slipe build` command to produce a deployment ready resource, including a `-luac` option to automatically compile the lua files using the MTA compiler. Self updating functionality, no longer will you need to manually update the CLI or core after this update. Exporting and import of modules. Your project can exist of seperate smaller modules, which can be exported and shared with others in the Slipe community. For more information on the CLI visit the documentation on mta-slipe.com
  2. NanoBob

    Slipe - C# for MTA

    I believe what you're referring to are CLEO mods, whilst CLEO does use the .cs file extension it's not C#, so no that wouldn't work.
  3. NanoBob

    Slipe - C# for MTA

    We haven't necesarily done benchmark tests, however inspecting the generated Lua code and the OO library used it's not much different than a "regular" Lua OOP library would be. Regarding the data types which do not have an exact conversion, that's exactly why we've created our wrappers around MTA classes. This means that in end user's (or end programmer / scripter) code you will not need to directly use Lua data types returned by MTA functions. But for the purpose of tables these are turned approached as arrays or dictionaries depending on their usage. EDIT: As a reply to your edit: no, but C# > Typescript IMO Our current MTA project actually consists of several parts of which all but the actual MTA part was written in C#, so this was a perfect way to use the same language on all ends.
  4. NanoBob

    Slipe - C# for MTA

    Slipe is an open source framework that enables anyone to write scripts for MTA:San Andreas in C# instead of Lua, wrapping all MTA elements and classes and including some .NET Core namespaces. It is based on CSharp.lua by Yang Huan. Slipe features: Object oriented wrappers for all MTA elements Async/await functionality for functions with callbacks C# style Http requests, sockets and XML methods. Use Visual Studio and its Intellisense Type safety You can find more information about the project on https://mta-slipe.com. Our Discord Our Github The project is still in Alpha, and since it is open source anyone is welcome to contribute
  5. NanoBob

    How Can I connect IPB in-game?

    Without code there really isn't much we can do to help.
  6. After a worrying discussion on Discord last night regarding password storage and remember me functionality I've decided to write a tutorial on how it should be done. This guide assumes you are not using MTA's built in account system, but a custom one. 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. 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 = dbExec(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 pasword 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() dbExec(function() triggerClientEvent(player, "loginSuccess", token) end,mysqlHandle, "INSERT INTO access_tokens (user_id, token) VALUES (?, ?)", results[1].id, 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 prgoress. 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 recomend 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 possibilty. 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 stirng '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.
  7. NanoBob

    MTA MYSQL PROBLEM

    Is your database actually mySQL or SQLLite? Because you state mysql both in your code and topic title, but your dbConnect call is for a SQLLite database.
  8. NanoBob

    Help with setPedAnimation

    Indeed
  9. NanoBob

    Create my own LUA compiler

    Just to inform you, if you're planning on created a lua compiler to use with MTA, that will not work.
  10. NanoBob

    Help with setPedAnimation

    In the original GTA:SA files there was code and animations for sex, these were disabled in the release of the game, but still remained in the game. Now the issue is that people found out about that (and made the "hot coffee" mod, which reenabled them. In response to that in an updated version of GTA:SA Rockstar Games had removed the animations alltogether. This means that people with later versions of GTA:SA will be unable to see the animations, whilst people with the original version will be able to see them.
  11. NanoBob

    MySQL Help

    That is exactly what you ahve to do. The results are returned in an array like table. Every entry in that table is one row from your database. Every row in that table is also a table, of which the keys are the string names of the columns in your database table. if(accData[i].username) then outputChatBox(accData[i].username,source,255,0,0, true) -- used to check results end
  12. NanoBob

    Bansync : Synchronise bans with other servers

    If the server is set up to follow your server's bans for that ban type as well, then yes. Adding a ban like that would most likely look something like this: Then in the server settings for the other server your server would need to be enabled like this: So with the config above if I ban someone from SAES:RPG, and your server has "abusive behaviour" bans from SAES:RPG enabled, then the player will also e unable to join your server (given you have implemented the code snippet which can be found on the developers page, on the management dashboard, whilst logged in with your server account. The reason SAES:RPG is there is because I am actually the lead developer of SAES:RPG. I hope that in the coming weeks many other servers will join the platform, so we can keep our servers clear of any nasty people.
  13. We all know that cheaters and hackers are not people you want on your server, or on any server for that matter. In order to prevent these people who get banned on one server for cheating, hacking (or just being a dickhead) from joining another server and doing the exact same, ruining the game for other players I have developed Bansync. Bansync is a way for a server owner to both contribute, and profit from a ban database, somewhat similar to how VAC works. Where getting banned from one server would mean you get banned from others as well. Anyone can sign up to join bansync as a server, and contribute to the database. And as a server owner you will be able to specify per server what types of bans you want to enforce on your server. ( See screenshot in spoiler below) Besides just being a ban database, it's also a platform for people to appeal their bans which were handed out using bansync. When an appeal is accepted the ban is automatically lifted and the player will be able to play on any servers enforcing bansync. Bansync runs as a website at https://bans.nanobob.net/ , once you sign up for a server account you will have information on how to implement bansync available on your admin dashboard. I welcome any questions, and encourage you to browse the website, it contains a more detailed and in depth explanation of the project. I would also like to ask for anyone who is interested and owns a server, or plays on a server which you think should be hacker free, to implement this, or ask the developers to implement bansync. This way we can make the MTA community just a bit nicer for everyone. Screenshots:
  14. NanoBob

    HELP! Database ( ID System )

    A better idea would be to use an autoincrement column in your database. So your code won't need to asign the IDs. But since you also have a username, which is unique per playerm why not use that as primary key?