Jump to content

Base MySQL Gamemode [Login/Registration System]


Recommended Posts

Posted
13 hours ago, Zow said:

Do you plan to update another small feature? like spawn position, spawn after dead, admin level, camera view on login/register etc.

This resource is awesome anyway.

Spawn position as in? The database already saves the players last known position when they quit.

spawn position after death doesn’t need to be in the database

admin level is easy for anyone to add

camera view can again be easily edited

This resource is basically a template, it should have all the code necessary for you to see how it works and to easily add in things like an admin level yourself. I can’t overcomplicate this script by also giving players the option to change camera views etc. It’s just a MySQL template and that’s it. If you need help with these things the RageMP discord has plenty of people who can help

  • 3 months later...
Posted

Any idea to add "if statement" to check if the letters is not a-z or 0-9 then give them errors
I find some function to check it but I don't know how to use it
Sorry about this question I'm pretty new

        case 1: //Register State
        {
            if(username.length >= 3 && pass.length >= 5){
                gm.mysql.handle.query('SELECT * FROM `accounts` WHERE `username` = ?', [username], function(err, res){
                    if(res.length > 0){
                        player.call("loginHandler", ["takeninfo"]);
                    } else {
                        bcrypt.hash(pass, null, null, function(err, hash) {
                            if(!err){
                                gm.mysql.handle.query('INSERT INTO `accounts` SET username = ?, password = ?', [username, hash], function(err, res){
                                    if(!err){
                                        player.name = username;
                                        player.call("loginHandler", ["registered"]);
                                        gm.auth.registerAccount(player);
                                        console.log("\x1b[92m" + username + "\x1b[39m has just registered.");
                                    } else {
                                        console.log("\x1b[31m[ERROR] " + err)
                                    }
                                });
                            } else {
                                console.log("\x1b[31m[BCrypt]: " + err)
                            }
                        });
                    }
                });
            } else {
                player.call("loginHandler", ["tooshort"]);
            }            
            break;
        }

 

  • 10 months later...
  • 1 month later...
  • 5 months later...
Posted

I found a bug, reported it on github, problem is that when server is running for long enough (6/7 hours constantly) player can't login/register. I'm running Debian 10 (Buster) with mariadb and phpmyadmin. any ideas how to fix it?

Posted (edited)
8 hours ago, Self said:

I found a bug, reported it on github, problem is that when server is running for long enough (6/7 hours constantly) player can't login/register. I'm running Debian 10 (Buster) with mariadb and phpmyadmin. any ideas how to fix it?

Not entirely a bug, but it disconnects the connection if it's been unused for a while. There are solutions out there on Google on how to 'fix' this, one of the top results pointed me to this link: https://github.com/mysqljs/mysql/issues/431
 

I haven't tried this solution but you can give it a go. I don't want to fix this as I had rebuilt this using a pooling connections rather than having one connection like this current version and I don't find this current repo the most effective way to be using MySQL. Hopefully over the next week I can come back and update the repo though which should fix this issue.

EDIT: Any chance you could instead try this: https://github.com/RageMpOpenSource/RAGE-Accounts
 

I forgot I had this made which uses pooling, test it and see if you can still connect after a long time without any restarts.

Edited by MrPancakers
Posted
18 hours ago, MrPancakers said:

Not entirely a bug, but it disconnects the connection if it's been unused for a while. There are solutions out there on Google on how to 'fix' this, one of the top results pointed me to this link: https://github.com/mysqljs/mysql/issues/431
 

I haven't tried this solution but you can give it a go. I don't want to fix this as I had rebuilt this using a pooling connections rather than having one connection like this current version and I don't find this current repo the most effective way to be using MySQL. Hopefully over the next week I can come back and update the repo though which should fix this issue.

EDIT: Any chance you could instead try this: https://github.com/RageMpOpenSource/RAGE-Accounts
 

I forgot I had this made which uses pooling, test it and see if you can still connect after a long time without any restarts.

Alright I'll try to fix this issue, now I know where to look excatly, I am not thinking about installing new login system because I already changed a lot your code, I added admin system, ban system, player serial is saving to database etc, server is in development but the first thing to fix is your login script, thank you for advice I am going to try to fix it on my own, if I encounter any other issue i will write on this post. Thanks.

Posted (edited)

My really hardcode solution for this problem is that i set timeout for function that is sending query to database so that every hour one hardcoded query is send, I am going to see if that works, maybe someone will find this helpful. I will update post if it works.

 

EDIT: I meant Interval ( setInterval(); )

Edited by Self
mistake
Posted

I no longer recommend this resource and suggest using my new MySQL Accounts resource going forward. It fixes many issues and is also at least 3x faster at running queries

 

  • 3 years later...

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...