Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==============================================================================
- ** SA-MP (0.3.7) GeoIP v1.0
- ** By: DragonZafiro/NeloAngelo
- ** Created: 17/04/16
- ==============================================================================*/
- #include <a_samp>
- #include <a_http>
- #define APIKEY "api"
- //#define ALWAYS_RESPONSE
- public OnPlayerConnect(playerid)
- {
- new IP[30], str[300], pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, sizeof(pName));
- GetPlayerIp(playerid, IP, sizeof(IP));
- if(!strcmp(IP, "127.0.0.1"))
- {
- format(str, 230, "%s {FAFAFA}Has joined the server. {1FC7FF}Country: {FAFAFA}localhost", pName);
- SendClientMessageToAll(GetPlayerColor(playerid), str);
- }
- else
- {
- format(str, sizeof(str),"api.ipinfodb.com/v3/ip-country/?key="APIKEY"&ip=%s", IP);
- HTTP(playerid, HTTP_GET, str, "", "GetPlayerCountry");
- }
- return 1;
- }
- forward GetPlayerCountry(index, response_code, data[]);
- public GetPlayerCountry(index, response_code, data[])
- {
- new buffer[358];
- if(response_code == 200)
- {
- new str[230], city[3], country[20], pName[MAX_PLAYER_NAME];
- GetPlayerName(index, pName, sizeof(pName));
- format(buffer, sizeof(buffer), "%s", data);
- strmid(str, buffer, 4, strlen(buffer)); // Cutting the 'OK' response...
- strmid(city, str, strfind(str, ";", true) + 1, strfind(str, ";", true) + 3); // Getting City
- strmid(country, str, strfind(str, ";", true) + 4, strlen(buffer)); // Getting Country
- //printf("city: %s, country: %s", city, country);
- format(str, 230, "%s {FAFAFA}Has joined the server. {1FC7FF}Country: {FAFAFA}%s %s", pName, country, city);
- SendClientMessageToAll(GetPlayerColor(index), str);
- }
- else
- {
- new str[300], pName[MAX_PLAYER_NAME];
- GetPlayerName(index, pName, sizeof(pName));
- #if defined ALWAYS_RESPONSE
- new IP[30];
- GetPlayerIp(index, IP, sizeof(IP));
- format(str, sizeof(str),"api.ipinfodb.com/v3/ip-country/?key="APIKEY"&ip=%s", IP);
- HTTP(index, HTTP_GET, str, "", "GetPlayerCountry");
- #else // Normal message, without country
- format(str, 120, "%s {FAFAFA}Has joined the server.", pName);
- SendClientMessageToAll(GetPlayerColor(index), str);
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement