SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <a_samp> | |
| 2 | //#include <timerfix> // Фикс таймеров | |
| 3 | ||
| 4 | new ShowIPRange[32]; // Если IP играка забанен, сюда попадает диапазон, в котором он забанен. | |
| 5 | ||
| 6 | public OnFilterScriptInit() | |
| 7 | {
| |
| 8 | print("\n ------------------------------------- ");
| |
| 9 | print(" | Range Ban System 1.0 |");
| |
| 10 | print(" |By Dragon_Knight (ex: FITZ_NICK) 2012|");
| |
| 11 | print(" ------------------------------------- \n");
| |
| 12 | ||
| 13 | return 1; | |
| 14 | } | |
| 15 | ||
| 16 | public OnFilterScriptExit() | |
| 17 | {
| |
| 18 | ||
| 19 | return 1; | |
| 20 | } | |
| 21 | ||
| 22 | public OnPlayerConnect(playerid) | |
| 23 | {
| |
| 24 | if(IsPlayerNPC(playerid)) return 1; | |
| 25 | ||
| 26 | SetTimerEx("CheckPlayer",2500,false,"d",playerid);
| |
| 27 | ||
| 28 | return 1; | |
| 29 | } | |
| 30 | ||
| 31 | public OnPlayerDisconnect(playerid, reason) | |
| 32 | {
| |
| 33 | ||
| 34 | return 1; | |
| 35 | } | |
| 36 | ||
| 37 | public OnPlayerCommandText(playerid, cmdtext[]) | |
| 38 | {
| |
| 39 | new cmd[128], idx; | |
| 40 | new strmsg[200]; | |
| 41 | cmd = strtok(cmdtext, idx); | |
| 42 | ||
| 43 | if(strcmp(cmd, "/rangeadd", true) == 0) | |
| 44 | {
| |
| 45 | new rangeIP[32]; | |
| 46 | rangeIP = strtok(cmdtext, idx); | |
| 47 | ||
| 48 | if(!strlen(rangeIP)) | |
| 49 | {
| |
| 50 | SendClientMessage(playerid,0xFF0000FF,"Использование: /rangeadd [диапазон]. Например: '/rangeban 192.168.0.0-192.168.0.255'"); | |
| 51 | return 1; | |
| 52 | } | |
| 53 | ||
| 54 | new File:f = fopen("/range_ban.lst",io_append);
| |
| 55 | if(f) | |
| 56 | {
| |
| 57 | new writestr[64]; | |
| 58 | format(writestr,sizeof(writestr),"%s\n",rangeIP); | |
| 59 | fwrite(f,writestr); | |
| 60 | fclose(f); | |
| 61 | format(strmsg,sizeof(strmsg),"[RBS]: Диапазон адресов: '%s' ушпешно добавлен в банлист",rangeIP); | |
| 62 | SendClientMessage(playerid,0x00FF00FF,strmsg); | |
| 63 | } | |
| 64 | else | |
| 65 | {
| |
| 66 | format(strmsg,sizeof(strmsg),"[RBS]: Ошибка добавления диапазона адресов: '%s'",rangeIP); | |
| 67 | SendClientMessage(playerid,0xFF0000FF,strmsg); | |
| 68 | } | |
| 69 | ||
| 70 | return 1; | |
| 71 | } | |
| 72 | ||
| 73 | if(strcmp(cmd, "/rangecheck", true) == 0) | |
| 74 | {
| |
| 75 | new checkIP[32]; | |
| 76 | checkIP = strtok(cmdtext, idx); | |
| 77 | ||
| 78 | if(!strlen(checkIP)) | |
| 79 | {
| |
| 80 | SendClientMessage(playerid,0xFF0000FF,"Использование: /rangecheck [ip адрес]. Например: '/rangeban 192.168.0.1'"); | |
| 81 | return 1; | |
| 82 | } | |
| 83 | ||
| 84 | switch(CheckIPBan(checkIP)) | |
| 85 | {
| |
| 86 | case -1: | |
| 87 | {
| |
| 88 | SendClientMessage(playerid,0xFF0000FF,"[RBS]: При чтении файла произошла ошибка"); | |
| 89 | } | |
| 90 | case 0: | |
| 91 | {
| |
| 92 | format(strmsg,sizeof(strmsg),"[RBS]: IP адрес: '%s' не находиться в банлисте",checkIP); | |
| 93 | SendClientMessage(playerid,0x00FF00FF,strmsg); | |
| 94 | } | |
| 95 | case 1: | |
| 96 | {
| |
| 97 | format(strmsg,sizeof(strmsg),"[RBS]: IP адрес: '%s' находиться в банлисте. Забаненый диапазон: '%s'",checkIP,ShowIPRange); | |
| 98 | SendClientMessage(playerid,0xFF6600FF,strmsg); | |
| 99 | } | |
| 100 | } | |
| 101 | ||
| 102 | return 1; | |
| 103 | } | |
| 104 | ||
| 105 | return 0; | |
| 106 | } | |
| 107 | ||
| 108 | forward CheckPlayer(playerid); | |
| 109 | public CheckPlayer(playerid) | |
| 110 | {
| |
| 111 | if(!IsPlayerConnected(playerid)) return 0; | |
| 112 | ||
| 113 | new PlayerIP[16], strmsg[200]; | |
| 114 | GetPlayerIp(playerid,PlayerIP,sizeof(PlayerIP)); | |
| 115 | ||
| 116 | switch(CheckIPBan(PlayerIP)) | |
| 117 | {
| |
| 118 | case -1: | |
| 119 | {
| |
| 120 | SendClientMessage(playerid,0xFF0000FF,"[RBS]: При чтении файла произошла ошибка. Мы проверим Вас через 30 секунд."); | |
| 121 | SetTimerEx("CheckPlayer",30000,false,"d",playerid);
| |
| 122 | } | |
| 123 | case 0: | |
| 124 | {
| |
| 125 | SendClientMessage(playerid,0x00FF00FF,"[RBS]: Всё нормально, можете играть."); | |
| 126 | } | |
| 127 | case 1: | |
| 128 | {
| |
| 129 | format(strmsg,sizeof(strmsg),"[RBS]: IP адрес: '%s' находиться в банлисте. Забаненый диапазон: '%s'",PlayerIP,ShowIPRange); | |
| 130 | SendClientMessage(playerid,0xFF6600FF,strmsg); | |
| 131 | Kick(playerid); | |
| 132 | } | |
| 133 | } | |
| 134 | ||
| 135 | return 1; | |
| 136 | } | |
| 137 | ||
| 138 | CheckIPBan(playerIP[]) | |
| 139 | {
| |
| 140 | new bool:IPFound; | |
| 141 | new File: f = fopen("/range_ban.lst",io_read), buff[32];
| |
| 142 | if(!f) | |
| 143 | {
| |
| 144 | print("\n[RBS]: Error reading banlist file\n");
| |
| 145 | return -1; | |
| 146 | } | |
| 147 | while(fread(f,buff)) | |
| 148 | {
| |
| 149 | new IPRange[2][16], FirstIP, IP[16], CurrentIP, LastIP; | |
| 150 | strclr(buff); | |
| 151 | split(buff,IPRange,'-'); | |
| 152 | FirstIP = EncodeIP(IPRange[0]); | |
| 153 | format(IP,sizeof(IP),"%s",playerIP); // Тапорка. Так мы указываем размер массива. | |
| 154 | CurrentIP = EncodeIP(IP); | |
| 155 | LastIP = EncodeIP(IPRange[1]); | |
| 156 | ||
| 157 | if(FirstIP <= CurrentIP <= LastIP) | |
| 158 | {
| |
| 159 | IPFound = true; | |
| 160 | format(ShowIPRange,sizeof(ShowIPRange),"%s",buff); | |
| 161 | break; | |
| 162 | } | |
| 163 | } | |
| 164 | fclose(f); | |
| 165 | ||
| 166 | if(IPFound == true) return 1; | |
| 167 | else return 0; | |
| 168 | } | |
| 169 | ||
| 170 | //-----------------------------------[Стоки]------------------------------------ | |
| 171 | stock split(const strsrc[], strdest[][], delimiter = '|') | |
| 172 | {
| |
| 173 | new i, li, aNum, len, srclen = strlen(strsrc); | |
| 174 | while(i <= srclen) | |
| 175 | {
| |
| 176 | if (strsrc[i] == delimiter || i == srclen) | |
| 177 | {
| |
| 178 | len = strmid(strdest[aNum], strsrc, li, i, 128); | |
| 179 | strdest[aNum][len] = 0; | |
| 180 | li = i + 1; | |
| 181 | aNum++; | |
| 182 | } | |
| 183 | i++; | |
| 184 | } | |
| 185 | } | |
| 186 | ||
| 187 | stock EncodeIP(ip[], size=sizeof(ip)) | |
| 188 | {
| |
| 189 | new val=0, acc=0, s=3; | |
| 190 | for(new i=0; i < size; i++) | |
| 191 | {
| |
| 192 | switch(ip[i]) | |
| 193 | {
| |
| 194 | case '.', '\0': | |
| 195 | {
| |
| 196 | val += acc << (s*8); | |
| 197 | acc = 0; | |
| 198 | if ((s--) == 0 || ip[i] == '\0') break; | |
| 199 | } | |
| 200 | case '0'..'9': | |
| 201 | {
| |
| 202 | acc = (acc * 10) + (ip[i] - '0'); | |
| 203 | } | |
| 204 | case '*': continue; | |
| 205 | default: printf("WARNING: unknown character #%d in ip address '%s': %c", ip[i], ip, ip[i]);
| |
| 206 | } | |
| 207 | } | |
| 208 | ||
| 209 | return val; | |
| 210 | } | |
| 211 | ||
| 212 | stock DecodeIP(value) | |
| 213 | {
| |
| 214 | new ip[16]; | |
| 215 | format(ip,sizeof(ip),"%i.%i.%i.%i",(value >> 24) & 0x000000FF,(value >> 16) & 0x000000FF,(value >> 8) & 0x000000FF,(value) & 0x000000FF); | |
| 216 | ||
| 217 | return ip; | |
| 218 | } | |
| 219 | ||
| 220 | stock strclr(str[]) | |
| 221 | {
| |
| 222 | for(new i=0; i<strlen(str); i++) | |
| 223 | {
| |
| 224 | if(str[i] == '\n' || str[i] == '\r') | |
| 225 | {
| |
| 226 | strdel(str,i,i+2); | |
| 227 | } | |
| 228 | } | |
| 229 | } | |
| 230 | ||
| 231 | stock strtok(const string[], &index) | |
| 232 | {
| |
| 233 | new length = strlen(string); | |
| 234 | while ((index < length) && (string[index] <= ' ')) index++; | |
| 235 | new offset = index; | |
| 236 | new result[32]; | |
| 237 | while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) | |
| 238 | {
| |
| 239 | result[index - offset] = string[index]; | |
| 240 | index++; | |
| 241 | } | |
| 242 | result[index - offset] = EOS; | |
| 243 | ||
| 244 | return result; | |
| 245 | } | |
| 246 | //------------------------------------------------------------------------------ |