Szerző Téma: Idõre ban  (Megtekintve 923 alkalommal)

Idõre ban
« Dátum: 2013. Október 03. - 16:01:13 »
0 Show voters
Helló Ladmin ba szeretnék egy /tempban id nap  parancsot de eddig nem nagyon jött össze a pawno hibát nem ír de a mikor vissza megyek nem kickel újra ki ezért volna a kérdése m ebben mi lehet a hiba?
 
//public OnPlayerConnect(playerid) alatt
TempBanCheck(playerid);
// parancs része
    if(strcmp(cmd, \"/tempban\", true) == 0)
        {
            new name[MAX_PLAYER_NAME];
            new giveplayer[MAX_PLAYER_NAME];
            new giveplayerid;
     //if(AdminLevel[playerid] >= 4)
     if(PlayerInfo[playerid][Level] >= 4)
            {
                tmp = strtok(cmdtext,idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_LIGHTBLUE, \"Használat: /tempban [iD] [Nap(ok)] [Oka]\");
                    return 1;
                }
                giveplayerid = ReturnUser(tmp);
                if(IsPlayerConnected(giveplayerid))
                {
                    tmp = strtok(cmdtext, idx);
                    if (!strlen(tmp))
                    {
                    SendClientMessage(playerid, COLOR_LIGHTBLUE, \"Használat: /tempban [iD] [Nap(Ok)] [Oka]\");
                    return 1;
                    }
                    new days = strval(tmp);
                    if(!IsNumeric(tmp))
                    return SendClientMessage(playerid, COLOR_LIGHTRED, \"Hiba: Rossz nap! Csak számokat használhatsz!\");
                    if(strval(tmp) <= 0 || strval(tmp) > 1000)
                    return SendClientMessage(playerid, COLOR_LIGHTRED, \"Hiba: Rossz nap! (1-1000)\");
                    new reason[128];
                    reason = strtok2(cmdtext,idx);
                    if (!strlen(reason))
                    return SendClientMessage(playerid, COLOR_LIGHTRED, \"Hiba: Az ok nincs megadva!\");
                    if (strlen(reason) <= 0 || strlen(reason) > 100)
                    return SendClientMessage(playerid, COLOR_LIGHTRED, \"Hiba:Az ok betûszáma túl kicsi!\");
                    new ip[15];
                    GetPlayerIp(giveplayerid,ip,15);
                    GetPlayerName(playerid, name, sizeof name);
                    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                    new File:tempban = fopen(\"ladmin/logs/TempBanok.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,\"|- Admin %s Ideiglenesen bannolta %s-t  %d napra | oka: %s -|\",name,giveplayer,days,reason);
                    SendClientMessageToAll(COLOR_LIGHTRED,string);
                    Kick(giveplayerid);
                }
                else
                {
                SendClientMessage(playerid,COLOR_LIGHTRED,\"valami\");
                }
      }
            else return SendClientMessage(playerid,COLOR_LIGHTRED,\"valami\");
            return true;
        }
//és a többi ami még kell
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, red, \"HIBA: Többszörös felhasználók vannak, belépve teljes játékosnév.\");
}
userid = INVALID_PLAYER_ID;
}
return userid;
}
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(\"ladmin/logs/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, \"|- kibannoltak eny idõre:: %d/%d/%d -|\", ban_day, ban_month, ban_year);
           SendClientMessage(playerid, COLOR_RED, str);
           return Kick(playerid);
       }
}
}
return true;
}
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;
}
stock strtok2(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;
}
split(const strsrc[], strdest[][], delimiter)
{
new i, li,aNum,len;
while(i <= strlen(strsrc))
{
    if(strsrc==delimiter || i==strlen(strsrc))
{
        len = strmid(strdest[aNum], strsrc, li, i, 128);
        strdest[aNum][len] = 0;
        li = i+1;
        aNum++;
}
i++;
}
return aNum;
}

 

Dupla hozzászólás automatikusan összefûzve. ( 2013. Október 03. - 18:43:37 )

a beírás az jó az biztos mert az adatokat beírja a file ba de a kiolvasásban nem vagyok biztos hogy jó-e így lehet hogy az nem jó?
« Utoljára szerkesztve: 2013. Október 03. - 18:43:38 írta solyom1992 »

Idõre ban
« Válasz #1 Dátum: 2013. Október 06. - 08:54:03 »
0 Show voters
Nézz utána az unix idõnek. Samp ban a gettime () függvény paraméterek nélkül ezzel tér vissza. Lényege hogy 1970 jan 1. 0 óra 0 perc óta él telt másodperceket adja meg. gmt+0  idõ zónában és téli nyári idõszámítást nem figyelembe véve. Ha át akarod alakítani rendes olvasható dátummá arra van függvény itt sampforumon is de az nem kezeli az idõzónákat sem a DST-t () Daylight Saving Time vagyis a téli nyári idõszámítást.de azt hogy mit itthon ki unban dátumnak azt meg bírod oldani viszont unix idõvel javaslom annak le ellenõrzését hogy banolva van e. Mert az csak ennyi: banoláskor ha egy napra akarod akkor az unban dátum gettime() +60*60*24 ugye egy nap másodpercben és csatlakozásnál meg if (bandate >= gettime())banolva van

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal