Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <dini>
- #define DIALOG1 1
- #define DIALOG2 2
- #define QCMD:%1(%2) \
- forward cmd_%1(%2); \
- public cmd_%1(%2)
- #define SCM(%0,%1) SendClientMessage(%0,-1,%1)
- #pragma unused ret_memcpy
- #pragma unused strtok
- stock BanPlayer(playerid,admin[],months,days,hours,reason[])
- {
- new
- dat = gettime()+mktime(hours,0,0,days,months,0),
- str[128],
- cesta[16+15];
- format(str,sizeof(str),"Administrátor {FFFF00}%s{FFFFFF} zabanoval hráče {FFFF00}%s{FFFFFF} do %s ( Duvod:{FF0000} %s )",admin,PlayerName(playerid),date(dat,2),reason);
- format(cesta,sizeof(cesta),"Banneds/%s.ini",PlayerIP(playerid));
- SendClientMessageToAll(-1,str);
- print(str);
- dini_Create(cesta);
- dini_Set(cesta,"JmenoHrace",PlayerName(playerid));
- dini_IntSet(cesta,"Kdy",gettime());
- dini_IntSet(cesta,"Dokdy",dat);
- dini_Set(cesta,"Admin",admin);
- dini_Set(cesta,"Duvod",reason);
- Kick(playerid);
- }
- stock PlayerIP(playerid)
- {
- new ip[16];
- GetPlayerIp(playerid,ip,sizeof(ip));
- return ip;
- }
- stock PlayerName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name));
- return name;
- }
- stock IsBanned(playerid)
- {
- new
- cesta[16+15];
- format(cesta,sizeof(cesta),"Banneds/%s.ini",PlayerIP(playerid));
- if(dini_Exists(cesta))
- {
- if(dini_Int(cesta,"Dokdy")-gettime() > 0)
- {
- return 3;
- }
- else
- {
- return 2;
- }
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new cesta[16+15];
- format(cesta,sizeof(cesta),"Banneds/%s.ini",PlayerIP(playerid));
- new strr[270];
- if(IsBanned(playerid) == 3)
- {
- format(strr,sizeof(strr),"{FFFFFF}Jméno hráče: {FF0000}%s\n{FFFFFF}Od kdy: {FF0000}%s\n{FFFFFF}Do kdy: {FF0000}%s\n{FFFFFF}Admin: {FF0000}%s\n{FFFFFF}Duvod: {FF0000}%s",dini_Get(cesta,"JmenoHrace"),date(dini_Int(cesta,"Kdy"),2),date(dini_Int(cesta,"Dokdy"),2),dini_Get(cesta,"Admin"),dini_Get(cesta,"Duvod"));
- ShowPlayerDialog(playerid,DIALOG1,DIALOG_STYLE_MSGBOX,"BANNED",strr,"OK","");
- Kick(playerid);
- }
- else if(IsBanned(playerid) == 2)
- {
- ShowPlayerDialog(playerid,DIALOG2,DIALOG_STYLE_MSGBOX,"UNBANNED","Nyní jsi unbanovaný, doufám, že jsi se poučil","OK","");
- dini_Remove(cesta);
- }
- return true;
- }
- forward OnPlayerCommand(playerid,command[]);
- public OnPlayerCommand(playerid,command[])
- {
- new
- cmd[50],
- params[128],
- size = strfind(command, " ", true);
- if(size != -1)
- {
- strmid(params,command,size+1,strlen(command));
- strmid(cmd,command,1,size);
- }else
- {
- strmid(cmd,command,1,strlen(command));
- params = " ";
- }
- format(cmd,50,"cmd_%s",cmd);
- if(CallLocalFunction(cmd,"is",playerid,params))
- {
- return true;
- }else
- {
- return SCM(playerid,"Příkaz {FF0000}neexistuje");
- }
- }
- public OnPlayerCommandText(playerid,cmdtext[]){
- return OnPlayerCommand(playerid,cmdtext);
- }
- /*
- *
- * CMDS
- *
- * */
- QCMD:ban(playerid,params[])
- {
- if(IsPlayerAdmin(playerid))
- {
- new
- id,
- mesice,
- dny,
- hodiny,
- duvod[15];
- if(sscanf(params,"idddz",id,mesice,dny,hodiny,duvod)) return SendClientMessage(playerid,-1,"Použití: /ban [ID] [MESICE] [DNY] [HODINY] [DUVOD]");
- else if(!IsPlayerConnected(id)) return SendClientMessage(playerid,-1,"Hráe není na serveru");
- else if(strlen(duvod) > 15 || strlen(duvod) < 1) return SendClientMessage(playerid,-1,"Moc krátký nebo moc dlouhý duvod");
- else
- {
- BanPlayer(id,PlayerName(playerid),mesice,dny,hodiny,duvod);
- }
- }
- else SendClientMessage(playerid,-1,"Nejsi RCON Admin!");
- return 1;
- }
- ///////////////////////////////////////////////
- /*stock mktime(hour,minute,second,day,month,year) {
- 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}; // Schaltjahr
- } else {
- days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
- }
- new days_this_year = 0;
- days_this_year = day;
- if(month > 1) { // No January Calculation, because its always the 0 past months
- for(new i=0; i<month-1;i++) {
- days_this_year += days_of_month[i];
- }
- }
- timestamp2 += days_this_year * 86400;
- for(new j=1970;j<year;j++) {
- timestamp2 += 31536000;
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp2 += 86400; // Schaltjahr + 1 Tag
- }
- 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 sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement