Tempban system kicks all players while connecting
#1

As the title says, IDK why,
under onplayerconnect:
pawn Код:
new name[24],ip[16];
    GetPlayerIp(playerid,ip,sizeof ip);
    GetPlayerName(playerid,name,sizeof name);
    for(new id; id < 24; id++)
    {
        if(!strcmp(name,TempBans[id][BannedName]))
        {   // ban type is name
            SendClientMessage(playerid,COLOR_RED,"Your ban has not expired!");
            Kick(playerid);
            return 1;
        }

        if(!strcmp(ip,TempBans[id][BannedIP]))
        {   // ban type is ip !
            SendClientMessage(playerid,COLOR_RED,"Your ban has not expired!");
            Kick(playerid);
            return 1;
        }
stocks:
pawn Код:
forward TempBanUpdate();
public TempBanUpdate()
{
    new day,month,year,hour,minute,second,str[100];
    gettime(hour,minute,second);
    getdate(year,month,day);
    for(new id; id < 24; id++)
    {
        if(TempBans[id][UnbanDate] == day) // type 1 = day ban (unban on specific day)
        {
            if(strlen(TempBans[id][BannedIP]) > 0)
            {
                format(str,sizeof str,"unbanip %s",TempBans[id][BannedIP]);
                SendRconCommand(str);
                format(str,sizeof str,"Auto-Unban: IP %s was unbanned. (Ban Expired)",TempBans[id][BannedIP]);
                print(str);
                DeleteTempBanEntry(id);
                return 1;
            }

            if(strlen(TempBans[id][BannedName]) > 0)
            {
                format(str,sizeof str,"Auto-Unban: Name %s was unbanned. (Ban Expired)",TempBans[id][BannedName]);
                print(str);
                DeleteTempBanEntry(id);
            }
        }
    }
    return 1;
}

DeleteTempBanEntry(id)
{
    strdel(TempBans[id][BannedName],0,24);
    strdel(TempBans[id][BannedIP],0,16);
    TempBans[id][UnbanDate] = 0;
}

GetCurrentTempBanCount()
{
    new loaded;
    for(new id; id < 24; id++) //max of 24 temporary bans
    {
        if(strlen(TempBans[id][BannedName]) > 0 || strlen(TempBans[id][BannedIP]) > 0) loaded++;
    }
    return loaded;
}

GetTempBanSlot()
{
    new loaded;
    for(new id; id < 24; id++) //max of 24 temporary bans
    {
        if(strlen(TempBans[id][BannedName]) == 0 || strlen(TempBans[id][BannedIP]) == 0) loaded = id;
    }
    return loaded;
}

stock SaveTempBans()
{
    new dat[100];
    new File: file = fopen("tempbans.txt", io_write);
    for(new id; id<24; id++)
    {
        format(dat, 100, "%s,%s,%d\r\n",TempBans[id][BannedName],TempBans[id][BannedIP],TempBans[id][UnbanDate]);
        fwrite(file, dat);
    }
    fclose(file);
}

LoadTempBans()
{
    // load the bans
    new loaded=0;
    if(fexist("tempbans.txt"))
    {
        new dat[100];
        new File: file = fopen("tempbans.txt", io_read);
        if (file)
        {
            for(new id; id < 24; id++) //max of 24 temporary bans
            {
                fread(file,dat);
                sscanf(dat,"p<,>s[24]s[16]d",TempBans[id][BannedName],TempBans[id][BannedIP],TempBans[id][UnbanDate]);
                if(strlen(TempBans[id][BannedName]) > 0) loaded++;
            }
            fclose(file);
        }
    }
    return 1;
}

GetBan(ip[])
{
    for(new id; id < 24; id++)
    {
        if(!strcmp(ip,TempBans[id][BannedIP]))
        {
            return id;
        }
    }
    return 0;
}

stock TempAdmin(playerid)
{
    if(IsPlayerAdmin(playerid)) return true;
    return false;
}
tempban commands:
pawn Код:
CMD:tempbanip(playerid,params[])
{
    if (PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid,COLOR_RED,"You Are Not An Administrator.");
    new ip[16],days;
    if(GetCurrentTempBanCount() == 24) return SendClientMessage(playerid,COLOR_RED,"Temp Ban Limit Reached.");
    if(sscanf(params, "s[16]d",ip,days)) return SendClientMessage(playerid,COLOR_RED,"Usage: /tempbanip <ip> <amount of days ahead>");
    new year,mon,d;
    getdate(year,mon,d);
    new i = GetTempBanSlot();
    TempBans[i][BannedIP] = ip;
    TempBans[i][UnbanDate] = d+days;
    new str[100];
    format(str,sizeof str,"** IP %s set to be unbanned on %d/%d/%d",mon,d+days,year);
    SendClientMessage(playerid,COLOR_RED,str);
    format(str,sizeof str,"banip %s",ip);
    SendRconCommand(str);
    return 1;
}
CMD:tempban(playerid,params[])
{
    if (PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid,COLOR_RED,"You Are Not An Administrator.");
    new days,rsn[24],id,name[24];
    if(GetCurrentTempBanCount() == 24) return SendClientMessage(playerid,COLOR_RED,"Temp Ban Limit Reached.");
    if(sscanf(params, "uds[24]",id,days,rsn)) return SendClientMessage(playerid,COLOR_RED,"Usage: /tempban <PlayerID/Name> <Amount Of Days> <Reason>");
    new year,mon,d;
    getdate(year,mon,d);
    new i = GetTempBanSlot();
    new aname[24];
    GetPlayerName(playerid,aname,sizeof aname);
    GetPlayerName(id,name,sizeof name);
    format(TempBans[i][BannedName],sizeof name,"%s",name);
    TempBans[i][BannedName] = name;
    TempBans[i][UnbanDate] = d+days;
    new str[128];
    GetPlayerName(id,name,sizeof name);
    format(str,sizeof str,"%s (ID%d) has been temporary banned by Admin %s (ID:%d) (%s)",aname,playerid,name,id,rsn);
    SendClientMessage(playerid,COLOR_RED,str);
    return 1;
}
CMD:tempunban(playerid,params[])
{
    if (PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid,COLOR_RED,"You Are Not An Administrator.");
    new ip[16];
    if(GetCurrentTempBanCount() == 24) return SendClientMessage(playerid,COLOR_RED,"Temp Ban Limit Reached.");
    if(sscanf(params, "s[16]",ip)) return SendClientMessage(playerid,COLOR_RED,"Usage: /tempunban <IPAddress>");
    new i = GetBan(ip);
    if(i == 0) return SendClientMessage(playerid,COLOR_RED,"Ban Entry could not be found! Try again.");
    new str[100];
    format(str,sizeof str,"IP %s unbanned!",ip);
    SendClientMessage(playerid,COLOR_RED,str);
    DeleteTempBanEntry(i);
    return 1;
}
forward BanExDelay(playerid);
public BanExDelay(playerid)
{
    new reason[60];
    GetPVarString(playerid, "BanReason",reason, sizeof(reason));
    BanEx(playerid, reason);
    return 1;
}
Reply
#2

Anyone?
Reply
#3

pawn Код:
new name[24],ip[16];
    GetPlayerIp(playerid,ip,sizeof ip);
    GetPlayerName(playerid,name,sizeof name);
    for(new id; id < 24; id++)
    {
        if(strcmp(name,TempBans[id][BannedName]))
        {   // ban type is name
            SendClientMessage(playerid,COLOR_RED,"Your ban has not expired!");
            Kick(playerid);
            return 1;
        }

        if(strcmp(ip,TempBans[id][BannedIP]))
        {   // ban type is ip !
            SendClientMessage(playerid,COLOR_RED,"Your ban has not expired!");
            Kick(playerid);
            return 1;
        }
Try this and awnser mee
Reply
#4

or try:
pawn Код:
new name[24],ip[16];
    GetPlayerIp(playerid,ip,sizeof ip);
    GetPlayerName(playerid,name,sizeof name);
    for(new id; id < 24; id++)
    {
        if(name == TempBans[id][BannedName])
        {   // ban type is name
            SendClientMessage(playerid,COLOR_RED,"Your ban has not expired!");
            Kick(playerid);
            return 1;
        }

        if(ip == TempBans[id][BannedIP])
        {   // ban type is ip !
            SendClientMessage(playerid,COLOR_RED,"Your ban has not expired!");
            Kick(playerid);
            return 1;
        }
Reply
#5

Both not working, this tempban system is from: CJ101's Tempban system, please help me
Reply
#6

Keep in mind that strcmp returns 0 even if one or both of strings is/are NULL.

pawn Код:
#if !defined isnull
    #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
pawn Код:
if(!isnull(TempBans[id][BannedName]) && !strcmp(name,TempBans[id][BannedName]))

if(!isnull(TempBans[id][BannedIP]) && !strcmp(ip,TempBans[id][BannedIP]))
Reply
#7

Quote:
Originally Posted by bgedition
Посмотреть сообщение
or try:
pawn Код:
new name[24],ip[16];
    GetPlayerIp(playerid,ip,sizeof ip);
    GetPlayerName(playerid,name,sizeof name);
    for(new id; id < 24; id++)
    {
        if(name == TempBans[id][BannedName])
        {   // ban type is name
            SendClientMessage(playerid,COLOR_RED,"Your ban has not expired!");
            Kick(playerid);
            return 1;
        }

        if(ip == TempBans[id][BannedIP])
        {   // ban type is ip !
            SendClientMessage(playerid,COLOR_RED,"Your ban has not expired!");
            Kick(playerid);
            return 1;
        }
You can't compare strings like that in Pawn.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)