Core/Commands: Add support for ip2nation database lookups when using .pinfo command.

This will (when a full database exists) allow for seeing (approximately) which country a player might be from when doing .pinfo <player>
Note: External data required for this patch to work correctly can be found at http://www.ip2nation.com/ip2nation/Download

Signed-off-by: click <click@gonnamakeyou.com>
This commit is contained in:
Spp
2012-03-23 05:35:32 +01:00
committed by click
parent 479c0976ab
commit 0fe4580fe0
4 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
DROP TABLE IF EXISTS ip2nation;
CREATE TABLE ip2nation (
ip int(11) unsigned NOT NULL default '0',
country char(2) NOT NULL default '',
KEY ip (ip)
);
DROP TABLE IF EXISTS ip2nationCountries;
CREATE TABLE ip2nationCountries (
code varchar(4) NOT NULL default '',
iso_code_2 varchar(2) NOT NULL default '',
iso_code_3 varchar(3) default '',
iso_country varchar(255) NOT NULL default '',
country varchar(255) NOT NULL default '',
lat float NOT NULL default '0',
lon float NOT NULL default '0',
PRIMARY KEY (code),
KEY code (code)
);

View File

@@ -42,6 +42,7 @@
#include "Transport.h"
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
#include "CreatureGroups.h"
#include "ace/INET_Addr.h"
//mute player for some times
bool ChatHandler::HandleMuteCommand(const char* args)
@@ -347,6 +348,20 @@ bool ChatHandler::HandlePInfoCommand(const char* args)
{
last_ip = fields[3].GetString();
last_login = fields[4].GetString();
uint32 ip = inet_addr(last_ip.c_str());
#if TRINITY_ENDIAN == BIGENDIAN
EndianConvertReverse(ip);
#endif
if (QueryResult result2 = WorldDatabase.PQuery("SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE "
"i.ip < %u AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1", ip))
{
Field* fields2 = result2->Fetch();
last_ip.append(" (");
last_ip.append(fields2[0].GetString());
last_ip.append(")");
}
}
else
{

View File

@@ -1625,6 +1625,9 @@ void World::SetInitialWorldSettings()
sLog->outString("Loading Autobroadcasts...");
LoadAutobroadcasts();
sLog->outString("Loading Ip2nation...");
LoadIp2nation();
///- Load and initialize scripts
sObjectMgr->LoadQuestStartScripts(); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate
sObjectMgr->LoadQuestEndScripts(); // must be after load Creature/Gameobject(Template/Data) and QuestTemplate
@@ -1881,6 +1884,23 @@ void World::LoadAutobroadcasts()
sLog->outString();
}
void World::LoadIp2nation()
{
uint32 oldMSTime = getMSTime();
QueryResult result = WorldDatabase.Query("SELECT count(c.code) FROM ip2nationCountries c, ip2nation i WHERE c.code = i.country");
uint32 count = 0;
if (result)
{
Field* fields = result->Fetch();
count = fields[0].GetUInt32();
}
sLog->outString(">> Loaded %u ip2nation definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
/// Update the World !
void World::Update(uint32 diff)
{

View File

@@ -740,6 +740,8 @@ class World
void LoadAutobroadcasts();
void LoadIp2nation();
void UpdateAreaDependentAuras();
void ProcessStartEvent();