SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   TIMEBAN (https://forum.sa-mp.com/showthread.php?t=644871)

Mivco 15/11/2017 06:54 PM

TIMEBAN
 
I want to ask if I have this code well done.
Under pawno there is a code but the servers can make mistakes.
Thanks

PHP Code:

#include <YSI\y_ini>
#include <YSI\y_commands>
#define HODINA(%0) 3600*%0
#define DIALOG_ID 874
#define BANPATH "Timeban/%s.txt"

enum bInfo
{
    
bIP,
    
bDATE,
    
bHODINY,
    
bNAME,
}

enum pInfo
{
    
Admin
}

new 
PlayerBan[MAX_PLAYERS][bInfo];
new 
PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadBan_data(playerid,name[],value[]);
public 
LoadBan_data(playerid,name[],value[])
{
    
INI_Int("Ip",PlayerBan[playerid][bIP]);
    
INI_Int("Date",PlayerBan[playerid][bDATE]);
    
INI_Int("Hodiny",PlayerBan[playerid][bHODINY]);
    
INI_Int("Name",PlayerBan[playerid][bNAME]);
    return 
1;
}

public 
OnPlayerConnect(playerid)
{
if(
fexist(BanPath(playerid)))
{
    
INI_ParseFile(BanPath(playerid), "LoadBan_%s", .bExtra true, .extra playerid);
    new 
dovod[75],string[128],ip[20];
    
GetPlayerIp(playerid,ip,20);
    if(
gettime() > strval(string))
    {
        
SendClientMessage(playerid,0x0000FFFF,"[TimeBan] {FF0000}Ban ti vypršal, dúfam že si sa poučil");
        
fremove(BanPath(playerid));
        }else{
        new 
strong[100];
        new 
ban[128];
        
strcat(ban,"Tvoj ešte stále nevypršal !\n");
        
format(strongsizeof(strong),"Nick: %s \n"Jmeno(playerid));
        
strcat(ban,strong);
        
format(strongsizeof(strong),"IP: %s \n"PlayerBan[playerid][bIP]);
        
strcat(ban,strong);
        
format(strongsizeof(strong), "Dôvod: %s \n"dovod);
        
strcat(ban,strong);
        
format(strongsizeof(strong), "Admin: %s \n"PlayerInfo[playerid][Admin]);
        
strcat(ban,strong);
        
format(strongsizeof(strong), "Kedy: %s \n"date(strval(string)));
        
strcat(ban,strong);
        
format(strongsizeof(strong), "Platnosť %s \n"date(strval(string)));
        
strcat(ban,strong);
        
ShowPlayerDialog(playerid,DIALOG_ID,DIALOG_STYLE_MSGBOX,"{0000FF}TimeBan",ban,"OK","");
        
SetTimerEx("KickPublic"15000"d"playerid);
    }
}
return 
1;
}

CMD:ban(playeridparams[])
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_WASTED) return SendClientMessage(playerid,0x0000FFFF,"[Server]: Nemôžeš byť vo výbere postáv !");
    new 
a[3][60],id,hodiny;
    if(
UnFormat(params,a,' ',3) != 3) return SendClientMessage(playerid,0x0000FFFF,"[Server]: /ban [id] [hodinky] [dovod]");
    
id strval(a[0]);
    if(!
IsPlayerConnected(id)) return SendClientMessage(playerid,0x0000FFFF,"[Server]: Hráč není na servery !");
    if(
IsPlayerAdmin(id)) return SendClientMessage(playerid,0x0000FFFF,"[Server]: Nemôžeš zabanovať hlavného admina !");
    new 
plrIP[64],name[32];

    
hodiny strval(a[1]);
    new 
INI:Fi INI_Open(BanPath(playerid));
    
INI_SetTag(Fi,"BAN Data");
    
INI_WriteInt(Fi,"Ip"GetPlayerIp(playeridplrIP64));
    
INI_WriteInt(Fi,"Date"gettime());
    
INI_WriteInt(Fi,"Hodiny"HODINA(hodiny)+gettime());
     
INI_WriteInt(Fi,"Name"GetPlayerName(playerid,name,sizeof(name)));
    
INI_WriteString(Fi,"Hrac",a[2]);
    
INI_Close(Fi);

    new 
strong[128];
    
format(strongsizeof(strong),"[TimeBan] {FF0000}Admin {FFFFFF}%s{FF0000} dal hráčovy {FFFFFF}%s {FF0000}ban na %d hodín Dôvod: %s",Jmeno(playerid),Jmeno(id),hodiny,a[2]);
    
SendClientMessageToAll(-1,strong);
    
SetTimerEx("KickPublic"15000"d"id);
    return 
true;
}

forward KickPublic(playerid);
public 
KickPublic(playerid)
{
    
Kick(playerid);
    return 
1;
}

stock BanPath(playerid)
{
    new 
string[128],playername[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,playername,sizeof(playername));
    
format(string,sizeof(string),BANPATH,playername);
    return 
string;
}


stock Jmeno(playerid)
{
    new 
n[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,n,MAX_PLAYER_NAME);
    return 
n;
}

stock UnFormat(str[],variables[][],cha,m=0)
{
    new 
len strlen(str),chcount,i,start,varcount;
    while(
len+1)
    {
        if(
== len && chcount != 0)
        {
            
strmid(variables[varcount],str,start+1,strlen(str),128);
            
chcount++;
        }
        if(
str[i] == cha)
        {
            if((
== 0) || (chcount != m-1))
            {
                
strmid(variables[varcount],str,start + ((start == 0) ? 1),i,128);
                
start i;
                
chcount++;
                
varcount++;
            }
        }
        
i++;
    }
    return 
chcount;
}

stock datetimestamp_form=)
{
    new 
year=1970day=0month=0hour=0mins=0sec=0;
    new 
days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    new 
names_of_month[12][10] = {"Januar","Februar","Marec","April","Maj","Jun","Jul","August","September","Oktober","November","December"};
     new 
returnstring[32];
      while(
timestamp>31622400)
      {
           
timestamp -= 31536000;
        if ( ((
year == 0) && (year 100 != 0)) || (year 400 == 0) ) timestamp -= 86400;
        
year++;
    }
    if ( ((
year == 0) && (year 100 != 0)) || (year 400 == 0) )
    
days_of_month[1] = 29;
    else
    
days_of_month[1] = 28;
    while(
timestamp>86400)
    {
        
timestamp -= 86400day++;
        if(
day==days_of_month[month]) day=0month++;
    }
    while(
timestamp>60)
    {
        
timestamp -= 60mins++;
         if( 
mins == 60mins=0hour++;
    }
    
sec=timestamp;
    switch( 
_form )
    {
        case 
1format(returnstring31"%02d/%02d/%d %02d:%02d:%02d"day+1month+1yearhourminssec);
        case 
2format(returnstring31"%s %02d, %d, %02d:%02d:%02d"names_of_month[month],day+1,yearhourminssec);
        case 
3format(returnstring31"%d %c%c%c %d, %02d:%02d"day+1,names_of_month[month][0],names_of_month[month][1],names_of_month[month][2], year,hour,mins);
        default: 
format(returnstring31"%02d.%02d.%d %02d:%02d:%02d"day+1month+1yearhourminssec);
    }
    return 
returnstring;



Gameluner 15/11/2017 07:13 PM

Re: TIMEBAN
 
Chybu zde nevidím, nu což, prohlédl jsem to jen zběžně.

Sorry, that I doesn't speak English, but this man is a Slovak. :)

Lucases 15/11/2017 08:52 PM

Re: TIMEBAN
 
You should save the IP as a string, because there are "." (points) between numbers.
Save also name as string, and since you aren't using mysql you can't save nor get the date. If you use INI you'll have to make three lines (day,month,year).
Lower IP variable to 16.
Change your ban path from .txt to .ini
You created a variable string[128] and you used "Gettime > strval(string)" without putting any data inside it.

You could format only one variable with inside dialog string without all those strcat.


All times are GMT. The time now is 06:15 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.