Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- IP to Country von Tobias Hübner steht unter
- einer Creative Commons Namensnennung-Nicht-kommerziell-Weitergabe
- unter gleichen Bedingungen 3.0 Unported Lizenz.
- http://creativecommons.org/licenses/by-nc-sa/3.0/
- http://www.multi-rl.de/
- */
- #include <a_samp>
- #include <a_http>
- forward HttpResponse(index, response_code, data[]);
- forward split(const strsrc[], strdest[][], delimiter);
- public OnFilterScriptInit( )
- {
- printf( "IP to Country von Atrox geladen" );
- }
- public OnFilterScriptExit( )
- {
- printf( "IP to Country von Atrox unloaded." );
- }
- public OnPlayerConnect(playerid)
- {
- if(IsPlayerNPC(playerid)) return 1;// No NPCs
- new IPAdress[16], URL[50];
- GetPlayerIp(playerid, IPAdress, sizeof(IPAdress));
- format(URL, sizeof(URL), "multi-rl.de/ip.php?ip=%s", IPAdress);
- HTTP(playerid, HTTP_GET, URL, "", "HttpResponse" );
- return 1;
- }
- public HttpResponse(index, response_code, data[])
- {
- if(response_code != 200)
- return printf("Atrox IP to Country: Fehler beim Verbinden! Errorcode: %d", response_code);
- new data2[60], CountryName[50], CountryCode[5], array[2][50];
- format(data2, sizeof(data2), "%s", data);
- split(data2, array, ',');
- format(CountryCode, sizeof(CountryCode), "%s", array[0]);
- format(CountryName, sizeof(CountryName), "%s", array[1]);
- //Do something, for example:
- if(strcmp(CountryCode, "DE") && strcmp(CountryCode, "AT") && strcmp(CountryCode, "CH") && /*IP like 'localhost'*/strcmp(CountryCode, "RD"))
- {
- SendClientMessage(index, 0xFFFFFFFF, "Wir erlauben nur deutsche Verbindungen!");
- Kick(index);
- }
- return 1;
- }
- public split(const strsrc[], strdest[][], delimiter)
- {
- new i, li;
- new aNum;
- new len;
- while(i <= strlen(strsrc))
- {
- if(strsrc[i]==delimiter || i==strlen(strsrc))
- {
- len = strmid(strdest[aNum], strsrc, li, i, 128);
- strdest[aNum][len] = 0;
- li = i+1;
- aNum++;
- }
- i++;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement