· 6 years ago · Aug 10, 2019, 08:00 AM
1function PlayerCanJoin( player )
2{
3 local result = true;
4
5 if ( player.Name.tolower() == ServerBot.tolower() )
6 {
7 KickPlayer( player, "Nickname invalido", "BOT", ServerBot, "true" );
8
9 result = false;
10 }
11 else if ( QuerySQL( bans, "SELECT * FROM bans WHERE playerName = '" + player.Name + "'" ) )
12 {
13 if ( time() > GetSQLColumnData( QuerySQL( bans, "SELECT * FROM bans WHERE playerName = '" + player.Name + "'" ), 2 ).tointeger() )
14 {
15 QuerySQL( bans, "DELETE FROM bans WHERE playerName = '" + player.Name + "'" );
16
17 PrivMessage( "YOUR BAN HAS BEEN DELETED.", player, "orange" );
18
19 result = true;
20 }
21 else
22 {
23 Message( format( "Enforcing prior ban on:[ %s ] Reason[ yes ] Time left:[ %d ]", player.Name, GetSQLColumnData( QuerySQL( bans, "SELECT * FROM bans WHERE playerName = '" + player.Name + "'" ), 2 ) ), "blue" );
24
25 result = false;
26 }
27 }
28
29 return result;
30}
31
32function onServerStart()
33{
34 try
35 {
36 QuerySQL( db, "CREATE TABLE IF NOT EXISTS Account ( LowerName VARCHAR(32), Name VARCHAR(32), Password VARCHAR(255), UID VARCHAR(255), UID2 VARCHAR(255), IP VARCHAR(32), DateRegistered TEXT, LastSeen TEXT, Cash INTEGER, Joins INTEGER, Level INTEGER, Kills INTEGER, Deaths INTEGER, Headshots INTEGER )" );
37 QuerySQL( bans, "CREATE TABLE IF NOT EXISTS bans ( playerName VARCHAR( 32 ), timeBannedAt INTEGER, expiresAt INTEGER )" );
38 QuerySQL( gtl, "CREATE TABLE IF NOT EXISTS Location ( LocName VARCHAR(255), Pos TEXT, Date TEXT, LowerCreator VARCHAR(32), Creator VARCHAR(32) )" );
39 }
40 catch( error )
41 {
42 SetServerPassword( psswd );
43
44 print( format( "[FATAL ERROR] ERROR WHEN TRYING TO LOAD DATABASES, (ONSERVERSTART EVENT); ERROR: %s", error ) );
45 }
46}
47
48function onScriptLoad()
49{
50 try
51 {
52 db <- ConnectSQL( "data~base.db" );
53 bans <- ConnectSQL( "bans.db" );
54 gtl <- ConnectSQL( "gotoloc.db" );
55 }
56 catch( error )
57 {
58 SetServerPassword( psswd );
59
60 print( format( "[FATAL ERROR] ERROR WHEN TRYING TO LOAD DATABASES, (ONSCRIPTLOAD EVENT); ERROR: %s", error ) );
61 }
62}
63
64function onPlayerJoin( player )
65{
66 if ( PlayerCanJoin( player ) )
67 {
68 // stuff
69 }
70}
71
72function onPlayerCommand( player, cmd, text )
73{
74 cmd = cmd.tolower();
75
76 if ( cmd == "ban" )
77 {
78 if ( text )
79 {
80 local plr = GetPlayer( GetTok( text, " ", 1 ) ), spl = split( text, " " );
81 if ( ( plr ) && ( spl.len() == 3 ) )
82 {
83 local xd = split( spl[ 1 ], ":" ), reason = spl[ 2 ];
84 if ( ( xd.len() == 4 ) && ( xd[ 1 ].tointeger() <= 23 ) && ( xd[ 2 ].tointeger() <= 59 ) && ( xd[ 3 ].tointeger() <= 59 ) )
85 {
86 local expires = time() + ( xd[ 0 ].tointeger() * 86400 ) + ( xd[ 1 ].tointeger() * 3600 ) + ( xd[ 2 ].tointeger() * 60 ) + xd[ 3 ].tointeger();
87 Message( "time(): " + time() + "\nexpires: " + expires + "", "blue" );
88
89 QuerySQL( bans, "INSERT INTO bans ( playerName, timeBannedAt, expiresAt ) VALUES ( '" + plr.Name + "', '" + time() + "', '" + expires.tointeger() + "' )" );
90
91 Message( format( ">> %s banned:[ %s ] Reason:[ %s ] Time left:[ %d ]", player.Name.tolower(), plr.Name, reason, expires.tointeger() ), "blue" );
92 }
93 }
94 }
95 }
96}