rendered paste body#include <a_samp>
#include <file>
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_RED 0xAA3333AA
static fileLength;
static isTimer = 0;
static timerID;
public OnFilterScriptInit()
{
new string[256];
string = "Echo filterscript created by tommy4 loaded...";
print("\n-------------------------------");
print(" Echo filterscript by tommy4");
print("-------------------------------\n");
save(string);
fremove("echo/irc.txt");
fileLength = 0;
new File:irc = fopen("echo/irc.txt", io_write);
fclose(irc);
return 1;
}
public CheckFile(cmdtext[])
{
new string[1024];
new command[256];
new nick[MAX_PLAYER_NAME];
new msg[1024];
new File:irc = fopen("echo/irc.txt", io_read);
new idx;
new cmd[256];
cmd = strtok(cmdtext, idx);
fseek(irc, fileLength, seek_start);
while(fread(irc, string, sizeof(string), false))
{
strmid(command, string, 0, strfind(string, " ", false, 1), sizeof(command));
if(strcmp(command, "/say", true) == 0)
{
strmid(string, string, strfind(string, " ", false, 1), strlen(string), sizeof(string));
SendClientMessageToAll(COLOR_WHITE, string);
strmid(nick, string, strfind(string, " ", false, 1)+1, strfind(string, ":", false, 1), sizeof(nick));
strmid(msg, string, strfind(string, ":", false, 1)+1, strlen(string)-2, sizeof(msg));
format(string, sizeof(string), "14* [%s]: %s", nick, msg);
save(string);
} else {
if(strcmp(command, "/showmessage", true) == 0)
{
for (new i = 0; i < 100; i++) {
strmid(nick, string, strfind(string, " ", false, 1)+1, strfind(string, ":", false, 1), sizeof(nick));
strmid(msg, string, strfind(string, ":", false, 1)+1, strlen(string)-2, sizeof(msg));
GameTextForPlayer(i, msg, 5000, 3);
}
format(string, sizeof(string), "14* [%s] shows a message using showmessage: %s", nick, msg);
save(string);
} else {
if(strcmp(command, "/ban", true) == 0)
{
new commandIndex;
new tmp[256];
new banID;
new tmpUsername[MAX_PLAYER_NAME];
tmp = strtok(string, commandIndex);
if(!strlen(tmp))
{
printf("Test 1: %s",tmp);
// This is quite impossible, since this selects the "/ban"
return 1;
}
tmp = strtok(string, commandIndex);
if(!strlen(tmp) )
{
printf("Test 2: %s",tmp);
// To prevent that we ban ID 0 by mistyping.
return 1;
}
banID = strval(tmp);
printf("Test 3: ID: %d",banID);
if (IsNumeric(tmp)) {
if (IsPlayerConnected(banID)) {
SendClientMessage(banID, COLOR_RED, "You have been banned from the server.");
Wait(1000);
new BanString[256];
GetPlayerName(banID, tmpUsername, sizeof(tmpUsername));
format(BanString, sizeof(BanString), "%s has been banned from the server.", tmpUsername);
NewsMessage(BanString);
Ban(banID);
format(string, sizeof(string), "%s has been banned from the server.", tmpUsername);
save(string);
// And do the other required stuff
}
else
{
format(string, sizeof(string), "No one with id %s is connected!", banID);
save(string);
}
}
else
{
format(string, sizeof(string), "The input is not numeric!");
save(string);
}
}
else
{
if(strcmp(command, "/kick", true) == 0)
{
new commandIndex;
new tmp[256];
new kickID;
new tmpUsername[MAX_PLAYER_NAME];
tmp = strtok(string, commandIndex);
if(!strlen(tmp))
{
printf("Test 1: %s",tmp);
// This is quite impossible, since this selects the "/ban"
return 1;
}
tmp = strtok(string, commandIndex);
if(!strlen(tmp) )
{
printf("Test 2: %s",tmp);
// To prevent that we ban ID 0 by mistyping.
return 1;
}
kickID = strval(tmp);
printf("Test 3: ID: %d",kickID);
if (IsNumeric(tmp)) {
if (IsPlayerConnected(kickID)) {
SendClientMessage(kickID, COLOR_RED, "You have been kicked from the server.");
Wait(1000);
new BanString[256];
GetPlayerName(kickID, tmpUsername, sizeof(tmpUsername));
format(BanString, sizeof(BanString), "%s has been kicked from the server.", tmpUsername);
NewsMessage(BanString);
Kick(kickID);
format(string, sizeof(string), "%s has been kicked from the server.", tmpUsername);
save(string);
// And do the other required stuff
}
else
{
format(string, sizeof(string), "No one with id %s is connected!", kickID);
save(string);
}
}
else
{
format(string, sizeof(string), "The input is not numeric!");
save(string);
}
}
}
}
}
}
fileLength = flength(irc);
fclose(irc);
return 1;
}
public OnFilterScriptExit()
{
new string[256];
string = "Echo filterscript created by tommy4 unloaded...";
save(string);
return 1;
}
public OnPlayerText(playerid, text[])
{
new playerName[MAX_PLAYER_NAME];
new string[256];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(string, sizeof(string), "%s 7[id:%d]1: %s", playerName, playerid, text);
save(string);
return 1;
}
public OnPlayerPrivmsg(senderid, playerid, text[])
{
new sname[256], pname[256];
GetPlayerName(playerid, pname, sizeof(pname));
GetPlayerName(senderid, sname, sizeof(sname));
new temp[256];
format(temp, sizeof(temp), "2PM: 10%s7[id:%d]1 to 10%s7[id:%d]1: %s",sname, senderid, pname, playerid, text);
save(temp);
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[], text[])
{
new cmd[256];
new idx;
new string[256];
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/login", true) != 0 && strcmp(cmd, "/register", true) != 0 && strcmp(cmd, "/undercoverlogin", true) != 0) {
new pname[256];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "3*** %s 7[id:%d]1 used command: %s",pname, playerid, cmdtext);
save(string);
}
}
public OnPlayerConnect(playerid)
{
if(isTimer == 1)
{
KillTimer(timerID);
}
timerID = SetTimer("CheckFile", 1000, 1);
isTimer = 1;
new playerName[MAX_PLAYER_NAME];
new string[256];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(string, sizeof(string), "12%s [id:%d] has joined the server", playerName, playerid);
save(string);
return 1;
}
public OnPlayerDisconnect(playerid)
{
new playerName[MAX_PLAYER_NAME];
new string[256];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(string, sizeof(string), "12%s [id:%d] has left the server", playerName, playerid);
save(string);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
new playerName[MAX_PLAYER_NAME];
new killerName[MAX_PLAYER_NAME];
new string[256];
GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
new float:weaponName[64];
GetWeaponName(reason, weaponName, 64);
if(killerid != INVALID_PLAYER_ID)
{
GetPlayerName(killerid, killerName, MAX_PLAYER_NAME);
format(string, sizeof(string), "4%s [id:%d] has killed %s [id:%d] using a %s", killerName, killerid, playerName, playerid, weaponName);
}
else
{
format(string, sizeof(string), "4%s [id:%d] died", playerName, playerid);
}
save(string);
return 1;
}
save(text[])
{
new File:log = fopen("echo/echo.txt", io_append);
new string[256];
format(string, sizeof(string), "%s\r\n", text);
fwrite(log, string);
fclose(log);
return 1;
}
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;
}
public NewsMessage(string[])
{
new newsString[256];
format(newsString, sizeof(newsString), "NEWS: %s", string);
SendClientMessageToAll(COLOR_WHITE,newsString);
}
public Wait(time)
{
new stamp = tickcount();
while (tickcount() - stamp < time){}
return 1;
}
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}