|
Оффлайн
Воскресенье, 25.08.2013, 16:30 | Сообщение # 1
|
|
Здравствуйте, уважаемые игроки. В данном мануале я расскажу как сделать так чтобы вы могли банить игрока по дням.
Добавим в начало мода.
Цитата (Код) #define send SendClientMessage
В OnPlayerConnect Цитата (Код) new PlayerIP[16]; GetPlayerIp(playerid, PlayerIP, sizeof(PlayerIP)); new UnBanTime = CheckTimeBanList( PlayerIP ); if(UnBanTime-GetTimeStamp() > 0) { new ubDay, ubHour, ubMin, ubSec, ubMSec; timeconvert((UnBanTime-GetTimeStamp())*1000,ubMin,ubSec,ubMSec); ubHour = ubMin/60; ubMin = ubMin%60; ubDay = ubHour/24; ubHour = ubHour%24; new UnBanTimeStr[256]; format(UnBanTimeStr, sizeof(UnBanTimeStr), "FS: Вы забанены, осталось %d дней %d часов %d минут и %d секунд.", ubDay, ubHour, ubMin, ubSec); send(playerid, COLOR_LIGHTRED, UnBanTimeStr); Kick(playerid); TogglePlayerControllable(playerid, 0); Добавим стоки в конец мода Цитата (Код) stock BanLog(string[]) { new entry[256]; format(entry, sizeof(entry), "%s\n",string); new File:hFile; hFile = fopen("[logs]/ban.log", io_append); fwrite(hFile, entry); fclose(hFile); } stock AddBan(player, playerid[], giveplayerid[], type = 1, chislo = 0, reason[]) { new totalban = 0; switch(type) { case 1: totalban = 60*chislo; // минуты case 2: totalban = 3600*chislo; // часы case 3: totalban = 86400*chislo; // сутки default: totalban = chislo; // секунды } new string[64]; format(string, sizeof(string), "banlist/%s.ini", playerid); new OpenBan = ini_createFile(string); if(OpenBan < 0) ini_openFile(string); ini_setInteger(OpenBan, "BanTime", gettime()); ini_setInteger(OpenBan, "UnBanTime", gettime()+totalban); ini_setString(OpenBan, "PlayerBan", giveplayerid); ini_setString(OpenBan, "Reason", reason); ini_closeFile(OpenBan); // Закрываем файл. return Kick(player); } stock UnBan(playerid[]) { new string[64]; format(string, sizeof(string), "banlist/%s.ini", playerid); return fremove(string); } CheckTimeBanList(ip[16]) { if(!fexist("Logs/TimeBanList.txt")) return false; new File:file = fopen("Logs/TimeBanList.txt", io_read); new TempStr[256]; new colon; new currentIP[16]; new unbantime; while( fread(file, TempStr, sizeof(TempStr)) ){ for(new i=0;i<strlen(TempStr);i++){ if(TempStr == ':'){ colon = i; break; } } strmid(currentIP, TempStr, 0, colon, sizeof(currentIP)); strmid(TempStr, TempStr, colon+1, strlen(TempStr), sizeof(TempStr)); unbantime = strval(TempStr); if( strcmp(ip, currentIP, true) == 0 && strlen(ip) == strlen(currentIP) ){ fclose(file); if(unbantime-GetTimeStamp() <= 0){ DeleteFromTimeBanList(currentIP); } return unbantime; } } fclose(file); return false; } DeleteFromTimeBanList(ip[16]) { if(!fexist("Logs/TimeBanList.txt")) return; new File:file = fopen("Logs/TimeBanList.txt", io_read); new File:tempFile = fopen("Logs/temp_TimeBanList.temp", io_append); new TempStr[256]; new colon; new currentIP[16]; while( fread(file, TempStr, sizeof(TempStr)) ){ for(new i=0;i<strlen(TempStr);i++){ if(TempStr == ':'){ colon = i; break; } } strmid(currentIP, TempStr, 0, colon, sizeof(currentIP)); if( !(strcmp(ip, currentIP, true) == 0 && strlen(ip) == strlen(currentIP)) ){ fwrite(tempFile, TempStr); } } fclose(file); fclose(tempFile); fremove("Logs/TimeBanList.txt"); file = fopen("Logs/TimeBanList.txt", io_append); tempFile = fopen("Logs/temp_TimeBanList.temp", io_read); while( fread(tempFile, TempStr, sizeof(TempStr)) ){ fwrite(file, TempStr); } fclose(file); fclose(tempFile); fremove("Logs/temp_TimeBanList.temp"); }
Теперь добавим команды в public OnPlayerCommandText
Цитата (Код) if(strcmp(cmd, "/ban", true) == 0) { if(PlayerInfo [playerid][pAdmin]>= 1) { tmp = strtok(cmdtext, idx); if(!strlen(tmp)) return send(playerid, 0xFFFFFFFF, "Furious: /ban [playerid][число] [причина]"); giveplayerid = strval(tmp); tmp = strtok(cmdtext, idx); if(!strlen(tmp)) return send(playerid, 0xFFFFFFFF, "Furious: /ban [playerid][число] [причина]"); new chislo = strval(tmp); if(!IsPlayerConnected(giveplayerid)) return send(playerid, COLOR_WHITE,"Этот игрок не в игре!"); if(giveplayerid != INVALID_PLAYER_ID) { new length = strlen(cmdtext); while ((idx < length) && (cmdtext [idx]<= ' ')) idx++; new offset = idx; new result[64]; while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))) { result[idx - offset] = cmdtext[idx]; idx++; } result[idx - offset] = EOS; if(!strlen(result)) return send(playerid, COLOR_WHITE, "Furious: {ffdb58}/ban [playerid][число] [причина]"); if(strval(tmp) < 1 || strval(tmp) > 365) return send(playerid, COLOR_GREY, "Количество дней бана игрока,должно быть от 1 до 3 65."); if(PlayerInfo [giveplayerid][pAdmin]== 6) { send(playerid, COLOR_WHITE, "Furious:{F42D2D} Этого игрока нельзя забанить!"); return true; } new PlayerNick[MAX_PLAYER_NAME], PlayerBan[MAX_PLAYER_NAME]; new ip[15]; GetPlayerIp(giveplayerid,ip,15); GetPlayerName(playerid, PlayerNick, MAX_PLAYER_NAME); GetPlayerName(giveplayerid, PlayerBan, MAX_PLAYER_NAME); new arank[64]; if(PlayerInfo [playerid][pAdmin]== 6) { arank = "Гл. Администратором"; } else if(PlayerInfo [playerid][pAdmin]== 5) { arank = "Гл. Модератором"; } else if(PlayerInfo [playerid][pAdmin]== 4) { arank = "Модератором"; } else if(PlayerInfo [playerid][pAdmin]== 3) { arank = "Модератором"; } else if(PlayerInfo [playerid][pAdmin]== 2) { arank = "Модератором"; } else if(PlayerInfo [playerid][pAdmin]== 1) { arank = "Модератором"; } else { arank = "Модератор"; } format(string, sizeof(string), "Furious: %s был(а) забанен(а) %s %s.(Дней: %d). Причина: %s", PlayerBan,arank,PlayerNick,chi slo,(result)); sendAll(COLOR_LIGHTRED, string); new year, month,day; getdate(year, month, day); new coordsstring3[512]; new msg3[] = "{ffdb58}__________________________________\n\n{ffdb58}Вас забанил:{ffffff} %s\n{ffdb58}Кол-во дней:{ffffff} %d\n{ffdb58}Дата бана: {FFFF FF}%d.%d.%d\n{ffdb58}Причина: {FFFFFF}%s\n\n{FFFFFF}Подробнее на сайте: {ffdb58}Furious.Ru"; format(coordsstring3, sizeof coordsstring3, msg3, PlayerNick,chislo,day,month,year,(result)); SPD(giveplayerid,82,DIALOG_STYLE_MSGBOX,"Вы были забанены",coordsstring3,"Закрыть",""); WriteLog(string,"ban.cfg"); PlayerInfo [giveplayerid][pBlockeds]+= 1; OnPlayerSave(giveplayerid); GetPlayerIp(giveplayerid,ip,sizeof(ip)); AddBan(giveplayerid, PlayerBan, PlayerNick, 3, chislo, result); format(string,sizeof(string),"banip %s",ip); SendRconCommand(string); SendRconCommand("reloadbans"); return true; } } return true; } if(strcmp(cmd,"/unban",true)==0) { if(PlayerInfo [playerid][pAdmin]>= 4) { tmp = strtok(cmdtext,idx); if(!strlen(tmp)) return send(playerid,COLOR_WHITE,"Furious: /unban [players nick]"); new adminname[32]; GetPlayerName(playerid, adminname, sizeof(adminname)); format(string, sizeof(string), "[Admin]: %s был(а) разбанен(а). Разбанил: %s.",tmp, adminname); ABroadCast(COLOR_RED, string, 1); format(string, sizeof(string), "Аккаунт %s был успешно разбанен!",tmp); send(playerid, COLOR_GREEN, string); UnBan(tmp); } return true; } |
|