SA-MP Forums Archive
[FilterScript] TAdmin - A MySQL administration system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FilterScript] TAdmin - A MySQL administration system (/showthread.php?tid=659739)



TAdmin - A MySQL administration system - M8 - 14.10.2018

TAdmin

A MySQL administration system because we don’t have enough of those!



This is my first ever release so go easy on me D: Hopefully the system is gonna be useful to some people because I spent a lot of time working on it and I’m super proud of the final product.

If you have suggestions, improvements, found bugs or just need some help, please make an issue, PM me on forum or post in the SA:MP forum topic.

The system current features: Requirements
Installation

1. Clone this repository locally and download the required plugins/includes.
2. Put the tadmin_tools.inc file in the pawno/include folder.
3. Open the pwn file and edit the following lines with your details:

pawn Code:
#define SYSTEMNAME “TAdmin” // Feel free to change it to “Admin System”, “Admin” etc etc.


#define ADMIN_MAX_LEVELS    4

#define COLOR_ADMINMSG           0xCC0000FF // Color used in the ‘Admin Message:’ messages.
#define ADMIN_LEVEL_1_COLOR   0xFF9900AA
#define ADMIN_LEVEL_2_COLOR   0x33AA33AA
#define ADMIN_LEVEL_3_COLOR   0x006699AA
#define ADMIN_LEVEL_4_COLOR   0xFF0000FF

#define ADMIN_LEVEL_1_NAME  “Trial Admin”
#define ADMIN_LEVEL_2_NAME  “Admin”
#define ADMIN_LEVEL_3_NAME  “Lead Admin”
#define ADMIN_LEVEL_4_NAME  “Management”

new bool:TAdmin_Debug = false;
new bool:SendQueryErrorsToAdmins = true;
new bool:AdminMapTeleport = true;
new bool:RCONFailedNotification = true;
new bool:UseDiscord = true;

/* TAdmin_Debug: Setting this to true will show debug messages in the server log, useful for debugging issues with TAdmin.
SendQueryErrorsToAdmins: Setting this to true will send Query errors to in-game admins. Query errors are always shown in the console regardless of this setting.
AdminMapTeleport: Setting this to true will allow admins to teleport by clicking on the map.
RCONFailedNotification: Setting this to true will send failed rcon login messages to all online admins. Failed login attempts are saved to Logs/FailedRCONLogins.txt regardless of this setting.
UseDiscord:  Setting this to true will enable all Discord related features. Discord settings can be found below. */


#define MAX_MUTE_TIME       120 // The max amount of time an admin can mute a player (in minutes)
#define MAX_JAIL_TIME       60 //The max amount of time an admin can jail a player (in minutes)

#define MYSQL_HOSTNAME      “localhost”
#define MYSQL_USERNAME      “root”
#define MYSQL_PASSWORD      “”
#define MYSQL_DATABASE      “main”

// – Discord Settings
#define ChannelAdminLogs “”
#define ChannelAdminChat “”
// Both AdminLogs and AdminChat require a Discord channel ID. Info here: [URL="http://toni.pw/l/discorddevmode"]http://toni.pw/l/discorddevmode[/URL]
4. Inside the Scriptfiles folder, create another folder titled Logs.

5. Open PHPMyAdmin localhost/phpmyadmin and create a new database corresponding to the value MYSQL_DATABASE in tadmin.pwn file.

6. Once you have created the database, import the main.sql file and you should have 4 tables titled accounts, adminlogs, reports and bans.

7. Finally, compile the filterscript, include it in server.cfg file filterscripts tadmin and run the server.

FAQ

Quote:
Q: How do I check if the player is an admin?

A: if(PlayerInfo[playerid][pAdmin] < 1) return 0; This is gonna check if the player's admin level is less than 1 and if it is, it returns 0, else it executes the command.

Quote:
Q: How do I add another admin level?

A: This is a bit more complicated so bear with me:

1. Firstly, increase the ADMIN_MAX_LEVELS value to whatever you want (I'll use 5 in this case).

2. Add the level's name and color:
#define ADMIN_LEVEL_5_COLOR 0xFF00FFFF` `#define ADMIN_LEVEL_5_NAME "Owner"

3. Edit GetAdminRank:
pawn Code:
GetAdminRank(playerid)
{
    new arank[64];
    switch(PlayerInfo[playerid][pAdmin])
    {
        case 5: arank = ADMIN_LEVEL_5_NAME;
        case 4: arank = ADMIN_LEVEL_4_NAME;
        case 3: arank = ADMIN_LEVEL_3_NAME;
        case 2: arank = ADMIN_LEVEL_2_NAME;
        case 1: arank = ADMIN_LEVEL_1_NAME;
        default: arank = "Unknown";
    }
    return arank;
}
4. Then, you can add the new admin level to /ahelp.
pawn Code:
SendClientMessage(playerid, ADMIN_LEVEL_5_COLOR, "Level 5 - {FFFFFF}Commands go here");
5. Finally, modify the /admins command so it can show level 5 admins as well:
pawn Code:
case 5: format(string, sizeof(string), "%s (%d) - Level %d (%s)", GetName(i), i, PlayerInfo[i][pAdmin], ADMIN_LEVEL_5_NAME);
Quote:

Q: I don’t care about the Discord stuff, can I remove them?

A: You can however you will have to spend some time removing them. I might release a seperate version without the Discord stuffs but for now, simply remove anything that says Discord.

Credits



Re: TAdmin - A MySQL administration system - ZigGamerx - 14.10.2018

well done. +REP


Re: TAdmin - A MySQL administration system - Mobtiesgangsa - 14.10.2018

excellent explanatory and detailing.Thank you for releasing such an unique source easy manageable


Re: TAdmin - A MySQL administration system - KinderClans - 14.10.2018

The script is good but needs a lot of tweaks.

You're using latest MySQL plugin but not foreach, the classic for(new i = 0; i < MAX_PLAYERS; i ++).

In the account check on OnPlayerConnect you don't need LIMIT 1.

pawn Code:
mysql_format(db, query, sizeof(query), "SELECT `pPass`, `pID` FROM `accounts` WHERE `pUsername` = '%e'", GetName(playerid));
Is enough.

Also why a loop to send a connect message? Just use SendClientMessageToAll! No need to loop everytime someone connects.

This:

pawn Code:
public OnPlayerConnect(playerid)
{
    new query[140], string[50];

    mysql_format(db, query, sizeof(query), "SELECT `pPass`, `pID` FROM `accounts` WHERE `pUsername` = '%e' LIMIT 0, 1", GetName(playerid));
    mysql_tquery(db, query, "CheckPlayer", "i", playerid);
   
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (!IsPlayerConnected(i)) continue;
        if (PlayerInfo[i][pAdmin] != 0) {
            format(string, sizeof(string), "* %s (%d) has connected. Country: %s", GetName(playerid), playerid, GetPlayerCountry(playerid));
        }
        else
        {
            format(string, sizeof(string), "* %s (%d) has connected.", GetName(playerid), playerid);
        }
        SendClientMessage(i, COLOR_GRAY, string);
    }
    if(TAdmin_Debug == true)
    {
        printf("[%s - Debug]: Player %s (%d) from %s, %s with IP %s connected. - OnPlayerConnect", SYSTEMNAME, GetName(playerid), playerid, GetPlayerCity(playerid), GetPlayerCountry(playerid), returnIP(playerid));
    }
    ResetPlayerVariables(playerid);
    TogglePlayerClock(playerid, 1);
    return 1;
}
Can be reduced to:

pawn Code:
public OnPlayerConnect(playerid)
{
    new query[140], string[100];

    mysql_format(db, query, sizeof(query), "SELECT `pPass`, `pID` FROM `accounts` WHERE `pUsername` = '%e'", GetName(playerid));
    mysql_tquery(db, query, "CheckPlayer", "i", playerid);
   
    format(string, sizeof(string), "* %s (%d) has connected. Country: %s", GetName(playerid), playerid, GetPlayerCountry(playerid));
    SendAdminMessage(COLOR_ADMINMSG, string);
   
    format(string, sizeof(string), "* %s (%d) has connected.", GetName(playerid), playerid);
    SendClientMessageToAll(COLOR_GRAY, string);
   
    if(TAdmin_Debug == true) printf("[%s - Debug]: Player %s (%d) from %s, %s with IP %s connected. - OnPlayerConnect", SYSTEMNAME, GetName(playerid), playerid, GetPlayerCity(playerid), GetPlayerCountry(playerid), returnIP(playerid));
   
    ResetPlayerVariables(playerid); TogglePlayerClock(playerid, 1);
    return 1;
}
For timers, use y_timers instead of default SetTimer.

/ahelp can be reduced up to 30% of lines too.

Also you're using Whirlpool without salting the passwords. Use SALT and SHA-256 to encrypt them. Better for you and better for the security of who'll use this system

Basically, this is a good system, but as said already, needs a lot of tweaks.

Good job tho.


Re: TAdmin - A MySQL administration system - M8 - 14.10.2018

Quote:
Originally Posted by KinderClans
View Post
You're using latest MySQL plugin but not foreach, the classic for(new i = 0; i < MAX_PLAYERS; i ++).
Originally, I wanted to use as little includes/plugins as possible so it's easier for anyone to just add it so I decided to go with classic loops and not foreach. But in the end, I still ended up with a lot of includes and plugins so I'll probably just add foreach in a future update. Same with y_timers.

Quote:
Originally Posted by KinderClans
View Post
mysql_format(db, query, sizeof(query), "SELECT `pPass`, `pID` FROM `accounts` WHERE `pUsername` = '%e'", GetName(playerid));
Thanks! Will fix this in a future update.

