SA-MP Forums Archive
[Ajuda] /tempban - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] /tempban (/showthread.php?tid=304024)



[Ajuda] /tempban - IILeonII - 16.12.2011

Bom galera peguei um FS aqui no forum de temp ban e talz mas o chato e que toda vez que eu for banir tenho que entrar na Rcon meu server tem sistema de admin

Alguem poderia me ajudar a ajustar para os admins do meu servidor usar sem eu ter que passa a rcon pra todos administradores?

FS

HTML Code:
/*x---------------------------------Important-------------------------------------x*/
//**INCLUDES**//
#include <a_samp>
/*x---------------------------------Defining-------------------------------------x*/
//**COLORS*//
#define GREEN 			0x21DD00FF
#define RED 			0xE60000FF
#define ADMIN_RED 		0xFB0000FF
#define YELLOW 			0xFFFF00FF
#define ORANGE 			0xF97804FF
#define LIGHTRED 		0xFF8080FF
#define LIGHTBLUE 		0x00C2ECFF
#define PURPLE 			0xB360FDFF
#define PLAYER_COLOR 	0xFFFFFFFF
#define BLUE 			0x1229FAFF
#define LIGHTGREEN 		0x38FF06FF
#define DARKPINK 		0xE100E1FF
#define DARKGREEN 		0x008040FF
#define ANNOUNCEMENT 	0x6AF7E1FF
#define COLOR_SYSTEM 	0xEFEFF7AA
#define GREY 			0xCECECEFF
#define PINK 			0xD52DFFFF
#define DARKGREY    	0x626262FF
#define AQUAGREEN   	0x03D687FF
#define NICESKY 		0x99FFFFAA
#define WHITE 			0xFFFFFFFF
/*x---------------------------------CallBacks-------------------------------------x*/
stock IsNumeric(const num[])
{
	for (new i = 0, j = strlen(num); i < j; i++)
	if (num[i] > '9' || num[i] < '0')
    return 0;
	return 1;
}

ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
	new pos = 0;
	while (text[pos] < 0x21)
	{
		if (text[pos] == 0) return INVALID_PLAYER_ID;
		pos++;
	}
	new userid = INVALID_PLAYER_ID;
	if (IsNumeric(text[pos]))
	{
		userid = strval(text[pos]);
		if (userid >=0 && userid < MAX_PLAYERS)
		{
			if(!IsPlayerConnected(userid))
				userid = INVALID_PLAYER_ID;
			else return userid;
		}
	}
	new len = strlen(text[pos]);
	new count = 0;
	new pname[MAX_PLAYER_NAME];
	for (new i = 0; i < MAX_PLAYERS; i++)
	{
		if (IsPlayerConnected(i))
		{
			GetPlayerName(i, pname, sizeof (pname));
			if (strcmp(pname, text[pos], true, len) == 0)
			{
				if (len == strlen(pname)) return i;
				else
				{
					count++;
					userid = i;
				}
			}
		}
	}
	if (count != 1)
	{
		if (playerid != INVALID_PLAYER_ID)
		{
			if (count) SendClientMessage(playerid, COLOR_SYSTEM, "There are multiple users, enter full playername.");
			else SendClientMessage(playerid, COLOR_SYSTEM, "Playername not found.");
		}
		userid = INVALID_PLAYER_ID;
	}
	return userid;
}

stock strtok(const str[], &index,seperator=' ')
{
	new length = strlen(str);
	new offset = index;
	new result[128];
	while ((index < length) && (str[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = str[index];
		index++;
	}

	result[index - offset] = EOS;
	if ((index < length) && (str[index] == seperator))
	{
		index++;
	}
	return result;
}

stock SendClientMessageToAdmins(color, msg[])
{
	new string[128];
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i))
		{
			if (IsPlayerAdmin(i))
			{
				SendClientMessage(i, color, msg);
				printf("%s", string);
			}
		}
	}
	return 1;
}

stock bigstr(const string[], &idx)
{
    new length = strlen(string);
	while ((idx < length) && (string[idx] <= ' '))
	{
		idx++;
	}
	new offset = idx;
	new result[128];
	while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
	{
		result[idx - offset] = string[idx];
		idx++;
	}
	result[idx - offset] = EOS;
	return result;
}

public OnFilterScriptInit()
{
	print("<|-----------------------------------------|>");
	print(" |  .: [  - SeifAdmin Script by Seif -  ] :.  |");
	print("<|-----------------------------------------|>");
	if (!fexist("Bans.txt"))
	{
		new File:open = fopen("Bans.txt",io_write);
		if (open) fclose(open);
	}
	if (!fexist("TempBans.ban"))
	{
		new File:open = fopen("TempBans.ban",io_write);
		if (open) fclose(open);
	}
	return 1;
}

public OnPlayerConnect(playerid)
{
	BanCheck(playerid);
	TempBanCheck(playerid);
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	new tmp[128],idx;
	new cmd[128];
	new name[MAX_PLAYER_NAME];
	new giveplayer[MAX_PLAYER_NAME];
	new giveplayerid;
	cmd = strtok(cmdtext,idx);
	if (strcmp(cmd,"/ban", true) == 0)
	{
	    if (IsPlayerAdmin(playerid))
		{
			new reason[128],str[128],namez[24],name1[24];
	    	tmp = strtok(cmdtext,idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid,ORANGE,"USAGE: /ban [name/ip] [reason]");
				SendClientMessage(playerid,ORANGE,"FUNCTION: Will ban the player's name/IP following by a reason. !! DO NOT ENTER THE ID !!");
				SendClientMessage(playerid,ORANGE,"HELP: Please enter a name or IP. If you're trying to execute a range ban...");
				SendClientMessage(playerid,ORANGE,"HELP: ...then make sure you got a valid player IP( /ip ) and replace some characters by * (NOT ALL)");
				return 1;
			}
            new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			while ((idx < length) && ((idx - offset) < (sizeof(reason) - 1)))
			{
				reason[idx - offset] = cmdtext[idx];
				idx++;
			}
			reason[idx - offset] = EOS;
	    	if(!strlen(reason))
			{
				SendClientMessage(playerid,ORANGE,"USAGE: /ban [name/ip] [reason]");
				SendClientMessage(playerid,RED,"ERROR: You must enter a reason for the ban!");
				return 1;
			}
			new File:file = fopen("Bans.txt",io_append);
			if (file)
			{
			    format(str,128,"%s\r\n",tmp);
			    fwrite(file,str);
			    fclose(file);
			}
			new count = 0;
			new ip[15];
			for(new i=0;i<MAX_PLAYERS;i++)
			{
			    if (IsPlayerConnected(i))
	   			{
					GetPlayerName(i,namez,24);
					GetPlayerName(playerid,name1,24);
					GetPlayerIp(i,ip,sizeof(ip));
					if (strcmp(tmp, namez,true)==0)
					{
						format(str,128,"|- Administrator %s banned %s. [Reason: %s] -|",name1,namez,reason);
						SendClientMessageToAll(ADMIN_RED,str);
						Kick(i);
					}
					else if(strcmp(tmp,ip,true)==0)
					{
					    format(str,128,"|- Administrator %s banned %s. [Reason: %s] -|",name1,namez,reason);
						SendClientMessageToAll(ADMIN_RED,str);
						format(str,128,"|- Banned IP: [ %s ] -|",ip);
						SendClientMessageToAdmins(ADMIN_RED,str);
						Kick(i);
					}
				}
				else
				{
				    GetPlayerIp(i,ip,sizeof(ip));
					if (!IsPlayerConnected(i) && strfind(tmp,".",true) != -1 && count == 0)
					{
					    GetPlayerName(playerid,name1,24);
						format(str,128,"|- Banned IP: [ %s ] by %s. [Reason: %s] -|",tmp,name1,reason);
						SendClientMessageToAdmins(ADMIN_RED,str);
					}
					else if (!IsPlayerConnected(i) && count == 0)
					{
					    for(new index = 1; index <= 128; index++)
						if (tmp[index] != '.')
						{
					    	GetPlayerName(playerid,name1,24);
							format(str,128,"|- Banned Name: [ %s ] by %s. [Reason: %s] -|",tmp,name1,reason);
							SendClientMessageToAdmins(ADMIN_RED,str);
							break;
						}
					}
					count++;
				}
			}
		}
		return true;
	}
	if (strcmp(cmd,"/idban", true) == 0)
	{
	    if (IsPlayerAdmin(playerid))
		{
			new reason[128],targetid,target[MAX_PLAYER_NAME],str[128];
	    	tmp = strtok(cmdtext,idx);
	    	targetid = ReturnUser(tmp);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid,ORANGE,"USAGE: /idban [partofname/id] [reason]");
				SendClientMessage(playerid,ORANGE,"FUNCTION: Will ban the player's IP following by a reason. ID supported and name supported only");
				return 1;
			}
			if (!IsPlayerConnected(targetid) || targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid,RED,"ERROR: Invalid player or player not connected");
            new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			while ((idx < length) && ((idx - offset) < (sizeof(reason) - 1)))
			{
				reason[idx - offset] = cmdtext[idx];
				idx++;
			}
			reason[idx - offset] = EOS;
	    	if(!strlen(reason))
			{
				SendClientMessage(playerid,ORANGE,"USAGE: /idban [partofname/id] [reason]");
				SendClientMessage(playerid,RED,"ERROR: You must enter a reason for the ban!");
				return 1;
			}
			new ip[15];
			GetPlayerIp(targetid,ip,sizeof(ip));
			new File:file = fopen("Bans.txt",io_append);
			if (file)
			{
			    format(str,128,"%s\r\n",ip);
			    fwrite(file,str);
			    fclose(file);
			}
			GetPlayerName(playerid,name,24);
			GetPlayerName(targetid,target,24);
			format(str,128,"|- Administrator %s banned %s. [Reason: %s] -|",name,target,reason);
			SendClientMessageToAll(ADMIN_RED,str);
			Kick(targetid);
		}
		return true;
	}
	if(strcmp(cmd, "/ip", true) == 0)
	{
		if (IsPlayerAdmin(playerid))
		{
			tmp = strtok(cmdtext,idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, ORANGE, "USAGE: /ip [playerid]");
				SendClientMessage(playerid, ORANGE, "FUNCTION: Will view a player's IP.");
				return 1;
			}
			giveplayerid = ReturnUser(tmp);
			new string[128];
			if(IsPlayerConnected(giveplayerid))
			{
			    new ip[15];
				GetPlayerIp(giveplayerid,ip,15);
				GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
				format(string, sizeof(string), "-| %s's IP: %s |-", giveplayer,ip);
				SendClientMessage(playerid,LIGHTBLUE, string);
			}
			else
			{
				format(string, sizeof(string), "%d is not an active player.", giveplayerid);
				SendClientMessage(playerid, RED, string);
			}
		}
		else return SendClientMessage(playerid, RED, "You are not an admin.");
		return true;
	}
	if(strcmp(cmd, "/tempban", true) == 0)
	{
		if (IsPlayerAdmin(playerid))
		{
			tmp = strtok(cmdtext,idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, ORANGE, "USAGE: /tempban [playerid] [day] [reason]");
				SendClientMessage(playerid, ORANGE, "FUNCTION: Temporarily bans a player. You must enter the month, day and hour numbers. You set them, not add.");
				return 1;
			}
			giveplayerid = ReturnUser(tmp);
			new string[128];
			if(IsPlayerConnected(giveplayerid))
			{
			    tmp = strtok(cmdtext, idx);
			    if (!strlen(tmp)) return SendClientMessage(playerid, ORANGE, "USAGE: /tempban [playerid] [day] [reason]");
				new days = strval(tmp);
				new reason[128];
				reason = bigstr(cmdtext, idx);
				if (!strlen(reason)) return SendClientMessage(playerid, ORANGE, "USAGE: /tempban [playerid] [day] [REASON]");
				new ip[15];
				GetPlayerIp(giveplayerid,ip,15);
				GetPlayerName(playerid, name, sizeof name);
				GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
				new File:tempban = fopen("TempBans.ban", io_append);
				if (tempban)
				{
				    new year,month,day;
				    getdate(year, month, day);
				    day += days;
				    if (IsMonth31(month))
				    {
				        if (day > 31)
				        {
				            month += 1;
				            if (month > 12)
				            {
				                year += 1;
				                while(day > 31) day -= 31;
				            }
				            else while(day > 31) day -= 31;
				        }
				    }
				    else if (!IsMonth31(month))
				    {
				        if (day > 30)
				        {
				            month += 1;
				            if (month > 12)
				            {
				                year += 1;
				                while(day > 30) day -= 30;
				            }
				            else while(day > 30) day -= 30;
				        }
				    }
				    else if (!IsMonth31(month) && IsMonth29(year) && month == 2)
				    {
				        if (day > 29)
				        {
				            month += 1;
				            if (month > 12)
				            {
				                year += 1;
				                while(day > 29) day -= 29;
				            }
				            else while(day > 29) day -= 29;
				        }
				    }
				    else if (!IsMonth31(month) && !IsMonth29(year) && month == 2)
				    {
				        if (day > 28)
				        {
				            month += 1;
				            if (month > 12)
				            {
				                year += 1;
				                while(day > 28) day -= 28;
				            }
				            else while(day > 28) day -= 28;
				        }
				    }
				    format(string, sizeof string, "%d|%d|%d|%s\n", day, month, year, ip);
				    fwrite(tempban, string);
				    fclose(tempban);
				}
				format(string,128,"|- Administrator %s temporarily banned %s for %d day(s). [Reason: %s] -|",name,giveplayer,days,reason);
				SendClientMessageToAll(ADMIN_RED,string);
				Kick(giveplayerid);
			}
			else
			{
				format(string, sizeof(string), "%d is not an active player.", giveplayerid);
				SendClientMessage(playerid, RED, string);
			}
		}
		else return SendClientMessage(playerid, RED, "You are not an admin.");
		return true;
	}
	return false;
}

stock BanCheck(playerid)
{
    new player[MAX_PLAYER_NAME];
	new ip[15];
	new ban[20];
	new ban2[20];
	new filestr[128];
    GetPlayerName(playerid, player, sizeof player);
	GetPlayerIp(playerid, ip, sizeof ip);
	format(ban,sizeof(ban),"%s",ip);
	strdel(ban,strlen(ban)-2,strlen(ban));
	format(ban2,128,"%s**",ban);
	new File:file = fopen("Bans.txt",io_read);
	if (file)
	{
	    while(fread(file,filestr,sizeof(filestr)))
	    {
	    	if (strfind(filestr, player, true) != -1 || strfind(filestr, ip, true) != -1 || strfind(filestr, ban2, true) != -1)
	    	{
	    	    SendClientMessage(playerid, ADMIN_RED, "|- You are banned from this server -|");
	    	    return Kick(playerid);
	    	}
		}
	}
	return true;
}

stock TempBanCheck(playerid)
{
	new ip[15];
	new str[128];
	new load[4][32];
	new ban_day, ban_month, ban_year, ban_ip[15];
	GetPlayerIp(playerid, ip, sizeof ip);
	new year, month, day;
	getdate(year, month, day);
	new File:file = fopen("TempBans.ban",io_read);
	if (file)
	{
	    while (fread(file, str, sizeof str))
	    {
	        split(str, load, '|');

	        ban_day = strval(load[0]);
	        ban_month = strval(load[1]);
	        ban_year = strval(load[2]);
	        strmid(ban_ip, load[3], 0, strlen(load[3])-1, 15);
	    	if (!(year >= ban_year && month >= ban_month && day >= ban_day && !strcmp(ban_ip, ip, true)))
	    	{
	    	    format(str, sizeof str, "|- You are temporarily banned from this server until: %d/%d/%d -|", ban_day, ban_month, ban_year);
	    	    SendClientMessage(playerid, ADMIN_RED, str);
	    	    return Kick(playerid);
	    	}
		}
	}
	return true;
}

