diff options
author | thenecromancer <none@none> | 2010-01-23 15:05:33 +0100 |
---|---|---|
committer | thenecromancer <none@none> | 2010-01-23 15:05:33 +0100 |
commit | 39ba392c7538db1bd18e617185c28420780e237c (patch) | |
tree | a620cd4b809816f697697af9478d6e538eb7cc5d | |
parent | 76102c1cdd0fc8bb473f9b3fd3965cea5a3794f6 (diff) | |
parent | d9cb0702158fd045285f2c0a904cb31a45a3864a (diff) |
Merge
--HG--
branch : trunk
115 files changed, 943 insertions, 1725 deletions
@@ -17,6 +17,6 @@ fa27379094e7ef11c253e8653764ec2d25156cd5 stable 0000000000000000000000000000000000000000 stable 0000000000000000000000000000000000000000 stable 078e5dcfcee8902cda1ef698d08b63b697584564 stable -078e5dcfcee8902cda1ef698d08b63b697584564 stable-last-3.1.3 -d1ba3282c63b513e524e567fcb62fa5c17cdb1a6 last-3.1.3 +d1ba3282c63b513e524e567fcb62fa5c17cdb1a6 3.1.3-stable-last 435b8bfb121ee03c36f53aa2f5dddb33d0865ab4 3.2.2a-initial-release +51984508c849874efc937d14993bbe5f73cba5d5 3.2.2a-stable diff --git a/doc/EventAI.txt b/doc/EventAI.txt index cf385643ba0..7d0294da05f 100644 --- a/doc/EventAI.txt +++ b/doc/EventAI.txt @@ -84,7 +84,7 @@ Some events such as EVENT_T_AGGRO, EVENT_T_DEATH, EVENT_T_SPAWNED, and EVENT_T_E 22 EVENT_T_RECEIVE_EMOTE EmoteId, Condition, CondValue1, CondValue2 Expires when a creature receives an emote with emote text id (enum TextEmotes) in (Param1). Conditions can be defined (Param2) with optional values (Param3,Param4), see enum ConditionType. 23 EVENT_T_BUFFED SpellID, AmmountInStack, RepeatMin, RepeatMax Expires when a creature has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4). 24 EVENT_T_TARGET_BUFFED SpellID, AmmountInStack, RepeatMin, RepeatMax Expires when a target unit has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4). - +35 EVENT_T_RESET NONE Expires when creature leaves combat, spawns or respawns. ========================================= Action Types diff --git a/doc/HowToScript.txt b/doc/HowToScript.txt new file mode 100644 index 00000000000..73968a08b19 --- /dev/null +++ b/doc/HowToScript.txt @@ -0,0 +1,27 @@ + +** HOW TO SCRIPT IN C++ ** + +1 - create a file myscript.cpp in scripts folder. +2 - copy the content of script_default.cpp, it as the structure on how the scripting fuctions are organized. + dont forget to change the name of fuctions, like GossipHello_default to GossipHello_myscript. + +3 - in fuction AddSC_default change to AddSC_myscript. +4 - newscript->Name="default"; change the string to "myscript" this name is the one to be called from the db +5 - dont forget to change the name in here to newscript->pGossipHello = &GossipHello_default; this is where the scripted fuctions are stored. +6 - and last thing is in ScriptMgr.cpp + +add your AddSC_myscript in here + +// -- Scripts to be added -- +extern void AddSC_default(); +// ------------------- + +and here + +// -- Inicialize the Scripts to be Added -- + AddSC_default(); +// ---------------------------------------- + +now start using the player fuctions to script ;) + +hope it helps, any question use our forum.
\ No newline at end of file diff --git a/doc/Text-tables.txt b/doc/Text-tables.txt new file mode 100644 index 00000000000..eac63384785 --- /dev/null +++ b/doc/Text-tables.txt @@ -0,0 +1,87 @@ +========================================= +Texts Documentation +========================================= + +Scriptdev2 Revision 695 introduces a new format for using texts in EventAI and SD2 Scripts. +This information relates to the *_texts tables located in the ScriptDev Database. + +Any script can at any time access and use text from any of the three text tables, as long as the entry does in fact exist. +Custom scripters are adviced to store their text data in custom_texts. + +The different tables has ranges of entries allowed for that table. +Reserved EventAI in Mangos entry -1 -> -999999 +script_texts: entry -1000000 -> -1999999 +custom_texts: entry -2000000 -> -2999999 +Any entry out of range for that table will display a startup error. + + +========================================= +Basic Structure of script_texts and custom_texts +========================================= +Below is a the list of current fields within the texts tables. + +Field_Name Description +----------------------------------------------------------- +entry This value is mearly an NEGATIVE identifier of the current text number. Required for sql queries. +content_default This is the actual text presented in the default language (English). + +content_loc1 This is the actual text presented in the Localization #1 Clients (Korean) +content_loc2 This is the actual text presented in the Localization #2 Clients (French) +content_loc3 This is the actual text presented in the Localization #3 Clients (German) +content_loc4 This is the actual text presented in the Localization #4 Clients (Chinese) +content_loc5 This is the actual text presented in the Localization #5 Clients (Taiwanese) +content_loc6 This is the actual text presented in the Localization #6 Clients (Spanish) +content_loc7 This is the actual text presented in the Localization #7 Clients (Spanish Mexico) +content_loc8 This is the actual text presented in the Localization #8 Clients (Russian) + +sound This value is the Sound ID that corresponds to the actual text used (Defined in SoundEntries.dbc). +type Variables used to define type of text (Say/Yell/Textemote/Whisper). +language This value is the Language that the text is native in (Defined in Languages.dbc). +emote Value from enum Emote (defined in Emotes.dbc). Only source of text will play this emote (not target, if target are defined in DoScriptText) +comment This is a comment regarding the text entry (For ACID, accepted format is to use Creature ID of NPC using it). + +Note: Fields `content_loc1` to `content_loc8` are NULL values by default and are handled by seperate localization projects. + + +========================================= +Text Types (type) +========================================= +Below is the list of current Text types that texts tables can handle. These were previously seperate Actions in ACID. + +# Internal Name Description +----------------------------------------------------------- +0 CHAT_TYPE_SAY This type sets the text to be displayed as a Say (Speech Bubble). +1 CHAT_TYPE_YELL This type sets the text to be displayed as a Yell (Red Speech Bubble) and usually has a matching Sound ID. +2 CHAT_TYPE_TEXT_EMOTE This type sets the text to be displayed as a text emote in orange in the chat log. +3 CHAT_TYPE_BOSS_EMOTE This type sets the text to be displayed as a text emote in orange in the chat log (Used only for specific Bosses). +4 CHAT_TYPE_WHISPER This type sets the text to be displayed as a whisper to the player in the chat log. +5 CHAT_TYPE_BOSS_WHISPER This type sets the text to be displayed as a whisper to the player in the chat log (Used only for specific Bosses). +6 CHAT_TYPE_ZONE_YELL Same as CHAT_TYPE_YELL but will display to all players in current zone. + + +========================================= +Language Types (language) +========================================= +Below is the list of current Language types that are allowed. +This is the Race Language that the text is native to (So it will display properly) + +# Internal Name Description +----------------------------------------------------------- +0 UNIVERSAL Text in this language is understood by ALL Races. +1 ORCISH Text in this language is understood ONLY by Horde Races. +2 DARNASSIAN Text in this language is understood ONLY by the Night Elf Race. +3 TAURAHE Text in this language is understood ONLY by the Tauren Race. +6 DWARVISH Text in this language is understood ONLY by the Dwarf Race. +7 COMMON Text in this language is understood ONLY by Alliance Races. +8 DEMONIC Text in this language is understood ONLY by the Demon Race (Not Implimented). +9 TITAN This language was used by Sargeras to speak with other Titians (Not Implemented). +10 THALASSIAN Text in this language is understood ONLY by the Blood Elf Race. +11 DRACONIC Text in this language is understood ONLY by the Dragon Race. +12 KALIMAG Text will display as Kalimag (not readable by players, language of all elementals) +13 GNOMISH Text in this language is understood ONLY by the Gnome Race. +14 TROLL Text in this language is understood ONLY by the Troll Race. +33 GUTTERSPEAK Text in this language is understood ONLY by the Undead Race. +35 DRAENEI Text in this language is understood ONLY by the Draenai Race. +36 ZOMBIE (not currently used?) +37 GNOMISH BINARY Binary language used by Alliance when drinking Binary Brew +38 GOBLIN BINARY Binary language used by Horce when drinking Binary Brew
\ No newline at end of file diff --git a/sql/updates/7139_world_creature_classlevelstats.sql b/sql/updates/7139_world_creature_classlevelstats.sql deleted file mode 100644 index 5dc5eea7233..00000000000 --- a/sql/updates/7139_world_creature_classlevelstats.sql +++ /dev/null @@ -1,406 +0,0 @@ -ALTER TABLE `creature_classlevelstats` -ADD COLUMN `basedmg` float NOT NULL DEFAULT 0 AFTER `basearmor`, -ADD COLUMN `baserangeddmg` float NOT NULL DEFAULT 0 AFTER `basedmg`; - -TRUNCATE `creature_classlevelstats`; -INSERT INTO `creature_classlevelstats` (`level`,`class`,`basehp0`,`basehp1`,`basehp2`,`basemana`,`basearmor`,`basedmg`,`baserangeddmg`) VALUES -(1, 1, 42, 1, 1, 0, 8, 1.25, 1), -(2, 1, 55, 1, 1, 0, 20, 2.5, 2), -(3, 1, 71, 1, 1, 0, 33, 3.75, 3), -(4, 1, 86, 1, 1, 0, 68, 5, 4), -(5, 1, 102, 1, 1, 0, 111, 6.25, 5), -(6, 1, 120, 1, 1, 0, 165, 6.25, 5), -(7, 1, 137, 1, 1, 0, 230, 7.5, 6.25), -(8, 1, 156, 1, 1, 0, 306, 10, 7.5), -(9, 1, 176, 1, 1, 0, 387, 11.25, 8.75), -(10, 1, 198, 1, 1, 0, 463, 12.5, 10), -(11, 1, 222, 1, 1, 0, 528, 15, 11.25), -(12, 1, 247, 1, 1, 0, 562, 16.25, 13.75), -(13, 1, 273, 1, 1, 0, 596, 18.75, 15), -(14, 1, 300, 1, 1, 0, 630, 20, 16.25), -(15, 1, 328, 1, 1, 0, 665, 21.25, 17.5), -(16, 1, 356, 1, 1, 0, 700, 23.75, 18.75), -(17, 1, 386, 1, 1, 0, 734, 25, 20), -(18, 1, 417, 1, 1, 0, 768, 27.5, 21.25), -(19, 1, 449, 1, 1, 0, 802, 28.75, 22.5), -(20, 1, 484, 1, 1, 0, 836, 30, 25), -(21, 1, 521, 1, 1, 0, 872, 32.5, 26.25), -(22, 1, 562, 1, 1, 0, 906, 33.75, 27.5), -(23, 1, 605, 1, 1, 0, 940, 36.25, 28.75), -(24, 1, 651, 1, 1, 0, 975, 37.5, 30), -(25, 1, 699, 1, 1, 0, 1008, 38.75, 31.25), -(26, 1, 750, 1, 1, 0, 1043, 41.25, 32.5), -(27, 1, 800, 1, 1, 0, 1078, 42.5, 33.75), -(28, 1, 853, 1, 1, 0, 1111, 45, 35), -(29, 1, 905, 1, 1, 0, 1145, 46.25, 37.5), -(30, 1, 955, 1, 1, 0, 1179, 47.5, 38.75), -(31, 1, 1006, 1, 1, 0, 1213, 50, 40), -(32, 1, 1057, 1, 1, 0, 1249, 51.25, 41.25), -(33, 1, 1110, 1, 1, 0, 1281, 53.75, 42.5), -(34, 1, 1163, 1, 1, 0, 1317, 55, 43.75), -(35, 1, 1220, 1, 1, 0, 1349, 56.25, 45), -(36, 1, 1277, 1, 1, 0, 1456, 58.75, 46.25), -(37, 1, 1336, 1, 1, 0, 1568, 60, 48.75), -(38, 1, 1395, 1, 1, 0, 1684, 62.5, 50), -(39, 1, 1459, 1, 1, 0, 1808, 63.75, 51.25), -(40, 1, 1524, 1, 1, 0, 1938, 65, 52.5), -(41, 1, 1585, 1, 1, 0, 2074, 68.75, 55), -(42, 1, 1651, 1, 1, 0, 2218, 72.5, 57.5), -(43, 1, 1716, 1, 1, 0, 2369, 75, 60), -(44, 1, 1782, 1, 1, 0, 2528, 78.75, 63.75), -(45, 1, 1848, 1, 1, 0, 2695, 82.5, 66.25), -(46, 1, 1919, 1, 1, 0, 2750, 86.25, 68.75), -(47, 1, 1990, 1, 1, 0, 2804, 90, 71.25), -(48, 1, 2062, 1, 1, 0, 2857, 92.5, 75), -(49, 1, 2138, 1, 1, 0, 2912, 96.25, 77.5), -(50, 1, 2215, 1, 1, 0, 2966, 100, 80), -(51, 1, 2292, 1, 1, 0, 3018, 102.5, 81.25), -(52, 1, 2371, 1, 1, 0, 3060, 103.75, 83.75), -(53, 1, 2453, 1, 1, 0, 3128, 106.25, 85), -(54, 1, 2533, 1, 1, 0, 3180, 107.5, 86.25), -(55, 1, 2614, 1, 1, 0, 3234, 110, 87.5), -(56, 1, 2699, 1, 1, 0, 3289, 112.5, 90), -(57, 1, 2784, 1, 1, 0, 3342, 113.75, 91.25), -(58, 1, 2871, 3989, 1, 0, 3396, 130, 103.75), -(59, 1, 2961, 4142, 1, 0, 3449, 145, 116.25), -(60, 1, 3052, 4979, 1, 0, 3750, 160, 127.5), -(61, 1, 3144, 5158, 1, 0, 4047, 175, 140), -(62, 1, 3237, 5341, 1, 0, 4344, 190, 152.5), -(63, 1, 3331, 5527, 1, 0, 4641, 205, 163.75), -(64, 1, 3427, 5715, 1, 0, 4937, 220, 176.25), -(65, 1, 3524, 5914, 1, 0, 5234, 235, 187.5), -(66, 1, 3624, 6116, 1, 0, 5531, 250, 200), -(67, 1, 3728, 6326, 1, 0, 5829, 265, 212.5), -(68, 1, 3834, 6542, 6986, 0, 6126, 285, 227.5), -(69, 1, 3942, 6761, 7984, 0, 6423, 305, 243.75), -(70, 1, 4050, 6986, 8982, 0, 6719, 325, 260), -(71, 1, 4163, 7181, 9291, 0, 7018, 345, 276.25), -(72, 1, 4278, 7380, 9610, 0, 7318, 365, 292.5), -(73, 1, 4399, 7588, 9940, 0, 7618, 385, 307.5), -(74, 1, 4524, 7804, 10282, 0, 7918, 405, 323.75), -(75, 1, 4652, 8025, 10635, 0, 8219, 425, 340), -(76, 1, 4781, 8247, 11001, 0, 8520, 445, 356.25), -(77, 1, 4916, 8480, 11379, 0, 8822, 465, 372.5), -(78, 1, 5052, 1, 11770, 0, 9124, 485, 387.5), -(79, 1, 5194, 1, 12175, 0, 9426, 505, 403.75), -(80, 1, 5342, 9215, 12600, 0, 9729, 525, 420), -(81, 1, 5496, 1, 13033, 0, 10033, 545, 436.25), -(82, 1, 5647, 1, 13481, 0, 10356, 565, 452.5), -(83, 1, 5808, 1, 13945, 0, 10673, 585, 467.5), -(84, 1, 1, 1, 1, 0, 1, 0, 0), -(85, 1, 1, 1, 1, 0, 1, 0, 0), -(86, 1, 1, 1, 1, 0, 1, 0, 0), -(87, 1, 1, 1, 1, 0, 1, 0, 0), -(88, 1, 1, 1, 1, 0, 1, 0, 0), -(89, 1, 1, 1, 1, 0, 1, 0, 0), -(90, 1, 1, 1, 1, 0, 1, 0, 0), -(91, 1, 1, 1, 1, 0, 1, 0, 0), -(92, 1, 1, 1, 1, 0, 1, 0, 0), -(93, 1, 1, 1, 1, 0, 1, 0, 0), -(94, 1, 1, 1, 1, 0, 1, 0, 0), -(95, 1, 1, 1, 1, 0, 1, 0, 0), -(96, 1, 1, 1, 1, 0, 1, 0, 0), -(97, 1, 1, 1, 1, 0, 1, 0, 0), -(98, 1, 1, 1, 1, 0, 1, 0, 0), -(99, 1, 1, 1, 1, 0, 1, 0, 0), -(100, 1, 1, 1, 1, 0, 1, 0, 0), -(1, 2, 41, 1, 1, 60, 7, 1.25, 1), -(2, 2, 54, 1, 1, 69, 19, 2.5, 2), -(3, 2, 69, 1, 1, 79, 33, 3.75, 3), -(4, 2, 83, 1, 1, 104, 66, 5, 4), -(5, 2, 98, 1, 1, 115, 109, 6.25, 5), -(6, 2, 115, 1, 1, 126, 163, 6.25, 5), -(7, 2, 131, 1, 1, 138, 208, 7.5, 6.25), -(8, 2, 148, 1, 1, 165, 303, 8.75, 7.5), -(9, 2, 166, 1, 1, 178, 369, 11.25, 8.75), -(10, 2, 186, 1, 1, 191, 460, 12.5, 10), -(11, 2, 208, 1, 1, 205, 526, 13.75, 11.25), -(12, 2, 230, 1, 1, 249, 560, 16.25, 12.5), -(13, 2, 253, 1, 1, 264, 596, 17.5, 13.75), -(14, 2, 276, 1, 1, 295, 630, 18.75, 15), -(15, 2, 301, 1, 1, 326, 665, 20, 16.25), -(16, 2, 325, 1, 1, 357, 700, 22.5, 17.5), -(17, 2, 350, 1, 1, 390, 734, 23.75, 18.75), -(18, 2, 377, 1, 1, 408, 768, 25, 20), -(19, 2, 404, 1, 1, 456, 802, 27.5, 21.25), -(20, 2, 433, 1, 1, 490, 836, 28.75, 22.5), -(21, 2, 464, 1, 1, 510, 872, 30, 23.75), -(22, 2, 498, 1, 1, 545, 906, 32.5, 25), -(23, 2, 533, 1, 1, 581, 940, 33.75, 26.25), -(24, 2, 571, 1, 1, 618, 975, 35, 28.75), -(25, 2, 610, 1, 1, 655, 1008, 36.25, 30), -(26, 2, 651, 1, 1, 693, 1042, 38.75, 31.25), -(27, 2, 690, 1, 1, 732, 1078, 40, 32.5), -(28, 2, 732, 1, 1, 756, 1110, 41.25, 33.75), -(29, 2, 773, 1, 1, 811, 1145, 43.75, 35), -(30, 2, 811, 1, 1, 852, 1178, 45, 36.25), -(31, 2, 850, 1, 1, 878, 1213, 46.25, 37.5), -(32, 2, 888, 1, 1, 935, 1248, 48.75, 38.75), -(33, 2, 928, 1, 1, 963, 1281, 50, 40), -(34, 2, 967, 1, 1, 1007, 1316, 51.25, 41.25), -(35, 2, 1009, 1, 1, 1067, 1349, 52.5, 42.5), -(36, 2, 1050, 1, 1, 1097, 1455, 55, 43.75), -(37, 2, 1093, 1, 1, 1142, 1567, 56.25, 45), -(38, 2, 1135, 1, 1, 1189, 1683, 57.5, 46.25), -(39, 2, 1180, 1, 1, 1236, 1807, 60, 47.5), -(40, 2, 1226, 1, 1, 1283, 1937, 61.25, 48.75), -(41, 2, 1268, 1, 1, 1332, 2072, 68.75, 55), -(42, 2, 1321, 1, 1, 1381, 2216, 71.25, 57.5), -(43, 2, 1373, 1, 1, 1432, 2367, 75, 60), -(44, 2, 1426, 1, 1, 1483, 2527, 77.5, 62.5), -(45, 2, 1478, 1, 1, 1534, 2692, 81.25, 65), -(46, 2, 1535, 1, 1, 1587, 2749, 85, 67.5), -(47, 2, 1592, 1, 1, 1640, 2802, 87.5, 70), -(48, 2, 1650, 1, 1, 1695, 2855, 91.25, 72.5), -(49, 2, 1710, 1, 1, 1750, 2910, 93.75, 75), -(50, 2, 1772, 1, 1, 1807, 2964, 97.5, 77.5), -(51, 2, 1834, 1, 1, 1864, 3017, 101.25, 81.25), -(52, 2, 1897, 1, 1, 1923, 3072, 103.75, 82.5), -(53, 2, 1962, 1, 1, 1982, 3126, 105, 85), -(54, 2, 2026, 1, 1, 2041, 3178, 107.5, 86.25), -(55, 2, 2091, 1, 1, 2117, 3232, 108.75, 87.5), -(56, 2, 2159, 1, 1, 2163, 3287, 111.25, 88.75), -(57, 2, 2227, 1, 1, 2241, 3340, 112.5, 90), -(58, 2, 2297, 3191, 1, 2289, 3394, 128.75, 103.75), -(59, 2, 2369, 3314, 1, 2369, 3447, 142.5, 113.75), -(60, 2, 2442, 3984, 1, 2434, 3748, 156.25, 125), -(61, 2, 2515, 4126, 1, 2486, 4044, 171.25, 136.25), -(62, 2, 2590, 4274, 1, 2568, 4340, 185, 147.5), -(63, 2, 2665, 4422, 1, 2620, 4637, 198.75, 158.75), -(64, 2, 2740, 4572, 1, 2705, 4933, 212.5, 170), -(65, 2, 2819, 4731, 1, 2790, 5228, 226.25, 181.25), -(66, 2, 2899, 4892, 6116, 2846, 5523, 240, 192.5), -(67, 2, 2982, 5060, 1, 2933, 5821, 255, 203.75), -(68, 2, 3067, 5233, 6986, 2991, 6116, 283.75, 227.5), -(69, 2, 3153, 5409, 7984, 3080, 6412, 302.5, 241.25), -(70, 2, 3240, 5589, 8982, 3155, 6708, 321.25, 256.25), -(71, 2, 3330, 5744, 9291, 3231, 7007, 340, 271.25), -(72, 2, 3422, 5903, 9610, 3309, 7305, 357.5, 286.25), -(73, 2, 3519, 6070, 9940, 3387, 7604, 376.25, 301.25), -(74, 2, 3619, 1, 10282, 3466, 7903, 395, 316.25), -(75, 2, 3722, 6420, 10635, 3561, 8204, 413.75, 331.25), -(76, 2, 3825, 1, 11001, 3643, 8503, 432.5, 346.25), -(77, 2, 3933, 1, 11379, 3725, 8803, 451.25, 361.25), -(78, 2, 4042, 1, 11770, 3809, 9104, 470, 376.25), -(79, 2, 4155, 1, 12175, 3893, 9405, 488.75, 390), -(80, 2, 4274, 1, 12600, 3994, 9706, 506.25, 405), -(81, 2, 4394, 1, 13033, 4081, 10007, 525, 420), -(82, 2, 4518, 1, 13481, 4169, 10253, 543.75, 435), -(83, 2, 4646, 1, 13945, 4258, 10573, 562.5, 450), -(84, 2, 1, 1, 1, 1, 1, 0, 0), -(85, 2, 1, 1, 1, 1, 1, 0, 0), -(86, 2, 1, 1, 1, 1, 1, 0, 0), -(87, 2, 1, 1, 1, 1, 1, 0, 0), -(88, 2, 1, 1, 1, 1, 1, 0, 0), -(89, 2, 1, 1, 1, 1, 1, 0, 0), -(90, 2, 1, 1, 1, 1, 1, 0, 0), -(91, 2, 1, 1, 1, 1, 1, 0, 0), -(92, 2, 1, 1, 1, 1, 1, 0, 0), -(93, 2, 1, 1, 1, 1, 1, 0, 0), -(94, 2, 1, 1, 1, 1, 1, 0, 0), -(95, 2, 1, 1, 1, 1, 1, 0, 0), -(96, 2, 1, 1, 1, 1, 1, 0, 0), -(97, 2, 1, 1, 1, 1, 1, 0, 0), -(98, 2, 1, 1, 1, 1, 1, 0, 0), -(99, 2, 1, 1, 1, 1, 1, 0, 0), -(100, 2, 1, 1, 1, 1, 1, 0, 0), -(1, 4, 42, 1, 1, 0, 6, 1.25, 1), -(2, 4, 55, 1, 1, 0, 18, 2.5, 2), -(3, 4, 71, 1, 1, 0, 31, 3.75, 3), -(4, 4, 86, 1, 1, 0, 63, 5, 4), -(5, 4, 102, 1, 1, 0, 102, 6.25, 5), -(6, 4, 120, 1, 1, 0, 152, 6.25, 5), -(7, 4, 137, 1, 1, 0, 212, 7.5, 6.25), -(8, 4, 156, 1, 1, 0, 286, 8.75, 7.5), -(9, 4, 176, 1, 1, 0, 363, 10, 7.5), -(10, 4, 198, 1, 1, 0, 443, 11.25, 8.75), -(11, 4, 222, 1, 1, 0, 488, 12.5, 10), -(12, 4, 247, 1, 1, 0, 519, 15, 11.25), -(13, 4, 273, 1, 1, 0, 553, 16.25, 12.5), -(14, 4, 300, 1, 1, 0, 577, 17.5, 13.75), -(15, 4, 328, 1, 1, 0, 612, 18.75, 15), -(16, 4, 356, 1, 1, 0, 645, 20, 16.25), -(17, 4, 386, 1, 1, 0, 676, 21.25, 17.5), -(18, 4, 417, 1, 1, 0, 706, 23.75, 18.75), -(19, 4, 449, 1, 1, 0, 738, 25, 20), -(20, 4, 484, 1, 1, 0, 769, 26.25, 21.25), -(21, 4, 521, 1, 1, 0, 801, 27.5, 22.5), -(22, 4, 562, 1, 1, 0, 833, 28.75, 23.75), -(23, 4, 605, 1, 1, 0, 863, 30, 23.75), -(24, 4, 651, 1, 1, 0, 895, 31.25, 25), -(25, 4, 699, 1, 1, 0, 926, 33.75, 26.25), -(26, 4, 750, 1, 1, 0, 957, 35, 27.5), -(27, 4, 800, 1, 1, 0, 989, 36.25, 28.75), -(28, 4, 853, 1, 1, 0, 1020, 37.5, 30), -(29, 4, 905, 1, 1, 0, 1051, 38.75, 31.25), -(30, 4, 955, 1, 1, 0, 1082, 40, 32.5), -(31, 4, 1006, 1, 1, 0, 1113, 42.5, 33.75), -(32, 4, 1057, 1, 1, 0, 1146, 43.75, 35), -(33, 4, 1110, 1, 1, 0, 1173, 45, 36.25), -(34, 4, 1163, 1, 1, 0, 1208, 46.25, 37.5), -(35, 4, 1220, 1, 1, 0, 1237, 47.5, 38.75), -(36, 4, 1277, 1, 1, 0, 1349, 48.75, 40), -(37, 4, 1336, 1, 1, 0, 1434, 51.25, 40), -(38, 4, 1395, 1, 1, 0, 1538, 52.5, 41.25), -(39, 4, 1459, 1, 1, 0, 1649, 53.75, 42.5), -(40, 4, 1524, 1, 1, 0, 1764, 55, 43.75), -(41, 4, 1585, 1, 1, 0, 1886, 67.5, 53.75), -(42, 4, 1651, 1, 1, 0, 2015, 71.25, 56.25), -(43, 4, 1716, 1, 1, 0, 2148, 73.75, 58.75), -(44, 4, 1782, 1, 1, 0, 2303, 76.25, 61.25), -(45, 4, 1848, 1, 1, 0, 2436, 80, 63.75), -(46, 4, 1919, 1, 1, 0, 2485, 82.5, 66.25), -(47, 4, 1990, 1, 1, 0, 2535, 85, 68.75), -(48, 4, 2062, 1, 1, 0, 2582, 88.75, 70), -(49, 4, 2138, 1, 1, 0, 2631, 91.25, 72.5), -(50, 4, 2215, 1, 1, 0, 2680, 93.75, 75), -(51, 4, 2292, 1, 1, 0, 2728, 101.25, 81.25), -(52, 4, 2371, 1, 1, 0, 2778, 103.75, 82.5), -(53, 4, 2453, 1, 1, 0, 2826, 105, 83.75), -(54, 4, 2533, 1, 1, 0, 2874, 106.25, 85), -(55, 4, 2614, 1, 1, 0, 2922, 108.75, 86.25), -(56, 4, 2699, 1, 1, 0, 2972, 110, 87.5), -(57, 4, 2784, 1, 1, 0, 3020, 111.25, 88.75), -(58, 4, 2871, 3989, 1, 0, 3068, 127.5, 102.5), -(59, 4, 2961, 4142, 1, 0, 3117, 140, 112.5), -(60, 4, 3052, 4979, 1, 0, 3388, 152.5, 122.5), -(61, 4, 3144, 5158, 1, 0, 3655, 165, 131.25), -(62, 4, 3237, 5341, 1, 0, 3922, 177.5, 141.25), -(63, 4, 3331, 5527, 1, 0, 4189, 190, 151.25), -(64, 4, 3427, 5715, 1, 0, 4457, 202.5, 161.25), -(65, 4, 3524, 5914, 1, 0, 4724, 215, 171.25), -(66, 4, 3624, 6116, 1, 0, 5104, 227.5, 181.25), -(67, 4, 3728, 6326, 1, 0, 5326, 240, 191.25), -(68, 4, 3834, 6542, 6986, 0, 5527, 281.25, 225), -(69, 4, 3942, 6761, 7984, 0, 5795, 298.75, 238.75), -(70, 4, 4050, 6986, 8982, 0, 6062, 315, 251.25), -(71, 4, 4163, 7181, 9291, 0, 6332, 331.25, 265), -(72, 4, 4278, 7380, 9610, 0, 6602, 347.5, 278.75), -(73, 4, 4399, 7580, 9940, 0, 6872, 365, 291.25), -(74, 4, 4524, 1, 10282, 0, 7143, 381.25, 305), -(75, 4, 4652, 1, 10635, 0, 7415, 397.5, 318.75), -(76, 4, 4781, 1, 11001, 0, 7686, 415, 331.25), -(77, 4, 4916, 1, 11379, 0, 7958, 431.25, 345), -(78, 4, 5052, 1, 11770, 0, 8230, 447.5, 357.5), -(79, 4, 5194, 1, 12175, 0, 8503, 463.75, 371.25), -(80, 4, 5342, 1, 12600, 0, 8776, 481.25, 385), -(81, 4, 5496, 1, 13033, 0, 9068, 497.5, 397.5), -(82, 4, 5647, 1, 13481, 0, 9348, 513.75, 411.25), -(83, 4, 5808, 1, 13945, 0, 9589, 530, 425), -(84, 4, 1, 1, 1, 0, 1, 0, 0), -(85, 4, 1, 1, 1, 0, 1, 0, 0), -(86, 4, 1, 1, 1, 0, 1, 0, 0), -(87, 4, 1, 1, 1, 0, 1, 0, 0), -(88, 4, 1, 1, 1, 0, 1, 0, 0), -(89, 4, 1, 1, 1, 0, 1, 0, 0), -(90, 4, 1, 1, 1, 0, 1, 0, 0), -(91, 4, 1, 1, 1, 0, 1, 0, 0), -(92, 4, 1, 1, 1, 0, 1, 0, 0), -(93, 4, 1, 1, 1, 0, 1, 0, 0), -(94, 4, 1, 1, 1, 0, 1, 0, 0), -(95, 4, 1, 1, 1, 0, 1, 0, 0), -(96, 4, 1, 1, 1, 0, 1, 0, 0), -(97, 4, 1, 1, 1, 0, 1, 0, 0), -(98, 4, 1, 1, 1, 0, 1, 0, 0), -(99, 4, 1, 1, 1, 0, 1, 0, 0), -(100, 4, 1, 1, 1, 0, 1, 0, 0), -(1, 8, 40, 1, 1, 120, 5, 1.25, 1), -(2, 8, 52, 1, 1, 147, 16, 2.5, 2), -(3, 8, 67, 1, 1, 174, 28, 3.75, 3), -(4, 8, 81, 1, 1, 202, 57, 5, 4), -(5, 8, 95, 1, 1, 230, 93, 6.25, 5), -(6, 8, 111, 1, 1, 259, 139, 5, 5), -(7, 8, 126, 1, 1, 289, 194, 6.25, 5), -(8, 8, 143, 1, 1, 319, 265, 7.5, 6.25), -(9, 8, 160, 1, 1, 350, 339, 8.75, 7.5), -(10, 8, 178, 1, 1, 382, 423, 11.25, 8.75), -(11, 8, 199, 1, 1, 459, 447, 12.5, 10), -(12, 8, 219, 1, 1, 537, 475, 13.75, 10), -(13, 8, 241, 1, 1, 601, 509, 15, 11.25), -(14, 8, 263, 1, 1, 710, 523, 16.25, 12.5), -(15, 8, 285, 1, 1, 790, 559, 17.5, 13.75), -(16, 8, 307, 1, 1, 856, 589, 18.75, 15), -(17, 8, 330, 1, 1, 938, 617, 20, 16.25), -(18, 8, 354, 1, 1, 1020, 643, 21.25, 16.25), -(19, 8, 379, 1, 1, 1118, 674, 22.5, 17.5), -(20, 8, 405, 1, 1, 1202, 701, 23.75, 18.75), -(21, 8, 432, 1, 1, 1272, 729, 25, 20), -(22, 8, 463, 1, 1, 1357, 759, 26.25, 21.25), -(23, 8, 494, 1, 1, 1443, 786, 27.5, 21.25), -(24, 8, 528, 1, 1, 1545, 815, 28.75, 22.5), -(25, 8, 562, 1, 1, 1633, 843, 30, 23.75), -(26, 8, 598, 1, 1, 1707, 871, 31.25, 25), -(27, 8, 633, 1, 1, 1812, 900, 32.5, 26.25), -(28, 8, 669, 1, 1, 1977, 928, 33.75, 27.5), -(29, 8, 704, 1, 1, 2068, 957, 35, 27.5), -(30, 8, 737, 1, 1, 2175, 984, 36.25, 28.75), -(31, 8, 770, 1, 1, 2253, 1012, 37.5, 30), -(32, 8, 802, 1, 1, 2362, 1042, 38.75, 31.25), -(33, 8, 835, 1, 1, 2457, 1065, 40, 32.5), -(34, 8, 867, 1, 1, 2553, 1098, 41.25, 32.5), -(35, 8, 902, 1, 1, 2680, 1124, 42.5, 33.75), -(36, 8, 935, 1, 1, 2763, 1241, 43.75, 35), -(37, 8, 970, 1, 1, 2861, 1300, 45, 36.25), -(38, 8, 1004, 1, 1, 2975, 1391, 46.25, 37.5), -(39, 8, 1040, 1, 1, 3075, 1489, 47.5, 38.75), -(40, 8, 1077, 1, 1, 3191, 1590, 48.75, 38.75), -(41, 8, 1110, 1, 1, 3293, 1697, 67.5, 53.75), -(42, 8, 1156, 1, 1, 3471, 1811, 70, 56.25), -(43, 8, 1201, 1, 1, 3575, 1926, 72.5, 58.75), -(44, 8, 1247, 1, 1, 3680, 2078, 75, 60), -(45, 8, 1294, 1, 1, 3801, 2177, 77.5, 62.5), -(46, 8, 1343, 1, 1, 3923, 2220, 80, 63.75), -(47, 8, 1393, 1, 1, 4031, 2265, 82.5, 66.25), -(48, 8, 1443, 1, 1, 4140, 2307, 85, 68.75), -(49, 8, 1497, 1, 1, 4281, 2349, 87.5, 70), -(50, 8, 1551, 1, 1, 4393, 2393, 90, 72.5), -(51, 8, 1604, 1, 1, 4506, 2437, 101.25, 81.25), -(52, 8, 1660, 1, 1, 4650, 2481, 102.5, 82.5), -(53, 8, 1717, 1, 1, 4765, 2524, 105, 83.75), -(54, 8, 1773, 1, 1, 4896, 2567, 106.25, 85), -(55, 8, 1830, 1, 1, 5013, 2609, 107.5, 86.25), -(56, 8, 1889, 1, 1, 5206, 2654, 108.75, 87.5), -(57, 8, 1949, 1, 1, 5340, 2698, 110, 88.75), -(58, 8, 2010, 2793, 1, 5461, 2740, 126.25, 101.25), -(59, 8, 2073, 2899, 1, 5598, 2784, 137.5, 110), -(60, 8, 2136, 3484, 1, 5751, 3025, 147.5, 118.75), -(61, 8, 2201, 3611, 1, 5875, 3263, 158.75, 127.5), -(62, 8, 2266, 3739, 1, 6015, 3500, 170, 136.25), -(63, 8, 2332, 3870, 1, 6156, 3736, 181.25, 145), -(64, 8, 2399, 4000, 1, 6229, 3977, 191.25, 153.75), -(65, 8, 2467, 4140, 4731, 6443, 4214, 202.5, 162.5), -(66, 8, 2552, 4281, 4892, 6588, 4460, 213.75, 171.25), -(67, 8, 2610, 4429, 1, 6749, 4710, 225, 180), -(68, 8, 2684, 4580, 5588, 6882, 4928, 280, 223.75), -(69, 8, 2759, 4733, 6387, 7031, 5167, 293.75, 235), -(70, 8, 2835, 4890, 7185, 7196, 5404, 308.75, 247.5), -(71, 8, 2914, 5027, 7432, 7332, 5645, 323.75, 258.75), -(72, 8, 2995, 5166, 7688, 7500, 5886, 337.5, 270), -(73, 8, 3098, 5311, 7952, 7654, 6126, 352.5, 282.5), -(74, 8, 3186, 1, 8225, 7809, 6368, 367.5, 293.75), -(75, 8, 3256, 5617, 8508, 7981, 6610, 381.25, 305), -(76, 8, 3367, 1, 8800, 8139, 6851, 396.25, 317.5), -(77, 8, 3462, 1, 9103, 8313, 7094, 411.25, 328.75), -(78, 8, 3558, 1, 9416, 8459, 7335, 425, 340), -(79, 8, 3658, 1, 9740, 8636, 7579, 440, 352.5), -(80, 8, 3739, 1, 10080, 8814, 7822, 455, 363.75), -(81, 8, 3870, 1, 10486, 8979, 8102, 470, 375), -(82, 8, 3977, 1, 10784, 9160, 8340, 483.75, 387.5), -(83, 8, 4090, 1, 11156, 9325, 8505, 498.75, 398.75), -(84, 8, 1, 1, 1, 1, 1, 0, 0), -(85, 8, 1, 1, 1, 1, 1, 0, 0), -(86, 8, 1, 1, 1, 1, 1, 0, 0), -(87, 8, 1, 1, 1, 1, 1, 0, 0), -(88, 8, 1, 1, 1, 1, 1, 0, 0), -(89, 8, 1, 1, 1, 1, 1, 0, 0), -(90, 8, 1, 1, 1, 1, 1, 0, 0), -(91, 8, 1, 1, 1, 1, 1, 0, 0), -(92, 8, 1, 1, 1, 1, 1, 0, 0), -(93, 8, 1, 1, 1, 1, 1, 0, 0), -(94, 8, 1, 1, 1, 1, 1, 0, 0), -(95, 8, 1, 1, 1, 1, 1, 0, 0), -(96, 8, 1, 1, 1, 1, 1, 0, 0), -(97, 8, 1, 1, 1, 1, 1, 0, 0), -(98, 8, 1, 1, 1, 1, 1, 0, 0), -(99, 8, 1, 1, 1, 1, 1, 0, 0), -(100, 8, 1, 1, 1, 1, 1, 0, 0);
\ No newline at end of file diff --git a/sql/updates/7139_world_creature_template.sql b/sql/updates/7139_world_creature_template.sql deleted file mode 100644 index 808df5b5dbc..00000000000 --- a/sql/updates/7139_world_creature_template.sql +++ /dev/null @@ -1,11 +0,0 @@ -ALTER TABLE `creature_template` -DROP COLUMN `mindmg`, -DROP COLUMN `maxdmg`, -DROP COLUMN `attackpower`, -DROP COLUMN `minrangedmg`, -DROP COLUMN `maxrangedmg`, -DROP COLUMN `rangedattackpower`; - -ALTER TABLE `creature_template` -ADD COLUMN `Dmg_Mod` float NOT NULL DEFAULT 1 AFTER `Armor_Mod`, -ADD COLUMN `Rangeddmg_Mod` float NOT NULL DEFAULT 1 AFTER `Dmg_Mod`; diff --git a/sql/updates/7147_world_creature_classlevelstats.sql b/sql/updates/7147_world_creature_classlevelstats.sql new file mode 100644 index 00000000000..6b10bb9806c --- /dev/null +++ b/sql/updates/7147_world_creature_classlevelstats.sql @@ -0,0 +1,4 @@ +ALTER TABLE `creature_classlevelstats` +DROP COLUMN `basedmg`, +DROP COLUMN `baserangeddmg`; + diff --git a/sql/updates/7147_world_creature_template.sql b/sql/updates/7147_world_creature_template.sql new file mode 100644 index 00000000000..7202edab18a --- /dev/null +++ b/sql/updates/7147_world_creature_template.sql @@ -0,0 +1,10 @@ +ALTER TABLE `creature_template` +DROP COLUMN `dmg_Mod`, +DROP COLUMN `rangeddmg_Mod`, +ADD COLUMN `mindmg` float NOT NULL DEFAULT '0' AFTER `rank`, +ADD COLUMN `maxdmg` float NOT NULL DEFAULT '0' AFTER `mindmg`, +ADD COLUMN `attackpower` int(10) unsigned NOT NULL DEFAULT '0' AFTER `dmgschool`, +ADD COLUMN `minrangedmg` float NOT NULL DEFAULT '0' AFTER `trainer_race`, +ADD COLUMN `maxrangedmg` float NOT NULL DEFAULT '0' AFTER `minrangedmg`, +ADD COLUMN `rangedattackpower` smallint(5) unsigned NOT NULL DEFAULT '0' AFTER `maxrangedmg`; + diff --git a/src/framework/Utilities/Callback.h b/src/framework/Utilities/Callback.h index 0e58bfa0c56..d2e2c36851a 100644 --- a/src/framework/Utilities/Callback.h +++ b/src/framework/Utilities/Callback.h @@ -269,6 +269,7 @@ namespace Trinity /// ---------- QUERY CALLBACKS ----------- +#include "QueryResult.h" class QueryResult; namespace Trinity @@ -278,8 +279,8 @@ namespace Trinity public: virtual void Execute() = 0; virtual ~IQueryCallback() {} - virtual void SetResult(QueryResult* result) = 0; - virtual QueryResult* GetResult() = 0; + virtual void SetResult(QueryResult_AutoPtr result) = 0; + virtual QueryResult_AutoPtr GetResult() = 0; }; template < class CB > @@ -288,50 +289,50 @@ namespace Trinity public: _IQueryCallback(CB const& cb) : CB(cb) {} void Execute() { CB::_Execute(); } - void SetResult(QueryResult* result) { CB::m_param1 = result; } - QueryResult* GetResult() { return CB::m_param1; } + void SetResult(QueryResult_AutoPtr result) { CB::m_param1 = result; } + QueryResult_AutoPtr GetResult() { return CB::m_param1; } }; template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void > class QueryCallback : - public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1, ParamType2, ParamType3 > > + public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > > { private: - typedef _Callback < Class, QueryResult*, ParamType1, ParamType2, ParamType3 > QC3; + typedef _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > QC3; public: - QueryCallback(Class *object, typename QC3::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2, ParamType3 param3) + QueryCallback(Class *object, typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3) : _IQueryCallback< QC3 >(QC3(object, method, result, param1, param2, param3)) {} }; template < class Class, typename ParamType1, typename ParamType2 > class QueryCallback < Class, ParamType1, ParamType2 > : - public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1, ParamType2 > > + public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2 > > { private: - typedef _Callback < Class, QueryResult*, ParamType1, ParamType2 > QC2; + typedef _Callback < Class, QueryResult_AutoPtr, ParamType1, ParamType2 > QC2; public: - QueryCallback(Class *object, typename QC2::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2) + QueryCallback(Class *object, typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2) : _IQueryCallback< QC2 >(QC2(object, method, result, param1, param2)) {} }; template < class Class, typename ParamType1 > class QueryCallback < Class, ParamType1 > : - public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1 > > + public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr, ParamType1 > > { private: - typedef _Callback < Class, QueryResult*, ParamType1 > QC1; + typedef _Callback < Class, QueryResult_AutoPtr, ParamType1 > QC1; public: - QueryCallback(Class *object, typename QC1::Method method, QueryResult* result, ParamType1 param1) + QueryCallback(Class *object, typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1) : _IQueryCallback< QC1 >(QC1(object, method, result, param1)) {} }; template < class Class > - class QueryCallback < Class > : public _IQueryCallback< _Callback < Class, QueryResult* > > + class QueryCallback < Class > : public _IQueryCallback< _Callback < Class, QueryResult_AutoPtr > > { private: - typedef _Callback < Class, QueryResult* > QC0; + typedef _Callback < Class, QueryResult_AutoPtr > QC0; public: - QueryCallback(Class *object, typename QC0::Method method, QueryResult* result) + QueryCallback(Class *object, typename QC0::Method method, QueryResult_AutoPtr result) : _IQueryCallback< QC0 >(QC0(object, method, result)) {} }; @@ -339,44 +340,44 @@ namespace Trinity template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void > class SQueryCallback : - public _IQueryCallback< _SCallback < QueryResult*, ParamType1, ParamType2, ParamType3 > > + public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > > { private: - typedef _SCallback < QueryResult*, ParamType1, ParamType2, ParamType3 > QC3; + typedef _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3 > QC3; public: - SQueryCallback(typename QC3::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2, ParamType3 param3) + SQueryCallback(typename QC3::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2, ParamType3 param3) : _IQueryCallback< QC3 >(QC3(method, result, param1, param2, param3)) {} }; template < typename ParamType1, typename ParamType2 > class SQueryCallback < ParamType1, ParamType2 > : - public _IQueryCallback< _SCallback < QueryResult*, ParamType1, ParamType2 > > + public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2 > > { private: - typedef _SCallback < QueryResult*, ParamType1, ParamType2 > QC2; + typedef _SCallback < QueryResult_AutoPtr, ParamType1, ParamType2 > QC2; public: - SQueryCallback(typename QC2::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2) + SQueryCallback(typename QC2::Method method, QueryResult_AutoPtr result, ParamType1 param1, ParamType2 param2) : _IQueryCallback< QC2 >(QC2(method, result, param1, param2)) {} }; template < typename ParamType1 > class SQueryCallback < ParamType1 > : - public _IQueryCallback< _SCallback < QueryResult*, ParamType1 > > + public _IQueryCallback< _SCallback < QueryResult_AutoPtr, ParamType1 > > { private: - typedef _SCallback < QueryResult*, ParamType1 > QC1; + typedef _SCallback < QueryResult_AutoPtr, ParamType1 > QC1; public: - SQueryCallback(typename QC1::Method method, QueryResult* result, ParamType1 param1) + SQueryCallback(typename QC1::Method method, QueryResult_AutoPtr result, ParamType1 param1) : _IQueryCallback< QC1 >(QC1(method, result, param1)) {} }; template < > - class SQueryCallback < > : public _IQueryCallback< _SCallback < QueryResult* > > + class SQueryCallback < > : public _IQueryCallback< _SCallback < QueryResult_AutoPtr > > { private: - typedef _SCallback < QueryResult* > QC0; + typedef _SCallback < QueryResult_AutoPtr > QC0; public: - SQueryCallback(QC0::Method method, QueryResult* result) + SQueryCallback(QC0::Method method, QueryResult_AutoPtr result) : _IQueryCallback< QC0 >(QC0(method, result)) {} }; } diff --git a/src/game/AccountMgr.cpp b/src/game/AccountMgr.cpp index 4b186725451..40b1291397c 100644 --- a/src/game/AccountMgr.cpp +++ b/src/game/AccountMgr.cpp @@ -59,10 +59,9 @@ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string pass AccountOpResult AccountMgr::DeleteAccount(uint32 accid) { - QueryResult *result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid); if(!result) return AOR_NAME_NOT_EXIST; // account doesn't exist - delete result; result = CharacterDatabase.PQuery("SELECT guid FROM characters WHERE account='%d'",accid); if (result) @@ -83,8 +82,6 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid) Player::DeleteFromDB(guid, accid, false); // no need to update realm characters } while (result->NextRow()); - - delete result; } // table realm specific but common for all characters of account for realm @@ -108,10 +105,9 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid) AccountOpResult AccountMgr::ChangeUsername(uint32 accid, std::string new_uname, std::string new_passwd) { - QueryResult *result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid); if(!result) return AOR_NAME_NOT_EXIST; // account doesn't exist - delete result; if(utf8length(new_uname) > MAX_ACCOUNT_STR) return AOR_NAME_TOO_LONG; @@ -156,24 +152,22 @@ AccountOpResult AccountMgr::ChangePassword(uint32 accid, std::string new_passwd) uint32 AccountMgr::GetId(std::string username) { loginDatabase.escape_string(username); - QueryResult *result = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", username.c_str()); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", username.c_str()); if(!result) return 0; else { uint32 id = (*result)[0].GetUInt32(); - delete result; return id; } } uint32 AccountMgr::GetSecurity(uint32 acc_id) { - QueryResult *result = loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u'", acc_id); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u'", acc_id); if(result) { uint32 sec = (*result)[0].GetUInt32(); - delete result; return sec; } @@ -182,13 +176,12 @@ uint32 AccountMgr::GetSecurity(uint32 acc_id) uint32 AccountMgr::GetSecurity(uint32 acc_id, int32 realm_id) { - QueryResult *result = (realm_id == -1) + QueryResult_AutoPtr result = (realm_id == -1) ? loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u' AND RealmID = '%d'", acc_id, realm_id) : loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", acc_id, realm_id); if(result) { uint32 sec = (*result)[0].GetUInt32(); - delete result; return sec; } @@ -197,11 +190,10 @@ uint32 AccountMgr::GetSecurity(uint32 acc_id, int32 realm_id) bool AccountMgr::GetName(uint32 acc_id, std::string &name) { - QueryResult *result = loginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id); if(result) { name = (*result)[0].GetCppString(); - delete result; return true; } @@ -217,12 +209,9 @@ bool AccountMgr::CheckPassword(uint32 accid, std::string passwd) normalizeString(username); normalizeString(passwd); - QueryResult *result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d' AND sha_pass_hash='%s'", accid, CalculateShaPassHash(username, passwd).c_str()); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d' AND sha_pass_hash='%s'", accid, CalculateShaPassHash(username, passwd).c_str()); if (result) - { - delete result; return true; - } return false; } diff --git a/src/game/AchievementMgr.cpp b/src/game/AchievementMgr.cpp index 17818f9dfa3..66c5b2ecd30 100644 --- a/src/game/AchievementMgr.cpp +++ b/src/game/AchievementMgr.cpp @@ -535,7 +535,7 @@ void AchievementMgr::SaveToDB() } } -void AchievementMgr::LoadFromDB(QueryResult *achievementResult, QueryResult *criteriaResult) +void AchievementMgr::LoadFromDB(QueryResult_AutoPtr achievementResult, QueryResult_AutoPtr criteriaResult) { if(achievementResult) { @@ -553,7 +553,6 @@ void AchievementMgr::LoadFromDB(QueryResult *achievementResult, QueryResult *cri ca.date = time_t(fields[1].GetUInt64()); ca.changed = false; } while(achievementResult->NextRow()); - delete achievementResult; } if(criteriaResult) @@ -583,7 +582,6 @@ void AchievementMgr::LoadFromDB(QueryResult *achievementResult, QueryResult *cri progress.date = date; progress.changed = false; } while(criteriaResult->NextRow()); - delete criteriaResult; } } @@ -1937,7 +1935,7 @@ void AchievementGlobalMgr::LoadAchievementCriteriaData() { m_criteriaDataMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT criteria_id, type, value1, value2 FROM achievement_criteria_data"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT criteria_id, type, value1, value2 FROM achievement_criteria_data"); if(!result) { @@ -1988,8 +1986,6 @@ void AchievementGlobalMgr::LoadAchievementCriteriaData() ++count; } while(result->NextRow()); - delete result; - // post loading checks for (uint32 entryId = 0; entryId < sAchievementCriteriaStore.GetNumRows(); ++entryId) { @@ -2061,7 +2057,7 @@ void AchievementGlobalMgr::LoadAchievementCriteriaData() void AchievementGlobalMgr::LoadCompletedAchievements() { - QueryResult *result = CharacterDatabase.Query("SELECT achievement FROM character_achievement GROUP BY achievement"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT achievement FROM character_achievement GROUP BY achievement"); if(!result) { @@ -2091,8 +2087,6 @@ void AchievementGlobalMgr::LoadCompletedAchievements() m_allCompletedAchievements.insert(achievement_id); } while(result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %lu realm completed achievements.",(unsigned long)m_allCompletedAchievements.size()); } @@ -2102,7 +2096,7 @@ void AchievementGlobalMgr::LoadRewards() m_achievementRewards.clear(); // need for reload case // 0 1 2 3 4 5 6 - QueryResult *result = WorldDatabase.Query("SELECT entry, title_A, title_H, item, sender, subject, text FROM achievement_reward"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, title_A, title_H, item, sender, subject, text FROM achievement_reward"); if(!result) { @@ -2203,8 +2197,6 @@ void AchievementGlobalMgr::LoadRewards() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u achievement rewards", count ); } @@ -2213,7 +2205,7 @@ void AchievementGlobalMgr::LoadRewardLocales() { m_achievementRewardLocales.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry,subject_loc1,text_loc1,subject_loc2,text_loc2,subject_loc3,text_loc3,subject_loc4,text_loc4,subject_loc5,text_loc5,subject_loc6,text_loc6,subject_loc7,text_loc7,subject_loc8,text_loc8 FROM locales_achievement_reward"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,subject_loc1,text_loc1,subject_loc2,text_loc2,subject_loc3,text_loc3,subject_loc4,text_loc4,subject_loc5,text_loc5,subject_loc6,text_loc6,subject_loc7,text_loc7,subject_loc8,text_loc8 FROM locales_achievement_reward"); if (!result) { @@ -2273,8 +2265,6 @@ void AchievementGlobalMgr::LoadRewardLocales() } } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu achievement reward locale strings", (unsigned long)m_achievementRewardLocales.size() ); } diff --git a/src/game/AchievementMgr.h b/src/game/AchievementMgr.h index 4e7ce2495a0..11473653fe7 100644 --- a/src/game/AchievementMgr.h +++ b/src/game/AchievementMgr.h @@ -232,7 +232,7 @@ class AchievementMgr void Reset(); static void DeleteFromDB(uint32 lowguid); - void LoadFromDB(QueryResult *achievementResult, QueryResult *criteriaResult); + void LoadFromDB(QueryResult_AutoPtr achievementResult, QueryResult_AutoPtr criteriaResult); void SaveToDB(); void ResetAchievementCriteria(AchievementCriteriaTypes type, uint32 miscvalue1=0, uint32 miscvalue2=0); void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscvalue1=0, uint32 miscvalue2=0, Unit *unit=NULL, uint32 time=0); diff --git a/src/game/AddonMgr.cpp b/src/game/AddonMgr.cpp index 15d5633f2cb..9116f504a1d 100644 --- a/src/game/AddonMgr.cpp +++ b/src/game/AddonMgr.cpp @@ -42,7 +42,7 @@ AddonMgr::~AddonMgr() void AddonMgr::LoadFromDB() { - QueryResult* result = CharacterDatabase.PQuery("SELECT name, crc FROM addons"); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name, crc FROM addons"); if(!result) { sLog.outErrorDb("The table `addons` is empty"); @@ -68,8 +68,6 @@ void AddonMgr::LoadFromDB() m_knownAddons.push_back(addon); } while(result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u known addons", count); } diff --git a/src/game/ArenaTeam.cpp b/src/game/ArenaTeam.cpp index 1d9669007fc..320d8aa6b98 100644 --- a/src/game/ArenaTeam.cpp +++ b/src/game/ArenaTeam.cpp @@ -116,13 +116,12 @@ bool ArenaTeam::AddMember(const uint64& PlayerGuid) else { // 0 1 - QueryResult *result = CharacterDatabase.PQuery("SELECT name, class FROM characters WHERE guid='%u'", GUID_LOPART(PlayerGuid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name, class FROM characters WHERE guid='%u'", GUID_LOPART(PlayerGuid)); if(!result) return false; plName = (*result)[0].GetCppString(); plClass = (*result)[1].GetUInt8(); - delete result; // check if player already in arenateam of that size if(Player::GetArenaTeamIdFromDB(PlayerGuid, GetType()) != 0) @@ -175,7 +174,7 @@ bool ArenaTeam::AddMember(const uint64& PlayerGuid) bool ArenaTeam::LoadArenaTeamFromDB(uint32 ArenaTeamId) { - QueryResult *result = CharacterDatabase.PQuery("SELECT arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,EmblemColor,BorderStyle,BorderColor FROM arena_team WHERE arenateamid = '%u'", ArenaTeamId); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,EmblemColor,BorderStyle,BorderColor FROM arena_team WHERE arenateamid = '%u'", ArenaTeamId); if(!result) return false; @@ -192,8 +191,6 @@ bool ArenaTeam::LoadArenaTeamFromDB(uint32 ArenaTeamId) m_BorderStyle = fields[7].GetUInt32(); m_BorderColor = fields[8].GetUInt32(); - delete result; - // only load here, so additional checks can be made LoadStatsFromDB(ArenaTeamId); LoadMembersFromDB(ArenaTeamId); @@ -215,7 +212,7 @@ bool ArenaTeam::LoadArenaTeamFromDB(uint32 ArenaTeamId) void ArenaTeam::LoadStatsFromDB(uint32 ArenaTeamId) { // 0 1 2 3 4 5 - QueryResult *result = CharacterDatabase.PQuery("SELECT rating,games,wins,played,wins2,rank FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT rating,games,wins,played,wins2,rank FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId); if(!result) return; @@ -228,14 +225,12 @@ void ArenaTeam::LoadStatsFromDB(uint32 ArenaTeamId) m_stats.games_season = fields[3].GetUInt32(); m_stats.wins_season = fields[4].GetUInt32(); m_stats.rank = fields[5].GetUInt32(); - - delete result; } void ArenaTeam::LoadMembersFromDB(uint32 ArenaTeamId) { // 0 1 2 3 4 5 6 7 - QueryResult *result = CharacterDatabase.PQuery("SELECT member.guid,played_week,wons_week,played_season,wons_season,personal_rating,name,class " + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT member.guid,played_week,wons_week,played_season,wons_season,personal_rating,name,class " "FROM arena_team_member member " "INNER JOIN characters chars on member.guid = chars.guid " "WHERE member.arenateamid = '%u'", ArenaTeamId); @@ -256,7 +251,6 @@ void ArenaTeam::LoadMembersFromDB(uint32 ArenaTeamId) newmember.Class = fields[7].GetUInt8(); m_members.push_back(newmember); }while( result->NextRow() ); - delete result; } void ArenaTeam::SetCaptain(const uint64& guid) diff --git a/src/game/AuctionHouseBot.cpp b/src/game/AuctionHouseBot.cpp index 6b86f9de306..e7fc4cea8c3 100644 --- a/src/game/AuctionHouseBot.cpp +++ b/src/game/AuctionHouseBot.cpp @@ -485,19 +485,13 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con return; } - QueryResult* result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE itemowner<>%u AND buyguid<>%u", AHBplayerGUID, AHBplayerGUID); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE itemowner<>%u AND buyguid<>%u", AHBplayerGUID, AHBplayerGUID); if (!result) - { - delete result; return; - } if (result->GetRowCount() == 0) - { - delete result; return; - } // Fetches content of selected AH AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID()); @@ -508,7 +502,6 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con uint32 tmpdata = result->Fetch()->GetUInt32(); possibleBids.push_back(tmpdata); }while (result->NextRow()); - delete result; for (uint32 count = 1; count <= config->GetBidsPerInterval(); ++count) { @@ -701,7 +694,7 @@ void AuctionHouseBot::Update() WorldSession _session(AHBplayerAccount, NULL, SEC_PLAYER, true, 0, LOCALE_enUS); Player _AHBplayer(&_session); - _AHBplayer.MinimalLoadFromDB(NULL, AHBplayerGUID); + _AHBplayer.MinimalLoadFromDB(QueryResult_AutoPtr(NULL), AHBplayerGUID); ObjectAccessor::Instance().AddObject(&_AHBplayer); // Only for testing, this can likely be removed, once I know it's working as expected. @@ -832,7 +825,7 @@ void AuctionHouseBot::Initialize() if (AHBSeller) { - QueryResult* results = (QueryResult*) NULL; + QueryResult_AutoPtr results = QueryResult_AutoPtr(NULL); char npcQuery[] = "SELECT distinct item FROM npc_vendor"; results = WorldDatabase.PQuery(npcQuery); if (results != NULL) @@ -843,8 +836,6 @@ void AuctionHouseBot::Initialize() npcItems.push_back(fields[0].GetUInt32()); } while (results->NextRow()); - - delete results; } else { @@ -872,8 +863,6 @@ void AuctionHouseBot::Initialize() lootItems.push_back(fields[0].GetUInt32()); } while (results->NextRow()); - - delete results; } else { diff --git a/src/game/AuctionHouseMgr.cpp b/src/game/AuctionHouseMgr.cpp index b2b5d250b28..f2531811205 100644 --- a/src/game/AuctionHouseMgr.cpp +++ b/src/game/AuctionHouseMgr.cpp @@ -267,7 +267,7 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry * auction) void AuctionHouseMgr::LoadAuctionItems() { // data needs to be at first place for Item::LoadFromDB - QueryResult *result = CharacterDatabase.Query("SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid"); if (!result) { @@ -310,7 +310,6 @@ void AuctionHouseMgr::LoadAuctionItems() ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString(">> Loaded %u auction items", count); @@ -318,7 +317,7 @@ void AuctionHouseMgr::LoadAuctionItems() void AuctionHouseMgr::LoadAuctions() { - QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse"); if (!result) { barGoLink bar(1); @@ -330,7 +329,6 @@ void AuctionHouseMgr::LoadAuctions() Field *fields = result->Fetch(); uint32 AuctionCount=fields[0].GetUInt32(); - delete result; if (!AuctionCount) { @@ -415,7 +413,6 @@ void AuctionHouseMgr::LoadAuctions() GetAuctionsMap(auctioneerInfo->faction_A)->AddAuction(aItem); } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString(">> Loaded %u auctions", AuctionCount); @@ -506,19 +503,13 @@ void AuctionHouseObject::Update() if (AuctionsMap.empty()) return; - QueryResult* result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE time <= %u ORDER BY TIME ASC", (uint32)curTime+60); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE time <= %u ORDER BY TIME ASC", (uint32)curTime+60); if (!result) - { - delete result; return; - } if (result->GetRowCount() == 0) - { - delete result; return; - } vector<uint32> expiredAuctions; @@ -527,7 +518,6 @@ void AuctionHouseObject::Update() uint32 tmpdata = result->Fetch()->GetUInt32(); expiredAuctions.push_back(tmpdata); } while (result->NextRow()); - delete result; while (!expiredAuctions.empty()) { diff --git a/src/game/Bag.cpp b/src/game/Bag.cpp index 37b276cf584..e71bfc02fd0 100644 --- a/src/game/Bag.cpp +++ b/src/game/Bag.cpp @@ -108,7 +108,7 @@ void Bag::SaveToDB() Item::SaveToDB(); } -bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) +bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result) { if(!Item::LoadFromDB(guid, owner_guid, result)) return false; diff --git a/src/game/Bag.h b/src/game/Bag.h index 5b36a291cd3..fc363abe538 100644 --- a/src/game/Bag.h +++ b/src/game/Bag.h @@ -55,7 +55,7 @@ class Bag : public Item // overwrite virtual Item::SaveToDB void SaveToDB(); // overwrite virtual Item::LoadFromDB - bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result = NULL); + bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL)); // overwrite virtual Item::DeleteFromDB void DeleteFromDB(); diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp index f6cf7fdddba..84ab2ba9222 100644 --- a/src/game/BattleGroundMgr.cpp +++ b/src/game/BattleGroundMgr.cpp @@ -1645,7 +1645,7 @@ void BattleGroundMgr::CreateInitialBattleGrounds() uint32 count = 0; // 0 1 2 3 4 5 6 7 8 - QueryResult *result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,AllianceStartO,HordeStartLoc,HordeStartO FROM battleground_template"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,AllianceStartO,HordeStartLoc,HordeStartO FROM battleground_template"); if (!result) { @@ -1747,8 +1747,6 @@ void BattleGroundMgr::CreateInitialBattleGrounds() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u battlegrounds", count ); } @@ -1758,7 +1756,7 @@ void BattleGroundMgr::InitAutomaticArenaPointDistribution() if (sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_POINTS)) { sLog.outDebug("Initializing Automatic Arena Point Distribution"); - QueryResult * result = CharacterDatabase.Query("SELECT NextArenaPointDistributionTime FROM saved_variables"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT NextArenaPointDistributionTime FROM saved_variables"); if (!result) { sLog.outDebug("Battleground: Next arena point distribution time not found in SavedVariables, reseting it now."); @@ -1766,10 +1764,7 @@ void BattleGroundMgr::InitAutomaticArenaPointDistribution() CharacterDatabase.PExecute("INSERT INTO saved_variables (NextArenaPointDistributionTime) VALUES ('"UI64FMTD"')", m_NextAutoDistributionTime); } else - { m_NextAutoDistributionTime = time_t((*result)[0].GetUInt64()); - delete result; - } sLog.outDebug("Automatic Arena Point Distribution initialized."); } } @@ -2054,7 +2049,7 @@ void BattleGroundMgr::LoadBattleMastersEntry() { mBattleMastersMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query( "SELECT entry,bg_template FROM battlemaster_entry" ); + QueryResult_AutoPtr result = WorldDatabase.Query( "SELECT entry,bg_template FROM battlemaster_entry" ); uint32 count = 0; @@ -2089,8 +2084,6 @@ void BattleGroundMgr::LoadBattleMastersEntry() } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u battlemaster entries", count ); } diff --git a/src/game/Channel.cpp b/src/game/Channel.cpp index da125b6392b..3b32f29371c 100644 --- a/src/game/Channel.cpp +++ b/src/game/Channel.cpp @@ -53,7 +53,7 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) //load not built in channel if saved std::string _name(name); CharacterDatabase.escape_string(_name); - QueryResult *result = CharacterDatabase.PQuery("SELECT m_name, m_team, m_announce, m_moderate, m_password, BannedList FROM channels WHERE m_name = '%s' AND m_team = '%u'", _name.c_str(), m_Team); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT m_name, m_team, m_announce, m_moderate, m_password, BannedList FROM channels WHERE m_name = '%s' AND m_team = '%u'", _name.c_str(), m_Team); if (result)//load { Field *fields = result->Fetch(); @@ -64,8 +64,6 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) m_password = fields[4].GetString(); const char* db_BannedList = fields[5].GetString(); - delete result; - m_IsSaved = true; if (db_BannedList) diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp index 4ecde2bf5c8..1262550f808 100644 --- a/src/game/CharacterHandler.cpp +++ b/src/game/CharacterHandler.cpp @@ -106,17 +106,14 @@ class CharacterHandler { public: - void HandleCharEnumCallback(QueryResult * result, uint32 account) + void HandleCharEnumCallback(QueryResult_AutoPtr result, uint32 account) { WorldSession * session = sWorld.FindSession(account); if(!session) - { - delete result; return; - } session->HandleCharEnum(result); } - void HandlePlayerLoginCallback(QueryResult * /*dummy*/, SqlQueryHolder * holder) + void HandlePlayerLoginCallback(QueryResult_AutoPtr /*dummy*/, SqlQueryHolder * holder) { if (!holder) return; WorldSession *session = sWorld.FindSession(((LoginQueryHolder*)holder)->GetAccountId()); @@ -129,7 +126,7 @@ class CharacterHandler } } chrHandler; -void WorldSession::HandleCharEnum(QueryResult * result) +void WorldSession::HandleCharEnum(QueryResult_AutoPtr result) { WorldPacket data(SMSG_CHAR_ENUM, 100); // we guess size @@ -147,8 +144,6 @@ void WorldSession::HandleCharEnum(QueryResult * result) ++num; } while( result->NextRow() ); - - delete result; } data.put<uint8>(0, num); @@ -281,12 +276,11 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) return; } - QueryResult *resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId()); + QueryResult_AutoPtr resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId()); if (resultacct) { Field *fields=resultacct->Fetch(); uint32 acctcharcount = fields[0].GetUInt32(); - delete resultacct; if (acctcharcount >= sWorld.getConfig(CONFIG_CHARACTERS_PER_ACCOUNT)) { @@ -296,13 +290,12 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) } } - QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId()); uint8 charcount = 0; if ( result ) { Field *fields=result->Fetch(); charcount = fields[0].GetUInt8(); - delete result; if (charcount >= sWorld.getConfig(CONFIG_CHARACTERS_PER_REALM)) { @@ -340,7 +333,7 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) if(!AllowTwoSideAccounts || skipCinematics == 1 || class_ == CLASS_DEATH_KNIGHT) { - QueryResult *result2 = CharacterDatabase.PQuery("SELECT level,race,class FROM characters WHERE account = '%u' %s", + QueryResult_AutoPtr result2 = CharacterDatabase.PQuery("SELECT level,race,class FROM characters WHERE account = '%u' %s", GetAccountId(), (skipCinematics == 1 || class_ == CLASS_DEATH_KNIGHT) ? "" : "LIMIT 1"); if(result2) { @@ -361,7 +354,6 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) { data << (uint8)CHAR_CREATE_UNIQUE_CLASS_LIMIT; SendPacket( &data ); - delete result2; return; } } @@ -386,7 +378,6 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) { data << (uint8)CHAR_CREATE_PVP_TEAMS_VIOLATION; SendPacket( &data ); - delete result2; return; } } @@ -416,7 +407,6 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) { data << (uint8)CHAR_CREATE_UNIQUE_CLASS_LIMIT; SendPacket( &data ); - delete result2; return; } } @@ -429,7 +419,6 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) } } } - delete result2; } } @@ -516,13 +505,12 @@ void WorldSession::HandleCharDeleteOpcode( WorldPacket & recv_data ) return; } - QueryResult *result = CharacterDatabase.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid)); if(result) { Field *fields = result->Fetch(); accountId = fields[0].GetUInt32(); name = fields[1].GetCppString(); - delete result; } // prevent deleting other players' characters using cheating tools @@ -652,14 +640,13 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder) } //QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow()); - QueryResult *resultGuild = holder->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD); + QueryResult_AutoPtr resultGuild = holder->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD); if(resultGuild) { Field *fields = resultGuild->Fetch(); pCurrChar->SetInGuild(fields[0].GetUInt32()); pCurrChar->SetRank(fields[1].GetUInt32()); - delete resultGuild; } else if(pCurrChar->GetGuildId()) // clear guild related fields in case wrong data about non existed membership { @@ -977,14 +964,11 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data) ); } -void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname) +void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId, std::string newname) { WorldSession * session = sWorld.FindSession(accountId); if(!session) - { - if(result) delete result; - return; - } + return; if (!result) { @@ -998,8 +982,6 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uin uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER); std::string oldname = result->Fetch()[1].GetCppString(); - delete result; - CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_RENAME), guidLow); CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow); @@ -1187,7 +1169,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) uint8 gender, skin, face, hairStyle, hairColor, facialHair; recv_data >> gender >> skin >> hairColor >> hairStyle >> facialHair >> face; - QueryResult *result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid)); if (!result) { WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1); @@ -1198,7 +1180,6 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) Field *fields = result->Fetch(); uint32 at_loginFlags = fields[0].GetUInt32(); - delete result; if (!(at_loginFlags & AT_LOGIN_CUSTOMIZE)) { @@ -1248,12 +1229,11 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data) } CharacterDatabase.escape_string(newname); - if(QueryResult *result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid ='%u'", GUID_LOPART(guid))) + if(QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid ='%u'", GUID_LOPART(guid))) { std::string oldname = result->Fetch()[0].GetCppString(); std::string IP_str = GetRemoteAddress(); sLog.outChar("Account: %d (IP: %s), Character[%s] (guid:%u) Customized to: %s", GetAccountId(), IP_str.c_str(), oldname.c_str(), GUID_LOPART(guid), newname.c_str()); - delete result; } Player::Customize(guid, gender, skin, face, hairStyle, hairColor, facialHair); CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_CUSTOMIZE), GUID_LOPART(guid)); diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index a5cf781864e..f21e3b2511d 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -751,7 +751,7 @@ ChatCommand * ChatHandler::getCommandTable() { load_command_table = false; - QueryResult *result = WorldDatabase.Query("SELECT name,security,help FROM command"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT name,security,help FROM command"); if (result) { do @@ -762,7 +762,6 @@ ChatCommand * ChatHandler::getCommandTable() SetDataForCommandInTable(commandTable, name.c_str(), fields[1].GetUInt16(), fields[2].GetCppString(), name); } while(result->NextRow()); - delete result; } } diff --git a/src/game/Chat.h b/src/game/Chat.h index efde05f8c94..f4dba8b6596 100644 --- a/src/game/Chat.h +++ b/src/game/Chat.h @@ -605,8 +605,8 @@ class TRINITY_DLL_SPEC ChatHandler GameObject* GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid,uint32 entry); // Utility methods for commands - bool LookupPlayerSearchCommand(QueryResult* result, int32 limit); - bool HandleBanListHelper(QueryResult* result); + bool LookupPlayerSearchCommand(QueryResult_AutoPtr result, int32 limit); + bool HandleBanListHelper(QueryResult_AutoPtr result); bool HandleBanHelper(BanMode mode,char const* args); bool HandleBanInfoHelper(uint32 accountid, char const* accountname); bool HandleUnBanHelper(BanMode mode,char const* args); diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 4b6e8186801..29ed9983cd2 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1107,24 +1107,15 @@ void Creature::SelectLevel(const CreatureInfo *cinfo) //damage float damagemod = 1.0f;//_GetDamageMod(rank); - float mindmg = stats->GenerateMinDmg(cinfo); - float maxdmg = stats->GenerateMaxDmg(cinfo); - float attackpower = stats->GenerateAttackPower(cinfo); - SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, mindmg * damagemod); - SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, maxdmg * damagemod); + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, cinfo->mindmg * damagemod); + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, cinfo->maxdmg * damagemod); - SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, attackpower * damagemod); + SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE,cinfo->minrangedmg * damagemod); + SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE,cinfo->maxrangedmg * damagemod); - // ranged damage - float minrangeddmg = stats->GenerateRangedDmg(cinfo) / 2.5f; - float maxrangeddmg = stats->GenerateRangedDmg(cinfo) - mindmg; - float rangedattackpower = (minrangeddmg + maxrangeddmg) / 2 * 0.3; + SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, cinfo->attackpower * damagemod); - SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE, minrangeddmg * damagemod); - SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE, maxrangeddmg * damagemod); - - SetModifierValue(UNIT_MOD_ATTACK_POWER_RANGED, BASE_VALUE, rangedattackpower * damagemod); } float Creature::_GetHealthMod(int32 Rank) diff --git a/src/game/Creature.h b/src/game/Creature.h index d3bee8d2eca..ad8dfc2b01c 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -89,7 +89,10 @@ struct CreatureInfo float speed; float scale; uint32 rank; + float mindmg; + float maxdmg; uint32 dmgschool; + uint32 attackpower; float dmg_multiplier; uint32 baseattacktime; uint32 rangeattacktime; @@ -101,6 +104,9 @@ struct CreatureInfo uint32 trainer_spell; uint32 trainer_class; uint32 trainer_race; + float minrangedmg; + float maxrangedmg; + uint32 rangedattackpower; uint32 type; // enum CreatureType values uint32 type_flags; // enum CreatureTypeFlags mask values uint32 lootid; @@ -123,8 +129,6 @@ struct CreatureInfo float ModHealth; float ModMana; float ModArmor; - float ModDmg; - float ModRangedDmg; bool RacialLeader; uint32 questItems[6]; uint32 movementId; @@ -171,8 +175,6 @@ struct TRINITY_DLL_SPEC CreatureBaseStats uint32 BaseHealth[MAX_CREATURE_BASE_HP]; uint32 BaseMana; uint32 BaseArmor; - uint32 BaseDmg; - uint32 BaseRangedDmg; // Helpers @@ -195,26 +197,6 @@ struct TRINITY_DLL_SPEC CreatureBaseStats return uint32((BaseArmor * info->ModArmor) + 0.5f); } - uint32 GenerateMinDmg(CreatureInfo const* info) const - { - return uint32((BaseDmg * (info->baseattacktime / 1000.0f) / 2.5f) * info->ModDmg + 0.5f); - } - - uint32 GenerateMaxDmg(CreatureInfo const* info) const - { - return uint32((BaseDmg * (info->baseattacktime / 1000) - GenerateMinDmg(info)) * info->ModDmg + 0.5f); - } - - uint32 GenerateAttackPower(CreatureInfo const* info) const - { - return uint32(((GenerateMinDmg(info) + GenerateMaxDmg(info)) / 2.0f * 0.3f) * info->ModDmg + 0.5f); - } - - uint32 GenerateRangedDmg(CreatureInfo const* info) const - { - return uint32((BaseDmg * (info->baseattacktime / 1000.0f) * info->ModRangedDmg) + 0.5f); - } - static CreatureBaseStats const* GetBaseStats(uint32 level, uint8 unitClass); }; diff --git a/src/game/CreatureEventAIMgr.cpp b/src/game/CreatureEventAIMgr.cpp index d25862afd29..78c6885f5f2 100644 --- a/src/game/CreatureEventAIMgr.cpp +++ b/src/game/CreatureEventAIMgr.cpp @@ -39,7 +39,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() objmgr.LoadTrinityStrings(WorldDatabase,"creature_ai_texts",MIN_CREATURE_AI_TEXT_STRING_ID,MAX_CREATURE_AI_TEXT_STRING_ID); // Gather Additional data from EventAI Texts - QueryResult *result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM creature_ai_texts"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM creature_ai_texts"); sLog.outString("Loading EventAI Texts additional data..."); if (result) @@ -95,8 +95,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u additional CreatureEventAI Texts data.", count); } @@ -118,7 +116,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons() m_CreatureEventAI_Summon_Map.clear(); // Gather additional data for EventAI - QueryResult *result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, spawntimesecs FROM creature_ai_summons"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, spawntimesecs FROM creature_ai_summons"); if (result) { barGoLink bar(result->GetRowCount()); @@ -149,8 +147,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Summons() ++Count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u CreatureEventAI summon definitions", Count); } @@ -171,7 +167,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() m_CreatureEventAI_Event_Map.clear(); // Gather event data - QueryResult *result = WorldDatabase.Query("SELECT id, creature_id, event_type, event_inverse_phase_mask, event_chance, event_flags, " + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, creature_id, event_type, event_inverse_phase_mask, event_chance, event_flags, " "event_param1, event_param2, event_param3, event_param4, " "action1_type, action1_param1, action1_param2, action1_param3, " "action2_type, action2_param1, action2_param2, action2_param3, " @@ -729,8 +725,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() } } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u CreatureEventAI scripts", Count); } diff --git a/src/game/CreatureGroups.cpp b/src/game/CreatureGroups.cpp index afaca9cf714..6b497129fe8 100644 --- a/src/game/CreatureGroups.cpp +++ b/src/game/CreatureGroups.cpp @@ -78,14 +78,13 @@ void CreatureGroupManager::LoadCreatureFormations() CreatureGroupMap.clear(); //Check Integrity of the table - QueryResult *result = WorldDatabase.PQuery("SELECT MAX(leaderGUID) FROM creature_formations"); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT MAX(leaderGUID) FROM creature_formations"); if(!result) { sLog.outErrorDb(" ...an error occured while loading the table creature_formations ( maybe it doesn't exist ?)\n"); return; } - delete result; //Get group data result = WorldDatabase.PQuery("SELECT leaderGUID, memberGUID, dist, angle, groupAI FROM creature_formations ORDER BY leaderGUID"); @@ -126,14 +125,13 @@ void CreatureGroupManager::LoadCreatureFormations() // check data correctness { - QueryResult* result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE guid = %u", group_member->leaderGUID); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE guid = %u", group_member->leaderGUID); if(!result) { sLog.outErrorDb("creature_formations table leader guid %u incorrect (not exist)", group_member->leaderGUID); delete group_member; continue; } - delete result; result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE guid = %u", memberGUID); if(!result) @@ -142,7 +140,6 @@ void CreatureGroupManager::LoadCreatureFormations() delete group_member; continue; } - delete result; } CreatureGroupMap[memberGUID] = group_member; @@ -152,8 +149,6 @@ void CreatureGroupManager::LoadCreatureFormations() sLog.outString(); sLog.outString( ">> Loaded %u creatures in formations", total_records ); sLog.outString(); - //Free some heap - delete result; } void CreatureGroup::AddMember(Creature *member) diff --git a/src/game/GameEventMgr.cpp b/src/game/GameEventMgr.cpp index a884db5dc0f..04d0ea34842 100644 --- a/src/game/GameEventMgr.cpp +++ b/src/game/GameEventMgr.cpp @@ -194,7 +194,7 @@ void GameEventMgr::StopEvent( uint16 event_id, bool overwrite ) void GameEventMgr::LoadFromDB() { { - QueryResult *result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event"); if (!result) { sLog.outString(">> Table game_event is empty."); @@ -205,12 +205,11 @@ void GameEventMgr::LoadFromDB() Field *fields = result->Fetch(); uint32 max_event_id = fields[0].GetUInt16(); - delete result; mGameEvent.resize(max_event_id+1); } - QueryResult *result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,description,world_event FROM game_event"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,description,world_event FROM game_event"); if (!result) { mGameEvent.clear(); @@ -267,7 +266,6 @@ void GameEventMgr::LoadFromDB() pGameEvent.description = fields[6].GetCppString(); } while( result->NextRow() ); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u game events", count ); @@ -323,7 +321,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u game event saves in game events", count ); - delete result; } // load game event links (prerequisites) @@ -378,7 +375,6 @@ void GameEventMgr::LoadFromDB() } while (result->NextRow()); sLog.outString(); sLog.outString( ">> Loaded %u game event prerequisites in game events", count ); - delete result; } // Creatures @@ -425,7 +421,6 @@ void GameEventMgr::LoadFromDB() crelist.push_back(guid); } while( result->NextRow() ); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u creatures in game events", count ); @@ -475,7 +470,6 @@ void GameEventMgr::LoadFromDB() golist.push_back(guid); } while( result->NextRow() ); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u gameobjects in game events", count ); @@ -539,7 +533,6 @@ void GameEventMgr::LoadFromDB() equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet)); } while( result->NextRow() ); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u model/equipment changes in game events", count ); @@ -588,8 +581,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u quests additions in game events", count ); - - delete result; } // GO Quests @@ -633,7 +624,6 @@ void GameEventMgr::LoadFromDB() questlist.push_back(QuestRelation(id, quest)); } while( result->NextRow() ); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u quests additions in game events", count ); @@ -682,8 +672,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u quest event conditions in game events", count ); - - delete result; } // load conditions of the events @@ -730,8 +718,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u conditions in game events", count ); - - delete result; } // load condition saves @@ -784,8 +770,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u condition saves in game events", count ); - - delete result; } mGameEventNPCFlags.resize(mGameEvent.size()); @@ -831,8 +815,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u npcflags in game events", count ); - - delete result; } // Vendor @@ -902,8 +884,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u vendor additions in game events", count ); - - delete result; } // load game event npc gossip ids @@ -948,8 +928,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u npc gossip textids in game events", count ); - - delete result; } // set all flags to 0 @@ -995,8 +973,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u battleground holidays in game events", count ); - - delete result; } //////////////////////// @@ -1054,7 +1030,6 @@ void GameEventMgr::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u pools in game events", count ); - delete result; } } diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index 23b79a3de1b..5d6f730a045 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -71,7 +71,7 @@ GameObject::~GameObject() // CleanupsBeforeDelete(); } -void GameObject::CleanupsBeforeDelete() +void GameObject::CleanupsBeforeDelete(bool finalCleanup) { if(m_uint32Values) // field array can be not exist if GameOBject not loaded { diff --git a/src/game/GameObject.h b/src/game/GameObject.h index 3d6d94e3596..dd0b3508b36 100644 --- a/src/game/GameObject.h +++ b/src/game/GameObject.h @@ -589,7 +589,7 @@ class TRINITY_DLL_SPEC GameObject : public WorldObject, public GridObject<GameOb void AddToWorld(); void RemoveFromWorld(); - void CleanupsBeforeDelete(); + void CleanupsBeforeDelete(bool finalCleanup = true); bool Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 animprogress, GOState go_state, uint32 artKit = 0); void Update(uint32 p_time); diff --git a/src/game/GlobalEvents.cpp b/src/game/GlobalEvents.cpp index 458933244dd..defdd96f1f9 100644 --- a/src/game/GlobalEvents.cpp +++ b/src/game/GlobalEvents.cpp @@ -32,7 +32,7 @@ #include "ObjectDefines.h" #include "Corpse.h" -static void CorpsesEraseCallBack(QueryResult *result, bool bones) +static void CorpsesEraseCallBack(QueryResult_AutoPtr result, bool bones) { if(!result) return; @@ -68,8 +68,6 @@ static void CorpsesEraseCallBack(QueryResult *result, bool bones) CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow); } } while (result->NextRow()); - - delete result; } /// Handle periodic erase of corpses and bones diff --git a/src/game/Group.cpp b/src/game/Group.cpp index c0bfc7ef182..a4ebf7bfc27 100644 --- a/src/game/Group.cpp +++ b/src/game/Group.cpp @@ -125,7 +125,7 @@ bool Group::Create(const uint64 &guid, const char * name) return true; } -bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool loadMembers) +bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult_AutoPtr result, bool loadMembers) { if(isBGGroup()) return false; @@ -144,10 +144,7 @@ bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool // group leader not exist if(!objmgr.GetPlayerNameByGUID(m_leaderGuid, m_leaderName)) - { - if(!external) delete result; return false; - } m_groupType = (*result)[13].GetBool() ? GROUPTYPE_RAID : GROUPTYPE_NORMAL; @@ -172,7 +169,6 @@ bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool for (int i=0; i<TARGETICONCOUNT; ++i) m_targetIcons[i] = (*result)[5+i].GetUInt64(); - if(!external) delete result; if(loadMembers) { @@ -184,7 +180,6 @@ bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool { LoadMemberFromDB((*result)[0].GetUInt32(), (*result)[2].GetUInt8(), (*result)[1].GetBool()); } while( result->NextRow() ); - delete result; // group too small if(GetMembersCount() < 2) return false; diff --git a/src/game/Group.h b/src/game/Group.h index 8c5aceb3a01..61d31ce969a 100644 --- a/src/game/Group.h +++ b/src/game/Group.h @@ -166,7 +166,7 @@ class TRINITY_DLL_SPEC Group // group manipulation methods bool Create(const uint64 &guid, const char * name); - bool LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result = NULL, bool loadMembers = true); + bool LoadGroupFromDB(const uint64 &leaderGuid, QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL), bool loadMembers = true); bool LoadMemberFromDB(uint32 guidLow, uint8 subgroup, bool assistant); bool AddInvite(Player *player); uint32 RemoveInvite(Player *player); diff --git a/src/game/Guild.cpp b/src/game/Guild.cpp index 66dba877ca0..8f547d46b70 100644 --- a/src/game/Guild.cpp +++ b/src/game/Guild.cpp @@ -147,7 +147,7 @@ bool Guild::AddMember(uint64 plGuid, uint32 plRank) } else { - QueryResult *result = CharacterDatabase.PQuery("SELECT name,zone,level,class FROM characters WHERE guid = '%u'", GUID_LOPART(plGuid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name,zone,level,class FROM characters WHERE guid = '%u'", GUID_LOPART(plGuid)); if (!result) return false; // player doesn't exist @@ -156,7 +156,7 @@ bool Guild::AddMember(uint64 plGuid, uint32 plRank) newmember.ZoneId = fields[1].GetUInt32(); newmember.Level = fields[2].GetUInt8(); newmember.Class = fields[3].GetUInt8(); - delete result; + if (newmember.Level < 1 || newmember.Level > STRONG_MAX_LEVEL || newmember.Class < CLASS_WARRIOR || newmember.Class >= MAX_CLASSES) { @@ -215,14 +215,13 @@ bool Guild::LoadGuildFromDB(uint32 GuildId) //set m_Id in case guild data are broken in DB and Guild will be Disbanded (deleted from DB) m_Id = GuildId; - QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(TabId) FROM guild_bank_tab WHERE guildid='%u'", GuildId); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(TabId) FROM guild_bank_tab WHERE guildid='%u'", GuildId); if (result) { Field *fields = result->Fetch(); m_PurchasedTabs = fields[0].GetUInt32(); if (m_PurchasedTabs > GUILD_BANK_MAX_TABS) m_PurchasedTabs = GUILD_BANK_MAX_TABS; - delete result; } if (!LoadRanksFromDB(GuildId)) @@ -256,8 +255,6 @@ bool Guild::LoadGuildFromDB(uint32 GuildId) time_t time = fields[9].GetUInt64(); m_GuildBankMoney = fields[10].GetUInt64(); - delete result; - if (time > 0) { tm local = *(localtime(&time)); // dereference and assign @@ -295,7 +292,7 @@ bool Guild::LoadRanksFromDB(uint32 GuildId) { Field *fields; // 0 1 2 3 - QueryResult *result = CharacterDatabase.PQuery("SELECT rid,rname,rights,BankMoneyPerDay FROM guild_rank WHERE guildid = '%u' ORDER BY rid ASC", GuildId); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT rid,rname,rights,BankMoneyPerDay FROM guild_rank WHERE guildid = '%u' ORDER BY rid ASC", GuildId); if (!result) { @@ -329,7 +326,6 @@ bool Guild::LoadRanksFromDB(uint32 GuildId) AddRank(rankName,rankRights,rankMoney); }while (result->NextRow()); - delete result; if (m_Ranks.size() < GUILD_RANKS_MIN_COUNT) // if too few ranks, renew them { @@ -360,7 +356,7 @@ bool Guild::LoadRanksFromDB(uint32 GuildId) bool Guild::LoadMembersFromDB(uint32 GuildId) { // 0 1 2 3 4 5 - QueryResult *result = CharacterDatabase.PQuery("SELECT guild_member.guid,rank, pnote, offnote, BankResetTimeMoney,BankRemMoney," + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT guild_member.guid,rank, pnote, offnote, BankResetTimeMoney,BankRemMoney," // 6 7 8 9 10 11 "BankResetTimeTab0, BankRemSlotsTab0, BankResetTimeTab1, BankRemSlotsTab1, BankResetTimeTab2, BankRemSlotsTab2," // 12 13 14 15 16 17 @@ -422,7 +418,6 @@ bool Guild::LoadMembersFromDB(uint32 GuildId) members[GUID_LOPART(guid)] = newmember; }while (result->NextRow()); - delete result; if (members.empty()) return false; @@ -879,7 +874,7 @@ void Guild::LoadGuildEventLogFromDB() return; // 0 1 2 3 4 5 - QueryResult *result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid1, PlayerGuid2, NewRank, TimeStamp FROM guild_eventlog WHERE guildid=%u ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_EVENTLOG_MAX_RECORDS); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid1, PlayerGuid2, NewRank, TimeStamp FROM guild_eventlog WHERE guildid=%u ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_EVENTLOG_MAX_RECORDS); if (!result) return; bool isNextLogGuidSet = false; @@ -909,7 +904,6 @@ void Guild::LoadGuildEventLogFromDB() m_GuildEventLog.push_front(NewEvent); } while (result->NextRow()); - delete result; m_EventLogLoaded = true; } @@ -1161,7 +1155,7 @@ void Guild::LoadGuildBankFromDB() LoadGuildBankEventLogFromDB(); // 0 1 2 3 - QueryResult *result = CharacterDatabase.PQuery("SELECT TabId, TabName, TabIcon, TabText FROM guild_bank_tab WHERE guildid='%u' ORDER BY TabId", m_Id); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT TabId, TabName, TabIcon, TabText FROM guild_bank_tab WHERE guildid='%u' ORDER BY TabId", m_Id); if (!result) { m_PurchasedTabs = 0; @@ -1184,8 +1178,6 @@ void Guild::LoadGuildBankFromDB() m_TabListMap[TabId] = NewTab; }while (result->NextRow()); - delete result; - // data needs to be at first place for Item::LoadFromDB // 0 1 2 3 4 result = CharacterDatabase.PQuery("SELECT data, TabId, SlotId, item_guid, item_entry FROM guild_bank_item JOIN item_instance ON item_guid = guid WHERE guildid='%u' ORDER BY TabId", m_Id); @@ -1232,8 +1224,6 @@ void Guild::LoadGuildBankFromDB() pItem->AddToWorld(); m_TabListMap[TabId]->Slots[SlotId] = pItem; }while (result->NextRow()); - - delete result; } // This unload should be called when the last member of the guild gets offline @@ -1452,7 +1442,7 @@ uint32 Guild::GetBankSlotPerDay(uint32 rankId, uint8 TabId) void Guild::LoadBankRightsFromDB(uint32 GuildId) { // 0 1 2 3 - QueryResult *result = CharacterDatabase.PQuery("SELECT TabId, rid, gbright, SlotPerDay FROM guild_bank_right WHERE guildid = '%u' ORDER BY TabId", GuildId); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT TabId, rid, gbright, SlotPerDay FROM guild_bank_right WHERE guildid = '%u' ORDER BY TabId", GuildId); if (!result) return; @@ -1468,7 +1458,6 @@ void Guild::LoadBankRightsFromDB(uint32 GuildId) SetBankRightsAndSlots(rankId, TabId, right, SlotPerDay, false); }while (result->NextRow()); - delete result; return; } @@ -1485,7 +1474,7 @@ void Guild::LoadGuildBankEventLogFromDB() for (uint32 tabId = 0; tabId < m_PurchasedTabs; tabId++) { // 0 1 2 3 4 5 6 - QueryResult *result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, tabId, GUILD_BANK_MAX_LOGS); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, tabId, GUILD_BANK_MAX_LOGS); if (!result) continue; @@ -1522,12 +1511,11 @@ void Guild::LoadGuildBankEventLogFromDB() isNextLogGuidSet = true; } } while (result->NextRow()); - delete result; } //special handle for guild bank money log // 0 1 2 3 4 5 6 - QueryResult *result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_BANK_MONEY_LOGS_TAB, GUILD_BANK_MAX_LOGS); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_BANK_MONEY_LOGS_TAB, GUILD_BANK_MAX_LOGS); if (!result) return; @@ -1559,7 +1547,6 @@ void Guild::LoadGuildBankEventLogFromDB() m_GuildBankEventLog_Money.push_front(NewEvent); } while (result->NextRow()); - delete result; } void Guild::UnloadGuildBankEventLog() diff --git a/src/game/InstanceSaveMgr.cpp b/src/game/InstanceSaveMgr.cpp index 0141396b39a..9e8cd3eb694 100644 --- a/src/game/InstanceSaveMgr.cpp +++ b/src/game/InstanceSaveMgr.cpp @@ -238,7 +238,7 @@ void InstanceSaveManager::_DelHelper(DatabaseType &db, const char *fields, const int res = vsnprintf( szQueryTail, MAX_QUERY_LEN, queryTail, ap ); va_end(ap); - QueryResult *result = db.PQuery("SELECT %s FROM %s %s", fields, table, szQueryTail); + QueryResult_AutoPtr result = db.PQuery("SELECT %s FROM %s %s", fields, table, szQueryTail); if(result) { do @@ -253,7 +253,6 @@ void InstanceSaveManager::_DelHelper(DatabaseType &db, const char *fields, const } db.DirectPExecute("DELETE FROM %s WHERE %s", table, ss.str().c_str()); } while (result->NextRow()); - delete result; } } @@ -281,7 +280,7 @@ void InstanceSaveManager::CleanupInstances() // creature_respawn and gameobject_respawn are in another database // first, obtain total instance set std::set<uint32> InstanceSet; - QueryResult *result = CharacterDatabase.Query("SELECT id FROM instance"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id FROM instance"); if (result) { do @@ -290,7 +289,6 @@ void InstanceSaveManager::CleanupInstances() InstanceSet.insert(fields[0].GetUInt32()); } while (result->NextRow()); - delete result; } // creature_respawn @@ -304,7 +302,6 @@ void InstanceSaveManager::CleanupInstances() WorldDatabase.DirectPExecute("DELETE FROM creature_respawn WHERE instance = '%u'", fields[0].GetUInt32()); } while (result->NextRow()); - delete result; } // gameobject_respawn @@ -318,7 +315,6 @@ void InstanceSaveManager::CleanupInstances() WorldDatabase.DirectPExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'", fields[0].GetUInt32()); } while (result->NextRow()); - delete result; } // characters @@ -332,7 +328,6 @@ void InstanceSaveManager::CleanupInstances() CharacterDatabase.PExecute("UPDATE characters SET instance_id = '0' WHERE instance_id = '%u'", fields[0].GetUInt32()); } while (result->NextRow()); - delete result; } // corpse @@ -346,7 +341,6 @@ void InstanceSaveManager::CleanupInstances() CharacterDatabase.PExecute("UPDATE corpse SET instance = '0' WHERE instance = '%u'", fields[0].GetUInt32()); } while (result->NextRow()); - delete result; } bar.step(); @@ -365,7 +359,7 @@ void InstanceSaveManager::PackInstances() // all valid ids are in the instance table // any associations to ids not in this table are assumed to be // cleaned already in CleanupInstances - QueryResult *result = CharacterDatabase.Query("SELECT id FROM instance"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id FROM instance"); if (result) { do @@ -374,7 +368,6 @@ void InstanceSaveManager::PackInstances() InstanceSet.insert(fields[0].GetUInt32()); } while (result->NextRow()); - delete result; } barGoLink bar(InstanceSet.size() + 1); @@ -422,7 +415,7 @@ void InstanceSaveManager::LoadResetTimes() typedef std::multimap<uint32 /*PAIR32(map,difficulty)*/, uint32 /*instanceid*/ > ResetTimeMapDiffInstances; ResetTimeMapDiffInstances mapDiffResetInstances; - QueryResult *result = CharacterDatabase.Query("SELECT id, map, difficulty, resettime FROM instance WHERE resettime > 0"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id, map, difficulty, resettime FROM instance WHERE resettime > 0"); if( result ) { do @@ -437,7 +430,6 @@ void InstanceSaveManager::LoadResetTimes() } } while (result->NextRow()); - delete result; // update reset time for normal instances with the max creature respawn time + X hours result = WorldDatabase.Query("SELECT MAX(respawntime), instance FROM creature_respawn WHERE instance > 0 GROUP BY instance"); @@ -456,7 +448,6 @@ void InstanceSaveManager::LoadResetTimes() } } while (result->NextRow()); - delete result; } // schedule the reset times @@ -492,7 +483,6 @@ void InstanceSaveManager::LoadResetTimes() SetResetTimeFor(mapid,difficulty,newresettime); } while(result->NextRow()); - delete result; } // clean expired instances, references to them will be deleted in CleanupInstances diff --git a/src/game/Item.cpp b/src/game/Item.cpp index 7d6e1cd3021..1a32bfd4107 100644 --- a/src/game/Item.cpp +++ b/src/game/Item.cpp @@ -339,18 +339,14 @@ void Item::SaveToDB() SetState(ITEM_UNCHANGED); } -bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) +bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result) { // create item before any checks for store correct guid // and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB Object::_Create(guid, 0, HIGHGUID_ITEM); - bool delete_result = false; if(!result) - { result = CharacterDatabase.PQuery("SELECT data FROM item_instance WHERE guid = '%u'", guid); - delete_result = true; - } if (!result) { @@ -363,7 +359,6 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) if(!LoadValues(fields[0].GetString())) { sLog.outError("Item #%d have broken data in `data` field. Can't be loaded.",guid); - if (delete_result) delete result; return false; } @@ -377,8 +372,6 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result) need_save = true; } - if (delete_result) delete result; - ItemPrototype const* proto = GetProto(); if(!proto) return false; diff --git a/src/game/Item.h b/src/game/Item.h index 3dcdcab95a8..bf893fcd3c3 100644 --- a/src/game/Item.h +++ b/src/game/Item.h @@ -240,7 +240,7 @@ class TRINITY_DLL_SPEC Item : public Object bool IsBindedNotWith(Player const* player) const; bool IsBoundByEnchant() const; virtual void SaveToDB(); - virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result = NULL); + virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL)); virtual void DeleteFromDB(); void DeleteFromInventoryDB(); diff --git a/src/game/ItemEnchantmentMgr.cpp b/src/game/ItemEnchantmentMgr.cpp index 790eb1699c3..e1d6135d6b0 100644 --- a/src/game/ItemEnchantmentMgr.cpp +++ b/src/game/ItemEnchantmentMgr.cpp @@ -55,7 +55,7 @@ void LoadRandomEnchantmentsTable() float chance; uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT entry, ench, chance FROM item_enchantment_template"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, ench, chance FROM item_enchantment_template"); if (result) { @@ -76,8 +76,6 @@ void LoadRandomEnchantmentsTable() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u Item Enchantment definitions", count ); } diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 8d22191b25e..16fe0f48fd5 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -336,7 +336,7 @@ bool ChatHandler::HandleGoCreatureCommand(const char* args) } //sLog.outError("DEBUG: %s", whereClause.c_str()); - QueryResult *result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map FROM creature %s", whereClause.str().c_str() ); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map FROM creature %s", whereClause.str().c_str() ); if (!result) { SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND); @@ -353,8 +353,6 @@ bool ChatHandler::HandleGoCreatureCommand(const char* args) float ort = fields[3].GetFloat(); int mapid = fields[4].GetUInt16(); - delete result; - if(!MapManager::IsValidMapCoord(mapid,x,y,z,ort)) { PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid); @@ -436,7 +434,7 @@ bool ChatHandler::HandleGoObjectCommand(const char* args) bool ChatHandler::HandleGameObjectTargetCommand(const char* args) { Player* pl = m_session->GetPlayer(); - QueryResult *result; + QueryResult_AutoPtr result; GameEventMgr::ActiveEvents const& activeEventsList = gameeventmgr.GetActiveEventList(); if(*args) { @@ -515,8 +513,6 @@ bool ChatHandler::HandleGameObjectTargetCommand(const char* args) found = true; } while( result->NextRow() && (!found) ); - delete result; - if (!found) { PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id); @@ -837,7 +833,7 @@ bool ChatHandler::HandleGameObjectNearCommand(const char* args) uint32 count = 0; Player* pl = m_session->GetPlayer(); - QueryResult *result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, " + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, " "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ " "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_", pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), @@ -864,8 +860,6 @@ bool ChatHandler::HandleGameObjectNearCommand(const char* args) ++count; } while (result->NextRow()); - - delete result; } PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count); @@ -2170,7 +2164,7 @@ bool ChatHandler::HandlePInfoCommand(const char* args) return false; // 0 1 2 3 4 5 - QueryResult *result = CharacterDatabase.PQuery("SELECT totaltime, level, money, account, race, class FROM characters WHERE guid = '%u'", GUID_LOPART(target_guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT totaltime, level, money, account, race, class FROM characters WHERE guid = '%u'", GUID_LOPART(target_guid)); if (!result) return false; @@ -2181,7 +2175,6 @@ bool ChatHandler::HandlePInfoCommand(const char* args) accId = fields[3].GetUInt32(); race = fields[4].GetUInt8(); Class = fields[5].GetUInt8(); - delete result; } std::string username = GetTrinityString(LANG_ERROR); @@ -2190,7 +2183,7 @@ bool ChatHandler::HandlePInfoCommand(const char* args) uint32 security = 0; std::string last_login = GetTrinityString(LANG_ERROR); - QueryResult* result = loginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login " + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login " "FROM account a " "LEFT JOIN account_access aa " "ON (a.id = aa.id) " @@ -2215,8 +2208,6 @@ bool ChatHandler::HandlePInfoCommand(const char* args) last_ip = "-"; last_login = "-"; } - - delete result; } std::string nameLink = playerLink(target_name); @@ -2303,7 +2294,7 @@ bool ChatHandler::HandleWpAddCommand(const char* args) pathid = target->GetWaypointPath(); else { - QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(id) FROM waypoint_data"); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT MAX(id) FROM waypoint_data"); uint32 maxpathid = result->Fetch()->GetInt32(); pathid = maxpathid+1; sLog.outDebug("DEBUG: HandleWpAddCommand - New path started."); @@ -2325,13 +2316,10 @@ bool ChatHandler::HandleWpAddCommand(const char* args) sLog.outDebug("DEBUG: HandleWpAddCommand - point == 0"); - QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'",pathid); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'",pathid); if( result ) - { point = (*result)[0].GetUInt32(); - delete result; - } Player* player = m_session->GetPlayer(); Map *map = player->GetMap(); @@ -2385,13 +2373,10 @@ bool ChatHandler::HandleWpLoadPathCommand(const char *args) } guidlow = target->GetDBTableGUIDLow(); - QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE guid = '%u'",guidlow); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT guid FROM creature_addon WHERE guid = '%u'",guidlow); if( result ) - { WorldDatabase.PExecute("UPDATE creature_addon SET path_id = '%u' WHERE guid = '%u'", pathid, guidlow); - delete result; - } else WorldDatabase.PExecute("INSERT INTO creature_addon(guid,path_id) VALUES ('%u','%u')", guidlow, pathid); @@ -2471,7 +2456,7 @@ bool ChatHandler::HandleWpEventCommand(const char* args) if(id) { - QueryResult *result = WorldDatabase.PQuery( "SELECT id FROM waypoint_scripts WHERE guid = %u", id); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT id FROM waypoint_scripts WHERE guid = %u", id); if( !result ) { @@ -2479,14 +2464,11 @@ bool ChatHandler::HandleWpEventCommand(const char* args) PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: ", id); } else - { PSendSysMessage("|cff00ff00Wp Event: You have choosed an existing waypoint script guid: %u|r", id); - delete result; - } } else { - QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(guid) FROM waypoint_scripts"); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT MAX(guid) FROM waypoint_scripts"); id = result->Fetch()->GetUInt32(); WorldDatabase.PExecute("INSERT INTO waypoint_scripts(guid)VALUES(%u)", id+1); PSendSysMessage("%s%s%u|r", "|cff00ff00","Wp Event: New waypoint event added: |r|cff00ffff", id+1); @@ -2509,7 +2491,7 @@ bool ChatHandler::HandleWpEventCommand(const char* args) float a8, a9, a10, a11; char const* a7; - QueryResult *result = WorldDatabase.PQuery( "SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = %u", id); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = %u", id); if( !result ) { @@ -2536,21 +2518,18 @@ bool ChatHandler::HandleWpEventCommand(const char* args) PSendSysMessage("|cffff33ffid:|r|cff00ffff %u|r|cff00ff00, guid: |r|cff00ffff%u|r|cff00ff00, delay: |r|cff00ffff%u|r|cff00ff00, command: |r|cff00ffff%u|r|cff00ff00, datalong: |r|cff00ffff%u|r|cff00ff00, datalong2: |r|cff00ffff%u|r|cff00ff00, datatext: |r|cff00ffff%s|r|cff00ff00, posx: |r|cff00ffff%f|r|cff00ff00, posy: |r|cff00ffff%f|r|cff00ff00, posz: |r|cff00ffff%f|r|cff00ff00, orientation: |r|cff00ffff%f|r", id, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); } while(result->NextRow()); - - delete result; } if(show == "del") { id = atoi(arg_id); - QueryResult *result = WorldDatabase.PQuery( "SELECT guid FROM waypoint_scripts WHERE guid = %u", id); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT guid FROM waypoint_scripts WHERE guid = %u", id); if( result ) { WorldDatabase.PExecuteLog("DELETE FROM waypoint_scripts WHERE guid = %u", id); PSendSysMessage("%s%s%u|r","|cff00ff00","Wp Event: Waypoint script removed: ", id); - delete result; } else PSendSysMessage("|cffff33ffWp Event: ERROR: you have selected a non existing script: %u|r", id); @@ -2613,7 +2592,7 @@ bool ChatHandler::HandleWpEventCommand(const char* args) } else { - QueryResult *result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid='%u'",id); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid='%u'",id); if(!result) { @@ -2621,8 +2600,6 @@ bool ChatHandler::HandleWpEventCommand(const char* args) return true; } - delete result; - if(arg_str_2 == "posx") { coord = atof(arg_3); @@ -2734,8 +2711,7 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) // Check the creature if (wpCreature->GetEntry() == VISUAL_WAYPOINT ) { - QueryResult *result = - WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid); if(!result) { @@ -2767,9 +2743,6 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) } while( result->NextRow() ); - // Cleanup memory - sLog.outDebug("DEBUG: HandleWpModifyCommand - Cleanup memory"); - delete result; // We have the waypoint number and the GUID of the "master npc" // Text is enclosed in "<>", all other arguments not arg_str = strtok((char*)NULL, " "); @@ -2939,7 +2912,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) return false; } - QueryResult *result = WorldDatabase.PQuery( "SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow()); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow()); if(!result) { @@ -2966,14 +2939,12 @@ bool ChatHandler::HandleWpShowCommand(const char* args) } while( result->NextRow() ); - // Cleanup memory - delete result; return true; } if(show == "on") { - QueryResult *result = WorldDatabase.PQuery( "SELECT point, position_x,position_y,position_z FROM waypoint_data WHERE id = '%u'", pathid); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT point, position_x,position_y,position_z FROM waypoint_data WHERE id = '%u'", pathid); if(!result) { @@ -2985,7 +2956,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) PSendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid); // Delete all visuals for this NPC - QueryResult *result2 = WorldDatabase.PQuery( "SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid); + QueryResult_AutoPtr result2 = WorldDatabase.PQuery( "SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid); if(result2) { @@ -3012,8 +2983,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args) } while( result2->NextRow() ); - delete result2; - if( hasError ) { PSendSysMessage(LANG_WAYPOINT_TOOFAR1); @@ -3041,7 +3010,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args) { PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id); delete wpCreature; - delete result; return false; } @@ -3064,8 +3032,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args) while( result->NextRow() ); SendSysMessage("|cff00ff00Showing the current creature's path.|r"); - // Cleanup memory - delete result; return true; } @@ -3073,7 +3039,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) { PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid); - QueryResult *result = WorldDatabase.PQuery( "SELECT position_x,position_y,position_z FROM waypoint_data WHERE point='1' AND id = '%u'",pathid); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT position_x,position_y,position_z FROM waypoint_data WHERE point='1' AND id = '%u'",pathid); if(!result) { PSendSysMessage(LANG_WAYPOINT_NOTFOUND, pathid); @@ -3096,7 +3062,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args) { PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, id); delete pCreature; - delete result; return false; } @@ -3110,8 +3075,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args) pCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5); } - // Cleanup memory - delete result; return true; } @@ -3119,13 +3082,9 @@ bool ChatHandler::HandleWpShowCommand(const char* args) { PSendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid); - QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'",pathid); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT MAX(point) FROM waypoint_data WHERE id = '%u'",pathid); if( result ) - { Maxpoint = (*result)[0].GetUInt32(); - - delete result; - } else Maxpoint = 0; @@ -3151,7 +3110,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args) { PSendSysMessage(LANG_WAYPOINT_NOTCREATED, id); delete pCreature; - delete result; return false; } @@ -3165,14 +3123,12 @@ bool ChatHandler::HandleWpShowCommand(const char* args) pCreature->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.5); } - // Cleanup memory - delete result; return true; } if(show == "off") { - QueryResult *result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id = '%u'", 1); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id = '%u'", 1); if(!result) { SendSysMessage(LANG_WAYPOINT_VP_NOTFOUND); @@ -3211,8 +3167,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args) } SendSysMessage(LANG_WAYPOINT_VP_ALLREMOVED); - // Cleanup memory - delete result; return true; } @@ -3759,7 +3713,7 @@ bool ChatHandler::HandleLookupPlayerIpCommand(const char* args) loginDatabase.escape_string (ip); - QueryResult* result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ()); + QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ()); return LookupPlayerSearchCommand (result,limit); } @@ -3778,7 +3732,7 @@ bool ChatHandler::HandleLookupPlayerAccountCommand(const char* args) loginDatabase.escape_string (account); - QueryResult* result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ()); + QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ()); return LookupPlayerSearchCommand (result,limit); } @@ -3795,12 +3749,12 @@ bool ChatHandler::HandleLookupPlayerEmailCommand(const char* args) loginDatabase.escape_string (email); - QueryResult* result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ()); + QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ()); return LookupPlayerSearchCommand (result,limit); } -bool ChatHandler::LookupPlayerSearchCommand(QueryResult* result, int32 limit) +bool ChatHandler::LookupPlayerSearchCommand(QueryResult_AutoPtr result, int32 limit) { if(!result) { @@ -3816,7 +3770,7 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult* result, int32 limit) uint32 acc_id = fields[0].GetUInt32(); std::string acc_name = fields[1].GetCppString(); - QueryResult* chars = CharacterDatabase.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id); + QueryResult_AutoPtr chars = CharacterDatabase.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id); if(chars) { PSendSysMessage(LANG_LOOKUP_PLAYER_ACCOUNT,acc_name.c_str(),acc_id); @@ -3834,13 +3788,9 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult* result, int32 limit) ++i; } while( chars->NextRow() && ( limit == -1 || i < limit ) ); - - delete chars; } } while(result->NextRow()); - delete result; - if(i==0) // empty accounts only { PSendSysMessage(LANG_NO_PLAYERS_FOUND); diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 2a01fbb2a2c..9af7c517321 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -1457,10 +1457,9 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(const char *args) // Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1 if (gmRealmID == -1) { - QueryResult *result = loginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm); if (result) { - delete result; SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); SetSentErrorMessage(true); return false; @@ -2620,7 +2619,7 @@ bool ChatHandler::HandleAddItemCommand(const char *args) { std::string itemName = citemName+1; WorldDatabase.escape_string(itemName); - QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str()); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str()); if (!result) { PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1); @@ -2628,7 +2627,6 @@ bool ChatHandler::HandleAddItemCommand(const char *args) return false; } itemId = result->Fetch()->GetUInt16(); - delete result; } else return false; @@ -2811,16 +2809,13 @@ bool ChatHandler::HandleListItemCommand(const char *args) if(count < 0) return false; - QueryResult *result; + QueryResult_AutoPtr result; // inventory case uint32 inv_count = 0; result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id); if(result) - { inv_count = (*result)[0].GetUInt32(); - delete result; - } result=CharacterDatabase.PQuery( // 0 1 2 3 4 5 @@ -2857,8 +2852,6 @@ bool ChatHandler::HandleListItemCommand(const char *args) int64 res_count = result->GetRowCount(); - delete result; - if(count > res_count) count-=res_count; else if(count) @@ -2869,10 +2862,7 @@ bool ChatHandler::HandleListItemCommand(const char *args) uint32 mail_count = 0; result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id); if(result) - { mail_count = (*result)[0].GetUInt32(); - delete result; - } if(count > 0) { @@ -2884,7 +2874,7 @@ bool ChatHandler::HandleListItemCommand(const char *args) item_id,uint32(count)); } else - result = NULL; + result = QueryResult_AutoPtr(NULL); if(result) { @@ -2907,8 +2897,6 @@ bool ChatHandler::HandleListItemCommand(const char *args) int64 res_count = result->GetRowCount(); - delete result; - if(count > res_count) count-=res_count; else if(count) @@ -2919,10 +2907,7 @@ bool ChatHandler::HandleListItemCommand(const char *args) uint32 auc_count = 0; result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id); if(result) - { auc_count = (*result)[0].GetUInt32(); - delete result; - } if(count > 0) { @@ -2933,7 +2918,7 @@ bool ChatHandler::HandleListItemCommand(const char *args) item_id,uint32(count)); } else - result = NULL; + result = QueryResult_AutoPtr(NULL); if(result) { @@ -2949,18 +2934,13 @@ bool ChatHandler::HandleListItemCommand(const char *args) PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos); } while (result->NextRow()); - - delete result; } // guild bank case uint32 guild_count = 0; result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id); if(result) - { guild_count = (*result)[0].GetUInt32(); - delete result; - } result=CharacterDatabase.PQuery( // 0 1 2 @@ -2984,8 +2964,6 @@ bool ChatHandler::HandleListItemCommand(const char *args) int64 res_count = result->GetRowCount(); - delete result; - if(count > res_count) count-=res_count; else if(count) @@ -3036,15 +3014,12 @@ bool ChatHandler::HandleListObjectCommand(const char *args) if(count < 0) return false; - QueryResult *result; + QueryResult_AutoPtr result; uint32 obj_count = 0; result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id); if(result) - { obj_count = (*result)[0].GetUInt32(); - delete result; - } if(m_session) { @@ -3072,8 +3047,6 @@ bool ChatHandler::HandleListObjectCommand(const char *args) else PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid); } while (result->NextRow()); - - delete result; } PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count); @@ -3171,15 +3144,12 @@ bool ChatHandler::HandleListCreatureCommand(const char *args) if(count < 0) return false; - QueryResult *result; + QueryResult_AutoPtr result; uint32 cr_count = 0; result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id); if(result) - { cr_count = (*result)[0].GetUInt32(); - delete result; - } if(m_session) { @@ -3207,8 +3177,6 @@ bool ChatHandler::HandleListCreatureCommand(const char *args) else PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid); } while (result->NextRow()); - - delete result; } PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count); @@ -5932,7 +5900,7 @@ bool ChatHandler::HandleBanInfoCharacterCommand(const char *args) bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname) { - QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid); if(!result) { PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname); @@ -5954,7 +5922,6 @@ bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname) fields[0].GetString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES):GetTrinityString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString()); }while (result->NextRow()); - delete result; return true; } @@ -5973,7 +5940,7 @@ bool ChatHandler::HandleBanInfoIPCommand(const char *args) std::string IP = cIP; loginDatabase.escape_string(IP); - QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str()); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str()); if(!result) { PSendSysMessage(LANG_BANINFO_NOIP); @@ -5985,7 +5952,7 @@ bool ChatHandler::HandleBanInfoIPCommand(const char *args) PSendSysMessage(LANG_BANINFO_IPENTRY, fields[0].GetString(), fields[1].GetString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER):fields[2].GetString(), permanent ? GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString()); - delete result; + return true; } @@ -5999,7 +5966,7 @@ bool ChatHandler::HandleBanListCharacterCommand(const char *args) std::string filter = cFilter; loginDatabase.escape_string(filter); - QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str()); if (!result) { PSendSysMessage(LANG_BANLIST_NOCHARACTER); @@ -6017,7 +5984,7 @@ bool ChatHandler::HandleBanListAccountCommand(const char *args) std::string filter = cFilter ? cFilter : ""; loginDatabase.escape_string(filter); - QueryResult* result; + QueryResult_AutoPtr result; if(filter.empty()) { @@ -6040,7 +6007,7 @@ bool ChatHandler::HandleBanListAccountCommand(const char *args) return HandleBanListHelper(result); } -bool ChatHandler::HandleBanListHelper(QueryResult* result) +bool ChatHandler::HandleBanListHelper(QueryResult_AutoPtr result) { PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT); @@ -6052,12 +6019,11 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result) Field* fields = result->Fetch(); uint32 accountid = fields[0].GetUInt32(); - QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid); + QueryResult_AutoPtr banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid); if(banresult) { Field* fields2 = banresult->Fetch(); PSendSysMessage("%s",fields2[0].GetString()); - delete banresult; } } while (result->NextRow()); } @@ -6083,7 +6049,7 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result) accmgr.GetName (account_id,account_name); // No SQL injection. id is uint32. - QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id); + QueryResult_AutoPtr banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id); if (banInfo) { Field *fields2 = banInfo->Fetch(); @@ -6108,13 +6074,10 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result) fields2[2].GetString(),fields2[3].GetString()); } }while ( banInfo->NextRow() ); - delete banInfo; } }while( result->NextRow() ); SendSysMessage("==============================================================================="); } - - delete result; return true; } @@ -6126,7 +6089,7 @@ bool ChatHandler::HandleBanListIPCommand(const char *args) std::string filter = cFilter ? cFilter : ""; loginDatabase.escape_string(filter); - QueryResult* result; + QueryResult_AutoPtr result; if(filter.empty()) { @@ -6188,7 +6151,6 @@ bool ChatHandler::HandleBanListIPCommand(const char *args) SendSysMessage("==============================================================================="); } - delete result; return true; } @@ -6892,7 +6854,7 @@ bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/) bool ChatHandler::HandleGMListFullCommand(const char* /*args*/) { ///- Get the accounts with GM Level >0 - QueryResult *result = loginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0"); + QueryResult_AutoPtr result = loginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0"); if(result) { SendSysMessage(LANG_GMLIST); @@ -6908,7 +6870,6 @@ bool ChatHandler::HandleGMListFullCommand(const char* /*args*/) }while( result->NextRow() ); PSendSysMessage("========================"); - delete result; } else PSendSysMessage(LANG_GMLIST_EMPTY); @@ -7396,7 +7357,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args) if (TargetName) { //check for offline players - QueryResult *result = CharacterDatabase.PQuery("SELECT characters.guid FROM characters WHERE characters.name = '%s'",name.c_str()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT characters.guid FROM characters WHERE characters.name = '%s'",name.c_str()); if (!result) { SendSysMessage(LANG_COMMAND_FREEZE_WRONG); @@ -7405,7 +7366,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args) //if player found: delete his freeze aura Field *fields=result->Fetch(); uint64 pguid = fields[0].GetUInt64(); - delete result; + CharacterDatabase.PQuery("DELETE FROM character_aura WHERE character_aura.spell = 9454 AND character_aura.guid = '%u'",pguid); PSendSysMessage(LANG_COMMAND_UNFREEZE,name.c_str()); return true; @@ -7423,7 +7384,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args) bool ChatHandler::HandleListFreezeCommand(const char *args) { //Get names from DB - QueryResult *result = CharacterDatabase.PQuery("SELECT characters.name FROM characters LEFT JOIN character_aura ON (characters.guid = character_aura.guid) WHERE character_aura.spell = 9454"); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT characters.name FROM characters LEFT JOIN character_aura ON (characters.guid = character_aura.guid) WHERE character_aura.spell = 9454"); if (!result) { SendSysMessage(LANG_COMMAND_NO_FROZEN_PLAYERS); @@ -7440,7 +7401,6 @@ bool ChatHandler::HandleListFreezeCommand(const char *args) PSendSysMessage(LANG_COMMAND_FROZEN_PLAYERS,fplayers.c_str()); } while (result->NextRow()); - delete result; return true; } diff --git a/src/game/LootMgr.cpp b/src/game/LootMgr.cpp index 7288b1f0f27..502b552fbf8 100644 --- a/src/game/LootMgr.cpp +++ b/src/game/LootMgr.cpp @@ -100,7 +100,7 @@ void LootStore::LoadLootTable() sLog.outString( "%s :", GetName()); // 0 1 2 3 4 5 6 7 8 9 - QueryResult *result = WorldDatabase.PQuery("SELECT entry, item, ChanceOrQuestChance, lootmode, groupid, mincountOrRef, maxcount, lootcondition, condition_value1, condition_value2 FROM %s",GetName()); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT entry, item, ChanceOrQuestChance, lootmode, groupid, mincountOrRef, maxcount, lootcondition, condition_value1, condition_value2 FROM %s",GetName()); if (result) { @@ -163,8 +163,6 @@ void LootStore::LoadLootTable() } while (result->NextRow()); - delete result; - Verify(); // Checks validity of the loot store sLog.outString(); diff --git a/src/game/Mail.cpp b/src/game/Mail.cpp index 44513c671a5..12425866090 100644 --- a/src/game/Mail.cpp +++ b/src/game/Mail.cpp @@ -135,11 +135,10 @@ void WorldSession::HandleSendMail(WorldPacket & recv_data ) else { rc_team = objmgr.GetPlayerTeamByGUID(rc); - if (QueryResult* result = CharacterDatabase.PQuery("SELECT COUNT(*) FROM mail WHERE receiver = '%u'", GUID_LOPART(rc))) + if (QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(*) FROM mail WHERE receiver = '%u'", GUID_LOPART(rc))) { Field *fields = result->Fetch(); mails_count = fields[0].GetUInt32(); - delete result; } } //do not allow to have more than 100 mails in mailbox.. mails count is in opcode uint8!!! - so max can be 255.. diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 5e41fcb3c57..0a6498e5c58 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -2357,7 +2357,7 @@ void Map::AddObjectToRemoveList(WorldObject *obj) { assert(obj->GetMapId()==GetId() && obj->GetInstanceId()==GetInstanceId()); - obj->CleanupsBeforeDelete(); // remove or simplify at least cross referenced links + obj->CleanupsBeforeDelete(false); // remove or simplify at least cross referenced links i_objectsToRemove.insert(obj); //sLog.outDebug("Object (GUID: %u TypeId: %u ) added to removing list.",obj->GetGUIDLow(),obj->GetTypeId()); @@ -2761,7 +2761,7 @@ void InstanceMap::CreateInstanceData(bool load) if (load) { // TODO: make a global storage for this - QueryResult* result = CharacterDatabase.PQuery("SELECT data FROM instance WHERE map = '%u' AND id = '%u'", GetId(), i_InstanceId); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data FROM instance WHERE map = '%u' AND id = '%u'", GetId(), i_InstanceId); if (result) { Field* fields = result->Fetch(); @@ -2771,7 +2771,6 @@ void InstanceMap::CreateInstanceData(bool load) sLog.outDebug("Loading instance data for `%s` with id %u", objmgr.GetScriptName(i_script_id), i_InstanceId); i_data->Load(data); } - delete result; } } } diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index b57f9b8d2c1..efc59aadbd1 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -358,12 +358,9 @@ void MapManager::InitMaxInstanceId() { i_MaxInstanceId = 0; - QueryResult *result = CharacterDatabase.Query("SELECT MAX(id) FROM instance"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(id) FROM instance"); if (result) - { i_MaxInstanceId = result->Fetch()[0].GetUInt32(); - delete result; - } } uint32 MapManager::GetNumInstances() diff --git a/src/game/MiscHandler.cpp b/src/game/MiscHandler.cpp index bb52ac3b52e..e1cf4165005 100644 --- a/src/game/MiscHandler.cpp +++ b/src/game/MiscHandler.cpp @@ -537,7 +537,7 @@ void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data ) CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack, GetAccountId(), friendNote, "SELECT guid, race, account FROM characters WHERE name = '%s'", friendName.c_str()); } -void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote) +void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId, std::string friendNote) { uint64 friendGuid; uint64 friendAcctid; @@ -558,8 +558,6 @@ void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 acc team = Player::TeamForRace((*result)[1].GetUInt8()); friendAcctid = (*result)[2].GetUInt32(); - delete result; - if ( session->GetSecurity() >= SEC_MODERATOR || sWorld.getConfig(CONFIG_ALLOW_GM_FRIEND) || accmgr.GetSecurity(friendAcctid) < SEC_MODERATOR) { if(friendGuid) @@ -627,7 +625,7 @@ void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data ) CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str()); } -void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId) +void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId) { uint64 IgnoreGuid; FriendsResult ignoreResult; @@ -644,8 +642,6 @@ void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 acc { IgnoreGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER); - delete result; - if(IgnoreGuid) { if(IgnoreGuid==session->GetPlayer()->GetGUID()) //not add yourself @@ -1306,7 +1302,7 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data) uint32 accid = plr->GetSession()->GetAccountId(); - QueryResult *result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid); if(!result) { SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str()); @@ -1330,8 +1326,6 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data) data << msg; _player->GetSession()->SendPacket(&data); - delete result; - sLog.outDebug("Received whois command from player %s for character %s", GetPlayer()->GetName(), charname.c_str()); } diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index f145456f2e4..9e674e74706 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -522,7 +522,7 @@ void WorldSession::SendStablePet(uint64 guid ) } // 0 1 2 3 4 - QueryResult* result = CharacterDatabase.PQuery("SELECT owner, id, entry, level, name FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot", + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT owner, id, entry, level, name FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot", _player->GetGUIDLow(),PET_SAVE_FIRST_STABLE_SLOT,PET_SAVE_LAST_STABLE_SLOT); if(result) @@ -539,8 +539,6 @@ void WorldSession::SendStablePet(uint64 guid ) ++num; }while( result->NextRow() ); - - delete result; } data.put<uint8>(wpos, num); // set real data to placeholder @@ -581,7 +579,7 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data ) uint32 free_slot = 1; - QueryResult *result = CharacterDatabase.PQuery("SELECT owner,slot,id FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot ", + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT owner,slot,id FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot ", _player->GetGUIDLow(),PET_SAVE_FIRST_STABLE_SLOT,PET_SAVE_LAST_STABLE_SLOT); if(result) { @@ -598,8 +596,6 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data ) // this slot not free, skip ++free_slot; }while( result->NextRow() ); - - delete result; } WorldPacket data(SMSG_STABLE_RESULT, 1); @@ -636,13 +632,12 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data ) uint32 creature_id = 0; { - QueryResult *result = CharacterDatabase.PQuery("SELECT entry FROM character_pet WHERE owner = '%u' AND id = '%u' AND slot >='%u' AND slot <= '%u'", + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT entry FROM character_pet WHERE owner = '%u' AND id = '%u' AND slot >='%u' AND slot <= '%u'", _player->GetGUIDLow(),petnumber,PET_SAVE_FIRST_STABLE_SLOT,PET_SAVE_LAST_STABLE_SLOT); if(result) { Field *fields = result->Fetch(); creature_id = fields[0].GetUInt32(); - delete result; } } @@ -762,7 +757,7 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data ) return; // find swapped pet slot in stable - QueryResult *result = CharacterDatabase.PQuery("SELECT slot,entry FROM character_pet WHERE owner = '%u' AND id = '%u'", + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT slot,entry FROM character_pet WHERE owner = '%u' AND id = '%u'", _player->GetGUIDLow(),pet_number); if(!result) return; @@ -771,7 +766,6 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data ) uint32 slot = fields[0].GetUInt32(); uint32 creature_id = fields[1].GetUInt32(); - delete result; if(!creature_id) { diff --git a/src/game/Object.cpp b/src/game/Object.cpp index eeb96db5798..7433113f051 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1165,7 +1165,7 @@ void WorldObject::setActive( bool on ) } } -void WorldObject::CleanupsBeforeDelete() +void WorldObject::CleanupsBeforeDelete(bool finalCleanup) { } diff --git a/src/game/Object.h b/src/game/Object.h index aea0216e688..b97fd4798ff 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -571,7 +571,7 @@ class TRINITY_DLL_SPEC WorldObject : public Object, public WorldLocation bool IsInBetween(const WorldObject *obj1, const WorldObject *obj2, float size = 0) const; - virtual void CleanupsBeforeDelete(); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units + virtual void CleanupsBeforeDelete(bool finalCleanup = true); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units virtual void SendMessageToSet(WorldPacket *data, bool self); virtual void SendMessageToSetInRange(WorldPacket *data, float dist, bool self); diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 3416fcff41d..e91aefe4b31 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -319,7 +319,7 @@ void ObjectMgr::LoadCreatureLocales() { mCreatureLocaleMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,subname_loc1,name_loc2,subname_loc2,name_loc3,subname_loc3,name_loc4,subname_loc4,name_loc5,subname_loc5,name_loc6,subname_loc6,name_loc7,subname_loc7,name_loc8,subname_loc8 FROM locales_creature"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,name_loc1,subname_loc1,name_loc2,subname_loc2,name_loc3,subname_loc3,name_loc4,subname_loc4,name_loc5,subname_loc5,name_loc6,subname_loc6,name_loc7,subname_loc7,name_loc8,subname_loc8 FROM locales_creature"); if(!result) return; @@ -364,8 +364,6 @@ void ObjectMgr::LoadCreatureLocales() } } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu creature locale strings", (unsigned long)mCreatureLocaleMap.size() ); } @@ -374,7 +372,7 @@ void ObjectMgr::LoadNpcOptionLocales() { mGossipMenuItemsLocaleMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT menu_id,id," + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT menu_id,id," "option_text_loc1,box_text_loc1,option_text_loc2,box_text_loc2," "option_text_loc3,box_text_loc3,option_text_loc4,box_text_loc4," "option_text_loc5,box_text_loc5,option_text_loc6,box_text_loc6," @@ -425,8 +423,6 @@ void ObjectMgr::LoadNpcOptionLocales() } } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu gossip_menu_option locale strings", (unsigned long)mGossipMenuItemsLocaleMap.size() ); } @@ -435,7 +431,7 @@ void ObjectMgr::LoadPointOfInterestLocales() { mPointOfInterestLocaleMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry,icon_name_loc1,icon_name_loc2,icon_name_loc3,icon_name_loc4,icon_name_loc5,icon_name_loc6,icon_name_loc7,icon_name_loc8 FROM locales_points_of_interest"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,icon_name_loc1,icon_name_loc2,icon_name_loc3,icon_name_loc4,icon_name_loc5,icon_name_loc6,icon_name_loc7,icon_name_loc8 FROM locales_points_of_interest"); if(!result) return; @@ -468,8 +464,6 @@ void ObjectMgr::LoadPointOfInterestLocales() } } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu points_of_interest locale strings", (unsigned long)mPointOfInterestLocaleMap.size() ); } @@ -1122,7 +1116,7 @@ bool ObjectMgr::CheckCreatureLinkedRespawn(uint32 guid, uint32 linkedGuid) const void ObjectMgr::LoadCreatureLinkedRespawn() { mCreatureLinkedRespawnMap.clear(); - QueryResult *result = WorldDatabase.Query("SELECT guid, linkedGuid FROM creature_linked_respawn ORDER BY guid ASC"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT guid, linkedGuid FROM creature_linked_respawn ORDER BY guid ASC"); if(!result) { @@ -1150,8 +1144,6 @@ void ObjectMgr::LoadCreatureLinkedRespawn() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u linked respawns", mCreatureLinkedRespawnMap.size() ); } @@ -1181,7 +1173,7 @@ void ObjectMgr::LoadCreatures() { uint32 count = 0; // 0 1 2 3 - QueryResult *result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid," + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT creature.guid, id, map, modelid," // 4 5 6 7 8 9 10 11 "equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint," // 12 13 14 15 16 17 18 19 @@ -1357,8 +1349,6 @@ void ObjectMgr::LoadCreatures() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu creatures", (unsigned long)mCreatureDataMap.size() ); } @@ -1537,7 +1527,7 @@ void ObjectMgr::LoadGameobjects() uint32 count = 0; // 0 1 2 3 4 5 6 - QueryResult *result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation," + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT gameobject.guid, id, map, position_x, position_y, position_z, orientation," // 7 8 9 10 11 12 13 14 15 16 17 "rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, spawnMask, phaseMask, event, pool_entry " "FROM gameobject LEFT OUTER JOIN game_event_gameobject ON gameobject.guid = game_event_gameobject.guid " @@ -1674,8 +1664,6 @@ void ObjectMgr::LoadGameobjects() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu gameobjects", (unsigned long)mGameObjectDataMap.size()); } @@ -1716,7 +1704,7 @@ void ObjectMgr::LoadCreatureRespawnTimes() { uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM creature_respawn"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM creature_respawn"); if (!result) { @@ -1745,8 +1733,6 @@ void ObjectMgr::LoadCreatureRespawnTimes() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu creature respawn times", (unsigned long)mCreatureRespawnTimes.size() ); } @@ -1758,7 +1744,7 @@ void ObjectMgr::LoadGameobjectRespawnTimes() uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM gameobject_respawn"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM gameobject_respawn"); if(!result) { @@ -1787,8 +1773,6 @@ void ObjectMgr::LoadGameobjectRespawnTimes() ++count; } while (result->NextRow()); - delete result; - sLog.outString( ">> Loaded %lu gameobject respawn times", (unsigned long)mGORespawnTimes.size() ); sLog.outString(); } @@ -1801,14 +1785,10 @@ uint64 ObjectMgr::GetPlayerGUIDByName(std::string name) const CharacterDatabase.escape_string(name); // Player name safe to sending to DB (checked at login) and this function using - QueryResult *result = CharacterDatabase.PQuery("SELECT guid FROM characters WHERE name = '%s'", name.c_str()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT guid FROM characters WHERE name = '%s'", name.c_str()); if(result) - { guid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER); - delete result; - } - return guid; } @@ -1821,12 +1801,11 @@ bool ObjectMgr::GetPlayerNameByGUID(const uint64 &guid, std::string &name) const return true; } - QueryResult *result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid = '%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid = '%u'", GUID_LOPART(guid)); if(result) { name = (*result)[0].GetCppString(); - delete result; return true; } @@ -1841,12 +1820,11 @@ uint32 ObjectMgr::GetPlayerTeamByGUID(const uint64 &guid) const return Player::TeamForRace(player->getRace()); } - QueryResult *result = CharacterDatabase.PQuery("SELECT race FROM characters WHERE guid = '%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT race FROM characters WHERE guid = '%u'", GUID_LOPART(guid)); if(result) { uint8 race = (*result)[0].GetUInt8(); - delete result; return Player::TeamForRace(race); } @@ -1861,11 +1839,10 @@ uint32 ObjectMgr::GetPlayerAccountIdByGUID(const uint64 &guid) const return player->GetSession()->GetAccountId(); } - QueryResult *result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE guid = '%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE guid = '%u'", GUID_LOPART(guid)); if(result) { uint32 acc = (*result)[0].GetUInt32(); - delete result; return acc; } @@ -1874,11 +1851,10 @@ uint32 ObjectMgr::GetPlayerAccountIdByGUID(const uint64 &guid) const uint32 ObjectMgr::GetPlayerAccountIdByPlayerName(const std::string& name) const { - QueryResult *result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", name.c_str()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name = '%s'", name.c_str()); if(result) { uint32 acc = (*result)[0].GetUInt32(); - delete result; return acc; } @@ -1889,7 +1865,7 @@ void ObjectMgr::LoadItemLocales() { mItemLocaleMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,description_loc1,name_loc2,description_loc2,name_loc3,description_loc3,name_loc4,description_loc4,name_loc5,description_loc5,name_loc6,description_loc6,name_loc7,description_loc7,name_loc8,description_loc8 FROM locales_item"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,name_loc1,description_loc1,name_loc2,description_loc2,name_loc3,description_loc3,name_loc4,description_loc4,name_loc5,description_loc5,name_loc6,description_loc6,name_loc7,description_loc7,name_loc8,description_loc8 FROM locales_item"); if(!result) return; @@ -1935,8 +1911,6 @@ void ObjectMgr::LoadItemLocales() } } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu Item locale strings", (unsigned long)mItemLocaleMap.size() ); } @@ -2359,7 +2333,7 @@ void ObjectMgr::LoadItemRequiredTarget() uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM item_required_target"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM item_required_target"); if (!result) { @@ -2450,8 +2424,6 @@ void ObjectMgr::LoadItemRequiredTarget() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u Item required targets", count); } @@ -2461,7 +2433,7 @@ void ObjectMgr::LoadPetLevelInfo() // Loading levels data { // 0 1 2 3 4 5 6 7 8 9 - QueryResult *result = WorldDatabase.Query("SELECT creature_entry, level, hp, mana, str, agi, sta, inte, spi, armor FROM pet_levelstats"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT creature_entry, level, hp, mana, str, agi, sta, inte, spi, armor FROM pet_levelstats"); uint32 count = 0; @@ -2528,8 +2500,6 @@ void ObjectMgr::LoadPetLevelInfo() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u level pet stats definitions", count ); } @@ -2575,7 +2545,7 @@ void ObjectMgr::LoadPlayerInfo() // Load playercreate { // 0 1 2 3 4 5 6 - QueryResult *result = WorldDatabase.Query("SELECT race, class, map, zone, position_x, position_y, position_z FROM playercreateinfo"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT race, class, map, zone, position_x, position_y, position_z FROM playercreateinfo"); uint32 count = 0; @@ -2657,8 +2627,6 @@ void ObjectMgr::LoadPlayerInfo() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u player create definitions", count ); } @@ -2667,7 +2635,7 @@ void ObjectMgr::LoadPlayerInfo() sLog.outString("Loading Player Create Items Data..."); { // 0 1 2 3 - QueryResult *result = WorldDatabase.Query("SELECT race, class, itemid, amount FROM playercreateinfo_item"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT race, class, itemid, amount FROM playercreateinfo_item"); uint32 count = 0; @@ -2727,8 +2695,6 @@ void ObjectMgr::LoadPlayerInfo() } while(result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u custom player create items", count ); } @@ -2738,7 +2704,7 @@ void ObjectMgr::LoadPlayerInfo() sLog.outString("Loading Player Create Spell Data..."); { - QueryResult *result = NULL; + QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL); if(sWorld.getConfig(CONFIG_START_ALL_SPELLS)) result = WorldDatabase.Query("SELECT race, class, Spell, Active FROM playercreateinfo_spell_custom"); else @@ -2794,8 +2760,6 @@ void ObjectMgr::LoadPlayerInfo() } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u player create spells", count ); } @@ -2805,7 +2769,7 @@ void ObjectMgr::LoadPlayerInfo() sLog.outString("Loading Player Create Action Data..."); { // 0 1 2 3 4 - QueryResult *result = WorldDatabase.Query("SELECT race, class, button, action, type FROM playercreateinfo_action"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT race, class, button, action, type FROM playercreateinfo_action"); uint32 count = 0; @@ -2847,8 +2811,6 @@ void ObjectMgr::LoadPlayerInfo() } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u player create actions", count ); } @@ -2858,7 +2820,7 @@ void ObjectMgr::LoadPlayerInfo() sLog.outString("Loading Player Create Level HP/Mana Data..."); { // 0 1 2 3 - QueryResult *result = WorldDatabase.Query("SELECT class, level, basehp, basemana FROM player_classlevelstats"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT class, level, basehp, basemana FROM player_classlevelstats"); uint32 count = 0; @@ -2913,8 +2875,6 @@ void ObjectMgr::LoadPlayerInfo() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u level health/mana definitions", count ); } @@ -2950,7 +2910,7 @@ void ObjectMgr::LoadPlayerInfo() sLog.outString("Loading Player Create Level Stats Data..."); { // 0 1 2 3 4 5 6 7 - QueryResult *result = WorldDatabase.Query("SELECT race, class, level, str, agi, sta, inte, spi FROM player_levelstats"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT race, class, level, str, agi, sta, inte, spi FROM player_levelstats"); uint32 count = 0; @@ -3014,8 +2974,6 @@ void ObjectMgr::LoadPlayerInfo() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u level stats definitions", count ); } @@ -3074,7 +3032,7 @@ void ObjectMgr::LoadPlayerInfo() mPlayerXPperLevel[level] = 0; // 0 1 - QueryResult *result = WorldDatabase.Query("SELECT lvl, xp_for_next_level FROM player_xp_for_level"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT lvl, xp_for_next_level FROM player_xp_for_level"); uint32 count = 0; @@ -3115,8 +3073,6 @@ void ObjectMgr::LoadPlayerInfo() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u xp for level definitions", count ); } @@ -3241,7 +3197,7 @@ void ObjectMgr::LoadGuilds() Guild *newguild; uint32 count = 0; - QueryResult *result = CharacterDatabase.Query( "SELECT guildid FROM guild" ); + QueryResult_AutoPtr result = CharacterDatabase.Query( "SELECT guildid FROM guild" ); if (!result) { @@ -3275,8 +3231,6 @@ void ObjectMgr::LoadGuilds() }while (result->NextRow()); - delete result; - //delete unused LogGuid records in guild_eventlog and guild_bank_eventlog table //you can comment these lines if you don't plan to change CONFIG_GUILD_EVENT_LOG_COUNT and CONFIG_GUILD_BANK_EVENT_LOG_COUNT CharacterDatabase.PQuery("DELETE FROM guild_eventlog WHERE LogGuid > '%u'", sWorld.getConfig(CONFIG_GUILD_EVENT_LOG_COUNT)); @@ -3290,7 +3244,7 @@ void ObjectMgr::LoadArenaTeams() { uint32 count = 0; - QueryResult *result = CharacterDatabase.Query( "SELECT arenateamid FROM arena_team" ); + QueryResult_AutoPtr result = CharacterDatabase.Query( "SELECT arenateamid FROM arena_team" ); if( !result ) { @@ -3322,8 +3276,6 @@ void ObjectMgr::LoadArenaTeams() AddArenaTeam(newarenateam); }while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u arenateam definitions", count ); } @@ -3335,7 +3287,7 @@ void ObjectMgr::LoadGroups() uint64 leaderGuid = 0; uint32 count = 0; // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 - QueryResult *result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups"); if( !result ) { @@ -3367,8 +3319,6 @@ void ObjectMgr::LoadGroups() AddGroup(group); }while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u group definitions", count ); @@ -3409,7 +3359,6 @@ void ObjectMgr::LoadGroups() CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", fields[0].GetUInt32()); } }while( result->NextRow() ); - delete result; } // clean groups @@ -3479,7 +3428,6 @@ void ObjectMgr::LoadGroups() InstanceSave *save = sInstanceSaveManager.AddInstanceSave(mapEntry->MapID, fields[2].GetUInt32(), Difficulty(diff), (time_t)fields[5].GetUInt64(), (fields[6].GetUInt32() == 0), true); group->BindToInstance(save, fields[3].GetBool(), true); }while( result->NextRow() ); - delete result; } sLog.outString(); @@ -3499,7 +3447,7 @@ void ObjectMgr::LoadQuests() mExclusiveQuestGroups.clear(); // 0 1 2 3 4 5 6 7 8 - QueryResult *result = WorldDatabase.Query("SELECT entry, Method, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue," + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, Method, ZoneOrSort, SkillOrClass, MinLevel, QuestLevel, Type, RequiredRaces, RequiredSkillValue," // 9 10 11 12 13 14 15 16 17 18 "RepObjectiveFaction, RepObjectiveValue, RepObjectiveFaction2, RepObjectiveValue2, RequiredMinRepFaction, RequiredMinRepValue, RequiredMaxRepFaction, RequiredMaxRepValue, SuggestedPlayers, LimitTime," // 19 20 21 22 23 24 25 26 27 28 29 30 @@ -3557,8 +3505,6 @@ void ObjectMgr::LoadQuests() mQuestTemplates[newQuest->GetQuestId()] = newQuest; } while( result->NextRow() ); - delete result; - std::map<uint32,uint32> usedMailTemplates; // Post processing @@ -4173,7 +4119,7 @@ void ObjectMgr::LoadQuestLocales() { mQuestLocaleMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry," + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry," "Title_loc1,Details_loc1,Objectives_loc1,OfferRewardText_loc1,RequestItemsText_loc1,EndText_loc1,ObjectiveText1_loc1,ObjectiveText2_loc1,ObjectiveText3_loc1,ObjectiveText4_loc1," "Title_loc2,Details_loc2,Objectives_loc2,OfferRewardText_loc2,RequestItemsText_loc2,EndText_loc2,ObjectiveText1_loc2,ObjectiveText2_loc2,ObjectiveText3_loc2,ObjectiveText4_loc2," "Title_loc3,Details_loc3,Objectives_loc3,OfferRewardText_loc3,RequestItemsText_loc3,EndText_loc3,ObjectiveText1_loc3,ObjectiveText2_loc3,ObjectiveText3_loc3,ObjectiveText4_loc3," @@ -4291,8 +4237,6 @@ void ObjectMgr::LoadQuestLocales() } } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu Quest locale strings", (unsigned long)mQuestLocaleMap.size() ); } @@ -4306,7 +4250,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) scripts.clear(); // need for reload support - QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename ); + QueryResult_AutoPtr result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename ); uint32 count = 0; @@ -4555,8 +4499,6 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) ++count; } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u script definitions", count ); } @@ -4694,10 +4636,9 @@ void ObjectMgr::LoadWaypointScripts() for (ScriptMapMap::const_iterator itr = sWaypointScripts.begin(); itr != sWaypointScripts.end(); ++itr) { - QueryResult *query = WorldDatabase.PQuery("SELECT * FROM waypoint_scripts WHERE id = %u", itr->first); + QueryResult_AutoPtr query = WorldDatabase.PQuery("SELECT * FROM waypoint_scripts WHERE id = %u", itr->first); if(!query || !query->GetRowCount()) sLog.outErrorDb("There is no waypoint which links to the waypoint script %u", itr->first); - delete query; } } @@ -4710,7 +4651,7 @@ void ObjectMgr::LoadGossipScripts() void ObjectMgr::LoadItemTexts() { - QueryResult *result = CharacterDatabase.Query("SELECT id, text FROM item_text"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id, text FROM item_text"); uint32 count = 0; @@ -4739,8 +4680,6 @@ void ObjectMgr::LoadItemTexts() } while ( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u item texts", count ); } @@ -4793,7 +4732,7 @@ void ObjectMgr::LoadPageTextLocales() { mPageTextLocaleMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text"); if(!result) return; @@ -4827,8 +4766,6 @@ void ObjectMgr::LoadPageTextLocales() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu PageText locale strings", (unsigned long)mPageTextLocaleMap.size() ); } @@ -4877,7 +4814,7 @@ GossipText const *ObjectMgr::GetGossipText(uint32 Text_ID) const void ObjectMgr::LoadGossipText() { - QueryResult *result = WorldDatabase.Query( "SELECT * FROM npc_text" ); + QueryResult_AutoPtr result = WorldDatabase.Query( "SELECT * FROM npc_text" ); int count = 0; if( !result ) @@ -4930,14 +4867,13 @@ void ObjectMgr::LoadGossipText() sLog.outString(); sLog.outString( ">> Loaded %u npc texts", count ); - delete result; } void ObjectMgr::LoadNpcTextLocales() { mNpcTextLocaleMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry," + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry," "Text0_0_loc1,Text0_1_loc1,Text1_0_loc1,Text1_1_loc1,Text2_0_loc1,Text2_1_loc1,Text3_0_loc1,Text3_1_loc1,Text4_0_loc1,Text4_1_loc1,Text5_0_loc1,Text5_1_loc1,Text6_0_loc1,Text6_1_loc1,Text7_0_loc1,Text7_1_loc1," "Text0_0_loc2,Text0_1_loc2,Text1_0_loc2,Text1_1_loc2,Text2_0_loc2,Text2_1_loc2,Text3_0_loc2,Text3_1_loc1,Text4_0_loc2,Text4_1_loc2,Text5_0_loc2,Text5_1_loc2,Text6_0_loc2,Text6_1_loc2,Text7_0_loc2,Text7_1_loc2," "Text0_0_loc3,Text0_1_loc3,Text1_0_loc3,Text1_1_loc3,Text2_0_loc3,Text2_1_loc3,Text3_0_loc3,Text3_1_loc1,Text4_0_loc3,Text4_1_loc3,Text5_0_loc3,Text5_1_loc3,Text6_0_loc3,Text6_1_loc3,Text7_0_loc3,Text7_1_loc3," @@ -4994,8 +4930,6 @@ void ObjectMgr::LoadNpcTextLocales() } } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu NpcText locale strings", (unsigned long)mNpcTextLocaleMap.size() ); } @@ -5009,7 +4943,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp) if (!serverUp) CharacterDatabase.PExecute("DELETE FROM mail WHERE expire_time < '" UI64FMTD "' AND has_items = '0' AND itemTextId = 0", (uint64)basetime); // 0 1 2 3 4 5 6 7 8 9 - QueryResult* result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,itemTextId,has_items,expire_time,cod,checked,mailTemplateId FROM mail WHERE expire_time < '" UI64FMTD "'", (uint64)basetime); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,itemTextId,has_items,expire_time,cod,checked,mailTemplateId FROM mail WHERE expire_time < '" UI64FMTD "'", (uint64)basetime); if ( !result ) { barGoLink bar(1); @@ -5058,7 +4992,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp) //delete or return mail: if (has_items) { - QueryResult *resultItems = CharacterDatabase.PQuery("SELECT item_guid,item_template FROM mail_items WHERE mail_id='%u'", m->messageID); + QueryResult_AutoPtr resultItems = CharacterDatabase.PQuery("SELECT item_guid,item_template FROM mail_items WHERE mail_id='%u'", m->messageID); if(resultItems) { do @@ -5071,8 +5005,6 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp) m->AddItem(item_guid_low, item_template); } while (resultItems->NextRow()); - - delete resultItems; } //if it is mail from AH, it shouldn't be returned, but deleted if (m->messageType != MAIL_NORMAL || (m->checked & (MAIL_CHECK_MASK_AUCTION | MAIL_CHECK_MASK_COD_PAYMENT | MAIL_CHECK_MASK_RETURNED))) @@ -5099,7 +5031,6 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp) delete m; ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u mails", count ); @@ -5109,7 +5040,7 @@ void ObjectMgr::LoadQuestAreaTriggers() { mQuestAreaTriggerMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query( "SELECT id,quest FROM areatrigger_involvedrelation" ); + QueryResult_AutoPtr result = WorldDatabase.Query( "SELECT id,quest FROM areatrigger_involvedrelation" ); uint32 count = 0; @@ -5164,8 +5095,6 @@ void ObjectMgr::LoadQuestAreaTriggers() } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u quest trigger points", count ); } @@ -5174,7 +5103,7 @@ void ObjectMgr::LoadTavernAreaTriggers() { mTavernAreaTriggerSet.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT id FROM areatrigger_tavern"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id FROM areatrigger_tavern"); uint32 count = 0; @@ -5209,8 +5138,6 @@ void ObjectMgr::LoadTavernAreaTriggers() mTavernAreaTriggerSet.insert(Trigger_ID); } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u tavern triggers", count ); } @@ -5218,7 +5145,7 @@ void ObjectMgr::LoadTavernAreaTriggers() void ObjectMgr::LoadAreaTriggerScripts() { mAreaTriggerScripts.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry, ScriptName FROM areatrigger_scripts"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, ScriptName FROM areatrigger_scripts"); uint32 count = 0; @@ -5253,8 +5180,6 @@ void ObjectMgr::LoadAreaTriggerScripts() mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName); } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u areatrigger scripts", count ); } @@ -5407,7 +5332,7 @@ void ObjectMgr::LoadGraveyardZones() { mGraveYardMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT id,ghost_zone,faction FROM game_graveyard_zone"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id,ghost_zone,faction FROM game_graveyard_zone"); uint32 count = 0; @@ -5464,8 +5389,6 @@ void ObjectMgr::LoadGraveyardZones() sLog.outErrorDb("Table `game_graveyard_zone` has a duplicate record for Graveyard (ID: %u) and Zone (ID: %u), skipped.",safeLocId,zoneId); } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u graveyard-zone links", count ); } @@ -5676,7 +5599,7 @@ void ObjectMgr::LoadAreaTriggerTeleports() uint32 count = 0; // 0 1 2 3 4 5 6 - QueryResult *result = WorldDatabase.Query("SELECT id, access_id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM areatrigger_teleport"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, access_id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM areatrigger_teleport"); if( !result ) { @@ -5734,8 +5657,6 @@ void ObjectMgr::LoadAreaTriggerTeleports() } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u area trigger teleport definitions", count ); } @@ -5747,7 +5668,7 @@ void ObjectMgr::LoadAccessRequirements() uint32 count = 0; // 0 1 2 3 4 5 6 7 8 9 10 11 - QueryResult *result = WorldDatabase.Query("SELECT id, level_min, level_max, item, item2, heroic_key, heroic_key2, quest_done, quest_failed_text, heroic_quest_done, heroic_quest_failed_text, heroic_level_min FROM access_requirement"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, level_min, level_max, item, item2, heroic_key, heroic_key2, quest_done, quest_failed_text, heroic_quest_done, heroic_quest_failed_text, heroic_level_min FROM access_requirement"); if( !result ) { @@ -5850,8 +5771,6 @@ void ObjectMgr::LoadAccessRequirements() } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u access requirement definitions", count ); } @@ -5894,26 +5813,17 @@ AreaTrigger const* ObjectMgr::GetMapEntranceTrigger(uint32 Map) const void ObjectMgr::SetHighestGuids() { - QueryResult *result = CharacterDatabase.Query( "SELECT MAX(guid) FROM characters" ); + QueryResult_AutoPtr result = CharacterDatabase.Query( "SELECT MAX(guid) FROM characters" ); if( result ) - { m_hiCharGuid = (*result)[0].GetUInt32()+1; - delete result; - } result = WorldDatabase.Query( "SELECT MAX(guid) FROM creature" ); if( result ) - { m_hiCreatureGuid = (*result)[0].GetUInt32()+1; - delete result; - } result = CharacterDatabase.Query( "SELECT MAX(guid) FROM item_instance" ); if( result ) - { m_hiItemGuid = (*result)[0].GetUInt32()+1; - delete result; - } // Cleanup other tables from not existed guids (>=m_hiItemGuid) CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", m_hiItemGuid); @@ -5923,59 +5833,35 @@ void ObjectMgr::SetHighestGuids() result = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject" ); if( result ) - { m_hiGoGuid = (*result)[0].GetUInt32()+1; - delete result; - } result = CharacterDatabase.Query("SELECT MAX(id) FROM auctionhouse" ); if( result ) - { m_auctionid = (*result)[0].GetUInt32()+1; - delete result; - } result = CharacterDatabase.Query( "SELECT MAX(id) FROM mail" ); if( result ) - { m_mailid = (*result)[0].GetUInt32()+1; - delete result; - } result = CharacterDatabase.Query( "SELECT MAX(id) FROM item_text" ); if( result ) - { m_ItemTextId = (*result)[0].GetUInt32()+1; - delete result; - } result = CharacterDatabase.Query( "SELECT MAX(guid) FROM corpse" ); if( result ) - { m_hiCorpseGuid = (*result)[0].GetUInt32()+1; - delete result; - } result = CharacterDatabase.Query("SELECT MAX(arenateamid) FROM arena_team"); if (result) - { m_arenaTeamId = (*result)[0].GetUInt32()+1; - delete result; - } result = CharacterDatabase.Query("SELECT MAX(setguid) FROM character_equipmentsets"); if (result) - { m_equipmentSetGuid = (*result)[0].GetUInt64()+1; - delete result; - } result = CharacterDatabase.Query( "SELECT MAX(guildid) FROM guild" ); if (result) - { m_guildId = (*result)[0].GetUInt32()+1; - delete result; - } } uint32 ObjectMgr::GenerateArenaTeamId() @@ -6124,7 +6010,7 @@ void ObjectMgr::LoadGameObjectLocales() { mGameObjectLocaleMap.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT entry," + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry," "name_loc1,name_loc2,name_loc3,name_loc4,name_loc5,name_loc6,name_loc7,name_loc8," "castbarcaption_loc1,castbarcaption_loc2,castbarcaption_loc3,castbarcaption_loc4," "castbarcaption_loc5,castbarcaption_loc6,castbarcaption_loc7,castbarcaption_loc8 FROM locales_gameobject"); @@ -6177,8 +6063,6 @@ void ObjectMgr::LoadGameObjectLocales() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %lu gameobject locale strings", (unsigned long)mGameObjectLocaleMap.size() ); } @@ -6422,7 +6306,7 @@ void ObjectMgr::LoadGameobjectInfo() void ObjectMgr::LoadExplorationBaseXP() { uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT level,basexp FROM exploration_basexp"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT level,basexp FROM exploration_basexp"); if (!result) { @@ -6449,8 +6333,6 @@ void ObjectMgr::LoadExplorationBaseXP() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u BaseXP definitions", count ); } @@ -6470,7 +6352,7 @@ uint32 ObjectMgr::GetXPForLevel(uint8 level) void ObjectMgr::LoadPetNames() { uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT word,entry,half FROM pet_name_generation"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT word,entry,half FROM pet_name_generation"); if (!result) { @@ -6500,7 +6382,6 @@ void ObjectMgr::LoadPetNames() ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u pet name parts", count ); @@ -6508,12 +6389,11 @@ void ObjectMgr::LoadPetNames() void ObjectMgr::LoadPetNumber() { - QueryResult* result = CharacterDatabase.Query("SELECT MAX(id) FROM character_pet"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(id) FROM character_pet"); if (result) { Field *fields = result->Fetch(); m_hiPetNumber = fields[0].GetUInt32()+1; - delete result; } barGoLink bar(1); @@ -6549,7 +6429,7 @@ void ObjectMgr::LoadCorpses() { uint32 count = 0; // 0 1 2 3 4 5 6 7 8 10 - QueryResult *result = CharacterDatabase.Query("SELECT position_x, position_y, position_z, orientation, map, data, time, corpse_type, instance, guid FROM corpse WHERE corpse_type <> 0"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT position_x, position_y, position_z, orientation, map, data, time, corpse_type, instance, guid FROM corpse WHERE corpse_type <> 0"); if(!result) { @@ -6584,7 +6464,6 @@ void ObjectMgr::LoadCorpses() ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString(">> Loaded %u corpses", count); @@ -6595,7 +6474,7 @@ void ObjectMgr::LoadReputationOnKill() uint32 count = 0; // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT creature_id, RewOnKillRepFaction1, RewOnKillRepFaction2," + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT creature_id, RewOnKillRepFaction1, RewOnKillRepFaction2," // 3 4 5 6 7 8 9 "IsTeamAward1, MaxStanding1, RewOnKillRepValue1, IsTeamAward2, MaxStanding2, RewOnKillRepValue2, TeamDependent " "FROM creature_onkill_reputation"); @@ -6662,8 +6541,6 @@ void ObjectMgr::LoadReputationOnKill() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u creature award reputation definitions", count); } @@ -6673,7 +6550,7 @@ void ObjectMgr::LoadPointsOfInterest() uint32 count = 0; // 0 1 2 3 4 5 6 - QueryResult *result = WorldDatabase.Query("SELECT entry, x, y, icon, flags, data, icon_name FROM points_of_interest"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, x, y, icon, flags, data, icon_name FROM points_of_interest"); if(!result) { @@ -6714,8 +6591,6 @@ void ObjectMgr::LoadPointsOfInterest() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u Points of Interest definitions", count); } @@ -6726,7 +6601,7 @@ void ObjectMgr::LoadNPCSpellClickSpells() mSpellClickInfoMap.clear(); // 0 1 2 3 4 5 6 7 8 - QueryResult *result = WorldDatabase.Query("SELECT npc_entry, spell_id, quest_start, quest_start_active, quest_end, cast_flags, aura_required, aura_forbidden, user_type FROM npc_spellclick_spells"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT npc_entry, spell_id, quest_start, quest_start_active, quest_end, cast_flags, aura_required, aura_forbidden, user_type FROM npc_spellclick_spells"); if(!result) { @@ -6834,8 +6709,6 @@ void ObjectMgr::LoadNPCSpellClickSpells() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u spellclick definitions", count); } @@ -6845,7 +6718,7 @@ void ObjectMgr::LoadWeatherZoneChances() uint32 count = 0; // 0 1 2 3 4 5 6 7 8 9 10 11 12 - QueryResult *result = WorldDatabase.Query("SELECT zone, spring_rain_chance, spring_snow_chance, spring_storm_chance, summer_rain_chance, summer_snow_chance, summer_storm_chance, fall_rain_chance, fall_snow_chance, fall_storm_chance, winter_rain_chance, winter_snow_chance, winter_storm_chance FROM game_weather"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT zone, spring_rain_chance, spring_snow_chance, spring_storm_chance, summer_rain_chance, summer_snow_chance, summer_storm_chance, fall_rain_chance, fall_snow_chance, fall_storm_chance, winter_rain_chance, winter_snow_chance, winter_storm_chance FROM game_weather"); if(!result) { @@ -6897,8 +6770,6 @@ void ObjectMgr::LoadWeatherZoneChances() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u weather definitions", count); } @@ -6985,7 +6856,7 @@ void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map,char const* table) uint32 count = 0; - QueryResult *result = WorldDatabase.PQuery("SELECT id,quest FROM %s",table); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id,quest FROM %s",table); if (!result) { @@ -7019,8 +6890,6 @@ void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map,char const* table) ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u quest relations from %s", count,table); } @@ -7085,7 +6954,7 @@ void ObjectMgr::LoadReservedPlayersNames() { m_ReservedNames.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT name FROM reserved_name"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT name FROM reserved_name"); uint32 count = 0; @@ -7121,8 +6990,6 @@ void ObjectMgr::LoadReservedPlayersNames() ++count; } while ( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u reserved player names", count ); } @@ -7395,7 +7262,7 @@ bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 mi ++itr; } - QueryResult *result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s",table); + QueryResult_AutoPtr result = db.PQuery("SELECT entry,content_default,content_loc1,content_loc2,content_loc3,content_loc4,content_loc5,content_loc6,content_loc7,content_loc8 FROM %s",table); if (!result) { @@ -7465,8 +7332,6 @@ bool ObjectMgr::LoadTrinityStrings(DatabaseType& db, char const* table, int32 mi } } while (result->NextRow()); - delete result; - sLog.outString(); if (min_value == MIN_TRINITY_STRING_ID) sLog.outString( ">> Loaded %u Trinity strings from table %s", count,table); @@ -7500,7 +7365,7 @@ void ObjectMgr::LoadSpellDisabledEntrys() m_DisabledPlayerSpells.clear(); // need for reload case m_DisabledCreatureSpells.clear(); m_DisabledPetSpells.clear(); - QueryResult *result = WorldDatabase.Query("SELECT entry, disable_mask FROM spell_disabled"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, disable_mask FROM spell_disabled"); uint32 total_count = 0; @@ -7537,8 +7402,6 @@ void ObjectMgr::LoadSpellDisabledEntrys() ++total_count; } while ( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u disabled spells from `spell_disabled`", total_count); } @@ -7548,7 +7411,7 @@ void ObjectMgr::LoadFishingBaseSkillLevel() mFishingBaseForArea.clear(); // for reload case uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT entry,skill FROM skill_fishing_base_level"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,skill FROM skill_fishing_base_level"); if( !result ) { @@ -7583,8 +7446,6 @@ void ObjectMgr::LoadFishingBaseSkillLevel() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u areas for fishing base skill level", count ); } @@ -7875,7 +7736,7 @@ void ObjectMgr::LoadGameTele() m_GameTeleMap.clear(); // for reload case uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, map, name FROM game_tele"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, map, name FROM game_tele"); if( !result ) { @@ -7926,7 +7787,6 @@ void ObjectMgr::LoadGameTele() ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u GameTeleports", count ); @@ -8005,7 +7865,7 @@ void ObjectMgr::LoadMailLevelRewards() m_mailLevelRewardMap.clear(); // for reload case uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT level, raceMask, mailTemplateId, senderEntry FROM mail_level_reward"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT level, raceMask, mailTemplateId, senderEntry FROM mail_level_reward"); if( !result ) { @@ -8060,7 +7920,6 @@ void ObjectMgr::LoadMailLevelRewards() ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u level dependent mail rewards,", count ); @@ -8075,7 +7934,7 @@ void ObjectMgr::LoadTrainerSpell() std::set<uint32> skip_trainers; - QueryResult *result = WorldDatabase.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer"); if( !result ) { @@ -8174,7 +8033,6 @@ void ObjectMgr::LoadTrainerSpell() ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString( ">> Loaded %d Trainers", count ); @@ -8189,7 +8047,7 @@ void ObjectMgr::LoadVendors() std::set<uint32> skip_vendors; - QueryResult *result = WorldDatabase.Query("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor"); if( !result ) { barGoLink bar( 1 ); @@ -8224,7 +8082,6 @@ void ObjectMgr::LoadVendors() ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString( ">> Loaded %d Vendors ", count ); @@ -8235,7 +8092,7 @@ void ObjectMgr::LoadNpcTextId() m_mCacheNpcTextIdMap.clear(); - QueryResult* result = WorldDatabase.Query("SELECT npc_guid, textid FROM npc_gossip"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT npc_guid, textid FROM npc_gossip"); if( !result ) { barGoLink bar( 1 ); @@ -8275,7 +8132,6 @@ void ObjectMgr::LoadNpcTextId() ++count; } while (result->NextRow()); - delete result; sLog.outString(); sLog.outString( ">> Loaded %d NpcTextId ", count ); @@ -8285,7 +8141,7 @@ void ObjectMgr::LoadGossipMenu() { m_mGossipMenusMap.clear(); - QueryResult* result = WorldDatabase.Query("SELECT entry, text_id, " + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, text_id, " "cond_1, cond_1_val_1, cond_1_val_2, cond_2, cond_2_val_1, cond_2_val_2 FROM gossip_menu"); if(!result) @@ -8348,8 +8204,6 @@ void ObjectMgr::LoadGossipMenu() } while(result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u gossip_menu entries", count); } @@ -8358,7 +8212,7 @@ void ObjectMgr::LoadGossipMenuItems() { m_mGossipMenuItemsMap.clear(); - QueryResult *result = WorldDatabase.Query( + QueryResult_AutoPtr result = WorldDatabase.Query( "SELECT menu_id, id, option_icon, option_text, option_id, npc_option_npcflag, " "action_menu_id, action_poi_id, action_script_id, box_coded, box_money, box_text, " "cond_1, cond_1_val_1, cond_1_val_2, " @@ -8476,8 +8330,6 @@ void ObjectMgr::LoadGossipMenuItems() } while(result->NextRow()); - delete result; - if (!gossipScriptSet.empty()) { for(std::set<uint32>::const_iterator itr = gossipScriptSet.begin(); itr != gossipScriptSet.end(); ++itr) @@ -8600,7 +8452,7 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, int32 ma void ObjectMgr::LoadScriptNames() { m_scriptNames.push_back(""); - QueryResult *result = WorldDatabase.Query( + QueryResult_AutoPtr result = WorldDatabase.Query( "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " "UNION " "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' " @@ -8632,7 +8484,6 @@ void ObjectMgr::LoadScriptNames() m_scriptNames.push_back((*result)[0].GetString()); ++count; } while (result->NextRow()); - delete result; std::sort(m_scriptNames.begin(), m_scriptNames.end()); sLog.outString(); @@ -8735,7 +8586,7 @@ CreatureInfo const *GetCreatureInfo(uint32 id) void ObjectMgr::LoadTransportEvents() { - QueryResult *result = WorldDatabase.Query("SELECT entry, waypoint_id, event_id FROM transport_events"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, waypoint_id, event_id FROM transport_events"); if( !result ) { @@ -8764,8 +8615,6 @@ void ObjectMgr::LoadTransportEvents() while(result->NextRow()); sLog.outString( "\n>> Loaded %u transport events \n", result->GetRowCount() ); - - delete result; } CreatureInfo const* GetCreatureTemplateStore(uint32 entry) @@ -8792,7 +8641,7 @@ void ObjectMgr::LoadGMTickets() } m_GMTicketList.clear(); - QueryResult *result = CharacterDatabase.Query( "SELECT guid, playerGuid, name, message, createtime, map, posX, posY, posZ, timestamp, closed, assignedto, comment FROM gm_tickets" ); + QueryResult_AutoPtr result = CharacterDatabase.Query( "SELECT guid, playerGuid, name, message, createtime, map, posX, posY, posZ, timestamp, closed, assignedto, comment FROM gm_tickets" ); if(!result) { @@ -8830,8 +8679,6 @@ void ObjectMgr::LoadGMTickets() } while( result->NextRow() ); - delete result; - result = CharacterDatabase.PQuery("SELECT MAX(guid) from gm_tickets"); m_GMticketid = 0; @@ -8840,7 +8687,6 @@ void ObjectMgr::LoadGMTickets() Field *fields = result->Fetch(); m_GMticketid = fields[0].GetUInt64(); } - delete result; sLog.outString(">> Loaded %u GM Tickets from the database.", count); } @@ -8917,7 +8763,7 @@ CreatureBaseStats const* ObjectMgr::GetCreatureBaseStats(uint32 level, uint8 uni void ObjectMgr::LoadCreatureClassLevelStats() { - QueryResult *result = WorldDatabase.Query("SELECT level, class, basehp0, basehp1, basehp2, basemana, basearmor, basedmg, baserangeddmg FROM creature_classlevelstats"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT level, class, basehp0, basehp1, basehp2, basemana, basearmor FROM creature_classlevelstats"); if (!result) { @@ -8941,8 +8787,6 @@ void ObjectMgr::LoadCreatureClassLevelStats() stats.BaseHealth[i] = fields[i + 2].GetUInt32(); stats.BaseMana = fields[5].GetUInt32(); stats.BaseArmor = fields[6].GetUInt32(); - stats.BaseDmg = fields[7].GetUInt32(); - stats.BaseRangedDmg = fields[8].GetUInt32(); if (stats.Level > STRONG_MAX_LEVEL) { @@ -8972,8 +8816,6 @@ void ObjectMgr::LoadCreatureClassLevelStats() } while (result->NextRow()); - delete result; - for (uint32 i = 0; i < sCreatureStorage.MaxEntry; ++i) { CreatureInfo const* info = sCreatureStorage.LookupEntry<CreatureInfo>(i); @@ -8989,8 +8831,6 @@ void ObjectMgr::LoadCreatureClassLevelStats() CreatureBaseStats new_stats = CreatureBaseStats(); new_stats.BaseArmor = 1; - new_stats.BaseDmg = 1; - new_stats.BaseRangedDmg = 1; for (uint8 j = 0; j < MAX_CREATURE_BASE_HP; ++j) new_stats.BaseHealth[j] = 1; new_stats.BaseMana = 0; diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index b1a058690e1..b5a42b2101f 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -108,7 +108,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool uint32 ownerid = owner->GetGUIDLow(); - QueryResult *result; + QueryResult_AutoPtr result; if (petnumber) // known petnumber entry 0 1 2(?) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @@ -141,10 +141,7 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool // update for case of current pet "slot = 0" petentry = fields[1].GetUInt32(); if (!petentry) - { - delete result; return false; - } uint32 summon_spell_id = fields[17].GetUInt32(); SpellEntry const* spellInfo = sSpellStore.LookupEntry(summon_spell_id); @@ -153,20 +150,14 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool // check temporary summoned pets like mage water elemental if (current && is_temporary_summoned) - { - delete result; return false; - } PetType pet_type = PetType(fields[18].GetUInt8()); if(pet_type==HUNTER_PET) { CreatureInfo const* creatureInfo = objmgr.GetCreatureTemplate(petentry); if(!creatureInfo || !creatureInfo->isTameable(owner->CanTameExoticPets())) - { - delete result; return false; - } } uint32 pet_number = fields[0].GetUInt32(); @@ -174,17 +165,13 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool if (current && owner->IsPetNeedBeTemporaryUnsummoned()) { owner->SetTemporaryUnsummonedPetNumber(pet_number); - delete result; return false; } Map *map = owner->GetMap(); uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_PET); if (!Create(guid, map, owner->GetPhaseMask(), petentry, pet_number)) - { - delete result; return false; - } float px, py, pz; owner->GetClosePoint(px, py, pz, GetObjectSize(), PET_FOLLOW_DIST, GetFollowAngle()); @@ -194,7 +181,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool { sLog.outError("Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)", GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); - delete result; return false; } @@ -206,7 +192,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool if (cinfo->type == CREATURE_TYPE_CRITTER) { map->Add((Creature*)this); - delete result; return true; } @@ -324,7 +309,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool CleanupActionBar(); // remove unknown spells from action bar after load - delete result; sLog.outDebug("New Pet has guid %u", GetGUIDLow()); owner->PetSpellInitialize(); @@ -349,7 +333,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool { m_declinedname->name[i] = fields2[i].GetCppString(); } - delete result; } } @@ -1067,7 +1050,7 @@ void Pet::_LoadSpellCooldowns() m_CreatureSpellCooldowns.clear(); m_CreatureCategoryCooldowns.clear(); - QueryResult *result = CharacterDatabase.PQuery("SELECT spell,time FROM pet_spell_cooldown WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT spell,time FROM pet_spell_cooldown WHERE guid = '%u'",m_charmInfo->GetPetNumber()); if(result) { @@ -1103,8 +1086,6 @@ void Pet::_LoadSpellCooldowns() } while (result->NextRow()); - delete result; - if(!m_CreatureSpellCooldowns.empty() && GetOwner()) ((Player*)GetOwner())->GetSession()->SendPacket(&data); } @@ -1131,7 +1112,7 @@ void Pet::_SaveSpellCooldowns() void Pet::_LoadSpells() { - QueryResult *result = CharacterDatabase.PQuery("SELECT spell,active FROM pet_spell WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT spell,active FROM pet_spell WHERE guid = '%u'",m_charmInfo->GetPetNumber()); if (result) { @@ -1142,8 +1123,6 @@ void Pet::_LoadSpells() addSpell(fields[0].GetUInt32(), ActiveStates(fields[1].GetUInt8()), PETSPELL_UNCHANGED); } while (result->NextRow()); - - delete result; } } @@ -1182,7 +1161,7 @@ void Pet::_LoadAuras(uint32 timediff) { sLog.outDebug("Loading auras for pet %u",GetGUIDLow()); - QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_mask,recalculate_mask,stackcount,amount0,amount1,amount2,base_amount0,base_amount1,base_amount2,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_mask,recalculate_mask,stackcount,amount0,amount1,amount2,base_amount0,base_amount1,base_amount2,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); if (result) { @@ -1244,8 +1223,6 @@ void Pet::_LoadAuras(uint32 timediff) } } while (result->NextRow()); - - delete result; } } @@ -1669,7 +1646,7 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/) // now need only reset for offline pets (all pets except online case) uint32 except_petnumber = online_pet ? online_pet->GetCharmInfo()->GetPetNumber() : 0; - QueryResult *resultPets = CharacterDatabase.PQuery( + QueryResult_AutoPtr resultPets = CharacterDatabase.PQuery( "SELECT id FROM character_pet WHERE owner = '%u' AND id <> '%u'", owner->GetGUIDLow(),except_petnumber); @@ -1677,16 +1654,13 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/) if (!resultPets) return; - QueryResult *result = CharacterDatabase.PQuery( + QueryResult_AutoPtr result = CharacterDatabase.PQuery( "SELECT DISTINCT pet_spell.spell FROM pet_spell, character_pet " "WHERE character_pet.owner = '%u' AND character_pet.id = pet_spell.guid AND character_pet.id <> %u", owner->GetGUIDLow(),except_petnumber); if (!result) - { - delete resultPets; return; - } bool need_comma = false; std::ostringstream ss; @@ -1707,8 +1681,6 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/) } while (resultPets->NextRow()); - delete resultPets; - ss << ") AND spell IN ("; bool need_execute = false; @@ -1730,8 +1702,6 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= NULL*/) } while (result->NextRow()); - delete result; - if (!need_execute) return; diff --git a/src/game/PetitionsHandler.cpp b/src/game/PetitionsHandler.cpp index 13d36b467d5..74a6f56705f 100644 --- a/src/game/PetitionsHandler.cpp +++ b/src/game/PetitionsHandler.cpp @@ -207,7 +207,7 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data) // a petition is invalid, if both the owner and the type matches // we checked above, if this player is in an arenateam, so this must be // datacorruption - QueryResult *result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT petitionguid FROM petition WHERE ownerguid = '%u' AND type = '%u'", _player->GetGUIDLow(), type); std::ostringstream ssInvalidPetitionGUIDs; @@ -218,8 +218,6 @@ void WorldSession::HandlePetitionBuyOpcode(WorldPacket & recv_data) Field *fields = result->Fetch(); ssInvalidPetitionGUIDs << "'" << fields[0].GetUInt32() << "' , "; } while (result->NextRow()); - - delete result; } // delete petitions with the same guid as this one @@ -248,7 +246,7 @@ void WorldSession::HandlePetitionShowSignOpcode(WorldPacket & recv_data) // solve (possible) some strange compile problems with explicit use GUID_LOPART(petitionguid) at some GCC versions (wrong code optimization in compiler?) uint32 petitionguid_low = GUID_LOPART(petitionguid); - QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", petitionguid_low); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", petitionguid_low); if(!result) { sLog.outError("Petition %u is not found for player %u %s", GUID_LOPART(petitionguid), GetPlayer()->GetGUIDLow(), GetPlayer()->GetName()); @@ -256,7 +254,6 @@ void WorldSession::HandlePetitionShowSignOpcode(WorldPacket & recv_data) } Field *fields = result->Fetch(); uint32 type = fields[0].GetUInt32(); - delete result; // if guild petition and has guild => error, return; if(type==9 && _player->GetGuildId()) @@ -286,7 +283,6 @@ void WorldSession::HandlePetitionShowSignOpcode(WorldPacket & recv_data) result->NextRow(); } - delete result; SendPacket(&data); } @@ -311,7 +307,7 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid) std::string name = "NO_NAME_FOR_GUID"; uint8 signs = 0; - QueryResult *result = CharacterDatabase.PQuery( + QueryResult_AutoPtr result = CharacterDatabase.PQuery( "SELECT ownerguid, name, " " (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, " " type " @@ -324,7 +320,6 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid) name = fields[1].GetCppString(); signs = fields[2].GetUInt8(); type = fields[3].GetUInt32(); - delete result; } else { @@ -387,13 +382,12 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket & recv_data) if(!item) return; - QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); if(result) { Field* fields = result->Fetch(); type = fields[0].GetUInt32(); - delete result; } else { @@ -451,7 +445,7 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data) recv_data >> petitionguid; // petition guid recv_data >> unk; - QueryResult *result = CharacterDatabase.PQuery( + QueryResult_AutoPtr result = CharacterDatabase.PQuery( "SELECT ownerguid, " " (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, " " type " @@ -468,8 +462,6 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data) uint8 signs = fields[1].GetUInt8(); uint32 type = fields[2].GetUInt32(); - delete result; - uint32 plguidlo = _player->GetGUIDLow(); if(GUID_LOPART(ownerguid) == plguidlo) return; @@ -531,7 +523,6 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data) if(result) { - delete result; WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8+8+4)); data << petitionguid; data << _player->GetGUID(); @@ -578,13 +569,12 @@ void WorldSession::HandlePetitionDeclineOpcode(WorldPacket & recv_data) recv_data >> petitionguid; // petition guid sLog.outDebug("Petition %u declined by %u", GUID_LOPART(petitionguid), _player->GetGUIDLow()); - QueryResult *result = CharacterDatabase.PQuery("SELECT ownerguid FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT ownerguid FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); if(!result) return; Field *fields = result->Fetch(); ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER); - delete result; Player *owner = objmgr.GetPlayer(ownerguid); if(owner) // petition owner online @@ -612,13 +602,12 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket & recv_data) if (!player) return; - QueryResult *result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); if (!result) return; Field *fields = result->Fetch(); type = fields[0].GetUInt32(); - delete result; sLog.outDebug("OFFER PETITION: type %u, GUID1 %u, to player id: %u", type, GUID_LOPART(petitionguid), GUID_LOPART(plguid)); @@ -694,7 +683,6 @@ void WorldSession::HandleOfferPetitionOpcode(WorldPacket & recv_data) result->NextRow(); } - delete result; player->GetSession()->SendPacket(&data); } @@ -715,14 +703,13 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) sLog.outDebug("Petition %u turned in by %u", GUID_LOPART(petitionguid), _player->GetGUIDLow()); // data - QueryResult *result = CharacterDatabase.PQuery("SELECT ownerguid, name, type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT ownerguid, name, type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); if(result) { Field *fields = result->Fetch(); ownerguidlo = fields[0].GetUInt32(); name = fields[1].GetCppString(); type = fields[2].GetUInt32(); - delete result; } else { @@ -778,7 +765,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) data.Initialize(SMSG_TURN_IN_PETITION_RESULTS, 4); data << (uint32)PETITION_TURN_NEED_MORE_SIGNATURES; // need more signatures... SendPacket(&data); - delete result; return; } @@ -787,7 +773,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) if(objmgr.GetGuildByName(name)) { SendGuildCommandResult(GUILD_CREATE_S, name, GUILD_NAME_EXISTS); - delete result; return; } } @@ -796,7 +781,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) if(objmgr.GetArenaTeamByName(name)) { SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, name, "", ERR_ARENA_TEAM_NAME_EXISTS_S); - delete result; return; } } @@ -804,10 +788,7 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) // and at last charter item check Item *item = _player->GetItemByGuid(petitionguid); if(!item) - { - delete result; return; - } // OK! @@ -820,7 +801,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) if(!guild->Create(_player, name)) { delete guild; - delete result; return; } @@ -842,7 +822,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) { sLog.outError("PetitionsHandler: arena team create failed."); delete at; - delete result; return; } @@ -866,8 +845,6 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data) } } - delete result; - CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("DELETE FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); diff --git a/src/game/Player.cpp b/src/game/Player.cpp index b6e996f050c..a444bb79fbd 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -542,12 +542,12 @@ Player::~Player () sWorld.DecreasePlayerCount(); } -void Player::CleanupsBeforeDelete() +void Player::CleanupsBeforeDelete(bool finalCleanup) { TradeCancel(false); DuelComplete(DUEL_INTERUPTED); - Unit::CleanupsBeforeDelete(); + Unit::CleanupsBeforeDelete(finalCleanup); if (m_transport) m_transport->RemovePassenger(this); @@ -1468,7 +1468,7 @@ void Player::setDeathState(DeathState s) } } -bool Player::BuildEnumData( QueryResult * result, WorldPacket * p_data ) +bool Player::BuildEnumData( QueryResult_AutoPtr result, WorldPacket * p_data ) { // 0 1 2 3 4 5 6 7 // "SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, " @@ -3690,7 +3690,7 @@ void Player::RemoveAllSpellCooldown() } } -void Player::_LoadSpellCooldowns(QueryResult *result) +void Player::_LoadSpellCooldowns(QueryResult_AutoPtr result) { // some cooldowns can be already set at aura loading... @@ -3723,8 +3723,6 @@ void Player::_LoadSpellCooldowns(QueryResult *result) sLog.outDebug("Player (GUID: %u) spell %u, item %u cooldown loaded (%u secs).", GetGUIDLow(), spell_id, item_id, uint32(db_time-curTime)); } while( result->NextRow() ); - - delete result; } } @@ -4166,11 +4164,10 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC LeaveAllArenaTeams(playerguid); // the player was uninvited already on logout so just remove from group - QueryResult *resultGroup = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", guid); + QueryResult_AutoPtr resultGroup = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", guid); if(resultGroup) { uint64 leaderGuid = MAKE_NEW_GUID((*resultGroup)[0].GetUInt32(), 0, HIGHGUID_PLAYER); - delete resultGroup; Group* group = objmgr.GetGroupByLeader(leaderGuid); if(group) { @@ -4182,7 +4179,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC RemovePetitionsAndSigns(playerguid, 10); // return back all mails with COD and Item 0 1 2 3 4 5 6 7 - QueryResult *resultMail = CharacterDatabase.PQuery("SELECT id,messageType,mailTemplateId,sender,subject,itemTextId,money,has_items FROM mail WHERE receiver='%u' AND has_items<>0 AND cod<>0", guid); + QueryResult_AutoPtr resultMail = CharacterDatabase.PQuery("SELECT id,messageType,mailTemplateId,sender,subject,itemTextId,money,has_items FROM mail WHERE receiver='%u' AND has_items<>0 AND cod<>0", guid); if(resultMail) { do @@ -4217,7 +4214,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC if(has_items) { // data needs to be at first place for Item::LoadFromDB - QueryResult *resultItems = CharacterDatabase.PQuery("SELECT data,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id); + QueryResult_AutoPtr resultItems = CharacterDatabase.PQuery("SELECT data,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id); if(resultItems) { do @@ -4245,8 +4242,6 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC draft.AddItem(pItem); } while (resultItems->NextRow()); - - delete resultItems; } } @@ -4257,13 +4252,11 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC draft.AddMoney(money).SendReturnToSender(pl_account, guid, sender); } while (resultMail->NextRow()); - - delete resultMail; } // unsummon and delete for pets in world is not required: player deleted from CLI or character list with not loaded pet. // Get guids of character's pets, will deleted in transaction - QueryResult *resultPets = CharacterDatabase.PQuery("SELECT id FROM character_pet WHERE owner = '%u'",guid); + QueryResult_AutoPtr resultPets = CharacterDatabase.PQuery("SELECT id FROM character_pet WHERE owner = '%u'",guid); // NOW we can finally clear other DB data related to character CharacterDatabase.BeginTransaction(); @@ -4275,7 +4268,6 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC uint32 petguidlow = fields3[0].GetUInt32(); Pet::DeleteFromDB(petguidlow); } while (resultPets->NextRow()); - delete resultPets; } CharacterDatabase.PExecute("DELETE FROM characters WHERE guid = '%u'",guid); @@ -6545,22 +6537,20 @@ void Player::ModifyArenaPoints(int32 value) uint32 Player::GetGuildIdFromDB(uint64 guid) { - QueryResult* result = CharacterDatabase.PQuery("SELECT guildid FROM guild_member WHERE guid='%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT guildid FROM guild_member WHERE guid='%u'", GUID_LOPART(guid)); if(!result) return 0; uint32 id = result->Fetch()[0].GetUInt32(); - delete result; return id; } uint32 Player::GetRankFromDB(uint64 guid) { - QueryResult *result = CharacterDatabase.PQuery( "SELECT rank FROM guild_member WHERE guid='%u'", GUID_LOPART(guid) ); + QueryResult_AutoPtr result = CharacterDatabase.PQuery( "SELECT rank FROM guild_member WHERE guid='%u'", GUID_LOPART(guid) ); if( result ) { uint32 v = result->Fetch()[0].GetUInt32(); - delete result; return v; } else @@ -6569,24 +6559,22 @@ uint32 Player::GetRankFromDB(uint64 guid) uint32 Player::GetArenaTeamIdFromDB(uint64 guid, uint8 type) { - QueryResult *result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u' AND type='%u' LIMIT 1", GUID_LOPART(guid), type); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u' AND type='%u' LIMIT 1", GUID_LOPART(guid), type); if(!result) return 0; uint32 id = (*result)[0].GetUInt32(); - delete result; return id; } uint32 Player::GetZoneIdFromDB(uint64 guid) { uint32 guidLow = GUID_LOPART(guid); - QueryResult *result = CharacterDatabase.PQuery( "SELECT zone FROM characters WHERE guid='%u'", guidLow ); + QueryResult_AutoPtr result = CharacterDatabase.PQuery( "SELECT zone FROM characters WHERE guid='%u'", guidLow ); if (!result) return 0; Field* fields = result->Fetch(); uint32 zone = fields[0].GetUInt32(); - delete result; if (!zone) { @@ -6599,7 +6587,6 @@ uint32 Player::GetZoneIdFromDB(uint64 guid) float posx = fields[1].GetFloat(); float posy = fields[2].GetFloat(); float posz = fields[3].GetFloat(); - delete result; zone = MapManager::Instance().GetZoneId(map,posx,posy,posz); @@ -6612,13 +6599,12 @@ uint32 Player::GetZoneIdFromDB(uint64 guid) uint32 Player::GetLevelFromDB(uint64 guid) { - QueryResult *result = CharacterDatabase.PQuery("SELECT level FROM characters WHERE guid='%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT level FROM characters WHERE guid='%u'", GUID_LOPART(guid)); if (!result) return 0; Field* fields = result->Fetch(); uint8 level = fields[0].GetUInt8(); - delete result; return level; } @@ -15158,9 +15144,8 @@ void Player::SendQuestUpdateAddCreatureOrGo( Quest const* pQuest, uint64 guid, u /*** LOAD SYSTEM ***/ /*********************************************************/ -bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid ) +bool Player::MinimalLoadFromDB( QueryResult_AutoPtr result, uint32 guid ) { - bool delete_result = true; if (!result) { // 0 1 2 3 4 5 6 7 8 9 10 11 @@ -15168,16 +15153,12 @@ bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid ) if (!result) return false; } - else - delete_result = false; Field *fields = result->Fetch(); if (!LoadValues( fields[1].GetString())) { sLog.outError("Player #%d have broken data in `data` field. Can't be loaded for character list.",GUID_LOPART(guid)); - if (delete_result) - delete result; return false; } @@ -15206,9 +15187,6 @@ bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid ) _LoadBoundInstances();*/ - if (delete_result) - delete result; - for (uint8 i = 0; i < PLAYER_SLOTS_COUNT; i++) m_items[i] = NULL; @@ -15218,7 +15196,7 @@ bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid ) return true; } -void Player::_LoadDeclinedNames(QueryResult* result) +void Player::_LoadDeclinedNames(QueryResult_AutoPtr result) { if(!result) return; @@ -15230,11 +15208,9 @@ void Player::_LoadDeclinedNames(QueryResult* result) Field *fields = result->Fetch(); for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) m_declinedname->name[i] = fields[i].GetCppString(); - - delete result; } -void Player::_LoadArenaTeamInfo(QueryResult *result) +void Player::_LoadArenaTeamInfo(QueryResult_AutoPtr result) { // arenateamid, played_week, played_season, personal_rating memset((void*)&m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1], 0, sizeof(uint32) * MAX_ARENA_SLOT * ARENA_TEAM_END); @@ -15268,10 +15244,9 @@ void Player::_LoadArenaTeamInfo(QueryResult *result) m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (arenaSlot * ARENA_TEAM_END) + ARENA_TEAM_PERSONAL_RATING] = personal_rating; // Personal Rating }while (result->NextRow()); - delete result; } -void Player::_LoadEquipmentSets(QueryResult *result) +void Player::_LoadEquipmentSets(QueryResult_AutoPtr result) { // SetPQuery(PLAYER_LOGIN_QUERY_LOADEQUIPMENTSETS, "SELECT setguid, setindex, name, iconname, item0, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18 FROM character_equipmentsets WHERE guid = '%u' ORDER BY setindex", GUID_LOPART(m_guid)); if (!result) @@ -15300,10 +15275,9 @@ void Player::_LoadEquipmentSets(QueryResult *result) if(count >= MAX_EQUIPMENT_SET_INDEX) // client limit break; } while (result->NextRow()); - delete result; } -void Player::_LoadBGData(QueryResult* result) +void Player::_LoadBGData(QueryResult_AutoPtr result) { if (!result) return; @@ -15321,13 +15295,11 @@ void Player::_LoadBGData(QueryResult* result) m_bgData.taxiPath[0] = fields[7].GetUInt32(); m_bgData.taxiPath[1] = fields[8].GetUInt32(); m_bgData.mountSpell = fields[9].GetUInt32(); - - delete result; } bool Player::LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float& o, bool& in_flight, uint64 guid) { - QueryResult *result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,taxi_path FROM characters WHERE guid = '%u'",GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map,taxi_path FROM characters WHERE guid = '%u'",GUID_LOPART(guid)); if(!result) return false; @@ -15340,13 +15312,12 @@ bool Player::LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float& mapid = fields[4].GetUInt32(); in_flight = !fields[5].GetCppString().empty(); - delete result; return true; } bool Player::LoadValuesArrayFromDB(Tokens& data, uint64 guid) { - QueryResult *result = CharacterDatabase.PQuery("SELECT data FROM characters WHERE guid='%u'",GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data FROM characters WHERE guid='%u'",GUID_LOPART(guid)); if( !result ) return false; @@ -15354,8 +15325,6 @@ bool Player::LoadValuesArrayFromDB(Tokens& data, uint64 guid) data = StrSplit(fields[0].GetCppString(), " "); - delete result; - return true; } @@ -15398,7 +15367,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) { //// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 //QueryResult *result = CharacterDatabase.PQuery("SELECT guid, account, data, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty, arena_pending_points, instance_id, speccount, activespec FROM characters WHERE guid = '%u'", guid); - QueryResult *result = holder->GetResult(PLAYER_LOGIN_QUERY_LOADFROM); + QueryResult_AutoPtr result = holder->GetResult(PLAYER_LOGIN_QUERY_LOADFROM); if(!result) { @@ -15415,7 +15384,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) if( dbAccountId != GetSession()->GetAccountId() ) { sLog.outError("Player (GUID: %u) loading from wrong account (is: %u, should be: %u)",guid,GetSession()->GetAccountId(),dbAccountId); - delete result; return false; } @@ -15427,7 +15395,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS || (GetSession()->GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(m_name))) { - delete result; CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid ='%u'", uint32(AT_LOGIN_RENAME),guid); return false; } @@ -15435,7 +15402,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) if(!LoadValues( fields[2].GetString())) { sLog.outError("Player #%d have broken data in `data` field. Can't be loaded.", GUID_LOPART(guid)); - delete result; return false; } @@ -15485,10 +15451,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) // load home bind and check in same time class/race pair, it used later for restore broken positions if(!_LoadHomeBind(holder->GetResult(PLAYER_LOGIN_QUERY_LOADHOMEBIND))) - { - delete result; return false; - } InitPrimaryProfessions(); // to max set before any spell loaded @@ -15720,7 +15683,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) if (!map) { sLog.outError("ERROR: Player (guidlow %d) has invalid default map coordinates (X: %f Y: %f Z: %f O: %f). or instance couldn't be created",guid,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); - delete result; return false; } } @@ -15860,7 +15822,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) m_specsCount = fields[42].GetUInt8(); m_activeSpec = fields[43].GetUInt8(); - delete result; // sanity check if (m_specsCount > MAX_TALENT_SPECS || m_activeSpec > MAX_TALENT_SPEC || @@ -16023,7 +15984,7 @@ bool Player::isAllowedToLoot(Creature* creature) return !creature->hasLootRecipient(); } -void Player::_LoadActions(QueryResult *result, bool startup) +void Player::_LoadActions(QueryResult_AutoPtr result, bool startup) { if (result) { @@ -16050,12 +16011,10 @@ void Player::_LoadActions(QueryResult *result, bool startup) } } while (result->NextRow()); - - delete result; } } -void Player::_LoadAuras(QueryResult *result, uint32 timediff) +void Player::_LoadAuras(QueryResult_AutoPtr result, uint32 timediff) { sLog.outDebug("Loading auras for player %u",GetGUIDLow()); @@ -16121,8 +16080,6 @@ void Player::_LoadAuras(QueryResult *result, uint32 timediff) } } while (result->NextRow()); - - delete result; } if(getClass() == CLASS_WARRIOR && !HasAuraType(SPELL_AURA_MOD_SHAPESHIFT)) @@ -16173,7 +16130,7 @@ void Player::LoadCorpse() } } -void Player::_LoadInventory(QueryResult *result, uint32 timediff) +void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff) { //QueryResult *result = CharacterDatabase.PQuery("SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GetGUIDLow()); std::map<uint64, Bag*> bagMap; // fast guid lookup for bags @@ -16309,7 +16266,6 @@ void Player::_LoadInventory(QueryResult *result, uint32 timediff) } } while (result->NextRow()); - delete result; m_itemUpdateQueueBlocked = false; // send by mail problematic items @@ -16339,7 +16295,7 @@ void Player::_LoadInventory(QueryResult *result, uint32 timediff) void Player::_LoadMailedItems(Mail *mail) { // data needs to be at first place for Item::LoadFromDB - QueryResult* result = CharacterDatabase.PQuery("SELECT data, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID); if (!result) return; @@ -16374,11 +16330,9 @@ void Player::_LoadMailedItems(Mail *mail) AddMItem(item); } while (result->NextRow()); - - delete result; } -void Player::_LoadMailInit(QueryResult *resultUnread, QueryResult *resultDelivery) +void Player::_LoadMailInit(QueryResult_AutoPtr resultUnread, QueryResult_AutoPtr resultDelivery) { //set a count of unread mails //QueryResult *resultMails = CharacterDatabase.PQuery("SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" UI64FMTD "'", GUID_LOPART(playerGuid),(uint64)cTime); @@ -16386,7 +16340,6 @@ void Player::_LoadMailInit(QueryResult *resultUnread, QueryResult *resultDeliver { Field *fieldMail = resultUnread->Fetch(); unReadMails = fieldMail[0].GetUInt8(); - delete resultUnread; } // store nearest delivery time (it > 0 and if it < current then at next player update SendNewMaill will be called) @@ -16395,7 +16348,6 @@ void Player::_LoadMailInit(QueryResult *resultUnread, QueryResult *resultDeliver { Field *fieldMail = resultDelivery->Fetch(); m_nextMailDelivereTime = (time_t)fieldMail[0].GetUInt64(); - delete resultDelivery; } } @@ -16403,7 +16355,7 @@ void Player::_LoadMail() { m_mail.clear(); //mails are in right order 0 1 2 3 4 5 6 7 8 9 10 11 12 13 - QueryResult *result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked,stationery,mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC",GetGUIDLow()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked,stationery,mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC",GetGUIDLow()); if (result) { do @@ -16438,7 +16390,6 @@ void Player::_LoadMail() m_mail.push_back(m); } while (result->NextRow()); - delete result; } m_mailsLoaded = true; } @@ -16455,7 +16406,7 @@ void Player::LoadPet() } } -void Player::_LoadQuestStatus(QueryResult *result) +void Player::_LoadQuestStatus(QueryResult_AutoPtr result) { mQuestStatus.clear(); @@ -16557,8 +16508,6 @@ void Player::_LoadQuestStatus(QueryResult *result) } } while (result->NextRow()); - - delete result; } // clear quest log tail @@ -16566,7 +16515,7 @@ void Player::_LoadQuestStatus(QueryResult *result) SetQuestSlot(i, 0); } -void Player::_LoadDailyQuestStatus(QueryResult *result) +void Player::_LoadDailyQuestStatus(QueryResult_AutoPtr result) { for (uint32 quest_daily_idx = 0; quest_daily_idx < PLAYER_MAX_DAILY_QUESTS; ++quest_daily_idx) SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1+quest_daily_idx,0); @@ -16602,14 +16551,12 @@ void Player::_LoadDailyQuestStatus(QueryResult *result) sLog.outDebug("Daily quest {%u} cooldown for player (GUID: %u)", quest_id, GetGUIDLow()); } while (result->NextRow()); - - delete result; } m_DailyQuestChanged = false; } -void Player::_LoadSpells(QueryResult *result) +void Player::_LoadSpells(QueryResult_AutoPtr result) { //QueryResult *result = CharacterDatabase.PQuery("SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'",GetGUIDLow()); @@ -16622,18 +16569,15 @@ void Player::_LoadSpells(QueryResult *result) addSpell(fields[0].GetUInt32(), fields[1].GetBool(), false, false, fields[2].GetBool()); } while (result->NextRow()); - - delete result; } } -void Player::_LoadGroup(QueryResult *result) +void Player::_LoadGroup(QueryResult_AutoPtr result) { //QueryResult *result = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", GetGUIDLow()); if (result) { uint64 leaderGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER); - delete result; if (Group* group = objmgr.GetGroupByLeader(leaderGuid)) { uint8 subgroup = group->GetMemberGroup(GetGUID()); @@ -16648,7 +16592,7 @@ void Player::_LoadGroup(QueryResult *result) } } -void Player::_LoadBoundInstances(QueryResult *result) +void Player::_LoadBoundInstances(QueryResult_AutoPtr result) { for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) m_boundInstances[i].clear(); @@ -16706,7 +16650,6 @@ void Player::_LoadBoundInstances(QueryResult *result) if (InstanceSave *save = sInstanceSaveManager.AddInstanceSave(mapId, instanceId, Difficulty(difficulty), resetTime, !perm, true)) BindToInstance(save, perm, true); } while (result->NextRow()); - delete result; } } @@ -16986,7 +16929,7 @@ bool Player::Satisfy(AccessRequirement const *ar, uint32 target_map, bool report return true; } -bool Player::_LoadHomeBind(QueryResult *result) +bool Player::_LoadHomeBind(QueryResult_AutoPtr result) { PlayerInfo const *info = objmgr.GetPlayerInfo(getRace(), getClass()); if (!info) @@ -17005,7 +16948,6 @@ bool Player::_LoadHomeBind(QueryResult *result) m_homebindX = fields[2].GetFloat(); m_homebindY = fields[3].GetFloat(); m_homebindZ = fields[4].GetFloat(); - delete result; MapEntry const* bindMapEntry = sMapStore.LookupEntry(m_homebindMapId); @@ -17638,7 +17580,7 @@ void Player::SetFloatValueInDB(uint16 index, float value, uint64 guid) void Player::Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8 hairStyle, uint8 hairColor, uint8 facialHair) { // 0 - QueryResult* result = CharacterDatabase.PQuery("SELECT playerBytes2 FROM characters WHERE guid = '%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT playerBytes2 FROM characters WHERE guid = '%u'", GUID_LOPART(guid)); if(!result) return; @@ -17649,8 +17591,6 @@ void Player::Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8 player_bytes2 |= facialHair; CharacterDatabase.PExecute("UPDATE characters SET gender = '%u', playerBytes = '%u', playerBytes2 = '%u' WHERE guid = '%u'", gender, skin | (face << 8) | (hairStyle << 16) | (hairColor << 24), player_bytes2, GUID_LOPART(guid)); - - delete result; } void Player::SendAttackSwingDeadTarget() @@ -18448,7 +18388,7 @@ void Player::SendProficiency(uint8 pr1, uint32 pr2) void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type) { - QueryResult *result = NULL; + QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL); if(type==10) result = CharacterDatabase.PQuery("SELECT ownerguid,petitionguid FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid)); else @@ -18468,8 +18408,6 @@ void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type) } while ( result->NextRow() ); - delete result; - if(type==10) CharacterDatabase.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid)); else @@ -18492,7 +18430,7 @@ void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type) void Player::LeaveAllArenaTeams(uint64 guid) { - QueryResult *result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u'", GUID_LOPART(guid)); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u'", GUID_LOPART(guid)); if(!result) return; @@ -18507,8 +18445,6 @@ void Player::LeaveAllArenaTeams(uint64 guid) at->DelMember(guid); } } while (result->NextRow()); - - delete result; } void Player::SetRestBonus (float rest_bonus_new) @@ -21906,7 +21842,7 @@ void Player::learnSpellHighRank(uint32 spellid) learnSpellHighRank(next); } -void Player::_LoadSkills(QueryResult *result) +void Player::_LoadSkills(QueryResult_AutoPtr result) { // 0 1 2 // SetPQuery(PLAYER_LOGIN_QUERY_LOADSKILLS, "SELECT skill, value, max FROM character_skills WHERE guid = '%u'", GUID_LOPART(m_guid)); @@ -21969,7 +21905,6 @@ void Player::_LoadSkills(QueryResult *result) break; } } while (result->NextRow()); - delete result; } for (; count < PLAYER_MAX_SKILLS; ++count) @@ -22813,7 +22748,7 @@ void Player::SetMap(Map * map) m_mapRef.link(map, this); } -void Player::_LoadGlyphs(QueryResult *result) +void Player::_LoadGlyphs(QueryResult_AutoPtr result) { // SetPQuery(PLAYER_LOGIN_QUERY_LOADGLYPHS, "SELECT spec, glyph1, glyph2, glyph3, glyph4, glyph5, glyph6 from character_glyphs WHERE guid = '%u'", GUID_LOPART(m_guid)); if (!result) @@ -22835,8 +22770,6 @@ void Player::_LoadGlyphs(QueryResult *result) m_Glyphs[spec][5] = fields[6].GetUInt32(); } while (result->NextRow()); - - delete result; } void Player::_SaveGlyphs() @@ -22849,7 +22782,7 @@ void Player::_SaveGlyphs() } } -void Player::_LoadTalents(QueryResult *result) +void Player::_LoadTalents(QueryResult_AutoPtr result) { // SetPQuery(PLAYER_LOGIN_QUERY_LOADTALENTS, "SELECT spell, spec FROM character_talent WHERE guid = '%u'", GUID_LOPART(m_guid)); if (result) @@ -22861,8 +22794,6 @@ void Player::_LoadTalents(QueryResult *result) AddTalent(fields[0].GetUInt32(), fields[1].GetUInt32(), false); } while( result->NextRow() ); - - delete result; } } @@ -23046,7 +22977,7 @@ void Player::ActivateSpec(uint8 spec) // Let client clear his current Actions SendActionButtons(2); m_actionButtons.clear(); - if (QueryResult *result = CharacterDatabase.PQuery("SELECT button,action,type FROM character_action WHERE guid = '%u' AND spec = '%u' ORDER BY button", GetGUIDLow(), m_activeSpec)) + if (QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT button,action,type FROM character_action WHERE guid = '%u' AND spec = '%u' ORDER BY button", GetGUIDLow(), m_activeSpec)) _LoadActions(result, false); ResummonPetTemporaryUnSummonedIfAny(); diff --git a/src/game/Player.h b/src/game/Player.h index 3781df95a89..8c17670700a 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -970,7 +970,7 @@ class TRINITY_DLL_SPEC Player : public Unit, public GridObject<Player> explicit Player (WorldSession *session); ~Player ( ); - void CleanupsBeforeDelete(); + void CleanupsBeforeDelete(bool finalCleanup = true); static UpdateMask updateVisualBits; static void InitVisibleBits(); @@ -1002,7 +1002,7 @@ class TRINITY_DLL_SPEC Player : public Unit, public GridObject<Player> void Update( uint32 time ); - static bool BuildEnumData( QueryResult * result, WorldPacket * p_data ); + static bool BuildEnumData( QueryResult_AutoPtr result, WorldPacket * p_data ); void SetInWater(bool apply); @@ -1377,7 +1377,7 @@ class TRINITY_DLL_SPEC Player : public Unit, public GridObject<Player> bool LoadFromDB(uint32 guid, SqlQueryHolder *holder); bool isBeingLoaded() const { return GetSession()->PlayerLoading();} - bool MinimalLoadFromDB(QueryResult *result, uint32 guid); + bool MinimalLoadFromDB(QueryResult_AutoPtr result, uint32 guid); static bool LoadValuesArrayFromDB(Tokens& data,uint64 guid); static uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index); static float GetFloatValueFromArray(Tokens const& data, uint16 index); @@ -1596,7 +1596,7 @@ class TRINITY_DLL_SPEC Player : public Unit, public GridObject<Player> void RemoveCategoryCooldown(uint32 cat); void RemoveArenaSpellCooldowns(); void RemoveAllSpellCooldown(); - void _LoadSpellCooldowns(QueryResult *result); + void _LoadSpellCooldowns(QueryResult_AutoPtr result); void _SaveSpellCooldowns(); void SetLastPotionId(uint32 item_id) { m_lastPotionId = item_id; } void UpdatePotionCooldown(Spell* spell = NULL); @@ -2326,27 +2326,27 @@ Spell * m_spellModTakingSpell; /*** LOAD SYSTEM ***/ /*********************************************************/ - void _LoadActions(QueryResult *result, bool startup); - void _LoadAuras(QueryResult *result, uint32 timediff); + void _LoadActions(QueryResult_AutoPtr result, bool startup); + void _LoadAuras(QueryResult_AutoPtr result, uint32 timediff); void _LoadGlyphAuras(); - void _LoadBoundInstances(QueryResult *result); - void _LoadInventory(QueryResult *result, uint32 timediff); - void _LoadMailInit(QueryResult *resultUnread, QueryResult *resultDelivery); + void _LoadBoundInstances(QueryResult_AutoPtr result); + void _LoadInventory(QueryResult_AutoPtr result, uint32 timediff); + void _LoadMailInit(QueryResult_AutoPtr resultUnread, QueryResult_AutoPtr resultDelivery); void _LoadMail(); void _LoadMailedItems(Mail *mail); - void _LoadQuestStatus(QueryResult *result); - void _LoadDailyQuestStatus(QueryResult *result); - void _LoadGroup(QueryResult *result); - void _LoadSkills(QueryResult *result); - void _LoadSpells(QueryResult *result); - void _LoadFriendList(QueryResult *result); - bool _LoadHomeBind(QueryResult *result); - void _LoadDeclinedNames(QueryResult *result); - void _LoadArenaTeamInfo(QueryResult *result); - void _LoadEquipmentSets(QueryResult *result); - void _LoadBGData(QueryResult* result); - void _LoadGlyphs(QueryResult *result); - void _LoadTalents(QueryResult *result); + void _LoadQuestStatus(QueryResult_AutoPtr result); + void _LoadDailyQuestStatus(QueryResult_AutoPtr result); + void _LoadGroup(QueryResult_AutoPtr result); + void _LoadSkills(QueryResult_AutoPtr result); + void _LoadSpells(QueryResult_AutoPtr result); + void _LoadFriendList(QueryResult_AutoPtr result); + bool _LoadHomeBind(QueryResult_AutoPtr result); + void _LoadDeclinedNames(QueryResult_AutoPtr result); + void _LoadArenaTeamInfo(QueryResult_AutoPtr result); + void _LoadEquipmentSets(QueryResult_AutoPtr result); + void _LoadBGData(QueryResult_AutoPtr result); + void _LoadGlyphs(QueryResult_AutoPtr result); + void _LoadTalents(QueryResult_AutoPtr result); /*********************************************************/ /*** SAVE SYSTEM ***/ diff --git a/src/game/PlayerDump.cpp b/src/game/PlayerDump.cpp index 107b282f9dd..26574d6280b 100644 --- a/src/game/PlayerDump.cpp +++ b/src/game/PlayerDump.cpp @@ -198,7 +198,7 @@ bool changetokGuid(std::string &str, int n, std::map<uint32, uint32> &guidMap, u return changetoknth(str, n, chritem, false, nonzero); } -std::string CreateDumpString(char const* tableName, QueryResult *result) +std::string CreateDumpString(char const* tableName, QueryResult_AutoPtr result) { if(!tableName || !result) return ""; std::ostringstream ss; @@ -248,7 +248,7 @@ std::string PlayerDumpWriter::GenerateWhereStr(char const* field, GUIDs const& g return wherestr.str(); } -void StoreGUID(QueryResult *result,uint32 field,std::set<uint32>& guids) +void StoreGUID(QueryResult_AutoPtr result,uint32 field,std::set<uint32>& guids) { Field* fields = result->Fetch(); uint32 guid = fields[field].GetUInt32(); @@ -256,7 +256,7 @@ void StoreGUID(QueryResult *result,uint32 field,std::set<uint32>& guids) guids.insert(guid); } -void StoreGUID(QueryResult *result,uint32 data,uint32 field, std::set<uint32>& guids) +void StoreGUID(QueryResult_AutoPtr result,uint32 data,uint32 field, std::set<uint32>& guids) { Field* fields = result->Fetch(); std::string dataStr = fields[data].GetCppString(); @@ -301,7 +301,7 @@ void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl else // not set case, get single guid string wherestr = GenerateWhereStr(fieldname,guid); - QueryResult *result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str()); if(!result) return; @@ -329,8 +329,6 @@ void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl dump += "\n"; } while (result->NextRow()); - - delete result; } while(guids && guids_itr != guids->end()); // not set case iterate single time, set case iterate for all guids } @@ -400,13 +398,12 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s { // check character count { - QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", account); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", account); uint8 charcount = 0; if (result) { Field *fields=result->Fetch(); charcount = fields[0].GetUInt8(); - delete result; if (charcount >= 10) return DUMP_TOO_MANY_CHARS; @@ -417,7 +414,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s if (!fin) return DUMP_FILE_OPEN_ERROR; - QueryResult * result = NULL; + QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL); char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20]; // make sure the same guid doesn't already exist and is safe to use @@ -426,10 +423,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s { result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE guid = '%d'", guid); if (result) - { guid = objmgr.m_hiCharGuid; // use first free if exists - delete result; - } else incHighest = false; } else @@ -444,10 +438,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s CharacterDatabase.escape_string(name); // for safe, we use name only for sql quearies anyway result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE name = '%s'", name.c_str()); if (result) - { name = ""; // use the one from the dump - delete result; - } } else name = ""; @@ -557,8 +548,6 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s result = CharacterDatabase.PQuery("SELECT * FROM characters WHERE name = '%s'", name.c_str()); if (result) { - delete result; - if(!changenth(line, 37, "1")) // rename on login: `at_login` field 37 in raw field list ROLLBACK(DUMP_FILE_BROKEN); } diff --git a/src/game/PoolHandler.cpp b/src/game/PoolHandler.cpp index c2cb8045b81..15afb656805 100644 --- a/src/game/PoolHandler.cpp +++ b/src/game/PoolHandler.cpp @@ -350,7 +350,7 @@ PoolHandler::PoolHandler() void PoolHandler::LoadFromDB() { - QueryResult *result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template"); if (!result) { sLog.outString(">> Table pool_template is empty."); @@ -361,7 +361,6 @@ void PoolHandler::LoadFromDB() { Field *fields = result->Fetch(); max_pool_id = fields[0].GetUInt16(); - delete result; } mPoolTemplate.resize(max_pool_id + 1); @@ -392,8 +391,6 @@ void PoolHandler::LoadFromDB() } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u objects pools", count ); @@ -458,7 +455,6 @@ void PoolHandler::LoadFromDB() } while (result->NextRow()); sLog.outString(); sLog.outString( ">> Loaded %u creatures in pools", count ); - delete result; } // Gameobjects @@ -530,7 +526,6 @@ void PoolHandler::LoadFromDB() } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u gameobject in pools", count ); - delete result; } // Pool of pools @@ -619,7 +614,6 @@ void PoolHandler::LoadFromDB() } } } - delete result; sLog.outString(); sLog.outString( ">> Loaded %u pools in mother pools", count ); @@ -629,7 +623,7 @@ void PoolHandler::LoadFromDB() // The initialize method will spawn all pools not in an event and not in another pool, this is why there is 2 left joins with 2 null checks void PoolHandler::Initialize() { - QueryResult *result = WorldDatabase.Query("SELECT DISTINCT pool_template.entry FROM pool_template LEFT JOIN game_event_pool ON pool_template.entry=game_event_pool.pool_entry LEFT JOIN pool_pool ON pool_template.entry=pool_pool.pool_id WHERE game_event_pool.pool_entry IS NULL AND pool_pool.pool_id IS NULL"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT DISTINCT pool_template.entry FROM pool_template LEFT JOIN game_event_pool ON pool_template.entry=game_event_pool.pool_entry LEFT JOIN pool_pool ON pool_template.entry=pool_pool.pool_id WHERE game_event_pool.pool_entry IS NULL AND pool_pool.pool_id IS NULL"); uint32 count=0; if (result) { @@ -647,7 +641,6 @@ void PoolHandler::Initialize() SpawnPool(pool_entry, 0, TYPEID_UNIT); count++; } while (result->NextRow()); - delete result; } sLog.outBasic("Pool handling system initialized, %u pools spawned.", count); diff --git a/src/game/QueryHandler.cpp b/src/game/QueryHandler.cpp index c0a9cfd8f87..af2ffbb7272 100644 --- a/src/game/QueryHandler.cpp +++ b/src/game/QueryHandler.cpp @@ -77,17 +77,14 @@ void WorldSession::SendNameQueryOpcodeFromDB(uint64 guid) GUID_LOPART(guid)); } -void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult *result, uint32 accountId) +void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult_AutoPtr result, uint32 accountId) { if(!result) return; WorldSession * session = sWorld.FindSession(accountId); if(!session) - { - delete result; return; - } Field *fields = result->Fetch(); uint32 guid = fields[0].GetUInt32(); @@ -122,7 +119,6 @@ void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult *result, uint32 data << uint8(0); // is not declined session->SendPacket( &data ); - delete result; } void WorldSession::HandleNameQueryOpcode( WorldPacket & recv_data ) diff --git a/src/game/ReputationMgr.cpp b/src/game/ReputationMgr.cpp index bdd6af49ccc..9027ed8b426 100644 --- a/src/game/ReputationMgr.cpp +++ b/src/game/ReputationMgr.cpp @@ -459,7 +459,7 @@ void ReputationMgr::SetInactive(FactionState* faction, bool inactive) faction->Changed = true; } -void ReputationMgr::LoadFromDB(QueryResult *result) +void ReputationMgr::LoadFromDB(QueryResult_AutoPtr result) { // Set initial reputations (so everything is nifty before DB data load) Initialize(); @@ -513,8 +513,6 @@ void ReputationMgr::LoadFromDB(QueryResult *result) } } while( result->NextRow() ); - - delete result; } } diff --git a/src/game/ReputationMgr.h b/src/game/ReputationMgr.h index 6c78e0fa3b5..bb997e5ea11 100644 --- a/src/game/ReputationMgr.h +++ b/src/game/ReputationMgr.h @@ -23,6 +23,7 @@ #include "SharedDefines.h" #include "Language.h" #include "DBCStructure.h" +#include "QueryResult.h" #include <map> static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK] = @@ -68,7 +69,7 @@ class ReputationMgr ~ReputationMgr() {} void SaveToDB(); - void LoadFromDB(QueryResult *result); + void LoadFromDB(QueryResult_AutoPtr result); public: // statics static const int32 PointsInRank[MAX_REPUTATION_RANK]; static const int32 Reputation_Cap = 42999; diff --git a/src/game/ScriptSystem.cpp b/src/game/ScriptSystem.cpp index 8645d19bcff..261852b27de 100644 --- a/src/game/ScriptSystem.cpp +++ b/src/game/ScriptSystem.cpp @@ -39,15 +39,14 @@ SystemMgr& SystemMgr::Instance() void SystemMgr::LoadVersion() { //Get Version information - QueryResult* pResult = TScriptDB.PQuery("SELECT script_version FROM version LIMIT 1"); + QueryResult_AutoPtr Result = TScriptDB.PQuery("SELECT script_version FROM version LIMIT 1"); - if (pResult) + if (Result) { - Field* pFields = pResult->Fetch(); + Field* pFields = Result->Fetch(); outstring_log("TSCR: Database version is: %s", pFields[0].GetString()); outstring_log(""); - delete pResult; } else { @@ -61,19 +60,19 @@ void SystemMgr::LoadScriptTexts() outstring_log("TSCR: Loading Script Texts..."); LoadTrinityStrings(TScriptDB,"script_texts",TEXT_SOURCE_RANGE,1+(TEXT_SOURCE_RANGE*2)); - QueryResult* pResult = TScriptDB.PQuery("SELECT entry, sound, type, language, emote FROM script_texts"); + QueryResult_AutoPtr Result = TScriptDB.PQuery("SELECT entry, sound, type, language, emote FROM script_texts"); outstring_log("TSCR: Loading Script Texts additional data..."); - if (pResult) + if (Result) { - barGoLink bar(pResult->GetRowCount()); + barGoLink bar(Result->GetRowCount()); uint32 uiCount = 0; do { bar.step(); - Field* pFields = pResult->Fetch(); + Field* pFields = Result->Fetch(); StringTextData pTemp; int32 iId = pFields[0].GetInt32(); @@ -108,8 +107,7 @@ void SystemMgr::LoadScriptTexts() m_mTextDataMap[iId] = pTemp; ++uiCount; - } while (pResult->NextRow()); - delete pResult; + } while (Result->NextRow()); outstring_log(""); outstring_log(">> Loaded %u additional Script Texts data.", uiCount); @@ -128,19 +126,19 @@ void SystemMgr::LoadScriptTextsCustom() outstring_log("TSCR: Loading Custom Texts..."); LoadTrinityStrings(TScriptDB,"custom_texts",TEXT_SOURCE_RANGE*2,1+(TEXT_SOURCE_RANGE*3)); - QueryResult* pResult = TScriptDB.PQuery("SELECT entry, sound, type, language, emote FROM custom_texts"); + QueryResult_AutoPtr Result = TScriptDB.PQuery("SELECT entry, sound, type, language, emote FROM custom_texts"); outstring_log("TSCR: Loading Custom Texts additional data..."); - if (pResult) + if (Result) { - barGoLink bar(pResult->GetRowCount()); + barGoLink bar(Result->GetRowCount()); uint32 uiCount = 0; do { bar.step(); - Field* pFields = pResult->Fetch(); + Field* pFields = Result->Fetch(); StringTextData pTemp; int32 iId = pFields[0].GetInt32(); @@ -175,8 +173,7 @@ void SystemMgr::LoadScriptTextsCustom() m_mTextDataMap[iId] = pTemp; ++uiCount; - } while (pResult->NextRow()); - delete pResult; + } while (Result->NextRow()); outstring_log(""); outstring_log(">> Loaded %u additional Custom Texts data.", uiCount); @@ -198,26 +195,23 @@ void SystemMgr::LoadScriptWaypoints() uint64 uiCreatureCount = 0; // Load Waypoints - QueryResult* pResult = TScriptDB.PQuery("SELECT COUNT(entry) FROM script_waypoint GROUP BY entry"); - if (pResult) - { - uiCreatureCount = pResult->GetRowCount(); - delete pResult; - } + QueryResult_AutoPtr Result = TScriptDB.PQuery("SELECT COUNT(entry) FROM script_waypoint GROUP BY entry"); + if (Result) + uiCreatureCount = Result->GetRowCount(); outstring_log("TSCR: Loading Script Waypoints for %u creature(s)...", uiCreatureCount); - pResult = TScriptDB.PQuery("SELECT entry, pointid, location_x, location_y, location_z, waittime FROM script_waypoint ORDER BY pointid"); + Result = TScriptDB.PQuery("SELECT entry, pointid, location_x, location_y, location_z, waittime FROM script_waypoint ORDER BY pointid"); - if (pResult) + if (Result) { - barGoLink bar(pResult->GetRowCount()); + barGoLink bar(Result->GetRowCount()); uint32 uiNodeCount = 0; do { bar.step(); - Field* pFields = pResult->Fetch(); + Field* pFields = Result->Fetch(); ScriptPointMove pTemp; pTemp.uiCreatureEntry = pFields[0].GetUInt32(); @@ -241,9 +235,7 @@ void SystemMgr::LoadScriptWaypoints() m_mPointMoveMap[uiEntry].push_back(pTemp); ++uiNodeCount; - } while (pResult->NextRow()); - - delete pResult; + } while (Result->NextRow()); outstring_log(""); outstring_log(">> Loaded %u Script Waypoint nodes.", uiNodeCount); diff --git a/src/game/SkillDiscovery.cpp b/src/game/SkillDiscovery.cpp index 280a713afa5..610e925ae31 100644 --- a/src/game/SkillDiscovery.cpp +++ b/src/game/SkillDiscovery.cpp @@ -55,7 +55,7 @@ void LoadSkillDiscoveryTable() uint32 count = 0; // 0 1 2 3 - QueryResult *result = WorldDatabase.Query("SELECT spellId, reqSpell, reqSkillValue, chance FROM skill_discovery_template"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spellId, reqSpell, reqSkillValue, chance FROM skill_discovery_template"); if (!result) { @@ -138,8 +138,6 @@ void LoadSkillDiscoveryTable() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u skill discovery definitions", count ); if (!ssNonDiscoverableEntries.str().empty()) diff --git a/src/game/SkillExtraItems.cpp b/src/game/SkillExtraItems.cpp index b13db542c16..8c7dfffa871 100644 --- a/src/game/SkillExtraItems.cpp +++ b/src/game/SkillExtraItems.cpp @@ -59,7 +59,7 @@ void LoadSkillExtraItemTable() SkillExtraItemStore.clear(); // need for reload // 0 1 2 3 - QueryResult *result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template"); if (result) { @@ -108,8 +108,6 @@ void LoadSkillExtraItemTable() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u spell specialization definitions", count ); } diff --git a/src/game/SocialMgr.cpp b/src/game/SocialMgr.cpp index 830c3959071..c619da3178d 100644 --- a/src/game/SocialMgr.cpp +++ b/src/game/SocialMgr.cpp @@ -291,7 +291,7 @@ void SocialMgr::BroadcastToFriendListers(Player *player, WorldPacket *packet) } } -PlayerSocial *SocialMgr::LoadFromDB(QueryResult *result, uint32 guid) +PlayerSocial *SocialMgr::LoadFromDB(QueryResult_AutoPtr result, uint32 guid) { PlayerSocial *social = &m_socialMap[guid]; social->SetPlayerGUID(guid); @@ -318,7 +318,6 @@ PlayerSocial *SocialMgr::LoadFromDB(QueryResult *result, uint32 guid) break; } while (result->NextRow()); - delete result; return social; } diff --git a/src/game/SocialMgr.h b/src/game/SocialMgr.h index 4be1462c2f5..40f0066ec2e 100644 --- a/src/game/SocialMgr.h +++ b/src/game/SocialMgr.h @@ -151,7 +151,7 @@ class SocialMgr void SendFriendStatus(Player *player, FriendsResult result, uint32 friend_guid, bool broadcast); void BroadcastToFriendListers(Player *player, WorldPacket *packet); // Loading - PlayerSocial *LoadFromDB(QueryResult *result, uint32 guid); + PlayerSocial *LoadFromDB(QueryResult_AutoPtr result, uint32 guid); private: SocialMap m_socialMap; }; diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index a3128ba7567..95a70a545e7 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -332,7 +332,7 @@ Aura * Aura::Create(SpellEntry const* spellproto, uint8 effMask, WorldObject * o Aura::Aura(SpellEntry const* spellproto, uint8 effMask, WorldObject * owner, Unit * caster, int32 *baseAmount, Item * castItem, uint64 casterGUID) : m_spellProto(spellproto), m_owner(owner), m_casterGuid(casterGUID ? casterGUID : caster->GetGUID()), m_castItemGuid(castItem ? castItem->GetGUID() : 0), - m_applyTime(time(NULL)), m_timeCla(0), m_isSingleTarget(false), + m_applyTime(time(NULL)), m_timeCla(0), m_isSingleTarget(false), m_updateTargetMapInterval(0), m_procCharges(0), m_stackAmount(1), m_isRemoved(false), m_casterLevel(caster ? caster->getLevel() : m_spellProto->spellLevel) { if(m_spellProto->manaPerSecond || m_spellProto->manaPerSecondPerLevel) @@ -453,6 +453,7 @@ void Aura::_Remove(AuraRemoveMode removeMode) void Aura::UpdateTargetMap(Unit * caster) { + m_updateTargetMapInterval = UPDATE_TARGET_MAP_INTERVAL; for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) if(m_effects[i] && !IsRemoved()) UpdateTargetMapForEffect(caster, i); @@ -474,7 +475,10 @@ void Aura::UpdateOwner(uint32 diff, WorldObject * owner) Update(diff, caster); - UpdateTargetMap(caster); + if (m_updateTargetMapInterval <= diff) + UpdateTargetMap(caster); + else + m_updateTargetMapInterval -= diff; // update aura effects for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) @@ -1126,6 +1130,21 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, } break; case SPELLFAMILY_DEATHKNIGHT: + // Blood of the North + // Reaping + // Death Rune Mastery + if (GetSpellProto()->SpellIconID == 3041 || GetSpellProto()->SpellIconID == 22 || GetSpellProto()->SpellIconID == 2622) + { + if (!GetEffect(0) || GetEffect(0)->GetAuraType() != SPELL_AURA_PERIODIC_DUMMY) + break; + if (target->GetTypeId() != TYPEID_PLAYER) + break; + if(((Player*)target)->getClass() != CLASS_DEATH_KNIGHT) + break; + + // aura removed - remove death runes + ((Player*)target)->RemoveRunesByAuraEffect(GetEffect(0)); + } switch(GetId()) { case 50514: // Summon Gargoyle diff --git a/src/game/SpellAuras.h b/src/game/SpellAuras.h index 8d0a11c4877..dfa5fca6432 100644 --- a/src/game/SpellAuras.h +++ b/src/game/SpellAuras.h @@ -33,6 +33,9 @@ class AuraEffect; class Aura; class DynamicObject; +// update aura target map every 500 ms instead of every update - reduce amount of grid searcher calls +#define UPDATE_TARGET_MAP_INTERVAL 500 + class AuraApplication { friend AuraApplication * Unit::__ApplyAura(Aura * aura); @@ -172,6 +175,7 @@ class TRINITY_DLL_SPEC Aura int32 m_maxDuration; // Max aura duration int32 m_duration; // Current time int32 m_timeCla; // Timer for power per sec calcultion + int32 m_updateTargetMapInterval; // Timer for UpdateTargetMapOfEffect uint8 const m_casterLevel; // Aura level (store caster level for correct show level dep amount) uint8 m_procCharges; // Aura charges (0 for infinite) diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index efe742087c6..ca0e13d6277 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -2680,7 +2680,18 @@ void Spell::EffectSendEvent(uint32 EffectIndex) we do not handle a flag dropping or clicking on flag in battleground by sendevent system */ sLog.outDebug("Spell ScriptStart %u for spellid %u in EffectSendEvent ", m_spellInfo->EffectMiscValue[EffectIndex], m_spellInfo->Id); - m_caster->GetMap()->ScriptsStart(sEventScripts, m_spellInfo->EffectMiscValue[EffectIndex], m_caster, focusObject); + + Object *pTarget; + if (focusObject) + pTarget = focusObject; + else if (unitTarget) + pTarget = unitTarget; + else if (gameObjTarget) + pTarget = gameObjTarget; + else + pTarget = NULL; + + m_caster->GetMap()->ScriptsStart(sEventScripts, m_spellInfo->EffectMiscValue[EffectIndex], m_caster, pTarget); } void Spell::EffectPowerBurn(uint32 i) diff --git a/src/game/SpellHandler.cpp b/src/game/SpellHandler.cpp index ff9852fe7de..7abb9820d71 100644 --- a/src/game/SpellHandler.cpp +++ b/src/game/SpellHandler.cpp @@ -216,7 +216,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket) if(pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED))// wrapped? { - QueryResult *result = CharacterDatabase.PQuery("SELECT entry, flags FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT entry, flags FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); if (result) { Field *fields = result->Fetch(); @@ -227,7 +227,6 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket) pItem->SetEntry(entry); pItem->SetUInt32Value(ITEM_FIELD_FLAGS, flags); pItem->SetState(ITEM_CHANGED, pUser); - delete result; } else { diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index 1a17bc5a301..ea98dab2c99 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -1107,7 +1107,7 @@ void SpellMgr::LoadSpellTargetPositions() uint32 count = 0; // 0 1 2 3 4 5 - QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position"); if( !result ) { @@ -1212,8 +1212,6 @@ void SpellMgr::LoadSpellTargetPositions() } } - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u spell teleport coordinates", count ); } @@ -1243,7 +1241,7 @@ void SpellMgr::LoadSpellProcEvents() uint32 count = 0; // 0 1 2 3 4 5 6 7 8 9 10 - QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event"); if( !result ) { barGoLink bar( 1 ); @@ -1297,8 +1295,6 @@ void SpellMgr::LoadSpellProcEvents() ++count; } while( result->NextRow() ); - delete result; - sLog.outString(); if (customProc) sLog.outString( ">> Loaded %u extra spell proc event conditions + %u custom", count, customProc ); @@ -1311,7 +1307,7 @@ void SpellMgr::LoadSpellBonusess() mSpellBonusMap.clear(); // need for reload case uint32 count = 0; // 0 1 2 3 4 - QueryResult *result = WorldDatabase.Query("SELECT entry, direct_bonus, dot_bonus, ap_bonus, ap_dot_bonus FROM spell_bonus_data"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, direct_bonus, dot_bonus, ap_bonus, ap_dot_bonus FROM spell_bonus_data"); if( !result ) { barGoLink bar( 1 ); @@ -1346,8 +1342,6 @@ void SpellMgr::LoadSpellBonusess() ++count; } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u extra spell bonus data", count); } @@ -1488,7 +1482,7 @@ void SpellMgr::LoadSpellElixirs() uint32 count = 0; // 0 1 - QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir"); if( !result ) { @@ -1525,8 +1519,6 @@ void SpellMgr::LoadSpellElixirs() ++count; } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u spell elixir definitions", count ); } @@ -1538,7 +1530,7 @@ void SpellMgr::LoadSpellThreats() uint32 count = 0; // 0 1 - QueryResult *result = WorldDatabase.Query("SELECT entry, Threat FROM spell_threat"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, Threat FROM spell_threat"); if (!result) { @@ -1573,8 +1565,6 @@ void SpellMgr::LoadSpellThreats() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u aggro generating spells", count ); } @@ -1776,7 +1766,7 @@ void SpellMgr::LoadSpellLearnSpells() mSpellLearnSpells.clear(); // need for reload case // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell"); if (!result) { barGoLink bar(1); @@ -1826,8 +1816,6 @@ void SpellMgr::LoadSpellLearnSpells() ++count; } while (result->NextRow()); - delete result; - // search auto-learned spells and add its to map also for use in unlearn spells/talents uint32 dbc_count = 0; for (uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) @@ -1887,7 +1875,7 @@ void SpellMgr::LoadSpellScriptTarget() uint32 count = 0; - QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target"); if (!result) { @@ -1989,8 +1977,6 @@ void SpellMgr::LoadSpellScriptTarget() ++count; } while (result->NextRow()); - delete result; - // Check all spells for (uint32 i = 1; i < sSpellStore.GetNumRows(); ++i) { @@ -2047,7 +2033,7 @@ void SpellMgr::LoadSpellPetAuras() uint32 count = 0; // 0 1 2 3 - QueryResult *result = WorldDatabase.Query("SELECT spell, effectId, pet, aura FROM spell_pet_auras"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spell, effectId, pet, aura FROM spell_pet_auras"); if (!result) { barGoLink bar(1); @@ -2105,8 +2091,6 @@ void SpellMgr::LoadSpellPetAuras() ++count; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u spell pet auras", count ); } @@ -2387,7 +2371,7 @@ void SpellMgr::LoadSpellAreas() uint32 count = 0; // 0 1 2 3 4 5 6 7 8 - QueryResult *result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area"); if (!result) { @@ -2579,8 +2563,6 @@ void SpellMgr::LoadSpellAreas() ++count; } while(result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u spell area requirements", count ); } @@ -3124,7 +3106,7 @@ void SpellMgr::LoadSpellEnchantProcData() uint32 count = 0; // 0 1 2 3 - QueryResult *result = WorldDatabase.Query("SELECT entry, customChance, PPMChance, procEx FROM spell_enchant_proc_data"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, customChance, PPMChance, procEx FROM spell_enchant_proc_data"); if (!result) { barGoLink bar(1); @@ -3163,8 +3145,6 @@ void SpellMgr::LoadSpellEnchantProcData() ++count; } while(result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u enchant proc data definitions", count); } @@ -3174,7 +3154,7 @@ void SpellMgr::LoadSpellRequired() mSpellsReqSpell.clear(); // need for reload case mSpellReq.clear(); // need for reload case - QueryResult *result = WorldDatabase.Query("SELECT spell_id, req_spell from spell_required"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spell_id, req_spell from spell_required"); if (!result) { @@ -3202,8 +3182,6 @@ void SpellMgr::LoadSpellRequired() ++rows; } while (result->NextRow()); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u spell required records", rows ); } @@ -3927,7 +3905,7 @@ void SpellMgr::LoadSpellLinked() uint32 count = 0; // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT spell_trigger, spell_effect, type FROM spell_linked_spell"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT spell_trigger, spell_effect, type FROM spell_linked_spell"); if (!result) { barGoLink bar(1); @@ -3988,8 +3966,6 @@ void SpellMgr::LoadSpellLinked() ++count; } while( result->NextRow() ); - delete result; - sLog.outString(); sLog.outString( ">> Loaded %u linked spells", count ); } diff --git a/src/game/StatSystem.cpp b/src/game/StatSystem.cpp index b5895fbb2e6..7197779fdfd 100644 --- a/src/game/StatSystem.cpp +++ b/src/game/StatSystem.cpp @@ -25,7 +25,6 @@ #include "SharedDefines.h" #include "SpellAuras.h" #include "SpellAuraEffects.h" -#include "ObjectMgr.h" /*####################################### ######## ######## @@ -866,8 +865,7 @@ void Creature::UpdateDamagePhysical(WeaponAttackType attType) float weapon_maxdamage = GetWeaponDamageRange(attType, MAXDAMAGE); /* difference in AP between current attack power and base value from DB */ - CreatureBaseStats const* stats = objmgr.GetCreatureBaseStats(getLevel(), GetCreatureInfo()->unit_class); - float att_pwr_change = GetTotalAttackPowerValue(attType) - stats->GenerateAttackPower(GetCreatureInfo()); + float att_pwr_change = GetTotalAttackPowerValue(attType) - GetCreatureInfo()->attackpower; float base_value = GetModifierValue(unitMod, BASE_VALUE) + (att_pwr_change * GetAPMultiplier(attType, false) / 14.0f); float base_pct = GetModifierValue(unitMod, BASE_PCT); float total_value = GetModifierValue(unitMod, TOTAL_VALUE); diff --git a/src/game/Transports.cpp b/src/game/Transports.cpp index f0efef5ee20..8e7eb82597e 100644 --- a/src/game/Transports.cpp +++ b/src/game/Transports.cpp @@ -33,7 +33,7 @@ void MapManager::LoadTransports() { - QueryResult *result = WorldDatabase.Query("SELECT entry, name, period FROM transports"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, name, period FROM transports"); uint32 count = 0; @@ -111,7 +111,6 @@ void MapManager::LoadTransports() //t->GetMap()->Add<GameObject>((GameObject *)t); ++count; } while(result->NextRow()); - delete result; sLog.outString(); sLog.outString( ">> Loaded %u transports", count ); @@ -130,8 +129,6 @@ void MapManager::LoadTransports() sLog.outErrorDb("Transport %u '%s' have record (GUID: %u) in `gameobject`. Transports DON'T must have any records in `gameobject` or its behavior will be unpredictable/bugged.",entry,name.c_str(),guid); } while(result->NextRow()); - - delete result; } } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index fdf54cb018a..1204c508695 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -3885,6 +3885,7 @@ void Unit::RemoveOwnedAura(AuraMap::iterator &i, AuraRemoveMode removeMode) ++m_auraUpdateIterator; m_ownedAuras.erase(i); + m_removedAuras.push_back(aura); // Unregister single target aura if (aura->IsSingleTarget()) @@ -12960,7 +12961,7 @@ void Unit::RemoveFromWorld() } } -void Unit::CleanupsBeforeDelete() +void Unit::CleanupsBeforeDelete(bool finalCleanup) { if (IsInWorld()) RemoveFromWorld(); @@ -12970,7 +12971,10 @@ void Unit::CleanupsBeforeDelete() //A unit may be in removelist and not in world, but it is still in grid //and may have some references during delete RemoveAllAuras(); - m_cleanupDone = true; + + if (finalCleanup) + m_cleanupDone = true; + InterruptNonMeleeSpells(true); m_Events.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList CombatStop(); diff --git a/src/game/Unit.h b/src/game/Unit.h index a0614298484..5ff61195cc4 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1101,7 +1101,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject void AddToWorld(); void RemoveFromWorld(); - void CleanupsBeforeDelete(); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units) + void CleanupsBeforeDelete(bool finalCleanup = true); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units) DiminishingLevels GetDiminishing(DiminishingGroup group); void IncrDiminishing(DiminishingGroup group); diff --git a/src/game/WaypointManager.cpp b/src/game/WaypointManager.cpp index f4d14eb00d1..61d2b041092 100644 --- a/src/game/WaypointManager.cpp +++ b/src/game/WaypointManager.cpp @@ -34,7 +34,7 @@ void WaypointStore::Free() void WaypointStore::Load() { - QueryResult *result = WorldDatabase.PQuery("SELECT COUNT(id) FROM waypoint_data"); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT COUNT(id) FROM waypoint_data"); if (!result) { sLog.outError("an error occured while loading the table `waypoint_data` (maybe it doesn't exist ?)"); @@ -42,7 +42,6 @@ void WaypointStore::Load() } records = (*result)[0].GetUInt32(); - delete result; result = WorldDatabase.PQuery("SELECT id,point,position_x,position_y,position_z,move_flag,delay,action,action_chance FROM waypoint_data ORDER BY id, point"); if(!result) @@ -96,7 +95,6 @@ void WaypointStore::Load() } while(result->NextRow()) ; - delete result; sLog.outString(); sLog.outString(">> Loaded %u waypoints", count); } @@ -106,7 +104,7 @@ void WaypointStore::UpdatePath(uint32 id) if(waypoint_map.find(id)!= waypoint_map.end()) waypoint_map[id]->clear(); - QueryResult *result; + QueryResult_AutoPtr result; result = WorldDatabase.PQuery("SELECT id,point,position_x,position_y,position_z,move_flag,delay,action,action_chance FROM waypoint_data WHERE id = %u ORDER BY point", id); @@ -147,7 +145,5 @@ void WaypointStore::UpdatePath(uint32 id) while (result->NextRow()); waypoint_map[id] = path_data; - - delete result; } diff --git a/src/game/World.cpp b/src/game/World.cpp index 7779fbdee6c..9c68dca848f 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1748,7 +1748,7 @@ void World::LoadAutobroadcasts() { m_Autobroadcasts.clear(); - QueryResult *result = WorldDatabase.Query("SELECT text FROM autobroadcast"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT text FROM autobroadcast"); if (!result) { @@ -1777,8 +1777,6 @@ void World::LoadAutobroadcasts() count++; } while(result->NextRow()); - delete result; - sLog.outString(); sLog.outString(">> Loaded %u autobroadcasts definitions", count); } @@ -2154,7 +2152,7 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura loginDatabase.escape_string(safe_author); uint32 duration_secs = TimeStringToSecs(duration); - QueryResult *resultAccounts = NULL; //used for kicking + QueryResult_AutoPtr resultAccounts = QueryResult_AutoPtr(NULL); //used for kicking ///- Update the database with ban information switch(mode) @@ -2203,7 +2201,6 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura } while(resultAccounts->NextRow()); - delete resultAccounts; return BAN_SUCCESS; } @@ -2449,13 +2446,13 @@ void World::UpdateRealmCharCount(uint32 accountId) "SELECT COUNT(guid) FROM characters WHERE account = '%u'", accountId); } -void World::_UpdateRealmCharCount(QueryResult *resultCharCount, uint32 accountId) +void World::_UpdateRealmCharCount(QueryResult_AutoPtr resultCharCount, uint32 accountId) { if (resultCharCount) { Field *fields = resultCharCount->Fetch(); uint32 charCount = fields[0].GetUInt32(); - delete resultCharCount; + loginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", accountId, realmID); loginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charCount, accountId, realmID); } @@ -2465,13 +2462,12 @@ void World::InitDailyQuestResetTime() { time_t mostRecentQuestTime; - QueryResult* result = CharacterDatabase.Query("SELECT MAX(time) FROM character_queststatus_daily"); + QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(time) FROM character_queststatus_daily"); if (result) { Field *fields = result->Fetch(); mostRecentQuestTime = (time_t)fields[0].GetUInt64(); - delete result; } else mostRecentQuestTime = 0; @@ -2511,12 +2507,11 @@ void World::ResetDailyQuests() void World::UpdateAllowedSecurity() { - QueryResult *result = loginDatabase.PQuery("SELECT allowedSecurityLevel from realmlist WHERE id = '%d'", realmID); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT allowedSecurityLevel from realmlist WHERE id = '%d'", realmID); if (result) { m_allowedSecurityLevel = AccountTypes(result->Fetch()->GetUInt16()); sLog.outDebug("Allowed Level: %u Result %u", m_allowedSecurityLevel, result->Fetch()->GetUInt16()); - delete result; } } @@ -2533,7 +2528,7 @@ void World::UpdateMaxSessionCounters() void World::LoadDBVersion() { - QueryResult* result = WorldDatabase.Query("SELECT db_version, script_version, cache_id FROM version LIMIT 1"); + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT db_version, script_version, cache_id FROM version LIMIT 1"); //QueryResult* result = WorldDatabase.Query("SELECT version, creature_ai_version, cache_id FROM db_version LIMIT 1"); if (result) { @@ -2544,7 +2539,6 @@ void World::LoadDBVersion() // will be overwrite by config values if different and non-0 m_configs[CONFIG_CLIENTCACHE_VERSION] = fields[2].GetUInt32(); - delete result; } if (m_DBVersion.empty()) diff --git a/src/game/World.h b/src/game/World.h index 7fdd520a2dc..68684e1896b 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -30,6 +30,7 @@ #include "Policies/Singleton.h" #include "SharedDefines.h" #include "ace/Atomic_Op.h" +#include "QueryResult.h" #include <map> #include <set> @@ -645,7 +646,7 @@ class World protected: void _UpdateGameTime(); // callback for UpdateRealmCharacters - void _UpdateRealmCharCount(QueryResult *resultCharCount, uint32 accountId); + void _UpdateRealmCharCount(QueryResult_AutoPtr resultCharCount, uint32 accountId); void InitDailyQuestResetTime(); void ResetDailyQuests(); diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp index 7b7dac2c31b..c87421e4d59 100644 --- a/src/game/WorldSession.cpp +++ b/src/game/WorldSession.cpp @@ -566,7 +566,7 @@ void WorldSession::LoadGlobalAccountData() ); } -void WorldSession::LoadAccountData(QueryResult* result, uint32 mask) +void WorldSession::LoadAccountData(QueryResult_AutoPtr result, uint32 mask) { for (uint32 i = 0; i < NUM_ACCOUNT_DATA_TYPES; ++i) if (mask & (1 << i)) @@ -598,8 +598,6 @@ void WorldSession::LoadAccountData(QueryResult* result, uint32 mask) m_accountData[type].Data = fields[2].GetCppString(); } while (result->NextRow()); - - delete result; } void WorldSession::SetAccountData(AccountDataType type, time_t time_, std::string data) @@ -648,7 +646,7 @@ void WorldSession::LoadTutorialsData() for (int aX = 0 ; aX < 8 ; ++aX ) m_Tutorials[ aX ] = 0; - QueryResult *result = CharacterDatabase.PQuery("SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u'", GetAccountId()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u'", GetAccountId()); if(result) { @@ -660,10 +658,7 @@ void WorldSession::LoadTutorialsData() m_Tutorials[iI] = fields[iI].GetUInt32(); } while( result->NextRow() ); - - delete result; } - m_TutorialsChanged = false; } @@ -682,12 +677,9 @@ void WorldSession::SaveTutorialsData() uint32 Rows=0; // it's better than rebuilding indexes multiple times - QueryResult *result = CharacterDatabase.PQuery("SELECT count(*) AS r FROM character_tutorial WHERE account = '%u'", GetAccountId()); + QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT count(*) AS r FROM character_tutorial WHERE account = '%u'", GetAccountId()); if(result) - { Rows = result->Fetch()[0].GetUInt32(); - delete result; - } if (Rows) { diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h index 6a6121385b7..40021262fd1 100644 --- a/src/game/WorldSession.h +++ b/src/game/WorldSession.h @@ -28,6 +28,7 @@ #include "Common.h" #include "SharedDefines.h" #include "AddonMgr.h" +#include "QueryResult.h" struct ItemPrototype; struct AuctionEntry; @@ -162,7 +163,7 @@ class TRINITY_DLL_SPEC WorldSession //void SendTestCreatureQueryOpcode( uint32 entry, uint64 guid, uint32 testvalue ); void SendNameQueryOpcode(Player* p); void SendNameQueryOpcodeFromDB(uint64 guid); - static void SendNameQueryOpcodeFromDBCallBack(QueryResult *result, uint32 accountId); + static void SendNameQueryOpcodeFromDBCallBack(QueryResult_AutoPtr result, uint32 accountId); void SendTrainerList( uint64 guid ); void SendTrainerList( uint64 guid, const std::string& strTitle ); @@ -191,7 +192,7 @@ class TRINITY_DLL_SPEC WorldSession void SetAccountData(AccountDataType type, time_t time_, std::string data); void SendAccountDataTimes(uint32 mask); void LoadGlobalAccountData(); - void LoadAccountData(QueryResult* result, uint32 mask); + void LoadAccountData(QueryResult_AutoPtr result, uint32 mask); void LoadTutorialsData(); void SendTutorialsData(); void SaveTutorialsData(); @@ -269,7 +270,7 @@ class TRINITY_DLL_SPEC WorldSession void HandleCharDeleteOpcode(WorldPacket& recvPacket); void HandleCharCreateOpcode(WorldPacket& recvPacket); void HandlePlayerLoginOpcode(WorldPacket& recvPacket); - void HandleCharEnum(QueryResult * result); + void HandleCharEnum(QueryResult_AutoPtr result); void HandlePlayerLogin(LoginQueryHolder * holder); // played time @@ -338,10 +339,10 @@ class TRINITY_DLL_SPEC WorldSession void HandleEmoteOpcode(WorldPacket& recvPacket); void HandleContactListOpcode(WorldPacket& recvPacket); void HandleAddFriendOpcode(WorldPacket& recvPacket); - static void HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote); + static void HandleAddFriendOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId, std::string friendNote); void HandleDelFriendOpcode(WorldPacket& recvPacket); void HandleAddIgnoreOpcode(WorldPacket& recvPacket); - static void HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId); + static void HandleAddIgnoreOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId); void HandleDelIgnoreOpcode(WorldPacket& recvPacket); void HandleSetContactNotesOpcode(WorldPacket& recvPacket); void HandleBugOpcode(WorldPacket& recvPacket); @@ -610,7 +611,7 @@ class TRINITY_DLL_SPEC WorldSession void HandleSetActionBarToggles(WorldPacket& recv_data); void HandleCharRenameOpcode(WorldPacket& recv_data); - static void HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname); + static void HandleChangePlayerNameOpcodeCallBack(QueryResult_AutoPtr result, uint32 accountId, std::string newname); void HandleSetPlayerDeclinedNames(WorldPacket& recv_data); void HandleTotemDestroyed(WorldPacket& recv_data); diff --git a/src/game/WorldSocket.cpp b/src/game/WorldSocket.cpp index 3480fd57718..af6ddd4f0e5 100644 --- a/src/game/WorldSocket.cpp +++ b/src/game/WorldSocket.cpp @@ -738,7 +738,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) loginDatabase.escape_string (safe_account); // No SQL injection, username escaped. - QueryResult *result = + QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT " "id, " //0 "sessionkey, " //1 @@ -798,7 +798,6 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) packet << uint8 (AUTH_FAILED); SendPacket (packet); - delete result; sLog.outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs)."); return -1; } @@ -818,8 +817,6 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) if (locale >= MAX_LOCALE) locale = LOCALE_enUS; - delete result; - // Checks gmlevel per Realm result = loginDatabase.PQuery ("SELECT " @@ -836,11 +833,10 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) { fields = result->Fetch (); security = fields[1].GetInt32(); - delete result; } // Re-check account ban (same check as in realmd) - QueryResult *banresult = + QueryResult_AutoPtr banresult = loginDatabase.PQuery ("SELECT 1 FROM account_banned WHERE id = %u AND active = 1 " "UNION " "SELECT 1 FROM ip_banned WHERE ip = '%s'", @@ -852,8 +848,6 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) packet << uint8 (AUTH_BANNED); SendPacket (packet); - delete banresult; - sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (Account banned)."); return -1; } diff --git a/src/scripts/eastern_kingdoms/blackrock_depths/boss_ambassador_flamelash.cpp b/src/scripts/eastern_kingdoms/blackrock_depths/boss_ambassador_flamelash.cpp index a6146827240..82475e89fec 100644 --- a/src/scripts/eastern_kingdoms/blackrock_depths/boss_ambassador_flamelash.cpp +++ b/src/scripts/eastern_kingdoms/blackrock_depths/boss_ambassador_flamelash.cpp @@ -45,7 +45,7 @@ struct TRINITY_DLL_DECL boss_ambassador_flamelashAI : public ScriptedAI void SummonSpirits(Unit* victim) { - if (Creature *Spirit = DoSpawnCreature(9178, RAND(irand(0,-9),irand(0,9)), RAND(irand(0,-9),irand(0,9)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000)) + if (Creature *Spirit = DoSpawnCreature(9178, irand(-9,9), irand(-9,9), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000)) Spirit->AI()->AttackStart(victim); } diff --git a/src/scripts/eastern_kingdoms/blackrock_depths/boss_general_angerforge.cpp b/src/scripts/eastern_kingdoms/blackrock_depths/boss_general_angerforge.cpp index c0370e57e25..fe33defffd7 100644 --- a/src/scripts/eastern_kingdoms/blackrock_depths/boss_general_angerforge.cpp +++ b/src/scripts/eastern_kingdoms/blackrock_depths/boss_general_angerforge.cpp @@ -55,13 +55,13 @@ struct TRINITY_DLL_DECL boss_general_angerforgeAI : public ScriptedAI void SummonAdds(Unit* victim) { - if (Creature *SummonedAdd = DoSpawnCreature(8901, RAND(irand(0,-14),irand(0,14)), RAND(irand(0,-14),irand(0,14)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000)) + if (Creature *SummonedAdd = DoSpawnCreature(8901, irand(-14,14), irand(-14,14), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000)) SummonedAdd->AI()->AttackStart(victim); } void SummonMedics(Unit* victim) { - if (Creature *SummonedMedic = DoSpawnCreature(8894, RAND(irand(0,-9),irand(0,9)), RAND(irand(0,-9),irand(0,9)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000)) + if (Creature *SummonedMedic = DoSpawnCreature(8894, irand(-9,9), irand(-9,9), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000)) SummonedMedic->AI()->AttackStart(victim); } diff --git a/src/scripts/eastern_kingdoms/boss_kruul.cpp b/src/scripts/eastern_kingdoms/boss_kruul.cpp index 12c12cab3de..2e06e33b51b 100644 --- a/src/scripts/eastern_kingdoms/boss_kruul.cpp +++ b/src/scripts/eastern_kingdoms/boss_kruul.cpp @@ -66,7 +66,7 @@ struct TRINITY_DLL_DECL boss_kruulAI : public ScriptedAI void SummonHounds(Unit* pVictim) { - if (Creature *Hound = DoSpawnCreature(19207, RAND(irand(0,-9),irand(0,9)), RAND(irand(0,-9),irand(0,9)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 300000)) + if (Creature *Hound = DoSpawnCreature(19207, irand(-9,9), irand(-9,9), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 300000)) Hound->AI()->AttackStart(pVictim); } diff --git a/src/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp b/src/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp index 6a40cecacb6..dcba83ab249 100644 --- a/src/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp +++ b/src/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp @@ -270,11 +270,8 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI //damage const CreatureInfo *cinfo = m_creature->GetCreatureInfo(); - const CreatureBaseStats *stats = ((CreatureBaseStats*)m_creature)->GetBaseStats(m_creature->getLevel(), cinfo->unit_class); - float mindmg = stats->GenerateMinDmg(cinfo); - float maxdmg = stats->GenerateMaxDmg(cinfo); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, mindmg); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, maxdmg); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, cinfo->mindmg); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, cinfo->maxdmg); m_creature->UpdateDamagePhysical(BASE_ATTACK); } @@ -396,18 +393,15 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI //damage const CreatureInfo *cinfo = m_creature->GetCreatureInfo(); - const CreatureBaseStats *stats = ((CreatureBaseStats*)m_creature)->GetBaseStats(m_creature->getLevel(), cinfo->unit_class); - float mindmg = stats->GenerateMinDmg(cinfo); - float maxdmg = stats->GenerateMaxDmg(cinfo); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, 2 * mindmg); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, 2 * maxdmg); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, 2*cinfo->mindmg); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, 2*cinfo->maxdmg); m_creature->UpdateDamagePhysical(BASE_ATTACK); - m_creature->SetBaseWeaponDamage(OFF_ATTACK, MINDAMAGE, mindmg); - m_creature->SetBaseWeaponDamage(OFF_ATTACK, MAXDAMAGE, maxdmg); + m_creature->SetBaseWeaponDamage(OFF_ATTACK, MINDAMAGE, cinfo->mindmg); + m_creature->SetBaseWeaponDamage(OFF_ATTACK, MAXDAMAGE, cinfo->maxdmg); //Sigh, updating only works on main attack, do it manually .... - m_creature->SetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE, mindmg); - m_creature->SetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE, maxdmg); + m_creature->SetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE, cinfo->mindmg); + m_creature->SetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE, cinfo->maxdmg); m_creature->SetAttackTime(OFF_ATTACK, (m_creature->GetAttackTime(BASE_ATTACK)*150)/100); } diff --git a/src/scripts/eastern_kingdoms/scholomance/boss_jandice_barov.cpp b/src/scripts/eastern_kingdoms/scholomance/boss_jandice_barov.cpp index 7c120dbda0b..e836037ec0e 100644 --- a/src/scripts/eastern_kingdoms/scholomance/boss_jandice_barov.cpp +++ b/src/scripts/eastern_kingdoms/scholomance/boss_jandice_barov.cpp @@ -53,7 +53,7 @@ struct TRINITY_DLL_DECL boss_jandicebarovAI : public ScriptedAI void SummonIllusions(Unit* victim) { - if (Creature *Illusion = DoSpawnCreature(11439, RAND(irand(0,-9),irand(0,9)), RAND(irand(0,-9),irand(0,9)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000)) + if (Creature *Illusion = DoSpawnCreature(11439, irand(-9,9), irand(-9,9), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000)) Illusion->AI()->AttackStart(victim); } diff --git a/src/scripts/eastern_kingdoms/scholomance/boss_kormok.cpp b/src/scripts/eastern_kingdoms/scholomance/boss_kormok.cpp index 5ffea850954..15a7729bf36 100644 --- a/src/scripts/eastern_kingdoms/scholomance/boss_kormok.cpp +++ b/src/scripts/eastern_kingdoms/scholomance/boss_kormok.cpp @@ -51,13 +51,13 @@ struct TRINITY_DLL_DECL boss_kormokAI : public ScriptedAI void SummonMinions(Unit* victim) { - if (Creature *SummonedMinion = DoSpawnCreature(16119, RAND(irand(0,-7),irand(0,7)), RAND(irand(0,-7),irand(0,7)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000)) + if (Creature *SummonedMinion = DoSpawnCreature(16119, irand(-7,7), irand(-7,7), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000)) SummonedMinion->AI()->AttackStart(victim); } void SummonMages(Unit* victim) { - if (Creature *SummonedMage = DoSpawnCreature(16120, RAND(irand(0,-9),irand(0,9)), RAND(irand(0,-9),irand(0,9)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000)) + if (Creature *SummonedMage = DoSpawnCreature(16120, irand(-9,9), irand(-9,9), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000)) SummonedMage->AI()->AttackStart(victim); } diff --git a/src/scripts/eastern_kingdoms/stratholme/boss_nerubenkan.cpp b/src/scripts/eastern_kingdoms/stratholme/boss_nerubenkan.cpp index b5785be38a1..e3b965926ea 100644 --- a/src/scripts/eastern_kingdoms/stratholme/boss_nerubenkan.cpp +++ b/src/scripts/eastern_kingdoms/stratholme/boss_nerubenkan.cpp @@ -63,7 +63,7 @@ struct TRINITY_DLL_DECL boss_nerubenkanAI : public ScriptedAI void RaiseUndeadScarab(Unit* pVictim) { - if (Creature* pUndeadScarab = DoSpawnCreature(10876, RAND(irand(-9,0),irand(0,9)), RAND(irand(-9,0),irand(0,9)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 180000)) + if (Creature* pUndeadScarab = DoSpawnCreature(10876, irand(-9,9), irand(-9,9), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 180000)) if (pUndeadScarab->AI()) pUndeadScarab->AI()->AttackStart(pVictim); } diff --git a/src/scripts/eastern_kingdoms/zulaman/boss_janalai.cpp b/src/scripts/eastern_kingdoms/zulaman/boss_janalai.cpp index 8981645221c..aef4b337a97 100644 --- a/src/scripts/eastern_kingdoms/zulaman/boss_janalai.cpp +++ b/src/scripts/eastern_kingdoms/zulaman/boss_janalai.cpp @@ -213,8 +213,8 @@ struct TRINITY_DLL_DECL boss_janalaiAI : public ScriptedAI float dx, dy; for (int i(0); i < 40; ++i) { - dx =(rand()%(area_dx))-(area_dx/2); - dy =(rand()%(area_dy))-(area_dy/2); + dx = irand(-area_dx/2, area_dx/2); + dy = irand(-area_dy/2, area_dy/2); Creature* bomb = DoSpawnCreature(MOB_FIRE_BOMB, dx, dy, 0, 0, TEMPSUMMON_TIMED_DESPAWN, 15000); if (bomb) FireBombGUIDs[i] = bomb->GetGUID(); diff --git a/src/scripts/eastern_kingdoms/zulgurub/boss_arlokk.cpp b/src/scripts/eastern_kingdoms/zulgurub/boss_arlokk.cpp index 05ab5c81447..7cea97bb7c2 100644 --- a/src/scripts/eastern_kingdoms/zulgurub/boss_arlokk.cpp +++ b/src/scripts/eastern_kingdoms/zulgurub/boss_arlokk.cpp @@ -234,11 +234,8 @@ struct TRINITY_DLL_DECL boss_arlokkAI : public ScriptedAI m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); const CreatureInfo *cinfo = m_creature->GetCreatureInfo(); - const CreatureBaseStats *stats = ((CreatureBaseStats*)m_creature)->GetBaseStats(m_creature->getLevel(), cinfo->unit_class); - float mindmg = stats->GenerateMinDmg(cinfo); - float maxdmg = stats->GenerateMaxDmg(cinfo); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (mindmg +((mindmg/100) * 35))); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (maxdmg +((maxdmg/100) * 35))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 35))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 35))); m_creature->UpdateDamagePhysical(BASE_ATTACK); if (Unit* pTarget = SelectUnit(SELECT_TARGET_RANDOM,0)) diff --git a/src/scripts/eastern_kingdoms/zulgurub/boss_marli.cpp b/src/scripts/eastern_kingdoms/zulgurub/boss_marli.cpp index e240ae5db9a..e4b12ffb972 100644 --- a/src/scripts/eastern_kingdoms/zulgurub/boss_marli.cpp +++ b/src/scripts/eastern_kingdoms/zulgurub/boss_marli.cpp @@ -145,11 +145,8 @@ struct TRINITY_DLL_DECL boss_marliAI : public ScriptedAI DoScriptText(SAY_TRANSFORM, m_creature); DoCast(m_creature, SPELL_SPIDER_FORM); const CreatureInfo *cinfo = m_creature->GetCreatureInfo(); - const CreatureBaseStats *stats = ((CreatureBaseStats*)m_creature)->GetBaseStats(m_creature->getLevel(), cinfo->unit_class); - float mindmg = stats->GenerateMinDmg(cinfo); - float maxdmg = stats->GenerateMaxDmg(cinfo); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (mindmg +((mindmg/100) * 35))); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (maxdmg +((maxdmg/100) * 35))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 35))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 35))); m_creature->UpdateDamagePhysical(BASE_ATTACK); DoCast(m_creature->getVictim(), SPELL_ENVOLWINGWEB); @@ -188,11 +185,8 @@ struct TRINITY_DLL_DECL boss_marliAI : public ScriptedAI { m_creature->SetDisplayId(15220); const CreatureInfo *cinfo = m_creature->GetCreatureInfo(); - const CreatureBaseStats *stats = ((CreatureBaseStats*)m_creature)->GetBaseStats(m_creature->getLevel(), cinfo->unit_class); - float mindmg = stats->GenerateMinDmg(cinfo); - float maxdmg = stats->GenerateMaxDmg(cinfo); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (mindmg +((mindmg/100) * 1))); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (maxdmg +((maxdmg/100) * 1))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 1))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 1))); m_creature->UpdateDamagePhysical(BASE_ATTACK); PhaseTwo = false; diff --git a/src/scripts/eastern_kingdoms/zulgurub/boss_thekal.cpp b/src/scripts/eastern_kingdoms/zulgurub/boss_thekal.cpp index 3f8b49c8970..e7002673cd3 100644 --- a/src/scripts/eastern_kingdoms/zulgurub/boss_thekal.cpp +++ b/src/scripts/eastern_kingdoms/zulgurub/boss_thekal.cpp @@ -185,11 +185,8 @@ struct TRINITY_DLL_DECL boss_thekalAI : public ScriptedAI m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); m_creature->SetHealth(int(m_creature->GetMaxHealth()*1.0)); const CreatureInfo *cinfo = m_creature->GetCreatureInfo(); - const CreatureBaseStats *stats = ((CreatureBaseStats*)m_creature)->GetBaseStats(m_creature->getLevel(), cinfo->unit_class); - float mindmg = stats->GenerateMinDmg(cinfo); - float maxdmg = stats->GenerateMaxDmg(cinfo); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (mindmg +((mindmg/100) * 40))); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (maxdmg +((maxdmg/100) * 40))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 40))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 40))); m_creature->UpdateDamagePhysical(BASE_ATTACK); DoResetThreat(); PhaseTwo = true; diff --git a/src/scripts/eastern_kingdoms/zulgurub/boss_venoxis.cpp b/src/scripts/eastern_kingdoms/zulgurub/boss_venoxis.cpp index 5ea03ab4615..3b094b74b1e 100644 --- a/src/scripts/eastern_kingdoms/zulgurub/boss_venoxis.cpp +++ b/src/scripts/eastern_kingdoms/zulgurub/boss_venoxis.cpp @@ -148,11 +148,8 @@ struct TRINITY_DLL_DECL boss_venoxisAI : public ScriptedAI DoCast(m_creature, SPELL_SNAKE_FORM); m_creature->SetFloatValue(OBJECT_FIELD_SCALE_X, 2.00f); const CreatureInfo *cinfo = m_creature->GetCreatureInfo(); - const CreatureBaseStats *stats = ((CreatureBaseStats*)m_creature)->GetBaseStats(m_creature->getLevel(), cinfo->unit_class); - float mindmg = stats->GenerateMinDmg(cinfo); - float maxdmg = stats->GenerateMaxDmg(cinfo); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (mindmg +((mindmg/100) * 25))); - m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (maxdmg +((maxdmg/100) * 25))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 25))); + m_creature->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 25))); m_creature->UpdateDamagePhysical(BASE_ATTACK); DoResetThreat(); PhaseTwo = true; diff --git a/src/scripts/kalimdor/maraudon/boss_noxxion.cpp b/src/scripts/kalimdor/maraudon/boss_noxxion.cpp index 70bc4b67368..9fa9a9079cf 100644 --- a/src/scripts/kalimdor/maraudon/boss_noxxion.cpp +++ b/src/scripts/kalimdor/maraudon/boss_noxxion.cpp @@ -51,7 +51,7 @@ struct TRINITY_DLL_DECL boss_noxxionAI : public ScriptedAI void SummonAdds(Unit* pVictim) { - if (Creature *Add = DoSpawnCreature(13456, RAND(irand(0,-7),irand(0,7)), RAND(irand(0,-7),irand(0,7)), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 90000)) + if (Creature *Add = DoSpawnCreature(13456, irand(-7,7), irand(-7,7), 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 90000)) Add->AI()->AttackStart(pVictim); } diff --git a/src/scripts/northrend/naxxramas/boss_gluth.cpp b/src/scripts/northrend/naxxramas/boss_gluth.cpp index 51fe10ff001..525d9fd0f65 100644 --- a/src/scripts/northrend/naxxramas/boss_gluth.cpp +++ b/src/scripts/northrend/naxxramas/boss_gluth.cpp @@ -138,7 +138,7 @@ struct TRINITY_DLL_DECL boss_gluthAI : public BossAI } } - if (me->getVictim()->GetEntry() == MOB_ZOMBIE) + if (me->getVictim() && me->getVictim()->GetEntry() == MOB_ZOMBIE) { if (me->IsWithinMeleeRange(me->getVictim())) { diff --git a/src/scripts/northrend/naxxramas/boss_thaddius.cpp b/src/scripts/northrend/naxxramas/boss_thaddius.cpp index fa685759e83..b2a4b16b2a7 100644 --- a/src/scripts/northrend/naxxramas/boss_thaddius.cpp +++ b/src/scripts/northrend/naxxramas/boss_thaddius.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 - 2009 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008 - 2010 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,19 +18,22 @@ #include "ScriptedPch.h" #include "naxxramas.h" +#include "SpellId.h" //Stalagg enum StalaggYells { SAY_STAL_AGGRO = -1533023, //not used SAY_STAL_SLAY = -1533024, //not used - SAY_STAL_DEATH = -1533025 //not used + SAY_STAL_DEATH = -1533025 //not used }; enum StalagSpells { - SPELL_POWERSURGE = 54529, - H_SPELL_POWERSURGE = 28134 + SPELL_POWERSURGE = SPELL_POWER_SURGE_28134, + H_SPELL_POWERSURGE = SPELL_POWER_SURGE_54529, + SPELL_MAGNETIC_PULL = SPELL_MAGNETIC_PULL_28338, + SPELL_STALAGG_TESLA = SPELL_STALAGG_TESLA_PASSIVE_28097 }; //Feugen @@ -43,8 +46,18 @@ enum FeugenYells enum FeugenSpells { - SPELL_STATICFIELD = 28135, - H_SPELL_STATICFIELD = 54528 + SPELL_STATICFIELD = SPELL_STATIC_FIELD_28135, + H_SPELL_STATICFIELD = SPELL_STATIC_FIELD_54528, + SPELL_FEUGEN_TESLA = SPELL_FEUGEN_TESLA_PASSIVE_28109 +}; + +// Thaddius DoAction +enum ThaddiusActions +{ + ACTION_FEUGEN_RESET, + ACTION_FEUGEN_DIED, + ACTION_STALAGG_RESET, + ACTION_STALAGG_DIED }; //generic @@ -68,11 +81,11 @@ enum ThaddiusYells enum ThaddiusSpells { - SPELL_POLARITY_SHIFT = 28089, - SPELL_BALL_LIGHTNING = 28299, - SPELL_CHAIN_LIGHTNING = 28167, - H_SPELL_CHAIN_LIGHTNING = 54531, - SPELL_BERSERK = 27680 + SPELL_POLARITY_SHIFT = SPELL_POLARITY_SHIFT_28089, + SPELL_BALL_LIGHTNING = SPELL_BALL_LIGHTNING_28299, + SPELL_CHAIN_LIGHTNING = SPELL_CHAIN_LIGHTNING_28167, + H_SPELL_CHAIN_LIGHTNING = SPELL_CHAIN_LIGHTNING_54531, + SPELL_BERSERK = SPELL_BERSERK_27680 }; enum Events @@ -83,17 +96,39 @@ enum Events EVENT_BERSERK, }; -bool CheckStalaggAlive = true; -bool CheckFeugenAlive = true; - struct TRINITY_DLL_DECL boss_thaddiusAI : public BossAI { boss_thaddiusAI(Creature *c) : BossAI(c, BOSS_THADDIUS) { - me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_STUNNED); - me->SetReactState(REACT_PASSIVE); + // init is a bit tricky because thaddius shall track the life of both adds, but not if there was a wipe + // and, in particular, if there was a crash after both adds were killed (should not respawn) + + // Moreover, the adds may not yet be spawn. So just track down the status if mob is spawn + // and each mob will send its status at reset (meaning that it is alive) + checkFeugenAlive = false; + if (Creature *pFeugen = m_creature->GetCreature(*m_creature, instance->GetData64(DATA_FEUGEN))) + checkFeugenAlive = pFeugen->isAlive(); + + checkStalaggAlive = false; + if (Creature *pStalagg = m_creature->GetCreature(*m_creature, instance->GetData64(DATA_STALAGG))) + checkStalaggAlive = pStalagg->isAlive(); + + if (!checkFeugenAlive && !checkStalaggAlive) + { + me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_STUNNED); + me->SetReactState(REACT_AGGRESSIVE); + } + else + { + me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_STUNNED); + me->SetReactState(REACT_PASSIVE); + } } + bool checkStalaggAlive; + bool checkFeugenAlive; + uint32 uiAddsTimer; + void KilledUnit(Unit* victim) { if (!(rand()%5)) @@ -106,6 +141,37 @@ struct TRINITY_DLL_DECL boss_thaddiusAI : public BossAI DoScriptText(SAY_DEATH, me); } + void DoAction(const int32 action) + { + switch(action) + { + case ACTION_FEUGEN_RESET: + checkFeugenAlive = true; + break; + case ACTION_FEUGEN_DIED: + checkFeugenAlive = false; + break; + case ACTION_STALAGG_RESET: + checkStalaggAlive = true; + break; + case ACTION_STALAGG_DIED: + checkStalaggAlive = false; + break; + } + + if (!checkFeugenAlive && !checkStalaggAlive) + { + me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_STUNNED); + // REACT_AGGRESSIVE only reset when he takes damage. + DoZoneInCombat(); + } + else + { + me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_STUNNED); + me->SetReactState(REACT_PASSIVE); + } + } + void EnterCombat(Unit *who) { _EnterCombat(); @@ -115,17 +181,40 @@ struct TRINITY_DLL_DECL boss_thaddiusAI : public BossAI events.ScheduleEvent(EVENT_BERSERK, 360000); } + void DamageTaken(Unit *pDoneBy, uint32 &uiDamage) + { + me->SetReactState(REACT_AGGRESSIVE); + } + void UpdateAI(const uint32 diff) { - if (CheckStalaggAlive == false && CheckFeugenAlive == false) { - me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_STUNNED); - me->SetReactState(REACT_AGGRESSIVE); - } + if (checkFeugenAlive && checkStalaggAlive) + uiAddsTimer = 0; - if (!UpdateVictim()) - return; + if (checkStalaggAlive != checkFeugenAlive) + { + uiAddsTimer += diff; + if (uiAddsTimer > 5000) + { + if (!checkStalaggAlive) + { + if (instance) + if (Creature *pStalagg = m_creature->GetCreature(*m_creature, instance->GetData64(DATA_STALAGG))) + pStalagg->Respawn(); + } + else + { + if (instance) + if (Creature *pFeugen = m_creature->GetCreature(*m_creature, instance->GetData64(DATA_FEUGEN))) + pFeugen->Respawn(); + } + } + } + + if (!UpdateVictim()) + return; - events.Update(diff); + events.Update(diff); if (me->hasUnitState(UNIT_STAT_CASTING)) return; @@ -162,29 +251,76 @@ CreatureAI* GetAI_boss_thaddius(Creature* pCreature) struct TRINITY_DLL_DECL mob_stalaggAI : public ScriptedAI { - mob_stalaggAI(Creature *c) : ScriptedAI(c) {} - - uint32 PowerSurgeTimer; - - void reset() - { - PowerSurgeTimer = urand(20000,25000); - } - - void JustDied(Unit *killer) - { - CheckStalaggAlive = false; - } - - void UpdateAI(const uint32 uiDiff) - { - if (PowerSurgeTimer <= uiDiff) - { - DoCast(m_creature, RAID_MODE(SPELL_POWERSURGE, H_SPELL_POWERSURGE)); - PowerSurgeTimer = urand(15000,20000); - } else PowerSurgeTimer -= uiDiff; - DoMeleeAttackIfReady(); - } + mob_stalaggAI(Creature *c) : ScriptedAI(c) + { + pInstance = c->GetInstanceData(); + } + + ScriptedInstance* pInstance; + + uint32 powerSurgeTimer; + uint32 magneticPullTimer; + + void Reset() + { + if (pInstance) + if (Creature *pThaddius = m_creature->GetCreature(*m_creature, pInstance->GetData64(DATA_THADDIUS))) + if (pThaddius->AI()) + pThaddius->AI()->DoAction(ACTION_STALAGG_RESET); + powerSurgeTimer = urand(20000,25000); + magneticPullTimer = 20000; + } + + void EnterCombat(Unit *pWho) + { + DoCast(SPELL_STALAGG_TESLA); + } + + void JustDied(Unit *killer) + { + if (pInstance) + if (Creature *pThaddius = m_creature->GetCreature(*m_creature, pInstance->GetData64(DATA_THADDIUS))) + if (pThaddius->AI()) + pThaddius->AI()->DoAction(ACTION_STALAGG_DIED); + } + + void UpdateAI(const uint32 uiDiff) + { + if (!UpdateVictim()) + return; + + if (magneticPullTimer <= uiDiff) + { + if (Creature *pFeugen = m_creature->GetCreature(*m_creature, pInstance->GetData64(DATA_FEUGEN))) + { + Unit* pStalaggVictim = m_creature->getVictim(); + Unit* pFeugenVictim = pFeugen->getVictim(); + + if (pFeugenVictim && pStalaggVictim) + { + // magnetic pull is not working. So just jump. + + // reset aggro to be sure that feugen will not follow the jump + pFeugen->getThreatManager().modifyThreatPercent(pFeugenVictim, -100); + pFeugenVictim->JumpTo(m_creature, 0.3f); + + m_creature->getThreatManager().modifyThreatPercent(pStalaggVictim, -100); + pStalaggVictim->JumpTo(pFeugen, 0.3f); + } + } + + magneticPullTimer = 20000; + } + else magneticPullTimer -= uiDiff; + + if (powerSurgeTimer <= uiDiff) + { + DoCast(m_creature, RAID_MODE(SPELL_POWERSURGE, H_SPELL_POWERSURGE)); + powerSurgeTimer = urand(15000,20000); + } else powerSurgeTimer -= uiDiff; + + DoMeleeAttackIfReady(); + } }; CreatureAI* GetAI_mob_stalagg(Creature* pCreature) @@ -194,35 +330,55 @@ CreatureAI* GetAI_mob_stalagg(Creature* pCreature) struct TRINITY_DLL_DECL mob_feugenAI : public ScriptedAI { - mob_feugenAI(Creature *c) : ScriptedAI(c) {} - - uint32 StaticFieldTimer; - uint32 Checktimer; - - void reset() - { - StaticFieldTimer = 5000; - } - - void JustDied(Unit *killer) - { - CheckFeugenAlive = false; - } - - void UpdateAI(const uint32 uiDiff) - { - if (StaticFieldTimer <= uiDiff) - { - DoCast(m_creature, RAID_MODE(SPELL_STATICFIELD, H_SPELL_STATICFIELD)); - StaticFieldTimer = 5000; - } else StaticFieldTimer -= uiDiff; - DoMeleeAttackIfReady(); - } + mob_feugenAI(Creature *c) : ScriptedAI(c) + { + pInstance = c->GetInstanceData(); + } + + ScriptedInstance* pInstance; + + uint32 staticFieldTimer; + + void Reset() + { + if (pInstance) + if (Creature *pThaddius = m_creature->GetCreature(*m_creature, pInstance->GetData64(DATA_THADDIUS))) + if (pThaddius->AI()) + pThaddius->AI()->DoAction(ACTION_FEUGEN_RESET); + staticFieldTimer = 5000; + } + + void EnterCombat(Unit *pWho) + { + DoCast(SPELL_FEUGEN_TESLA); + } + + void JustDied(Unit *killer) + { + if (pInstance) + if (Creature *pThaddius = m_creature->GetCreature(*m_creature, pInstance->GetData64(DATA_THADDIUS))) + if (pThaddius->AI()) + pThaddius->AI()->DoAction(ACTION_FEUGEN_DIED); + } + + void UpdateAI(const uint32 uiDiff) + { + if (!UpdateVictim()) + return; + + if (staticFieldTimer <= uiDiff) + { + DoCast(m_creature, RAID_MODE(SPELL_STATICFIELD, H_SPELL_STATICFIELD)); + staticFieldTimer = 5000; + } else staticFieldTimer -= uiDiff; + + DoMeleeAttackIfReady(); + } }; CreatureAI* GetAI_mob_feugen(Creature* pCreature) { - return new mob_feugenAI(pCreature); + return new mob_feugenAI(pCreature); } void AddSC_boss_thaddius() @@ -233,13 +389,13 @@ void AddSC_boss_thaddius() newscript->GetAI = &GetAI_boss_thaddius; newscript->RegisterSelf(); - newscript = new Script; - newscript->Name = "mob_stalagg"; - newscript->GetAI = &GetAI_mob_stalagg; - newscript->RegisterSelf(); + newscript = new Script; + newscript->Name = "mob_stalagg"; + newscript->GetAI = &GetAI_mob_stalagg; + newscript->RegisterSelf(); - newscript = new Script; - newscript->Name = "mob_feugen"; - newscript->GetAI = &GetAI_mob_feugen; - newscript->RegisterSelf(); + newscript = new Script; + newscript->Name = "mob_feugen"; + newscript->GetAI = &GetAI_mob_feugen; + newscript->RegisterSelf(); } diff --git a/src/scripts/northrend/naxxramas/instance_naxxramas.cpp b/src/scripts/northrend/naxxramas/instance_naxxramas.cpp index 103dba7e4b8..19a330b58d6 100644 --- a/src/scripts/northrend/naxxramas/instance_naxxramas.cpp +++ b/src/scripts/northrend/naxxramas/instance_naxxramas.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2008 - 2009 Trinity <http://www.trinitycore.org/> +/* Copyright (C) 2008 - 2010 Trinity <http://www.trinitycore.org/> * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -115,6 +115,9 @@ struct TRINITY_DLL_DECL instance_naxxramas : public InstanceData uint64 uiBaron; uint64 uiSir; + uint64 uiThaddius; + uint64 uiFeugen; + uint64 uiStalagg; void OnCreatureCreate(Creature* pCreature, bool add) { @@ -126,6 +129,9 @@ struct TRINITY_DLL_DECL instance_naxxramas : public InstanceData case 16065: uiLady = pCreature->GetGUID(); return; case 30549: uiBaron = pCreature->GetGUID(); return; case 16063: uiSir = pCreature->GetGUID(); return; + case 15928: uiThaddius = pCreature->GetGUID(); return; + case 15930: uiFeugen = pCreature->GetGUID(); return; + case 15929: uiStalagg = pCreature->GetGUID(); return; } AddMinion(pCreature, add); @@ -180,6 +186,12 @@ struct TRINITY_DLL_DECL instance_naxxramas : public InstanceData return uiBaron; if (id == DATA_SIR) return uiSir; + if (id == DATA_THADDIUS) + return uiThaddius; + if (id == DATA_FEUGEN) + return uiFeugen; + if (id == DATA_STALAGG) + return uiStalagg; return 0; } diff --git a/src/scripts/northrend/naxxramas/naxxramas.h b/src/scripts/northrend/naxxramas/naxxramas.h index 6f4dcae41a7..48121ff1309 100644 --- a/src/scripts/northrend/naxxramas/naxxramas.h +++ b/src/scripts/northrend/naxxramas/naxxramas.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 - 2009 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008 - 2010 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,11 +44,18 @@ enum Data DATA_HEIGAN_ERUPT, DATA_GOTHIK_GATE, DATA_SAPPHIRON_BIRTH, +}; + +enum Data64 +{ DATA_FAERLINA, DATA_THANE, DATA_LADY, DATA_BARON, - DATA_SIR + DATA_SIR, + DATA_THADDIUS, + DATA_FEUGEN, + DATA_STALAGG }; #define GO_BIRTH 181356 diff --git a/src/scripts/world/npcs_special.cpp b/src/scripts/world/npcs_special.cpp index 93e68d074e1..a57507f9c6a 100644 --- a/src/scripts/world/npcs_special.cpp +++ b/src/scripts/world/npcs_special.cpp @@ -1580,7 +1580,6 @@ struct TRINITY_DLL_DECL npc_snake_trap_serpentsAI : public ScriptedAI SpellTimer = 0; CreatureInfo const *Info = m_creature->GetCreatureInfo(); - CreatureBaseStats const *stats = ((CreatureBaseStats*)m_creature)->GetBaseStats(m_creature->getLevel(), Info->unit_class); if (Info->Entry == C_VIPER) IsViper = true; @@ -1589,9 +1588,8 @@ struct TRINITY_DLL_DECL npc_snake_trap_serpentsAI : public ScriptedAI //Add delta to make them not all hit the same time uint32 delta = (rand() % 7) * 100; - float attackpower = stats->GenerateAttackPower(Info); m_creature->SetStatFloatValue(UNIT_FIELD_BASEATTACKTIME, Info->baseattacktime + delta); - m_creature->SetStatFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER , attackpower); + m_creature->SetStatFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER , Info->attackpower); } //Redefined for random target selection: diff --git a/src/shared/Database/DBCStore.h b/src/shared/Database/DBCStore.h index ea4ce109e27..4344b6e6450 100644 --- a/src/shared/Database/DBCStore.h +++ b/src/shared/Database/DBCStore.h @@ -83,7 +83,7 @@ class DBCStorage uint32 sqlRecordCount = 0; uint32 sqlHighestIndex = 0; Field *fields = NULL; - QueryResult *result = NULL; + QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL); // Load data from sql if (sql) { @@ -188,7 +188,6 @@ class DBCStorage break; case FT_STRING: sLog.outError("Unsupported data type in table '%s' at char %d", sql->sqlTableName.c_str(), columnNumber); - delete result; return false; case FT_SORT: break; @@ -201,14 +200,12 @@ class DBCStorage else { sLog.outError("Incorrect sql format string '%s' at char %d", sql->sqlTableName.c_str(), columnNumber); - delete result; return false; } } if (sqlColumnNumber != (result->GetFieldCount()-1)) { sLog.outError("SQL and DBC format strings are not matching for table: '%s'", sql->sqlTableName.c_str()); - delete result; return false; } @@ -216,7 +213,6 @@ class DBCStorage ++rowIndex; }while (result->NextRow()); } - delete result; } // error in dbc file at loading if NULL diff --git a/src/shared/Database/Database.cpp b/src/shared/Database/Database.cpp index ac2cdfa4163..da214e71650 100644 --- a/src/shared/Database/Database.cpp +++ b/src/shared/Database/Database.cpp @@ -117,9 +117,9 @@ void Database::SetResultQueue(SqlResultQueue * queue) } -QueryResult* Database::PQuery(const char *format,...) +QueryResult_AutoPtr Database::PQuery(const char *format,...) { - if(!format) return NULL; + if(!format) return QueryResult_AutoPtr(NULL); va_list ap; char szQuery [MAX_QUERY_LEN]; @@ -130,7 +130,7 @@ QueryResult* Database::PQuery(const char *format,...) if(res==-1) { sLog.outError("SQL Query truncated (and not execute) for format: %s",format); - return false; + return QueryResult_AutoPtr(NULL); } return Query(szQuery); @@ -217,12 +217,9 @@ bool Database::DirectPExecute(const char * format,...) bool Database::CheckRequiredField( char const* table_name, char const* required_name ) { // check required field - QueryResult* result = PQuery("SELECT %s FROM %s LIMIT 1",required_name,table_name); + QueryResult_AutoPtr result = PQuery("SELECT %s FROM %s LIMIT 1",required_name,table_name); if(result) - { - delete result; return true; - } // check fail, prepare readabale error message diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h index 804501cd7f9..e1b44c99057 100644 --- a/src/shared/Database/Database.h +++ b/src/shared/Database/Database.h @@ -52,8 +52,8 @@ class TRINITY_DLL_SPEC Database virtual void InitDelayThread() = 0; virtual void HaltDelayThread() = 0; - virtual QueryResult* Query(const char *sql) = 0; - QueryResult* PQuery(const char *format,...) ATTR_PRINTF(2,3); + virtual QueryResult_AutoPtr Query(const char *sql) = 0; + QueryResult_AutoPtr PQuery(const char *format,...) ATTR_PRINTF(2,3); virtual QueryNamedResult* QueryNamed(const char *sql) = 0; QueryNamedResult* PQueryNamed(const char *format,...) ATTR_PRINTF(2,3); @@ -61,41 +61,41 @@ class TRINITY_DLL_SPEC Database // Query / member template<class Class> - bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql); + bool AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *sql); template<class Class, typename ParamType1> - bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql); + bool AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql); template<class Class, typename ParamType1, typename ParamType2> - bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql); + bool AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql); template<class Class, typename ParamType1, typename ParamType2, typename ParamType3> - bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql); + bool AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql); // Query / static template<typename ParamType1> - bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql); + bool AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql); template<typename ParamType1, typename ParamType2> - bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql); + bool AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql); template<typename ParamType1, typename ParamType2, typename ParamType3> - bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql); + bool AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql); // PQuery / member template<class Class> - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5); + bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *format,...) ATTR_PRINTF(4,5); template<class Class, typename ParamType1> - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6); + bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6); template<class Class, typename ParamType1, typename ParamType2> - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6,7); + bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6,7); template<class Class, typename ParamType1, typename ParamType2, typename ParamType3> - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7,8); + bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7,8); // PQuery / static template<typename ParamType1> - bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4,5); + bool AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4,5); template<typename ParamType1, typename ParamType2> - bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6); + bool AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6); template<typename ParamType1, typename ParamType2, typename ParamType3> - bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6,7); + bool AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6,7); template<class Class> // QueryHolder - bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder); + bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*), SqlQueryHolder *holder); template<class Class, typename ParamType1> - bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1); + bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1); virtual bool Execute(const char *sql) = 0; bool PExecute(const char *format,...) ATTR_PRINTF(2,3); diff --git a/src/shared/Database/DatabaseImpl.h b/src/shared/Database/DatabaseImpl.h index 01ee52065fa..d77b16c8ea6 100644 --- a/src/shared/Database/DatabaseImpl.h +++ b/src/shared/Database/DatabaseImpl.h @@ -68,7 +68,7 @@ template<class Class> bool -Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql) +Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *sql) { ASYNC_QUERY_BODY(sql, itr) return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class>(object, method), itr->second)); @@ -76,59 +76,59 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const c template<class Class, typename ParamType1> bool -Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql) +Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql) { ASYNC_QUERY_BODY(sql, itr) - return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second)); + return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1>(object, method, (QueryResult_AutoPtr)NULL, param1), itr->second)); } template<class Class, typename ParamType1, typename ParamType2> bool -Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) +Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) { ASYNC_QUERY_BODY(sql, itr) - return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second)); + return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult_AutoPtr)NULL, param1, param2), itr->second)); } template<class Class, typename ParamType1, typename ParamType2, typename ParamType3> bool -Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql) +Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql) { ASYNC_QUERY_BODY(sql, itr) - return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult*)NULL, param1, param2, param3), itr->second)); + return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult_AutoPtr)NULL, param1, param2, param3), itr->second)); } // -- Query / static -- template<typename ParamType1> bool -Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql) +Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql) { ASYNC_QUERY_BODY(sql, itr) - return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second)); + return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1>(method, (QueryResult_AutoPtr)NULL, param1), itr->second)); } template<typename ParamType1, typename ParamType2> bool -Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) +Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) { ASYNC_QUERY_BODY(sql, itr) - return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second)); + return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult_AutoPtr)NULL, param1, param2), itr->second)); } template<typename ParamType1, typename ParamType2, typename ParamType3> bool -Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql) +Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql) { ASYNC_QUERY_BODY(sql, itr) - return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult*)NULL, param1, param2, param3), itr->second)); + return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult_AutoPtr)NULL, param1, param2, param3), itr->second)); } // -- PQuery / member -- template<class Class> bool -Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) +Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *format,...) { ASYNC_PQUERY_BODY(format, szQuery) return AsyncQuery(object, method, szQuery); @@ -136,7 +136,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const template<class Class, typename ParamType1> bool -Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) +Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...) { ASYNC_PQUERY_BODY(format, szQuery) return AsyncQuery(object, method, param1, szQuery); @@ -144,7 +144,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy template<class Class, typename ParamType1, typename ParamType2> bool -Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) +Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) { ASYNC_PQUERY_BODY(format, szQuery) return AsyncQuery(object, method, param1, param2, szQuery); @@ -152,7 +152,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy template<class Class, typename ParamType1, typename ParamType2, typename ParamType3> bool -Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) +Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) { ASYNC_PQUERY_BODY(format, szQuery) return AsyncQuery(object, method, param1, param2, param3, szQuery); @@ -162,7 +162,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy template<typename ParamType1> bool -Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) +Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...) { ASYNC_PQUERY_BODY(format, szQuery) return AsyncQuery(method, param1, szQuery); @@ -170,7 +170,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param template<typename ParamType1, typename ParamType2> bool -Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) +Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) { ASYNC_PQUERY_BODY(format, szQuery) return AsyncQuery(method, param1, param2, szQuery); @@ -178,7 +178,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), Para template<typename ParamType1, typename ParamType2, typename ParamType3> bool -Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) +Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) { ASYNC_PQUERY_BODY(format, szQuery) return AsyncQuery(method, param1, param2, param3, szQuery); @@ -188,18 +188,18 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, Param template<class Class> bool -Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder) +Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*), SqlQueryHolder *holder) { ASYNC_DELAYHOLDER_BODY(holder, itr) - return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second); + return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult_AutoPtr)NULL, holder), m_threadBody, itr->second); } template<class Class, typename ParamType1> bool -Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1) +Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1) { ASYNC_DELAYHOLDER_BODY(holder, itr) - return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second); + return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult_AutoPtr)NULL, holder, param1), m_threadBody, itr->second); } #undef ASYNC_QUERY_BODY diff --git a/src/shared/Database/DatabaseMysql.cpp b/src/shared/Database/DatabaseMysql.cpp index 6412ed9312f..cc94ca3540d 100644 --- a/src/shared/Database/DatabaseMysql.cpp +++ b/src/shared/Database/DatabaseMysql.cpp @@ -235,7 +235,7 @@ bool DatabaseMysql::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **p return true; } -QueryResult* DatabaseMysql::Query(const char *sql) +QueryResult_AutoPtr DatabaseMysql::Query(const char *sql) { MYSQL_RES *result = NULL; MYSQL_FIELD *fields = NULL; @@ -243,13 +243,13 @@ QueryResult* DatabaseMysql::Query(const char *sql) uint32 fieldCount = 0; if(!_Query(sql,&result,&fields,&rowCount,&fieldCount)) - return NULL; + return QueryResult_AutoPtr(NULL); QueryResultMysql *queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount); queryResult->NextRow(); - return queryResult; + return QueryResult_AutoPtr(queryResult); } QueryNamedResult* DatabaseMysql::QueryNamed(const char *sql) diff --git a/src/shared/Database/DatabaseMysql.h b/src/shared/Database/DatabaseMysql.h index d4e440f96f6..4f7ab2b88b7 100644 --- a/src/shared/Database/DatabaseMysql.h +++ b/src/shared/Database/DatabaseMysql.h @@ -49,7 +49,7 @@ class TRINITY_DLL_SPEC DatabaseMysql : public Database bool Initialize(const char *infoString); void InitDelayThread(); void HaltDelayThread(); - QueryResult* Query(const char *sql); + QueryResult_AutoPtr Query(const char *sql); QueryNamedResult* QueryNamed(const char *sql); bool Execute(const char *sql); bool DirectExecute(const char* sql); diff --git a/src/shared/Database/DatabasePostgre.cpp b/src/shared/Database/DatabasePostgre.cpp index 983932dc03d..a1283538b20 100644 --- a/src/shared/Database/DatabasePostgre.cpp +++ b/src/shared/Database/DatabasePostgre.cpp @@ -158,22 +158,22 @@ bool DatabasePostgre::_Query(const char *sql, PGresult** pResult, uint64* pRowCo return true; } -QueryResult* DatabasePostgre::Query(const char *sql) +QueryResult_AutoPtr DatabasePostgre::Query(const char *sql) { if (!mPGconn) - return 0; + return QueryResult_AutoPtr(NULL); PGresult* result = NULL; uint64 rowCount = 0; uint32 fieldCount = 0; if(!_Query(sql,&result,&rowCount,&fieldCount)) - return NULL; + return QueryResult_AutoPtr(NULL); QueryResultPostgre * queryResult = new QueryResultPostgre(result, rowCount, fieldCount); queryResult->NextRow(); - return queryResult; + return QueryResult_AutoPtr(queryResult); } QueryNamedResult* DatabasePostgre::QueryNamed(const char *sql) diff --git a/src/shared/Database/DatabasePostgre.h b/src/shared/Database/DatabasePostgre.h index fcd420ef8e4..cd93f416bfe 100644 --- a/src/shared/Database/DatabasePostgre.h +++ b/src/shared/Database/DatabasePostgre.h @@ -45,7 +45,7 @@ class DatabasePostgre : public Database bool Initialize(const char *infoString); void InitDelayThread(); void HaltDelayThread(); - QueryResult* Query(const char *sql); + QueryResult_AutoPtr Query(const char *sql); QueryNamedResult* QueryNamed(const char *sql); bool Execute(const char *sql); bool DirectExecute(const char* sql); diff --git a/src/shared/Database/QueryResult.h b/src/shared/Database/QueryResult.h index a0c77752300..f9488f5a030 100644 --- a/src/shared/Database/QueryResult.h +++ b/src/shared/Database/QueryResult.h @@ -21,6 +21,11 @@ #if !defined(QUERYRESULT_H) #define QUERYRESULT_H +#include <ace/Refcounted_Auto_Ptr.h> +#include <ace/Null_Mutex.h> + +#include "Field.h" + class TRINITY_DLL_SPEC QueryResult { public: @@ -44,6 +49,8 @@ class TRINITY_DLL_SPEC QueryResult uint64 mRowCount; }; +typedef ACE_Refcounted_Auto_Ptr<QueryResult, ACE_Null_Mutex> QueryResult_AutoPtr; + typedef std::vector<std::string> QueryFieldNames; class TRINITY_DLL_SPEC QueryNamedResult diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp index efe00b9c0f6..e36297ed35b 100644 --- a/src/shared/Database/SQLStorage.cpp +++ b/src/shared/Database/SQLStorage.cpp @@ -27,8 +27,8 @@ extern DatabasePostgre WorldDatabase; extern DatabaseMysql WorldDatabase; #endif -const char CreatureInfosrcfmt[]="iiiiiiiiiisssiiiiiiiffiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisiifffffliiiiiiiliiis"; -const char CreatureInfodstfmt[]="iiiiiiiiiisssiiiiiiiffiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisiifffffliiiiiiiliiii"; +const char CreatureInfosrcfmt[]="iiiiiiiiiisssiiiiiiiffiffiifiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifffliiiiiiiliiis"; +const char CreatureInfodstfmt[]="iiiiiiiiiisssiiiiiiiffiffiifiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifffliiiiiiiliiii"; const char CreatureDataAddonInfofmt[]="iiiiiis"; const char CreatureModelfmt[]="iffbi"; const char CreatureInfoAddonInfofmt[]="iiiiiis"; diff --git a/src/shared/Database/SQLStorageImpl.h b/src/shared/Database/SQLStorageImpl.h index 5ad8a66679a..c74be48c34c 100644 --- a/src/shared/Database/SQLStorageImpl.h +++ b/src/shared/Database/SQLStorageImpl.h @@ -122,7 +122,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) { uint32 maxi; Field *fields; - QueryResult *result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table); + QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table); if(!result) { sLog.outError("Error loading %s table (not exist?)\n", store.table); @@ -130,14 +130,12 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) } maxi = (*result)[0].GetUInt32()+1; - delete result; result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table); if(result) { fields = result->Fetch(); store.RecordCount = fields[0].GetUInt32(); - delete result; } else store.RecordCount = 0; @@ -158,7 +156,6 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) { store.RecordCount = 0; sLog.outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n", store.table, store.iNumFields); - delete result; exit(1); // Stop server at loading broken or non-compatible table. } @@ -206,8 +203,6 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) ++count; }while( result->NextRow() ); - delete result; - store.pIndex = newIndex; store.MaxEntry = maxi; store.data = _data; diff --git a/src/shared/Database/SqlOperations.cpp b/src/shared/Database/SqlOperations.cpp index 1012c94cbdd..793fabecde7 100644 --- a/src/shared/Database/SqlOperations.cpp +++ b/src/shared/Database/SqlOperations.cpp @@ -109,7 +109,7 @@ bool SqlQueryHolder::SetQuery(size_t index, const char *sql) } /// not executed yet, just stored (it's not called a holder for nothing) - m_queries[index] = SqlResultPair(strdup(sql), NULL); + m_queries[index] = SqlResultPair(strdup(sql), QueryResult_AutoPtr(NULL)); return true; } @@ -136,7 +136,7 @@ bool SqlQueryHolder::SetPQuery(size_t index, const char *format, ...) return SetQuery(index,szQuery); } -QueryResult* SqlQueryHolder::GetResult(size_t index) +QueryResult_AutoPtr SqlQueryHolder::GetResult(size_t index) { if(index < m_queries.size()) { @@ -150,10 +150,10 @@ QueryResult* SqlQueryHolder::GetResult(size_t index) return m_queries[index].second; } else - return NULL; + return QueryResult_AutoPtr(NULL); } -void SqlQueryHolder::SetResult(size_t index, QueryResult *result) +void SqlQueryHolder::SetResult(size_t index, QueryResult_AutoPtr result) { /// store the result in the holder if(index < m_queries.size()) @@ -167,11 +167,7 @@ SqlQueryHolder::~SqlQueryHolder() /// if the result was never used, free the resources /// results used already (getresult called) are expected to be deleted if(m_queries[i].first != NULL) - { free((void*)(const_cast<char*>(m_queries[i].first))); - if(m_queries[i].second) - delete m_queries[i].second; - } } } diff --git a/src/shared/Database/SqlOperations.h b/src/shared/Database/SqlOperations.h index acaffb29c70..18641c743e1 100644 --- a/src/shared/Database/SqlOperations.h +++ b/src/shared/Database/SqlOperations.h @@ -27,6 +27,7 @@ #include "LockedQueue.h" #include <queue> #include "Utilities/Callback.h" +#include "QueryResult.h" /// ---- BASE --- @@ -95,7 +96,7 @@ class SqlQueryHolder { friend class SqlQueryHolderEx; private: - typedef std::pair<const char*, QueryResult*> SqlResultPair; + typedef std::pair<const char*, QueryResult_AutoPtr> SqlResultPair; std::vector<SqlResultPair> m_queries; public: SqlQueryHolder() {} @@ -103,8 +104,8 @@ class SqlQueryHolder bool SetQuery(size_t index, const char *sql); bool SetPQuery(size_t index, const char *format, ...) ATTR_PRINTF(3,4); void SetSize(size_t size); - QueryResult* GetResult(size_t index); - void SetResult(size_t index, QueryResult *result); + QueryResult_AutoPtr GetResult(size_t index); + void SetResult(size_t index, QueryResult_AutoPtr result); bool Execute(Trinity::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue); }; diff --git a/src/trinitycore/CliRunnable.cpp b/src/trinitycore/CliRunnable.cpp index e074594de72..4549ffcf03e 100644 --- a/src/trinitycore/CliRunnable.cpp +++ b/src/trinitycore/CliRunnable.cpp @@ -215,7 +215,7 @@ bool ChatHandler::HandleServerExitCommand(const char* /*args*/) bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/) { ///- Get the list of accounts ID logged to the realm - QueryResult *resultDB = CharacterDatabase.Query("SELECT name,account FROM characters WHERE online > 0"); + QueryResult_AutoPtr resultDB = CharacterDatabase.Query("SELECT name,account FROM characters WHERE online > 0"); if (!resultDB) { SendSysMessage(LANG_ACCOUNT_LIST_EMPTY); @@ -236,7 +236,7 @@ bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/) ///- Get the username, last IP and GM level of each account // No SQL injection. account is uint32. - QueryResult *resultLogin = + QueryResult_AutoPtr resultLogin = loginDatabase.PQuery("SELECT a.username, a.last_ip, aa.gmlevel, a.expansion " "FROM account a " "LEFT JOIN account_access aa " @@ -247,16 +247,12 @@ bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/) Field *fieldsLogin = resultLogin->Fetch(); PSendSysMessage(LANG_ACCOUNT_LIST_LINE, fieldsLogin[0].GetString(),name.c_str(),fieldsLogin[1].GetString(),fieldsLogin[2].GetUInt32(),fieldsLogin[3].GetUInt32()); - - delete resultLogin; } else PSendSysMessage(LANG_ACCOUNT_LIST_ERROR,name.c_str()); }while(resultDB->NextRow()); - delete resultDB; - SendSysMessage(LANG_ACCOUNT_LIST_BAR); return true; } diff --git a/src/trinitycore/Master.cpp b/src/trinitycore/Master.cpp index 221ce4967a9..41169565565 100644 --- a/src/trinitycore/Master.cpp +++ b/src/trinitycore/Master.cpp @@ -135,9 +135,9 @@ public: { loopCounter = 0; sLog.outDetail ("Ping MySQL to keep connection alive"); - delete WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1"); - delete loginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1"); - delete CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1"); + WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1"); + loginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1"); + CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1"); } } diff --git a/src/trinitycore/RASocket.cpp b/src/trinitycore/RASocket.cpp index bed7fbf57ca..a55af0e270a 100644 --- a/src/trinitycore/RASocket.cpp +++ b/src/trinitycore/RASocket.cpp @@ -154,7 +154,7 @@ void RASocket::OnRead() ///- Escape the Login to allow quotes in names loginDatabase.escape_string(login); - QueryResult* result = loginDatabase.PQuery("SELECT a.id, aa.gmlevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = '%s'",login.c_str ()); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT a.id, aa.gmlevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = '%s'",login.c_str ()); ///- If the user is not found, deny access if(!result) @@ -187,7 +187,6 @@ void RASocket::OnRead() { stage=LG; } - delete result; } } break; @@ -204,13 +203,12 @@ void RASocket::OnRead() loginDatabase.escape_string(login); loginDatabase.escape_string(pw); - QueryResult *check = loginDatabase.PQuery( + QueryResult_AutoPtr check = loginDatabase.PQuery( "SELECT 1 FROM account WHERE username = '%s' AND sha_pass_hash=SHA1(CONCAT('%s',':','%s'))", login.c_str(), login.c_str(), pw.c_str()); if(check) { - delete check; r=GetSocket(); stage=OK; ++iUsers; diff --git a/src/trinityrealm/AuthSocket.cpp b/src/trinityrealm/AuthSocket.cpp index f9aa40af629..b5fe5f040c1 100644 --- a/src/trinityrealm/AuthSocket.cpp +++ b/src/trinityrealm/AuthSocket.cpp @@ -399,12 +399,11 @@ bool AuthSocket::_HandleLogonChallenge() std::string address = GetRemoteAddress(); loginDatabase.escape_string(address); - QueryResult *result = loginDatabase.PQuery("SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str()); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str()); if (result) { pkt << (uint8)REALM_AUTH_ACCOUNT_BANNED; sLog.outBasic("[AuthChallenge] Banned ip %s tries to login!",GetRemoteAddress().c_str ()); - delete result; } else { @@ -446,7 +445,7 @@ bool AuthSocket::_HandleLogonChallenge() //set expired bans to inactive loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); ///- If the account is banned, reject the logon attempt - QueryResult *banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE id = %u AND active = 1", (*result)[1].GetUInt32()); + QueryResult_AutoPtr banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE id = %u AND active = 1", (*result)[1].GetUInt32()); if (banresult) { if ((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64()) @@ -459,8 +458,6 @@ bool AuthSocket::_HandleLogonChallenge() pkt << (uint8) REALM_AUTH_ACCOUNT_FREEZED; sLog.outBasic("[AuthChallenge] Temporarily banned account %s tries to login!",_login.c_str ()); } - - delete banresult; } else { @@ -535,7 +532,6 @@ bool AuthSocket::_HandleLogonChallenge() sLog.outBasic("[AuthChallenge] account %s is using '%c%c%c%c' locale (%u)", _login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName)); } } - delete result; } else //no account { @@ -737,7 +733,7 @@ bool AuthSocket::_HandleLogonProof() //Increment number of failed logins by one and if it reaches the limit temporarily ban that account or IP loginDatabase.PExecute("UPDATE account SET failed_logins = failed_logins + 1 WHERE username = '%s'",_safelogin.c_str()); - if (QueryResult *loginfail = loginDatabase.PQuery("SELECT id, failed_logins FROM account WHERE username = '%s'", _safelogin.c_str())) + if (QueryResult_AutoPtr loginfail = loginDatabase.PQuery("SELECT id, failed_logins FROM account WHERE username = '%s'", _safelogin.c_str())) { Field* fields = loginfail->Fetch(); uint32 failed_logins = fields[1].GetUInt32(); @@ -765,7 +761,6 @@ bool AuthSocket::_HandleLogonProof() current_ip.c_str(), WrongPassBanTime, _login.c_str(), failed_logins); } } - delete loginfail; } } } @@ -805,7 +800,7 @@ bool AuthSocket::_HandleReconnectChallenge() _login = (const char*)ch->I; _safelogin = _login; - QueryResult *result = loginDatabase.PQuery ("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str ()); + QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str ()); // Stop if the account is not found if (!result) @@ -817,7 +812,6 @@ bool AuthSocket::_HandleReconnectChallenge() Field* fields = result->Fetch (); K.SetHexStr (fields[0].GetString ()); - delete result; ///- Sending response ByteBuffer pkt; @@ -885,7 +879,7 @@ bool AuthSocket::_HandleRealmList() ///- Get the user id (else close the connection) // No SQL injection (escaped user name) - QueryResult *result = loginDatabase.PQuery("SELECT id,sha_pass_hash FROM account WHERE username = '%s'",_safelogin.c_str()); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT id,sha_pass_hash FROM account WHERE username = '%s'",_safelogin.c_str()); if (!result) { sLog.outError("[ERROR] user %s tried to login and we cannot find him in the database.",_login.c_str()); @@ -895,7 +889,6 @@ bool AuthSocket::_HandleRealmList() uint32 id = (*result)[0].GetUInt32(); std::string rI = (*result)[1].GetCppString(); - delete result; ///- Update realm list if need m_realmList.UpdateIfNeed(); @@ -935,7 +928,6 @@ bool AuthSocket::_HandleRealmList() { Field *fields = result->Fetch(); AmountOfCharacters = fields[0].GetUInt8(); - delete result; } else AmountOfCharacters = 0; diff --git a/src/trinityrealm/Main.cpp b/src/trinityrealm/Main.cpp index 9b94c61afe2..68e200969e3 100644 --- a/src/trinityrealm/Main.cpp +++ b/src/trinityrealm/Main.cpp @@ -288,7 +288,7 @@ extern int main(int argc, char **argv) { loopCounter = 0; sLog.outDetail("Ping MySQL to keep connection alive"); - delete loginDatabase.Query("SELECT 1 FROM realmlist LIMIT 1"); + loginDatabase.Query("SELECT 1 FROM realmlist LIMIT 1"); } #ifdef WIN32 if (m_ServiceStatus == 0) stopEvent = true; diff --git a/src/trinityrealm/RealmList.cpp b/src/trinityrealm/RealmList.cpp index a04a4fd7bfb..5a441de8012 100644 --- a/src/trinityrealm/RealmList.cpp +++ b/src/trinityrealm/RealmList.cpp @@ -83,7 +83,7 @@ void RealmList::UpdateRealms(bool init) { sLog.outDetail("Updating Realm List..."); - QueryResult *result = loginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name"); + QueryResult_AutoPtr result = loginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name"); ///- Circle through results and add them to the realm map if (result) @@ -98,6 +98,5 @@ void RealmList::UpdateRealms(bool init) if (init) sLog.outString("Added realm \"%s\".", fields[1].GetString()); } while(result->NextRow()); - delete result; } } |