Changeset 5448

Show
Ignore:
Timestamp:
26/06/2009 01:23:36 (9 months ago)
Author:
NiLuJe
Message:

AMX Mod X:

  • Resync GeoIPEx.
Location:
Mirrors/AMXModX/dlls/geoip_ex
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • Mirrors/AMXModX/dlls/geoip_ex/GeoIP.c

    r5443 r5448  
    251251} 
    252252 
    253 /* 
    254 static 
     253/* static 
    255254int _file_exists(const char *file_name) { 
    256255        struct stat file_stat; 
    257256        return( (stat(file_name, &file_stat) == 0) ? 1:0); 
    258 } 
    259  
    260 int GeoIP_db_avail(int type) { 
     257} */ 
     258 
     259/* int GeoIP_db_avail(int type) { 
    261260        const char * filePath; 
    262261        if (type < 0 || type >= NUM_DB_TYPES) { 
     
    269268        } 
    270269        return _file_exists(filePath); 
    271 } 
    272 */ 
     270}*/ 
    273271 
    274272static 
  • Mirrors/AMXModX/dlls/geoip_ex/Makefile

    r5444 r5448  
    1010DEBUG_FLAGS = -g -ggdb3 
    1111CPP = gcc-4.1 
    12 NAME = geoipex 
     12NAME = geoip 
    1313 
    1414BIN_SUFFIX_32 = amxx_i386.so 
    1515BIN_SUFFIX_64 = amxx_amd64.so 
    1616 
    17 OBJECTS = sdk/amxxmodule.cpp GeoIP.c GeoIPCity.c regionName.c timeZone.c geoip_amxx.cpp 
     17OBJECTS = sdk/amxxmodule.cpp GeoIP.c geoip_amxx.cpp 
    1818 
    19 LINK = 
     19LINK =  
    2020 
    2121INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \ 
     
    6262        mkdir -p $(BIN_DIR) 
    6363        mkdir -p $(BIN_DIR)/sdk 
    64         $(MAKE) geoipex 
     64        $(MAKE) geoip 
    6565 
    6666amd64: 
    6767        $(MAKE) all AMD64=true 
    6868 
    69 geoipex: $(OBJ_LINUX) 
     69geoip: $(OBJ_LINUX) 
    7070        $(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) 
    7171 
  • Mirrors/AMXModX/dlls/geoip_ex/geoip_amxx.cpp

    r5443 r5448  
    1717} 
    1818 
    19 /* Deprecated */ 
     19/* Depreceted */ 
    2020static cell AMX_NATIVE_CALL amx_geoip_code2(AMX *amx, cell *params) 
    2121{ 
     
    2929} 
    3030 
    31 /* Deprecated */ 
     31/* Depreceted */ 
    3232static cell AMX_NATIVE_CALL amx_geoip_code3( AMX *amx, cell *params ) 
    3333{ 
     
    130130static cell AMX_NATIVE_CALL amx_geoip_city( AMX *amx, cell *params ) 
    131131{ 
    132         int len = 0; 
    133         char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
    134  
    135         StripPort( ip ); 
    136         GeoIPRecord* rec = GeoIP_record_by_addr( gi, ip ); 
    137          
    138         if ( rec  ) 
    139         { 
    140                 cell res = MF_SetAmxString( amx, params[2], rec->city ? rec->city : "error", params[3] ); 
    141                 free( rec ); 
    142                 return res; 
     132        if ( !db_default ) 
     133        { 
     134                int len = 0; 
     135                char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
     136 
     137                StripPort( ip ); 
     138                GeoIPRecord* rec = GeoIP_record_by_addr( gi, ip ); 
     139                 
     140                if ( rec  ) 
     141                { 
     142                        cell res = MF_SetAmxString( amx, params[2], rec->city ? rec->city : "error", params[3] ); 
     143                        free( rec ); 
     144                        return res; 
     145                } 
    143146        } 
    144147         
     
    148151static cell AMX_NATIVE_CALL amx_geoip_latitude( AMX *amx, cell *params ) 
    149152{ 
    150         int len = 0; 
    151         char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
    152  
    153         StripPort( ip ); 
    154         GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
    155          
    156         return ( rec ) ? amx_ftoc( rec->latitude ) : 0; 
     153        if ( !db_default ) 
     154        { 
     155                int len = 0; 
     156                char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
     157 
     158                StripPort( ip ); 
     159                GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
     160 
     161                return ( rec ) ? amx_ftoc( rec->latitude ) : 0; 
     162        } 
     163         
     164        return 0; 
    157165} 
    158166 
    159167static cell AMX_NATIVE_CALL amx_geoip_longitude( AMX *amx, cell *params ) 
    160168{ 
    161         int len = 0; 
    162         char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
    163  
    164         StripPort( ip ); 
    165         GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
    166          
    167         return ( rec ) ? amx_ftoc( rec->longitude ) : 0; 
     169        if ( !db_default ) 
     170        { 
     171                int len = 0; 
     172                char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
     173 
     174                StripPort( ip ); 
     175                GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
     176 
     177                return ( rec ) ? amx_ftoc( rec->longitude ) : 0; 
     178        } 
     179         
     180        return 0; 
    168181} 
    169182 
    170183static cell AMX_NATIVE_CALL amx_geoip_region( AMX *amx, cell *params ) 
    171184{ 
    172         int len = 0; 
    173         char *ip = MF_GetAmxString(amx, params[1], 0, &len); 
    174  
    175         StripPort( ip ); 
    176         GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
    177  
    178         if ( rec ) 
    179         { 
    180                 MF_SetAmxString( amx, params[2], rec->region, 2 ); 
    181                 return 1; 
     185        if ( !db_default ) 
     186        { 
     187                int len = 0; 
     188                char *ip = MF_GetAmxString(amx, params[1], 0, &len); 
     189 
     190                StripPort( ip ); 
     191                GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
     192 
     193                if ( rec ) 
     194                { 
     195                        MF_SetAmxString( amx, params[2], rec->region, 2 ); 
     196                        return 1; 
     197                } 
    182198        } 
    183199         
     
    187203static cell AMX_NATIVE_CALL amx_geoip_region_name( AMX *amx, cell *params ) 
    188204{ 
    189         int len = 0; 
    190         char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
    191  
    192         StripPort( ip ); 
    193         GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
    194          
    195         if ( rec ) 
    196         { 
    197                 const char *region = GeoIP_region_name_by_code( rec->country_code, rec->region ); 
    198                 return MF_SetAmxString( amx, params[2], region, params[3] ); 
     205        if ( !db_default ) 
     206        { 
     207                int len = 0; 
     208                char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
     209 
     210                StripPort( ip ); 
     211                GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
     212                 
     213                if ( rec ) 
     214                { 
     215                        const char *region = GeoIP_region_name_by_code( rec->country_code, rec->region ); 
     216                        return MF_SetAmxString( amx, params[2], region, params[3] ); 
     217                } 
    199218        } 
    200219 
     
    204223static cell AMX_NATIVE_CALL amx_geoip_timezone( AMX *amx, cell *params ) 
    205224{ 
    206         int len = 0; 
    207         char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
    208  
    209         StripPort( ip ); 
    210         GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
    211  
    212         if ( rec ) 
    213         { 
    214                 const char *timezone = GeoIP_time_zone_by_country_and_region( rec->country_code, rec->region ); 
    215                 return MF_SetAmxString( amx, params[2], timezone, params[3] ); 
     225        if ( !db_default ) 
     226        { 
     227                int len = 0; 
     228                char *ip = MF_GetAmxString( amx, params[1], 0, &len ); 
     229 
     230                StripPort( ip ); 
     231                GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
     232 
     233                if ( rec ) 
     234                { 
     235                        const char *timezone = GeoIP_time_zone_by_country_and_region( rec->country_code, rec->region ); 
     236                        return MF_SetAmxString( amx, params[2], timezone, params[3] ); 
     237                } 
    216238        } 
    217239 
     
    221243static cell AMX_NATIVE_CALL amx_geoip_continent_code( AMX *amx, cell *params ) 
    222244{ 
    223         int len = 0; 
    224         char *ip = MF_GetAmxString(amx, params[1], 0, &len); 
    225  
    226         StripPort( ip ); 
    227         GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
    228  
    229         if ( rec ) 
    230         { 
    231                 MF_SetAmxString( amx, params[2], rec->continent_code, 2 ); 
    232                 return 1; 
    233         } 
    234          
    235         return 0; 
     245        if ( !db_default ) 
     246        { 
     247                int len = 0; 
     248                char *ip = MF_GetAmxString(amx, params[1], 0, &len); 
     249 
     250                StripPort( ip ); 
     251                GeoIPRecord *rec = GeoIP_record_by_addr( gi, ip ); 
     252 
     253                if ( rec ) 
     254                { 
     255                        MF_SetAmxString( amx, params[2], rec->continent_code, 2 ); 
     256                        return 1; 
     257                } 
     258        } 
     259 
     260        return 0; 
     261} 
     262 
     263static cell AMX_NATIVE_CALL amx_geoip_distance( AMX *amx, cell *params ) 
     264{ 
     265        REAL RAD_CONVERT  =     (REAL)M_PI / 180; 
     266        REAL EARTH_RADIUS =     (REAL)6378.2; 
     267 
     268        REAL lat1 = amx_ctof( params[1] ) * RAD_CONVERT; 
     269        REAL lon1 = amx_ctof( params[2] ) * RAD_CONVERT; 
     270        REAL lat2 = amx_ctof( params[3] ) * RAD_CONVERT; 
     271        REAL lon2 = amx_ctof( params[4] ) * RAD_CONVERT; 
     272 
     273        return amx_ftoc( EARTH_RADIUS * acos( sin( lat1 ) * sin( lat2 ) + cos( lat1 ) * cos( lat2 ) * cos( lon2 - lon1 ) ) ); 
    236274} 
    237275 
     
    297335        { "geoip_continent_code", amx_geoip_continent_code }, 
    298336 
     337        { "geoip_distance"              , amx_geoip_distance     }, 
    299338        { NULL                                  , NULL                                   }, 
    300339}; 
  • Mirrors/AMXModX/dlls/geoip_ex/geoip_amxx.h

    r5442 r5448  
    44#define GEOIPDATADIR "" 
    55 
     6#define M_PI                    3.14159265358979323846 
     7 
     8 
     9#include <math.h> 
    610#include "amxxmodule.h" 
    711#include "GeoIP.h" 
  • Mirrors/AMXModX/dlls/geoip_ex/include/geoip_ex.inc

    r5442 r5448  
    140140 * 
    141141 * @param ip            The IP address to lookup. 
    142  * @param result        The result of the geoip lookup. 
     142 * @return                      true on a successful lookup, false on a failed lookup. 
    143143 */ 
    144 native geoip_continent_code( const ip[], result[3] ); 
     144native bool:geoip_continent_code( const ip[], result[3] ); 
     145 
     146/** 
     147 * Calculate the distance between geographical coordinates, latitude and longitude. 
     148 * 
     149 * @param lat1          The first IP latitude. 
     150 * @param lon1          The first IP longitude. 
     151 * @param lat2          The second IP latitude. 
     152 * @param lon2          The second IP longitude. 
     153 * @param result        The distance as result in kilometer. 
     154 */ 
     155native Float:geoip_distance( Float:lat1, Float:lon1, Float:lat2, Float:lon2 ); 
  • Mirrors/AMXModX/dlls/geoip_ex/msvc8/geoip.vcproj

    r5441 r5448  
    201201                                > 
    202202                        </File> 
    203                         <File 
    204                                 RelativePath="..\svn_version.h" 
    205                                 > 
    206                         </File> 
    207203                </Filter> 
    208204                <Filter 
     
    258254                        > 
    259255                        <File 
    260                                 RelativePath="..\..\..\plugins\include\geoip.inc" 
     256                                RelativePath="..\geoip.inc" 
    261257                                > 
    262258                        </File> 
  • Mirrors/AMXModX/dlls/geoip_ex/sdk/amxxmodule.cpp

    r5442 r5448  
    27072707        va_start(arglst, fmt); 
    27082708        vsnprintf(msg, sizeof(msg) - 1, fmt, arglst); 
     2709        // vsnprintf_s(msg, sizeof(msg), _TRUNCATE, fmt, arglst); 
    27092710        va_end(arglst); 
    27102711 
     
    27182719        va_start(arglst, fmt); 
    27192720        vsnprintf(msg, sizeof(msg) - 1, fmt, arglst); 
     2721        // vsnprintf_s(msg, sizeof(msg), _TRUNCATE, fmt, arglst); 
    27202722        va_end(arglst); 
    27212723 
  • Mirrors/AMXModX/dlls/geoip_ex/sdk/amxxmodule.h

    r5442 r5448  
    287287                         * functions above are deprecated. */ 
    288288                        #pragma warning (disable:4996) 
    289                                  
     289 
    290290                #endif 
    291291        #else