PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <tinyxml>
#include <SteamWorks>
bool IsClientJoinTeam[MAXPLAYERS+1] = {false,...};
char s_ip[MAXPLAYERS+1][32];
#define VERSION "1.0"
public Plugin myinfo =
{
name = "Easy IP Query",
author = "2389736818",
description = "",
version = "1.0",
url = "www.sourcemod.net"
}
public OnPluginStart()
{
CreateConVar("ipfinder_online", VERSION, "Easy IP Query", FCVAR_NOTIFY|FCVAR_DONTRECORD);
HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);
}
public void OnClientConnected(int client)
{
if(!IsFakeClient(client))
{
IsClientJoinTeam[client] = false;
}
}
public void Event_PlayerTeam(Handle event, char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if(IsClientValid(client) && !IsClientJoinTeam[client])
{
IsClientJoinTeam[client] = true;
CreateTimer(1.0,TimerFindIP,client,TIMER_FLAG_NO_MAPCHANGE);
}
}
public Action TimerFindIP(Handle Timer, any client)
{
if(IsClientValid(client))
{
if(GetClientIP(client, s_ip[client], sizeof(s_ip[])))
{
GetTrackValue(client,s_ip[client]);
}
}
}
public int OnTransferComplete(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, int client)
{
if (!bFailure && bRequestSuccessful && eStatusCode == k_EHTTPStatusCode200OK)
{
SteamWorks_GetHTTPResponseBodyCallback(hRequest, CMD_GetTrack,client);
}
delete(hRequest);
}
public int CMD_GetTrack(int client, int args)
{
char sip[255];
GetTrackValue("ip", sip, sizeof(sip));
char scity[255];
GetTrackValue("city", scity, sizeof(scity));
char sregion[255];
GetTrackValue("region", sregion, sizeof(sregion));
char scountry[255];
GetTrackValue("country", scountry, sizeof(scountry));
char scountry_name[255];
GetTrackValue("country_name", scountry_name, sizeof(scountry_name));
char sorg[255];
GetTrackValue("org", sorg, sizeof(sorg));
PrintToServer(" \x02[Easy IP Query]\x01 Player \x04%N--%s\x01 \x05 Come From: [%s-%s] %s %s ISP: %s",client,s_ip,scountry,scountry_name,sregion,scity,sorg);
}
void GetTrackValue(int client, const char[] tag, char[] sResult, const char[] sip, maxlength)
{
char sRequest[256];
if (sRequest[0] == '\0')
{
FormatEx(sRequest, sizeof(sRequest), "https://ipapi.co/%s/xml",sip);
}
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest);
if (!hRequest || !SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) || !SteamWorks_SetHTTPRequestContextValue(hRequest, client) || !SteamWorks_SendHTTPRequest(hRequest))
{
delete(hRequest);
}
Handle hDoc = TinyXml_CreateDocument();
//TinyXml_LoadFile(hDoc, "https://ipapi.co/%s/xml");
Handle hRoot = TinyXml_RootElement(hDoc); // <tracks>
if(hRoot == INVALID_HANDLE)
{
CloseHandle(hDoc);
return false;
}
bool bResult = false;
// Get the first <track> inside of <tracks>
Handle hTrack = TinyXml_FirstChildElement(hRoot, "track"); // <track>
if(hTrack != INVALID_HANDLE)
{
Handle hEntry = TinyXml_FirstChildElement(hTrack);
// Iterate over all elements of the <track> element.
while(hEntry != INVALID_HANDLE)
{
decl String:sKey[128];
TinyXml_Value(hEntry, sKey, sizeof(sKey));
// if the key matches "tag", return it.
if(StrEqual(sKey, tag))
{
TinyXml_GetText(hEntry, sResult, maxlength);
bResult = true;
break;
}
hEntry = TinyXml_NextSiblingElement(hEntry);
}
CloseHandle(hEntry);
CloseHandle(hTrack);
}
CloseHandle(hRoot);
CloseHandle(hDoc);
return bResult;
}
int String_GetStringFromPosion(const char[] source, int source_size, int pos_start = 0, int pos_end = 0, char[] result, int result_size)
{
int iCount;
for(int i = 0; i < source_size; i++)
{
if(i >= pos_end)
break;
else if(i < (pos_start - 1))
continue;
else
{
char buffer[1];
buffer[0] = source[i];
//TrimString(buffer);
StrCat(result, result_size, buffer);
iCount++;
}
}
return iCount;
}
int String_GetPosion(const char[] source, const int source_size, const char[] search, const int posion_start = 1)
{
if(posion_start == 1)
{
return StrContains(source, search, true);
}
int pos = -1;
int size = source_size - posion_start;
if(size > 0){
char[] buffer = new char[size];
for(int i = 0; i < source_size; i++)
{
if(i > (posion_start - 1))
{
StrCat(buffer, size, source[i]);
}
}
pos = StrContains(buffer, search, true) + posion_start;
}
return pos;
}
stock bool IsClientValid(int client)
{
if(client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client))
{
return true;
}
return false;
}