stock split(const strsrc[], strdest[][], delimiter)
{
	new i, li;
	new aNum;
	new len;

	while(i <= strlen(strsrc)){
	    if(strsrc[i]==delimiter || i==strlen(strsrc)){
	        len = strmid(strdest[aNum], strsrc, li, i, 128);
	        strdest[aNum][len] = 0;
	        li = i+1;
	        aNum++;
		}
		i++;
	}
	return 1;
}

stock IsMonth31(month)
{
 	switch (month)
	{
	    case 1: return 1;
	    case 3: return 1;
	    case 5: return 1;
	    case 7: return 1;
	    case 8: return 1;
	    case 10: return 1;
	    case 12: return 1;
	    default: return 0;
	}
	return 0;
}

stock IsMonth29(year)
{
 	new y = 2000;
 	for(new i = 4; i < 3000; i += 4) if ((y+i) == year) return 1;
 	return 0;
}



Re: [Ajuda] /tempban - Lуs - 16.12.2011

Vocк tem que colocar o sistema no seu GM para usar as variбveis do seu GM.


Re: [Ajuda] /tempban - ViniBorn - 16.12.2011

Ou acessar diretamente o arquivo.


Re: [Ajuda] /tempban - Nake01 - 16.12.2011

Amigo use as suas variaves de Administraзгo ex:

RCON й:
pawn Code:
if(IsPlayerAdmin(playerid))
No meu GM eu uso:
pawn Code:
if(PlayerInfo[playerid][Admin] >= 3)
Entгo sу podera banir quem tiver o level 3 ou maior que ele, veja do seu GM e modifique