Quote:
Originally Posted by KinderClans
View Post
pawn Code:
format(string, sizeof(string), "* %s (%d) has connected. Country: %s", GetName(playerid), playerid, GetPlayerCountry(playerid));
    SendAdminMessage(COLOR_ADMINMSG, string);
   
    format(string, sizeof(string), "* %s (%d) has connected.", GetName(playerid), playerid);
    SendClientMessageToAll(COLOR_GRAY, string);
That would send 2 messages to admins, no? That's why it's looping through the players. To find which one is an admin and which one is not so it sends the correct message.

Also yeah, not really happy with the current /ahelp layout (Spent a long time deciding it) so I'll work on improving it.

Quote:
Originally Posted by KinderClans
View Post
Also you're using Whirlpool without salting the passwords. Use SALT and SHA-256 to encrypt them. Better for you and better for the security of who'll use this system
Will add that as well, didn't spend enough time on the login/reg system.

Thanks for the criticism!


Re: TAdmin - A MySQL administration system - M8 - 15.10.2018

1.0.1 - Small fixes
https://github.com/ToniTurnerr/TAdmi...ases/tag/1.0.1


Re: TAdmin - A MySQL administration system - Calisthenics - 15.10.2018

Any script that loads permissions or sensitive information needs to check against race condition. You do not want regular players to suddenly become administrators if the query takes long enough.

Quote:
Originally Posted by KinderClans
View Post
In the account check on OnPlayerConnect you don't need LIMIT 1.

pawn Code:
mysql_format(db, query, sizeof(query), "SELECT `pPass`, `pID` FROM `accounts` WHERE `pUsername` = '%e'", GetName(playerid));
Is enough.
His initial query would stop searching if one record is found, however now it will continue searching as it expects there might be multiple rows.

If you remove it, set `pUsername` as UNIQUE column (it now knows there are no duplicates and expects ONLY one row).


Re: TAdmin - A MySQL administration system - M8 - 18.10.2018

1.1 - Update
Admin jail will come in the next update

https://github.com/ToniTurnerr/TAdmin/releases/tag/1.1


Re: TAdmin - A MySQL administration system - SonnyGamer - 18.10.2018

Is this admin system bug free? Did you test all features or any server uses this system? If its bug free I might use it in my server.


Re: TAdmin - A MySQL administration system - solstice_ - 18.10.2018

Good job, I would like to see how the admin tool system looks, is it something similiar to mine?


Re: TAdmin - A MySQL administration system - M8 - 19.10.2018

Quote:
Originally Posted by SonnyGamer
View Post
Is this admin system bug free? Did you test all features or any server uses this system? If its bug free I might use it in my server.
It should be! I did test it pretty well while developing it but its possible a bug or two slipped. If you do end up finding bugs, report them to me and I'll fix them.

Quote:
Originally Posted by willbedie
View Post
Good job, I would like to see how the admin tool system looks, is it something similiar to mine?
I took a lot of inspiration from different admin systems I found, so it's possible!


Re: TAdmin - A MySQL administration system - Danielknow - 20.10.2018

look cool bro


Re: TAdmin - A MySQL administration system - M8 - 20.10.2018

1.1.1 - Updates
https://github.com/ToniTurnerr/TAdmi...ases/tag/1.1.1

Open to suggestions on what to add next. Reply here, PM me or submit an issue on github!


Re: TAdmin - A MySQL administration system - M8 - 22.10.2018

1.1.2 - Report System
https://github.com/ToniTurnerr/TAdmi...ases/tag/1.1.2

This is probably the last update for sometime as I think the system is pretty much completed. Suggestions, bugs and improvements are always appreciated.


Re: TAdmin - A MySQL administration system - solstice_ - 22.10.2018

Why are you just copy-pasting every system of mine lmfao, you'll have to ask for permission to do that. I released it so people can use on their servers, not to re-release it with a little change of code here and there. Shame.


Re: TAdmin - A MySQL administration system - M8 - 22.10.2018

Quote:
Originally Posted by willbedie
View Post
Why are you just copy-pasting every system of mine lmfao, you'll have to ask for permission to do that. I released it so people can use on their servers, not to re-release it with a little change of code here and there. Shame.
Literally no idea what you're talking about lol. I just checked your system and sure it has /dr and /ar (like pretty much all report systems) but the code is not even the same? If I did use your report system, I would have given you credit for it (just like I did with the ban system and the login/reg).


Re: TAdmin - A MySQL administration system - solstice_ - 22.10.2018

Quote:
Originally Posted by M8
View Post
Literally no idea what you're talking about lol. I just checked your system and sure it has /dr and /ar (like pretty much all report systems) but the code is not even the same? If I did use your report system, I would have given you credit for it (just like I did with the ban system and the login/reg).
Yeah not talking about ban / register system, but the report code is very similiar to mine


Re: TAdmin - A MySQL administration system - feheristi97 - 19.12.2018

plugins streamer sscanf mysql discord-connector Whirlpool

did I forget any plugins to include because I doesnt wanna start up.


Re: TAdmin - A MySQL administration system - Gabi3 - 31.01.2019

When I go in game and type any commands from this filterscript it says that the cmd is unknown. What could be the problem?