Admin system
#1

Hi, im making an admin system for a friend, i got a register and login comand, and thanks to joestaff, a make admin.
but i got no more experience than that.... so i really need help. please make a ban and kick comand here, and write it step by step and explain it please, so i can learn, tell me whats that strlen thingy n stuff, and how do you make it check what i wrote and then execute the Kick comand, and then how to tell the player, you were kicked by admin blabla, and send a message to who kicked saying, you kicked blabla. and same for ban, thaankkssss
btw i use strcmp!
Reply
#2

Have you used dcmd?
Reply
#3

Quote:
Originally Posted by MadeMan
Have you used dcmd?
nope, fgot to say, its strcmp!
Reply
#4

If you have compiling errors let me know because i did'nt test it
Here you go:

First Step:
Add this to the first lines of your game mode/filterscript
Код:
#define ORANGE 0xF97804FF
#define RED 0xE60000FF
#define ADMIN_RED 0xFB0000FF
enum Info
{
	pAdminLevel,
};
new giveplayerid;
Add these after public OnPlayerCommandText
Код:
new idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/kick", true) == 0)
{
new reason[256];
if (PlayerInfo[playerid][pAdminLevel] >= 1 || IsPlayerAdmin(playerid))
	{
	tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			SendClientMessage(playerid, ORANGE, "USAGE: /kick [playerid] [reason]");
			SendClientMessage(playerid, ORANGE, "FUNCTION: Will kick the specified player. **PLEASE ENTER THE ID ONLY!**");
			return 1;
		}

		giveplayerid = ReturnUser(tmp);
		if(giveplayerid != INVALID_PLAYER_ID)
		{
		  GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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: /kick [playerid] [reason]");
					return 1;
				}
			else
			{
				printf("[ADMIN NEWS]: Admin %s kicked %s. Reason: %s", sendername, giveplayer, reason);
				format(string, sizeof(string), "-| Administrator %s kicked %s. [Reason: %s ]|-", sendername,giveplayer,reason);
				SendClientMessageToAll(ADMIN_RED, string);
				Kick(giveplayerid);
				KickLog(string);
				format(string, sizeof(string), "** [%i]%s left the server. ( Kicked ) **",playerid,player);
				SendClientMessageToAll(GRAY, string);
			}
		}

		else if(giveplayerid == INVALID_PLAYER_ID)
		{
			format(string, sizeof(string), "%d is not an active player.", giveplayerid);
			SendClientMessage(playerid, RED, string);
		}
	}
	else
 	{
 	SendClientMessage(playerid, RED, "You are not an admin with the required level.");
 	}
	return 1;
}
if (strcmp(cmd,"/ban", true) == 0) // ban command
	{
	  if (PlayerInfo[playerid][pAdminLevel] >= 3 || IsPlayerAdmin(playerid))
		{
			new reason[256],str[128],namez[24],name1[24],ip[20];
	  	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;
			}
      reason = strtok(cmdtext,idx);
	  	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;
			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,1);
						IPLog(namez,ip);
						Kick(i);
					}
				}
				else
				{
				  GetPlayerIp(i,ip,sizeof(ip));
					if (!IsPlayerConnected(i) && strfind(tmp,".",true) != -1 && count == 0)
					{
					  GetPlayerName(playerid,name1,24);
						IPLog("[none]",tmp);
						format(str,128,"|- Banned IP: [ %s ] by %s -|",tmp,name1);
						SendClientMessageToAdmins(ADMIN_RED,str,1);
					}
					count++;
				}
			}
		}
		return true;
	}
Reply
#5

Quote:
Originally Posted by [GTA
Deadly_Evil ]
If you have compiling errors let me know because i did'nt test it
Here you go:

First Step:
Add this to the first lines of your game mode/filterscript
Код:
#define ORANGE 0xF97804FF
#define RED 0xE60000FF
#define ADMIN_RED 0xFB0000FF
enum Info
{
	pAdminLevel,
};
new giveplayerid;
Add these after public OnPlayerCommandText
Код:
new idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/kick", true) == 0)
{
new reason[256];
if (PlayerInfo[playerid][pAdminLevel] >= 1 || IsPlayerAdmin(playerid))
	{
	tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			SendClientMessage(playerid, ORANGE, "USAGE: /kick [playerid] [reason]");
			SendClientMessage(playerid, ORANGE, "FUNCTION: Will kick the specified player. **PLEASE ENTER THE ID ONLY!**");
			return 1;
		}

		giveplayerid = ReturnUser(tmp);
		if(giveplayerid != INVALID_PLAYER_ID)
		{
		  GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
			GetPlayerName(playerid, sendername, sizeof(sendername));
			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: /kick [playerid] [reason]");
					return 1;
				}
			else
			{
				printf("[ADMIN NEWS]: Admin %s kicked %s. Reason: %s", sendername, giveplayer, reason);
				format(string, sizeof(string), "-| Administrator %s kicked %s. [Reason: %s ]|-", sendername,giveplayer,reason);
				SendClientMessageToAll(ADMIN_RED, string);
				Kick(giveplayerid);
				KickLog(string);
				format(string, sizeof(string), "** [%i]%s left the server. ( Kicked ) **",playerid,player);
				SendClientMessageToAll(GRAY, string);
			}
		}

		else if(giveplayerid == INVALID_PLAYER_ID)
		{
			format(string, sizeof(string), "%d is not an active player.", giveplayerid);
			SendClientMessage(playerid, RED, string);
		}
	}
	else
 	{
 	SendClientMessage(playerid, RED, "You are not an admin with the required level.");
 	}
	return 1;
}
if (strcmp(cmd,"/ban", true) == 0) // ban command
	{
	  if (PlayerInfo[playerid][pAdminLevel] >= 3 || IsPlayerAdmin(playerid))
		{
			new reason[256],str[128],namez[24],name1[24],ip[20];
	  	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;
			}
      reason = strtok(cmdtext,idx);
	  	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;
			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,1);
						IPLog(namez,ip);
						Kick(i);
					}
				}
				else
				{
				  GetPlayerIp(i,ip,sizeof(ip));
					if (!IsPlayerConnected(i) && strfind(tmp,".",true) != -1 && count == 0)
					{
					  GetPlayerName(playerid,name1,24);
						IPLog("[none]",tmp);
						format(str,128,"|- Banned IP: [ %s ] by %s -|",tmp,name1);
						SendClientMessageToAdmins(ADMIN_RED,str,1);
					}
					count++;
				}
			}
		}
		return true;
	}
will test now thanks, but i have my enums already, i alraedy have registe, makeadmin and login.. but my things are these:
new IsLogged[MAX_PLAYERS];
enum pInfo
{
AdminLevel,
Cash,

}
new PlayerInfo[MAX_PLAYERS][pInfo];

and this is where the player file with adminlevel,cash, password etc is saved to format(file,sizeof(file),"/admin/users/%s.ini",name); but il try your thing now . thanks
btw can you teach me how you did it step by step please?
and undefined symbol on giveplayerid and return user too... but i only testd kick!
Reply
#6

Its my sleep time sorry !
I am too lazy right now!
Reply
#7

Quote:
Originally Posted by [GTA
Deadly_Evil ]
Its my sleep time sorry !
I am too lazy right now!
lol ok thanks though
Reply
#8

by the way dude there is some commands in base have kick and ban and test_cmds have /v and etc..
Reply
#9

Quote:
Originally Posted by hvampire
by the way dude there is some commands in base have kick and ban and test_cmds have /v and etc..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Tried, and it just failed :-/!!
Reply
#10

for admin script dcmd is better and u only need to define it :

Top Of Script:
Код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
OnPlayerCommandText:
Код:
dcmd(urcommand, how much letters ur command has, cmdtext);
and then put ur command anywhere in the script

for example kick and ban command in strmp :

kick :
Код:
if(strcmp("/kick", cmd, true) == 0)
	{
	  if(IsPlayerAdmin(playerid)) {
			tmp = strtok(cmdtext,idx);
			if(!strlen(tmp) || strlen(tmp) > 5) {
				return SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /kick (id) [reason]");
			}
			
			new id = strval(tmp);

			if(!IsPlayerConnected(id)) {
				SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/kick : Bad player ID");
				return 1;
			}
			
			gMessage = strrest(cmdtext,idx);
			
			GetPlayerName(id,iName,sizeof(iName));
			SendClientMessage(id,ADMINFS_MESSAGE_COLOR,"-- You have been kicked from the server.");

			if(strlen(gMessage) > 0) {
				format(Message,sizeof(Message),"Reason: %s",gMessage);
				SendClientMessage(id,ADMINFS_MESSAGE_COLOR,Message);
			}
			
			format(Message,sizeof(Message),">> %s(%d) has been kicked.",iName,id);
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,Message);
			
			Kick(id);
			return 1;
		} else {
      SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/kick : You are not an admin");
			return 1;
		}
	}
Ban :

Код:
if(strcmp("/ban", cmd, true) == 0)
	{
	  if(IsPlayerAdmin(playerid)) {
			tmp = strtok(cmdtext,idx);
			if(!strlen(tmp) || strlen(tmp) > 5) {
				return SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /ban (id) [reason]");
			}

			new id = strval(tmp);

			if(!IsPlayerConnected(id)) {
				SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/ban : Bad player ID");
				return 1;
			}

			gMessage = strrest(cmdtext,idx);

			GetPlayerName(id,iName,sizeof(iName));
			SendClientMessage(id,ADMINFS_MESSAGE_COLOR,"-- You have been banned from the server.");

			if(strlen(gMessage) > 0) {
				format(Message,sizeof(Message),"Reason: %s",gMessage);
				SendClientMessage(id,ADMINFS_MESSAGE_COLOR,Message);
			}

			format(Message,sizeof(Message),">> %s(%d) has been banned.",iName,id);
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,Message);

			Ban(id);
			return 1;
		} else {
      SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/ban : You are not an admin");
			return 1;
		}
	}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)