Little help -
new121 - 01.03.2012
pawn Код:
CMD:ban(playerid, params[])
{
if (PlayerInfo[playerid][pAdmin] >= 2)
{
new string[128], ID, reason[64];
if(sscanf(params, "us[64]", ID, reason)) return SendClientMessage(playerid, COLOR_GRAD1, "BAN USAGE: /ban id reason");
if(IsPlayerConnected(giveplayerid))
{
if(PlayerInfo[ID][pAdmin] > PlayerInfo[playerid][pAdmin])
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s Been banned! Attempting to ban a higher level administrator!", name);
SendClientMessageToAll(COLOR_BAN, string);
PlayerInfo[ID][pBanned] ++;
return 1;
}
else
{
new pip[16], File:ftw=fopen("Bannedips.txt", io_write);
new BIP= GetPlayerIp(playerid, pip, sizeof(pip));
format(string,sizeof(string)," %i banned for %s\r\n", BIP, reason);
SendClientMessageToAll(COLOR_BAN, string);
fwrite(ftw, string);
fclose(ftw);
return 1;
}
}
}
else SendClientMessage(playerid, COLOR_GRAD1, "Invalid player specified.");
return 1;
}
I made that cmd as you can see in the second half when i ban I player it saves their ip to a file, now I am wondering what I do on onplayerconnect to read that file and see if the person who is connecting's ip is on that list.
how would I do this?
I know I would do
pawn Код:
new File:ftw=fopen("Bannedips.txt", io_read);
// what do I do here to see if the users ip is on the list,
//kicks the player if the ip is on the list
Re: Little help -
Walsh - 01.03.2012
Quote:
Originally Posted by new121
pawn Код:
CMD:ban(playerid, params[]) { if (PlayerInfo[playerid][pAdmin] >= 2) { new string[128], ID, reason[64]; if(sscanf(params, "us[64]", ID, reason)) return SendClientMessage(playerid, COLOR_GRAD1, "BAN USAGE: /ban id reason");
if(IsPlayerConnected(giveplayerid)) { if(PlayerInfo[ID][pAdmin] > PlayerInfo[playerid][pAdmin]) {
new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); format(string, sizeof(string), "%s Been banned! Attempting to ban a higher level administrator!", name); SendClientMessageToAll(COLOR_BAN, string); PlayerInfo[ID][pBanned] ++; return 1; } else {
new pip[16], File:ftw=fopen("Bannedips.txt", io_write); new BIP= GetPlayerIp(playerid, pip, sizeof(pip)); format(string,sizeof(string)," %i banned for %s\r\n", BIP, reason); SendClientMessageToAll(COLOR_BAN, string); fwrite(ftw, string); fclose(ftw); return 1; }
} } else SendClientMessage(playerid, COLOR_GRAD1, "Invalid player specified."); return 1; }
I made that cmd as you can see in the second half when i ban I player it saves their ip to a file, now I am wondering what I do on onplayerconnect to read that file and see if the person who is connecting's ip is on that list.
how would I do this?
|
All you have to do is add
Ban or
BanEx in your command. Those both ban IP's, so reading the IP and checking if it's banned or not is unnecessary.
Re: Little help -
new121 - 01.03.2012
I am trying to do this so lower level admins can unban without having to have access to the server folder
Re: Little help -
Walsh - 01.03.2012
Quote:
Originally Posted by new121
I am trying to do this so lower level admins can unban without having to have access to the server folder
|
Then you should say so in your original post man.
Re: Little help -
new121 - 01.03.2012
I don't see what different it makes, all I am asking is how to read if someones current ip is on that file.
Re: Little help -
Walsh - 01.03.2012
Well, when someone knows that you also want an unban command to be possible, then it would influence the advice they give. Sorry I couldn't help you. I'll still try. OnPlayerConnect you would make a string and assign it to GetPlayerIP.I think then you would loop through the whole ban file, and add an if statement using strcmp if the GetPlayerIp string is equal to anything on the ban list then kick them? I'm not too experienced as you can tell. D:
Re: Little help -
new121 - 01.03.2012
Yea I have no idea how to tell if something is = to something on a file.
Re: Little help -
Walsh - 01.03.2012
By using
strcmp, a string comparer.
Re: Little help -
new121 - 01.03.2012
Can you provide an example?
Re: Little help -
Walsh - 01.03.2012
This probably doesn't work as I'm new to this as well. I just looked up a lot of C++ references to help me come up with this.
pawn Код:
public OnPlayerConnect(playerid)
{
new IP[20],filestring[124];
GetPlayerIp(playerid,IP,sizeof(IP)); //Stores the players IP into the IP string
new File:banfile=fopen(/*your file here*/,io_read)// this opens your ban file and prepares it for reading.
while(fread(/*your file here*/,filestring,sizeof(filestring)); // Reads the ban file and stores its content into filestring
{
if(strfind(filestring,IP) != -1)
{
SendClientMessage(playerid,-1,"You are banned.");
Kick(playerid);
}
}
return 1;
}
You might also wanna learn how the file functions work completely if you haven't already. Goodluck man.