Move versioning to a static library to improve trivial build speed (
bug 5997 part 9, r=ds).
3 * =============================================================================
4 * SourceMod GeoIP Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include <sourcemod_version.h>
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_pShareSys->RegisterLibrary(myself, "GeoIP");
60 g_pSM->LogMessage(myself, "GeoIP database info: %s", GeoIP_database_info(gi));
65 void GeoIP_Extension::SDK_OnUnload()
71 const char *GeoIP_Extension::GetExtensionVerString()
73 return SOURCEMOD_VERSION;
76 const char *GeoIP_Extension::GetExtensionDateString()
78 return SOURCEMOD_BUILD_TIME;
81 /*******************************
83 * GEOIP NATIVE IMPLEMENTATIONS *
85 *******************************/
87 inline void StripPort(char *ip)
89 char *tmp = strchr(ip, ':');
95 static cell_t sm_Geoip_Code2(IPluginContext *pCtx, const cell_t *params)
100 pCtx->LocalToString(params[1], &ip);
103 ccode = GeoIP_country_code_by_addr(gi, ip);
105 pCtx->StringToLocal(params[2], 3, ccode ? ccode : "");
107 return ccode ? 1 : 0;
110 static cell_t sm_Geoip_Code3(IPluginContext *pCtx, const cell_t *params)
115 pCtx->LocalToString(params[1], &ip);
118 ccode = GeoIP_country_code3_by_addr(gi, ip);
119 pCtx->StringToLocal(params[2], 4, ccode ? ccode : "");
121 return ccode ? 1 : 0;
124 static cell_t sm_Geoip_Country(IPluginContext *pCtx, const cell_t *params)
129 pCtx->LocalToString(params[1], &ip);
132 ccode = GeoIP_country_name_by_addr(gi, ip);
133 pCtx->StringToLocal(params[2], params[3], (ccode) ? ccode : "");
135 return ccode ? 1 : 0;
138 const sp_nativeinfo_t geoip_natives[] =
140 {"GeoipCode2", sm_Geoip_Code2},
141 {"GeoipCode3", sm_Geoip_Code3},
142 {"GeoipCountry", sm_Geoip_Country},