Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include a_samp
- #include a_mysql
- #include zcmd
- #define red 0xFF0000AA
- #define COLOR_Silver 0xCACACAAA
- //==================================News======================================//
- new banned[MAX_PLAYERS],
- whatunbanip[32],
- whatbanip[32],
- mysql;
- //====================================Forwards================================//
- forward BanCheck(playerid);
- forward BanIPCheck(playerid);
- forward kickplayer(playerid);
- forward Unban(playerid);
- forward Unbanip(playerid);
- forward Banip(playerid);
- forward Baninfo(playerid);
- //============================================================================//
- public OnFilterScriptInit()
- {
- mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
- mysql = mysql_connect("MYSQL_HOST", "MYSQL_USER", "MYSQL_DATABASE", "MYSQL_PASSWORD");
- if(mysql_errno(mysql) != 0)
- {
- print("Could not connect to database!");
- }
- else
- {
- print("Successfully connected on DB ");
- }
- return 1;
- }
- public OnFilterScriptExit() {
- mysql_close();
- }
- public OnPlayerConnect(playerid) {
- banned[playerid] = 0;
- new name1[35];
- GetPlayerName(playerid,name1,sizeof(name1));
- new Query[250];
- mysql_format(mysql, Query, sizeof(Query),"SELECT `banned`, `ip`, `date`, `time`, `bannedby`, `banned`, `reason` FROM `banneds` WHERE `name` = '%e' LIMIT 1", name1);
- mysql_tquery(mysql, Query, "BanCheck", "i", playerid);
- return 1;
- }
- CMD:ban(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- new strdate[128],strtime[128], tmp[256], tmp2[256], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index);
- if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: /ban [playerid] [reason]");
- if(!strlen(tmp2)) return SendClientMessage(playerid, red, "ERROR: You must give a reason");
- new player1, playername[MAX_PLAYER_NAME], ip[128], adminname[MAX_PLAYER_NAME], string[128];
- player1 = strval(tmp);
- if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID && player1 != playerid && !IsPlayerAdmin(player1)) {
- GetPlayerName(player1, playername, sizeof(playername)); GetPlayerName(playerid, adminname, sizeof(adminname)); GetPlayerIp(playerid,ip,sizeof(ip));
- new year,month,day,hour,minuite,second; getdate(year, month, day); gettime(hour,minuite,second);
- format(string,sizeof(string),"|- %s has been banned by Administrator %s [Reason: %s] [Date: %d/%d/%d] [Time: %d:%d] -|",playername,adminname,params[2],day,month,year,hour,minuite);
- SendClientMessageToAll(COLOR_Silver,string);
- print(string);
- format(strdate, sizeof(strdate), "%d-%d-%d ",year,month,day);
- format(strtime,sizeof(strtime),"%d:%d:%d",hour,minuite,second);
- new Query[250];
- format(Query, sizeof(Query), "UPDATE `banneds` SET `ip` = '%s', `date` = '%s', `time` = '%s', `bannedby` = '%s', `banned` = '%d', `reason` = '%s' WHERE `name` = '%s'", ip,strdate,strtime,adminname,1,params[2],playername);
- mysql_tquery(mysql, Query, "", "");
- format(Query, sizeof(Query),"INSERT INTO `bannedips`(`ip`) VALUES ('%s')",ip);
- mysql_tquery(mysql, Query, "", "");
- return SetTimerEx("kickplayer", 500, false, "i", playerid);
- } else return SendClientMessage(playerid, red, "Player is not connected or is yourself or is the highest level admin");
- } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
- }
- CMD:unban(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /unban [playername]");
- new Query[250];
- format(Query, sizeof(Query), "SELECT * FROM banneds WHERE `name` = '%s'", params);
- mysql_tquery(mysql, Query, "Unban", "i", playerid);
- } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
- return 1;
- }
- CMD:unbanip(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /unbanip [ip]");
- new size; size = strval(params);
- if(size > 15 && size < 30) {
- new Query[250];
- format(Query, sizeof(Query), "SELECT * FROM bannedips WHERE `ip` = '%s'", params);
- strins(whatunbanip, params, 0);
- mysql_tquery(mysql, Query, "Unbanip", "i", playerid);
- } else return SendClientMessage(playerid,red,"ERROR: IP is too short OR is too long");
- } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
- return 1;
- }
- CMD:banip(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /banip [ip]");
- new Query[250];
- format(Query, sizeof(Query), "SELECT * FROM bannedips WHERE `ip` = '%s'", params);
- mysql_tquery(mysql, Query, "Banip", "i", playerid);
- strins(whatbanip, params, 0);
- } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
- return 1;
- }
- public Banip(playerid) {
- new rows, fields,string[128],Query[250];
- cache_get_data(rows, fields, mysql);
- if(rows)
- {
- whatbanip = "";
- return SendClientMessage(playerid,red,"ERROR: That ip already banned");
- }
- if(!rows)
- {
- format(Query, sizeof(Query),"INSERT INTO `bannedips`(`ip`) VALUES ('%s')",whatbanip);
- mysql_tquery(mysql, Query, "", "");
- format(string,sizeof(string),"[IP]: %s has been successfully banned",whatbanip);
- SendClientMessage(playerid,0x00FFFFAA,string);
- whatbanip = "";
- }
- return 1;
- }
- CMD:baninfo(playerid,params[]) {
- if(IsPlayerAdmin(playerid)) {
- if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /baninfo [playername]");
- new Query[250];
- format(Query, sizeof(Query), "SELECT * FROM banneds WHERE `name` = '%s'", params);
- mysql_tquery(mysql, Query, "Baninfo", "i", playerid);
- } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
- return 1;
- }
- //================================Publics=====================================//
- public BanCheck(playerid) {
- new rows, fields,ibanned[10],ifbanned;
- cache_get_data(rows, fields, mysql);
- if(rows)
- {
- cache_get_field_content(0, "banned", ibanned, mysql, 10);
- ifbanned = strval(ibanned);
- if(ifbanned == 1) {
- new save[4][80],name1[MAX_PLAYER_NAME+1]; GetPlayerName(playerid,name1,sizeof(name1));
- cache_get_field_content(0, "date", save[0], mysql, 80);
- cache_get_field_content(0, "time", save[1], mysql, 80);
- cache_get_field_content(0, "bannedby", save[2], mysql, 80);
- cache_get_field_content(0, "reason", save[3], mysql, 80);
- new str[350],content[128]; format(content,sizeof content,"%s %s",save[0],save[1]);
- format(str, sizeof(str),"{C0C0C0}Your Account's currently Banned.\n\n{00FFFF}In-Game Name: {33FF33}%s\n{00FFFF}Administrator: {33FF33}%s\n{00FFFF}Date: {33FF33}%s\n{00FFFF}Reason: {33FF33}%s\n{C0C0C0}* if you think that you're banned wrongfully,\nfeel free to make unban appeal on our forum: forum",name1,save[2],content,save[3]);
- ShowPlayerDialog(playerid, 801, DIALOG_STYLE_MSGBOX, "{FF0000}You Are Banned!", str, "Close","");
- SetTimerEx("kickplayer", 500, false, "i", playerid);
- }
- }
- if(!rows)
- {
- new Query[250],ip1[32]; GetPlayerIp(playerid,ip1,sizeof(ip1));
- format(Query, sizeof(Query), "SELECT * FROM `bannedips` WHERE `ip` = '%s'", ip1);
- mysql_tquery(mysql, Query, "BanIPCheck", "i", playerid);
- }
- return 1;
- }
- public BanIPCheck(playerid) {
- new rows, fields,string[128];
- cache_get_data(rows, fields, mysql);
- if(rows)
- {
- new name1[MAX_PLAYER_NAME]; GetPlayerName(playerid,name1,sizeof(name1));
- format(string,sizeof(string),"%s has been Auto Kicked | Reason: Banned IP |",name1);
- SendClientMessageToAll(COLOR_Silver,string);
- SetTimerEx("kickplayer", 500, false, "i", playerid);
- }
- if(!rows)
- {
- new Query[250],datum[50],hour1,minute1,second1,year1,month1,day1,tijd[50],ip1[32];
- new name1[MAX_PLAYER_NAME]; GetPlayerName(playerid,name1,sizeof(name1));
- getdate(year1, month1, day1); gettime(hour1,minute1,second1); GetPlayerIp(playerid,ip1,sizeof(ip1));
- format(datum, sizeof(datum), "%d-%d-%d", year1, month1, day1); format(tijd, sizeof(tijd), "%d:%d:%d", hour1, minute1, second1);
- new none[15]; none = "None";
- format(Query, sizeof(Query),"INSERT INTO `banneds` (name,ip,date,time,bannedby,banned,reason) VALUES ('%s','%s','%s','%s','%s','%s','%s')",name1,ip1,datum,tijd,none,none,none);
- mysql_tquery(mysql, Query, "", "");
- }
- }
- public Unban(playerid) {
- new rows, fields,string[128];
- cache_get_data(rows, fields, mysql);
- if(rows)
- {
- new Query[250],saving0[10],saving1[32],saving2[32],unban;
- cache_get_field_content(0, "name", saving2, mysql, 32);
- cache_get_field_content(0, "banned", saving0, mysql, 10);
- cache_get_field_content(0, "ip", saving1, mysql, 32);
- unban = strval(saving0);
- if(unban == 1) {
- new none[10]; none = "0";
- format(Query, sizeof(Query),"UPDATE `banneds` SET `banned` = 0,`bannedby` = %s,`reason` = %s WHERE `name` = '%s'",none,none,saving2);
- mysql_tquery(mysql, Query, "", "");
- format(Query, 100, "DELETE FROM `bannedips` WHERE `ip` = '%s'", saving1);
- mysql_tquery(mysql, Query, "", "");
- format(string,sizeof(string),"%s successfully has been unbanned",saving2);
- SendClientMessage(playerid,0x00FFFFAA,string);
- } else return SendClientMessage(playerid,red,"ERROR: This Player is not banned");
- } else return SendClientMessage(playerid,red,"ERROR: Player Name Not Exist on Database");
- return 1;
- }
- public Unbanip(playerid) {
- new rows, fields,string[128];
- cache_get_data(rows, fields, mysql);
- if(rows)
- {
- new Query[250];
- format(Query, 100, "DELETE FROM `bannedips` WHERE `ip` = '%s'", whatunbanip);
- mysql_tquery(mysql, Query, "", "");
- format(string,sizeof(string),"[IP]: %s has been successfully unbanned", whatunbanip);
- SendClientMessage(playerid,0x00FFFFAA,string);
- whatunbanip = "";
- } else return SendClientMessage(playerid,red,"ERROR: IP Not Exist on banned ips Database"); whatunbanip = "";
- return 1;
- }
- public Baninfo(playerid) {
- new rows, fields;
- cache_get_data(rows, fields, mysql);
- if(rows)
- {
- new save[5][50],save5[128],banned1,str[350],str2[80],datetime[50];
- cache_get_field_content(0, "banned", save[0], mysql, 10);
- banned1 = strval(save[0]);
- if(banned1 == 1) {
- cache_get_field_content(0, "date", save[1], mysql, 50);
- cache_get_field_content(0, "time", save[2], mysql, 50);
- cache_get_field_content(0, "bannedby", save[3], mysql, 50);
- cache_get_field_content(0, "name", save[4], mysql, 50);
- cache_get_field_content(0, "reason", save5, mysql, 128);
- format(str2,sizeof(str2),"%s Ban Information",save[4]);
- format(datetime,sizeof(datetime),"%s %s",save[1],save[2]);
- format(str, sizeof(str),"{00FFFF}Player Name: {33FF33}%s\n\n{00FFFF}Banned By: {33FF33}%s\n\n{00FFFF}Date: {33FF33}%s\n\n{00FFFF}Reason: {33FF33}%s",save[4],save[3],datetime,save5);
- ShowPlayerDialog(playerid, 801, DIALOG_STYLE_MSGBOX, str2, str, "Close","");
- } else return SendClientMessage(playerid,red,"ERROR: This player is not banned");
- } else return SendClientMessage(playerid,red,"ERROR: Player Name not Exist on database");
- return 1;
- }
- public kickplayer(playerid) {
- return Kick(playerid);
- }
- //==================================a fuction=================================//
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- //============================================================================//
Advertisement
Add Comment
Please, Sign In to add comment