From 9aebfaf722127fa6477782aeac7534c48ba0bffb Mon Sep 17 00:00:00 2001 From: kandera Date: Wed, 3 Apr 2013 03:37:56 -0400 Subject: DB/Commands: fix the use of gobject info when used with a game object entry --- src/server/scripts/Commands/cs_gobject.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/server/scripts/Commands') diff --git a/src/server/scripts/Commands/cs_gobject.cpp b/src/server/scripts/Commands/cs_gobject.cpp index f99e51fb260..12fd4250eb8 100644 --- a/src/server/scripts/Commands/cs_gobject.cpp +++ b/src/server/scripts/Commands/cs_gobject.cpp @@ -592,7 +592,8 @@ public: entry = object->GetEntry(); else entry = atoi((char*)args); - } + } else + entry = atoi((char*)args); GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry); -- cgit v1.2.3 From 678cade1163080263bdea9e349fbb67b7af15ea7 Mon Sep 17 00:00:00 2001 From: xjose93 Date: Tue, 16 Apr 2013 17:08:58 +0200 Subject: Core/Commands: rename guilds (.guild rename "old guildname" "new guildname") --- sql/updates/world/2013_04_16_01_world_misc.sql | 10 +++++ src/server/game/Guilds/Guild.cpp | 13 ++++++ src/server/game/Guilds/Guild.h | 2 + src/server/game/Miscellaneous/Language.h | 4 +- src/server/scripts/Commands/cs_guild.cpp | 50 ++++++++++++++++++++++ .../Database/Implementation/CharacterDatabase.cpp | 2 + .../Database/Implementation/CharacterDatabase.h | 1 + 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 sql/updates/world/2013_04_16_01_world_misc.sql (limited to 'src/server/scripts/Commands') diff --git a/sql/updates/world/2013_04_16_01_world_misc.sql b/sql/updates/world/2013_04_16_01_world_misc.sql new file mode 100644 index 00000000000..4c7561a0e69 --- /dev/null +++ b/sql/updates/world/2013_04_16_01_world_misc.sql @@ -0,0 +1,10 @@ +DELETE FROM `command` WHERE `name` = 'guild rename'; +INSERT INTO `command` (`name`, `security`, `help`) VALUES +('guild rename', 3, 'Syntax: .guild rename "$GuildName" "$NewGuildName" \n\n Rename a guild named $GuildName with $NewGuildName. Guild name and new guild name must in quotes.'); + +SET @ENTRY1 := 96; +SET @ENTRY2 := 97; +DELETE FROM `trinity_string` WHERE `entry` IN (@ENTRY1, @ENTRY2); +INSERT INTO `trinity_string` (`entry`, `content_default`) VALUES +(@ENTRY1, 'The guild name \'%s\' is already taken'), +(@ENTRY2, 'Changed guild name \'%s\' to \'%s\''); diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp index 158a20d67d1..2ec9130f263 100644 --- a/src/server/game/Guilds/Guild.cpp +++ b/src/server/game/Guilds/Guild.cpp @@ -1285,6 +1285,19 @@ void Guild::OnPlayerStatusChange(Player* player, uint32 flag, bool state) } } +bool Guild::SetName(std::string const& name) +{ + if (m_name == name || name.empty() || name.length() > 24 || sObjectMgr->IsReservedName(name) || !ObjectMgr::IsValidCharterName(name)) + return false; + + m_name = name; + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GUILD_NAME); + stmt->setString(0, m_name); + stmt->setUInt32(1, GetId()); + CharacterDatabase.Execute(stmt); + return true; +} + void Guild::HandleRoster(WorldSession* session /*= NULL*/) { // Guess size diff --git a/src/server/game/Guilds/Guild.h b/src/server/game/Guilds/Guild.h index 6af397f6fed..f6a3e095957 100644 --- a/src/server/game/Guilds/Guild.h +++ b/src/server/game/Guilds/Guild.h @@ -657,6 +657,8 @@ public: std::string const& GetMOTD() const { return m_motd; } std::string const& GetInfo() const { return m_info; } + bool SetName(std::string const& name); + // Handle client commands void HandleRoster(WorldSession* session = NULL); // NULL = broadcast void HandleQuery(WorldSession* session); diff --git a/src/server/game/Miscellaneous/Language.h b/src/server/game/Miscellaneous/Language.h index f4379e59f19..e03adf2a4a1 100644 --- a/src/server/game/Miscellaneous/Language.h +++ b/src/server/game/Miscellaneous/Language.h @@ -119,7 +119,9 @@ enum TrinityStrings LANG_RBAC_LIST_GROUPS_HEADER = 93, LANG_RBAC_LIST_ROLES_HEADER = 94, LANG_RBAC_LIST_PERMISSIONS_HEADER = 95, - // Room for more level 0 96-99 not used + LANG_GUILD_RENAME_ALREADY_EXISTS = 96, + LANG_GUILD_RENAME_DONE = 97, + // Room for more level 0 98-99 not used // level 1 chat LANG_GLOBAL_NOTIFY = 100, diff --git a/src/server/scripts/Commands/cs_guild.cpp b/src/server/scripts/Commands/cs_guild.cpp index afe792048f6..9d2214c82e9 100644 --- a/src/server/scripts/Commands/cs_guild.cpp +++ b/src/server/scripts/Commands/cs_guild.cpp @@ -43,6 +43,7 @@ public: { "invite", SEC_GAMEMASTER, true, &HandleGuildInviteCommand, "", NULL }, { "uninvite", SEC_GAMEMASTER, true, &HandleGuildUninviteCommand, "", NULL }, { "rank", SEC_GAMEMASTER, true, &HandleGuildRankCommand, "", NULL }, + { "rename", SEC_GAMEMASTER, true, &HandleGuildRenameCommand, "", NULL }, { NULL, 0, false, NULL, "", NULL } }; static ChatCommand commandTable[] = @@ -192,6 +193,55 @@ public: uint8 newRank = uint8(atoi(rankStr)); return targetGuild->ChangeMemberRank(targetGuid, newRank); } + + static bool HandleGuildRenameCommand(ChatHandler* handler, char const* _args) + { + if (!*_args) + return false; + + char *args = (char *)_args; + + char const* oldGuildStr = handler->extractQuotedArg(args); + if (!oldGuildStr) + { + handler->SendSysMessage(LANG_BAD_VALUE); + handler->SetSentErrorMessage(true); + return false; + } + + char const* newGuildStr = handler->extractQuotedArg(strtok(NULL, "")); + if (!newGuildStr) + { + handler->SendSysMessage(LANG_INSERT_GUILD_NAME); + handler->SetSentErrorMessage(true); + return false; + } + + Guild* guild = sGuildMgr->GetGuildByName(oldGuildStr); + if (!guild) + { + handler->PSendSysMessage(LANG_COMMAND_COULDNOTFIND, oldGuildStr); + handler->SetSentErrorMessage(true); + return false; + } + + if (sGuildMgr->GetGuildByName(newGuildStr)) + { + handler->PSendSysMessage(LANG_GUILD_RENAME_ALREADY_EXISTS, newGuildStr); + handler->SetSentErrorMessage(true); + return false; + } + + if (!guild->SetName(newGuildStr)) + { + handler->SendSysMessage(LANG_BAD_VALUE); + handler->SetSentErrorMessage(true); + return false; + } + + handler->PSendSysMessage(LANG_GUILD_RENAME_DONE, oldGuildStr, newGuildStr); + return true; + } }; void AddSC_guild_commandscript() diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index 2b57693db9b..f834ead6a5b 100644 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -171,6 +171,8 @@ void CharacterDatabaseConnection::DoPrepareStatements() // 0: uint32, 1: string, 2: uint32, 3: string, 4: string, 5: uint64, 6-10: uint32, 11: uint64 PrepareStatement(CHAR_INS_GUILD, "INSERT INTO guild (guildid, name, leaderguid, info, motd, createdate, EmblemStyle, EmblemColor, BorderStyle, BorderColor, BackgroundColor, BankMoney) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_GUILD, "DELETE FROM guild WHERE guildid = ?", CONNECTION_ASYNC); // 0: uint32 + // 0: string, 1: uint32 + PrepareStatement(CHAR_UPD_GUILD_NAME, "UPDATE guild SET name = ? WHERE guildid = ?", CONNECTION_ASYNC); // 0: uint32, 1: uint32, 2: uint8, 4: string, 5: string PrepareStatement(CHAR_INS_GUILD_MEMBER, "INSERT INTO guild_member (guildid, guid, rank, pnote, offnote) VALUES (?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_GUILD_MEMBER, "DELETE FROM guild_member WHERE guid = ?", CONNECTION_ASYNC); // 0: uint32 diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index 3eb6a726007..65878b4c577 100644 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -166,6 +166,7 @@ enum CharacterDatabaseStatements CHAR_INS_GUILD, CHAR_DEL_GUILD, + CHAR_UPD_GUILD_NAME, CHAR_INS_GUILD_MEMBER, CHAR_DEL_GUILD_MEMBER, CHAR_DEL_GUILD_MEMBERS, -- cgit v1.2.3 From 7542049eba46205572b9c9498d6891df31d0ca5b Mon Sep 17 00:00:00 2001 From: Bezo Date: Mon, 15 Apr 2013 14:56:00 +0300 Subject: [Ip2nationLock] Implement the ip2nation lock country. --- sql/base/auth_database.sql | 1 + sql/updates/auth/2013_04_22_00_auth_misc.sql | 21 ++++++++ sql/updates/world/2013_04_22_00_world_misc.sql | 7 +++ src/server/authserver/Server/AuthSocket.cpp | 40 ++++++++++++--- src/server/scripts/Commands/cs_account.cpp | 60 +++++++++++++++++++++- src/server/scripts/Commands/cs_misc.cpp | 2 +- .../Database/Implementation/LoginDatabase.cpp | 5 +- .../shared/Database/Implementation/LoginDatabase.h | 3 ++ .../Database/Implementation/WorldDatabase.cpp | 1 - .../shared/Database/Implementation/WorldDatabase.h | 1 - 10 files changed, 129 insertions(+), 12 deletions(-) create mode 100644 sql/updates/auth/2013_04_22_00_auth_misc.sql create mode 100644 sql/updates/world/2013_04_22_00_world_misc.sql (limited to 'src/server/scripts/Commands') diff --git a/sql/base/auth_database.sql b/sql/base/auth_database.sql index c3752e980dd..943be73b20f 100644 --- a/sql/base/auth_database.sql +++ b/sql/base/auth_database.sql @@ -34,6 +34,7 @@ CREATE TABLE `account` ( `last_ip` varchar(15) NOT NULL DEFAULT '127.0.0.1', `failed_logins` int(10) unsigned NOT NULL DEFAULT '0', `locked` tinyint(3) unsigned NOT NULL DEFAULT '0', + `lock_country` varchar(2) NOT NULL DEFAULT '00', `last_login` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `online` tinyint(3) unsigned NOT NULL DEFAULT '0', `expansion` tinyint(3) unsigned NOT NULL DEFAULT '2', diff --git a/sql/updates/auth/2013_04_22_00_auth_misc.sql b/sql/updates/auth/2013_04_22_00_auth_misc.sql new file mode 100644 index 00000000000..508c0aab944 --- /dev/null +++ b/sql/updates/auth/2013_04_22_00_auth_misc.sql @@ -0,0 +1,21 @@ +ALTER TABLE `account` ADD COLUMN `lock_country` VARCHAR(2) NOT NULL DEFAULT '00' AFTER `locked`; + +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) +); diff --git a/sql/updates/world/2013_04_22_00_world_misc.sql b/sql/updates/world/2013_04_22_00_world_misc.sql new file mode 100644 index 00000000000..99eee20ffef --- /dev/null +++ b/sql/updates/world/2013_04_22_00_world_misc.sql @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS ip2nation; +DROP TABLE IF EXISTS ip2nationCountries; + +DELETE FROM `command` WHERE `name` in ('account lock', 'account lock ip', 'account lock country'); +INSERT INTO `command` (`name`,`security`,`help`) VALUES +('account lock ip', 0, 'Syntax: .account lock ip [on|off]\nAllow login from account only from current used IP or remove this requirement.'), +('account lock country', 0, 'Syntax: .account lock country [on|off]\nAllow login from account only from current used Country or remove this requirement.'); diff --git a/src/server/authserver/Server/AuthSocket.cpp b/src/server/authserver/Server/AuthSocket.cpp index 32ddf029f1c..a080a038314 100644 --- a/src/server/authserver/Server/AuthSocket.cpp +++ b/src/server/authserver/Server/AuthSocket.cpp @@ -386,17 +386,45 @@ bool AuthSocket::_HandleLogonChallenge() sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Account '%s' is locked to IP - '%s'", _login.c_str(), fields[3].GetCString()); sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Player address is '%s'", ip_address.c_str()); - if (strcmp(fields[3].GetCString(), ip_address.c_str())) + if (strcmp(fields[4].GetCString(), ip_address.c_str())) { sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Account IP differs"); - pkt << (uint8) WOW_FAIL_SUSPENDED; + pkt << uint8(WOW_FAIL_LOCKED_ENFORCED); locked = true; } else sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Account IP matches"); } else + { sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Account '%s' is not locked to ip", _login.c_str()); + std::string accountCountry = fields[3].GetString(); + if (accountCountry.empty() || accountCountry == "00") + sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Account '%s' is not locked to country", _login.c_str()); + else if (!accountCountry.empty()) + { + uint32 ip = inet_addr(ip_address.c_str()); + EndianConvertReverse(ip); + + stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_LOGON_COUNTRY); + stmt->setUInt32(0, ip); + if (PreparedQueryResult sessionCountryQuery = LoginDatabase.Query(stmt)) + { + std::string loginCountry = (*sessionCountryQuery)[0].GetString(); + sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Account '%s' is locked to country: '%s' Player country is '%s'", _login.c_str(), accountCountry.c_str(), loginCountry.c_str()); + if (loginCountry != accountCountry) + { + sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Account country differs."); + pkt << uint8(WOW_FAIL_UNLOCKABLE_LOCK); + locked = true; + } + else + sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] Account country matches"); + } + else + sLog->outDebug(LOG_FILTER_AUTHSERVER, "[AuthChallenge] IP2NATION Table empty"); + } + } if (!locked) { @@ -426,8 +454,8 @@ bool AuthSocket::_HandleLogonChallenge() std::string rI = fields[0].GetString(); // Don't calculate (v, s) if there are already some in the database - std::string databaseV = fields[5].GetString(); - std::string databaseS = fields[6].GetString(); + std::string databaseV = fields[6].GetString(); + std::string databaseS = fields[7].GetString(); sLog->outDebug(LOG_FILTER_NETWORKIO, "database authentication values: v='%s' s='%s'", databaseV.c_str(), databaseS.c_str()); @@ -484,7 +512,7 @@ bool AuthSocket::_HandleLogonChallenge() if (securityFlags & 0x04) // Security token input pkt << uint8(1); - uint8 secLevel = fields[4].GetUInt8(); + uint8 secLevel = fields[5].GetUInt8(); _accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR; _localizationName.resize(4); @@ -498,7 +526,7 @@ bool AuthSocket::_HandleLogonChallenge() } } else //no account - pkt << (uint8)WOW_FAIL_UNKNOWN_ACCOUNT; + pkt << uint8(WOW_FAIL_UNKNOWN_ACCOUNT); } socket().send((char const*)pkt.contents(), pkt.size()); diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp index 3953beab3da..cf2816c985e 100644 --- a/src/server/scripts/Commands/cs_account.cpp +++ b/src/server/scripts/Commands/cs_account.cpp @@ -42,13 +42,19 @@ public: { "password", SEC_CONSOLE, true, &HandleAccountSetPasswordCommand, "", NULL }, { NULL, SEC_PLAYER, false, NULL, "", NULL } }; + static ChatCommand accountLockCommandTable[] = + { + { "country", SEC_PLAYER, true, &HandleAccountLockCountryCommand, "", NULL }, + { "ip", SEC_PLAYER, true, &HandleAccountLockIpCommand, "", NULL }, + { NULL, SEC_PLAYER, false, NULL, "", NULL }, + }; static ChatCommand accountCommandTable[] = { { "addon", SEC_MODERATOR, false, &HandleAccountAddonCommand, "", NULL }, { "create", SEC_CONSOLE, true, &HandleAccountCreateCommand, "", NULL }, { "delete", SEC_CONSOLE, true, &HandleAccountDeleteCommand, "", NULL }, { "onlinelist", SEC_CONSOLE, true, &HandleAccountOnlineListCommand, "", NULL }, - { "lock", SEC_PLAYER, false, &HandleAccountLockCommand, "", NULL }, + { "lock", SEC_PLAYER, false, NULL, "", accountLockCommandTable }, { "set", SEC_ADMINISTRATOR, true, NULL, "", accountSetCommandTable }, { "password", SEC_PLAYER, false, &HandleAccountPasswordCommand, "", NULL }, { "", SEC_PLAYER, false, &HandleAccountCommand, "", NULL }, @@ -245,7 +251,57 @@ public: return true; } - static bool HandleAccountLockCommand(ChatHandler* handler, char const* args) + static bool HandleAccountLockCountryCommand(ChatHandler* handler, char const* args) + { + if (!*args) + { + handler->SendSysMessage(LANG_USE_BOL); + handler->SetSentErrorMessage(true); + return false; + } + std::string param = (char*)args; + + if (!param.empty()) + { + if (param == "on") + { + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_LOGON_COUNTRY); + uint32 ip = inet_addr(handler->GetSession()->GetRemoteAddress().c_str()); + EndianConvertReverse(ip); + stmt->setUInt32(0, ip); + PreparedQueryResult result = LoginDatabase.Query(stmt); + if (result) + { + Field* fields = result->Fetch(); + std::string country = fields[0].GetString(); + stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_CONTRY); + stmt->setString(0, country); + stmt->setUInt32(1, handler->GetSession()->GetAccountId()); + LoginDatabase.Execute(stmt); + handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED); + } + else + { + handler->PSendSysMessage("[IP2NATION] Table empty"); + sLog->outDebug(LOG_FILTER_AUTHSERVER, "[IP2NATION] Table empty"); + } + } + else if (param == "off") + { + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_LOCK_CONTRY); + stmt->setString(0, "00"); + stmt->setUInt32(1, handler->GetSession()->GetAccountId()); + LoginDatabase.Execute(stmt); + handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED); + } + return true; + } + handler->SendSysMessage(LANG_USE_BOL); + handler->SetSentErrorMessage(true); + return false; + } + + static bool HandleAccountLockIpCommand(ChatHandler* handler, char const* args) { if (!*args) { diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index c6d80cea3a5..bb7d6ea9594 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -1587,7 +1587,7 @@ public: EndianConvertReverse(ip); #endif - PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_IP2NATION_COUNTRY); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP2NATION_COUNTRY); stmt->setUInt32(0, ip); diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp index a23294a038c..4b0ee041603 100644 --- a/src/server/shared/Database/Implementation/LoginDatabase.cpp +++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp @@ -37,7 +37,8 @@ void LoginDatabaseConnection::DoPrepareStatements() PrepareStatement(LOGIN_SEL_SESSIONKEY, "SELECT a.sessionkey, a.id, aa.gmlevel FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE username = ?", CONNECTION_SYNCH); PrepareStatement(LOGIN_UPD_VS, "UPDATE account SET v = ?, s = ? WHERE username = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_LOGONPROOF, "UPDATE account SET sessionkey = ?, last_ip = ?, last_login = NOW(), locale = ?, failed_logins = 0, os = ? WHERE username = ?", CONNECTION_ASYNC); - PrepareStatement(LOGIN_SEL_LOGONCHALLENGE, "SELECT a.sha_pass_hash, a.id, a.locked, a.last_ip, aa.gmlevel, a.v, a.s FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = ?", CONNECTION_SYNCH); + PrepareStatement(LOGIN_SEL_LOGONCHALLENGE, "SELECT a.sha_pass_hash, a.id, a.locked, a.lock_country, a.last_ip, aa.gmlevel, a.v, a.s FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = ?", CONNECTION_SYNCH); + PrepareStatement(LOGIN_SEL_LOGON_COUNTRY, "SELECT country FROM ip2nation WHERE ip < ? ORDER BY ip DESC LIMIT 0,1", CONNECTION_SYNCH); PrepareStatement(LOGIN_UPD_FAILEDLOGINS, "UPDATE account SET failed_logins = failed_logins + 1 WHERE username = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_SEL_FAILEDLOGINS, "SELECT id, failed_logins FROM account WHERE username = ?", CONNECTION_SYNCH); PrepareStatement(LOGIN_SEL_ACCOUNT_ID_BY_NAME, "SELECT id FROM account WHERE username = ?", CONNECTION_SYNCH); @@ -59,6 +60,7 @@ void LoginDatabaseConnection::DoPrepareStatements() PrepareStatement(LOGIN_INS_REALM_CHARACTERS_INIT, "INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist, account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_EXPANSION, "UPDATE account SET expansion = ? WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_ACCOUNT_LOCK, "UPDATE account SET locked = ? WHERE id = ?", CONNECTION_ASYNC); + PrepareStatement(LOGIN_UPD_ACCOUNT_LOCK_CONTRY, "UPDATE account SET lock_country = ? WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_INS_LOG, "INSERT INTO logs (time, realm, type, level, string) VALUES (?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_USERNAME, "UPDATE account SET v = 0, s = 0, username = ?, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_PASSWORD, "UPDATE account SET v = 0, s = 0, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC); @@ -88,6 +90,7 @@ void LoginDatabaseConnection::DoPrepareStatements() PrepareStatement(LOGIN_SEL_ACCOUNT_WHOIS, "SELECT username, email, last_ip FROM account WHERE id = ?", CONNECTION_SYNCH); PrepareStatement(LOGIN_SEL_REALMLIST_SECURITY_LEVEL, "SELECT allowedSecurityLevel from realmlist WHERE id = ?", CONNECTION_SYNCH); PrepareStatement(LOGIN_DEL_ACCOUNT, "DELETE FROM account WHERE id = ?", CONNECTION_ASYNC); + PrepareStatement(LOGIN_SEL_IP2NATION_COUNTRY, "SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE i.ip < ? AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1", CONNECTION_SYNCH); PrepareStatement(LOGIN_SEL_ACCOUNT_ACCESS_BY_ID, "SELECT gmlevel, RealmID FROM account_access WHERE id = ? and (RealmID = ? OR RealmID = -1) ORDER BY gmlevel desc", CONNECTION_SYNCH); diff --git a/src/server/shared/Database/Implementation/LoginDatabase.h b/src/server/shared/Database/Implementation/LoginDatabase.h index 939cc4b4790..0f5a388a0b0 100644 --- a/src/server/shared/Database/Implementation/LoginDatabase.h +++ b/src/server/shared/Database/Implementation/LoginDatabase.h @@ -56,6 +56,7 @@ enum LoginDatabaseStatements LOGIN_UPD_VS, LOGIN_UPD_LOGONPROOF, LOGIN_SEL_LOGONCHALLENGE, + LOGIN_SEL_LOGON_COUNTRY, LOGIN_UPD_FAILEDLOGINS, LOGIN_SEL_FAILEDLOGINS, LOGIN_SEL_ACCOUNT_ID_BY_NAME, @@ -79,6 +80,7 @@ enum LoginDatabaseStatements LOGIN_INS_REALM_CHARACTERS_INIT, LOGIN_UPD_EXPANSION, LOGIN_UPD_ACCOUNT_LOCK, + LOGIN_UPD_ACCOUNT_LOCK_CONTRY, LOGIN_INS_LOG, LOGIN_UPD_USERNAME, LOGIN_UPD_PASSWORD, @@ -108,6 +110,7 @@ enum LoginDatabaseStatements LOGIN_SEL_ACCOUNT_WHOIS, LOGIN_SEL_REALMLIST_SECURITY_LEVEL, LOGIN_DEL_ACCOUNT, + LOGIN_SEL_IP2NATION_COUNTRY, LOGIN_SEL_ACCOUNT_ACCESS_BY_ID, LOGIN_SEL_RBAC_ACCOUNT_GROUPS, diff --git a/src/server/shared/Database/Implementation/WorldDatabase.cpp b/src/server/shared/Database/Implementation/WorldDatabase.cpp index 89f3cf8fdce..fa7818d2dca 100644 --- a/src/server/shared/Database/Implementation/WorldDatabase.cpp +++ b/src/server/shared/Database/Implementation/WorldDatabase.cpp @@ -80,7 +80,6 @@ void WorldDatabaseConnection::DoPrepareStatements() PrepareStatement(WORLD_SEL_COMMANDS, "SELECT name, security, help FROM command", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_CREATURE_TEMPLATE, "SELECT difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, modelid1, modelid2, modelid3, modelid4, name, subname, IconName, gossip_menu_id, minlevel, maxlevel, exp, faction_A, faction_H, npcflag, speed_walk, speed_run, scale, rank, mindmg, maxdmg, dmgschool, attackpower, dmg_multiplier, baseattacktime, rangeattacktime, unit_class, unit_flags, unit_flags2, dynamicflags, family, trainer_type, trainer_spell, trainer_class, trainer_race, minrangedmg, maxrangedmg, rangedattackpower, type, type_flags, lootid, pickpocketloot, skinloot, resistance1, resistance2, resistance3, resistance4, resistance5, resistance6, spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, PetSpellDataId, VehicleId, mingold, maxgold, AIName, MovementType, InhabitType, HoverHeight, Health_mod, Mana_mod, Armor_mod, RacialLeader, questItem1, questItem2, questItem3, questItem4, questItem5, questItem6, movementId, RegenHealth, mechanic_immune_mask, flags_extra, ScriptName FROM creature_template WHERE entry = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_WAYPOINT_SCRIPT_BY_ID, "SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = ?", CONNECTION_SYNCH); - PrepareStatement(WORLD_SEL_IP2NATION_COUNTRY, "SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE i.ip < ? AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_ITEM_TEMPLATE_BY_NAME, "SELECT entry FROM item_template WHERE name = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH); diff --git a/src/server/shared/Database/Implementation/WorldDatabase.h b/src/server/shared/Database/Implementation/WorldDatabase.h index 032baf29dd9..d8c3c69dbba 100644 --- a/src/server/shared/Database/Implementation/WorldDatabase.h +++ b/src/server/shared/Database/Implementation/WorldDatabase.h @@ -100,7 +100,6 @@ enum WorldDatabaseStatements WORLD_SEL_COMMANDS, WORLD_SEL_CREATURE_TEMPLATE, WORLD_SEL_WAYPOINT_SCRIPT_BY_ID, - WORLD_SEL_IP2NATION_COUNTRY, WORLD_SEL_ITEM_TEMPLATE_BY_NAME, WORLD_SEL_CREATURE_BY_ID, WORLD_SEL_GAMEOBJECT_NEAREST, -- cgit v1.2.3 From 4537d4082eb3d23fcf2e6d7038d7da9dbecd15b6 Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 22 Apr 2013 17:37:13 +0200 Subject: Scripts/Commands: Corrected queried database for ip2nation in .pinfo command --- src/server/scripts/Commands/cs_misc.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/server/scripts/Commands') diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index bb7d6ea9594..9fa143673ca 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -1588,12 +1588,8 @@ public: #endif PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP2NATION_COUNTRY); - stmt->setUInt32(0, ip); - - PreparedQueryResult result2 = WorldDatabase.Query(stmt); - - if (result2) + if (PreparedQueryResult result2 = LoginDatabase.Query(stmt)) { Field* fields2 = result2->Fetch(); lastIp.append(" ("); -- cgit v1.2.3 From f2b6b2f95e2664686e247ec0870fbb77a5770d54 Mon Sep 17 00:00:00 2001 From: xjose93 Date: Tue, 23 Apr 2013 15:33:42 +0200 Subject: Core/Commands: Improve .character rename [name], now can force rename .character rename [name] [newName] --- sql/updates/world/2013_04_29_00_world_misc.sql | 11 ++ src/server/game/Miscellaneous/Language.h | 5 +- src/server/scripts/Commands/cs_character.cpp | 121 ++++++++++++++++++--- .../Database/Implementation/CharacterDatabase.cpp | 1 + .../Database/Implementation/CharacterDatabase.h | 1 + 5 files changed, 123 insertions(+), 16 deletions(-) create mode 100644 sql/updates/world/2013_04_29_00_world_misc.sql (limited to 'src/server/scripts/Commands') diff --git a/sql/updates/world/2013_04_29_00_world_misc.sql b/sql/updates/world/2013_04_29_00_world_misc.sql new file mode 100644 index 00000000000..716a77be584 --- /dev/null +++ b/sql/updates/world/2013_04_29_00_world_misc.sql @@ -0,0 +1,11 @@ +DELETE FROM `command` WHERE `name` = 'character rename'; +INSERT INTO `command` (`name`, `security`, `help`) VALUES +('character rename', 2, 'Syntax: .character rename [$name] [$newName] \n\nMark selected in game or by $name in command character for rename at next login.\n\nIf $newName then the player will be forced rename.'); + +SET @ENTRY := 98; +SET @ENTRY1 := 167; +DELETE FROM `trinity_string` WHERE `entry` IN (@ENTRY, @ENTRY+1, @ENTRY1); +INSERT INTO `trinity_string` (`entry`, `content_default`) VALUES +(@ENTRY, '\'%s\' already exists as character name, choose another one'), +(@ENTRY+1, 'Player \'%s\' forced rename to \'%s\''), +(@ENTRY1, 'This name is reserved, choose another one'); diff --git a/src/server/game/Miscellaneous/Language.h b/src/server/game/Miscellaneous/Language.h index e03adf2a4a1..eb55e44c9ee 100644 --- a/src/server/game/Miscellaneous/Language.h +++ b/src/server/game/Miscellaneous/Language.h @@ -121,7 +121,8 @@ enum TrinityStrings LANG_RBAC_LIST_PERMISSIONS_HEADER = 95, LANG_GUILD_RENAME_ALREADY_EXISTS = 96, LANG_GUILD_RENAME_DONE = 97, - // Room for more level 0 98-99 not used + LANG_RENAME_PLAYER_ALREADY_EXISTS = 98, + LANG_RENAME_PLAYER_WITH_NEW_NAME = 99, // level 1 chat LANG_GLOBAL_NOTIFY = 100, @@ -198,7 +199,7 @@ enum TrinityStrings LANG_COMMAND_TELE_NOTFOUND = 164, LANG_COMMAND_TELE_PARAMETER = 165, LANG_COMMAND_TELE_NOLOCATION = 166, - // 167 // not used + LANG_RESERVED_NAME = 167, LANG_COMMAND_TELE_LOCATION = 168, LANG_MAIL_SENT = 169, diff --git a/src/server/scripts/Commands/cs_character.cpp b/src/server/scripts/Commands/cs_character.cpp index c29b62975ab..fdcf88177a9 100644 --- a/src/server/scripts/Commands/cs_character.cpp +++ b/src/server/scripts/Commands/cs_character.cpp @@ -308,28 +308,121 @@ public: if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; - if (target) + char const* newNameStr = strtok(NULL, " "); + + if (newNameStr) { - // check online security - if (handler->HasLowerSecurity(target, 0)) + std::string playerOldName; + std::string newName = newNameStr; + + if (target) + { + // check online security + if (handler->HasLowerSecurity(target, 0)) + return false; + + playerOldName = target->GetName(); + } + else + { + // check offline security + if (handler->HasLowerSecurity(NULL, targetGuid)) + return false; + + sObjectMgr->GetPlayerNameByGUID(targetGuid, playerOldName); + } + + if (!normalizePlayerName(newName)) + { + handler->SendSysMessage(LANG_BAD_VALUE); + handler->SetSentErrorMessage(true); + return false; + } + + if (ObjectMgr::CheckPlayerName(newName, true) != CHAR_NAME_SUCCESS) + { + handler->SendSysMessage(LANG_BAD_VALUE); + handler->SetSentErrorMessage(true); + return false; + } + + if (WorldSession* session = handler->GetSession()) + { + if (!session->HasPermission(RBAC_PERM_SKIP_CHECK_CHARACTER_CREATION_RESERVEDNAME) && sObjectMgr->IsReservedName(newName)) + { + handler->SendSysMessage(LANG_RESERVED_NAME); + handler->SetSentErrorMessage(true); + return false; + } + } + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME); + stmt->setString(0, newName); + PreparedQueryResult result = CharacterDatabase.Query(stmt); + if (result) + { + handler->PSendSysMessage(LANG_RENAME_PLAYER_ALREADY_EXISTS, newName.c_str()); + handler->SetSentErrorMessage(true); return false; + } + + // Remove declined name from db + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_DECLINED_NAME); + stmt->setUInt32(0, targetGuid); + CharacterDatabase.Execute(stmt); + + if (target) + { + target->SetName(newName); + + if (WorldSession* session = target->GetSession()) + session->KickPlayer(); + } + else + { + stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_NAME_BY_GUID); + stmt->setString(0, newName); + stmt->setUInt32(1, GUID_LOPART(targetGuid)); + CharacterDatabase.Execute(stmt); + } + + sWorld->UpdateCharacterNameData(targetGuid, newName); - handler->PSendSysMessage(LANG_RENAME_PLAYER, handler->GetNameLink(target).c_str()); - target->SetAtLoginFlag(AT_LOGIN_RENAME); + handler->PSendSysMessage(LANG_RENAME_PLAYER_WITH_NEW_NAME, playerOldName.c_str(), newName.c_str()); + + if (WorldSession* session = handler->GetSession()) + { + if (Player* player = session->GetPlayer()) + sLog->outCommand(session->GetAccountId(), "GM %s (Account: %u) forced rename %s to player %s (Account: %u)", player->GetName().c_str(), session->GetAccountId(), newName.c_str(), playerOldName.c_str(), sObjectMgr->GetPlayerAccountIdByGUID(targetGuid)); + } + else + sLog->outCommand(0, "CONSOLE forced rename '%s' to '%s' (GUID: %u)", playerOldName.c_str(), newName.c_str(), GUID_LOPART(targetGuid)); } else { - // check offline security - if (handler->HasLowerSecurity(NULL, targetGuid)) - return false; + if (target) + { + // check online security + if (handler->HasLowerSecurity(target, 0)) + return false; - std::string oldNameLink = handler->playerLink(targetName); - handler->PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid)); + handler->PSendSysMessage(LANG_RENAME_PLAYER, handler->GetNameLink(target).c_str()); + target->SetAtLoginFlag(AT_LOGIN_RENAME); + } + else + { + // check offline security + if (handler->HasLowerSecurity(NULL, targetGuid)) + return false; - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); - stmt->setUInt16(0, uint16(AT_LOGIN_RENAME)); - stmt->setUInt32(1, GUID_LOPART(targetGuid)); - CharacterDatabase.Execute(stmt); + std::string oldNameLink = handler->playerLink(targetName); + handler->PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid)); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); + stmt->setUInt16(0, uint16(AT_LOGIN_RENAME)); + stmt->setUInt32(1, GUID_LOPART(targetGuid)); + CharacterDatabase.Execute(stmt); + } } return true; diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index f834ead6a5b..2e6ab10b087 100644 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -165,6 +165,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_SEL_MATCH_MAKER_RATING, "SELECT matchMakerRating FROM character_arena_stats WHERE guid = ? AND slot = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_CHARACTER_COUNT, "SELECT account, COUNT(guid) FROM characters WHERE account = ? GROUP BY account", CONNECTION_ASYNC); PrepareStatement(CHAR_UPD_NAME, "UPDATE characters set name = ?, at_login = at_login & ~ ? WHERE guid = ?", CONNECTION_ASYNC); + PrepareStatement(CHAR_UPD_NAME_BY_GUID, "UPDATE characters SET name = ? WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_DECLINED_NAME, "DELETE FROM character_declinedname WHERE guid = ?", CONNECTION_ASYNC); // Guild handling diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index 65878b4c577..59ac15978b6 100644 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -161,6 +161,7 @@ enum CharacterDatabaseStatements CHAR_SEL_MATCH_MAKER_RATING, CHAR_SEL_CHARACTER_COUNT, CHAR_UPD_NAME, + CHAR_UPD_NAME_BY_GUID, CHAR_DEL_DECLINED_NAME, CHAR_SEL_CHARACTER_DATA_BY_GUID, -- cgit v1.2.3 From f4b83273ec8c109e264e37b691e97dfb89606f86 Mon Sep 17 00:00:00 2001 From: illusion Date: Sat, 11 May 2013 11:19:57 +0200 Subject: Core/Tickets * Fixed .ticket complete command not marking tickets as completed * Fixed "Need more help" button functionality after ticket has been answered by a GM Closes #9383 --- src/server/game/Handlers/TicketHandler.cpp | 9 +++++++-- src/server/game/Tickets/TicketMgr.cpp | 10 ++++++++-- src/server/game/Tickets/TicketMgr.h | 5 +++-- src/server/scripts/Commands/cs_ticket.cpp | 4 ++++ 4 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src/server/scripts/Commands') diff --git a/src/server/game/Handlers/TicketHandler.cpp b/src/server/game/Handlers/TicketHandler.cpp index 2da2735a3f9..7b35462e7a2 100644 --- a/src/server/game/Handlers/TicketHandler.cpp +++ b/src/server/game/Handlers/TicketHandler.cpp @@ -41,10 +41,15 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData) } GMTicketResponse response = GMTICKET_RESPONSE_CREATE_ERROR; + GmTicket* ticket = sTicketMgr->GetTicketByPlayer(GetPlayer()->GetGUID()); + + if (ticket && ticket->IsCompleted()) + sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID());; + // Player must not have ticket - if (!sTicketMgr->GetTicketByPlayer(GetPlayer()->GetGUID())) + if (!ticket || ticket->IsClosed()) { - GmTicket* ticket = new GmTicket(GetPlayer(), recvData); + ticket = new GmTicket(GetPlayer(), recvData); uint32 count; std::list times; diff --git a/src/server/game/Tickets/TicketMgr.cpp b/src/server/game/Tickets/TicketMgr.cpp index fe10b81b09d..d76f6e9444b 100644 --- a/src/server/game/Tickets/TicketMgr.cpp +++ b/src/server/game/Tickets/TicketMgr.cpp @@ -239,7 +239,10 @@ void GmTicket::SetChatLog(std::list time, std::string const& log) /////////////////////////////////////////////////////////////////////////////////////////////////// // Ticket manager -TicketMgr::TicketMgr() : _status(true), _lastTicketId(0), _lastSurveyId(0), _openTicketCount(0), _lastChange(time(NULL)) { } +TicketMgr::TicketMgr() : _status(true), _lastTicketId(0), _lastSurveyId(0), _openTicketCount(0), + _lastChange(time(NULL)) +{ +} TicketMgr::~TicketMgr() { @@ -247,7 +250,10 @@ TicketMgr::~TicketMgr() delete itr->second; } -void TicketMgr::Initialize() { SetStatus(sWorld->getBoolConfig(CONFIG_ALLOW_TICKETS)); } +void TicketMgr::Initialize() +{ + SetStatus(sWorld->getBoolConfig(CONFIG_ALLOW_TICKETS)); +} void TicketMgr::ResetTickets() { diff --git a/src/server/game/Tickets/TicketMgr.h b/src/server/game/Tickets/TicketMgr.h index 0fe45f81360..91ef98dda23 100644 --- a/src/server/game/Tickets/TicketMgr.h +++ b/src/server/game/Tickets/TicketMgr.h @@ -82,7 +82,7 @@ class GmTicket { public: GmTicket(); - explicit GmTicket(Player* player, WorldPacket& recvData); + GmTicket(Player* player, WorldPacket& recvData); ~GmTicket(); bool IsClosed() const { return _closedBy; } @@ -119,7 +119,8 @@ public: else if (_escalatedStatus == TICKET_UNASSIGNED) _escalatedStatus = TICKET_ASSIGNED; } - void SetClosedBy(const int64& value) { _closedBy = value; } + void SetClosedBy(int64 value) { _closedBy = value; } + void SetCompleted() { _completed = true; } void SetMessage(std::string const& message) { _message = message; diff --git a/src/server/scripts/Commands/cs_ticket.cpp b/src/server/scripts/Commands/cs_ticket.cpp index 95cbf70e1f8..0795b2ab90c 100644 --- a/src/server/scripts/Commands/cs_ticket.cpp +++ b/src/server/scripts/Commands/cs_ticket.cpp @@ -235,6 +235,10 @@ public: if (player->IsInWorld()) ticket->SendResponse(player->GetSession()); + SQLTransaction trans = SQLTransaction(NULL); + ticket->SetCompleted(); + ticket->SaveToDB(trans); + sTicketMgr->UpdateLastChange(); return true; } -- cgit v1.2.3 From 243c325ca4323feb4f7f80c0ecd3873c78cbf887 Mon Sep 17 00:00:00 2001 From: Spp Date: Tue, 7 May 2013 12:02:22 +0200 Subject: Core: Declare some functions const and remove use of "using" directive in a couple of files --- src/server/game/Entities/Unit/Unit.cpp | 101 ++++++++++++++--------------- src/server/game/Entities/Unit/Unit.h | 20 +++--- src/server/game/Movement/MotionMaster.cpp | 2 +- src/server/game/Movement/PathGenerator.cpp | 27 ++++---- src/server/game/Movement/PathGenerator.h | 58 ++++++++--------- src/server/scripts/Commands/cs_mmaps.cpp | 12 ++-- 6 files changed, 108 insertions(+), 112 deletions(-) (limited to 'src/server/scripts/Commands') diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 798c9371574..7886c276020 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -144,37 +144,30 @@ void DamageInfo::BlockDamage(uint32 amount) m_damage -= amount; } -ProcEventInfo::ProcEventInfo(Unit* actor, Unit* actionTarget, Unit* procTarget, uint32 typeMask, uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, Spell* spell, DamageInfo* damageInfo, HealInfo* healInfo) -:_actor(actor), _actionTarget(actionTarget), _procTarget(procTarget), _typeMask(typeMask), _spellTypeMask(spellTypeMask), _spellPhaseMask(spellPhaseMask), -_hitMask(hitMask), _spell(spell), _damageInfo(damageInfo), _healInfo(healInfo) -{ -} +ProcEventInfo::ProcEventInfo(Unit* actor, Unit* actionTarget, Unit* procTarget, + uint32 typeMask, uint32 spellTypeMask, + uint32 spellPhaseMask, uint32 hitMask, + Spell* spell, DamageInfo* damageInfo, + HealInfo* healInfo) : + _actor(actor), _actionTarget(actionTarget), _procTarget(procTarget), + _typeMask(typeMask), _spellTypeMask(spellTypeMask), + _spellPhaseMask(spellPhaseMask), _hitMask(hitMask), _spell(spell), + _damageInfo(damageInfo), _healInfo(healInfo) +{ } // we can disable this warning for this since it only // causes undefined behavior when passed to the base class constructor #ifdef _MSC_VER #pragma warning(disable:4355) #endif -Unit::Unit(bool isWorldObject): WorldObject(isWorldObject) - , m_movedPlayer(NULL) - , m_lastSanctuaryTime(0) - , m_TempSpeed(0.0f) - , IsAIEnabled(false) - , NeedChangeAI(false) - , m_ControlledByPlayer(false) - , movespline(new Movement::MoveSpline()) - , i_AI(NULL) - , i_disabledAI(NULL) - , m_AutoRepeatFirstCast(false) - , m_procDeep(0) - , m_removedAurasCount(0) - , i_motionMaster(this) - , m_ThreatManager(this) - , m_vehicle(NULL) - , m_vehicleKit(NULL) - , m_unitTypeMask(UNIT_MASK_NONE) - , m_HostileRefManager(this) - , _lastDamagedTime(0) +Unit::Unit(bool isWorldObject) : + WorldObject(isWorldObject), m_movedPlayer(NULL), m_lastSanctuaryTime(0), + m_TempSpeed(0.0f), IsAIEnabled(false), NeedChangeAI(false), + m_ControlledByPlayer(false), movespline(new Movement::MoveSpline()), + i_AI(NULL), i_disabledAI(NULL), m_AutoRepeatFirstCast(false), m_procDeep(0), + m_removedAurasCount(0), i_motionMaster(this), m_ThreatManager(this), + m_vehicle(NULL), m_vehicleKit(NULL), m_unitTypeMask(UNIT_MASK_NONE), + m_HostileRefManager(this), _lastDamagedTime(0) { #ifdef _MSC_VER #pragma warning(default:4355) @@ -1428,7 +1421,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss) victim->DealDamageMods(this, damage, NULL); /// @todo Move this to a packet handler - WorldPacket data(SMSG_SPELLDAMAGESHIELD, (8+8+4+4+4+4)); + WorldPacket data(SMSG_SPELLDAMAGESHIELD, 8 + 8 + 4 + 4 + 4 + 4 + 4); data << uint64(victim->GetGUID()); data << uint64(GetGUID()); data << uint32(i_spellProto->Id); @@ -1476,7 +1469,6 @@ bool Unit::IsDamageReducedByArmor(SpellSchoolMask schoolMask, SpellInfo const* s uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo const* spellInfo, WeaponAttackType /*attackType*/) { - uint32 newdamage = 0; float armor = float(victim->GetArmor()); // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura @@ -1486,16 +1478,16 @@ uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo if (Player* modOwner = GetSpellModOwner()) modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_IGNORE_ARMOR, armor); - AuraEffectList const& ResIgnoreAurasAb = GetAuraEffectsByType(SPELL_AURA_MOD_ABILITY_IGNORE_TARGET_RESIST); - for (AuraEffectList::const_iterator j = ResIgnoreAurasAb.begin(); j != ResIgnoreAurasAb.end(); ++j) + AuraEffectList const& resIgnoreAurasAb = GetAuraEffectsByType(SPELL_AURA_MOD_ABILITY_IGNORE_TARGET_RESIST); + for (AuraEffectList::const_iterator j = resIgnoreAurasAb.begin(); j != resIgnoreAurasAb.end(); ++j) { if ((*j)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL && (*j)->IsAffectedOnSpell(spellInfo)) armor = floor(AddPct(armor, -(*j)->GetAmount())); } - AuraEffectList const& ResIgnoreAuras = GetAuraEffectsByType(SPELL_AURA_MOD_IGNORE_TARGET_RESIST); - for (AuraEffectList::const_iterator j = ResIgnoreAuras.begin(); j != ResIgnoreAuras.end(); ++j) + AuraEffectList const& resIgnoreAuras = GetAuraEffectsByType(SPELL_AURA_MOD_IGNORE_TARGET_RESIST); + for (AuraEffectList::const_iterator j = resIgnoreAuras.begin(); j != resIgnoreAuras.end(); ++j) { if ((*j)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL) armor = floor(AddPct(armor, -(*j)->GetAmount())); @@ -1541,7 +1533,7 @@ uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo float levelModifier = getLevel(); if (levelModifier > 59) - levelModifier = levelModifier + (4.5f * (levelModifier - 59)); + levelModifier = levelModifier + 4.5f * (levelModifier - 59); float tmpvalue = 0.1f * armor / (8.5f * levelModifier + 40); tmpvalue = tmpvalue / (1.0f + tmpvalue); @@ -1551,9 +1543,7 @@ uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo if (tmpvalue > 0.75f) tmpvalue = 0.75f; - newdamage = uint32(damage - (damage * tmpvalue)); - - return (newdamage > 1) ? newdamage : 1; + return std::max(damage * (1.0f - tmpvalue), 1); } void Unit::CalcAbsorbResist(Unit* victim, SpellSchoolMask schoolMask, DamageEffectType damagetype, uint32 const damage, uint32 *absorb, uint32 *resist, SpellInfo const* spellInfo) @@ -1646,6 +1636,7 @@ void Unit::CalcAbsorbResist(Unit* victim, SpellSchoolMask schoolMask, DamageEffe if (((*itr)->GetAmount() > auraAbsorbMod) && (*itr)->IsAffectedOnSpell(spellInfo)) auraAbsorbMod = float((*itr)->GetAmount()); } + RoundToInterval(auraAbsorbMod, 0.0f, 100.0f); // We're going to call functions which can modify content of the list during iteration over it's elements @@ -1801,7 +1792,7 @@ void Unit::CalcAbsorbResist(Unit* victim, SpellSchoolMask schoolMask, DamageEffe // We're going to call functions which can modify content of the list during iteration over it's elements // Let's copy the list so we can prevent iterator invalidation AuraEffectList vSplitDamagePctCopy(victim->GetAuraEffectsByType(SPELL_AURA_SPLIT_DAMAGE_PCT)); - for (AuraEffectList::iterator itr = vSplitDamagePctCopy.begin(), next; (itr != vSplitDamagePctCopy.end()) && (dmgInfo.GetDamage() > 0); ++itr) + for (AuraEffectList::iterator itr = vSplitDamagePctCopy.begin(); itr != vSplitDamagePctCopy.end() && dmgInfo.GetDamage() > 0; ++itr) { // Check if aura was removed during iteration - we don't need to work on such auras AuraApplication const* aurApp = (*itr)->GetBase()->GetApplicationOfTarget(victim->GetGUID()); @@ -2209,7 +2200,7 @@ void Unit::SendMeleeAttackStop(Unit* victim) { WorldPacket data(SMSG_ATTACKSTOP, (8+8+4)); data.append(GetPackGUID()); - data.appendPackGUID(victim ? victim->GetGUID() : 0); + data.append(victim ? victim->GetPackGUID() : 0); data << uint32(0); //! Can also take the value 0x01, which seems related to updating rotation SendMessageToSet(&data, true); sLog->outDebug(LOG_FILTER_UNITS, "WORLD: Sent SMSG_ATTACKSTOP"); @@ -2248,7 +2239,7 @@ bool Unit::isBlockCritical() return false; } -int32 Unit::GetMechanicResistChance(const SpellInfo* spell) +int32 Unit::GetMechanicResistChance(const SpellInfo* spell) const { if (!spell) return 0; @@ -2272,11 +2263,15 @@ bool Unit::CanUseAttackType(uint8 attacktype) const { switch (attacktype) { - case BASE_ATTACK: return !HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED); - case OFF_ATTACK: return !HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_DISARM_OFFHAND); - case RANGED_ATTACK: return !HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_DISARM_RANGED); + case BASE_ATTACK: + return !HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISARMED); + case OFF_ATTACK: + return !HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_DISARM_OFFHAND); + case RANGED_ATTACK: + return !HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_DISARM_RANGED); + default: + return true; } - return true; } // Melee based spells hit result calculations @@ -4332,11 +4327,11 @@ bool Unit::HasAuraTypeWithValue(AuraType auratype, int32 value) const return false; } -bool Unit::HasNegativeAuraWithInterruptFlag(uint32 flag, uint64 guid) +bool Unit::HasNegativeAuraWithInterruptFlag(uint32 flag, uint64 guid) const { if (!(m_interruptMask & flag)) return false; - for (AuraApplicationList::iterator iter = m_interruptableAuras.begin(); iter != m_interruptableAuras.end(); ++iter) + for (AuraApplicationList::const_iterator iter = m_interruptableAuras.begin(); iter != m_interruptableAuras.end(); ++iter) { if (!(*iter)->IsPositive() && (*iter)->GetBase()->GetSpellInfo()->AuraInterruptFlags & flag && (!guid || (*iter)->GetBase()->GetCasterGUID() == guid)) return true; @@ -4344,9 +4339,9 @@ bool Unit::HasNegativeAuraWithInterruptFlag(uint32 flag, uint64 guid) return false; } -bool Unit::HasNegativeAuraWithAttribute(uint32 flag, uint64 guid) +bool Unit::HasNegativeAuraWithAttribute(uint32 flag, uint64 guid) const { - for (AuraApplicationMap::iterator iter = m_appliedAuras.begin(); iter != m_appliedAuras.end(); ++iter) + for (AuraApplicationMap::const_iterator iter = m_appliedAuras.begin(); iter != m_appliedAuras.end(); ++iter) { Aura const* aura = iter->second->GetBase(); if (!iter->second->IsPositive() && aura->GetSpellInfo()->Attributes & flag && (!guid || aura->GetCasterGUID() == guid)) @@ -4355,11 +4350,11 @@ bool Unit::HasNegativeAuraWithAttribute(uint32 flag, uint64 guid) return false; } -bool Unit::HasAuraWithMechanic(uint32 mechanicMask) +bool Unit::HasAuraWithMechanic(uint32 mechanicMask) const { - for (AuraApplicationMap::iterator iter = m_appliedAuras.begin(); iter != m_appliedAuras.end(); ++iter) + for (AuraApplicationMap::const_iterator iter = m_appliedAuras.begin(); iter != m_appliedAuras.end(); ++iter) { - SpellInfo const* spellInfo = iter->second->GetBase()->GetSpellInfo(); + SpellInfo const* spellInfo = iter->second->GetBase()->GetSpellInfo(); if (spellInfo->Mechanic && (mechanicMask & (1 << spellInfo->Mechanic))) return true; @@ -4394,7 +4389,7 @@ uint32 Unit::GetDiseasesByCaster(uint64 casterGUID, bool remove) }; uint32 diseases = 0; - for (AuraType const* itr = &diseaseAuraTypes[0]; itr && itr[0] != SPELL_AURA_NONE; ++itr) + for (AuraType const* itr = diseaseAuraTypes; *itr != SPELL_AURA_NONE; ++itr) { for (AuraEffectList::iterator i = m_modAuras[*itr].begin(); i != m_modAuras[*itr].end();) { @@ -9585,9 +9580,11 @@ void Unit::SetCharm(Unit* charm, bool apply) } if (charm->GetTypeId() == TYPEID_PLAYER - || !charm->ToCreature()->HasUnitTypeMask(UNIT_MASK_MINION) - || charm->GetOwnerGUID() != GetGUID()) + || !charm->ToCreature()->HasUnitTypeMask(UNIT_MASK_MINION) + || charm->GetOwnerGUID() != GetGUID()) + { m_Controlled.erase(charm); + } } } diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index c972f97788f..67a6fa2a994 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1462,19 +1462,19 @@ class Unit : public WorldObject uint32 GetRangedDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_RANGED, 2.0f, 100.0f, damage); } uint32 GetSpellDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_SPELL, 2.0f, 100.0f, damage); } - void ApplyResilience(const Unit* victim, float * crit, int32 * damage, bool isCrit, CombatRating type) const; + void ApplyResilience(Unit const* victim, float* crit, int32* damage, bool isCrit, CombatRating type) const; - float MeleeSpellMissChance(const Unit* victim, WeaponAttackType attType, int32 skillDiff, uint32 spellId) const; + float MeleeSpellMissChance(Unit const* victim, WeaponAttackType attType, int32 skillDiff, uint32 spellId) const; SpellMissInfo MeleeSpellHitResult(Unit* victim, SpellInfo const* spell); SpellMissInfo MagicSpellHitResult(Unit* victim, SpellInfo const* spell); SpellMissInfo SpellHitResult(Unit* victim, SpellInfo const* spell, bool canReflect = false); - float GetUnitDodgeChance() const; - float GetUnitParryChance() const; - float GetUnitBlockChance() const; - float GetUnitMissChance(WeaponAttackType attType) const; + float GetUnitDodgeChance() const; + float GetUnitParryChance() const; + float GetUnitBlockChance() const; + float GetUnitMissChance(WeaponAttackType attType) const; float GetUnitCriticalChance(WeaponAttackType attackType, const Unit* victim) const; - int32 GetMechanicResistChance(const SpellInfo* spell); + int32 GetMechanicResistChance(const SpellInfo* spell) const; bool CanUseAttackType(uint8 attacktype) const; virtual uint32 GetShieldBlockValue() const =0; @@ -1776,9 +1776,9 @@ class Unit : public WorldObject bool HasAuraTypeWithMiscvalue(AuraType auratype, int32 miscvalue) const; bool HasAuraTypeWithAffectMask(AuraType auratype, SpellInfo const* affectedSpell) const; bool HasAuraTypeWithValue(AuraType auratype, int32 value) const; - bool HasNegativeAuraWithInterruptFlag(uint32 flag, uint64 guid = 0); - bool HasNegativeAuraWithAttribute(uint32 flag, uint64 guid = 0); - bool HasAuraWithMechanic(uint32 mechanicMask); + bool HasNegativeAuraWithInterruptFlag(uint32 flag, uint64 guid = 0) const; + bool HasNegativeAuraWithAttribute(uint32 flag, uint64 guid = 0) const; + bool HasAuraWithMechanic(uint32 mechanicMask) const; AuraEffect* IsScriptOverriden(SpellInfo const* spell, int32 script) const; uint32 GetDiseasesByCaster(uint64 casterGUID, bool remove = false); diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 8e045b98dbb..a7148055376 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -426,7 +426,7 @@ void MotionMaster::MoveCharge(float x, float y, float z, float speed, uint32 id, void MotionMaster::MoveCharge(PathGenerator const& path) { - Vector3 dest = path.GetActualEndPosition(); + G3D::Vector3 dest = path.GetActualEndPosition(); MoveCharge(dest.x, dest.y, dest.z, SPEED_CHARGE, EVENT_CHARGE_PREPATH); diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index 07e33f353c7..046f24e67b2 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -28,9 +28,10 @@ ////////////////// PathGenerator ////////////////// PathGenerator::PathGenerator(const Unit* owner) : - _polyLength(0), _type(PATHFIND_BLANK), - _useStraightPath(false), _forceDestination(false), _pointPathLimit(MAX_POINT_PATH_LENGTH), - _endPosition(Vector3::zero()), _sourceUnit(owner), _navMesh(NULL), _navMeshQuery(NULL) + _polyLength(0), _type(PATHFIND_BLANK), _useStraightPath(false), + _forceDestination(false), _pointPathLimit(MAX_POINT_PATH_LENGTH), + _endPosition(G3D::Vector3::zero()), _sourceUnit(owner), _navMesh(NULL), + _navMeshQuery(NULL) { sLog->outDebug(LOG_FILTER_MAPS, "++ PathGenerator::PathGenerator for %u \n", _sourceUnit->GetGUIDLow()); @@ -58,10 +59,10 @@ bool PathGenerator::CalculatePath(float destX, float destY, float destZ, bool fo if (!Trinity::IsValidMapCoord(destX, destY, destZ) || !Trinity::IsValidMapCoord(x, y, z)) return false; - Vector3 dest(destX, destY, destZ); + G3D::Vector3 dest(destX, destY, destZ); SetEndPosition(dest); - Vector3 start(x, y, z); + G3D::Vector3 start(x, y, z); SetStartPosition(start); _forceDestination = forceDest; @@ -151,7 +152,7 @@ dtPolyRef PathGenerator::GetPolyByLocation(float const* point, float* distance) return INVALID_POLYREF; } -void PathGenerator::BuildPolyPath(Vector3 const& startPos, Vector3 const& endPos) +void PathGenerator::BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 const& endPos) { // *** getting start/end poly logic *** @@ -202,7 +203,7 @@ void PathGenerator::BuildPolyPath(Vector3 const& startPos, Vector3 const& endPos { Creature* owner = (Creature*)_sourceUnit; - Vector3 p = (distToStartPoly > 7.0f) ? startPos : endPos; + G3D::Vector3 const& p = (distToStartPoly > 7.0f) ? startPos : endPos; if (_sourceUnit->GetBaseMap()->IsUnderWater(p.x, p.y, p.z)) { sLog->outDebug(LOG_FILTER_MAPS, "++ BuildPolyPath :: underWater case\n"); @@ -230,7 +231,7 @@ void PathGenerator::BuildPolyPath(Vector3 const& startPos, Vector3 const& endPos if (DT_SUCCESS == _navMeshQuery->closestPointOnPoly(endPoly, endPoint, closestPoint)) { dtVcopy(endPoint, closestPoint); - SetActualEndPosition(Vector3(endPoint[2], endPoint[0], endPoint[1])); + SetActualEndPosition(G3D::Vector3(endPoint[2], endPoint[0], endPoint[1])); } _type = PATHFIND_INCOMPLETE; @@ -449,7 +450,7 @@ void PathGenerator::BuildPointPath(const float *startPoint, const float *endPoin _pathPoints.resize(pointCount); for (uint32 i = 0; i < pointCount; ++i) - _pathPoints[i] = Vector3(pathPoints[i*VERTEX_SIZE+2], pathPoints[i*VERTEX_SIZE], pathPoints[i*VERTEX_SIZE+1]); + _pathPoints[i] = G3D::Vector3(pathPoints[i*VERTEX_SIZE+2], pathPoints[i*VERTEX_SIZE], pathPoints[i*VERTEX_SIZE+1]); NormalizePath(); @@ -563,7 +564,7 @@ NavTerrain PathGenerator::GetNavTerrain(float x, float y, float z) } } -bool PathGenerator::HaveTile(const Vector3& p) const +bool PathGenerator::HaveTile(const G3D::Vector3& p) const { int tx = -1, ty = -1; float point[VERTEX_SIZE] = {p.y, p.z, p.x}; @@ -791,13 +792,13 @@ bool PathGenerator::InRangeYZX(const float* v1, const float* v2, float r, float return (dx * dx + dz * dz) < r * r && fabsf(dy) < h; } -bool PathGenerator::InRange(Vector3 const& p1, Vector3 const& p2, float r, float h) const +bool PathGenerator::InRange(G3D::Vector3 const& p1, G3D::Vector3 const& p2, float r, float h) const { - Vector3 d = p1 - p2; + G3D::Vector3 d = p1 - p2; return (d.x * d.x + d.y * d.y) < r * r && fabsf(d.z) < h; } -float PathGenerator::Dist3DSqr(Vector3 const& p1, Vector3 const& p2) const +float PathGenerator::Dist3DSqr(G3D::Vector3 const& p1, G3D::Vector3 const& p2) const { return (p1 - p2).squaredLength(); } diff --git a/src/server/game/Movement/PathGenerator.h b/src/server/game/Movement/PathGenerator.h index d41d3160db5..ac66b7cec57 100644 --- a/src/server/game/Movement/PathGenerator.h +++ b/src/server/game/Movement/PathGenerator.h @@ -24,9 +24,6 @@ #include "DetourNavMeshQuery.h" #include "MoveSplineInitArgs.h" -using Movement::Vector3; -using Movement::PointsArray; - class Unit; // 74*4.0f=296y number_of_points*interval = max_path_len @@ -63,42 +60,43 @@ class PathGenerator bool CalculatePath(float destX, float destY, float destZ, bool forceDest = false); // option setters - use optional - void SetUseStraightPath(bool useStraightPath) { _useStraightPath = useStraightPath; }; - void SetPathLengthLimit(float distance) { _pointPathLimit = std::min(uint32(distance/SMOOTH_PATH_STEP_SIZE), MAX_POINT_PATH_LENGTH); }; + void SetUseStraightPath(bool useStraightPath) { _useStraightPath = useStraightPath; } + void SetPathLengthLimit(float distance) { _pointPathLimit = std::min(uint32(distance/SMOOTH_PATH_STEP_SIZE), MAX_POINT_PATH_LENGTH); } // result getters - Vector3 const& GetStartPosition() const { return _startPosition; } - Vector3 const& GetEndPosition() const { return _endPosition; } - Vector3 const& GetActualEndPosition() const { return _actualEndPosition; } + G3D::Vector3 const& GetStartPosition() const { return _startPosition; } + G3D::Vector3 const& GetEndPosition() const { return _endPosition; } + G3D::Vector3 const& GetActualEndPosition() const { return _actualEndPosition; } + + Movement::PointsArray const& GetPath() const { return _pathPoints; } - PointsArray const& GetPath() const { return _pathPoints; } PathType GetPathType() const { return _type; } private: - dtPolyRef _pathPolyRefs[MAX_PATH_LENGTH]; // array of detour polygon references - uint32 _polyLength; // number of polygons in the path + dtPolyRef _pathPolyRefs[MAX_PATH_LENGTH]; // array of detour polygon references + uint32 _polyLength; // number of polygons in the path - PointsArray _pathPoints; // our actual (x,y,z) path to the target - PathType _type; // tells what kind of path this is + Movement::PointsArray _pathPoints; // our actual (x,y,z) path to the target + PathType _type; // tells what kind of path this is - bool _useStraightPath; // type of path will be generated - bool _forceDestination; // when set, we will always arrive at given point - uint32 _pointPathLimit; // limit point path size; min(this, MAX_POINT_PATH_LENGTH) + bool _useStraightPath; // type of path will be generated + bool _forceDestination; // when set, we will always arrive at given point + uint32 _pointPathLimit; // limit point path size; min(this, MAX_POINT_PATH_LENGTH) - Vector3 _startPosition; // {x, y, z} of current location - Vector3 _endPosition; // {x, y, z} of the destination - Vector3 _actualEndPosition;// {x, y, z} of the closest possible point to given destination + G3D::Vector3 _startPosition; // {x, y, z} of current location + G3D::Vector3 _endPosition; // {x, y, z} of the destination + G3D::Vector3 _actualEndPosition; // {x, y, z} of the closest possible point to given destination - Unit const* const _sourceUnit; // the unit that is moving - dtNavMesh const* _navMesh; // the nav mesh - dtNavMeshQuery const* _navMeshQuery; // the nav mesh query used to find the path + Unit const* const _sourceUnit; // the unit that is moving + dtNavMesh const* _navMesh; // the nav mesh + dtNavMeshQuery const* _navMeshQuery; // the nav mesh query used to find the path - dtQueryFilter _filter; // use single filter for all movements, update it when needed + dtQueryFilter _filter; // use single filter for all movements, update it when needed - void SetStartPosition(Vector3 Point) { _startPosition = Point; } - void SetEndPosition(Vector3 Point) { _actualEndPosition = Point; _endPosition = Point; } - void SetActualEndPosition(Vector3 Point) { _actualEndPosition = Point; } + void SetStartPosition(G3D::Vector3 const& point) { _startPosition = point; } + void SetEndPosition(G3D::Vector3 const& point) { _actualEndPosition = point; _endPosition = point; } + void SetActualEndPosition(G3D::Vector3 const& point) { _actualEndPosition = point; } void NormalizePath(); void Clear() @@ -107,15 +105,15 @@ class PathGenerator _pathPoints.clear(); } - bool InRange(Vector3 const& p1, Vector3 const& p2, float r, float h) const; - float Dist3DSqr(Vector3 const& p1, Vector3 const& p2) const; + bool InRange(G3D::Vector3 const& p1, G3D::Vector3 const& p2, float r, float h) const; + float Dist3DSqr(G3D::Vector3 const& p1, G3D::Vector3 const& p2) const; bool InRangeYZX(float const* v1, float const* v2, float r, float h) const; dtPolyRef GetPathPolyByPosition(dtPolyRef const* polyPath, uint32 polyPathSize, float const* Point, float* Distance = NULL) const; dtPolyRef GetPolyByLocation(float const* Point, float* Distance) const; - bool HaveTile(Vector3 const& p) const; + bool HaveTile(G3D::Vector3 const& p) const; - void BuildPolyPath(Vector3 const& startPos, Vector3 const& endPos); + void BuildPolyPath(G3D::Vector3 const& startPos, G3D::Vector3 const& endPos); void BuildPointPath(float const* startPoint, float const* endPoint); void BuildShortcut(); diff --git a/src/server/scripts/Commands/cs_mmaps.cpp b/src/server/scripts/Commands/cs_mmaps.cpp index 79cd0deb75e..55b6edbadbe 100644 --- a/src/server/scripts/Commands/cs_mmaps.cpp +++ b/src/server/scripts/Commands/cs_mmaps.cpp @@ -95,14 +95,14 @@ public: path.SetUseStraightPath(useStraightPath); bool result = path.CalculatePath(x, y, z); - PointsArray const& pointPath = path.GetPath(); + Movement::PointsArray const& pointPath = path.GetPath(); handler->PSendSysMessage("%s's path to %s:", target->GetName().c_str(), player->GetName().c_str()); handler->PSendSysMessage("Building: %s", useStraightPath ? "StraightPath" : "SmoothPath"); - handler->PSendSysMessage("Result: %s - Length: "SIZEFMTD" - Type: %u", (result ? "true" : "false"), pointPath.size(), path.GetPathType()); + handler->PSendSysMessage("Result: %s - Length: " SIZEFMTD " - Type: %u", (result ? "true" : "false"), pointPath.size(), path.GetPathType()); - Vector3 start = path.GetStartPosition(); - Vector3 end = path.GetEndPosition(); - Vector3 actualEnd = path.GetActualEndPosition(); + G3D::Vector3 const &start = path.GetStartPosition(); + G3D::Vector3 const &end = path.GetEndPosition(); + G3D::Vector3 const &actualEnd = path.GetActualEndPosition(); handler->PSendSysMessage("StartPosition (%.3f, %.3f, %.3f)", start.x, start.y, start.z); handler->PSendSysMessage("EndPosition (%.3f, %.3f, %.3f)", end.x, end.y, end.z); @@ -264,7 +264,7 @@ public: if (!creatureList.empty()) { - handler->PSendSysMessage("Found "SIZEFMTD" Creatures.", creatureList.size()); + handler->PSendSysMessage("Found " SIZEFMTD " Creatures.", creatureList.size()); uint32 paths = 0; uint32 uStartTime = getMSTime(); -- cgit v1.2.3