Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- --- Timeban System
- --- by
- --- Mort
- */
- #include <a_samp>
- #define MAX_SIZE_COMMAND 25
- #define MAX_SIZE_PARAMS 103
- #define mCmd:%0(%1,%2) \
- forward cmd_%0(%1,%2); \
- public cmd_%0(%1,%2)
- /*
- stock UnParams by Mort
- Získá parametry funkce a zapíše je do proměnných
- */
- #include <a_samp>
- stock UnParams(params[],&id,duvod[35],&roky,&mesice,&dny,&hodiny,&minuty,&sekundy,&bool:perma)
- {
- // if(!(params[0]) || (params[0] == 1) && (params[1] == 0)) return false;
- // if(!(params[1])) return false;
- new
- paraCount = 0,
- len = strlen(params) + 1
- ;
- new
- ch2,
- value2[50],
- pos2 = 0
- ;
- while((ch2 = params[pos2]) && ch2 != ' ')
- {
- pos2++;
- }
- strmid(value2,params,0,pos2);
- if(IsInt(value2))
- {
- id = strval(value2);
- for(new i = pos2;i<len;i++)
- {
- if(params[i] == ' ') // params je mezera , další bude nějakej str
- {
- new
- ch,
- delim = ' ',
- pos = i + 1,
- value[50],
- bool:stoped = false
- ;
- while((ch = params[pos]) && ch != delim && ch != EOS)
- {
- if((pos == (i + 1)) && ch == EOS) { stoped = true; break; }
- else
- {
- pos++;
- }
- }
- if(!stoped)
- {
- paraCount++;
- strmid(value,params,i+1,pos);
- if(paraCount == 1)
- {
- if(strlen(value) >= 5 && strlen(value) < 35)
- {
- perma = true;
- format(duvod,35,value);
- }
- else
- {
- return false;
- }
- }
- else if(paraCount == 2)
- {
- if(IsInt(value))
- {
- perma = false;
- roky = strval(value);
- }
- else
- {
- return false;
- }
- }
- else if(paraCount == 3)
- {
- if(IsInt(value))
- {
- mesice = strval(value);
- }
- else
- {
- return false;
- }
- }
- else if(paraCount == 4)
- {
- if(IsInt(value))
- {
- dny = strval(value);
- }
- else
- {
- return false;
- }
- }
- else if(paraCount == 5)
- {
- if(IsInt(value))
- {
- hodiny = strval(value);
- }
- else
- {
- return false;
- }
- }
- else if(paraCount == 6)
- {
- if(IsInt(value))
- {
- minuty = strval(value);
- }
- else
- {
- return false;
- }
- }
- else if(paraCount == 7)
- {
- if(IsInt(value))
- {
- sekundy = strval(value);
- }
- else
- {
- return false;
- }
- }
- }
- }
- }
- }
- else { return false; }
- return true;
- }
- stock IsInt(string[])
- {
- new len = strlen(string);
- for(new i=0;i<len;i++)
- {
- if(string[i] >= '0' && string[i] <= '9') { }
- else { return false; }
- }
- return true;
- }
- stock PN(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name));
- return name;
- }
- stock mktime(hour,minute,second,day,month,year) { // fixed by Mort
- new timestamp2;
- timestamp2 = second + (minute * 60) + (hour * 3600);
- new days_of_month[12];
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
- days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31};
- } else {
- days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31};
- }
- new days_this_year = 0;
- days_this_year = day;
- if(month > 0) {
- for(new i=0; i<month;i++) {
- days_this_year += days_of_month[i];
- }
- }
- timestamp2 += days_this_year * 86400;
- for(new j=0;j<year;j++) {
- timestamp2 += 31536000;
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp2 += 86400;
- }
- return timestamp2;
- }
- stock date( timestamp, _form=0 )
- {
- /*
- ~ convert a Timestamp to a Date.
- ~ 10.07.2009
- date( 1247182451 ) will print >> 09.07.2009-23:34:11
- date( 1247182451, 1) will print >> 09/07/2009, 23:34:11
- date( 1247182451, 2) will print >> July 09, 2009, 23:34:11
- date( 1247182451, 3) will print >> 9 Jul 2009, 23:34
- */
- new year=1970, day=0, month=0, hour=0, mins=0, sec=0;
- new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
- new names_of_month[12][10] = {"Leden","Únor","Březen","Duben","Květen","Červen","Červenec","Srpen","Září","Říjen","Listopad","Prosinec"};
- new returnstring[32];
- while(timestamp>31622400){
- timestamp -= 31536000;
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
- year++;
- }
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
- days_of_month[1] = 29;
- else
- days_of_month[1] = 28;
- while(timestamp>86400){
- timestamp -= 86400, day++;
- if(day==days_of_month[month]) day=0, month++;
- }
- while(timestamp>60){
- timestamp -= 60, mins++;
- if( mins == 60) mins=0, hour++;
- }
- sec=timestamp;
- switch( _form ){
- case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
- case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hour, mins, sec);
- case 3: format(returnstring, 31, "%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+2,mins);
- default: format(returnstring, 31, "%02d.%02d.%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
- }
- return returnstring;
- }
- stock GetIp(playerid)
- {
- new ip[16];
- GetPlayerIp(playerid,ip,sizeof(ip));
- return ip;
- }
- stock UnFormat(str[],variables[][],cha,m=0) // by QWER
- {
- new len = strlen(str),chcount,i,start,varcount;
- while(i < len+1)
- {
- if(i == len && chcount != 0)
- {
- strmid(variables[varcount],str,start+1,strlen(str),128);
- chcount++;
- }
- if(str[i] == cha)
- {
- if((m == 0) || (chcount != m-1))
- {
- strmid(variables[varcount],str,start + ((start == 0) ? 0 : 1),i,128);
- start = i;
- chcount++;
- varcount++;
- }
- }
- i++;
- }
- return chcount;
- }
- stock fcreate(filename[])
- {
- if (fexist(filename)){return false;}
- new File:fhandle = fopen(filename,io_write);
- fclose(fhandle);
- return true;
- }
- stock DeleteLineFromLine(file[],linea)// by QWER
- {
- new File:a = fopen(file,io_read);
- new str[128],str2[128];
- format(str2,128,"%s.part",file);
- new File:b = fopen(str2,io_write);
- new lineb = 1;
- while(fread(a,str))
- {
- if(lineb == linea)
- {
- lineb++;
- continue;
- }
- else
- {
- fwrite(b,str);
- }
- lineb++;
- }
- fclose(a);
- fremove(file);
- fclose(b);
- b = fopen(str2,io_read);
- fcreate(file);
- a = fopen(file,io_write);
- while(fread(b,str))
- {
- fwrite(a,str);
- }
- fclose(a);
- fclose(b);
- fremove(str2);
- }
- /*
- -- Can be used only for TimebanSystem v2 by Mort!!!!
- */
- forward OnPlayerCommandTextMCMD(playerid,cmdtext[]);
- public OnPlayerCommandTextMCMD(playerid,cmdtext[])
- {
- new
- LastPos = 1,
- command[MAX_SIZE_COMMAND],
- params[MAX_SIZE_PARAMS],
- testCommand[MAX_SIZE_COMMAND+5],
- ch
- ;
- while((ch = cmdtext[LastPos]) && ch != EOS && ch != ' ')
- {
- LastPos++;
- }
- strmid(command,cmdtext,1,LastPos);
- format(testCommand,sizeof(testCommand),"cmd_%s",command);
- strmid(params,cmdtext,LastPos+1,128);
- printf("params=%s",params);
- if(!params[0]) format(params,sizeof(params)," ");
- if(CallLocalFunction(testCommand,"is",playerid,params))
- {
- return true;
- }
- else
- {
- return SendClientMessage(playerid,-1,"Chybný příkaz");
- }
- }
- public OnPlayerCommandText(playerid,cmdtext[])
- {
- return OnPlayerCommandTextMCMD(playerid,cmdtext);
- }
- public OnPlayerConnect(playerid)
- {
- new
- File:soubor = fopen("bans.txt",io_read),
- str[128],
- line
- ;
- while((fread(soubor,str)))
- {
- line++;
- new
- var[5][35]
- ;
- UnFormat(str,var,';');
- if(strcmp(var[0],GetIp(playerid),true)==0 || strcmp(var[1],PN(playerid),true)==0)
- {
- if(strval(var[4]) < gettime())
- {
- SendClientMessage(playerid,-1,"Ban ti vypršel, doufám, že ses poučil");
- DeleteLineFromLine("bans.txt",line);
- break;
- }
- else
- {
- new s[256];
- format(s,sizeof(s),"{FF0000}Ban ti ještě nevypršel!!!\n{FFFFFF}Administrátor: {33FF00}%s\n{FFFFFF}Datum banu: {33FF00}%s\n{FFFFFF}Vypršení banu: {33FF00}%s\n{FFFFFF}Důvod: {33FF00}%s",PN(playerid),date(strval(var[3]),3),date(strval(var[4]),3),var[2]);
- ShowPlayerDialog(playerid,10001,DIALOG_STYLE_MSGBOX,"Ban",s,"OK","");
- Kick(playerid);
- break;
- }
- }
- }
- fclose(soubor);
- return 1;
- }
- ////////////////////////////////////////////////////////////////////////////////
- mCmd:ban(playerid,params[])
- {
- if(IsPlayerAdmin(playerid))
- {
- new
- id,
- duvod[35],
- roky,
- mesice,
- dny,
- hodiny,
- minuty,
- sekundy,
- bool:perma
- ;
- if(UnParams(params,id,duvod,roky,mesice,dny,hodiny,minuty,sekundy,perma)) //return SendClientMessage(playerid,-1,"Usage: /ban [ID] [DUVOD] ([ROKY] [MESICE] [DNY] [HODINY] [MINUTY] [SEKUNDY])");
- {
- if(!IsPlayerConnected(id)) return SendClientMessage(playerid,-1,"Zadané ID není na serveru");
- if(playerid == id) return SendClientMessage(playerid,-1,"Nemůžeš zabanovat sám sebe!");
- if(perma)
- {
- new s[128];
- format(s,sizeof(s),"Administrátor {FFFF00}%s {FF0000}pernamentně{FFFFFF} zabanoval hráče {FFFF00}%s {FFFFFF}(Důvod: {FFFF00}%s{FFFFFF})",PN(playerid),PN(id),duvod);
- SendClientMessageToAll(-1,s);
- Ban(id);
- }
- else
- {
- printf("roky = %d, mesice = %d, dny = %d, hodiny = %d, minuty = %d, sekundy = %d",roky,mesice,dny,hodiny,minuty,sekundy);
- new
- time = gettime() + mktime(hodiny,minuty,sekundy,dny,mesice,roky),
- str[128],
- str2[256],
- str3[128],
- File:soubor = fopen("bans.txt",io_append)
- ;
- format(str,sizeof(str),"Administrátor {FF0000}%s{FFFFFF} zabanoval hráče {FF0000}%s{FFFFFF} do {FFFF00}%s",PN(playerid),PN(id),date(time,3));
- SendClientMessageToAll(-1,str);
- format(str2,sizeof(str2),"{FF0000}Byl jsi zabanován!!!\n{FFFFFF}Administrátor: {33FF00}%s\n{FFFFFF}Datum banu: {33FF00}%s\n{FFFFFF}Vypršení banu: {33FF00}%s\n{FFFFFF}Důvod: {33FF00}%s",PN(playerid),date(gettime(),3),date(time,3),duvod);
- ShowPlayerDialog(playerid,10000,DIALOG_STYLE_MSGBOX,"Ban",str2,"OK","");
- format(str3,sizeof(str3),"%s;%s;%s;%d;%d\r\n",GetIp(id),PN(id),duvod,gettime(),time);
- fwrite(soubor,str3);
- fclose(soubor);
- Kick(id);
- }
- }
- else return SendClientMessage(playerid,-1,"Usage: /ban [ID] [DUVOD (min.5 znaků)] ([ROKY] [MESICE] [DNY] [HODINY] [MINUTY] [SEKUNDY])");
- }
- else SendClientMessage(playerid,-1,"Nejsi admin!");
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment