Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <sscanf2>
- #include <zcmd>
- #include <TimestampToDate>
- #define MAX_TIMEBANS 50
- forward CheckTimebans();
- enum tbans
- {
- Used,
- IP_Address[16],
- UnbanTimestamp
- };
- new Timebans[MAX_TIMEBANS][tbans];
- stock GetFreeTimebanID()
- {
- for(new i = 0; i < MAX_TIMEBANS; i ++)
- {
- if(!Timebans[i][Used]) return i;
- }
- return -1;
- }
- public OnGameModeInit()
- {
- AddPlayerClass(0,0.0,0.0,0.0,0.0,0,0,0,0,0,0);
- SetTimer("CheckTimebans",50000,true); // We run it every 5 seconds, there is really no need to check it every second.
- SetGameModeText("Jochem testing");
- return 1;
- }
- CMD:tban(playerid, params[])
- {
- if(IsPlayerAdmin(playerid))
- {
- new target, days, reason[80];
- if(!sscanf(params, "uds[80]", target, days, reason))
- {
- if(!IsPlayerAdmin(target))
- {
- new string[128], name[2][MAX_PLAYER_NAME], date[6], IP[16], ts_unban = gettime() + (days * 86400), timeban_id = GetFreeTimebanID();
- if(timeban_id != -1)
- {
- GetPlayerName(playerid,name[0],MAX_PLAYER_NAME);
- GetPlayerName(target,name[1],MAX_PLAYER_NAME);
- GetPlayerIp(target,IP,16);
- format(string,sizeof(string),"Administrator %s (ID: %d) has banned %s (ID: %d) from the server (%d days).",name[0],playerid,name[1],target,days);
- for(new i = 0; i < MAX_PLAYERS; i ++)
- {
- if(i != target) SendClientMessage(i,-1,string);
- }
- TimestampToDate(ts_unban,date[0],date[1],date[2],date[3],date[4],date[5],2); // One day = 86400 seconds. Assume the server is running in London, or create your own script so the player can choose his timezone.
- SendClientMessage(target,-1,"- YOU HAVE BEEN BANNED FROM THE SERVER -");
- format(string,sizeof(string),"- Administrator: %s (ID: %d)",name[0],playerid);
- SendClientMessage(target,-1,string);
- format(string,sizeof(string),"- Reason: %s",reason);
- SendClientMessage(target,-1,string);
- format(string,sizeof(string),"- Date you will be unbanned: %02d/%02d/%02d %02d:%02d:%02d (%d days)",date[2],date[1],date[0],date[3],date[4],date[5],days);
- SendClientMessage(target,-1,string);
- SendClientMessage(target,-1,"- For more info, visit our forums: www.google.com");
- Timebans[timeban_id][Used] = 1;
- format(Timebans[timeban_id][IP_Address],16,"%s",IP);
- Timebans[timeban_id][UnbanTimestamp] = ts_unban;
- /*
- Write your own code here to store the ban info (MySQL would be great here?)
- */
- BanEx(target,reason);
- return 1;
- }
- else return SendClientMessage(playerid,-1,"Error: There are no free timeban IDs, increase MAX_TIMEBANS in the script.");
- }
- else return SendClientMessage(playerid,-1,"Error: That player is an administrator.");
- }
- else return SendClientMessage(playerid,-1,"Usage: /tban [ID / Part of name] [Days] [Reason]");
- }
- else return 0;
- }
- public CheckTimebans()
- {
- new time = gettime(),string[25];
- for(new i = 0; i < MAX_TIMEBANS; i ++)
- {
- if(Timebans[i][Used])
- {
- if(Timebans[i][UnbanTimestamp] <= time)
- {
- format(string,sizeof(string),"unbanip %s",Timebans[i][IP_Address]);
- SendRconCommand(string);
- printf("IP Address %s has been unbanned.",Timebans[i][IP_Address]);
- }
- }
- }
- return 1;
- }
- main()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment