fixed silly design decisions in geoip that were copied over from amxmodx. natives now return true/false and the buffer is zeroed instead of filled with "ERROR"
3 * ================================================================
4 * SourceMod GeoIP Extension
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #include "extension.h"
38 * @brief Implement extension code here.
40 GeoIP_Extension g_GeoIP;
45 bool GeoIP_Extension::SDK_OnLoad(char *error, size_t maxlength, bool late)
47 char path[PLATFORM_MAX_PATH];
49 g_pSM->BuildPath(Path_SM, path, sizeof(path), "configs/geoip/GeoIP.dat");
50 gi = GeoIP_open(path, GEOIP_MEMORY_CACHE);
54 snprintf(error, maxlength, "Could not load configs/geoip/GeoIP.dat");
58 g_pShareSys->AddNatives(myself, geoip_natives);
59 g_pSM->LogMessage(myself, "GeoIP database info: %s", GeoIP_database_info(gi));
64 void GeoIP_Extension::SDK_OnUnload()
70 /*******************************
72 * GEOIP NATIVE IMPLEMENTATIONS *
74 *******************************/
76 inline void StripPort(char *ip)
78 char *tmp = strchr(ip, ':');
84 static cell_t sm_Geoip_Code2(IPluginContext *pCtx, const cell_t *params)
89 pCtx->LocalToString(params[1], &ip);
92 ccode = GeoIP_country_code_by_addr(gi, ip);
94 pCtx->StringToLocal(params[2], 3, ccode ? ccode : "");
99 static cell_t sm_Geoip_Code3(IPluginContext *pCtx, const cell_t *params)
104 pCtx->LocalToString(params[1], &ip);
107 ccode = GeoIP_country_code3_by_addr(gi, ip);
108 pCtx->StringToLocal(params[2], 4, ccode ? ccode : "");
110 return ccode ? 1 : 0;
113 static cell_t sm_Geoip_Country(IPluginContext *pCtx, const cell_t *params)
118 pCtx->LocalToString(params[1], &ip);
121 ccode = GeoIP_country_name_by_addr(gi, ip);
122 pCtx->StringToLocal(params[2], params[3], (ccode) ? ccode : "");
124 return ccode ? 1 : 0;
127 const sp_nativeinfo_t geoip_natives[] =
129 {"GeoipCode2", sm_Geoip_Code2},
130 {"GeoipCode3", sm_Geoip_Code3},
131 {"GeoipCountry", sm_Geoip_Country},