| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- #include <YSI_Coding\y_hooks>
- forward OnPlayerPassedBanCheck(playerid);
- Ban_CheckUser(playerid)
- {
- inline OnPlayerBanLoad()
- {
- if(cache_num_rows())
- {
- new expired;
- new banName[MAX_PLAYER_NAME];
- cache_get_value_name_int(0, "expired", expired);
- cache_get_value_name(0, "name", banName);
- if(expired <= 0)
- {
- Ban_RemoveUser(INVALID_PLAYER_ID, banName);
- CallRemoteFunction("OnPlayerPassedBanCheck", "i", playerid);
- }
- else
- {
- new banIP[MAX_PLAYER_IP];
- new banAdmin[MAX_PLAYER_NAME];
- new banReason[MAX_BAN_REASON];
- new banDate[40];
- new unbanDate[40];
- cache_get_value_name(0, "ip", banIP);
- cache_get_value_name(0, "admin", banAdmin);
- cache_get_value_name(0, "reason", banReason);
- cache_get_value_name(0, "date_ban", banDate);
- cache_get_value_name(0, "date_unban", unbanDate);
- SendClientMessage(playerid, 0xff6666ff, "You're banned from this server.");
- va_SendClientMessage(playerid, 0xff6666ff, "Name: %s, Banned by: %s, Reason: %s", banName, banAdmin, banReason);
- va_SendClientMessage(playerid, 0xff6666ff, "Ban Date: %s, Unban Date: %s", banDate, unbanDate);
- Kick(playerid);
- }
- }
- else CallRemoteFunction("OnPlayerPassedBanCheck", "i", playerid);
- }
- MySQL_TQueryInline(MySQL_GetHandle(), using inline OnPlayerBanLoad, "SELECT *, DATE_FORMAT(ban_date, '%%%%d %%%%M %%%%Y at %%%%r') AS date_ban, DATE_FORMAT(unban_date, '%%%%d %%%%M %%%%Y at %%%%r') AS date_unban, TIMESTAMPDIFF(SECOND, CURRENT_TIMESTAMP(), unban_date) AS expired FROM bans WHERE name = '%e' OR ip = '%e' LIMIT 1", Account_GetName(playerid), Account_GetIP(playerid));
- }
- Ban_AddUser(byid, bannedid, const reason[], intervalType, banDuration)
- {
- new interval[6];
- switch(intervalType)
- {
- case 0: StrCpy(interval, "DAY", sizeof(interval));
- case 1: StrCpy(interval, "MONTH", sizeof(interval));
- case 2: StrCpy(interval, "YEAR", sizeof(interval));
- }
- new adminName[MAX_PLAYER_NAME];
- if(byid == INVALID_PLAYER_ID)
- {
- StrCpy(adminName, "System", sizeof(adminName));
- }
- else StrCpy(adminName, Account_GetName(byid), sizeof(adminName));
- new query[512];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "INSERT INTO bans (name, ip, gpci, admin, reason, ban_date, unban_date) VALUES ('%e', '%e', '%e', '%e', '%e', CURRENT_TIMESTAMP(), DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL %i %s))", Account_GetName(bannedid), Account_GetIP(bannedid), Account_GetGPCI(bannedid), adminName, reason, banDuration, interval);
- mysql_tquery(MySQL_GetHandle(), query);
- Kick(bannedid);
- }
- Ban_AddOfflineUser(byid, const banned[], const reason[], intervalType, banDuration)
- {
- new bannedName[MAX_PLAYER_NAME];
- new banReason[MAX_BAN_REASON];
- new bannerName[MAX_PLAYER_NAME];
- StrCpy(bannedName, banned, sizeof(bannedName));
- StrCpy(banReason, reason, sizeof(banReason));
- StrCpy(bannerName, Account_GetName(byid), sizeof(bannerName));
- inline OnPlayerOffBan()
- {
- if(cache_num_rows())
- {
- new adminLevel;
- new playerIP[MAX_PLAYER_IP];
- new playerGPCI[MAX_PLAYER_GPCI];
- cache_get_value_name_int(0, "admin", adminLevel);
- cache_get_value_name(0, "ip", playerIP);
- cache_get_value_name(0, "gpci", playerGPCI);
- if(adminLevel >= Admin_GetLevel(byid))
- {
- return SendErrorMessageF(byid, "You can't use this command on %s.", bannedName);
- }
- new interval[6];
- new durationStr[8];
- switch(intervalType)
- {
- case 0: StrCpy(interval, "DAY", sizeof(interval)), durationStr = "days";
- case 1: StrCpy(interval, "MONTH", sizeof(interval)), durationStr = "months";
- case 2: StrCpy(interval, "YEAR", sizeof(interval)), durationStr = "years";
- }
- new query[512];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "INSERT INTO bans (name, ip, gpci, reason, admin, ban_date, unban_date) VALUES ('%e', '%e', '%e', '%e', '%e', CURRENT_TIMESTAMP(), DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL %i %s))", bannedName, playerIP, playerGPCI, banReason, bannerName, banDuration, interval);
- mysql_tquery(MySQL_GetHandle(), query);
- if(strlen(banReason) > 20)
- {
- SendAdmCmdF("%s was banned (offline) by %s for %d %s, reason: %.20s ...", bannedName, bannerName, banDuration, durationStr, banReason);
- SendAdmCmdF("... %s", banReason[20]);
- }
- else SendAdmCmdF("%s was banned (offline) by %s for %d %s, reason: %s", bannedName, bannerName, banDuration, durationStr, banReason);
- }
- else SendErrorMessageF(byid, "%s could not be found in the database.", bannedName);
- }
- MySQL_TQueryInline(MySQL_GetHandle(), using inline OnPlayerOffBan, "SELECT * FROM accounts WHERE name = '%e'", bannedName);
- return 1;
- }
- Ban_RemoveUser(playerid, const banned[])
- {
- new bannedName[MAX_PLAYER_NAME];
- new unbannerName[MAX_PLAYER_NAME];
- StrCpy(bannedName, banned, sizeof(bannedName));
- StrCpy(unbannerName, Account_GetName(playerid), sizeof(unbannerName));
- inline OnPlayerRemoveBan()
- {
- if(cache_affected_rows())
- {
- if(playerid != INVALID_PLAYER_ID) SendAdmCmdF("%s unbanned %s.", unbannerName, bannedName);
- }
- else SendErrorMessageF(playerid, "%s could not be found in the database.", bannedName);
- }
- MySQL_TQueryInline(MySQL_GetHandle(), using inline OnPlayerRemoveBan, "DELETE FROM bans WHERE name = '%e'", bannedName);
- }
- CMD:ban(playerid, params[])
- {
- if(isnull(params)) return SendSyntaxMessage(playerid, "/ban (options: d(ay), m(onth), y(ear))");
- new targetid;
- new duration;
- new interval;
- new reason[MAX_BAN_REASON];
- if(!strcmp(params, "d", true, 1))
- {
- if(sscanf(params, "{s[2]}iuS(Unspecified)[128]", duration, targetid, reason)) return SendSyntaxMessage(playerid, "/ban d (duration) (playerid) (reason)");
- interval = 0;
- }
- else if(!strcmp(params, "m", true, 1))
- {
- if(sscanf(params, "{s[2]}iuS(Unspecified)[128]", duration, targetid, reason)) return SendSyntaxMessage(playerid, "/ban m (duration) (playerid) (reason)");
- interval = 1;
- }
- else if(!strcmp(params, "y", true, 1))
- {
- if(sscanf(params, "{s[2]}iuS(Unspecified)[128]", duration, targetid, reason)) return SendSyntaxMessage(playerid, "/ban y (duration) (playerid) (reason)");
- interval = 2;
- }
- else return SendSyntaxMessage(playerid, "/ban (options: d(ay), m(onth), y(ear))");
- if(targetid == playerid) return SendErrorMessage(playerid, "You can't ban yourself.");
- if(duration < 1 || duration > 1000) return SendErrorMessage(playerid, "Invalid duration, must be between 1 and 1000.");
- if(!IsPlayerConnected(targetid)) return SendErrorMessage(playerid, "You specified an invalid player.");
- if(Admin_GetLevel(targetid) >= Admin_GetLevel(playerid)) return SendErrorMessageF(playerid, "You can't use this command on %s.", Account_GetName(targetid));
- if(strlen(reason) > MAX_BAN_REASON - 1) return SendErrorMessageF(playerid, "Invalid reason length, maximum characters is %d.", MAX_BAN_REASON - 1);
- new durationStr[8];
- switch(interval)
- {
- case 0: durationStr = "days";
- case 1: durationStr = "months";
- case 2: durationStr = "years";
- }
- if(strlen(reason) > 20)
- {
- SendAdmCmdF("%s was banned by %s for %d %s, reason: %.20s ...", Account_GetName(targetid), Account_GetName(playerid), duration, durationStr, reason);
- SendAdmCmdF("... %s", reason[20]);
- }
- else SendAdmCmdF("%s was banned by %s for %d %s, reason: %s", Account_GetName(targetid), Account_GetName(playerid), duration, durationStr, reason);
- Ban_AddUser(playerid, targetid, reason, interval, duration);
- return 1;
- }
- CMD:offban(playerid, params[])
- {
- if(isnull(params) || IsNumeric(params)) return SendSyntaxMessage(playerid, "/offban (options: d(ay), m(onth), y(ear))");
- new duration;
- new interval;
- new targetName[MAX_PLAYER_NAME];
- new reason[MAX_BAN_REASON];
- if(!strcmp(params, "d", true, 1))
- {
- if(sscanf(params, "{s[2]}is[24]S(Unspecified)[128]", duration, targetName, reason)) return SendSyntaxMessage(playerid, "/offban d (days) (name) (reason)");
- interval = 0;
- }
- else if(!strcmp(params, "m", true, 1))
- {
- if(sscanf(params, "{s[2]}is[24]S(Unspecified)[128]", duration, targetName, reason)) return SendSyntaxMessage(playerid, "/offban m (months) (name) (reason)");
- interval = 1;
- }
- else if(!strcmp(params, "y", true, 1))
- {
- if(sscanf(params, "{s[2]}is[24]S(Unspecified)[128]", duration, targetName, reason)) return SendSyntaxMessage(playerid, "/offban y (years) (name) (reason)");
- interval = 2;
- }
- else return SendSyntaxMessage(playerid, "/offban (options: d(ay), m(onth), y(ear))");
- if(duration < 1 || duration > 1000) return SendErrorMessage(playerid, "Invalid duration, must be between 1 and 1000.");
- if(strlen(reason) > MAX_BAN_REASON - 1) return SendErrorMessageF(playerid, "Invalid reason length, maximum characters is %d.", MAX_BAN_REASON - 1);
- foreach(new i : Player) if(!strcmp(targetName, Account_GetName(i)))
- {
- return SendErrorMessage(playerid, "That player is connected, use /ban insetead.");
- }
- Ban_AddOfflineUser(playerid, targetName, reason, interval, duration);
- return 1;
- }
- CMD:unban(playerid, params[])
- {
- if(isnull(params) || strval(params)) return SendSyntaxMessage(playerid, "/unban (name)");
- if(strlen(params) > MAX_PLAYER_NAME) return SendErrorMessageF(playerid, "Invalid name length, maximum characters is %d.", MAX_PLAYER_NAME);
- Ban_RemoveUser(playerid, params);
- return 1;
- }
|