K9283RU18934G3894TIK

lookup include

May 18th, 2020
20
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //===[Misc]=====================================================================
  2.  
  3. #include <a_http>
  4.  
  5. #define GetPlayerHost(%1) LookupData[%1][Hostname]
  6. #define GetPlayerISP(%1) LookupData[%1][ISP]
  7. #define GetPlayerCountryCode(%1) LookupData[%1][Code]
  8. #define GetPlayerCountryName(%1) LookupData[%1][Country]
  9. #define GetPlayerCountryRegion(%1) LookupData[%1][Region]
  10. #define IsProxyUser(%1) LookupData[%1][Proxy]
  11.  
  12. enum ldata
  13. {
  14. Hostname[60],
  15. ISP[60],
  16. Code[3],
  17. Country[45],
  18. Region[43],
  19. Proxy
  20. };
  21.  
  22. new
  23. LookupData[MAX_PLAYERS][ldata],
  24. PlayerSession[MAX_PLAYERS],
  25. Retry[MAX_PLAYERS];
  26.  
  27. forward OnLookupResponse(sessionid, response, data[]);
  28. forward OnLookupComplete(playerid);
  29.  
  30. //===[Callbacks]================================================================
  31.  
  32. public OnPlayerConnect(playerid)
  33. {
  34. cleardata(LookupData[playerid][Hostname]);
  35. cleardata(LookupData[playerid][ISP]);
  36. cleardata(LookupData[playerid][Code]);
  37. cleardata(LookupData[playerid][Country]);
  38. cleardata(LookupData[playerid][Region]);
  39. LookupData[playerid][Proxy] = 0;
  40.  
  41. Retry[playerid] = 0;
  42. PlayerSession[playerid] = 0;
  43. LookupPlayerIP(playerid);
  44.  
  45. return CallLocalFunction("Lookup_OnPlayerConnect", "i", playerid);
  46. }
  47.  
  48. public OnLookupResponse(sessionid, response, data[])
  49. {
  50. new xml[5][2],
  51. playerid = GetPlayerFromSession(sessionid);
  52.  
  53. if(playerid == -1) return 1;
  54.  
  55. if(response != 200)
  56. {
  57. if(Retry[playerid] == 0)
  58. {
  59. Retry[playerid] = 1;
  60. LookupPlayerIP(playerid);
  61. }
  62. return 1;
  63. }
  64.  
  65. xml[0][0] = strfind(data, "<host>", true);
  66. xml[0][1] = strfind(data, "</host>", true);
  67. xml[1][0] = strfind(data, "<isp>", true);
  68. xml[1][1] = strfind(data, "</isp>", true);
  69. xml[2][0] = strfind(data, "<code>", true);
  70. xml[2][1] = strfind(data, "</code>", true);
  71. xml[3][0] = strfind(data, "<country>", true);
  72. xml[3][1] = strfind(data, "</country>", true);
  73. xml[4][0] = strfind(data, "<region>", true);
  74. xml[4][1] = strfind(data, "</region>", true);
  75.  
  76. strmidex(LookupData[playerid][Hostname], data, 6 + xml[0][0], xml[0][1], 60);
  77. strmidex(LookupData[playerid][ISP], data, 5 + xml[1][0], xml[1][1], 60);
  78. strmidex(LookupData[playerid][Code], data, 6 + xml[2][0], xml[2][1], 3);
  79. strmidex(LookupData[playerid][Country], data, 9 + xml[3][0], xml[3][1], 40);
  80. strmidex(LookupData[playerid][Region], data, 8 + xml[4][0], xml[4][1], 40);
  81.  
  82. LookupData[playerid][Proxy] = strval(data[strfind(data, "<proxy>", true) + 7]);
  83.  
  84. CallLocalFunction("OnLookupComplete", "i", playerid);
  85.  
  86. return 1;
  87. }
  88.  
  89. //===[Functions]================================================================
  90.  
  91. stock LookupPlayerIP(playerid)
  92. {
  93. if(!IsPlayerNPC(playerid))
  94. {
  95.  
  96. new ip[16], lQuery[60];
  97.  
  98. static
  99. SessionIndex;
  100. SessionIndex++;
  101. PlayerSession[playerid] = SessionIndex;
  102.  
  103. GetPlayerIp(playerid, ip, sizeof(ip));
  104. format(lQuery, sizeof(lQuery), "www.countryffs.com/api.php?ip=%s", ip);
  105.  
  106. HTTP(SessionIndex, HTTP_GET, lQuery, "", "OnLookupResponse");
  107.  
  108. }
  109. }
  110.  
  111. stock GetPlayerFromSession(sessionid)
  112. {
  113. for(new i = 0; i < MAX_PLAYERS; i++)
  114. {
  115. if(IsPlayerConnected(i) && PlayerSession[i] == sessionid)
  116. return i;
  117. }
  118.  
  119. return -1;
  120. }
  121.  
  122. stock DisplayLookupData(playerid, targetid)
  123. {
  124. new lstr[300], boxname[40];
  125.  
  126. GetPlayerIp(targetid, boxname, sizeof(boxname));
  127. format(boxname, sizeof(boxname), "IP Lookup: %s", boxname);
  128.  
  129. format(lstr, sizeof(lstr),
  130. "Hostname: %s\n\
  131. ISP: %s\n\
  132. Country: %s (%s)\n\
  133. State/Region: %s",
  134. LookupData[targetid][Hostname],
  135. LookupData[targetid][ISP],
  136. LookupData[targetid][Country],
  137. LookupData[targetid][Code],
  138. LookupData[targetid][Region]);
  139.  
  140. ShowPlayerDialog(playerid, 30000, DIALOG_STYLE_MSGBOX, boxname, lstr, "Close", "");
  141. }
  142.  
  143. stock strmidex(dest[], const src[], start, end, maxlength=sizeof dest)
  144. {
  145. if(end - start > 1)
  146. strmid(dest, src, start, end, maxlength);
  147. }
  148.  
  149. stock cleardata(src[])
  150. {
  151. src[0] = '?';
  152.  
  153. new c = 1;
  154. while(src[c] != '\0')
  155. {
  156. src[c] = '\0';
  157. c++;
  158. }
  159. }
  160.  
  161. //===[Hooking]==================================================================
  162.  
  163. #if defined _ALS_OnPlayerConnect
  164. #undef OnPlayerConnect
  165. #else
  166. #define _ALS_OnPlayerConnect
  167. #endif
  168.  
  169. #define OnPlayerConnect Lookup_OnPlayerConnect
  170.  
  171. forward Lookup_OnPlayerConnect(playerid);
RAW Paste Data