geo_ip.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. _.-,=_""""--,_
  3. .-" =/7" _ .3#"=.
  4. ,#7 " " ,//)#d#######=. GEO-IP
  5. ,/ " # ,i-/###########= Version 2.1
  6. / _)#sm###=#=# #######\
  7. / (#/"_`;\//#=#\-#######\ FEATURES :
  8. / ,d####-_.._.)##P########\ + Gets Country, States/Provinces
  9. , ,"############\\##bi- `\| Y. and City Info for any IP Address
  10. | .d##############b\##P' V | + Bigger Database (SQLite)
  11. |\ '#################!", | + Faster Operation
  12. |C. \###=############7 | + Uses No Plugins
  13. '###. )#########/ '
  14. \#( \#######| / CREDITS :
  15. \B /#######7 / / Database (CSV) : http://db-ip.com
  16. \ \######" /" / Script By : Abhinav Dabral
  17. `. \###7' ,' (abhinavdabral)
  18. "-_ `"' ,-' ALIAS : Code Wave
  19. "-._ _.-" Facebook : fb.me/codewave
  20. """"---""""
  21. */
  22. stock GetPlayerLocation(playerid, Country[],State[], City[],isotype=0){
  23. new IPAddress[32];
  24. new a,b,c,d,ipf;
  25. new DB:IPDB;
  26. new DBResult:Result;
  27. new Q[256];
  28. GetPlayerIp(playerid,IPAddress,sizeof(IPAddress));
  29. new _parameters[4][8];
  30. new Destination[8];
  31. new SLen=strlen(IPAddress);
  32. new at,pos=0,tp=0;
  33. new tempo[256];
  34. for(new i=0;i<4;i++) format(_parameters[i],sizeof(_parameters),"");
  35. for(at=pos;at<=SLen;at++){
  36. strmid(tempo,IPAddress,at,at+1,sizeof(tempo));
  37. if(!strcmp(tempo,".",true)){
  38. if(tp<=3){
  39. strmid(Destination,IPAddress,pos,at,sizeof(Destination));
  40. format(_parameters[tp][0],256,"%s",Destination);
  41. tp=tp+1;
  42. }
  43. pos=at+1;
  44. }
  45. }
  46. a=strval(_parameters[0]);
  47. b=strval(_parameters[1]);
  48. c=strval(_parameters[2]);
  49. d=strval(_parameters[3]);
  50. if(a==127 && b==0 && c==0 && d==1){
  51. format(Country,256,"Localhost");
  52. return 0;
  53. }
  54. ipf = (16777216*a) + (65536*b) + (256*c) + d;
  55. IPDB=db_open("IPList.db");
  56. format(Q,sizeof(Q),"SELECT * FROM 'IPTable' WHERE start<=%d AND end>=%d",ipf,ipf);
  57. if(isotype==1) format(Q,sizeof(Q),"SELECT IPTable.start,IPTable.end,isoshort.alpha_three,IPTable.state,IPTable.city FROM 'IPTable','isoshort' WHERE IPTable.start<=%d AND IPTable.end>=%d AND IPTable.country==isoshort.alpha_two",ipf,ipf);
  58. else if(isotype==2) format(Q,sizeof(Q),"SELECT IPTable.start,IPTable.end,isofull.fullname,IPTable.state,IPTable.city FROM 'IPTable','isofull' WHERE IPTable.start<=%d AND IPTable.end>=%d AND IPTable.country==isofull.alpha_two",ipf,ipf);
  59. Result=db_query(IPDB, Q);
  60. if(db_num_rows(Result) == 1)
  61. {
  62. db_get_field(Result,2,Country,256);
  63. db_get_field(Result,3,State,256);
  64. db_get_field(Result,4,City,256);
  65. }
  66. db_free_result(Result);
  67. db_close(IPDB);
  68. return 1;
  69. }
  70. stock GetPlayerCountry(playerid,isotype=2){
  71. new Country[256], State[256], City[256];
  72. GetPlayerLocation(playerid,Country,State,City,isotype);
  73. return Country;
  74. }
  75. stock GetPlayerProvince(playerid){
  76. new Country[256], State[256], City[256];
  77. GetPlayerLocation(playerid,Country,State,City);
  78. return State;
  79. }
  80. stock GetPlayerCity(playerid){
  81. new Country[256], State[256], City[256];
  82. GetPlayerLocation(playerid,Country,State,City);
  83. return City;
  84. }