Compare commits

...

111 Commits

Author SHA1 Message Date
KimLS b26d9c07f1 Some of these really slow down profiling without adding much (short functions) 2015-02-13 00:38:28 -08:00
KimLS 8e45fd2253 Added profiling to a lot of /common, though not all some misc or small functions were purposely skipped 2015-02-12 13:32:58 -08:00
KimLS 76cdedccb8 Fix for not writing logs, added profiling to a bunch of common lib stuff. 2015-02-11 21:48:57 -08:00
KimLS d39e886459 Merge branch 'master' into profiler 2015-02-10 22:27:26 -08:00
KayenEQ 7f65080c45 Merge pull request #373 from KayenEQ/Development
numhits issue fix
2015-02-10 23:25:16 -05:00
KayenEQ c8acb7bd43 numhits issue fix 2015-02-10 23:24:41 -05:00
Trevius 69d727cbe5 (SoF+) Removed duplicate packets being sent to client on zone (Take #2)! 2015-02-10 19:22:42 -06:00
KimLS 9daf572ea7 Fix for no factions in database crashing the server and shared memory 2015-02-10 11:53:39 -08:00
Michael Cook (mackal) f613d12c61 Revert "(SoF+) Removed duplicate packets being sent to client on zone."
This reverts commit e6eb4e16d1.
2015-02-10 12:49:32 -05:00
Trevius 927e4f83ff (RoF2) Updated Expedition Opcodes 2015-02-09 20:07:04 -06:00
Trevius 82b9af3956 (RoF+) Guild Invites between RoF+ and previous Clients is now functional. 2015-02-09 19:54:14 -06:00
KimLS 82933a80d1 Merge branch 'master' of github.com:EQEmu/Server 2015-02-09 17:48:20 -08:00
KimLS 543e265b0a Adjustments to OP_SpawnAppearance, as well as updating import client files to handle newer spell files 2015-02-09 17:48:07 -08:00
Trevius c4eb6e2881 (RoF+) Setting Alt flag on characters in the Guild Management Window is now saved and functional for filtering. 2015-02-09 18:52:17 -06:00
Trevius e6eb4e16d1 (SoF+) Removed duplicate packets being sent to client on zone. 2015-02-09 17:23:43 -06:00
Michael Cook (mackal) 95b66583b3 Merge pull request #367 from JohnsonAskot/master
Sanity checking
2015-02-09 17:54:08 -05:00
Michael Cook (mackal) 45e7ff9193 Fix RoF2 item hotkeys
This string thing needs to be longer! Still no idea what it is
2015-02-09 03:02:25 -05:00
KayenEQ 48c65628d8 Merge pull request #371 from KayenEQ/Development
npc special ability (44) COUNTER_AVOID_DAMAGE
2015-02-08 20:30:41 -05:00
KayenEQ 0521cae8d0 Implemented npc specialability (44) COUNTER_AVOID_DAMAGE which when applied to the ATTACKING NPC will make their attacks more difficult to be avoided by riposte/dodge/parry/block.
Parama0: Negative modifer value that affects ALL avoid damage types dodge/parry/riposte/block) chance on defender. Ie (44,50 = 50 pct reduction to ALL)
Parama1: Negative modifer value that affects RIPOSTE chance on defender. Ie (44,1,0,50 = 50 pct reduction to riposte chance)
Parama2: Negative modifer value that affects PARRY chance on defender.  Ie (44,1,0,0,50 = 50 pct reduction to parry chance)
Parama3: Negative modifer value that affects BLOCK chance on defender.  Ie (44,1,0,0,0,50 = 50 pct reduction to block chance)
Parama4: Negative modifer value that affects DODGE chance on defender.  e (44,1,0,0,0,0,50 = 50 pct reduction to dodge chance)
Example of usage: Player has Improved Dodge V (+50 pct dodge chance), you want to negate this bonus you would set 44,1,0,0,0,0,50 on your NPC.

Clean up and minor fixes to AvoidDamage function.
Added support to a few AA bonuses there.
2015-02-08 20:17:51 -05:00
KayenEQ 4629c7c8c4 Merge git://github.com/EQEmu/Server into Development 2015-02-08 19:04:06 -05:00
Akkadius 8b925f549b derp [skip ci] 2015-02-08 06:19:14 -06:00
Akkadius cb81d956f6 Reduced #repop time dramatically by taking down hundreds of individual SELECT/DELETE/INSERT queries in routines and bringing it down to very few
See: https://www.youtube.com/watch?v=9kSFbyTBuAk
2015-02-08 05:01:58 -06:00
KayenEQ 1149f04389 Merge pull request #370 from KayenEQ/Development
bonus fix
2015-02-07 20:20:48 -05:00
KayenEQ 9aac1b0081 Merge git://github.com/EQEmu/Server into Development 2015-02-07 20:19:58 -05:00
KayenEQ 3392f4b1c3 bonus fix 2015-02-07 20:16:27 -05:00
KayenEQ 20712ce0e6 Merge pull request #369 from KayenEQ/Development
Should fix spell bonuses not being applied properly
2015-02-07 20:08:27 -05:00
KayenEQ 9a15361e93 Should fix spell bonuses not being applied properly 2015-02-07 20:07:46 -05:00
KimLS 452b1a1eae Added throttling to some appearance packets, also removed responding to client light packets. With the new light code we'll tell the client when the light has changed not the other way around. 2015-02-07 15:55:01 -08:00
JJ edbd055277 Revert b96e5a7f4d to search for better fix. 2015-02-07 17:27:48 -05:00
KimLS 00eb526876 Changed how i dump to file. 2015-02-07 12:51:54 -08:00
JohnsonAskot 7bf054bd58 Name removed from comments 2015-02-07 14:35:43 -05:00
Michael Cook (mackal) 67ee327f5b Better sanity checking in Client::BuyTraderItem to prevent potential exploits 2015-02-07 12:39:46 -05:00
JohnsonAskot 63810d5c1b Exploit fixes
Bind Wound was spammable via packet sending. You could buy a larger
stack than the max StackSize of an item from merchants that had
unlimited of those stackable items.
2015-02-07 12:34:50 -05:00
Akkadius d5047da637 Fix an issue that is slowing repops down and unecessarily causing more work for respawn timer code 2015-02-06 19:55:00 -06:00
Uleat 9446d75444 Merge branch 'master' of https://github.com/EQEmu/Server
Conflicts:
	changelog.txt
2015-02-06 13:20:32 -05:00
Uleat c9cd733d9a Updated command #iteminfo 2015-02-06 12:09:26 -05:00
Uleat 5a619bddaf Excluded limbo (cursor buffer) from HasItem checks 2015-02-06 09:58:57 -05:00
Uleat 5d64012d74 Removed iter_inst and iter_contents typedefs 2015-02-06 08:52:41 -05:00
Uleat 2bf2485b4c Enforced const_interator returns on const_iterator return types in Inventory and ItemInst 2015-02-06 07:57:15 -05:00
KimLS b5d33c7cbe Extended to shared database 2015-02-06 00:17:12 -08:00
KayenEQ 8acaa47b8f Merge pull request #366 from KayenEQ/Development
Optional additive worn effect bonus rule
2015-02-06 03:06:04 -05:00
KayenEQ bc6199a86f Implemented a better method for developers who want to have additivie
worn bonuses than what was prior implemented.

Removed old rule RuleB(Spells, AdditiveBonusValues)

Replaced with new rule RuleI(AdditiveBonusWornType)

The rule value denotes a specific 'worntype' that is to be
checked on items. If the items 'worntype' matches the rules worntype
then any worn effect on that item will be cacluated additively
instead of taking the highest value. This will also stack with
regular worn effects that take highest value. Unless the value
is set to (2) which is what all live items use. If set to 2 then
all worn effects will be calculated additively (same as what the old
rule did).

In laymans terms. You can take 3 Cleave I items and put them on a character
and they will all add together if you set the worn type = 3 and the rule = 3.
Which would also add to any regular cleave set to worn type = 2.

Hope you enjoyed the novel.
2015-02-06 02:49:42 -05:00
KimLS 05df5c3e74 Fixed linking 2015-02-05 23:36:35 -08:00
KimLS ac1a3d0743 Shared memory profiling 2015-02-05 23:31:39 -08:00
KimLS 7fd3cc3483 Merge from master 2015-02-05 23:24:51 -08:00
Trevius f26d303ee1 Fixed Environmental Damage for RoF2. 2015-02-05 22:34:55 -06:00
JJ b96e5a7f4d Group leader is not always member 0. 2015-02-05 19:18:51 -05:00
Michael Cook (mackal) 36d53f69d6 Fix query in Database::SetRaidGroupLeaderInfo 2015-02-05 18:11:38 -05:00
Akkadius ef5d475978 Correct db manifest [skip ci] 2015-02-05 06:05:49 -06:00
Akkadius dce6ccf4de GetTaskActivityDoneCountFromTaskID crash fix 2015-02-05 05:43:36 -06:00
KayenEQ b169544711 Merge pull request #365 from KayenEQ/Development
Calc focus effects from worn slots, for an additive foci bonus [NOT LIVE LIKE]
2015-02-05 06:24:43 -05:00
KayenEQ 1495eb42a3 sql 2015-02-05 04:27:52 -05:00
KayenEQ dd17597c92 Implemented non-live like feature to allow focus effects to be placed in worn slot
to provide an additive focus bonus that stacks with regular focus effects.
This is opposed to how regular focus effects work in which the highest
value is always taken. Please note, focus calculated from worn slot
will only use only the focuses base value (ie ignores all limit checks).

Example (Hypothetical).
Improved Heal I (10 pct focus) in Helm Worn Slot
Improved Heal I (10 pct focus) in Glove Worn Slot
Improved Heal V (50 pct focus) in Glove Focus Slot
Total Heal Focus would be 50 + 10 + 10

Added optional rule which is OFF by default.
UseAdditiveFocusFromWornSlot
2015-02-05 04:27:33 -05:00
Alex 54c3f9ab94 Merge pull request #364 from EQEmu/loot
Loot Upgrade
2015-02-05 00:06:38 -08:00
KimLS ecd05d821e Merge and fix the loot update branch, ready for merge I think 2015-02-04 23:13:02 -08:00
KayenEQ 4bd2e04482 Merge pull request #363 from KayenEQ/Development
Added perl function function: CanClassEquipItem(item_id)
2015-02-04 22:46:47 -05:00
KayenEQ cafd0eaba1 Added perl function function: CanClassEquipItem(item_id)
Returns a bool if can equip or not.
2015-02-04 22:46:02 -05:00
Uleat facd7d357d Light source exclusion tweak (helps with strobing effects) 2015-02-03 22:43:03 -05:00
Trevius 8bc5e5eee1 Crashfix for TempName() when numbers are passed at the end of the name. 2015-02-03 17:23:29 -06:00
KayenEQ bfa6bd3458 Merge pull request #362 from KayenEQ/Development
Improvements to the pet type (5) code.
2015-02-03 08:01:15 -05:00
KayenEQ 33767aeb91 Improvements to the pet type (5) code. 2015-02-03 07:59:29 -05:00
KayenEQ ff8a19b1cb Merge pull request #361 from KayenEQ/Development
Implemented pet type 5 (petTargetLock)
2015-02-03 07:10:41 -05:00
KayenEQ 356316db84 Optional SQL to convert all(?) live pets that should use the new pet type (5). 2015-02-03 07:09:24 -05:00
KayenEQ 379219aff1 Implemented new pet type (5) which summons a regular pet that locks onto
the casters target exclusively until the target dies, when target dies
the pet is killed. (Pets don't respond to commands except get lost).
This does not stack with regular pets.

Note: On live these pets cast an actual spell (Unsummon) that kills them for 20k damage,
due to how limiting that is to be hard coded, the pets will simply just
kill themselves instead.

Pending, will needd to add an optional SQL to update pet tables to convert
known live spells that use this.
2015-02-03 06:40:51 -05:00
KimLS 5747b3460f More perf work, need to switch branches. 2015-02-02 23:10:03 -08:00
KayenEQ a677d40f6d Merge pull request #360 from KayenEQ/Development
Fix to allow for PBAE/Targeted AE spells to check the 'npc_no_los' field...
2015-02-02 03:02:14 -05:00
KayenEQ aed3d9ef85 Fix to allow for PBAE/Targeted AE spells to check the 'npc_no_los' field in spell file
to disable LOS checks.
2015-02-02 03:01:37 -05:00
Akkadius f2667cee23 Implement Packet logs with dumps
- Category: 41: Packet: Server -> Client With Dump
	- Category: 42: Packet: Server -> Client With Dump
	See: http://wiki.eqemulator.org/p?Logging_System_Overhaul#packet-logging-levels
2015-02-02 00:10:22 -06:00
Michael Cook (mackal) e1c49f93e2 Out of bounds bandoleer fix 2015-02-02 00:18:29 -05:00
Akkadius d2b9d4ab20 find_replace fix for real 2015-02-01 22:40:56 -06:00
Akkadius 20c99e36d8 find_replace fix 2015-02-01 22:29:04 -06:00
Akkadius 3ec39ce06b Changelog 2015-02-01 22:00:21 -06:00
Akkadius 10e3c31ad6 Packet Logging database version update 2015-02-01 21:56:45 -06:00
Akkadius 4b08c75527 Add some 'is_category_enabled' before some more core logging function calls 2015-02-01 21:47:41 -06:00
Akkadius 8aa8982b66 Add File 2015_02_01_logsys_packet_logs.sql 2015-02-01 21:43:50 -06:00
Akkadius 5daa29aa3f Merge branch 'master' of https://github.com/EQEmu/Server 2015-02-01 21:42:53 -06:00
Akkadius 75c48e5800 Add category prefix in file based log messages 2015-02-01 21:42:43 -06:00
JJ 6c982179bc Merge pull request #358 from noudess/master
Repair min/max faction issues.
2015-02-01 20:59:23 -05:00
Akkadius 02e56331ec Have is_category_enabled update appropriately when settings are set via #logs 2015-02-01 19:57:02 -06:00
Akkadius 774e429d87 Get Logs::Client_Server_Packet_Unhandled to show raw opcodes 2015-02-01 19:56:32 -06:00
Michael Cook (mackal) 3340d01902 Merge pull request #359 from KinglyKrab/master
Added new rule to make the UnmemSpellAll on death optional.
2015-02-01 19:40:15 -05:00
Kinglykrab 180612bb21 Added new rule to make the UnmemSpellAll on death optional.
- New Rule: Character:UnmemSpellsOnDeath (default true)
2015-02-01 18:57:26 -05:00
Michael Cook (mackal) 8649ed1dcb Add quest debugging to lua 2015-02-01 17:25:16 -05:00
Akkadius f9ba99e99f Merge branch 'master' of https://github.com/EQEmu/Server
Conflicts:
	common/eqemu_logsys.h
2015-02-01 15:56:05 -06:00
Paul Coene 1d40f20da0 Remove incorrect use of before_hit 2015-02-01 16:14:05 -05:00
Paul Coene 614014a238 Faction update 2015-02-01 15:02:14 -05:00
Paul Coene 1ff2a043f4 Merge branch 'master' of https://github.com/EQEmu/Server 2015-02-01 09:34:04 -05:00
Paul Coene 115d0d14ac Fix issues with faction where chars were not allowed to earn faction to
offset starting faction values.
2015-02-01 09:31:07 -05:00
KimLS b6a2ac05bf UCS Profiling 2015-02-01 02:25:07 -08:00
Akkadius b3ea1a9da7 Some changes 2015-02-01 04:05:32 -06:00
Akkadius 5fcd3eb38e Implement stable Server -> Client packet logging 2015-02-01 03:25:16 -06:00
Akkadius e35205eaf4 Add Packet :: Server -> Client logging 2015-02-01 02:13:47 -06:00
Akkadius 081a61a948 Add Packet :: Server -> Client category 2015-02-01 02:11:58 -06:00
Akkadius d75c632d73 Chnage netcode logging check to use is_category_enabled instead of just checking for console 2015-02-01 02:10:18 -06:00
Akkadius d9c47fcd41 Add a category check pre Logs::Client_Server_Packet trigger 2015-02-01 02:09:24 -06:00
Akkadius 387b445685 Fix the 'is_category_enabled' in each of the database loaders 2015-02-01 02:08:46 -06:00
Akkadius 46ac254b3a Add struct member LogSettings::is_category_enabled so that it can be used for fast checking in intense portions of code 2015-02-01 01:58:10 -06:00
Akkadius 5f64b1e1c8 Modify category descriptor Packet :: Client -> Server 2015-02-01 01:06:19 -06:00
Akkadius 5c729e65c9 Add sanity checks to GMSayHookCallBackProcess 2015-02-01 01:05:39 -06:00
Akkadius 4f4eee2b16 Re-Order string_util.h 2015-02-01 01:03:30 -06:00
Akkadius ed9bdaf60c Add to string_util.h void find_replace(std::string& string_subject, std::string& search_string, std::string& replace_string) { 2015-02-01 01:00:05 -06:00
KimLS 2c6eba93ae Back to ST profiling, wont bother profiling the common library for now. 2015-01-31 22:21:52 -08:00
KimLS 444b652c4f Working working working on adding profiling, also switched to multi-threaded profiler (slower but need it). 2015-01-31 19:06:14 -08:00
KimLS 2acf84ce4a Merge branch 'master' into profiler 2015-01-31 14:54:10 -08:00
KimLS e135f46711 Added profiler to loginserver as initial work cause it's the smallest service or one of the smallest 2015-01-31 14:52:27 -08:00
Akkadius a6b95aeceb At point in which Client -> Server packet logging is working, will do more prechecking to declare that anything actually is subscribed to this category before outputting 2015-01-31 02:23:58 -06:00
KimLS 54fae508c5 Merge branch 'master' into loot 2014-10-02 10:16:15 -07:00
KimLS 0cd320dd75 Merge branch 'master' into loot 2014-09-29 19:24:12 -07:00
KimLS 725c5633f6 Fix for avg_coin 2014-09-29 17:13:32 -07:00
KimLS ef082b9144 Merge branch 'master' into loot 2014-09-27 20:09:13 -07:00
KimLS 7fed01ddea initial rewrite of loot code 2014-09-27 19:57:45 -07:00
147 changed files with 3063 additions and 2855 deletions
+12
View File
@@ -31,6 +31,7 @@
#EQEMU_SANITIZE_LUA_LIBS
#EQEMU_BUILD_CLIENT_FILES
#EQEMU_MAP_DIR
#EQEMU_ENABLE_PROFILING
#We set a fairly new version (as of 2013) because I found finding perl was a bit... buggy on older ones
#Can change this if you really want but you should upgrade!
@@ -257,6 +258,7 @@ OPTION(EQEMU_BUILD_TESTS "Build utility tests." OFF)
OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON)
OPTION(EQEMU_BUILD_LUA "Build Lua parser." ON)
OPTION(EQEMU_BUILD_CLIENT_FILES "Build Client Import/Export Data Programs." ON)
OPTION(EQEMU_ENABLE_PROFILING "Enable CPU profiler. Note: will slow down execution time." OFF)
#C++11 stuff
IF(NOT MSVC)
@@ -331,6 +333,16 @@ IF(EQEMU_BUILD_LUA)
ADD_SUBDIRECTORY(luabind)
ENDIF(EQEMU_BUILD_LUA)
IF(EQEMU_ENABLE_PROFILING)
ADD_DEFINITIONS(-DEQPERF_ENABLED)
ADD_DEFINITIONS(-DEQP_MULTITHREAD)
INCLUDE_DIRECTORIES("eqperf")
ADD_SUBDIRECTORY(eqperf)
SET(PERF_LIBS eqperf)
ELSE(EQEMU_ENABLE_PROFILING)
SET(PERF_LIBS "")
ENDIF(EQEMU_ENABLE_PROFILING)
IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS)
ADD_SUBDIRECTORY(common)
ENDIF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS)
+48
View File
@@ -1,5 +1,53 @@
EQEMu Changelog (Started on Sept 24, 2003 15:50)
-------------------------------------------------------
== 02/09/2015 ==
Trevius: (RoF+) Setting Alt flag on characters in the Guild Management Window is now saved and functional for filtering.
Trevius: (RoF+) Guild Invites between RoF+ and previous Clients is now functional.
== 02/08/2015 ==
Kayen: Implemented npc specialability (44) COUNTER_AVOID_DAMAGE which when applied to the ATTACKING NPC will make their attacks more difficult to be avoided by riposte/dodge/parry/block.
Parama0: Negative modifer value that affects ALL avoid damage types dodge/parry/riposte/block) chance on defender. Ie (44,50 = 50 pct reduction to ALL)
Parama1: Negative modifer value that affects RIPOSTE chance on defender. Ie (44,1,0,50 = 50 pct reduction to riposte chance)
Parama2: Negative modifer value that affects PARRY chance on defender. Ie (44,1,0,0,50 = 50 pct reduction to parry chance)
Parama3: Negative modifer value that affects BLOCK chance on defender. Ie (44,1,0,0,0,50 = 50 pct reduction to block chance)
Parama4: Negative modifer value that affects DODGE chance on defender. e (44,1,0,0,0,0,50 = 50 pct reduction to dodge chance)
Example of usage: Player has Improved Dodge V (+50 pct dodge chance), you want to negate this bonus you would set 44,1,0,0,0,0,50 on your NPC.
== 02/07/2015 ==
Akkadius: Reduced #repop time dramatically by taking down hundreds of individual SELECT/DELETE/INSERT queries in routines and bringing it down to very few
See: https://www.youtube.com/watch?v=9kSFbyTBuAk
== 02/06/2015 ==
Uleat: Updated returns for Inventory and ItemInst const iterators. (const == const)
Uleat: Replaced 'iter_inst' and 'iter_contents' typedefs with their stl definitions
Uleat: Removed 'limbo' from the 'HasItem' series of checks - including lore checks. The client excludes this range and it causes issues when performing item searches - dupe lore checks were added to account for this.
Uleat: Updated command #iteminfo to show light source information and a few other things
== 02/05/2015 ==
Trevius: Fixed Environmental Damage for RoF2.
== 02/03/2015 ==
Trevius: Crashfix for TempName() when numbers are passed at the end of the name.
Uleat: Tweaking of item type exclusions to alleviate strobing conditions with light sources
== 02/02/2015 ==
Akkadius: Implement Packet logs with dumps
- Category: 41: Packet: Server -> Client With Dump
- Category: 42: Packet: Server -> Client With Dump
See: http://wiki.eqemulator.org/p?Logging_System_Overhaul#packet-logging-levels
== 02/01/2015 ==
demonstar55: Add quest debugging to lua
eq.debug("Test debug level implicit 1")
eq.debug("Test debug level explicit 1", 1)
eq.debug("Test debug level explicit 2", 2)
eq.debug("Test debug level explicit 3", 3)
Akkadius: Add Packet Logging Categories
- 5 - Packet: Client -> Server - Logs::Client_Server_Packet
- 39 - Packet: Server -> Client - Logs::Server_Client_Packet
- 40 - Packet: Client -> Server Unhandled - Logs::Client_Server_Packet_Unhandled
See: http://wiki.eqemulator.org/p?Logging_System_Overhaul#packet-logging
== 01/31/2015 ==
Trevius: Fixed FindGroundZ() and GetGroundZ() to once again utilize the X and Y arguments that are passed to them.
+4 -1
View File
@@ -11,15 +11,17 @@ ADD_EXECUTABLE(export_client_files ${export_sources} ${export_headers})
INSTALL(TARGETS export_client_files RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
TARGET_LINK_LIBRARIES(export_client_files common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
TARGET_LINK_LIBRARIES(export_client_files common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
IF(MSVC)
SET_TARGET_PROPERTIES(export_client_files PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(export_client_files "Ws2_32.lib")
TARGET_LINK_LIBRARIES(export_client_files "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(export_client_files "WS2_32")
TARGET_LINK_LIBRARIES(export_client_files "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@@ -30,6 +32,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(export_client_files "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(export_client_files "pthread")
TARGET_LINK_LIBRARIES(export_client_files "uuid")
ADD_DEFINITIONS(-fPIC)
ENDIF(UNIX)
+4 -1
View File
@@ -11,15 +11,17 @@ ADD_EXECUTABLE(import_client_files ${import_sources} ${import_headers})
INSTALL(TARGETS import_client_files RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
TARGET_LINK_LIBRARIES(import_client_files common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
TARGET_LINK_LIBRARIES(import_client_files common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
IF(MSVC)
SET_TARGET_PROPERTIES(import_client_files PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(import_client_files "Ws2_32.lib")
TARGET_LINK_LIBRARIES(import_client_files "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(import_client_files "WS2_32")
TARGET_LINK_LIBRARIES(import_client_files "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@@ -30,6 +32,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(import_client_files "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(import_client_files "pthread")
TARGET_LINK_LIBRARIES(import_client_files "uuid")
ADD_DEFINITIONS(-fPIC)
ENDIF(UNIX)
+30 -2
View File
@@ -76,6 +76,24 @@ int GetSpellColumns(SharedDatabase *db) {
return results.RowCount();
}
bool IsStringField(int i) {
switch(i)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
return true;
break;
default:
return false;
}
}
void ImportSpells(SharedDatabase *db) {
Log.Out(Logs::General, Logs::Status, "Importing Spells...");
FILE *f = fopen("import/spells_us.txt", "r");
@@ -113,7 +131,12 @@ void ImportSpells(SharedDatabase *db) {
sql += "'";
}
sql += split[i];
if(split[i].compare("") == 0 && !IsStringField(i)) {
sql += "0";
}
else {
sql += split[i];
}
sql += "'";
}
@@ -128,7 +151,12 @@ void ImportSpells(SharedDatabase *db) {
sql += "'";
}
sql += split[i];
if(split[i].compare("") == 0 && !IsStringField(i)) {
sql += "0";
} else {
sql += split[i];
}
sql += "'";
}
+2 -4
View File
@@ -39,7 +39,6 @@ SET(common_sources
mutex.cpp
mysql_request_result.cpp
mysql_request_row.cpp
opcode_map.cpp
opcodemgr.cpp
packet_dump.cpp
packet_dump_file.cpp
@@ -49,7 +48,6 @@ SET(common_sources
proc_launcher.cpp
ptimer.cpp
races.cpp
rdtsc.cpp
rulesys.cpp
serverinfo.cpp
shareddb.cpp
@@ -62,6 +60,7 @@ SET(common_sources
timeoutmgr.cpp
timer.cpp
unix.cpp
uuid.cpp
worldconn.cpp
xml_parser.cpp
platform.cpp
@@ -158,12 +157,10 @@ SET(common_headers
packet_functions.h
platform.h
proc_launcher.h
profiler.h
ptimer.h
queue.h
races.h
random.h
rdtsc.h
rulesys.h
ruletypes.h
seperator.h
@@ -182,6 +179,7 @@ SET(common_headers
types.h
unix.h
useperl.h
uuid.h
version.h
worldconn.h
xml_parser.h
+102 -22
View File
@@ -57,11 +57,13 @@ Establish a connection to a mysql database with the supplied parameters
Database::Database(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
{
_eqp
DBInitVars();
Connect(host, user, passwd, database, port);
}
bool Database::Connect(const char* host, const char* user, const char* passwd, const char* database, uint32 port) {
_eqp
uint32 errnum= 0;
char errbuf[MYSQL_ERRMSG_SIZE];
if (!Open(host, user, passwd, database, port, &errnum, errbuf)) {
@@ -75,6 +77,7 @@ bool Database::Connect(const char* host, const char* user, const char* passwd, c
}
void Database::DBInitVars() {
_eqp
varcache_array = 0;
varcache_max = 0;
varcache_lastupdate = 0;
@@ -86,6 +89,7 @@ void Database::DBInitVars() {
Database::~Database()
{
_eqp
unsigned int x;
if (varcache_array) {
for (x=0; x<varcache_max; x++) {
@@ -101,7 +105,7 @@ Database::~Database()
Zero will also be returned if there is a database error.
*/
uint32 Database::CheckLogin(const char* name, const char* password, int16* oStatus) {
_eqp
if(strlen(name) >= 50 || strlen(password) >= 50)
return(0);
@@ -137,6 +141,7 @@ uint32 Database::CheckLogin(const char* name, const char* password, int16* oStat
//Get Banned IP Address List - Only return false if the incoming connection's IP address is not present in the banned_ips table.
bool Database::CheckBannedIPs(const char* loginIP)
{
_eqp
std::string query = StringFormat("SELECT ip_address FROM Banned_IPs WHERE ip_address='%s'", loginIP);
auto results = QueryDatabase(query);
@@ -153,6 +158,7 @@ bool Database::CheckBannedIPs(const char* loginIP)
}
bool Database::AddBannedIP(char* bannedIP, const char* notes) {
_eqp
std::string query = StringFormat("INSERT into Banned_IPs SET ip_address='%s', notes='%s'", bannedIP, notes);
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -162,6 +168,7 @@ bool Database::AddBannedIP(char* bannedIP, const char* notes) {
}
bool Database::CheckGMIPs(const char* ip_address, uint32 account_id) {
_eqp
std::string query = StringFormat("SELECT * FROM `gm_ips` WHERE `ip_address` = '%s' AND `account_id` = %i", ip_address, account_id);
auto results = QueryDatabase(query);
@@ -175,17 +182,20 @@ bool Database::AddBannedIP(char* bannedIP, const char* notes) {
}
bool Database::AddGMIP(char* ip_address, char* name) {
_eqp
std::string query = StringFormat("INSERT into `gm_ips` SET `ip_address` = '%s', `name` = '%s'", ip_address, name);
auto results = QueryDatabase(query);
return results.Success();
}
void Database::LoginIP(uint32 AccountID, const char* LoginIP) {
_eqp
std::string query = StringFormat("INSERT INTO account_ip SET accid=%i, ip='%s' ON DUPLICATE KEY UPDATE count=count+1, lastused=now()", AccountID, LoginIP);
QueryDatabase(query);
}
int16 Database::CheckStatus(uint32 account_id) {
_eqp
std::string query = StringFormat("SELECT `status`, UNIX_TIMESTAMP(`suspendeduntil`) as `suspendeduntil`, UNIX_TIMESTAMP() as `current`"
" FROM `account` WHERE `id` = %i", account_id);
@@ -215,6 +225,7 @@ int16 Database::CheckStatus(uint32 account_id) {
}
uint32 Database::CreateAccount(const char* name, const char* password, int16 status, uint32 lsaccount_id) {
_eqp
std::string query;
if (password)
@@ -238,6 +249,7 @@ uint32 Database::CreateAccount(const char* name, const char* password, int16 sta
}
bool Database::DeleteAccount(const char* name) {
_eqp
std::string query = StringFormat("DELETE FROM account WHERE name='%s';",name);
Log.Out(Logs::General, Logs::World_Server, "Account Attempting to be deleted:'%s'", name);
@@ -250,6 +262,7 @@ bool Database::DeleteAccount(const char* name) {
}
bool Database::SetLocalPassword(uint32 accid, const char* password) {
_eqp
std::string query = StringFormat("UPDATE account SET password=MD5('%s') where id=%i;", EscapeString(password).c_str(), accid);
auto results = QueryDatabase(query);
@@ -262,6 +275,7 @@ bool Database::SetLocalPassword(uint32 accid, const char* password) {
}
bool Database::SetAccountStatus(const char* name, int16 status) {
_eqp
std::string query = StringFormat("UPDATE account SET status=%i WHERE name='%s';", status, name);
std::cout << "Account being GM Flagged:" << name << ", Level: " << (int16) status << std::endl;
@@ -282,6 +296,7 @@ bool Database::SetAccountStatus(const char* name, int16 status) {
/* This initially creates the character during character create */
bool Database::ReserveName(uint32 account_id, char* name) {
_eqp
std::string query = StringFormat("SELECT `account_id`, `name` FROM `character_data` WHERE `name` = '%s'", name);
auto results = QueryDatabase(query);
for (auto row = results.begin(); row != results.end(); ++row) {
@@ -302,6 +317,7 @@ bool Database::ReserveName(uint32 account_id, char* name) {
returns false on failure, true otherwise
*/
bool Database::DeleteCharacter(char *name) {
_eqp
uint32 charid = 0;
if(!name || !strlen(name)) {
Log.Out(Logs::General, Logs::World_Server, "DeleteCharacter: request to delete without a name (empty char slot)");
@@ -359,6 +375,7 @@ bool Database::DeleteCharacter(char *name) {
}
bool Database::SaveCharacterCreate(uint32 character_id, uint32 account_id, PlayerProfile_Struct* pp){
_eqp
std::string query = StringFormat(
"REPLACE INTO `character_data` ("
"id,"
@@ -678,6 +695,7 @@ bool Database::SaveCharacterCreate(uint32 character_id, uint32 account_id, Playe
/* This only for new Character creation storing */
bool Database::StoreCharacter(uint32 account_id, PlayerProfile_Struct* pp, Inventory* inv) {
_eqp
uint32 charid = 0;
char zone[50];
float x, y, z;
@@ -732,6 +750,7 @@ bool Database::StoreCharacter(uint32 account_id, PlayerProfile_Struct* pp, Inven
}
uint32 Database::GetCharacterID(const char *name) {
_eqp
std::string query = StringFormat("SELECT `id` FROM `character_data` WHERE `name` = '%s'", name);
auto results = QueryDatabase(query);
auto row = results.begin();
@@ -748,6 +767,7 @@ uint32 Database::GetCharacterID(const char *name) {
Zero will also be returned if there is a database error.
*/
uint32 Database::GetAccountIDByChar(const char* charname, uint32* oCharID) {
_eqp
std::string query = StringFormat("SELECT `account_id`, `id` FROM `character_data` WHERE name='%s'", EscapeString(charname).c_str());
auto results = QueryDatabase(query);
@@ -772,6 +792,7 @@ uint32 Database::GetAccountIDByChar(const char* charname, uint32* oCharID) {
// Retrieve account_id for a given char_id
uint32 Database::GetAccountIDByChar(uint32 char_id) {
_eqp
std::string query = StringFormat("SELECT `account_id` FROM `character_data` WHERE `id` = %i LIMIT 1", char_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -786,6 +807,7 @@ uint32 Database::GetAccountIDByChar(uint32 char_id) {
}
uint32 Database::GetAccountIDByName(const char* accname, int16* status, uint32* lsid) {
_eqp
if (!isAlphaNumeric(accname))
return 0;
@@ -817,6 +839,7 @@ uint32 Database::GetAccountIDByName(const char* accname, int16* status, uint32*
}
void Database::GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID) {
_eqp
std::string query = StringFormat("SELECT `name`, `lsaccount_id` FROM `account` WHERE `id` = '%i'", accountid);
auto results = QueryDatabase(query);
@@ -837,6 +860,7 @@ void Database::GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID
}
void Database::GetCharName(uint32 char_id, char* name) {
_eqp
std::string query = StringFormat("SELECT `name` FROM `character_data` WHERE id='%i'", char_id);
auto results = QueryDatabase(query);
@@ -851,6 +875,7 @@ void Database::GetCharName(uint32 char_id, char* name) {
}
bool Database::LoadVariables() {
_eqp
char *query = nullptr;
auto results = QueryDatabase(query, LoadVariables_MQ(&query));
@@ -867,12 +892,14 @@ bool Database::LoadVariables() {
uint32 Database::LoadVariables_MQ(char** query)
{
_eqp
return MakeAnyLenString(query, "SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache_lastupdate);
}
// always returns true? not sure about this.
bool Database::LoadVariables_result(MySQLRequestResult results)
{
_eqp
uint32 i = 0;
LockMutex lock(&Mvarcache);
@@ -935,6 +962,7 @@ bool Database::LoadVariables_result(MySQLRequestResult results)
// Gets variable from 'variables' table
bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_len) {
_eqp
varvalue[0] = '\0';
LockMutex lock(&Mvarcache);
@@ -956,7 +984,7 @@ bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_
}
bool Database::SetVariable(const char* varname_in, const char* varvalue_in) {
_eqp
char *varname,*varvalue;
varname=(char *)malloc(strlen(varname_in)*2+1);
@@ -996,6 +1024,7 @@ bool Database::SetVariable(const char* varname_in, const char* varvalue_in) {
uint32 Database::GetMiniLoginAccount(char* ip)
{
_eqp
std::string query = StringFormat("SELECT `id` FROM `account` WHERE `minilogin_ip` = '%s'", ip);
auto results = QueryDatabase(query);
@@ -1008,7 +1037,7 @@ uint32 Database::GetMiniLoginAccount(char* ip)
// Get zone starting points from DB
bool Database::GetSafePoints(const char* short_name, uint32 version, float* safe_x, float* safe_y, float* safe_z, int16* minstatus, uint8* minlevel, char *flag_needed) {
_eqp
std::string query = StringFormat("SELECT safe_x, safe_y, safe_z, min_status, min_level, flag_needed FROM zone "
" WHERE short_name='%s' AND (version=%i OR version=0) ORDER BY version DESC", short_name, version);
auto results = QueryDatabase(query);
@@ -1038,7 +1067,7 @@ bool Database::GetSafePoints(const char* short_name, uint32 version, float* safe
}
bool Database::GetZoneLongName(const char* short_name, char** long_name, char* file_name, float* safe_x, float* safe_y, float* safe_z, uint32* graveyard_id, uint32* maxclients) {
_eqp
std::string query = StringFormat("SELECT long_name, file_name, safe_x, safe_y, safe_z, graveyard_id, maxclients FROM zone WHERE short_name='%s' AND version=0", short_name);
auto results = QueryDatabase(query);
@@ -1076,7 +1105,7 @@ bool Database::GetZoneLongName(const char* short_name, char** long_name, char* f
}
uint32 Database::GetZoneGraveyardID(uint32 zone_id, uint32 version) {
_eqp
std::string query = StringFormat("SELECT graveyard_id FROM zone WHERE zoneidnumber='%u' AND (version=%i OR version=0) ORDER BY version DESC", zone_id, version);
auto results = QueryDatabase(query);
@@ -1091,7 +1120,7 @@ uint32 Database::GetZoneGraveyardID(uint32 zone_id, uint32 version) {
}
bool Database::GetZoneGraveyard(const uint32 graveyard_id, uint32* graveyard_zoneid, float* graveyard_x, float* graveyard_y, float* graveyard_z, float* graveyard_heading) {
_eqp
std::string query = StringFormat("SELECT zone_id, x, y, z, heading FROM graveyard WHERE id=%i", graveyard_id);
auto results = QueryDatabase(query);
@@ -1119,6 +1148,7 @@ bool Database::GetZoneGraveyard(const uint32 graveyard_id, uint32* graveyard_zon
}
bool Database::LoadZoneNames() {
_eqp
std::string query("SELECT zoneidnumber, short_name FROM zone");
auto results = QueryDatabase(query);
@@ -1139,7 +1169,7 @@ bool Database::LoadZoneNames() {
}
uint32 Database::GetZoneID(const char* zonename) {
_eqp
if (zonename == nullptr)
return 0;
@@ -1151,6 +1181,7 @@ uint32 Database::GetZoneID(const char* zonename) {
}
const char* Database::GetZoneName(uint32 zoneID, bool ErrorUnknown) {
_eqp
auto iter = zonename_array.find(zoneID);
if (iter != zonename_array.end())
@@ -1163,7 +1194,7 @@ const char* Database::GetZoneName(uint32 zoneID, bool ErrorUnknown) {
}
uint8 Database::GetPEQZone(uint32 zoneID, uint32 version){
_eqp
std::string query = StringFormat("SELECT peqzone from zone where zoneidnumber='%i' AND (version=%i OR version=0) ORDER BY version DESC", zoneID, version);
auto results = QueryDatabase(query);
@@ -1181,6 +1212,7 @@ uint8 Database::GetPEQZone(uint32 zoneID, uint32 version){
bool Database::CheckNameFilter(const char* name, bool surname)
{
_eqp
std::string str_name = name;
if(surname)
@@ -1257,7 +1289,7 @@ bool Database::CheckNameFilter(const char* name, bool surname)
}
bool Database::AddToNameFilter(const char* name) {
_eqp
std::string query = StringFormat("INSERT INTO name_filter (name) values ('%s')", name);
auto results = QueryDatabase(query);
@@ -1273,6 +1305,7 @@ bool Database::AddToNameFilter(const char* name) {
}
uint32 Database::GetAccountIDFromLSID(uint32 iLSID, char* oAccountName, int16* oStatus) {
_eqp
uint32 account_id = 0;
std::string query = StringFormat("SELECT id, name, status FROM account WHERE lsaccount_id=%i", iLSID);
auto results = QueryDatabase(query);
@@ -1297,7 +1330,7 @@ uint32 Database::GetAccountIDFromLSID(uint32 iLSID, char* oAccountName, int16* o
}
void Database::GetAccountFromID(uint32 id, char* oAccountName, int16* oStatus) {
_eqp
std::string query = StringFormat("SELECT name, status FROM account WHERE id=%i", id);
auto results = QueryDatabase(query);
@@ -1317,10 +1350,12 @@ void Database::GetAccountFromID(uint32 id, char* oAccountName, int16* oStatus) {
}
void Database::ClearMerchantTemp(){
_eqp
QueryDatabase("DELETE FROM merchantlist_temp");
}
bool Database::UpdateName(const char* oldname, const char* newname) {
_eqp
std::cout << "Renaming " << oldname << " to " << newname << "..." << std::endl;
std::string query = StringFormat("UPDATE `character_data` SET `name` = '%s' WHERE `name` = '%s';", newname, oldname);
auto results = QueryDatabase(query);
@@ -1336,6 +1371,7 @@ bool Database::UpdateName(const char* oldname, const char* newname) {
// If the name is used or an error occurs, it returns false, otherwise it returns true
bool Database::CheckUsedName(const char* name) {
_eqp
std::string query = StringFormat("SELECT `id` FROM `character_data` WHERE `name` = '%s'", name);
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -1349,6 +1385,7 @@ bool Database::CheckUsedName(const char* name) {
}
uint8 Database::GetServerType() {
_eqp
std::string query("SELECT `value` FROM `variables` WHERE `varname` = 'ServerType' LIMIT 1");
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -1363,6 +1400,7 @@ uint8 Database::GetServerType() {
}
bool Database::MoveCharacterToZone(const char* charname, const char* zonename, uint32 zoneid) {
_eqp
if(zonename == nullptr || strlen(zonename) == 0)
return false;
@@ -1380,10 +1418,12 @@ bool Database::MoveCharacterToZone(const char* charname, const char* zonename, u
}
bool Database::MoveCharacterToZone(const char* charname, const char* zonename) {
_eqp
return MoveCharacterToZone(charname, zonename, GetZoneID(zonename));
}
bool Database::MoveCharacterToZone(uint32 iCharID, const char* iZonename) {
_eqp
std::string query = StringFormat("UPDATE `character_data` SET `zone_id` = %i, `x` = -1, `y` = -1, `z` = -1 WHERE `id` = %i", iZonename, GetZoneID(iZonename), iCharID);
auto results = QueryDatabase(query);
@@ -1395,6 +1435,7 @@ bool Database::MoveCharacterToZone(uint32 iCharID, const char* iZonename) {
}
bool Database::SetHackerFlag(const char* accountname, const char* charactername, const char* hacked) {
_eqp
std::string query = StringFormat("INSERT INTO `hackers` (account, name, hacked) values('%s','%s','%s')", accountname, charactername, hacked);
auto results = QueryDatabase(query);
@@ -1406,6 +1447,7 @@ bool Database::SetHackerFlag(const char* accountname, const char* charactername,
}
bool Database::SetMQDetectionFlag(const char* accountname, const char* charactername, const char* hacked, const char* zone) {
_eqp
//Utilize the "hacker" table, but also give zone information.
std::string query = StringFormat("INSERT INTO hackers(account,name,hacked,zone) values('%s','%s','%s','%s')", accountname, charactername, hacked, zone);
auto results = QueryDatabase(query);
@@ -1420,6 +1462,7 @@ bool Database::SetMQDetectionFlag(const char* accountname, const char* character
uint8 Database::GetRaceSkill(uint8 skillid, uint8 in_race)
{
_eqp
uint16 race_cap = 0;
//Check for a racial cap!
@@ -1438,6 +1481,7 @@ uint8 Database::GetRaceSkill(uint8 skillid, uint8 in_race)
uint8 Database::GetSkillCap(uint8 skillid, uint8 in_race, uint8 in_class, uint16 in_level)
{
_eqp
uint8 skill_level = 0, skill_formula = 0;
uint16 base_cap = 0, skill_cap = 0, skill_cap2 = 0, skill_cap3 = 0;
@@ -1487,6 +1531,7 @@ uint8 Database::GetSkillCap(uint8 skillid, uint8 in_race, uint8 in_class, uint16
}
uint32 Database::GetCharacterInfo(const char* iName, uint32* oAccID, uint32* oZoneID, uint32* oInstanceID, float* oX, float* oY, float* oZ) {
_eqp
std::string query = StringFormat("SELECT `id`, `account_id`, `zone_id`, `zone_instance`, `x`, `y`, `z` FROM `character_data` WHERE `name` = '%s'", iName);
auto results = QueryDatabase(query);
@@ -1510,7 +1555,7 @@ uint32 Database::GetCharacterInfo(const char* iName, uint32* oAccID, uint32* oZo
}
bool Database::UpdateLiveChar(char* charname,uint32 lsaccount_id) {
_eqp
std::string query = StringFormat("UPDATE account SET charname='%s' WHERE id=%i;",charname, lsaccount_id);
auto results = QueryDatabase(query);
@@ -1522,7 +1567,7 @@ bool Database::UpdateLiveChar(char* charname,uint32 lsaccount_id) {
}
bool Database::GetLiveChar(uint32 account_id, char* cname) {
_eqp
std::string query = StringFormat("SELECT charname FROM account WHERE id=%i", account_id);
auto results = QueryDatabase(query);
@@ -1541,26 +1586,31 @@ bool Database::GetLiveChar(uint32 account_id, char* cname) {
}
void Database::SetLFP(uint32 CharID, bool LFP) {
_eqp
std::string query = StringFormat("UPDATE `character_data` SET `lfp` = %i WHERE `id` = %i",LFP, CharID);
QueryDatabase(query);
}
void Database::SetLoginFlags(uint32 CharID, bool LFP, bool LFG, uint8 firstlogon) {
_eqp
std::string query = StringFormat("update `character_data` SET `lfp` = %i, `lfg` = %i, `firstlogon` = %i WHERE `id` = %i",LFP, LFG, firstlogon, CharID);
QueryDatabase(query);
}
void Database::SetLFG(uint32 CharID, bool LFG) {
_eqp
std::string query = StringFormat("update `character_data` SET `lfg` = %i WHERE `id` = %i",LFG, CharID);
QueryDatabase(query);
}
void Database::SetFirstLogon(uint32 CharID, uint8 firstlogon) {
_eqp
std::string query = StringFormat( "UPDATE `character_data` SET `firstlogon` = %i WHERE `id` = %i",firstlogon, CharID);
QueryDatabase(query);
}
void Database::AddReport(std::string who, std::string against, std::string lines) {
_eqp
char *escape_str = new char[lines.size()*2+1];
DoEscapeString(escape_str, lines.c_str(), lines.size());
@@ -1570,6 +1620,7 @@ void Database::AddReport(std::string who, std::string against, std::string lines
}
void Database::SetGroupID(const char* name, uint32 id, uint32 charid, uint32 ismerc) {
_eqp
std::string query;
if (id == 0) {
// removing from group
@@ -1589,12 +1640,14 @@ void Database::SetGroupID(const char* name, uint32 id, uint32 charid, uint32 ism
void Database::ClearAllGroups(void)
{
_eqp
std::string query("DELETE FROM `group_id`");
QueryDatabase(query);
return;
}
void Database::ClearGroup(uint32 gid) {
_eqp
ClearGroupLeader(gid);
if(gid == 0)
@@ -1610,6 +1663,7 @@ void Database::ClearGroup(uint32 gid) {
}
uint32 Database::GetGroupID(const char* name){
_eqp
std::string query = StringFormat("SELECT groupid from group_id where name='%s'", name);
auto results = QueryDatabase(query);
@@ -1620,7 +1674,7 @@ uint32 Database::GetGroupID(const char* name){
if (results.RowCount() == 0)
{
// Commenting this out until logging levels can prevent this from going to console
//Log.Out(Logs::General, Logs::None,, "Character not in a group: %s", name);
//Log.Out(Logs::General, Logs::None, "Character not in a group: %s", name);
return 0;
}
@@ -1631,6 +1685,7 @@ uint32 Database::GetGroupID(const char* name){
/* Is this really getting used properly... A half implementation ? Akkadius */
char* Database::GetGroupLeaderForLogin(const char* name, char* leaderbuf) {
_eqp
strcpy(leaderbuf, "");
uint32 group_id = 0;
@@ -1655,6 +1710,7 @@ char* Database::GetGroupLeaderForLogin(const char* name, char* leaderbuf) {
}
void Database::SetGroupLeaderName(uint32 gid, const char* name) {
_eqp
std::string query = StringFormat("UPDATE group_leaders SET leadername = '%s' WHERE gid = %u", EscapeString(name).c_str(), gid);
auto result = QueryDatabase(query);
@@ -1673,6 +1729,7 @@ void Database::SetGroupLeaderName(uint32 gid, const char* name) {
char *Database::GetGroupLeadershipInfo(uint32 gid, char* leaderbuf, char* maintank, char* assist, char* puller, char *marknpc, char *mentoree, int *mentor_percent, GroupLeadershipAA_Struct* GLAA)
{
_eqp
std::string query = StringFormat("SELECT `leadername`, `maintank`, `assist`, `puller`, `marknpc`, `mentoree`, `mentor_percent`, `leadershipaa` FROM `group_leaders` WHERE `gid` = %lu",(unsigned long)gid);
auto results = QueryDatabase(query);
@@ -1732,6 +1789,7 @@ char *Database::GetGroupLeadershipInfo(uint32 gid, char* leaderbuf, char* mainta
// Clearing all group leaders
void Database::ClearAllGroupLeaders(void) {
_eqp
std::string query("DELETE from group_leaders");
auto results = QueryDatabase(query);
@@ -1742,7 +1800,7 @@ void Database::ClearAllGroupLeaders(void) {
}
void Database::ClearGroupLeader(uint32 gid) {
_eqp
if(gid == 0)
{
ClearAllGroupLeaders();
@@ -1757,7 +1815,7 @@ void Database::ClearGroupLeader(uint32 gid) {
}
uint8 Database::GetAgreementFlag(uint32 acctid) {
_eqp
std::string query = StringFormat("SELECT rulesflag FROM account WHERE id=%i",acctid);
auto results = QueryDatabase(query);
@@ -1773,11 +1831,13 @@ uint8 Database::GetAgreementFlag(uint32 acctid) {
}
void Database::SetAgreementFlag(uint32 acctid) {
_eqp
std::string query = StringFormat("UPDATE account SET rulesflag=1 where id=%i", acctid);
QueryDatabase(query);
}
void Database::ClearRaid(uint32 rid) {
_eqp
if(rid == 0)
{
//clear all raids
@@ -1794,7 +1854,7 @@ void Database::ClearRaid(uint32 rid) {
}
void Database::ClearAllRaids(void) {
_eqp
std::string query("delete from raid_members");
auto results = QueryDatabase(query);
@@ -1804,7 +1864,7 @@ void Database::ClearAllRaids(void) {
void Database::ClearAllRaidDetails(void)
{
_eqp
std::string query("delete from raid_details");
auto results = QueryDatabase(query);
@@ -1813,7 +1873,7 @@ void Database::ClearAllRaidDetails(void)
}
void Database::ClearRaidDetails(uint32 rid) {
_eqp
if(rid == 0)
{
//clear all raids
@@ -1832,7 +1892,8 @@ void Database::ClearRaidDetails(uint32 rid) {
// returns 0 on error or no raid for that character, or
// the raid id that the character is a member of.
uint32 Database::GetRaidID(const char* name)
{
{
_eqp
std::string query = StringFormat("SELECT `raidid` FROM `raid_members` WHERE `name` = '%s'", name);
auto results = QueryDatabase(query);
@@ -1853,6 +1914,7 @@ uint32 Database::GetRaidID(const char* name)
const char* Database::GetRaidLeaderName(uint32 raid_id)
{
_eqp
// Would be a good idea to fix this to be a passed in variable and
// make the caller responsible. static local variables like this are
// not guaranteed to be thread safe (nor is the internal guard
@@ -1884,6 +1946,7 @@ const char* Database::GetRaidLeaderName(uint32 raid_id)
void Database::GetGroupLeadershipInfo(uint32 gid, uint32 rid, char *maintank,
char *assist, char *puller, char *marknpc, char *mentoree, int *mentor_percent, GroupLeadershipAA_Struct *GLAA)
{
_eqp
std::string query = StringFormat(
"SELECT maintank, assist, puller, marknpc, mentoree, mentor_percent, leadershipaa FROM raid_leaders WHERE gid = %lu AND rid = %lu",
(unsigned long)gid, (unsigned long)rid);
@@ -1941,6 +2004,7 @@ void Database::GetGroupLeadershipInfo(uint32 gid, uint32 rid, char *maintank,
void Database::GetRaidLeadershipInfo(uint32 rid, char *maintank,
char *assist, char *puller, char *marknpc, RaidLeadershipAA_Struct *RLAA)
{
_eqp
std::string query = StringFormat(
"SELECT maintank, assist, puller, marknpc, leadershipaa FROM raid_leaders WHERE gid = %lu AND rid = %lu",
(unsigned long)0xFFFFFFFF, (unsigned long)rid);
@@ -1984,7 +2048,8 @@ void Database::GetRaidLeadershipInfo(uint32 rid, char *maintank,
void Database::SetRaidGroupLeaderInfo(uint32 gid, uint32 rid)
{
std::string query = StringFormat("UPDATE raid_leaders SET leadershipaa = '', WHERE gid = %lu AND rid = %lu",
_eqp
std::string query = StringFormat("UPDATE raid_leaders SET leadershipaa = '' WHERE gid = %lu AND rid = %lu",
(unsigned long)gid, (unsigned long)rid);
auto results = QueryDatabase(query);
@@ -2001,6 +2066,7 @@ void Database::SetRaidGroupLeaderInfo(uint32 gid, uint32 rid)
// Clearing all raid leaders
void Database::ClearAllRaidLeaders(void)
{
_eqp
std::string query("DELETE from raid_leaders");
QueryDatabase(query);
return;
@@ -2008,6 +2074,7 @@ void Database::ClearAllRaidLeaders(void)
void Database::ClearRaidLeader(uint32 gid, uint32 rid)
{
_eqp
if (rid == 0) {
ClearAllRaidLeaders();
return;
@@ -2019,7 +2086,7 @@ void Database::ClearRaidLeader(uint32 gid, uint32 rid)
void Database::UpdateAdventureStatsEntry(uint32 char_id, uint8 theme, bool win)
{
_eqp
std::string field;
switch(theme)
@@ -2072,6 +2139,7 @@ void Database::UpdateAdventureStatsEntry(uint32 char_id, uint8 theme, bool win)
bool Database::GetAdventureStats(uint32 char_id, AdventureStats_Struct *as)
{
_eqp
std::string query = StringFormat(
"SELECT "
"`guk_wins`, "
@@ -2118,6 +2186,7 @@ bool Database::GetAdventureStats(uint32 char_id, AdventureStats_Struct *as)
uint32 Database::GetGuildIDByCharID(uint32 character_id)
{
_eqp
std::string query = StringFormat("SELECT guild_id FROM guild_members WHERE char_id='%i'", character_id);
auto results = QueryDatabase(query);
@@ -2133,6 +2202,7 @@ uint32 Database::GetGuildIDByCharID(uint32 character_id)
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings)
{
_eqp
std::string query =
"SELECT "
"log_category_id, "
@@ -2154,6 +2224,16 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings)
log_settings[log_category].log_to_file = atoi(row[3]);
log_settings[log_category].log_to_gmsay = atoi(row[4]);
/* Determine if any output method is enabled for the category
and set it to 1 so it can used to check if category is enabled */
const bool log_to_console = log_settings[log_category].log_to_console > 0;
const bool log_to_file = log_settings[log_category].log_to_file > 0;
const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0;
const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay;
if (is_category_enabled)
log_settings[log_category].is_category_enabled = 1;
/*
This determines whether or not the process needs to actually file log anything.
If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open
@@ -2162,4 +2242,4 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings)
Log.file_logs_enabled = true;
}
}
}
}
+5 -3
View File
@@ -110,7 +110,8 @@ MySQLRequestResult DBcore::QueryDatabase(const char* query, uint32 querylen, boo
/* Implement Logging at the Root */
if (mysql_errno(&mysql) > 0 && strlen(query) > 0){
Log.Out(Logs::General, Logs::MySQLError, "%i: %s \n %s", mysql_errno(&mysql), mysql_error(&mysql), query);
if (Log.log_settings[Logs::MySQLError].is_category_enabled == 1)
Log.Out(Logs::General, Logs::MySQLError, "%i: %s \n %s", mysql_errno(&mysql), mysql_error(&mysql), query);
}
return MySQLRequestResult(nullptr, 0, 0, 0, 0, mysql_errno(&mysql),errorBuffer);
@@ -125,8 +126,9 @@ MySQLRequestResult DBcore::QueryDatabase(const char* query, uint32 querylen, boo
rowCount = (uint32)mysql_num_rows(res);
MySQLRequestResult requestResult(res, (uint32)mysql_affected_rows(&mysql), rowCount, (uint32)mysql_field_count(&mysql), (uint32)mysql_insert_id(&mysql));
Log.Out(Logs::General, Logs::MySQLQuery, "%s (%u rows returned)", query, rowCount, requestResult.RowCount());
if (Log.log_settings[Logs::MySQLQuery].is_category_enabled == 1)
Log.Out(Logs::General, Logs::MySQLQuery, "%s (%u rows returned)", query, rowCount, requestResult.RowCount());
return requestResult;
}
+22
View File
@@ -50,6 +50,7 @@ EmuTCPConnection::EmuTCPConnection(uint32 ID, EmuTCPServer* iServer, SOCKET in_s
keepalive_timer(SERVER_TIMEOUT),
timeout_timer(SERVER_TIMEOUT * 2)
{
_eqp
id = 0;
Server = nullptr;
pOldFormat = iOldFormat;
@@ -76,6 +77,7 @@ EmuTCPConnection::EmuTCPConnection(bool iOldFormat, EmuTCPServer* iRelayServer,
keepalive_timer(SERVER_TIMEOUT),
timeout_timer(SERVER_TIMEOUT * 2)
{
_eqp
Server = iRelayServer;
if (Server)
RelayServer = true;
@@ -98,6 +100,7 @@ EmuTCPConnection::EmuTCPConnection(uint32 ID, EmuTCPServer* iServer, EmuTCPConne
keepalive_timer(SERVER_TIMEOUT),
timeout_timer(SERVER_TIMEOUT * 2)
{
_eqp
Server = iServer;
RelayLink = iRelayLink;
RelayServer = true;
@@ -117,6 +120,7 @@ EmuTCPConnection::~EmuTCPConnection() {
}
EmuTCPNetPacket_Struct* EmuTCPConnection::MakePacket(ServerPacket* pack, uint32 iDestination) {
_eqp
int32 size = sizeof(EmuTCPNetPacket_Struct) + pack->size;
if (pack->compressed) {
size += 4;
@@ -144,6 +148,7 @@ EmuTCPNetPacket_Struct* EmuTCPConnection::MakePacket(ServerPacket* pack, uint32
}
SPackSendQueue* EmuTCPConnection::MakeOldPacket(ServerPacket* pack) {
_eqp
SPackSendQueue* spsq = (SPackSendQueue*) new uchar[sizeof(SPackSendQueue) + pack->size + 4];
if (pack->pBuffer != 0 && pack->size != 0)
memcpy((char *) &spsq->buffer[4], (char *) pack->pBuffer, pack->size);
@@ -154,6 +159,7 @@ SPackSendQueue* EmuTCPConnection::MakeOldPacket(ServerPacket* pack) {
}
bool EmuTCPConnection::SendPacket(ServerPacket* pack, uint32 iDestination) {
_eqp
if (!Connected())
return false;
eTCPMode tmp = GetMode();
@@ -214,6 +220,7 @@ bool EmuTCPConnection::SendPacket(ServerPacket* pack, uint32 iDestination) {
}
bool EmuTCPConnection::SendPacket(EmuTCPNetPacket_Struct* tnps) {
_eqp
if (RemoteID)
return false;
if (!Connected())
@@ -254,6 +261,7 @@ bool EmuTCPConnection::SendPacket(EmuTCPNetPacket_Struct* tnps) {
}
ServerPacket* EmuTCPConnection::PopPacket() {
_eqp
ServerPacket* ret;
if (!MOutQueueLock.trylock())
return nullptr;
@@ -263,12 +271,14 @@ ServerPacket* EmuTCPConnection::PopPacket() {
}
void EmuTCPConnection::InModeQueuePush(EmuTCPNetPacket_Struct* tnps) {
_eqp
MSendQueue.lock();
InModeQueue.push(tnps);
MSendQueue.unlock();
}
void EmuTCPConnection::OutQueuePush(ServerPacket* pack) {
_eqp
MOutQueueLock.lock();
OutQueue.push(pack);
MOutQueueLock.unlock();
@@ -276,6 +286,7 @@ void EmuTCPConnection::OutQueuePush(ServerPacket* pack) {
bool EmuTCPConnection::LineOutQueuePush(char* line) {
_eqp
#if defined(GOTFRAGS) && 0
if (strcmp(line, "**CRASHME**") == 0) {
int i = 0;
@@ -369,6 +380,7 @@ bool EmuTCPConnection::LineOutQueuePush(char* line) {
}
void EmuTCPConnection::Disconnect(bool iSendRelayDisconnect) {
_eqp
TCPConnection::Disconnect();
if (RelayLink) {
@@ -378,6 +390,7 @@ void EmuTCPConnection::Disconnect(bool iSendRelayDisconnect) {
}
bool EmuTCPConnection::ConnectIP(uint32 irIP, uint16 irPort, char* errbuf) {
_eqp
if(!TCPConnection::ConnectIP(irIP, irPort, errbuf))
return(false);
@@ -432,6 +445,7 @@ bool EmuTCPConnection::ConnectIP(uint32 irIP, uint16 irPort, char* errbuf) {
}
void EmuTCPConnection::ClearBuffers() {
_eqp
TCPConnection::ClearBuffers();
LockMutex lock2(&MOutQueueLock);
@@ -448,6 +462,7 @@ void EmuTCPConnection::ClearBuffers() {
}
void EmuTCPConnection::SendNetErrorPacket(const char* reason) {
_eqp
#if TCPC_DEBUG >= 1
struct in_addr in;
in.s_addr = GetrIP();
@@ -469,6 +484,7 @@ void EmuTCPConnection::SendNetErrorPacket(const char* reason) {
}
void EmuTCPConnection::RemoveRelay(EmuTCPConnection* relay, bool iSendRelayDisconnect) {
_eqp
if (iSendRelayDisconnect) {
ServerPacket* pack = new ServerPacket(0, 5);
pack->pBuffer[0] = 3;
@@ -482,6 +498,7 @@ void EmuTCPConnection::RemoveRelay(EmuTCPConnection* relay, bool iSendRelayDisco
bool EmuTCPConnection::ProcessReceivedData(char* errbuf) {
_eqp
if (errbuf)
errbuf[0] = 0;
timeout_timer.Start();
@@ -505,6 +522,7 @@ bool EmuTCPConnection::ProcessReceivedData(char* errbuf) {
bool EmuTCPConnection::ProcessReceivedDataAsPackets(char* errbuf) {
_eqp
if (errbuf)
errbuf[0] = 0;
int32 base = 0;
@@ -621,6 +639,7 @@ bool EmuTCPConnection::ProcessReceivedDataAsPackets(char* errbuf) {
}
bool EmuTCPConnection::ProcessReceivedDataAsOldPackets(char* errbuf) {
_eqp
int32 base = 0;
int32 size = 4;
uchar* buffer;
@@ -695,6 +714,7 @@ bool EmuTCPConnection::ProcessReceivedDataAsOldPackets(char* errbuf) {
}
void EmuTCPConnection::ProcessNetworkLayerPacket(ServerPacket* pack) {
_eqp
uint8 opcode = pack->pBuffer[0];
uint8* data = &pack->pBuffer[1];
switch (opcode) {
@@ -780,6 +800,7 @@ void EmuTCPConnection::ProcessNetworkLayerPacket(ServerPacket* pack) {
}
bool EmuTCPConnection::SendData(bool &sent_something, char* errbuf) {
_eqp
sent_something = false;
if(!TCPConnection::SendData(sent_something, errbuf))
return(false);
@@ -799,6 +820,7 @@ bool EmuTCPConnection::SendData(bool &sent_something, char* errbuf) {
}
bool EmuTCPConnection::RecvData(char* errbuf) {
_eqp
if(!TCPConnection::RecvData(errbuf)) {
if (OutQueue.count())
return(true);
+8
View File
@@ -9,6 +9,7 @@ EmuTCPServer::EmuTCPServer(uint16 iPort, bool iOldFormat)
}
EmuTCPServer::~EmuTCPServer() {
_eqp
MInQueue.lock();
while(!m_InQueue.empty()) {
delete m_InQueue.front();
@@ -18,23 +19,27 @@ EmuTCPServer::~EmuTCPServer() {
}
void EmuTCPServer::Process() {
_eqp
CheckInQueue();
TCPServer<EmuTCPConnection>::Process();
}
void EmuTCPServer::CreateNewConnection(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 irPort)
{
_eqp
EmuTCPConnection *conn = new EmuTCPConnection(ID, this, in_socket, irIP, irPort, pOldFormat);
AddConnection(conn);
}
void EmuTCPServer::SendPacket(ServerPacket* pack) {
_eqp
EmuTCPNetPacket_Struct* tnps = EmuTCPConnection::MakePacket(pack);
SendPacket(&tnps);
}
void EmuTCPServer::SendPacket(EmuTCPNetPacket_Struct** tnps) {
_eqp
MInQueue.lock();
m_InQueue.push(*tnps);
MInQueue.unlock();
@@ -42,6 +47,7 @@ void EmuTCPServer::SendPacket(EmuTCPNetPacket_Struct** tnps) {
}
void EmuTCPServer::CheckInQueue() {
_eqp
EmuTCPNetPacket_Struct* tnps = 0;
while (( tnps = InQueuePop() )) {
@@ -57,6 +63,7 @@ void EmuTCPServer::CheckInQueue() {
}
EmuTCPNetPacket_Struct* EmuTCPServer::InQueuePop() {
_eqp
EmuTCPNetPacket_Struct* ret = nullptr;
MInQueue.lock();
if(!m_InQueue.empty()) {
@@ -69,6 +76,7 @@ EmuTCPNetPacket_Struct* EmuTCPServer::InQueuePop() {
EmuTCPConnection *EmuTCPServer::FindConnection(uint32 iID) {
_eqp
vitr cur, end;
cur = m_list.begin();
end = m_list.end();
+43 -76
View File
@@ -24,6 +24,7 @@
#include "platform.h"
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdio.h>
#ifndef STATIC_OPCODE
@@ -39,9 +40,11 @@ EQPacket::EQPacket(EmuOpcode op, const unsigned char *buf, uint32 len)
: BasePacket(buf, len),
emu_opcode(op)
{
_eqp
}
void EQPacket::build_raw_header_dump(char *buffer, uint16 seq) const {
_eqp
BasePacket::build_raw_header_dump(buffer, seq);
buffer += strlen(buffer);
@@ -50,17 +53,20 @@ void EQPacket::build_raw_header_dump(char *buffer, uint16 seq) const {
void EQPacket::DumpRawHeader(uint16 seq, FILE *to) const
{
_eqp
char buff[196];
build_raw_header_dump(buff, seq);
fprintf(to, "%s", buff);
}
void EQPacket::build_header_dump(char *buffer) const {
_eqp
sprintf(buffer, "[EmuOpCode 0x%04x Size=%u]", emu_opcode, size);
}
void EQPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{
_eqp
if (src_ip) {
std::string sIP,dIP;;
sIP=long2ip(src_ip);
@@ -75,6 +81,7 @@ void EQPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
void EQProtocolPacket::build_raw_header_dump(char *buffer, uint16 seq) const
{
_eqp
BasePacket::build_raw_header_dump(buffer, seq);
buffer += strlen(buffer);
@@ -83,6 +90,7 @@ void EQProtocolPacket::build_raw_header_dump(char *buffer, uint16 seq) const
void EQProtocolPacket::DumpRawHeader(uint16 seq, FILE *to) const
{
_eqp
char buff[196];
build_raw_header_dump(buff, seq);
fprintf(to, "%s", buff);
@@ -90,11 +98,13 @@ void EQProtocolPacket::DumpRawHeader(uint16 seq, FILE *to) const
void EQProtocolPacket::build_header_dump(char *buffer) const
{
_eqp
sprintf(buffer, "[ProtoOpCode 0x%04x Size=%u]",opcode,size);
}
void EQProtocolPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{
_eqp
if (src_ip) {
std::string sIP,dIP;;
sIP=long2ip(src_ip);
@@ -109,6 +119,7 @@ void EQProtocolPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
void EQApplicationPacket::build_raw_header_dump(char *buffer, uint16 seq) const
{
_eqp
BasePacket::build_raw_header_dump(buffer, seq);
buffer += strlen(buffer);
@@ -121,6 +132,7 @@ void EQApplicationPacket::build_raw_header_dump(char *buffer, uint16 seq) const
void EQApplicationPacket::DumpRawHeader(uint16 seq, FILE *to) const
{
_eqp
char buff[196];
build_raw_header_dump(buff, seq);
fprintf(to, "%s", buff);
@@ -128,6 +140,7 @@ void EQApplicationPacket::DumpRawHeader(uint16 seq, FILE *to) const
void EQApplicationPacket::build_header_dump(char *buffer) const
{
_eqp
#ifdef STATIC_OPCODE
sprintf(buffer, "[OpCode 0x%04x Size=%u]\n", emu_opcode,size);
#else
@@ -137,6 +150,7 @@ void EQApplicationPacket::build_header_dump(char *buffer) const
void EQApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{
_eqp
if (src_ip) {
std::string sIP,dIP;;
sIP=long2ip(src_ip);
@@ -155,6 +169,7 @@ void EQApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
void EQRawApplicationPacket::build_raw_header_dump(char *buffer, uint16 seq) const
{
_eqp
BasePacket::build_raw_header_dump(buffer, seq);
buffer += strlen(buffer);
@@ -167,6 +182,7 @@ void EQRawApplicationPacket::build_raw_header_dump(char *buffer, uint16 seq) con
void EQRawApplicationPacket::DumpRawHeader(uint16 seq, FILE *to) const
{
_eqp
char buff[196];
build_raw_header_dump(buff, seq);
fprintf(to, "%s", buff);
@@ -174,6 +190,7 @@ void EQRawApplicationPacket::DumpRawHeader(uint16 seq, FILE *to) const
void EQRawApplicationPacket::build_header_dump(char *buffer) const
{
_eqp
#ifdef STATIC_OPCODE
sprintf(buffer, "[OpCode 0x%04x (0x%04x) Size=%u]\n", emu_opcode, opcode,size);
#else
@@ -183,6 +200,7 @@ void EQRawApplicationPacket::build_header_dump(char *buffer) const
void EQRawApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
{
_eqp
if (src_ip) {
std::string sIP,dIP;;
sIP=long2ip(src_ip);
@@ -201,6 +219,7 @@ void EQRawApplicationPacket::DumpRawHeaderNoTime(uint16 seq, FILE *to) const
uint32 EQProtocolPacket::serialize(unsigned char *dest) const
{
_eqp
if (opcode>0xff) {
*(uint16 *)dest=opcode;
} else {
@@ -214,6 +233,7 @@ uint32 EQProtocolPacket::serialize(unsigned char *dest) const
uint32 EQApplicationPacket::serialize(uint16 opcode, unsigned char *dest) const
{
_eqp
uint8 OpCodeBytes = app_opcode_size;
if (app_opcode_size==1)
@@ -235,29 +255,10 @@ uint32 EQApplicationPacket::serialize(uint16 opcode, unsigned char *dest) const
return size+OpCodeBytes;
}
/*EQProtocolPacket::EQProtocolPacket(uint16 op, const unsigned char *buf, uint32 len)
: BasePacket(buf, len),
opcode(op)
{
uint32 offset;
opcode=ntohs(*(const uint16 *)buf);
offset=2;
if (len-offset) {
pBuffer= new unsigned char[len-offset];
memcpy(pBuffer,buf+offset,len-offset);
size=len-offset;
} else {
pBuffer=nullptr;
size=0;
}
OpMgr=&RawOpcodeManager;
}*/
bool EQProtocolPacket::combine(const EQProtocolPacket *rhs)
{
bool result=false;
_eqp
bool result=false;
if (opcode==OP_Combined && size+rhs->size+5<256) {
unsigned char *tmpbuffer=new unsigned char [size+rhs->size+3];
memcpy(tmpbuffer,pBuffer,size);
@@ -283,61 +284,12 @@ bool result=false;
}
return result;
}
/*
this is the code to do app-layer combining, instead of protocol layer.
this was taken out due to complex interactions with the opcode manager,
and will require a bit more thinking (likely moving into EQStream) to
get running again... but might be a good thing some day.
bool EQApplicationPacket::combine(const EQApplicationPacket *rhs)
{
uint32 newsize=0, offset=0;
unsigned char *tmpbuffer=nullptr;
if (opcode!=OP_AppCombined) {
newsize=app_opcode_size+size+(size>254?3:1)+app_opcode_size+rhs->size+(rhs->size>254?3:1);
tmpbuffer=new unsigned char [newsize];
offset=0;
if (size>254) {
tmpbuffer[offset++]=0xff;
*(uint16 *)(tmpbuffer+offset)=htons(size);
offset+=1;
} else {
tmpbuffer[offset++]=size;
}
offset+=serialize(tmpbuffer+offset);
} else {
newsize=size+app_opcode_size+rhs->size+(rhs->size>254?3:1);
tmpbuffer=new unsigned char [newsize];
memcpy(tmpbuffer,pBuffer,size);
offset=size;
}
if (rhs->size>254) {
tmpbuffer[offset++]=0xff;
*(uint16 *)(tmpbuffer+offset)=htons(rhs->size);
offset+=1;
} else {
tmpbuffer[offset++]=rhs->size;
}
offset+=rhs->serialize(tmpbuffer+offset);
size=offset;
opcode=OP_AppCombined;
delete[] pBuffer;
pBuffer=tmpbuffer;
return true;
}
*/
bool EQProtocolPacket::ValidateCRC(const unsigned char *buffer, int length, uint32 Key)
{
bool valid=false;
_eqp
bool valid=false;
// OP_SessionRequest, OP_SessionResponse, OP_OutOfSession are not CRC'd
if (buffer[0]==0x00 && (buffer[1]==OP_SessionRequest || buffer[1]==OP_SessionResponse || buffer[1]==OP_OutOfSession)) {
valid=true;
@@ -356,8 +308,9 @@ bool valid=false;
uint32 EQProtocolPacket::Decompress(const unsigned char *buffer, const uint32 length, unsigned char *newbuf, uint32 newbufsize)
{
uint32 newlen=0;
uint32 flag_offset=0;
_eqp
uint32 newlen=0;
uint32 flag_offset=0;
newbuf[0]=buffer[0];
if (buffer[0]==0x00) {
flag_offset=2;
@@ -381,7 +334,8 @@ uint32 flag_offset=0;
}
uint32 EQProtocolPacket::Compress(const unsigned char *buffer, const uint32 length, unsigned char *newbuf, uint32 newbufsize) {
uint32 flag_offset=1,newlength;
_eqp
uint32 flag_offset=1,newlength;
//dump_message_column(buffer,length,"Before: ");
newbuf[0]=buffer[0];
if (buffer[0]==0) {
@@ -404,6 +358,7 @@ uint32 flag_offset=1,newlength;
void EQProtocolPacket::ChatDecode(unsigned char *buffer, int size, int DecodeKey)
{
_eqp
if ((size >= 2) && buffer[1]!=0x01 && buffer[0]!=0x02 && buffer[0]!=0x1d) {
int Key=DecodeKey;
unsigned char *test=(unsigned char *)malloc(size);
@@ -429,6 +384,7 @@ void EQProtocolPacket::ChatDecode(unsigned char *buffer, int size, int DecodeKey
void EQProtocolPacket::ChatEncode(unsigned char *buffer, int size, int EncodeKey)
{
_eqp
if (buffer[1]!=0x01 && buffer[0]!=0x02 && buffer[0]!=0x1d) {
int Key=EncodeKey;
char *test=(char*)malloc(size);
@@ -452,10 +408,12 @@ void EQProtocolPacket::ChatEncode(unsigned char *buffer, int size, int EncodeKey
}
EQApplicationPacket *EQApplicationPacket::Copy() const {
_eqp
return(new EQApplicationPacket(*this));
}
EQRawApplicationPacket *EQProtocolPacket::MakeAppPacket() const {
_eqp
EQRawApplicationPacket *res = new EQRawApplicationPacket(opcode, pBuffer, size);
res->copyInfo(this);
return(res);
@@ -465,10 +423,13 @@ EQRawApplicationPacket::EQRawApplicationPacket(uint16 opcode, const unsigned cha
: EQApplicationPacket(OP_Unknown, buf, len),
opcode(opcode)
{
_eqp
}
EQRawApplicationPacket::EQRawApplicationPacket(const unsigned char *buf, const uint32 len)
: EQApplicationPacket(OP_Unknown, buf+sizeof(uint16), len-sizeof(uint16))
{
_eqp
if(GetExecutablePlatform() != ExePlatformUCS) {
opcode = *((const uint16 *) buf);
if(opcode == 0x0000)
@@ -502,11 +463,17 @@ EQRawApplicationPacket::EQRawApplicationPacket(const unsigned char *buf, const u
}
void DumpPacket(const EQApplicationPacket* app, bool iShowInfo) {
_eqp
if (iShowInfo) {
std::cout << "Dumping Applayer: 0x" << std::hex << std::setfill('0') << std::setw(4) << app->GetOpcode() << std::dec;
std::cout << " size:" << app->size << std::endl;
}
DumpPacketHex(app->pBuffer, app->size);
// DumpPacketAscii(app->pBuffer, app->size);
}
std::string DumpPacketToString(const EQApplicationPacket* app){
_eqp
std::ostringstream out;
out << DumpPacketHexToString(app->pBuffer, app->size);
return out.str();
}
+2 -1
View File
@@ -20,6 +20,7 @@
#include "base_packet.h"
#include "platform.h"
#include <iostream>
#ifdef STATIC_OPCODE
typedef unsigned short EmuOpcode;
@@ -146,6 +147,6 @@ protected:
};
extern void DumpPacket(const EQApplicationPacket* app, bool iShowInfo = false);
extern std::string DumpPacketToString(const EQApplicationPacket* app);
#endif
+108 -57
View File
@@ -23,6 +23,7 @@
#include "op_codes.h"
#include "crc16.h"
#include "platform.h"
#include "string_util.h"
#include <string>
#include <iomanip>
@@ -49,6 +50,7 @@
uint16 EQStream::MaxWindowSize=2048;
void EQStream::init(bool resetSession) {
_eqp
// we only reset these statistics if it is a 'new' connection
if ( resetSession )
{
@@ -91,6 +93,7 @@ void EQStream::init(bool resetSession) {
EQRawApplicationPacket *EQStream::MakeApplicationPacket(EQProtocolPacket *p)
{
_eqp
EQRawApplicationPacket *ap=nullptr;
Log.Out(Logs::Detail, Logs::Netcode, _L "Creating new application packet, length %d" __L, p->size);
// _raw(NET__APP_CREATE_HEX, 0xFFFF, p);
@@ -100,6 +103,7 @@ EQRawApplicationPacket *EQStream::MakeApplicationPacket(EQProtocolPacket *p)
EQRawApplicationPacket *EQStream::MakeApplicationPacket(const unsigned char *buf, uint32 len)
{
_eqp
EQRawApplicationPacket *ap=nullptr;
Log.Out(Logs::Detail, Logs::Netcode, _L "Creating new application packet, length %d" __L, len);
ap = new EQRawApplicationPacket(buf, len);
@@ -107,6 +111,7 @@ EQRawApplicationPacket *EQStream::MakeApplicationPacket(const unsigned char *buf
}
EQProtocolPacket *EQStream::MakeProtocolPacket(const unsigned char *buf, uint32 len) {
_eqp
uint16 proto_opcode = ntohs(*(const uint16 *)buf);
//advance over opcode.
@@ -118,6 +123,7 @@ EQProtocolPacket *EQStream::MakeProtocolPacket(const unsigned char *buf, uint32
void EQStream::ProcessPacket(EQProtocolPacket *p)
{
_eqp
uint32 processed=0, subpacket_length=0;
if (p == nullptr)
return;
@@ -515,6 +521,7 @@ void EQStream::ProcessPacket(EQProtocolPacket *p)
void EQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req)
{
_eqp
if(p == nullptr)
return;
@@ -526,6 +533,7 @@ void EQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req)
void EQStream::FastQueuePacket(EQApplicationPacket **p, bool ack_req)
{
_eqp
EQApplicationPacket *pack=*p;
*p = nullptr; //clear caller's pointer.. effectively takes ownership
@@ -555,9 +563,22 @@ void EQStream::FastQueuePacket(EQApplicationPacket **p, bool ack_req)
void EQStream::SendPacket(uint16 opcode, EQApplicationPacket *p)
{
uint32 chunksize,used;
_eqp
uint32 chunksize, used;
uint32 length;
if (Log.log_settings[Logs::Server_Client_Packet].is_category_enabled == 1){
if (p->GetOpcode() != OP_SpecialMesg){
Log.Out(Logs::General, Logs::Server_Client_Packet, "[%s - 0x%04x] [Size: %u]", OpcodeManager::EmuToName(p->GetOpcode()), p->GetOpcode(), p->Size());
}
}
if (Log.log_settings[Logs::Server_Client_Packet_With_Dump].is_category_enabled == 1){
if (p->GetOpcode() != OP_SpecialMesg){
Log.Out(Logs::General, Logs::Server_Client_Packet_With_Dump, "[%s - 0x%04x] [Size: %u] %s", OpcodeManager::EmuToName(p->GetOpcode()), p->GetOpcode(), p->Size(), DumpPacketToString(p).c_str());
}
}
// Convert the EQApplicationPacket to 1 or more EQProtocolPackets
if (p->size>(MaxLen-8)) { // proto-op(2), seq(2), app-op(2) ... data ... crc(2)
Log.Out(Logs::Detail, Logs::Netcode, _L "Making oversized packet, len %d" __L, p->size);
@@ -599,34 +620,36 @@ void EQStream::SendPacket(uint16 opcode, EQApplicationPacket *p)
void EQStream::SequencedPush(EQProtocolPacket *p)
{
_eqp
#ifdef COLLECTOR
delete p;
#else
MOutboundQueue.lock();
if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Pre-Push Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, SequencedBase, SequencedQueue.size(), NextOutSeq);
}
if(NextSequencedSend > SequencedQueue.size()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Pre-Push Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size());
}
if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Pre-Push Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, SequencedBase, SequencedQueue.size(), NextOutSeq);
}
if(NextSequencedSend > SequencedQueue.size()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Pre-Push Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size());
}
Log.Out(Logs::Detail, Logs::Netcode, _L "Pushing sequenced packet %d of length %d. Base Seq is %d." __L, NextOutSeq, p->size, SequencedBase);
*(uint16 *)(p->pBuffer)=htons(NextOutSeq);
SequencedQueue.push_back(p);
NextOutSeq++;
if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Push Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, SequencedBase, SequencedQueue.size(), NextOutSeq);
}
if(NextSequencedSend > SequencedQueue.size()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Push Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size());
}
if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Push Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, SequencedBase, SequencedQueue.size(), NextOutSeq);
}
if(NextSequencedSend > SequencedQueue.size()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Push Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size());
}
MOutboundQueue.unlock();
#endif
}
void EQStream::NonSequencedPush(EQProtocolPacket *p)
{
_eqp
#ifdef COLLECTOR
delete p;
#else
@@ -639,7 +662,8 @@ void EQStream::NonSequencedPush(EQProtocolPacket *p)
void EQStream::SendAck(uint16 seq)
{
uint16 Seq=htons(seq);
_eqp
uint16 Seq=htons(seq);
Log.Out(Logs::Detail, Logs::Netcode, _L "Sending ack with sequence %d" __L, seq);
SetLastAckSent(seq);
NonSequencedPush(new EQProtocolPacket(OP_Ack,(unsigned char *)&Seq,sizeof(uint16)));
@@ -647,8 +671,9 @@ uint16 Seq=htons(seq);
void EQStream::SendOutOfOrderAck(uint16 seq)
{
_eqp
Log.Out(Logs::Detail, Logs::Netcode, _L "Sending out of order ack with sequence %d" __L, seq);
uint16 Seq=htons(seq);
uint16 Seq=htons(seq);
NonSequencedPush(new EQProtocolPacket(OP_OutOfOrderAck,(unsigned char *)&Seq,sizeof(uint16)));
}
@@ -849,8 +874,9 @@ void EQStream::Write(int eq_fd)
void EQStream::WritePacket(int eq_fd, EQProtocolPacket *p)
{
uint32 length;
sockaddr_in address;
_eqp
uint32 length;
sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr=remote_ip;
address.sin_port=remote_port;
@@ -887,7 +913,8 @@ sockaddr_in address;
void EQStream::SendSessionResponse()
{
EQProtocolPacket *out=new EQProtocolPacket(OP_SessionResponse,nullptr,sizeof(SessionResponse));
_eqp
EQProtocolPacket *out=new EQProtocolPacket(OP_SessionResponse,nullptr,sizeof(SessionResponse));
SessionResponse *Response=(SessionResponse *)out->pBuffer;
Response->Session=htonl(Session);
Response->MaxLength=htonl(MaxLen);
@@ -909,7 +936,8 @@ EQProtocolPacket *out=new EQProtocolPacket(OP_SessionResponse,nullptr,sizeof(Ses
void EQStream::SendSessionRequest()
{
EQProtocolPacket *out=new EQProtocolPacket(OP_SessionRequest,nullptr,sizeof(SessionRequest));
_eqp
EQProtocolPacket *out=new EQProtocolPacket(OP_SessionRequest,nullptr,sizeof(SessionRequest));
SessionRequest *Request=(SessionRequest *)out->pBuffer;
memset(Request,0,sizeof(SessionRequest));
Request->Session=htonl(time(nullptr));
@@ -922,6 +950,7 @@ EQProtocolPacket *out=new EQProtocolPacket(OP_SessionRequest,nullptr,sizeof(Sess
void EQStream::_SendDisconnect()
{
_eqp
if(GetState() == CLOSED)
return;
@@ -934,6 +963,7 @@ void EQStream::_SendDisconnect()
void EQStream::InboundQueuePush(EQRawApplicationPacket *p)
{
_eqp
MInboundQueue.lock();
InboundQueue.push_back(p);
MInboundQueue.unlock();
@@ -941,7 +971,8 @@ void EQStream::InboundQueuePush(EQRawApplicationPacket *p)
EQApplicationPacket *EQStream::PopPacket()
{
EQRawApplicationPacket *p=nullptr;
_eqp
EQRawApplicationPacket *p=nullptr;
MInboundQueue.lock();
if (InboundQueue.size()) {
@@ -951,14 +982,12 @@ EQRawApplicationPacket *p=nullptr;
}
MInboundQueue.unlock();
//resolve the opcode if we can.
if(p) {
if(OpMgr != nullptr && *OpMgr != nullptr) {
if (p) {
if (OpMgr != nullptr && *OpMgr != nullptr) {
EmuOpcode emu_op = (*OpMgr)->EQToEmu(p->opcode);
if (emu_op == OP_Unknown) {
Log.Out(Logs::General, Logs::Netcode, "[ERROR] Unable to convert EQ opcode 0x%.4x to an Application opcode.", p->opcode);
}
// Log.Out(Logs::General, Logs::Client_Server_Packet_Unhandled, "Unknown :: [%s - 0x%04x] [Size: %u] %s", OpcodeManager::EmuToName(p->GetOpcode()), p->opcode, p->Size(), DumpPacketToString(p).c_str());
}
p->SetOpcode(emu_op);
}
}
@@ -968,7 +997,8 @@ EQRawApplicationPacket *p=nullptr;
EQRawApplicationPacket *EQStream::PopRawPacket()
{
EQRawApplicationPacket *p=nullptr;
_eqp
EQRawApplicationPacket *p=nullptr;
MInboundQueue.lock();
if (InboundQueue.size()) {
@@ -995,7 +1025,8 @@ EQRawApplicationPacket *p=nullptr;
EQRawApplicationPacket *EQStream::PeekPacket()
{
EQRawApplicationPacket *p=nullptr;
_eqp
EQRawApplicationPacket *p=nullptr;
MInboundQueue.lock();
if (InboundQueue.size()) {
@@ -1009,7 +1040,8 @@ EQRawApplicationPacket *p=nullptr;
void EQStream::InboundQueueClear()
{
EQApplicationPacket *p=nullptr;
_eqp
EQApplicationPacket *p=nullptr;
Log.Out(Logs::Detail, Logs::Netcode, _L "Clearing inbound queue" __L);
@@ -1027,7 +1059,8 @@ EQApplicationPacket *p=nullptr;
bool EQStream::HasOutgoingData()
{
bool flag;
_eqp
bool flag;
//once closed, we have nothing more to say
if(CheckClosed())
@@ -1052,7 +1085,8 @@ bool flag;
void EQStream::OutboundQueueClear()
{
EQProtocolPacket *p=nullptr;
_eqp
EQProtocolPacket *p=nullptr;
Log.Out(Logs::Detail, Logs::Netcode, _L "Clearing outbound queue" __L);
@@ -1074,7 +1108,8 @@ EQProtocolPacket *p=nullptr;
void EQStream::PacketQueueClear()
{
EQProtocolPacket *p=nullptr;
_eqp
EQProtocolPacket *p=nullptr;
Log.Out(Logs::Detail, Logs::Netcode, _L "Clearing future packet queue" __L);
@@ -1090,8 +1125,9 @@ EQProtocolPacket *p=nullptr;
void EQStream::Process(const unsigned char *buffer, const uint32 length)
{
static unsigned char newbuffer[2048];
uint32 newlength=0;
_eqp
static unsigned char newbuffer[2048];
uint32 newlength=0;
if (EQProtocolPacket::ValidateCRC(buffer,length,Key)) {
if (compressed) {
newlength=EQProtocolPacket::Decompress(buffer,length,newbuffer,2048);
@@ -1114,6 +1150,7 @@ uint32 newlength=0;
long EQStream::GetNextAckToSend()
{
_eqp
MAcks.lock();
long l=NextAckToSend;
MAcks.unlock();
@@ -1123,6 +1160,7 @@ long EQStream::GetNextAckToSend()
long EQStream::GetLastAckSent()
{
_eqp
MAcks.lock();
long l=LastAckSent;
MAcks.unlock();
@@ -1132,16 +1170,17 @@ long EQStream::GetLastAckSent()
void EQStream::AckPackets(uint16 seq)
{
std::deque<EQProtocolPacket *>::iterator itr, tmp;
_eqp
std::deque<EQProtocolPacket *>::iterator itr, tmp;
MOutboundQueue.lock();
//do a bit of sanity checking.
if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Pre-Ack Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, SequencedBase, SequencedQueue.size(), NextOutSeq);
}
if(NextSequencedSend > SequencedQueue.size()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Pre-Ack Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size());
}
//do a bit of sanity checking.
if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Pre-Ack Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, SequencedBase, SequencedQueue.size(), NextOutSeq);
}
if(NextSequencedSend > SequencedQueue.size()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Pre-Ack Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size());
}
SeqOrder ord = CompareSequence(SequencedBase, seq);
if(ord == SeqInOrder) {
@@ -1157,12 +1196,12 @@ if(NextSequencedSend > SequencedQueue.size()) {
//this is a good ack, we get to ack some blocks.
seq++; //we stop at the block right after their ack, counting on the wrap of both numbers.
while(SequencedBase != seq) {
if(SequencedQueue.empty()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "OUT OF PACKETS acked packet with sequence %lu. Next send is %d before this." __L, (unsigned long)SequencedBase, NextSequencedSend);
SequencedBase = NextOutSeq;
NextSequencedSend = 0;
break;
}
if(SequencedQueue.empty()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "OUT OF PACKETS acked packet with sequence %lu. Next send is %d before this." __L, (unsigned long)SequencedBase, NextSequencedSend);
SequencedBase = NextOutSeq;
NextSequencedSend = 0;
break;
}
Log.Out(Logs::Detail, Logs::Netcode, _L "Removing acked packet with sequence %lu. Next send is %d before this." __L, (unsigned long)SequencedBase, NextSequencedSend);
//clean out the acked packet
delete SequencedQueue.front();
@@ -1173,12 +1212,12 @@ Log.Out(Logs::Detail, Logs::Netcode, _L "OUT OF PACKETS acked packet with sequen
//advance the base sequence number to the seq of the block after the one we just got rid of.
SequencedBase++;
}
if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Post-Ack on %d Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, seq, SequencedBase, SequencedQueue.size(), NextOutSeq);
}
if(NextSequencedSend > SequencedQueue.size()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Post-Ack Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size());
}
if(uint16(SequencedBase + SequencedQueue.size()) != NextOutSeq) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Post-Ack on %d Invalid Sequenced queue: BS %d + SQ %d != NOS %d" __L, seq, SequencedBase, SequencedQueue.size(), NextOutSeq);
}
if(NextSequencedSend > SequencedQueue.size()) {
Log.Out(Logs::Detail, Logs::Netcode, _L "Post-Ack Next Send Sequence is beyond the end of the queue NSS %d > SQ %d" __L, NextSequencedSend, SequencedQueue.size());
}
}
MOutboundQueue.unlock();
@@ -1186,6 +1225,7 @@ if(NextSequencedSend > SequencedQueue.size()) {
void EQStream::SetNextAckToSend(uint32 seq)
{
_eqp
MAcks.lock();
Log.Out(Logs::Detail, Logs::Netcode, _L "Set Next Ack To Send to %lu" __L, (unsigned long)seq);
NextAckToSend=seq;
@@ -1194,6 +1234,7 @@ void EQStream::SetNextAckToSend(uint32 seq)
void EQStream::SetLastAckSent(uint32 seq)
{
_eqp
MAcks.lock();
Log.Out(Logs::Detail, Logs::Netcode, _L "Set Last Ack Sent to %lu" __L, (unsigned long)seq);
LastAckSent=seq;
@@ -1202,6 +1243,7 @@ void EQStream::SetLastAckSent(uint32 seq)
void EQStream::ProcessQueue()
{
_eqp
if(PacketQueue.empty()) {
return;
}
@@ -1217,8 +1259,9 @@ void EQStream::ProcessQueue()
EQProtocolPacket *EQStream::RemoveQueue(uint16 seq)
{
std::map<unsigned short,EQProtocolPacket *>::iterator itr;
EQProtocolPacket *qp=nullptr;
_eqp
std::map<unsigned short,EQProtocolPacket *>::iterator itr;
EQProtocolPacket *qp=nullptr;
if ((itr=PacketQueue.find(seq))!=PacketQueue.end()) {
qp=itr->second;
PacketQueue.erase(itr);
@@ -1229,6 +1272,7 @@ EQProtocolPacket *qp=nullptr;
void EQStream::SetStreamType(EQStreamType type)
{
_eqp
Log.Out(Logs::Detail, Logs::Netcode, _L "Changing stream type from %s to %s" __L, StreamTypeString(StreamType), StreamTypeString(type));
StreamType=type;
switch (StreamType) {
@@ -1259,6 +1303,7 @@ void EQStream::SetStreamType(EQStreamType type)
const char *EQStream::StreamTypeString(EQStreamType t)
{
_eqp
switch (t) {
case LoginStream:
return "Login";
@@ -1288,6 +1333,7 @@ const char *EQStream::StreamTypeString(EQStreamType t)
//returns SeqFuture if `seq` is later than `expected_seq`
EQStream::SeqOrder EQStream::CompareSequence(uint16 expected_seq , uint16 seq)
{
_eqp
if (expected_seq==seq) {
// Curent
return SeqInOrder;
@@ -1301,6 +1347,7 @@ EQStream::SeqOrder EQStream::CompareSequence(uint16 expected_seq , uint16 seq)
}
void EQStream::SetState(EQStreamState state) {
_eqp
MState.lock();
Log.Out(Logs::Detail, Logs::Netcode, _L "Changing state from %d to %d" __L, State, state);
State=state;
@@ -1309,7 +1356,7 @@ void EQStream::SetState(EQStreamState state) {
void EQStream::CheckTimeout(uint32 now, uint32 timeout) {
_eqp
bool outgoing_data = HasOutgoingData(); //up here to avoid recursive locking
EQStreamState orig_state = GetState();
@@ -1348,6 +1395,7 @@ void EQStream::CheckTimeout(uint32 now, uint32 timeout) {
void EQStream::Decay()
{
_eqp
MRate.lock();
uint32 rate=DecayRate;
MRate.unlock();
@@ -1360,6 +1408,7 @@ void EQStream::Decay()
void EQStream::AdjustRates(uint32 average_delta)
{
_eqp
if(GetExecutablePlatform() == ExePlatformWorld || GetExecutablePlatform() == ExePlatformZone) {
if (average_delta && (average_delta <= AVERAGE_DELTA_MAX)) {
MRate.lock();
@@ -1385,6 +1434,7 @@ void EQStream::AdjustRates(uint32 average_delta)
}
void EQStream::Close() {
_eqp
if(HasOutgoingData()) {
//there is pending data, wait for it to go out.
Log.Out(Logs::Detail, Logs::Netcode, _L "Stream requested to Close(), but there is pending data, waiting for it." __L);
@@ -1401,6 +1451,7 @@ void EQStream::Close() {
//this could be expanded to check more than the fitst opcode if
//we needed more complex matching
EQStream::MatchState EQStream::CheckSignature(const Signature *sig) {
_eqp
EQRawApplicationPacket *p = nullptr;
MatchState res = MatchNotReady;
+13 -3
View File
@@ -23,7 +23,8 @@
ThreadReturnType EQStreamFactoryReaderLoop(void *eqfs)
{
EQStreamFactory *fs=(EQStreamFactory *)eqfs;
_eqp
EQStreamFactory *fs = (EQStreamFactory*)eqfs;
#ifndef WIN32
Log.Out(Logs::Detail, Logs::None, "Starting EQStreamFactoryReaderLoop with thread ID %d", pthread_self());
@@ -40,7 +41,8 @@ EQStreamFactory *fs=(EQStreamFactory *)eqfs;
ThreadReturnType EQStreamFactoryWriterLoop(void *eqfs)
{
EQStreamFactory *fs=(EQStreamFactory *)eqfs;
_eqp
EQStreamFactory *fs = (EQStreamFactory*)eqfs;
#ifndef WIN32
Log.Out(Logs::Detail, Logs::None, "Starting EQStreamFactoryWriterLoop with thread ID %d", pthread_self());
@@ -58,6 +60,7 @@ ThreadReturnType EQStreamFactoryWriterLoop(void *eqfs)
EQStreamFactory::EQStreamFactory(EQStreamType type, int port, uint32 timeout)
: Timeoutable(5000), stream_timeout(timeout)
{
_eqp
StreamType=type;
Port=port;
sock=-1;
@@ -65,6 +68,7 @@ EQStreamFactory::EQStreamFactory(EQStreamType type, int port, uint32 timeout)
void EQStreamFactory::Close()
{
_eqp
Stop();
#ifdef _WINDOWS
@@ -77,7 +81,8 @@ void EQStreamFactory::Close()
bool EQStreamFactory::Open()
{
struct sockaddr_in address;
_eqp
struct sockaddr_in address;
#ifndef WIN32
pthread_t t1,t2;
#endif
@@ -118,6 +123,7 @@ struct sockaddr_in address;
std::shared_ptr<EQStream> EQStreamFactory::Pop()
{
_eqp
std::shared_ptr<EQStream> s = nullptr;
MNewStreams.lock();
if (NewStreams.size()) {
@@ -132,6 +138,7 @@ std::shared_ptr<EQStream> EQStreamFactory::Pop()
void EQStreamFactory::Push(std::shared_ptr<EQStream> s)
{
_eqp
MNewStreams.lock();
NewStreams.push(s);
MNewStreams.unlock();
@@ -139,6 +146,7 @@ void EQStreamFactory::Push(std::shared_ptr<EQStream> s)
void EQStreamFactory::ReaderLoop()
{
_eqp
fd_set readset;
std::map<std::pair<uint32, uint16>, std::shared_ptr<EQStream>>::iterator stream_itr;
int num;
@@ -216,6 +224,7 @@ void EQStreamFactory::ReaderLoop()
void EQStreamFactory::CheckTimeout()
{
_eqp
//lock streams the entire time were checking timeouts, it should be fast.
MStreams.lock();
@@ -250,6 +259,7 @@ void EQStreamFactory::CheckTimeout()
void EQStreamFactory::WriterLoop()
{
_eqp
std::map<std::pair<uint32, uint16>, std::shared_ptr<EQStream>>::iterator stream_itr;
bool havework=true;
std::vector<std::shared_ptr<EQStream>> wants_write;
+11
View File
@@ -28,6 +28,7 @@ EQEmuConfig *EQEmuConfig::_config = nullptr;
void EQEmuConfig::do_world(TiXmlElement *ele)
{
_eqp
const char *text;
TiXmlElement * sub_ele;;
text = ParseTextBlock(ele, "shortname");
@@ -145,6 +146,7 @@ void EQEmuConfig::do_world(TiXmlElement *ele)
void EQEmuConfig::do_chatserver(TiXmlElement *ele)
{
_eqp
const char *text;
text = ParseTextBlock(ele, "host", true);
if (text) {
@@ -158,6 +160,7 @@ void EQEmuConfig::do_chatserver(TiXmlElement *ele)
void EQEmuConfig::do_mailserver(TiXmlElement *ele)
{
_eqp
const char *text;
text = ParseTextBlock(ele, "host", true);
if (text) {
@@ -171,6 +174,7 @@ void EQEmuConfig::do_mailserver(TiXmlElement *ele)
void EQEmuConfig::do_database(TiXmlElement *ele)
{
_eqp
const char *text;
text = ParseTextBlock(ele, "host", true);
if (text) {
@@ -197,6 +201,7 @@ void EQEmuConfig::do_database(TiXmlElement *ele)
void EQEmuConfig::do_qsdatabase(TiXmlElement *ele)
{
_eqp
const char *text;
text = ParseTextBlock(ele, "host", true);
if (text) {
@@ -222,6 +227,7 @@ void EQEmuConfig::do_qsdatabase(TiXmlElement *ele)
void EQEmuConfig::do_zones(TiXmlElement *ele)
{
_eqp
const char *text;
TiXmlElement *sub_ele;
// TiXmlNode *node,*sub_node;
@@ -245,6 +251,7 @@ void EQEmuConfig::do_zones(TiXmlElement *ele)
void EQEmuConfig::do_files(TiXmlElement *ele)
{
_eqp
const char *text;
text = ParseTextBlock(ele, "spells", true);
if (text) {
@@ -262,6 +269,7 @@ void EQEmuConfig::do_files(TiXmlElement *ele)
void EQEmuConfig::do_directories(TiXmlElement *ele)
{
_eqp
const char *text;
text = ParseTextBlock(ele, "maps", true);
if (text) {
@@ -279,6 +287,7 @@ void EQEmuConfig::do_directories(TiXmlElement *ele)
void EQEmuConfig::do_launcher(TiXmlElement *ele)
{
_eqp
const char *text;
TiXmlElement *sub_ele;
text = ParseTextBlock(ele, "logprefix", true);
@@ -318,6 +327,7 @@ void EQEmuConfig::do_launcher(TiXmlElement *ele)
std::string EQEmuConfig::GetByName(const std::string &var_name) const
{
_eqp
if (var_name == "ShortName") {
return (ShortName);
}
@@ -445,6 +455,7 @@ std::string EQEmuConfig::GetByName(const std::string &var_name) const
void EQEmuConfig::Dump() const
{
_eqp
std::cout << "ShortName = " << ShortName << std::endl;
std::cout << "LongName = " << LongName << std::endl;
std::cout << "WorldAddress = " << WorldAddress << std::endl;
+6 -3
View File
@@ -96,6 +96,7 @@ void EQEmuLogSys::LoadLogSettingsDefaults()
memset(log_settings, 0, sizeof(LogSettings) * Logs::LogCategory::MaxCategoryID);
/* Set Defaults */
log_settings[Logs::LoginServer].log_to_console = Logs::General;
log_settings[Logs::World_Server].log_to_console = Logs::General;
log_settings[Logs::Zone_Server].log_to_console = Logs::General;
log_settings[Logs::QS_Server].log_to_console = Logs::General;
@@ -116,7 +117,7 @@ void EQEmuLogSys::LoadLogSettingsDefaults()
platform_file_name = "ucs";
else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformLogin)
platform_file_name = "login";
else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformLogin)
else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformLaunch)
platform_file_name = "launcher";
}
@@ -272,12 +273,14 @@ void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category,
void EQEmuLogSys::Out(Logs::DebugLevel debug_level, uint16 log_category, std::string message, ...)
{
_eqp
const bool log_to_console = log_settings[log_category].log_to_console > 0;
const bool log_to_file = log_settings[log_category].log_to_file > 0;
const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0;
const bool nothing_to_log = !log_to_console && !log_to_file && !log_to_gmsay;
if (nothing_to_log) return;
if (nothing_to_log)
return;
va_list args;
va_start(args, message);
@@ -288,7 +291,7 @@ void EQEmuLogSys::Out(Logs::DebugLevel debug_level, uint16 log_category, std::st
if (log_to_console) EQEmuLogSys::ProcessConsoleMessage(debug_level, log_category, output_debug_message);
if (log_to_gmsay) EQEmuLogSys::ProcessGMSay(debug_level, log_category, output_debug_message);
if (log_to_file) EQEmuLogSys::ProcessLogWrite(debug_level, log_category, output_message);
if (log_to_file) EQEmuLogSys::ProcessLogWrite(debug_level, log_category, output_debug_message);
}
void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp)
+17 -4
View File
@@ -48,12 +48,14 @@ namespace Logs {
Combat,
Commands,
Crash,
Database,
Debug,
Doors,
Error,
Guilds,
Inventory,
Launcher,
LoginServer,
Netcode,
Normal,
Object,
@@ -78,6 +80,10 @@ namespace Logs {
MySQLQuery,
Mercenaries,
QuestDebug,
Server_Client_Packet,
Client_Server_Packet_Unhandled,
Server_Client_Packet_With_Dump,
Client_Server_Packet_With_Dump,
MaxCategoryID /* Don't Remove this*/
};
@@ -88,16 +94,18 @@ namespace Logs {
"AI",
"Aggro",
"Attack",
"Client Server Packet",
"Packet :: Client -> Server",
"Combat",
"Commands",
"Crash",
"Database",
"Debug",
"Doors",
"Error",
"Guilds",
"Inventory",
"Launcher",
"LoginServer",
"Netcode",
"Normal",
"Object",
@@ -118,10 +126,14 @@ namespace Logs {
"WebInterface Server",
"World Server",
"Zone Server",
"MySQL Error",
"MySQL Query",
"MySQLError",
"MySQLQuery",
"Mercenaries",
"Quest Debug"
"Quest Debug",
"Packet :: Server -> Client",
"Packet :: Client -> Server Unhandled",
"Packet :: Server -> Client (Dump)",
"Packet :: Client -> Server (Dump)",
};
}
@@ -160,6 +172,7 @@ public:
uint8 log_to_file;
uint8 log_to_console;
uint8 log_to_gmsay;
uint8 is_category_enabled; /* When any log output in a category > 0, set this to 1 as (Enabled) */
};
/* Internally used memory reference for all log settings per category.
+1
View File
@@ -26,6 +26,7 @@ void InitExtendedProfile(ExtendedProfile_Struct *p) {
}
bool SetExtendedProfile(ExtendedProfile_Struct *to, char *old, unsigned int len) {
_eqp
if(len == 0 || old == nullptr) {
//handle old chars without an extended profile...
InitExtendedProfile(to);
+4
View File
@@ -21,6 +21,7 @@
const char *FactionValueToString(FACTION_VALUE fv)
{
_eqp
switch (fv) {
case FACTION_ALLY:
return ("Ally");
@@ -55,6 +56,7 @@ const char *FactionValueToString(FACTION_VALUE fv)
//o--------------------------------------------------------------
FACTION_VALUE CalculateFaction(FactionMods* fm, int32 tmpCharacter_value)
{
_eqp
int32 character_value = tmpCharacter_value;
if (fm) {
character_value += fm->base + fm->class_mod + fm->race_mod + fm->deity_mod;
@@ -92,6 +94,7 @@ FACTION_VALUE CalculateFaction(FactionMods* fm, int32 tmpCharacter_value)
// this function should check if some races have more than one race define
bool IsOfEqualRace(int r1, int r2)
{
_eqp
if (r1 == r2) {
return true;
}
@@ -113,6 +116,7 @@ bool IsOfEqualRace(int r1, int r2)
// trolls endure ogres, dark elves, ...
bool IsOfIndiffRace(int r1, int r2)
{
_eqp
if (r1 == r2) {
return true;
}
+57 -3
View File
@@ -39,10 +39,8 @@ BaseGuildManager::~BaseGuildManager() {
ClearGuilds();
}
bool BaseGuildManager::LoadGuilds() {
_eqp
ClearGuilds();
if(m_db == nullptr) {
@@ -104,6 +102,7 @@ bool BaseGuildManager::LoadGuilds() {
}
bool BaseGuildManager::RefreshGuild(uint32 guild_id) {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested to refresh guild %d when we have no database object.", guild_id);
return(false);
@@ -169,6 +168,7 @@ bool BaseGuildManager::RefreshGuild(uint32 guild_id) {
BaseGuildManager::GuildInfo *BaseGuildManager::_CreateGuild(uint32 guild_id, const char *guild_name, uint32 leader_char_id, uint8 minstatus, const char *guild_motd, const char *motd_setter, const char *Channel, const char *URL)
{
_eqp
std::map<uint32, GuildInfo *>::iterator res;
//remove any old entry.
@@ -213,6 +213,7 @@ BaseGuildManager::GuildInfo *BaseGuildManager::_CreateGuild(uint32 guild_id, con
}
bool BaseGuildManager::_StoreGuildDB(uint32 guild_id) {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested to store guild %d when we have no database object.", guild_id);
return(false);
@@ -295,6 +296,7 @@ bool BaseGuildManager::_StoreGuildDB(uint32 guild_id) {
}
uint32 BaseGuildManager::_GetFreeGuildID() {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested find a free guild ID when we have no database object.");
return(GUILD_NONE);
@@ -342,6 +344,7 @@ uint32 BaseGuildManager::_GetFreeGuildID() {
uint32 BaseGuildManager::CreateGuild(const char* name, uint32 leader_char_id) {
_eqp
uint32 gid = DBCreateGuild(name, leader_char_id);
if(gid == GUILD_NONE)
return(GUILD_NONE);
@@ -353,6 +356,7 @@ uint32 BaseGuildManager::CreateGuild(const char* name, uint32 leader_char_id) {
}
bool BaseGuildManager::DeleteGuild(uint32 guild_id) {
_eqp
if(!DBDeleteGuild(guild_id))
return(false);
@@ -362,6 +366,7 @@ bool BaseGuildManager::DeleteGuild(uint32 guild_id) {
}
bool BaseGuildManager::RenameGuild(uint32 guild_id, const char* name) {
_eqp
if(!DBRenameGuild(guild_id, name))
return(false);
@@ -371,6 +376,7 @@ bool BaseGuildManager::RenameGuild(uint32 guild_id, const char* name) {
}
bool BaseGuildManager::SetGuildLeader(uint32 guild_id, uint32 leader_char_id) {
_eqp
//get old leader first.
std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id);
@@ -390,6 +396,7 @@ bool BaseGuildManager::SetGuildLeader(uint32 guild_id, uint32 leader_char_id) {
}
bool BaseGuildManager::SetGuildMOTD(uint32 guild_id, const char* motd, const char *setter) {
_eqp
if(!DBSetGuildMOTD(guild_id, motd, setter))
return(false);
@@ -400,6 +407,7 @@ bool BaseGuildManager::SetGuildMOTD(uint32 guild_id, const char* motd, const cha
bool BaseGuildManager::SetGuildURL(uint32 GuildID, const char* URL)
{
_eqp
if(!DBSetGuildURL(GuildID, URL))
return(false);
@@ -410,6 +418,7 @@ bool BaseGuildManager::SetGuildURL(uint32 GuildID, const char* URL)
bool BaseGuildManager::SetGuildChannel(uint32 GuildID, const char* Channel)
{
_eqp
if(!DBSetGuildChannel(GuildID, Channel))
return(false);
@@ -419,6 +428,7 @@ bool BaseGuildManager::SetGuildChannel(uint32 GuildID, const char* Channel)
}
bool BaseGuildManager::SetGuild(uint32 charid, uint32 guild_id, uint8 rank) {
_eqp
if(rank > GUILD_MAX_RANK && guild_id != GUILD_NONE)
return(false);
@@ -439,6 +449,7 @@ bool BaseGuildManager::SetGuild(uint32 charid, uint32 guild_id, uint8 rank) {
//changes rank, but not guild.
bool BaseGuildManager::SetGuildRank(uint32 charid, uint8 rank) {
_eqp
if(rank > GUILD_MAX_RANK)
return(false);
@@ -452,6 +463,7 @@ bool BaseGuildManager::SetGuildRank(uint32 charid, uint8 rank) {
bool BaseGuildManager::SetBankerFlag(uint32 charid, bool is_banker) {
_eqp
if(!DBSetBankerFlag(charid, is_banker))
return(false);
@@ -461,12 +473,14 @@ bool BaseGuildManager::SetBankerFlag(uint32 charid, bool is_banker) {
}
bool BaseGuildManager::ForceRankUpdate(uint32 charid) {
_eqp
SendRankUpdate(charid);
return(true);
}
bool BaseGuildManager::SetAltFlag(uint32 charid, bool is_alt)
{
_eqp
if(!DBSetAltFlag(charid, is_alt))
return(false);
@@ -476,6 +490,7 @@ bool BaseGuildManager::SetAltFlag(uint32 charid, bool is_alt)
}
bool BaseGuildManager::SetTributeFlag(uint32 charid, bool enabled) {
_eqp
if(!DBSetTributeFlag(charid, enabled))
return(false);
@@ -485,6 +500,7 @@ bool BaseGuildManager::SetTributeFlag(uint32 charid, bool enabled) {
}
bool BaseGuildManager::SetPublicNote(uint32 charid, const char *note) {
_eqp
if(!DBSetPublicNote(charid, note))
return(false);
@@ -494,6 +510,7 @@ bool BaseGuildManager::SetPublicNote(uint32 charid, const char *note) {
}
uint32 BaseGuildManager::DBCreateGuild(const char* name, uint32 leader) {
_eqp
//first try to find a free ID.
uint32 new_id = _GetFreeGuildID();
if(new_id == GUILD_NONE)
@@ -515,6 +532,7 @@ uint32 BaseGuildManager::DBCreateGuild(const char* name, uint32 leader) {
}
bool BaseGuildManager::DBDeleteGuild(uint32 guild_id) {
_eqp
//remove the local entry
std::map<uint32, GuildInfo *>::iterator res;
@@ -551,6 +569,7 @@ bool BaseGuildManager::DBDeleteGuild(uint32 guild_id) {
}
bool BaseGuildManager::DBRenameGuild(uint32 guild_id, const char* name) {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested to rename guild %d when we have no database object.", guild_id);
return false;
@@ -587,6 +606,7 @@ bool BaseGuildManager::DBRenameGuild(uint32 guild_id, const char* name) {
}
bool BaseGuildManager::DBSetGuildLeader(uint32 guild_id, uint32 leader) {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested to set the leader for guild %d when we have no database object.", guild_id);
return false;
@@ -622,6 +642,7 @@ bool BaseGuildManager::DBSetGuildLeader(uint32 guild_id, uint32 leader) {
}
bool BaseGuildManager::DBSetGuildMOTD(uint32 guild_id, const char* motd, const char *setter) {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested to set the MOTD for guild %d when we have no database object.", guild_id);
return(false);
@@ -664,6 +685,7 @@ bool BaseGuildManager::DBSetGuildMOTD(uint32 guild_id, const char* motd, const c
bool BaseGuildManager::DBSetGuildURL(uint32 GuildID, const char* URL)
{
_eqp
if(m_db == nullptr)
return false;
@@ -697,6 +719,7 @@ bool BaseGuildManager::DBSetGuildURL(uint32 GuildID, const char* URL)
bool BaseGuildManager::DBSetGuildChannel(uint32 GuildID, const char* Channel)
{
_eqp
if(m_db == nullptr)
return(false);
@@ -730,6 +753,7 @@ bool BaseGuildManager::DBSetGuildChannel(uint32 GuildID, const char* Channel)
}
bool BaseGuildManager::DBSetGuild(uint32 charid, uint32 guild_id, uint8 rank) {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested to set char to guild %d when we have no database object.", guild_id);
return(false);
@@ -758,11 +782,13 @@ bool BaseGuildManager::DBSetGuild(uint32 charid, uint32 guild_id, uint8 rank) {
}
bool BaseGuildManager::DBSetGuildRank(uint32 charid, uint8 rank) {
_eqp
std::string query = StringFormat("UPDATE guild_members SET rank=%d WHERE char_id=%d", rank, charid);
return(QueryWithLogging(query, "setting a guild member's rank"));
}
bool BaseGuildManager::DBSetBankerFlag(uint32 charid, bool is_banker) {
_eqp
std::string query = StringFormat("UPDATE guild_members SET banker=%d WHERE char_id=%d",
is_banker? 1: 0, charid);
return(QueryWithLogging(query, "setting a guild member's banker flag"));
@@ -770,6 +796,7 @@ bool BaseGuildManager::DBSetBankerFlag(uint32 charid, bool is_banker) {
bool BaseGuildManager::GetBankerFlag(uint32 CharID)
{
_eqp
if(!m_db)
return false;
@@ -792,6 +819,7 @@ bool BaseGuildManager::GetBankerFlag(uint32 CharID)
bool BaseGuildManager::DBSetAltFlag(uint32 charid, bool is_alt)
{
_eqp
std::string query = StringFormat("UPDATE guild_members SET alt=%d WHERE char_id=%d",
is_alt ? 1: 0, charid);
@@ -800,6 +828,7 @@ bool BaseGuildManager::DBSetAltFlag(uint32 charid, bool is_alt)
bool BaseGuildManager::GetAltFlag(uint32 CharID)
{
_eqp
if(!m_db)
return false;
@@ -821,12 +850,14 @@ bool BaseGuildManager::GetAltFlag(uint32 CharID)
}
bool BaseGuildManager::DBSetTributeFlag(uint32 charid, bool enabled) {
_eqp
std::string query = StringFormat("UPDATE guild_members SET tribute_enable=%d WHERE char_id=%d",
enabled ? 1: 0, charid);
return(QueryWithLogging(query, "setting a guild member's tribute flag"));
}
bool BaseGuildManager::DBSetPublicNote(uint32 charid, const char* note) {
_eqp
if(m_db == nullptr)
return(false);
@@ -851,6 +882,7 @@ bool BaseGuildManager::DBSetPublicNote(uint32 charid, const char* note) {
}
bool BaseGuildManager::QueryWithLogging(std::string query, const char *errmsg) {
_eqp
if(m_db == nullptr)
return(false);
@@ -879,6 +911,7 @@ bool BaseGuildManager::QueryWithLogging(std::string query, const char *errmsg) {
" FROM `character_data` AS c LEFT JOIN guild_members AS g ON c.id=g.char_id "
#endif
static void ProcessGuildMember(MySQLRequestRow row, CharGuildInfo &into) {
_eqp
//fields from `characer_`
into.char_id = atoi(row[0]);
into.char_name = row[1];
@@ -906,6 +939,7 @@ static void ProcessGuildMember(MySQLRequestRow row, CharGuildInfo &into) {
bool BaseGuildManager::GetEntireGuild(uint32 guild_id, std::vector<CharGuildInfo *> &members) {
_eqp
members.clear();
if(m_db == nullptr)
@@ -930,6 +964,7 @@ bool BaseGuildManager::GetEntireGuild(uint32 guild_id, std::vector<CharGuildInfo
}
bool BaseGuildManager::GetCharInfo(const char *char_name, CharGuildInfo &into) {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested char info on %s when we have no database object.", char_name);
return(false);
@@ -961,6 +996,7 @@ bool BaseGuildManager::GetCharInfo(const char *char_name, CharGuildInfo &into) {
}
bool BaseGuildManager::GetCharInfo(uint32 char_id, CharGuildInfo &into) {
_eqp
if(m_db == nullptr) {
Log.Out(Logs::Detail, Logs::Guilds, "Requested char info on %d when we have no database object.", char_id);
return false;
@@ -991,6 +1027,7 @@ bool BaseGuildManager::GetCharInfo(uint32 char_id, CharGuildInfo &into) {
//returns ownership of the buffer.
uint8 *BaseGuildManager::MakeGuildList(const char *head_name, uint32 &length) const {
_eqp
//dynamic structs will make this a lot less painful.
length = sizeof(GuildsList_Struct);
@@ -1018,6 +1055,7 @@ uint8 *BaseGuildManager::MakeGuildList(const char *head_name, uint32 &length) co
}
const char *BaseGuildManager::GetRankName(uint32 guild_id, uint8 rank) const {
_eqp
if(rank > GUILD_MAX_RANK)
return("Invalid Rank");
std::map<uint32, GuildInfo *>::const_iterator res;
@@ -1028,6 +1066,7 @@ const char *BaseGuildManager::GetRankName(uint32 guild_id, uint8 rank) const {
}
const char *BaseGuildManager::GetGuildName(uint32 guild_id) const {
_eqp
if(guild_id == GUILD_NONE)
return("");
std::map<uint32, GuildInfo *>::const_iterator res;
@@ -1038,6 +1077,7 @@ const char *BaseGuildManager::GetGuildName(uint32 guild_id) const {
}
bool BaseGuildManager::GetGuildNameByID(uint32 guild_id, std::string &into) const {
_eqp
std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id);
if(res == m_guilds.end())
@@ -1048,6 +1088,7 @@ bool BaseGuildManager::GetGuildNameByID(uint32 guild_id, std::string &into) cons
uint32 BaseGuildManager::GetGuildIDByName(const char *GuildName)
{
_eqp
std::map<uint32, GuildInfo *>::iterator Iterator;
for(Iterator = m_guilds.begin(); Iterator != m_guilds.end(); ++Iterator)
@@ -1060,6 +1101,7 @@ uint32 BaseGuildManager::GetGuildIDByName(const char *GuildName)
}
bool BaseGuildManager::GetGuildMOTD(uint32 guild_id, char *motd_buffer, char *setter_buffer) const {
_eqp
std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id);
if(res == m_guilds.end())
@@ -1071,6 +1113,7 @@ bool BaseGuildManager::GetGuildMOTD(uint32 guild_id, char *motd_buffer, char *se
bool BaseGuildManager::GetGuildURL(uint32 GuildID, char *URLBuffer) const
{
_eqp
std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(GuildID);
if(res == m_guilds.end())
@@ -1082,6 +1125,7 @@ bool BaseGuildManager::GetGuildURL(uint32 GuildID, char *URLBuffer) const
bool BaseGuildManager::GetGuildChannel(uint32 GuildID, char *ChannelBuffer) const
{
_eqp
std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(GuildID);
if(res == m_guilds.end())
@@ -1091,12 +1135,14 @@ bool BaseGuildManager::GetGuildChannel(uint32 GuildID, char *ChannelBuffer) cons
}
bool BaseGuildManager::GuildExists(uint32 guild_id) const {
_eqp
if(guild_id == GUILD_NONE)
return(false);
return(m_guilds.find(guild_id) != m_guilds.end());
}
bool BaseGuildManager::IsGuildLeader(uint32 guild_id, uint32 char_id) const {
_eqp
if(guild_id == GUILD_NONE) {
Log.Out(Logs::Detail, Logs::Guilds, "Check leader for char %d: not a guild.", char_id);
return(false);
@@ -1112,6 +1158,7 @@ bool BaseGuildManager::IsGuildLeader(uint32 guild_id, uint32 char_id) const {
}
uint32 BaseGuildManager::FindGuildByLeader(uint32 leader) const {
_eqp
std::map<uint32, GuildInfo *>::const_iterator cur, end;
cur = m_guilds.begin();
end = m_guilds.end();
@@ -1124,6 +1171,7 @@ uint32 BaseGuildManager::FindGuildByLeader(uint32 leader) const {
//returns the rank to be sent to the client for display purposes, given their eqemu rank.
uint8 BaseGuildManager::GetDisplayedRank(uint32 guild_id, uint8 rank, uint32 char_id) const {
_eqp
std::map<uint32, GuildInfo *>::const_iterator res;
res = m_guilds.find(guild_id);
if(res == m_guilds.end())
@@ -1136,6 +1184,7 @@ uint8 BaseGuildManager::GetDisplayedRank(uint32 guild_id, uint8 rank, uint32 cha
}
bool BaseGuildManager::CheckGMStatus(uint32 guild_id, uint8 status) const {
_eqp
if(status >= 250) {
Log.Out(Logs::Detail, Logs::Guilds, "Check permission on guild %d with user status %d > 250, granted.", guild_id, status);
return(true); //250+ as allowed anything
@@ -1157,6 +1206,7 @@ bool BaseGuildManager::CheckGMStatus(uint32 guild_id, uint8 status) const {
}
bool BaseGuildManager::CheckPermission(uint32 guild_id, uint8 rank, GuildAction act) const {
_eqp
if(rank > GUILD_MAX_RANK) {
Log.Out(Logs::Detail, Logs::Guilds, "Check permission on guild %d and rank %d for action %s (%d): Invalid rank, denied.",
guild_id, rank, GuildActionNames[act], act);
@@ -1182,6 +1232,7 @@ bool BaseGuildManager::CheckPermission(uint32 guild_id, uint8 rank, GuildAction
}
bool BaseGuildManager::LocalDeleteGuild(uint32 guild_id) {
_eqp
std::map<uint32, GuildInfo *>::iterator res;
res = m_guilds.find(guild_id);
if(res == m_guilds.end())
@@ -1201,18 +1252,21 @@ void BaseGuildManager::ClearGuilds() {
}
BaseGuildManager::RankInfo::RankInfo() {
_eqp
uint8 r;
for(r = 0; r < _MaxGuildAction; r++)
permissions[r] = false;
}
BaseGuildManager::GuildInfo::GuildInfo() {
_eqp
leader_char_id = 0;
minstatus = 0;
}
uint32 BaseGuildManager::DoesAccountContainAGuildLeader(uint32 AccountID)
{
_eqp
std::string query = StringFormat("SELECT guild_id FROM guild_members WHERE char_id IN "
"(SELECT id FROM `character_data` WHERE account_id = %i) AND rank = 2",
AccountID);
+37 -27
View File
@@ -506,6 +506,7 @@ int16 Inventory::HasItem(uint32 item_id, uint8 quantity, uint8 where)
return slot_id;
}
// Behavioral change - Limbo is no longer checked due to improper handling of return value
if (where & invWhereCursor) {
// Check cursor queue
slot_id = _HasItem(m_cursor, item_id, quantity);
@@ -552,6 +553,7 @@ int16 Inventory::HasItemByUse(uint8 use, uint8 quantity, uint8 where)
return slot_id;
}
// Behavioral change - Limbo is no longer checked due to improper handling of return value
if (where & invWhereCursor) {
// Check cursor queue
slot_id = _HasItemByUse(m_cursor, use, quantity);
@@ -597,6 +599,7 @@ int16 Inventory::HasItemByLoreGroup(uint32 loregroup, uint8 where)
return slot_id;
}
// Behavioral change - Limbo is no longer checked due to improper handling of return value
if (where & invWhereCursor) {
// Check cursor queue
slot_id = _HasItemByLoreGroup(m_cursor, loregroup);
@@ -1011,7 +1014,8 @@ uint8 Inventory::FindHighestLightValue()
if (inst == nullptr) { continue; }
auto item = inst->GetItem();
if (item == nullptr) { continue; }
if (item->ItemType != ItemTypeMisc && item->ItemType != ItemTypeLight) { continue; }
// 'Gloomingdeep lantern' is ItemTypeArmor in the database..there may be others instances and/or types that need to be handled
if (item->ItemType != ItemTypeMisc && item->ItemType != ItemTypeLight && item->ItemType != ItemTypeArmor) { continue; }
if (item->Light & 0xF0) { continue; }
if (item->Light > light_value) { light_value = item->Light; }
}
@@ -1059,7 +1063,7 @@ int Inventory::GetSlotByItemInstCollection(const std::map<int16, ItemInst*> &col
}
if (t_inst && !t_inst->IsType(ItemClassContainer)) {
for (auto b_iter = t_inst->_begin(); b_iter != t_inst->_end(); ++b_iter) {
for (auto b_iter = t_inst->_cbegin(); b_iter != t_inst->_cend(); ++b_iter) {
if (b_iter->second == inst) {
return Inventory::CalcSlotId(iter->first, b_iter->first);
}
@@ -1070,13 +1074,10 @@ int Inventory::GetSlotByItemInstCollection(const std::map<int16, ItemInst*> &col
return -1;
}
void Inventory::dumpItemCollection(const std::map<int16, ItemInst*> &collection) {
iter_inst it;
iter_contents itb;
ItemInst* inst = nullptr;
for (it = collection.begin(); it != collection.end(); ++it) {
inst = it->second;
void Inventory::dumpItemCollection(const std::map<int16, ItemInst*> &collection)
{
for (auto it = collection.cbegin(); it != collection.cend(); ++it) {
auto inst = it->second;
if (!inst || !inst->GetItem())
continue;
@@ -1087,14 +1088,13 @@ void Inventory::dumpItemCollection(const std::map<int16, ItemInst*> &collection)
}
}
void Inventory::dumpBagContents(ItemInst *inst, iter_inst *it) {
iter_contents itb;
void Inventory::dumpBagContents(ItemInst *inst, std::map<int16, ItemInst*>::const_iterator *it)
{
if (!inst || !inst->IsType(ItemClassContainer))
return;
// Go through bag, if bag
for (itb = inst->_begin(); itb != inst->_end(); ++itb) {
for (auto itb = inst->_cbegin(); itb != inst->_cend(); ++itb) {
ItemInst* baginst = itb->second;
if (!baginst || !baginst->GetItem())
continue;
@@ -1109,7 +1109,7 @@ void Inventory::dumpBagContents(ItemInst *inst, iter_inst *it) {
// Internal Method: Retrieves item within an inventory bucket
ItemInst* Inventory::_GetItem(const std::map<int16, ItemInst*>& bucket, int16 slot_id) const
{
iter_inst it = bucket.find(slot_id);
auto it = bucket.find(slot_id);
if (it != bucket.end()) {
return it->second;
}
@@ -1122,6 +1122,8 @@ ItemInst* Inventory::_GetItem(const std::map<int16, ItemInst*>& bucket, int16 sl
// Assumes item has already been allocated
int16 Inventory::_PutItem(int16 slot_id, ItemInst* inst)
{
// What happens here when we _PutItem(MainCursor)? Bad things..really bad things...
//
// If putting a nullptr into slot, we need to remove slot without memory delete
if (inst == nullptr) {
//Why do we not delete the poped item here????
@@ -1203,7 +1205,7 @@ int16 Inventory::_HasItem(std::map<int16, ItemInst*>& bucket, uint32 item_id, ui
if (!inst->IsType(ItemClassContainer)) { continue; }
for (auto bag_iter = inst->_begin(); bag_iter != inst->_end(); ++bag_iter) {
for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) {
auto bag_inst = bag_iter->second;
if (bag_inst == nullptr) { continue; }
@@ -1234,7 +1236,7 @@ int16 Inventory::_HasItem(ItemInstQueue& iqueue, uint32 item_id, uint8 quantity)
uint8 quantity_found = 0;
for (auto iter = iqueue.begin(); iter != iqueue.end(); ++iter) {
for (auto iter = iqueue.cbegin(); iter != iqueue.cend(); ++iter) {
auto inst = *iter;
if (inst == nullptr) { continue; }
@@ -1251,7 +1253,7 @@ int16 Inventory::_HasItem(ItemInstQueue& iqueue, uint32 item_id, uint8 quantity)
if (!inst->IsType(ItemClassContainer)) { continue; }
for (auto bag_iter = inst->_begin(); bag_iter != inst->_end(); ++bag_iter) {
for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) {
auto bag_inst = bag_iter->second;
if (bag_inst == nullptr) { continue; }
@@ -1266,6 +1268,9 @@ int16 Inventory::_HasItem(ItemInstQueue& iqueue, uint32 item_id, uint8 quantity)
return legacy::SLOT_AUGMENT;
}
}
// We only check the visible cursor due to lack of queue processing ability (client allows duplicate in limbo)
break;
}
return INVALID_INDEX;
@@ -1288,7 +1293,7 @@ int16 Inventory::_HasItemByUse(std::map<int16, ItemInst*>& bucket, uint8 use, ui
if (!inst->IsType(ItemClassContainer)) { continue; }
for (auto bag_iter = inst->_begin(); bag_iter != inst->_end(); ++bag_iter) {
for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) {
auto bag_inst = bag_iter->second;
if (bag_inst == nullptr) { continue; }
@@ -1308,7 +1313,7 @@ int16 Inventory::_HasItemByUse(ItemInstQueue& iqueue, uint8 use, uint8 quantity)
{
uint8 quantity_found = 0;
for (auto iter = iqueue.begin(); iter != iqueue.end(); ++iter) {
for (auto iter = iqueue.cbegin(); iter != iqueue.cend(); ++iter) {
auto inst = *iter;
if (inst == nullptr) { continue; }
@@ -1320,7 +1325,7 @@ int16 Inventory::_HasItemByUse(ItemInstQueue& iqueue, uint8 use, uint8 quantity)
if (!inst->IsType(ItemClassContainer)) { continue; }
for (auto bag_iter = inst->_begin(); bag_iter != inst->_end(); ++bag_iter) {
for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) {
auto bag_inst = bag_iter->second;
if (bag_inst == nullptr) { continue; }
@@ -1330,6 +1335,9 @@ int16 Inventory::_HasItemByUse(ItemInstQueue& iqueue, uint8 use, uint8 quantity)
return Inventory::CalcSlotId(MainCursor, bag_iter->first);
}
}
// We only check the visible cursor due to lack of queue processing ability (client allows duplicate in limbo)
break;
}
return INVALID_INDEX;
@@ -1354,7 +1362,7 @@ int16 Inventory::_HasItemByLoreGroup(std::map<int16, ItemInst*>& bucket, uint32
if (!inst->IsType(ItemClassContainer)) { continue; }
for (auto bag_iter = inst->_begin(); bag_iter != inst->_end(); ++bag_iter) {
for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) {
auto bag_inst = bag_iter->second;
if (bag_inst == nullptr) { continue; }
@@ -1377,7 +1385,7 @@ int16 Inventory::_HasItemByLoreGroup(std::map<int16, ItemInst*>& bucket, uint32
// Internal Method: Checks an inventory queue type bucket for a particular item
int16 Inventory::_HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup)
{
for (auto iter = iqueue.begin(); iter != iqueue.end(); ++iter) {
for (auto iter = iqueue.cbegin(); iter != iqueue.cend(); ++iter) {
auto inst = *iter;
if (inst == nullptr) { continue; }
@@ -1394,7 +1402,7 @@ int16 Inventory::_HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup)
if (!inst->IsType(ItemClassContainer)) { continue; }
for (auto bag_iter = inst->_begin(); bag_iter != inst->_end(); ++bag_iter) {
for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) {
auto bag_inst = bag_iter->second;
if (bag_inst == nullptr) { continue; }
@@ -1409,6 +1417,9 @@ int16 Inventory::_HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup)
return legacy::SLOT_AUGMENT;
}
}
// We only check the visible cursor due to lack of queue processing ability (client allows duplicate in limbo)
break;
}
return INVALID_INDEX;
@@ -1504,8 +1515,7 @@ ItemInst::ItemInst(const ItemInst& copy)
m_attuned=copy.m_attuned;
m_merchantcount=copy.m_merchantcount;
// Copy container contents
iter_contents it;
for (it=copy.m_contents.begin(); it!=copy.m_contents.end(); ++it) {
for (auto it = copy.m_contents.begin(); it != copy.m_contents.end(); ++it) {
ItemInst* inst_old = it->second;
ItemInst* inst_new = nullptr;
@@ -1675,7 +1685,7 @@ bool ItemInst::IsAugmentSlotAvailable(int32 augtype, uint8 slot) const
// Retrieve item inside container
ItemInst* ItemInst::GetItem(uint8 index) const
{
iter_contents it = m_contents.find(index);
auto it = m_contents.find(index);
if (it != m_contents.end()) {
return it->second;
}
@@ -1738,7 +1748,7 @@ void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent)
// TODO: This needs work...
// Destroy container contents
iter_contents cur, end, del;
std::map<uint8, ItemInst*>::const_iterator cur, end, del;
cur = m_contents.begin();
end = m_contents.end();
for (; cur != end;) {
+7 -10
View File
@@ -33,9 +33,6 @@ class EvolveInfo; // Stores information about an evolving item family
#include <list>
#include <map>
// Helper typedefs
typedef std::map<int16, ItemInst*>::const_iterator iter_inst;
typedef std::map<uint8, ItemInst*>::const_iterator iter_contents;
namespace ItemField
{
@@ -86,8 +83,8 @@ public:
// Public Methods
/////////////////////////
inline std::list<ItemInst*>::const_iterator begin() { return m_list.begin(); }
inline std::list<ItemInst*>::const_iterator end() { return m_list.end(); }
inline std::list<ItemInst*>::const_iterator cbegin() { return m_list.cbegin(); }
inline std::list<ItemInst*>::const_iterator cend() { return m_list.cend(); }
inline int size() { return static_cast<int>(m_list.size()); } // TODO: change to size_t
inline bool empty() { return m_list.empty(); }
@@ -140,8 +137,8 @@ public:
ItemInst* GetItem(int16 slot_id) const;
ItemInst* GetItem(int16 slot_id, uint8 bagidx) const;
inline std::list<ItemInst*>::const_iterator cursor_begin() { return m_cursor.begin(); }
inline std::list<ItemInst*>::const_iterator cursor_end() { return m_cursor.end(); }
inline std::list<ItemInst*>::const_iterator cursor_cbegin() { return m_cursor.cbegin(); }
inline std::list<ItemInst*>::const_iterator cursor_cend() { return m_cursor.cend(); }
inline int CursorSize() { return m_cursor.size(); }
inline bool CursorEmpty() { return m_cursor.empty(); }
@@ -227,7 +224,7 @@ protected:
int GetSlotByItemInstCollection(const std::map<int16, ItemInst*> &collection, ItemInst *inst);
void dumpItemCollection(const std::map<int16, ItemInst*> &collection);
void dumpBagContents(ItemInst *inst, iter_inst *it);
void dumpBagContents(ItemInst *inst, std::map<int16, ItemInst*>::const_iterator *it);
// Retrieves item within an inventory bucket
ItemInst* _GetItem(const std::map<int16, ItemInst*>& bucket, int16 slot_id) const;
@@ -425,8 +422,8 @@ protected:
//////////////////////////
// Protected Members
//////////////////////////
iter_contents _begin() { return m_contents.begin(); }
iter_contents _end() { return m_contents.end(); }
std::map<uint8, ItemInst*>::const_iterator _cbegin() { return m_contents.cbegin(); }
std::map<uint8, ItemInst*>::const_iterator _cend() { return m_contents.cend(); }
friend class Inventory;
+34 -64
View File
@@ -24,36 +24,6 @@
std::map<int,std::string> DBFieldNames;
#ifndef WIN32
#if defined(FREEBSD) || defined(__CYGWIN__)
int print_stacktrace()
{
printf("Insert stack trace here...\n");
return(0);
}
#else //!WIN32 && !FREEBSD == linux
#include <execinfo.h>
int print_stacktrace()
{
void *ba[20];
int n = backtrace (ba, 20);
if (n != 0)
{
char **names = backtrace_symbols (ba, n);
if (names != nullptr)
{
int i;
std::cerr << "called from " << (char*)names[0] << std::endl;
for (i = 1; i < n; ++i)
std::cerr << " " << (char*)names[i] << std::endl;
free (names);
}
}
return(0);
}
#endif //!FREEBSD
#endif //!WIN32
void Unprotect(std::string &s, char what)
{
if (s.length()) {
@@ -78,12 +48,12 @@ void Protect(std::string &s, char what)
*/
bool ItemParse(const char *data, int length, std::map<int,std::map<int,std::string> > &items, int id_pos, int name_pos, int max_field, int level)
{
int i;
char *end,*ptr;
std::map<int,std::string> field;
static char *buffer=nullptr;
static int buffsize=0;
static char *temp=nullptr;
int i;
char *end,*ptr;
std::map<int,std::string> field;
static char *buffer=nullptr;
static int buffsize=0;
static char *temp=nullptr;
if (!buffsize || buffsize<(length+1)) {
buffer=(char *)realloc(buffer,length+1);
temp=(char *)realloc(temp,length+1);
@@ -186,10 +156,10 @@ static char *temp=nullptr;
int Tokenize(std::string s,std::map<int,std::string> & tokens, char delim)
{
int i,len;
std::string::size_type end;
//char temp[1024];
std::string x;
int i,len;
std::string::size_type end;
//char temp[1024];
std::string x;
tokens.clear();
i=0;
while(s.length()) {
@@ -335,14 +305,14 @@ void LoadItemDBFieldNames() {
void encode_length(unsigned long length, char *out)
{
char buf[4];
char buf[4];
memcpy(buf,&length,sizeof(unsigned long));
encode_chunk(buf,3,out);
}
unsigned long encode(char *in, unsigned long length, char *out)
{
unsigned long used=0,len=0;
unsigned long used=0,len=0;
while(used<length) {
encode_chunk(in+used,length-used,out+len);
used+=3;
@@ -355,8 +325,8 @@ unsigned long used=0,len=0;
unsigned long decode_length(char *in)
{
int length;
char buf[4];
int length;
char buf[4];
decode_chunk(in,&buf[0]);
buf[3]=0;
memcpy(&length,buf,sizeof(unsigned long));
@@ -366,8 +336,8 @@ char buf[4];
void decode(char *in, char *out)
{
char *ptr=in;
char *outptr=out;
char *ptr=in;
char *outptr=out;
while(*ptr) {
decode_chunk(ptr,outptr);
ptr+=4;
@@ -393,8 +363,8 @@ void decode_chunk(char *in, char *out)
void dump_message_column(unsigned char *buffer, unsigned long length, std::string leader, FILE *to)
{
unsigned long i,j;
unsigned long rows,offset=0;
unsigned long i,j;
unsigned long rows,offset=0;
rows=(length/16)+1;
for(i=0;i<rows;i++) {
fprintf(to, "%s%05ld: ",leader.c_str(),i*16);
@@ -419,8 +389,8 @@ unsigned long rows,offset=0;
std::string long2ip(unsigned long ip)
{
char temp[16];
union { unsigned long ip; struct { unsigned char a,b,c,d; } octet;} ipoctet;
char temp[16];
union { unsigned long ip; struct { unsigned char a,b,c,d; } octet;} ipoctet;
ipoctet.ip=ip;
sprintf(temp,"%d.%d.%d.%d",ipoctet.octet.a,ipoctet.octet.b,ipoctet.octet.c,ipoctet.octet.d);
@@ -430,8 +400,8 @@ union { unsigned long ip; struct { unsigned char a,b,c,d; } octet;} ipoctet;
std::string string_from_time(std::string pattern, time_t now)
{
struct tm *now_tm;
char time_string[51];
struct tm *now_tm;
char time_string[51];
if (!now)
time(&now);
@@ -450,9 +420,9 @@ std::string timestamp(time_t now)
std::string pop_arg(std::string &s, std::string seps, bool obey_quotes)
{
std::string ret;
unsigned long i;
bool in_quote=false;
std::string ret;
unsigned long i;
bool in_quote=false;
unsigned long length=s.length();
for(i=0;i<length;i++) {
@@ -481,8 +451,8 @@ bool in_quote=false;
int EQsprintf(char *buffer, const char *pattern, const char *arg1, const char *arg2, const char *arg3, const char *arg4, const char *arg5, const char *arg6, const char *arg7, const char *arg8, const char *arg9)
{
const char *args[9],*ptr;
char *bptr;
const char *args[9],*ptr;
char *bptr;
args[0]=arg1;
args[1]=arg2;
args[2]=arg3;
@@ -524,11 +494,11 @@ char *bptr;
std::string generate_key(int length)
{
std::string key;
//TODO: write this for win32...
std::string key;
//TODO: write this for win32...
#ifndef WIN32
int i;
timeval now;
int i;
timeval now;
static const char *chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for(i=0;i<length;i++) {
gettimeofday(&now,nullptr);
@@ -550,9 +520,9 @@ void print_hex(const char *data, unsigned long length) {
void build_hex_line(const char *buffer, unsigned long length, unsigned long offset, char *out_buffer, unsigned char padding)
{
char *ptr=out_buffer;
int i;
char printable[17];
char *ptr=out_buffer;
int i;
char printable[17];
ptr+=sprintf(ptr,"%0*lu:",padding,offset);
for(i=0;i<16; i++) {
if (i==8) {
-4
View File
@@ -24,10 +24,6 @@ void decode(char *in, char *out);
void encode_chunk(char *in, int len, char *out);
void decode_chunk(char *in, char *out);
#ifndef WIN32
int print_stacktrace();
#endif
void dump_message_column(unsigned char *buffer, unsigned long length, std::string leader="", FILE *to = stdout);
std::string string_from_time(std::string pattern, time_t now=0);
std::string timestamp(time_t now=0);
-1
View File
@@ -32,7 +32,6 @@ MySQLRequestResult::MySQLRequestResult(MYSQL_RES* result, uint32 rowsAffected, u
void MySQLRequestResult::FreeInternals()
{
safe_delete_array(m_ErrorBuffer);
if (m_Result != nullptr)
-307
View File
@@ -1,307 +0,0 @@
#include "global_define.h"
#include <map>
#include <string>
std::map<unsigned long, std::string> opcode_map;
std::string get_opcode_name(unsigned long opcode)
{
std::map<unsigned long, std::string>::iterator itr;;
return (itr = opcode_map.find(opcode)) != opcode_map.end() ? itr->second : "OP_Unknown";
}
void load_opcode_names()
{
opcode_map[0x0176] = "LiveOP_Heartbeat";
opcode_map[0x02d7] = "LiveOP_ReloadUI";
opcode_map[0x01eb] = "LiveOP_IncreaseStats";
opcode_map[0x0134] = "LiveOP_ApproveZone";
opcode_map[0x01d5] = "LiveOP_Dye";
opcode_map[0x0168] = "LiveOP_Stamina";
opcode_map[0x014d] = "LiveOP_ControlBoat";
opcode_map[0x003e] = "LiveOP_MobUpdate";
opcode_map[0x0027] = "LiveOP_ClientUpdate";
opcode_map[0x0024] = "LiveOP_ChannelMessage";
opcode_map[0x01d7] = "LiveOP_SimpleMessage";
opcode_map[0x01d8] = "LiveOP_FormattedMessage";
opcode_map[0x01c6] = "LiveOP_TGB";
opcode_map[0x0285] = "LiveOP_TestBuff";
opcode_map[0x012d] = "LiveOP_Bind_Wound";
opcode_map[0x01ab] = "LiveOP_Charm";
opcode_map[0x014c] = "LiveOP_Begging";
opcode_map[0x0152] = "LiveOP_MoveCoin";
opcode_map[0x0292] = "LiveOP_SpawnDoor";
opcode_map[0x009d] = "LiveOP_Sneak";
opcode_map[0x0079] = "LiveOP_ExpUpdate";
opcode_map[0x027d] = "LiveOP_DumpName";
opcode_map[0x01ea] = "LiveOP_RespondAA";
opcode_map[0x01c9] = "LiveOP_SendAAStats";
opcode_map[0x0366] = "LiveOP_SendAATable";
opcode_map[0x01e9] = "LiveOP_AAAction";
opcode_map[0x00bb] = "LiveOP_BoardBoat";
opcode_map[0x00bc] = "LiveOP_LeaveBoat";
opcode_map[0x02b8] = "LiveOP_AdventureInfoRequest";
opcode_map[0x02b9] = "LiveOP_AdventureInfo";
opcode_map[0x02a6] = "LiveOP_AdventureRequest";
opcode_map[0x02a8] = "LiveOP_AdventureDetails";
opcode_map[0x02a9] = "LiveOP_LDoNButton";
opcode_map[0x02ba] = "LiveOP_AdventureData";
opcode_map[0x02c9] = "LiveOP_AdventureFinish";
opcode_map[0x02c6] = "LiveOP_LeaveAdventure";
opcode_map[0x02ce] = "LiveOP_AdventureUpdate";
opcode_map[0x002b] = "LiveOP_SendExpZonein";
opcode_map[0x01e4] = "LiveOP_ZoneInSendName";
opcode_map[0x01bf] = "LiveOP_GuildLeader";
opcode_map[0x009a] = "LiveOP_GuildPeace";
opcode_map[0x0132] = "LiveOP_GuildRemove";
opcode_map[0x0059] = "LiveOP_GuildMemberList";
opcode_map[0x026e] = "LiveOP_GuildMemberUpdate";
opcode_map[0x0130] = "LiveOP_GuildInvite";
opcode_map[0x01c0] = "LiveOP_GuildMOTD";
opcode_map[0x003c] = "LiveOP_GuildPublicNote";
opcode_map[0x027e] = "LiveOP_GetGuildMOTD";
opcode_map[0x0277] = "LiveOP_GuildDemote";
opcode_map[0x0131] = "LiveOP_GuildInviteAccept";
opcode_map[0x00a4] = "LiveOP_GuildWar";
opcode_map[0x0133] = "LiveOP_GuildDelete";
opcode_map[0x0233] = "LiveOP_GuildManageRemove";
opcode_map[0x022d] = "LiveOP_GuildManageAdd";
opcode_map[0x0039] = "LiveOP_GuildManageStatus";
opcode_map[0x01e8] = "LiveOP_Trader";
opcode_map[0x01e7] = "LiveOP_Bazaar";
opcode_map[0x01c4] = "LiveOP_BecomeTrader";
opcode_map[0x01f4] = "LiveOP_BazaarInspect";
opcode_map[0x006e] = "LiveOP_TraderItemUpdate";
opcode_map[0x017c] = "LiveOP_TraderDelItem";
opcode_map[0x01eb] = "LiveOP_TraderShop";
opcode_map[0x01ca] = "LiveOP_TraderBuy";
opcode_map[0x01ac] = "LiveOP_PetCommands";
opcode_map[0x0042] = "LiveOP_TradeSkillCombine";
opcode_map[0x02e5] = "LiveOP_AugmentItem";
opcode_map[0x0367] = "LiveOP_ItemName";
opcode_map[0x02cd] = "LiveOP_ShopItem";
opcode_map[0x0065] = "LiveOP_ShopPlayerBuy";
opcode_map[0x006a] = "LiveOP_ShopPlayerSell";
opcode_map[0x006d] = "LiveOP_ShopDelItem";
opcode_map[0x0f6d] = "LiveOP_ShopEndConfirm";
opcode_map[0x00f7] = "LiveOP_ShopRequest";
opcode_map[0x006c] = "LiveOP_ShopEnd";
opcode_map[0x02d1] = "LiveOP_AdventureMerchantRequest";
opcode_map[0x02d2] = "LiveOP_AdventureMerchantResponse";
opcode_map[0x02d3] = "LiveOP_AdventureMerchantPurchase";
opcode_map[0x02e3] = "LiveOP_AdventurePointsUpdate";
opcode_map[0x0270] = "LiveOP_LFGCommand";
opcode_map[0x01d0] = "LiveOP_LFGAppearance";
opcode_map[0x01b5] = "LiveOP_MoneyUpdate";
opcode_map[0x0721] = "LiveOP_GroupDelete";
opcode_map[0x0272] = "LiveOP_GroupAcknowledge";
opcode_map[0x024a] = "LiveOP_GroupUpdate";
opcode_map[0x025f] = "LiveOP_GroupInvite";
opcode_map[0x00ff] = "LiveOP_GroupDisband";
opcode_map[0x00d5] = "LiveOP_GroupInvite2";
opcode_map[0x025e] = "LiveOP_GroupFollow";
opcode_map[0x00d7] = "LiveOP_GroupFollow2";
opcode_map[0x00d6] = "LiveOP_GroupCancelInvite";
opcode_map[0x0156] = "LiveOP_Split";
opcode_map[0x00d8] = "LiveOP_Jump";
opcode_map[0x01d6] = "LiveOP_ConsiderCorpse";
opcode_map[0x0064] = "LiveOP_SkillUpdate";
opcode_map[0x0178] = "LiveOP_GMEndTrainingResponse";
opcode_map[0x013c] = "LiveOP_GMEndTraining";
opcode_map[0x0175] = "LiveOP_GMTrainSkill";
opcode_map[0x013b] = "LiveOP_GMTraining";
opcode_map[0x017b] = "LiveOP_ConsumeAmmo";
opcode_map[0x0171] = "LiveOP_CombatAbility";
opcode_map[0x009c] = "LiveOP_TrackUnknown";
opcode_map[0x0234] = "LiveOP_TrackTarget";
opcode_map[0x0286] = "LiveOP_Track";
opcode_map[0x0297] = "LiveOP_ReadBook";
opcode_map[0x001f] = "LiveOP_ItemLinkClick";
opcode_map[0x01f4] = "LiveOP_ItemLinkResponse";
opcode_map[0x01d9] = "LiveOP_ItemLinkText";
opcode_map[0x0a41] = "LiveOP_RezzRequest";
opcode_map[0x00e5] = "LiveOP_RezzAnswer";
opcode_map[0x019b] = "LiveOP_RezzComplete";
opcode_map[0x0128] = "LiveOP_MoveDoor";
opcode_map[0x0127] = "LiveOP_ClickDoor";
opcode_map[0x0247] = "LiveOP_SendZonepoints";
opcode_map[0x008c] = "LiveOP_SetRunMode";
opcode_map[0x0248] = "LiveOP_InspectRequest";
opcode_map[0x0249] = "LiveOP_InspectAnswer";
opcode_map[0x0187] = "LiveOP_SenseTraps";
opcode_map[0x018e] = "LiveOP_DisarmTraps";
opcode_map[0x01bc] = "LiveOP_Assist";
opcode_map[0x0240] = "LiveOP_PickPocket";
opcode_map[0x0119] = "LiveOP_LootRequest";
opcode_map[0x011a] = "LiveOP_EndLootRequest";
opcode_map[0x011b] = "LiveOP_MoneyOnCorpse";
opcode_map[0x0179] = "LiveOP_LootComplete";
opcode_map[0x013f] = "LiveOP_LootItem";
opcode_map[0x0151] = "LiveOP_MoveItem";
opcode_map[0x0056] = "LiveOP_WhoAllRequest";
opcode_map[0x0229] = "LiveOP_WhoAllResponse";
opcode_map[0x0167] = "LiveOP_Consume";
opcode_map[0x0172] = "LiveOP_AutoAttack";
opcode_map[0x0186] = "LiveOP_AutoAttack2";
opcode_map[0x0173] = "LiveOP_TargetMouse";
opcode_map[0x01ba] = "LiveOP_TargetCommand";
opcode_map[0x01d8] = "LiveOP_TargetReject";
opcode_map[0x009e] = "LiveOP_Hide";
opcode_map[0x012e] = "LiveOP_Forage";
opcode_map[0x0077] = "LiveOP_Fishing";
opcode_map[0x0246] = "LiveOP_Bug";
opcode_map[0x00f2] = "LiveOP_Emote";
opcode_map[0x0140] = "LiveOP_EmoteAnim";
opcode_map[0x015c] = "LiveOP_Consider";
opcode_map[0x01cb] = "LiveOP_FaceChange";
opcode_map[0x0197] = "LiveOP_RandomReq";
opcode_map[0x0087] = "LiveOP_RandomReply";
opcode_map[0x01c3] = "LiveOP_Camp";
opcode_map[0x0192] = "LiveOP_YellForHelp";
opcode_map[0x00ef] = "LiveOP_SafePoint";
opcode_map[0x0157] = "LiveOP_Buff";
opcode_map[0x00c0] = "LiveOP_ColoredText";
opcode_map[0x0440] = "LiveOP_MultiLineMsg";
opcode_map[0x021c] = "LiveOP_SpecialMesg";
opcode_map[0x0013] = "LiveOP_Consent";
opcode_map[0x029d] = "LiveOP_ConsentResponse";
opcode_map[0x02d4] = "LiveOP_Deny";
opcode_map[0x016c] = "LiveOP_Stun";
opcode_map[0x0021] = "LiveOP_BeginCast";
opcode_map[0x00be] = "LiveOP_CastSpell";
opcode_map[0x01a8] = "LiveOP_InterruptCast";
opcode_map[0x0105] = "LiveOP_Death";
opcode_map[0x023f] = "LiveOP_FeignDeath";
opcode_map[0x012b] = "LiveOP_Illusion";
opcode_map[0x0078] = "LiveOP_LevelUpdate";
opcode_map[0x0371] = "LiveOP_LevelAppearance";
opcode_map[0x00c2] = "LiveOP_MemorizeSpell";
opcode_map[0x0244] = "LiveOP_HPUpdate";
opcode_map[0x022e] = "LiveOP_SendHPTarget";
opcode_map[0x007d] = "LiveOP_Mend";
opcode_map[0x0160] = "LiveOP_Taunt";
opcode_map[0x0199] = "LiveOP_GMDelCorpse";
opcode_map[0x0047] = "LiveOP_GMFind";
opcode_map[0x0020] = "LiveOP_GMServers";
opcode_map[0x010b] = "LiveOP_GMGoto";
opcode_map[0x028c] = "LiveOP_GMSummon";
opcode_map[0x010a] = "LiveOP_GMKick";
opcode_map[0x0109] = "LiveOP_GMKill";
opcode_map[0x0b40] = "LiveOP_GMNameChange";
opcode_map[0x00a3] = "LiveOP_GMLastName";
opcode_map[0x01b3] = "LiveOP_GMToggle";
opcode_map[0x028f] = "LiveOP_GMEmoteZone";
opcode_map[0x0074] = "LiveOP_GMBecomeNPC";
opcode_map[0x00de] = "LiveOP_GMHideMe";
opcode_map[0x0184] = "LiveOP_GMZoneRequest";
opcode_map[0x0239] = "LiveOP_GMZoneRequest2";
opcode_map[0x0068] = "LiveOP_Petition";
opcode_map[0x0085] = "LiveOP_PetitionRefresh";
opcode_map[0x01ee] = "LiveOP_PDeletePetition";
opcode_map[0x0092] = "LiveOP_PetitionBug";
opcode_map[0x0069] = "LiveOP_PetitionUpdate";
opcode_map[0x0076] = "LiveOP_PetitionCheckout";
opcode_map[0x0056] = "LiveOP_PetitionCheckout2";
opcode_map[0x0091] = "LiveOP_PetitionDelete";
opcode_map[0x02b4] = "LiveOP_PetitionResolve";
opcode_map[0x007e] = "LiveOP_PetitionCheckIn";
opcode_map[0x0090] = "LiveOP_PetitionUnCheckout";
opcode_map[0x01ec] = "LiveOP_PetitionQue";
opcode_map[0x01bb] = "LiveOP_SetServerFilter";
opcode_map[0x0218] = "LiveOP_NewSpawn";
opcode_map[0x0140] = "LiveOP_Animation";
opcode_map[0x0142] = "LiveOP_ZoneChange";
opcode_map[0x00f3] = "LiveOP_DeleteSpawn";
opcode_map[0x0265] = "LiveOP_CrashDump";
opcode_map[0x00e8] = "LiveOP_EnvDamage";
opcode_map[0x0101] = "LiveOP_Action";
opcode_map[0x00e2] = "LiveOP_Damage";
opcode_map[0x00bf] = "LiveOP_ManaChange";
opcode_map[0x027c] = "LiveOP_ClientError";
opcode_map[0x00fb] = "LiveOP_Save";
opcode_map[0x0316] = "LiveOP_LocInfo";
opcode_map[0x0188] = "LiveOP_Surname";
opcode_map[0x018f] = "LiveOP_SwapSpell";
opcode_map[0x01db] = "LiveOP_DeleteSpell";
opcode_map[0x029f] = "LiveOP_CloseContainer";
opcode_map[0x029f] = "LiveOP_ClickObjectAck";
opcode_map[0x00fa] = "LiveOP_CreateObject";
opcode_map[0x00f9] = "LiveOP_ClickObject";
opcode_map[0x01c1] = "LiveOP_ClearObject";
opcode_map[0x0265] = "LiveOP_ZoneUnavail";
opcode_map[0x02e0] = "LiveOP_ItemPacket";
opcode_map[0x029a] = "LiveOP_TradeRequest";
opcode_map[0x0037] = "LiveOP_TradeRequestAck";
opcode_map[0x002d] = "LiveOP_TradeAcceptClick";
opcode_map[0x0162] = "LiveOP_TradeMoneyUpdate";
opcode_map[0x0036] = "LiveOP_TradeCoins";
opcode_map[0x002e] = "LiveOP_CancelTrade";
opcode_map[0x002f] = "LiveOP_FinishTrade";
opcode_map[0x00a1] = "LiveOP_SaveOnZoneReq";
opcode_map[0x0185] = "LiveOP_Logout";
opcode_map[0x0298] = "LiveOP_RequestDuel";
opcode_map[0x0a5d] = "LiveOP_DuelResponse";
opcode_map[0x016e] = "LiveOP_DuelResponse2";
opcode_map[0x007c] = "LiveOP_InstillDoubt";
opcode_map[0x00ac] = "LiveOP_SafeFallSuccess";
opcode_map[0x02fb] = "LiveOP_DisciplineUpdate";
opcode_map[0x02f2] = "LiveOP_TributeUpdate";
opcode_map[0x02f3] = "LiveOP_TributeItem";
opcode_map[0x02f4] = "LiveOP_TributePointUpdate";
opcode_map[0x02f5] = "LiveOP_SendTributes";
opcode_map[0x02f6] = "LiveOP_TributeInfo";
opcode_map[0x02f7] = "LiveOP_SelectTribute";
opcode_map[0x02f8] = "LiveOP_TributeTimer";
opcode_map[0x02f9] = "LiveOP_StartTribute";
opcode_map[0x02fa] = "LiveOP_TributeNPC";
opcode_map[0x02fe] = "LiveOP_TributeMoney";
opcode_map[0x0364] = "LiveOP_TributeToggle";
opcode_map[0x0322] = "LiveOP_RecipesFavorite";
opcode_map[0x01f9] = "LiveOP_RecipesSearch";
opcode_map[0x01fa] = "LiveOP_RecipeReply";
opcode_map[0x01fb] = "LiveOP_RecipeDetails";
opcode_map[0x01fc] = "LiveOP_RecipeAutoCombine";
opcode_map[0x02db] = "LiveOP_FindPersonRequest";
opcode_map[0x02dc] = "LiveOP_FindPersonReply";
opcode_map[0x01dd] = "LiveOP_Shielding";
opcode_map[0x0198] = "LiveOP_SetDataRate";
opcode_map[0x023b] = "LiveOP_ZoneEntry";
opcode_map[0x006b] = "LiveOP_PlayerProfile";
opcode_map[0x0291] = "LiveOP_CharInventory";
opcode_map[0x0170] = "LiveOP_ZoneSpawns";
opcode_map[0x0026] = "LiveOP_TimeOfDay";
opcode_map[0x015b] = "LiveOP_Weather";
opcode_map[0x00ec] = "LiveOP_ReqNewZone";
opcode_map[0x00eb] = "LiveOP_NewZone";
opcode_map[0x00fd] = "LiveOP_ReqClientSpawn";
opcode_map[0x012F] = "LiveOP_SpawnAppearance";
opcode_map[0x0086] = "LiveOP_ClientReady";
opcode_map[0x0086] = "LiveOP_ZoneComplete";
opcode_map[0x02db] = "LiveOP_LoginComplete";
opcode_map[0x0195] = "LiveOP_ApproveWorld";
opcode_map[0x035f] = "LiveOP_LogServer";
opcode_map[0x01b2] = "LiveOP_MOTD";
opcode_map[0x0251] = "LiveOP_SendLoginInfo";
opcode_map[0x00ea] = "LiveOP_DeleteCharacter";
opcode_map[0x0102] = "LiveOP_SendCharInfo";
opcode_map[0x00e1] = "LiveOP_ExpansionInfo";
opcode_map[0x0104] = "LiveOP_CharacterCreate";
opcode_map[0x02ab] = "LiveOP_RandomNameGenerator";
opcode_map[0x005d] = "LiveOP_GuildsList";
opcode_map[0x0125] = "LiveOP_ApproveName";
opcode_map[0x0261] = "LiveOP_EnterWorld";
opcode_map[0x015a] = "LiveOP_World_Client_CRC1";
opcode_map[0x015e] = "LiveOP_World_Client_CRC2";
opcode_map[0x0269] = "LiveOP_SetChatServer";
opcode_map[0x0264] = "LiveOP_ZoneServerInfo";
opcode_map[0x0017] = "LiveOP_AckPacket";
opcode_map[0x012c] = "LiveOP_WearChange";
opcode_map[0x1FA1] = "LiveOP_WorldObjectsSent";
opcode_map[0x39C4] = "LiveOP_BlockedBuffs";
opcode_map[0x4656] = "LiveOP_SpawnPositionUpdate";
opcode_map[0x4b61] = "LiveOP_ManaUpdate";
opcode_map[0x02d6] = "LiveOP_EnduranceUpdate";
opcode_map[0x2ac1] = "LiveOP_MobManaUpdate";
opcode_map[0x6c5f] = "LiveOP_MobEnduranceUpdate";
opcode_map[0x73a8] = "LiveOP_SendMaxCharacters";
}
+49
View File
@@ -17,6 +17,7 @@
*/
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
@@ -89,6 +90,54 @@ void DumpPacketHex(const uchar* buf, uint32 size, uint32 cols, uint32 skip) {
safe_delete_array(ascii);
}
std::string DumpPacketHexToString(const uchar* buf, uint32 size, uint32 cols, uint32 skip) {
std::ostringstream out;
if (size == 0 || size > 39565)
return "";
out << "\n";
// Output as HEX
char output[4];
int j = 0;
char* ascii = new char[cols + 1];
memset(ascii, 0, cols + 1);
uint32 i;
for (i = skip; i < size; i++)
{
if ((i - skip) % cols == 0) {
if (i != skip)
out << " | " << ascii << std::endl;
out << std::setw(4) << std::setfill(' ') << i - skip << ": ";
memset(ascii, 0, cols + 1);
j = 0;
}
else if ((i - skip) % (cols / 2) == 0) {
out << "- ";
}
sprintf(output, "%02X ", (unsigned char)buf[i]);
out << output;
if (buf[i] >= 32 && buf[i] < 127) {
ascii[j++] = buf[i];
}
else {
ascii[j++] = '.';
}
// std::cout << std::setfill(0) << std::setw(2) << std::hex << (int)buf[i] << " "; // unknown intent [CODEBUG]
}
uint32 k = ((i - skip) - 1) % cols;
if (k < 8)
out << " ";
for (uint32 h = k + 1; h < cols; h++) {
out << " ";
}
out << " | " << ascii << std::endl;
safe_delete_array(ascii);
return out.str();
}
void DumpPacket(const uchar* buf, uint32 size)
{
DumpPacketHex(buf, size);
+1
View File
@@ -24,6 +24,7 @@ class ServerPacket;
void DumpPacketAscii(const uchar* buf, uint32 size, uint32 cols=16, uint32 skip=0);
void DumpPacketHex(const uchar* buf, uint32 size, uint32 cols=16, uint32 skip=0);
std::string DumpPacketHexToString(const uchar* buf, uint32 size, uint32 cols = 16, uint32 skip = 0);
void DumpPacketBin(const void* data, uint32 len);
void DumpPacket(const uchar* buf, uint32 size);
void DumpPacket(const ServerPacket* pack, bool iShowInfo = false);
-438
View File
@@ -1,438 +0,0 @@
#ifndef WIN32
#include <unistd.h>
#else
#include <winsock2.h>
#endif
#include <errno.h>
#include <string.h>
#include <time.h>
#include "packetfile.h"
#include "../common/eq_opcodes.h"
#include "../common/eq_packet_structs.h"
#include "../common/misc.h"
#include <map>
PacketFileWriter::PacketFileWriter(bool _force_flush) {
out = NULL;
force_flush = _force_flush;
}
PacketFileWriter::~PacketFileWriter() {
CloseFile();
}
bool PacketFileWriter::SetPacketStamp(const char *name, uint32 stamp) {
FILE *in;
in = fopen(name, "r+b");
if(in == NULL) {
fprintf(stderr, "Error opening packet file '%s': %s\n", name, strerror(errno));
return(false);
}
unsigned long magic = 0;
if(fread(&magic, sizeof(magic), 1, in) != 1) {
fprintf(stderr, "Error reading header from packet file: %s\n", strerror(errno));
fclose(in);
return(false);
}
PacketFileReader *ret = NULL;
if(magic == OLD_PACKET_FILE_MAGIC) {
OldPacketFileHeader *pos = 0;
uint32 stamp_pos = (uint32) &pos->packet_file_stamp;
fseek(in, stamp_pos, SEEK_SET);
OldPacketFileHeader hdr;
hdr.packet_file_stamp = stamp;
if(fwrite(&hdr.packet_file_stamp, sizeof(hdr.packet_file_stamp), 1, in) != 1) {
fprintf(stderr, "Error writting to packet file: %s\n", strerror(errno));
fclose(in);
return(false);
}
} else if(magic == PACKET_FILE_MAGIC) {
PacketFileHeader *pos = 0;
uint32 stamp_pos = (uint32) &pos->packet_file_stamp;
fseek(in, stamp_pos, SEEK_SET);
PacketFileHeader hdr;
hdr.packet_file_stamp = stamp;
if(fwrite(&hdr.packet_file_stamp, sizeof(hdr.packet_file_stamp), 1, in) != 1) {
fprintf(stderr, "Error writting to packet file: %s\n", strerror(errno));
fclose(in);
return(false);
}
} else {
fprintf(stderr, "Unknown packet file type 0x%.8x\n", magic);
fclose(in);
return(false);
}
fclose(in);
return(true);
}
bool PacketFileWriter::OpenFile(const char *name) {
CloseFile();
printf("Opening packet file: %s\n", name);
out = fopen(name, "wb");
if(out == NULL) {
fprintf(stderr, "Error opening packet file '%s': %s\n", name, strerror(errno));
return(false);
}
PacketFileHeader head;
head.packet_file_magic = PACKET_FILE_MAGIC;
head.packet_file_version = PACKET_FILE_CURRENT_VERSION;
head.packet_file_stamp = time(NULL);
if(fwrite(&head, sizeof(head), 1, out) != 1) {
fprintf(stderr, "Error writting header to packet file: %s\n", strerror(errno));
fclose(out);
return(false);
}
return(true);
}
void PacketFileWriter::CloseFile() {
if(out != NULL) {
fclose(out);
out = NULL;
printf("Closed packet file.\n");
}
}
void PacketFileWriter::WritePacket(uint16 eq_op, uint32 packlen, const unsigned char *packet, bool to_server, const struct timeval &tv) {
if(out == NULL)
return;
_WriteBlock(eq_op, packet, packlen, to_server, tv);
/*
Could log only the packets we care about, but this is most of the stream,
so just log them all...
switch(eq_op) {
case OP_NewZone:
case OP_ZoneSpawns:
case OP_NewSpawn:
case OP_MobUpdate:
case OP_ClientUpdate:
case OP_Death:
case OP_DeleteSpawn:
case OP_CastSpell:
case OP_ShopRequest:
case OP_ShopEndConfirm:
case OP_ItemPacket:
_WriteBlock(eq_op, packet, packlen);
default:
return;
}
*/
}
bool PacketFileWriter::_WriteBlock(uint16 eq_op, const void *d, uint16 len, bool to_server, const struct timeval &tv) {
if(out == NULL)
return(false);
PacketFileSection s;
s.opcode = eq_op;
s.len = len;
s.tv_sec = tv.tv_sec;
s.tv_msec = tv.tv_usec/1000;
if(to_server)
SetToServer(s);
else
SetToClient(s);
if(fwrite(&s, sizeof(s), 1, out) != 1) {
fprintf(stderr, "Error writting block header: %s\n", strerror(errno));
return(false);
}
if(fwrite(d, 1, len, out) != len) {
fprintf(stderr, "Error writting block body: %s\n", strerror(errno));
return(false);
}
if(force_flush)
fflush(out);
return(true);
}
PacketFileReader *PacketFileReader::OpenPacketFile(const char *name) {
FILE *in;
in = fopen(name, "rb");
if(in == NULL) {
fprintf(stderr, "Error opening packet file '%s': %s\n", name, strerror(errno));
return(NULL);
}
unsigned long magic = 0;
if(fread(&magic, sizeof(magic), 1, in) != 1) {
fprintf(stderr, "Error reading header to packet file: %s\n", strerror(errno));
fclose(in);
return(NULL);
}
PacketFileReader *ret = NULL;
if(magic == OLD_PACKET_FILE_MAGIC) {
ret = new OldPacketFileReader();
} else if(magic == PACKET_FILE_MAGIC) {
ret = new NewPacketFileReader();
} else {
fprintf(stderr, "Unknown packet file type 0x%.8x\n", magic);
fclose(in);
return(NULL);
}
if(!ret->OpenFile(name)) {
safe_delete(ret);
return(NULL);
}
return(ret);
}
PacketFileReader::PacketFileReader() {
packet_file_stamp = 0;
}
OldPacketFileReader::OldPacketFileReader()
: PacketFileReader()
{
in = NULL;
}
OldPacketFileReader::~OldPacketFileReader() {
CloseFile();
}
bool OldPacketFileReader::OpenFile(const char *name) {
CloseFile();
in = fopen(name, "rb");
if(in == NULL) {
fprintf(stderr, "Error opening packet file '%s': %s\n", name, strerror(errno));
return(false);
}
OldPacketFileHeader head;
if(fread(&head, sizeof(head), 1, in) != 1) {
fprintf(stderr, "Error reading header to packet file: %s\n", strerror(errno));
fclose(in);
return(false);
}
if(head.packet_file_magic != OLD_PACKET_FILE_MAGIC) {
fclose(in);
if(head.packet_file_magic > (OLD_PACKET_FILE_MAGIC)) {
fprintf(stderr, "Error: this is a build file, not a packet file, its allready processed!\n");
} else {
fprintf(stderr, "Error: this is not a packet file!\n");
}
return(false);
}
uint32 now = time(NULL);
if(head.packet_file_stamp > now) {
fprintf(stderr, "Error: invalid timestamp in file. Your clock or the collector's is wrong (%d sec ahead).\n", head.packet_file_stamp-now);
fclose(in);
return(false);
}
packet_file_stamp = head.packet_file_stamp;
return(true);
}
void OldPacketFileReader::CloseFile() {
if(in != NULL) {
fclose(in);
in = NULL;
}
}
bool OldPacketFileReader::ResetFile() {
if(in == NULL)
return(false);
rewind(in);
//gotta read past the header again
OldPacketFileHeader head;
if(fread(&head, sizeof(head), 1, in) != 1) {
return(false);
}
return(true);
}
bool OldPacketFileReader::ReadPacket(uint16 &eq_op, uint32 &packlen, unsigned char *packet, bool &to_server, struct timeval &tv) {
if(in == NULL)
return(false);
if(feof(in))
return(false);
OldPacketFileSection s;
if(fread(&s, sizeof(s), 1, in) != 1) {
if(!feof(in))
fprintf(stderr, "Error reading section header: %s\n", strerror(errno));
return(false);
}
eq_op = s.opcode;
if(packlen < s.len) {
fprintf(stderr, "Packet buffer is too small! %d < %d, skipping\n", packlen, s.len);
fseek(in, s.len, SEEK_CUR);
return(false);
}
if(fread(packet, 1, s.len, in) != s.len) {
if(feof(in))
fprintf(stderr, "Error: EOF encountered when expecting packet data.\n");
else
fprintf(stderr, "Error reading packet body: %s\n", strerror(errno));
return(false);
}
packlen = s.len;
to_server = false;
tv.tv_sec = 0;
tv.tv_usec = 0;
return(true);
}
NewPacketFileReader::NewPacketFileReader()
: PacketFileReader()
{
in = NULL;
}
NewPacketFileReader::~NewPacketFileReader() {
CloseFile();
}
bool NewPacketFileReader::OpenFile(const char *name) {
CloseFile();
in = fopen(name, "rb");
if(in == NULL) {
fprintf(stderr, "Error opening packet file '%s': %s\n", name, strerror(errno));
return(false);
}
PacketFileHeader head;
if(fread(&head, sizeof(head), 1, in) != 1) {
fprintf(stderr, "Error reading header to packet file: %s\n", strerror(errno));
fclose(in);
return(false);
}
if(head.packet_file_magic != PACKET_FILE_MAGIC) {
fclose(in);
if(head.packet_file_magic == (PACKET_FILE_MAGIC+1)) {
fprintf(stderr, "Error: this is a build file, not a packet file, its allready processed!\n");
} else {
fprintf(stderr, "Error: this is not a packet file!\n");
}
return(false);
}
uint32 now = time(NULL);
if(head.packet_file_stamp > now) {
fprintf(stderr, "Error: invalid timestamp in file. Your clock or the collector's is wrong (%d sec ahead).\n", head.packet_file_stamp-now);
fclose(in);
return(false);
}
packet_file_stamp = head.packet_file_stamp;
return(true);
}
void NewPacketFileReader::CloseFile() {
if(in != NULL) {
fclose(in);
in = NULL;
}
}
bool NewPacketFileReader::ResetFile() {
if(in == NULL)
return(false);
rewind(in);
//gotta read past the header again
PacketFileHeader head;
if(fread(&head, sizeof(head), 1, in) != 1) {
return(false);
}
return(true);
}
bool NewPacketFileReader::ReadPacket(uint16 &eq_op, uint32 &packlen, unsigned char *packet, bool &to_server, struct timeval &tv) {
if(in == NULL)
return(false);
if(feof(in))
return(false);
PacketFileSection s;
if(fread(&s, sizeof(s), 1, in) != 1) {
if(!feof(in))
fprintf(stderr, "Error reading section header: %s\n", strerror(errno));
return(false);
}
eq_op = s.opcode;
if(packlen < s.len) {
fprintf(stderr, "Packet buffer is too small! %d < %d, skipping\n", packlen, s.len);
fseek(in, s.len, SEEK_CUR);
return(false);
}
if(fread(packet, 1, s.len, in) != s.len) {
if(feof(in))
fprintf(stderr, "Error: EOF encountered when expecting packet data.\n");
else
fprintf(stderr, "Error reading packet body: %s\n", strerror(errno));
return(false);
}
packlen = s.len;
to_server = IsToServer(s);
tv.tv_sec = s.tv_sec;
tv.tv_usec = 1000*s.tv_msec;
return(true);
}
-130
View File
@@ -1,130 +0,0 @@
#ifndef PACKET_FILE_H
#define PACKET_FILE_H
#include "../common/types.h"
#include <stdio.h>
#include <time.h>
//#include <zlib.h>
//constants used in the packet file header
#define PACKET_FILE_MAGIC 0x93a7b6f6
#define OLD_PACKET_FILE_MAGIC 0x93a7b6f7
#define PACKET_FILE_CURRENT_VERSION 1
#pragma pack(1)
//old structs from when I forgot to put the version number in
struct OldPacketFileHeader {
uint32 packet_file_magic;
uint32 packet_file_stamp;
};
struct OldPacketFileSection {
uint16 opcode;
uint32 len;
};
struct PacketFileHeader {
uint32 packet_file_magic;
uint16 packet_file_version;
uint32 packet_file_stamp;
};
struct PacketFileSection {
uint16 opcode;
uint8 flags; //mainly for client->server, but others could be added
uint32 tv_sec;
uint16 tv_msec;
uint32 len;
};
#pragma pack()
#define TO_SERVER_FLAG 0x01
#define SetToClient(pfs) pfs.flags = pfs.flags&~TO_SERVER_FLAG
#define SetToServer(pfs) pfs.flags = pfs.flags|TO_SERVER_FLAG
#define IsToClient(pfs) (pfs.flags&TO_SERVER_FLAG == 0)
#define IsToServer(pfs) (pfs.flags&TO_SERVER_FLAG != 0)
class PacketFileWriter {
public:
PacketFileWriter(bool force_flush);
~PacketFileWriter();
bool OpenFile(const char *name);
void CloseFile();
void WritePacket(uint16 eq_op, uint32 packlen, const unsigned char *packet, bool to_server, const struct timeval &tv);
static bool SetPacketStamp(const char *file, uint32 stamp);
protected:
bool _WriteBlock(uint16 eq_op, const void *d, uint16 len, bool to_server, const struct timeval &tv);
//gzFile out;
FILE *out;
bool force_flush;
};
class PacketFileReader {
public:
PacketFileReader();
virtual bool OpenFile(const char *name) = 0;
virtual void CloseFile() = 0;
virtual bool ResetFile() = 0; //aka rewind
virtual bool ReadPacket(uint16 &eq_op, uint32 &packlen, unsigned char *packet, bool &to_server, struct timeval &tv) = 0;
time_t GetStamp() { return(time_t(packet_file_stamp)); }
//factory method to open the right packet file.
static PacketFileReader *OpenPacketFile(const char *name);
protected:
uint32 packet_file_stamp;
};
class OldPacketFileReader : public PacketFileReader {
public:
OldPacketFileReader();
virtual ~OldPacketFileReader();
bool OpenFile(const char *name);
void CloseFile();
bool ResetFile(); //aka rewind
bool ReadPacket(uint16 &eq_op, uint32 &packlen, unsigned char *packet, bool &to_server, struct timeval &tv);
time_t GetStamp() { return(time_t(packet_file_stamp)); }
protected:
//gzFile in;
FILE *in;
};
class NewPacketFileReader: public PacketFileReader {
public:
NewPacketFileReader();
virtual ~NewPacketFileReader();
bool OpenFile(const char *name);
void CloseFile();
bool ResetFile(); //aka rewind
bool ReadPacket(uint16 &eq_op, uint32 &packlen, unsigned char *packet, bool &to_server, struct timeval &tv);
time_t GetStamp() { return(time_t(packet_file_stamp)); }
protected:
//gzFile in;
FILE *in;
};
#endif
+1 -1
View File
@@ -5053,7 +5053,7 @@ namespace RoF2
//sprintf(hdr.unknown000, "06e0002Y1W00");
snprintf(hdr.unknown000, sizeof(hdr.unknown000), "%012d", item->ID);
snprintf(hdr.unknown000, sizeof(hdr.unknown000), "%016d", item->ID);
hdr.stacksize = stackable ? charges : 1;
hdr.unknown004 = 0;
+4 -3
View File
@@ -2865,7 +2865,7 @@ struct SetRunMode_Struct {
};
// EnvDamage is EnvDamage2 without a few bytes at the end.
// Size: 37 bytes
// Size: 39 bytes
struct EnvDamage2_Struct {
/*0000*/ uint32 id;
/*0004*/ uint16 unknown4;
@@ -2877,7 +2877,8 @@ struct EnvDamage2_Struct {
/*0031*/ uint16 unknown31; // New to Underfoot - Seen 66
/*0033*/ uint16 constant; // Always FFFF
/*0035*/ uint16 unknown35;
/*0037*/
/*0037*/ uint16 unknown37;
/*0039*/
};
//Bazaar Stuff
@@ -4352,7 +4353,7 @@ struct RoF2SlotStruct
struct ItemSerializationHeader
{
/*000*/ char unknown000[13]; // New for HoT. Looks like a string.
/*000*/ char unknown000[17]; // New for HoT. Looks like a string.
/*017*/ uint32 stacksize;
/*021*/ uint32 unknown004;
/*025*/ uint8 slot_type; // 0 = normal, 1 = bank, 2 = shared bank, 9 = merchant, 20 = ?
+6 -3
View File
@@ -47,6 +47,7 @@ const ProcLauncher::ProcRef ProcLauncher::ProcError = -1;
ProcLauncher::ProcLauncher()
{
_eqp
#ifndef WIN32
if(signal(SIGCHLD, ProcLauncher::HandleSigChild) == SIG_ERR)
fprintf(stderr, "Unable to register child signal handler. Thats bad.");
@@ -55,6 +56,7 @@ ProcLauncher::ProcLauncher()
}
void ProcLauncher::Process() {
_eqp
#ifdef _WINDOWS
std::map<ProcRef, Spec *>::iterator cur, end, tmp;
cur = m_running.begin();
@@ -108,7 +110,7 @@ void ProcLauncher::Process() {
}
void ProcLauncher::ProcessTerminated(std::map<ProcRef, Spec *>::iterator &it) {
_eqp
if(it->second->handler != nullptr)
it->second->handler->OnTerminate(it->first, it->second);
@@ -121,6 +123,7 @@ void ProcLauncher::ProcessTerminated(std::map<ProcRef, Spec *>::iterator &it) {
}
ProcLauncher::ProcRef ProcLauncher::Launch(Spec *&to_launch) {
_eqp
//consume the pointer
Spec *it = to_launch;
to_launch = nullptr;
@@ -275,6 +278,7 @@ ProcLauncher::ProcRef ProcLauncher::Launch(Spec *&to_launch) {
//if graceful is true, we try to be nice about it if possible
bool ProcLauncher::Terminate(const ProcRef &proc, bool graceful) {
_eqp
//we are only willing to kill things we started...
std::map<ProcRef, Spec *>::iterator res = m_running.find(proc);
if(res == m_running.end())
@@ -301,6 +305,7 @@ bool ProcLauncher::Terminate(const ProcRef &proc, bool graceful) {
}
void ProcLauncher::TerminateAll(bool final) {
_eqp
if(!final) {
//send a nice terminate to each process, with intention of waiting for them
std::map<ProcRef, Spec *>::iterator cur, end;
@@ -333,8 +338,6 @@ void ProcLauncher::HandleSigChild(int signum) {
}
#endif
ProcLauncher::Spec::Spec() {
handler = nullptr;
}
-92
View File
@@ -1,92 +0,0 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2004 EQEMu Development Team (http://eqemulator.net)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PROFILER_H
#define PROFILER_H
#ifdef EQPROFILE
#include "../common/rdtsc.h"
#include "../common/types.h"
class ScopedProfiler;
class GeneralProfiler {
friend class ScopedProfiler;
public:
inline GeneralProfiler(unsigned int _count) {
count = _count;
timers = new RDTSC_Collector[count];
}
inline virtual ~GeneralProfiler() {
safe_delete_array(timers);
}
inline double getTotalDuration(unsigned int id) {
return(id<count? timers[id].getTotalDuration() : 0);
}
inline double getAverage(unsigned int id) {
return(id<count? timers[id].getAverage() : 0);
}
inline unsigned long long getTicks(unsigned int id) {
return(id<count? timers[id].getTicks() : 0);
}
inline unsigned long long getTotalTicks(unsigned int id) {
return(id<count? timers[id].getTotalTicks() : 0);
}
inline unsigned long long getCount(unsigned int id) {
return(id<count? timers[id].getCount() : 0);
}
inline void reset() {
unsigned int r;
RDTSC_Collector *cur = timers;
for(r = 0; r < count; r++, cur++)
cur->reset();
}
RDTSC_Collector *timers;
unsigned int count;
};
class ScopedProfiler {
public:
inline ScopedProfiler(RDTSC_Collector *c) {
_it = c;
c->start();
}
inline ~ScopedProfiler() {
_it->stop();
}
protected:
RDTSC_Collector *_it;
};
#define _GP(obj, pkg, name) ScopedProfiler __eqemu_profiler(&obj.timers[pkg::name])
#else // else !EQPROFILE
//no profiling, dummy functions
#define _GP(obj, pkg, name) ;
#endif
#endif
-3
View File
@@ -175,7 +175,6 @@ bool PersistentTimer::Store(Database *db) {
}
bool PersistentTimer::Clear(Database *db) {
std::string query = StringFormat("DELETE FROM timers "
"WHERE char_id = %lu AND type = %u ",
(unsigned long)_char_id, _type);
@@ -416,7 +415,6 @@ PersistentTimer *PTimerList::Get(pTimerType type) {
}
void PTimerList::ToVector(std::vector< std::pair<pTimerType, PersistentTimer *> > &out) {
std::pair<pTimerType, PersistentTimer *> p;
std::map<pTimerType, PersistentTimer *>::iterator s;
@@ -432,7 +430,6 @@ void PTimerList::ToVector(std::vector< std::pair<pTimerType, PersistentTimer *>
}
bool PTimerList::ClearOffline(Database *db, uint32 char_id, pTimerType type) {
std::string query = StringFormat("DELETE FROM timers WHERE char_id=%lu AND type=%u ",(unsigned long)char_id, type);
#ifdef DEBUG_PTIMERS
-167
View File
@@ -1,167 +0,0 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rdtsc.h"
#include "types.h"
#ifdef _WINDOWS
#include <sys/timeb.h>
#include "../common/timer.h"
#else
#include <unistd.h>
#include <sys/time.h>
#endif
#ifdef i386
#define USE_RDTSC
#endif
bool RDTSC_Timer::_inited = false;
int64 RDTSC_Timer::_ticsperms = 0;
RDTSC_Timer::RDTSC_Timer() {
if(!_inited) {
//find our clock rate
RDTSC_Timer::init();
}
_start = 0;
_end = 0;
}
RDTSC_Timer::RDTSC_Timer(bool start_it) {
if(!_inited) {
//find our clock rate
RDTSC_Timer::init();
}
if(start_it)
start();
else {
_start = 0;
_end = 0;
}
}
int64 RDTSC_Timer::rdtsc() {
int64 res = 0;
#ifdef USE_RDTSC
#ifndef WIN64
#ifdef WIN32
//untested!
unsigned long highw, loww;
__asm {
push eax
push edx
rdtsc
mov highw, eax
mov loww, edx
pop edx
pop eax
}
res = ((int64)highw)<<32 | loww;
#else
//gnu version
__asm__ __volatile__ ("rdtsc" : "=A" (res));
#endif
#else
//fall back to get time of day
timeval t;
gettimeofday(&t, nullptr);
res = ((int64)t.tv_sec) * 1000 + t.tv_usec;
#endif
#endif
return(res);
}
void RDTSC_Timer::init() {
#ifdef USE_RDTSC
int64 before, after, sum;
int r;
sum = 0;
// run an average to increase accuracy of clock rate
for(r = 0; r < CALIBRATE_LOOPS; r++) {
before = rdtsc();
//sleep a know duration to figure out clock rate
#ifdef _WINDOWS
Sleep(SLEEP_TIME);
#else
usleep(SLEEP_TIME * 1000); //ms * 1000
#endif
after = rdtsc();
sum += after - before;
}
//ticks per sleep / ms per sleep
_ticsperms = (sum / CALIBRATE_LOOPS) / SLEEP_TIME;
#else
//if using gettimeofday, this is fixed at 1000
_ticsperms = 1000;
#endif
// printf("Tics per milisecond: %llu \n", _ticsperms);
_inited = true; //only want to do this once
}
//start the timer
void RDTSC_Timer::start() {
_start = rdtsc();
_end = 0;
}
//stop the timer
void RDTSC_Timer::stop() {
_end = rdtsc();
}
//calculate the elapsed duration
double RDTSC_Timer::getDuration() {
return(((double)(getTicks())) / double(_ticsperms));
}
RDTSC_Collector::RDTSC_Collector() : RDTSC_Timer() {
reset();
}
RDTSC_Collector::RDTSC_Collector(bool start_it) : RDTSC_Timer(start_it) {
reset();
}
void RDTSC_Collector::stop() {
RDTSC_Timer::stop();
_sum += RDTSC_Timer::getTicks();
_count++;
}
//calculate the elapsed duration
double RDTSC_Collector::getTotalDuration() {
return(((double)(getTotalTicks())) / double(_ticsperms));
}
double RDTSC_Collector::getAverage() {
return(((double)(getTotalTicks())) / double(_ticsperms * _count));
}
void RDTSC_Collector::reset() {
_sum = 0;
_count = 0;
}
-86
View File
@@ -1,86 +0,0 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef RDTSC_H
#define RDTSC_H
#define CALIBRATE_LOOPS 3
#define SLEEP_TIME 10 //in ms
/*
This class implementes the highest possibly prescision timer
which is avaliable on the current archetecture.
On intel, this uses the rdtsc instruction to get the actual
clock cycle count, and elsewhere it falls back to gettimeofday
All calculations are carried out in 64 bit integers.
*/
#include "types.h"
class RDTSC_Timer {
public:
RDTSC_Timer();
RDTSC_Timer(bool start_it);
void start(); //start the timer
virtual void stop(); //stop the timer
double getDuration(); //returns the number of miliseconds elapsed
//access functions
int64 getTicks() { return(_end - _start); }
static int64 ticksPerMS() { return(_ticsperms); }
protected:
static int64 rdtsc();
int64 _start;
int64 _end;
protected:
static void init();
static bool _inited;
static int64 _ticsperms;
};
//this is a timer which can be started and stoped many times.
//each time it contributes its counter to a sum, whic is used
//to find net duration.
class RDTSC_Collector : public RDTSC_Timer {
public:
RDTSC_Collector();
RDTSC_Collector(bool start_it);
void reset();
void stop(); //stop the timer
double getTotalDuration(); //returns the number of miliseconds elapsed
double getAverage();
int64 getTotalTicks() { return(_sum); }
int64 getCount() { return(_count); }
protected:
int64 _sum;
int64 _count;
};
#endif
+3 -1
View File
@@ -102,6 +102,7 @@ RULE_INT ( Character, BaseInstrumentSoftCap, 36) // Softcap for instrument mods,
RULE_INT ( Character, BaseRunSpeedCap, 158) // Base Run Speed Cap, on live it's 158% which will give you a runspeed of 1.580 hard capped to 225.
RULE_INT ( Character, OrnamentationAugmentType, 20) //Ornamentation Augment Type
RULE_REAL(Character, EnvironmentDamageMulipliter, 1)
RULE_BOOL(Character, UnmemSpellsOnDeath, true)
RULE_CATEGORY_END()
RULE_CATEGORY( Mercs )
@@ -299,7 +300,7 @@ RULE_INT ( Spells, MaxCastTimeReduction, 50) //Max percent your spell cast time
RULE_INT ( Spells, RootBreakFromSpells, 55) //Chance for root to break when cast on.
RULE_INT ( Spells, DeathSaveCharismaMod, 3) //Determines how much charisma effects chance of death save firing.
RULE_INT ( Spells, DivineInterventionHeal, 8000) //Divine intervention heal amount.
RULE_BOOL ( Spells, AdditiveBonusValues, false) //Allow certain bonuses to be calculated by adding together the value from each item, instead of taking the highest value. (ie Add together all Cleave Effects)
RULE_INT ( Spells, AdditiveBonusWornType, 0) //Calc worn bonuses to add together (instead of taking highest) if set to THIS worn type. (2=Will covert live items automatically)
RULE_BOOL ( Spells, UseCHAScribeHack, false) //ScribeSpells and TrainDiscs quest functions will ignore entries where field 12 is CHA. What's the best way to do this?
RULE_BOOL ( Spells, BuffLevelRestrictions, true) //Buffs will not land on low level toons like live
RULE_INT ( Spells, RootBreakCheckChance, 70) //Determines chance for a root break check to occur each buff tick.
@@ -328,6 +329,7 @@ RULE_BOOL ( Spells, Jun182014HundredHandsRevamp, false) // this should be true f
RULE_BOOL ( Spells, SwarmPetTargetLock, false) // Use old method of swarm pets target locking till target dies then despawning.
RULE_BOOL ( Spells, NPC_UseFocusFromSpells, true) // Allow npcs to use most spell derived focus effects.
RULE_BOOL ( Spells, NPC_UseFocusFromItems, false) // Allow npcs to use most item derived focus effects.
RULE_BOOL ( Spells, UseAdditiveFocusFromWornSlot, false) // Allows an additive focus effect to be calculated from worn slot.
RULE_CATEGORY_END()
RULE_CATEGORY( Combat )
+62 -9
View File
@@ -43,6 +43,7 @@ SharedDatabase::~SharedDatabase() {
bool SharedDatabase::SetHideMe(uint32 account_id, uint8 hideme)
{
_eqp
std::string query = StringFormat("UPDATE account SET hideme = %i WHERE id = %i", hideme, account_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -54,6 +55,7 @@ bool SharedDatabase::SetHideMe(uint32 account_id, uint8 hideme)
uint8 SharedDatabase::GetGMSpeed(uint32 account_id)
{
_eqp
std::string query = StringFormat("SELECT gmspeed FROM account WHERE id = '%i'", account_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -70,6 +72,7 @@ uint8 SharedDatabase::GetGMSpeed(uint32 account_id)
bool SharedDatabase::SetGMSpeed(uint32 account_id, uint8 gmspeed)
{
_eqp
std::string query = StringFormat("UPDATE account SET gmspeed = %i WHERE id = %i", gmspeed, account_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -80,6 +83,7 @@ bool SharedDatabase::SetGMSpeed(uint32 account_id, uint8 gmspeed)
}
uint32 SharedDatabase::GetTotalTimeEntitledOnAccount(uint32 AccountID) {
_eqp
uint32 EntitledTime = 0;
std::string query = StringFormat("SELECT `time_played` FROM `character_data` WHERE `account_id` = %u", AccountID);
auto results = QueryDatabase(query);
@@ -91,6 +95,7 @@ uint32 SharedDatabase::GetTotalTimeEntitledOnAccount(uint32 AccountID) {
bool SharedDatabase::SaveCursor(uint32 char_id, std::list<ItemInst*>::const_iterator &start, std::list<ItemInst*>::const_iterator &end)
{
_eqp
// Delete cursor items
std::string query = StringFormat("DELETE FROM inventory WHERE charid = %i "
"AND ((slotid >= 8000 AND slotid <= 8999) "
@@ -118,6 +123,7 @@ bool SharedDatabase::SaveCursor(uint32 char_id, std::list<ItemInst*>::const_iter
bool SharedDatabase::VerifyInventory(uint32 account_id, int16 slot_id, const ItemInst* inst)
{
_eqp
// Delete cursor items
std::string query = StringFormat("SELECT itemid, charges FROM sharedbank "
"WHERE acctid = %d AND slotid = %d",
@@ -150,7 +156,7 @@ bool SharedDatabase::VerifyInventory(uint32 account_id, int16 slot_id, const Ite
}
bool SharedDatabase::SaveInventory(uint32 char_id, const ItemInst* inst, int16 slot_id) {
_eqp
// If we never save tribute slots..how are we to ever benefit from them!!? The client
// object is destroyed upon zoning - including its inventory object..and if tributes
// don't exist in the database, then they will never be loaded when the new client
@@ -177,6 +183,7 @@ bool SharedDatabase::SaveInventory(uint32 char_id, const ItemInst* inst, int16 s
}
bool SharedDatabase::UpdateInventorySlot(uint32 char_id, const ItemInst* inst, int16 slot_id) {
_eqp
// need to check 'inst' argument for valid pointer
uint32 augslot[EmuConstants::ITEM_COMMON_SIZE] = { NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM };
@@ -222,6 +229,7 @@ bool SharedDatabase::UpdateInventorySlot(uint32 char_id, const ItemInst* inst, i
}
bool SharedDatabase::UpdateSharedBankSlot(uint32 char_id, const ItemInst* inst, int16 slot_id) {
_eqp
// need to check 'inst' argument for valid pointer
uint32 augslot[EmuConstants::ITEM_COMMON_SIZE] = { NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM };
@@ -267,6 +275,7 @@ bool SharedDatabase::UpdateSharedBankSlot(uint32 char_id, const ItemInst* inst,
}
bool SharedDatabase::DeleteInventorySlot(uint32 char_id, int16 slot_id) {
_eqp
// Delete item
std::string query = StringFormat("DELETE FROM inventory WHERE charid = %i AND slotid = %i", char_id, slot_id);
@@ -292,6 +301,7 @@ bool SharedDatabase::DeleteInventorySlot(uint32 char_id, int16 slot_id) {
}
bool SharedDatabase::DeleteSharedBankSlot(uint32 char_id, int16 slot_id) {
_eqp
// Delete item
uint32 account_id = GetAccountIDByChar(char_id);
@@ -321,6 +331,7 @@ bool SharedDatabase::DeleteSharedBankSlot(uint32 char_id, int16 slot_id) {
int32 SharedDatabase::GetSharedPlatinum(uint32 account_id)
{
_eqp
std::string query = StringFormat("SELECT sharedplat FROM account WHERE id = '%i'", account_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -336,6 +347,7 @@ int32 SharedDatabase::GetSharedPlatinum(uint32 account_id)
}
bool SharedDatabase::SetSharedPlatinum(uint32 account_id, int32 amount_to_add) {
_eqp
std::string query = StringFormat("UPDATE account SET sharedplat = sharedplat + %i WHERE id = %i", amount_to_add, account_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -346,7 +358,7 @@ bool SharedDatabase::SetSharedPlatinum(uint32 account_id, int32 amount_to_add) {
}
bool SharedDatabase::SetStartingItems(PlayerProfile_Struct* pp, Inventory* inv, uint32 si_race, uint32 si_class, uint32 si_deity, uint32 si_current_zone, char* si_name, int admin_level) {
_eqp
const Item_Struct* myitem;
std::string query = StringFormat("SELECT itemid, item_charges, slot FROM starting_items "
@@ -384,6 +396,7 @@ bool SharedDatabase::SetStartingItems(PlayerProfile_Struct* pp, Inventory* inv,
// Retrieve shared bank inventory based on either account or character
bool SharedDatabase::GetSharedBank(uint32 id, Inventory *inv, bool is_charid)
{
_eqp
std::string query;
if (is_charid)
@@ -484,6 +497,7 @@ bool SharedDatabase::GetSharedBank(uint32 id, Inventory *inv, bool is_charid)
// Overloaded: Retrieve character inventory based on character id
bool SharedDatabase::GetInventory(uint32 char_id, Inventory *inv)
{
_eqp
// Retrieve character inventory
std::string query =
StringFormat("SELECT slotid, itemid, charges, color, augslot1, augslot2, augslot3, augslot4, augslot5, "
@@ -627,6 +641,7 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory *inv)
// Overloaded: Retrieve character inventory based on account_id and character name
bool SharedDatabase::GetInventory(uint32 account_id, char *name, Inventory *inv)
{
_eqp
// Retrieve character inventory
std::string query =
StringFormat("SELECT slotid, itemid, charges, color, augslot1, "
@@ -736,6 +751,7 @@ bool SharedDatabase::GetInventory(uint32 account_id, char *name, Inventory *inv)
std::map<uint32, uint32> SharedDatabase::GetItemRecastTimestamps(uint32 char_id)
{
_eqp
std::map<uint32, uint32> timers;
std::string query = StringFormat("SELECT recast_type,timestamp FROM character_item_recast WHERE id=%u", char_id);
auto results = QueryDatabase(query);
@@ -749,6 +765,7 @@ std::map<uint32, uint32> SharedDatabase::GetItemRecastTimestamps(uint32 char_id)
uint32 SharedDatabase::GetItemRecastTimestamp(uint32 char_id, uint32 recast_type)
{
_eqp
std::string query = StringFormat("SELECT timestamp FROM character_item_recast WHERE id=%u AND recast_type=%u",
char_id, recast_type);
auto results = QueryDatabase(query);
@@ -761,6 +778,7 @@ uint32 SharedDatabase::GetItemRecastTimestamp(uint32 char_id, uint32 recast_type
void SharedDatabase::ClearOldRecastTimestamps(uint32 char_id)
{
_eqp
// This actually isn't strictly live-like. Live your recast timestamps are forever
std::string query =
StringFormat("DELETE FROM character_item_recast WHERE id = %u and timestamp < UNIX_TIMESTAMP()", char_id);
@@ -769,6 +787,7 @@ void SharedDatabase::ClearOldRecastTimestamps(uint32 char_id)
void SharedDatabase::GetItemsCount(int32 &item_count, uint32 &max_id)
{
_eqp
item_count = -1;
max_id = 0;
@@ -791,6 +810,7 @@ void SharedDatabase::GetItemsCount(int32 &item_count, uint32 &max_id)
}
bool SharedDatabase::LoadItems() {
_eqp
if(items_mmf) {
return true;
}
@@ -822,6 +842,7 @@ bool SharedDatabase::LoadItems() {
}
void SharedDatabase::LoadItems(void *data, uint32 size, int32 items, uint32 max_item_id) {
_eqp
EQEmu::FixedMemoryHashSet<Item_Struct> hash(reinterpret_cast<uint8*>(data), size, items, max_item_id);
char ndbuffer[4];
@@ -1079,6 +1100,7 @@ void SharedDatabase::LoadItems(void *data, uint32 size, int32 items, uint32 max_
}
const Item_Struct* SharedDatabase::GetItem(uint32 id) {
_eqp
if (id == 0)
{
return nullptr;
@@ -1098,6 +1120,7 @@ const Item_Struct* SharedDatabase::GetItem(uint32 id) {
}
const Item_Struct* SharedDatabase::IterateItems(uint32* id) {
_eqp
if(!items_hash || !id) {
return nullptr;
}
@@ -1119,6 +1142,7 @@ const Item_Struct* SharedDatabase::IterateItems(uint32* id) {
std::string SharedDatabase::GetBook(const char *txtfile)
{
_eqp
char txtfile2[20];
std::string txtout;
strcpy(txtfile2, txtfile);
@@ -1143,6 +1167,7 @@ std::string SharedDatabase::GetBook(const char *txtfile)
}
void SharedDatabase::GetFactionListInfo(uint32 &list_count, uint32 &max_lists) {
_eqp
list_count = 0;
max_lists = 0;
@@ -1158,10 +1183,11 @@ void SharedDatabase::GetFactionListInfo(uint32 &list_count, uint32 &max_lists) {
auto row = results.begin();
list_count = static_cast<uint32>(atoul(row[0]));
max_lists = static_cast<uint32>(atoul(row[1]));
max_lists = static_cast<uint32>(atoul(row[1] ? row[1] : "0"));
}
const NPCFactionList* SharedDatabase::GetNPCFactionEntry(uint32 id) {
_eqp
if(!faction_hash) {
return nullptr;
}
@@ -1174,6 +1200,7 @@ const NPCFactionList* SharedDatabase::GetNPCFactionEntry(uint32 id) {
}
void SharedDatabase::LoadNPCFactionLists(void *data, uint32 size, uint32 list_count, uint32 max_lists) {
_eqp
EQEmu::FixedMemoryHashSet<NPCFactionList> hash(reinterpret_cast<uint8*>(data), size, list_count, max_lists);
NPCFactionList faction;
@@ -1223,6 +1250,7 @@ void SharedDatabase::LoadNPCFactionLists(void *data, uint32 size, uint32 list_co
}
bool SharedDatabase::LoadNPCFactionLists() {
_eqp
if(faction_hash) {
return true;
}
@@ -1235,9 +1263,6 @@ bool SharedDatabase::LoadNPCFactionLists() {
uint32 list_count = 0;
uint32 max_lists = 0;
GetFactionListInfo(list_count, max_lists);
if(list_count == 0) {
EQ_EXCEPT("SharedDatabase", "Database returned no result");
}
uint32 size = static_cast<uint32>(EQEmu::FixedMemoryHashSet<NPCFactionList>::estimated_size(
list_count, max_lists));
@@ -1258,6 +1283,7 @@ bool SharedDatabase::LoadNPCFactionLists() {
// Create appropriate ItemInst class
ItemInst* SharedDatabase::CreateItem(uint32 item_id, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, uint32 aug6, uint8 attuned)
{
_eqp
const Item_Struct* item = nullptr;
ItemInst* inst = nullptr;
@@ -1287,6 +1313,7 @@ ItemInst* SharedDatabase::CreateItem(uint32 item_id, int16 charges, uint32 aug1,
// Create appropriate ItemInst class
ItemInst* SharedDatabase::CreateItem(const Item_Struct* item, int16 charges, uint32 aug1, uint32 aug2, uint32 aug3, uint32 aug4, uint32 aug5, uint32 aug6, uint8 attuned)
{
_eqp
ItemInst* inst = nullptr;
if (item) {
inst = CreateBaseItem(item, charges);
@@ -1310,6 +1337,7 @@ ItemInst* SharedDatabase::CreateItem(const Item_Struct* item, int16 charges, uin
}
ItemInst* SharedDatabase::CreateBaseItem(const Item_Struct* item, int16 charges) {
_eqp
ItemInst* inst = nullptr;
if (item) {
// if maxcharges is -1 that means it is an unlimited use item.
@@ -1336,6 +1364,7 @@ ItemInst* SharedDatabase::CreateBaseItem(const Item_Struct* item, int16 charges)
}
int32 SharedDatabase::DeleteStalePlayerCorpses() {
_eqp
if(RuleB(Zone, EnableShadowrest)) {
std::string query = StringFormat(
"UPDATE `character_corpses` SET `is_buried` = 1 WHERE `is_buried` = 0 AND "
@@ -1358,7 +1387,8 @@ int32 SharedDatabase::DeleteStalePlayerCorpses() {
return results.RowsAffected();
}
bool SharedDatabase::GetCommandSettings(std::map<std::string,uint8> &commands) {
bool SharedDatabase::GetCommandSettings(std::map<std::string, uint8> &commands) {
_eqp
const std::string query = "SELECT command, access FROM commands";
auto results = QueryDatabase(query);
@@ -1375,6 +1405,7 @@ bool SharedDatabase::GetCommandSettings(std::map<std::string,uint8> &commands) {
}
bool SharedDatabase::LoadSkillCaps() {
_eqp
if(skill_caps_mmf)
return true;
@@ -1401,6 +1432,7 @@ bool SharedDatabase::LoadSkillCaps() {
}
void SharedDatabase::LoadSkillCaps(void *data) {
_eqp
uint32 class_count = PLAYER_CLASS_COUNT;
uint32 skill_count = HIGHEST_SKILL + 1;
uint32 level_count = HARD_LEVEL_CAP + 1;
@@ -1428,6 +1460,7 @@ void SharedDatabase::LoadSkillCaps(void *data) {
}
uint16 SharedDatabase::GetSkillCap(uint8 Class_, SkillUseTypes Skill, uint8 Level) {
_eqp
if(!skill_caps_mmf) {
return 0;
}
@@ -1457,6 +1490,7 @@ uint16 SharedDatabase::GetSkillCap(uint8 Class_, SkillUseTypes Skill, uint8 Leve
}
uint8 SharedDatabase::GetTrainLevel(uint8 Class_, SkillUseTypes Skill, uint8 Level) {
_eqp
if(!skill_caps_mmf) {
return 0;
}
@@ -1506,6 +1540,7 @@ uint8 SharedDatabase::GetTrainLevel(uint8 Class_, SkillUseTypes Skill, uint8 Lev
}
void SharedDatabase::LoadDamageShieldTypes(SPDat_Spell_Struct* sp, int32 iMaxSpellID) {
_eqp
std::string query = StringFormat("SELECT `spellid`, `type` FROM `damageshieldtypes` WHERE `spellid` > 0 "
"AND `spellid` <= %i", iMaxSpellID);
@@ -1523,10 +1558,12 @@ void SharedDatabase::LoadDamageShieldTypes(SPDat_Spell_Struct* sp, int32 iMaxSpe
}
const EvolveInfo* SharedDatabase::GetEvolveInfo(uint32 loregroup) {
_eqp
return nullptr; // nothing here for now... database and/or sharemem pulls later
}
int SharedDatabase::GetMaxSpellID() {
_eqp
std::string query = "SELECT MAX(id) FROM spells_new";
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -1539,6 +1576,7 @@ int SharedDatabase::GetMaxSpellID() {
}
void SharedDatabase::LoadSpells(void *data, int max_spells) {
_eqp
SPDat_Spell_Struct *sp = reinterpret_cast<SPDat_Spell_Struct*>(data);
const std::string query = "SELECT * FROM spells_new ORDER BY id ASC";
@@ -1701,6 +1739,7 @@ void SharedDatabase::LoadSpells(void *data, int max_spells) {
}
int SharedDatabase::GetMaxBaseDataLevel() {
_eqp
const std::string query = "SELECT MAX(level) FROM base_data";
auto results = QueryDatabase(query);
if (!results.Success()) {
@@ -1716,6 +1755,7 @@ int SharedDatabase::GetMaxBaseDataLevel() {
}
bool SharedDatabase::LoadBaseData() {
_eqp
if(base_data_mmf) {
return true;
}
@@ -1744,6 +1784,7 @@ bool SharedDatabase::LoadBaseData() {
}
void SharedDatabase::LoadBaseData(void *data, int max_level) {
_eqp
char *base_ptr = reinterpret_cast<char*>(data);
const std::string query = "SELECT * FROM base_data ORDER BY level, class ASC";
@@ -1793,6 +1834,7 @@ void SharedDatabase::LoadBaseData(void *data, int max_level) {
}
const BaseDataStruct* SharedDatabase::GetBaseData(int lvl, int cl) {
_eqp
if(!base_data_mmf) {
return nullptr;
}
@@ -1822,6 +1864,7 @@ const BaseDataStruct* SharedDatabase::GetBaseData(int lvl, int cl) {
}
void SharedDatabase::GetLootTableInfo(uint32 &loot_table_count, uint32 &max_loot_table, uint32 &loot_table_entries) {
_eqp
loot_table_count = 0;
max_loot_table = 0;
loot_table_entries = 0;
@@ -1837,11 +1880,12 @@ void SharedDatabase::GetLootTableInfo(uint32 &loot_table_count, uint32 &max_loot
auto row = results.begin();
loot_table_count = static_cast<uint32>(atoul(row[0]));
max_loot_table = static_cast<uint32>(atoul(row[1]));
max_loot_table = static_cast<uint32>(atoul(row[1] ? row[1] : "0"));
loot_table_entries = static_cast<uint32>(atoul(row[2]));
}
void SharedDatabase::GetLootDropInfo(uint32 &loot_drop_count, uint32 &max_loot_drop, uint32 &loot_drop_entries) {
_eqp
loot_drop_count = 0;
max_loot_drop = 0;
loot_drop_entries = 0;
@@ -1858,11 +1902,12 @@ void SharedDatabase::GetLootDropInfo(uint32 &loot_drop_count, uint32 &max_loot_d
auto row =results.begin();
loot_drop_count = static_cast<uint32>(atoul(row[0]));
max_loot_drop = static_cast<uint32>(atoul(row[1]));
max_loot_drop = static_cast<uint32>(atoul(row[1] ? row[1] : "0"));
loot_drop_entries = static_cast<uint32>(atoul(row[2]));
}
void SharedDatabase::LoadLootTables(void *data, uint32 size) {
_eqp
EQEmu::FixedMemoryVariableHashSet<LootTable_Struct> hash(reinterpret_cast<uint8*>(data), size);
uint8 loot_table[sizeof(LootTable_Struct) + (sizeof(LootTableEntries_Struct) * 128)];
@@ -1916,6 +1961,7 @@ void SharedDatabase::LoadLootTables(void *data, uint32 size) {
}
void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
_eqp
EQEmu::FixedMemoryVariableHashSet<LootDrop_Struct> hash(reinterpret_cast<uint8*>(data), size);
uint8 loot_drop[sizeof(LootDrop_Struct) + (sizeof(LootDropEntries_Struct) * 1260)];
@@ -1964,6 +2010,7 @@ void SharedDatabase::LoadLootDrops(void *data, uint32 size) {
}
bool SharedDatabase::LoadLoot() {
_eqp
if(loot_table_mmf || loot_drop_mmf)
return true;
@@ -1988,6 +2035,7 @@ bool SharedDatabase::LoadLoot() {
}
const LootTable_Struct* SharedDatabase::GetLootTable(uint32 loottable_id) {
_eqp
if(!loot_table_hash)
return nullptr;
@@ -2002,6 +2050,7 @@ const LootTable_Struct* SharedDatabase::GetLootTable(uint32 loottable_id) {
}
const LootDrop_Struct* SharedDatabase::GetLootDrop(uint32 lootdrop_id) {
_eqp
if(!loot_drop_hash)
return nullptr;
@@ -2016,6 +2065,7 @@ const LootDrop_Struct* SharedDatabase::GetLootDrop(uint32 lootdrop_id) {
}
void SharedDatabase::LoadCharacterInspectMessage(uint32 character_id, InspectMessage_Struct* message) {
_eqp
std::string query = StringFormat("SELECT `inspect_message` FROM `character_inspect_messages` WHERE `id` = %u LIMIT 1", character_id);
auto results = QueryDatabase(query);
auto row = results.begin();
@@ -2026,11 +2076,13 @@ void SharedDatabase::LoadCharacterInspectMessage(uint32 character_id, InspectMes
}
void SharedDatabase::SaveCharacterInspectMessage(uint32 character_id, const InspectMessage_Struct* message) {
_eqp
std::string query = StringFormat("REPLACE INTO `character_inspect_messages` (id, inspect_message) VALUES (%u, '%s')", character_id, EscapeString(message->text).c_str());
auto results = QueryDatabase(query);
}
void SharedDatabase::GetBotInspectMessage(uint32 botid, InspectMessage_Struct* message) {
_eqp
std::string query = StringFormat("SELECT BotInspectMessage FROM bots WHERE BotID = %i", botid);
auto results = QueryDatabase(query);
@@ -2047,6 +2099,7 @@ void SharedDatabase::GetBotInspectMessage(uint32 botid, InspectMessage_Struct* m
}
void SharedDatabase::SetBotInspectMessage(uint32 botid, const InspectMessage_Struct* message) {
_eqp
std::string msg = EscapeString(message->text);
std::string query = StringFormat("UPDATE bots SET BotInspectMessage = '%s' WHERE BotID = %i", msg.c_str(), botid);
QueryDatabase(query);
+15 -1
View File
@@ -64,6 +64,7 @@ const std::string vStringFormat(const char* format, va_list args)
const std::string StringFormat(const char* format, ...)
{
_eqp
va_list args;
va_start(args, format);
std::string output = vStringFormat(format,args);
@@ -71,7 +72,6 @@ const std::string StringFormat(const char* format, ...)
return output;
}
// normal strncpy doesnt put a null term on copied strings, this one does
// ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecrt/htm/_wcecrt_strncpy_wcsncpy.asp
char* strn0cpy(char* dest, const char* source, uint32 size) {
@@ -122,6 +122,7 @@ void MakeLowerString(const char *source, char *target) {
}
int MakeAnyLenString(char** ret, const char* format, ...) {
_eqp
int buf_len = 128;
int chars = -1;
va_list argptr, tmpargptr;
@@ -141,6 +142,7 @@ int MakeAnyLenString(char** ret, const char* format, ...) {
}
uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...) {
_eqp
if (*bufsize == 0)
*bufsize = 256;
if (*ret == 0)
@@ -259,6 +261,7 @@ bool atobool(const char* iBool) {
// removes the crap and turns the underscores into spaces.
char *CleanMobName(const char *in, char *out)
{
_eqp
unsigned i, j;
for(i = j = 0; i < strlen(in); i++)
@@ -313,6 +316,7 @@ const char *ConvertArrayF(float input, char *returnchar)
}
std::vector<std::string> SplitString(const std::string &str, char delim) {
_eqp
std::vector<std::string> ret;
std::stringstream ss(str);
std::string item;
@@ -325,6 +329,7 @@ std::vector<std::string> SplitString(const std::string &str, char delim) {
}
std::string EscapeString(const std::string &s) {
_eqp
std::string ret;
size_t sz = s.length();
@@ -362,6 +367,7 @@ std::string EscapeString(const std::string &s) {
}
std::string EscapeString(const char *src, size_t sz) {
_eqp
std::string ret;
for(size_t i = 0; i < sz; ++i) {
@@ -408,3 +414,11 @@ bool isAlphaNumeric(const char *text)
return true;
}
void find_replace(std::string& string_subject, const std::string& search_string, const std::string& replace_string) {
auto index = string_subject.find_first_of(search_string);
while (index != std::string::npos) {
string_subject.replace(index, index + 1, replace_string);
index = string_subject.find_first_of(search_string);
}
}
+18 -21
View File
@@ -23,37 +23,34 @@
#include "types.h"
const std::string vStringFormat(const char* format, va_list args);
const std::string StringFormat(const char* format, ...);
std::string EscapeString(const std::string &s);
std::string EscapeString(const char *src, size_t sz);
const char *MakeLowerString(const char *source);
void MakeLowerString(const char *source, char *target);
int MakeAnyLenString(char** ret, const char* format, ...);
uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...);
uint32 hextoi(const char* num);
uint64 hextoi64(const char* num);
bool atobool(const char* iBool);
char* strn0cpy(char* dest, const char* source, uint32 size);
// return value =true if entire string(source) fit, false if it was truncated
bool isAlphaNumeric(const char *text);
bool strn0cpyt(char* dest, const char* source, uint32 size);
char *CleanMobName(const char *in, char *out);
char *RemoveApostrophes(const char *s);
char* strn0cpy(char* dest, const char* source, uint32 size);
const char *ConvertArray(int input, char *returnchar);
const char *ConvertArrayF(float input, char *returnchar);
const char *MakeLowerString(const char *source);
const std::string StringFormat(const char* format, ...);
const std::string vStringFormat(const char* format, va_list args);
void RemoveApostrophes(std::string &s);
char *RemoveApostrophes(const char *s);
int MakeAnyLenString(char** ret, const char* format, ...);
std::string EscapeString(const char *src, size_t sz);
std::string EscapeString(const std::string &s);
std::vector<std::string> SplitString(const std::string &s, char delim);
bool isAlphaNumeric(const char *text);
uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const char* format, ...);
uint32 hextoi(const char* num);
uint64 hextoi64(const char* num);
void MakeLowerString(const char *source, char *target);
void RemoveApostrophes(std::string &s);
void find_replace(std::string& string_subject, const std::string& search_string, const std::string& replace_string);
#endif
+8
View File
@@ -11,6 +11,7 @@
//note: all encoders and decoders must be valid functions.
//so if you specify set_defaults=false
StructStrategy::StructStrategy() {
_eqp
int r;
for(r = 0; r < _maxEmuOpcode; r++) {
encoders[r] = PassEncoder;
@@ -19,6 +20,7 @@ StructStrategy::StructStrategy() {
}
void StructStrategy::Encode(EQApplicationPacket **p, std::shared_ptr<EQStream> dest, bool ack_req) const {
_eqp
if((*p)->GetOpcodeBypass() != 0) {
PassEncoder(p, dest, ack_req);
return;
@@ -30,6 +32,7 @@ void StructStrategy::Encode(EQApplicationPacket **p, std::shared_ptr<EQStream> d
}
void StructStrategy::Decode(EQApplicationPacket *p) const {
_eqp
EmuOpcode op = p->GetOpcode();
Decoder proc = decoders[op];
proc(p);
@@ -37,6 +40,7 @@ void StructStrategy::Decode(EQApplicationPacket *p) const {
void StructStrategy::ErrorEncoder(EQApplicationPacket **in_p, std::shared_ptr<EQStream> dest, bool ack_req) {
_eqp
EQApplicationPacket *p = *in_p;
*in_p = nullptr;
@@ -46,11 +50,13 @@ void StructStrategy::ErrorEncoder(EQApplicationPacket **in_p, std::shared_ptr<EQ
}
void StructStrategy::ErrorDecoder(EQApplicationPacket *p) {
_eqp
Log.Out(Logs::General, Logs::Netcode, "[STRUCTS] Error decoding opcode %s: no decoder provided. Invalidating.", OpcodeManager::EmuToName(p->GetOpcode()));
p->SetOpcode(OP_Unknown);
}
void StructStrategy::PassEncoder(EQApplicationPacket **p, std::shared_ptr<EQStream> dest, bool ack_req) {
_eqp
dest->FastQueuePacket(p, ack_req);
}
@@ -67,10 +73,12 @@ namespace StructStrategyFactory {
static std::map<EmuOpcode, const StructStrategy *> strategies;
void RegisterPatch(EmuOpcode first_opcode, const StructStrategy *structs) {
_eqp
strategies[first_opcode] = structs;
}
const StructStrategy *FindPatch(EmuOpcode first_opcode) {
_eqp
std::map<EmuOpcode, const StructStrategy *>::const_iterator res;
res = strategies.find(first_opcode);
if(res == strategies.end())
+33
View File
@@ -75,6 +75,7 @@ TCPConnection::TCPConnection(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 ir
rIP(irIP),
rPort(irPort)
{
_eqp
pState = TCPS_Connected;
pFree = false;
pEcho = false;
@@ -90,6 +91,7 @@ TCPConnection::TCPConnection(uint32 ID, SOCKET in_socket, uint32 irIP, uint16 ir
}
TCPConnection::~TCPConnection() {
_eqp
FinishDisconnect();
ClearBuffers();
if (ConnectionType == Outgoing) {
@@ -113,12 +115,14 @@ TCPConnection::~TCPConnection() {
}
void TCPConnection::SetState(State_t in_state) {
_eqp
MState.lock();
pState = in_state;
MState.unlock();
}
TCPConnection::State_t TCPConnection::GetState() const {
_eqp
State_t ret;
MState.lock();
ret = pState;
@@ -128,6 +132,7 @@ TCPConnection::State_t TCPConnection::GetState() const {
bool TCPConnection::GetSockName(char *host, uint16 *port)
{
_eqp
bool result=false;
LockMutex lock(&MState);
if (!Connected())
@@ -165,11 +170,13 @@ bool TCPConnection::GetSockName(char *host, uint16 *port)
}
void TCPConnection::Free() {
_eqp
Disconnect();
pFree = true;
}
bool TCPConnection::Send(const uchar* data, int32 size) {
_eqp
if (!Connected())
return false;
if (!size)
@@ -179,6 +186,7 @@ bool TCPConnection::Send(const uchar* data, int32 size) {
}
void TCPConnection::ServerSendQueuePushEnd(const uchar* data, int32 size) {
_eqp
MSendQueue.lock();
if (sendbuf == nullptr) {
sendbuf = new uchar[size];
@@ -198,6 +206,7 @@ void TCPConnection::ServerSendQueuePushEnd(const uchar* data, int32 size) {
}
void TCPConnection::ServerSendQueuePushEnd(uchar** data, int32 size) {
_eqp
MSendQueue.lock();
if (sendbuf == 0) {
sendbuf = *data;
@@ -221,6 +230,7 @@ void TCPConnection::ServerSendQueuePushEnd(uchar** data, int32 size) {
}
void TCPConnection::ServerSendQueuePushFront(uchar* data, int32 size) {
_eqp
MSendQueue.lock();
if (sendbuf == 0) {
sendbuf = new uchar[size];
@@ -240,6 +250,7 @@ void TCPConnection::ServerSendQueuePushFront(uchar* data, int32 size) {
}
bool TCPConnection::ServerSendQueuePop(uchar** data, int32* size) {
_eqp
bool ret;
if (!MSendQueue.trylock())
return false;
@@ -257,6 +268,7 @@ bool TCPConnection::ServerSendQueuePop(uchar** data, int32* size) {
}
bool TCPConnection::ServerSendQueuePopForce(uchar** data, int32* size) {
_eqp
bool ret;
MSendQueue.lock();
if (sendbuf) {
@@ -273,6 +285,7 @@ bool TCPConnection::ServerSendQueuePopForce(uchar** data, int32* size) {
}
char* TCPConnection::PopLine() {
_eqp
char* ret;
if (!MLineOutQueue.trylock())
return 0;
@@ -282,6 +295,7 @@ char* TCPConnection::PopLine() {
}
bool TCPConnection::LineOutQueuePush(char* line) {
_eqp
MLineOutQueue.lock();
LineOutQueue.push(line);
MLineOutQueue.unlock();
@@ -290,6 +304,7 @@ bool TCPConnection::LineOutQueuePush(char* line) {
void TCPConnection::FinishDisconnect() {
_eqp
MState.lock();
if (connection_socket != INVALID_SOCKET && connection_socket != 0) {
if (pState == TCPS_Connected || pState == TCPS_Disconnecting || pState == TCPS_Disconnected) {
@@ -314,6 +329,7 @@ void TCPConnection::FinishDisconnect() {
}
void TCPConnection::Disconnect() {
_eqp
MState.lock();
if(pState == TCPS_Connected || pState == TCPS_Connecting) {
pState = TCPS_Disconnecting;
@@ -322,6 +338,7 @@ void TCPConnection::Disconnect() {
}
bool TCPConnection::GetAsyncConnect() {
_eqp
bool ret;
MAsyncConnect.lock();
ret = pAsyncConnect;
@@ -330,6 +347,7 @@ bool TCPConnection::GetAsyncConnect() {
}
bool TCPConnection::SetAsyncConnect(bool iValue) {
_eqp
bool ret;
MAsyncConnect.lock();
ret = pAsyncConnect;
@@ -339,6 +357,7 @@ bool TCPConnection::SetAsyncConnect(bool iValue) {
}
bool TCPConnection::ConnectReady() const {
_eqp
State_t s = GetState();
if (s != TCPS_Ready && s != TCPS_Disconnected)
return(false);
@@ -346,6 +365,7 @@ bool TCPConnection::ConnectReady() const {
}
void TCPConnection::AsyncConnect(const char* irAddress, uint16 irPort) {
_eqp
safe_delete_array(charAsyncConnect);
charAsyncConnect = new char[strlen(irAddress) + 1];
strcpy(charAsyncConnect, irAddress);
@@ -353,6 +373,7 @@ void TCPConnection::AsyncConnect(const char* irAddress, uint16 irPort) {
}
void TCPConnection::AsyncConnect(uint32 irIP, uint16 irPort) {
_eqp
if (ConnectionType != Outgoing) {
// If this code runs, we got serious problems
// Crash and burn.
@@ -394,6 +415,7 @@ void TCPConnection::AsyncConnect(uint32 irIP, uint16 irPort) {
}
bool TCPConnection::Connect(const char* irAddress, uint16 irPort, char* errbuf) {
_eqp
if (errbuf)
errbuf[0] = 0;
uint32 tmpIP = ResolveIP(irAddress);
@@ -411,6 +433,7 @@ bool TCPConnection::Connect(const char* irAddress, uint16 irPort, char* errbuf)
}
bool TCPConnection::ConnectIP(uint32 in_ip, uint16 in_port, char* errbuf) {
_eqp
if (errbuf)
errbuf[0] = 0;
if (ConnectionType != Outgoing) {
@@ -499,6 +522,7 @@ bool TCPConnection::ConnectIP(uint32 in_ip, uint16 in_port, char* errbuf) {
}
void TCPConnection::ClearBuffers() {
_eqp
LockMutex lock1(&MSendQueue);
LockMutex lock3(&MRunLoop);
LockMutex lock4(&MState);
@@ -511,6 +535,7 @@ void TCPConnection::ClearBuffers() {
}
bool TCPConnection::CheckNetActive() {
_eqp
MState.lock();
if (pState == TCPS_Connected || pState == TCPS_Disconnecting) {
MState.unlock();
@@ -523,6 +548,7 @@ bool TCPConnection::CheckNetActive() {
/* This is always called from an IO thread. Either the server socket's thread, or a
* special thread we create when we make an outbound connection. */
bool TCPConnection::Process() {
_eqp
char errbuf[TCPConnection_ErrorBufferSize];
switch(GetState()) {
case TCPS_Ready:
@@ -594,6 +620,7 @@ bool TCPConnection::Process() {
}
bool TCPConnection::RecvData(char* errbuf) {
_eqp
if (errbuf)
errbuf[0] = 0;
if (!Connected()) {
@@ -666,16 +693,19 @@ bool TCPConnection::RecvData(char* errbuf) {
bool TCPConnection::GetEcho() {
_eqp
bool ret;
ret = pEcho;
return ret;
}
void TCPConnection::SetEcho(bool iValue) {
_eqp
pEcho = iValue;
}
bool TCPConnection::ProcessReceivedData(char* errbuf) {
_eqp
if (errbuf)
errbuf[0] = 0;
if (!recvbuf)
@@ -810,6 +840,7 @@ bool TCPConnection::ProcessReceivedData(char* errbuf) {
}
bool TCPConnection::SendData(bool &sent_something, char* errbuf) {
_eqp
if (errbuf)
errbuf[0] = 0;
/************ Get first send packet on queue and send it! ************/
@@ -891,6 +922,7 @@ bool TCPConnection::SendData(bool &sent_something, char* errbuf) {
}
ThreadReturnType TCPConnection::TCPConnectionLoop(void* tmp) {
_eqp
#ifdef _WINDOWS
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
#endif
@@ -933,6 +965,7 @@ ThreadReturnType TCPConnection::TCPConnectionLoop(void* tmp) {
}
bool TCPConnection::RunLoop() {
_eqp
bool ret;
MRunLoop.lock();
ret = pRunLoop;
+9 -3
View File
@@ -24,18 +24,22 @@
Timeoutable::Timeoutable(uint32 check_frequency)
: next_check(check_frequency)
{
_eqp
timeout_manager.AddMember(this);
}
Timeoutable::~Timeoutable() {
_eqp
timeout_manager.DeleteMember(this);
}
TimeoutManager::TimeoutManager() {
_eqp
}
void TimeoutManager::CheckTimeouts() {
_eqp
std::vector<Timeoutable *>::iterator cur,end;
cur = members.begin();
end = members.end();
@@ -43,7 +47,7 @@ void TimeoutManager::CheckTimeouts() {
Timeoutable *it = *cur;
if(it->next_check.Check()) {
#ifdef TIMEOUT_DEBUG
Log.Out(Logs::General, Logs::None,, "Checking timeout on 0x%x\n", it);
Log.Out(Logs::General, Logs::None, "Checking timeout on 0x%x\n", it);
#endif
it->CheckTimeout();
}
@@ -52,19 +56,21 @@ void TimeoutManager::CheckTimeouts() {
//methods called by Timeoutable objects:
void TimeoutManager::AddMember(Timeoutable *who) {
_eqp
if(who == nullptr)
return;
DeleteMember(who); //just in case... prolly not needed.
members.push_back(who);
#ifdef TIMEOUT_DEBUG
Log.Out(Logs::General, Logs::None,, "Adding timeoutable 0x%x\n", who);
Log.Out(Logs::General, Logs::None, "Adding timeoutable 0x%x\n", who);
#endif
}
void TimeoutManager::DeleteMember(Timeoutable *who) {
_eqp
#ifdef TIMEOUT_DEBUG
Log.Out(Logs::General, Logs::None,, "Removing timeoutable 0x%x\n", who);
Log.Out(Logs::General, Logs::None, "Removing timeoutable 0x%x\n", who);
#endif
std::vector<Timeoutable *>::iterator cur,end;
cur = members.begin();
+1
View File
@@ -81,6 +81,7 @@ int gettimeofday (timeval *tp, ...)
/* This function checks if the timer triggered */
bool Timer::Check(bool iReset)
{
_eqp
if (enabled && current_time-start_time > timer_time) {
if (iReset) {
if (pUseAcurateTiming)
+1
View File
@@ -18,6 +18,7 @@
#ifndef TYPES_H
#define TYPES_H
#include <eqp_profiler.h>
#include <stdint.h>
typedef uint8_t byte;
typedef uint8_t uint8;
+44
View File
@@ -0,0 +1,44 @@
/*
EQEMu: Everquest Server Emulator
Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "uuid.h"
#ifdef WIN32
#include <rpc.h>
#else
#include <uuid/uuid.h>
#endif
std::string CreateUUID() {
#ifdef WIN32
UUID uuid;
UuidCreate(&uuid);
unsigned char *str = nullptr;
UuidToStringA(&uuid, &str);
std::string s((char*)str);
RpcStringFreeA(&str);
return s;
#else
char str[64] = { 0 };
uuid_t uuid;
uuid_generate_random(uuid);
uuid_unparse(uuid, str);
return str;
#endif
}
+26
View File
@@ -0,0 +1,26 @@
/*
EQEMu: Everquest Server Emulator
Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef COMMON_UUID_H
#define COMMON_UUID_H
#include <string>
std::string CreateUUID();
#endif
+2 -2
View File
@@ -22,7 +22,7 @@
#define LOGIN_VERSION "0.8.0"
#define EQEMU_PROTOCOL_VERSION "0.3.10"
#define CURRENT_VERSION "1.0.0"
#define CURRENT_VERSION "1.1.3"
/*
Everytime a Database SQL is added to Github,
@@ -30,7 +30,7 @@
Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt
*/
#define CURRENT_BINARY_DATABASE_VERSION 9073
#define CURRENT_BINARY_DATABASE_VERSION 9076
#define COMPILE_DATE __DATE__
#define COMPILE_TIME __TIME__
#ifndef WIN32
+8
View File
@@ -28,21 +28,25 @@
WorldConnection::WorldConnection(EmuTCPConnection::ePacketMode mode, const char *password)
: m_password(password)
{
_eqp
tcpc.SetPacketMode(mode);
pTryReconnect = true;
pConnected = false;
}
WorldConnection::~WorldConnection() {
_eqp
}
bool WorldConnection::SendPacket(ServerPacket* pack) {
_eqp
if (!Connected())
return false;
return tcpc.SendPacket(pack);
}
void WorldConnection::OnConnected() {
_eqp
const EQEmuConfig *Config=EQEmuConfig::get();
Log.Out(Logs::General, Logs::Netcode, "[WORLD] Connected to World: %s:%d", Config->WorldIP.c_str(), Config->WorldTCPPort);
@@ -53,6 +57,7 @@ void WorldConnection::OnConnected() {
}
void WorldConnection::Process() {
_eqp
//persistent connection....
if (!Connected()) {
pConnected = tcpc.Connected();
@@ -66,11 +71,13 @@ void WorldConnection::Process() {
}
void WorldConnection::AsyncConnect() {
_eqp
const EQEmuConfig *Config=EQEmuConfig::get();
tcpc.AsyncConnect(Config->WorldIP.c_str(), Config->WorldTCPPort);
}
bool WorldConnection::Connect() {
_eqp
const EQEmuConfig *Config=EQEmuConfig::get();
char errbuf[TCPConnection_ErrorBufferSize];
if (tcpc.Connect(Config->WorldIP.c_str(), Config->WorldTCPPort, errbuf)) {
@@ -82,6 +89,7 @@ bool WorldConnection::Connect() {
}
void WorldConnection::Disconnect() {
_eqp
tcpc.Disconnect();
}
+3
View File
@@ -23,6 +23,7 @@ XMLParser::XMLParser() {
}
bool XMLParser::ParseFile(const char *file, const char *root_ele) {
_eqp
std::map<std::string,ElementHandler>::iterator handler;
TiXmlDocument doc( file );
if(!doc.LoadFile()) {
@@ -70,6 +71,7 @@ bool XMLParser::ParseFile(const char *file, const char *root_ele) {
}
const char *XMLParser::ParseTextBlock(TiXmlNode *within, const char *name, bool optional) {
_eqp
TiXmlElement * txt = within->FirstChildElement(name);
if(txt == nullptr) {
if(!optional) {
@@ -88,6 +90,7 @@ const char *XMLParser::ParseTextBlock(TiXmlNode *within, const char *name, bool
}
const char *XMLParser::GetText(TiXmlNode *within, bool optional) {
_eqp
TiXmlNode *contents = within->FirstChild();
if(contents == nullptr || contents->Type() != TiXmlNode::TEXT) {
if(!optional) {
+4 -1
View File
@@ -15,15 +15,17 @@ ADD_EXECUTABLE(eqlaunch ${eqlaunch_sources} ${eqlaunch_headers})
INSTALL(TARGETS eqlaunch RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
TARGET_LINK_LIBRARIES(eqlaunch common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
TARGET_LINK_LIBRARIES(eqlaunch common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
IF(MSVC)
SET_TARGET_PROPERTIES(eqlaunch PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(eqlaunch "Ws2_32.lib")
TARGET_LINK_LIBRARIES(eqlaunch "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(eqlaunch "WS2_32")
TARGET_LINK_LIBRARIES(eqlaunch "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@@ -34,6 +36,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(eqlaunch "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(eqlaunch "pthread")
TARGET_LINK_LIBRARIES(eqlaunch "uuid")
ADD_DEFINITIONS(-fPIC)
ENDIF(UNIX)
+6
View File
@@ -69,6 +69,10 @@ int main(int argc, char *argv[]) {
Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler");
return 1;
}
if (signal(SIGBREAK, CatchSignal) == SIG_ERR) {
Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler");
return 1;
}
#ifndef WIN32
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler");
@@ -186,6 +190,8 @@ int main(int argc, char *argv[]) {
void CatchSignal(int sig_num) {
Log.Out(Logs::Detail, Logs::Launcher, "Caught signal %d", sig_num);
RunLoops = false;
_eqp_dump_file("eqlaunch");
}
+20
View File
@@ -0,0 +1,20 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(eqperf_sources
eqp_profile_event.cpp
eqp_profile_timer.cpp
eqp_profiler.cpp
eqp_profiler_node.cpp
)
SET(eqperf_headers
eqp_profile_event.h
eqp_profile_function.h
eqp_profile_timer.h
eqp_profiler.h
eqp_profiler_node.h
)
ADD_LIBRARY(eqperf ${eqperf_sources} ${eqperf_headers})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+47
View File
@@ -0,0 +1,47 @@
#include "eqp_profile_event.h"
#include "eqp_profile_timer.h"
#include "eqp_profiler.h"
EQP::CPU::ST::Event::Event(const char *function_name) {
function_name_ = function_name;
name_ = nullptr;
start_ = GetCurrentTimer();
identifier_ = EQP::CPU::ST::GetProfiler().EventStarted(function_name_, name_);
}
EQP::CPU::ST::Event::Event(const char *function_name, const char *name) {
function_name_ = function_name;
name_ = name;
start_ = GetCurrentTimer();
identifier_ = EQP::CPU::ST::GetProfiler().EventStarted(function_name_, name_);
}
EQP::CPU::ST::Event::~Event() {
uint64_t end = GetCurrentTimer();
EQP::CPU::ST::GetProfiler().EventFinished(end - start_, identifier_);
}
EQP::CPU::MT::Event::Event(const char *function_name) {
function_name_ = function_name;
name_ = nullptr;
start_ = GetCurrentTimer();
identifier_ = EQP::CPU::MT::GetProfiler().EventStarted(function_name_, name_);
}
EQP::CPU::MT::Event::Event(const char *function_name, const char *name) {
function_name_ = function_name;
name_ = name;
start_ = GetCurrentTimer();
identifier_ = EQP::CPU::MT::GetProfiler().EventStarted(function_name_, name_);
}
EQP::CPU::MT::Event::~Event() {
uint64_t end = GetCurrentTimer();
EQP::CPU::MT::GetProfiler().EventFinished(end - start_, identifier_);
}
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include <string>
#include <stdint.h>
#include "eqp_profile_function.h"
namespace EQP
{
namespace CPU
{
namespace ST
{
class EQP_EXPORT Event
{
public:
Event(const char *function_name);
Event(const char *function_name, const char *name);
~Event();
private:
const char *function_name_;
const char *name_;
uint64_t start_;
std::string identifier_;
};
}
namespace MT
{
class EQP_EXPORT Event
{
public:
Event(const char *function_name);
Event(const char *function_name, const char *name);
~Event();
private:
const char *function_name_;
const char *name_;
uint64_t start_;
std::string identifier_;
};
}
}
} // Profile
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#ifndef __PRETTY_FUNCTION__
#ifdef _MSC_VER
#define __PRETTY_FUNCTION__ __FUNCSIG__
#else
#define __PRETTY_FUNCTION__ __FUNCTION__
#endif
#endif
#ifdef _MSC_VER
//#define EQP_EXPORT __declspec(dllexport)
#define EQP_EXPORT
#else
#define EQP_EXPORT
#endif
+24
View File
@@ -0,0 +1,24 @@
#include "eqp_profile_timer.h"
#ifdef _MSC_VER
#include <Windows.h>
#else
#include <time.h>
#endif
uint64_t EQP::GetCurrentTimer()
{
#ifdef _MSC_VER
LARGE_INTEGER qpt_i;
QueryPerformanceCounter(&qpt_i);
return qpt_i.QuadPart;
#else
timespec tp;
if(clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
uint64_t res = tp.tv_sec * 1000000000;
res += tp.tv_nsec;
return res;
}
return 0;
#endif
}
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include <stdint.h>
namespace EQP
{
uint64_t GetCurrentTimer();
} // EQP
+245
View File
@@ -0,0 +1,245 @@
#include "eqp_profiler.h"
#include "eqp_profile_timer.h"
#include <iostream>
#include <thread>
#include <mutex>
#include <vector>
#include <algorithm>
#include "../common/uuid.h"
struct EQP::CPU::MT::Profiler::impl
{
std::mutex lock_;
std::unordered_map<std::thread::id, ThreadInfo*> nodes_;
std::string identifier_;
};
EQP::CPU::ST::Profiler &EQP::CPU::ST::GetProfiler() {
static EQP::CPU::ST::Profiler st_profiler;
return st_profiler;
}
EQP::CPU::MT::Profiler &EQP::CPU::MT::GetProfiler() {
static EQP::CPU::MT::Profiler mt_profiler;
return mt_profiler;
}
EQP::CPU::ST::Profiler::Profiler() {
root_ = new ProfilerNode;
root_->SetParent(root_);
current_ = root_;
identifier_ = CreateUUID();
}
EQP::CPU::ST::Profiler::~Profiler() {
delete root_;
}
std::string EQP::CPU::ST::Profiler::EventStarted(const char *func, const char *name) {
std::string cur_name = func;
if(name) {
cur_name += " - ";
cur_name += name;
}
auto search = current_->GetNodes().find(cur_name);
if(search != current_->GetNodes().end()) {
current_ = search->second;
} else {
ProfilerNode *t = new ProfilerNode;
t->SetParent(current_);
current_->GetNodes()[cur_name] = t;
current_ = t;
}
current_->GetCount()++;
current_->SetStarted(GetCurrentTimer());
return identifier_;
}
void EQP::CPU::ST::Profiler::EventFinished(uint64_t time, std::string ident) {
if(ident.compare(identifier_) != 0) {
return;
}
current_->SetStarted(0);
current_->GetTime() += time;
current_ = current_->GetParent();
}
void EQP::CPU::ST::Profiler::Clear() {
for(auto &iter : root_->GetNodes()) {
delete iter.second;
}
root_->GetNodes().clear();
root_->SetTime(0);
root_->SetCount(0);
current_ = root_;
identifier_ = CreateUUID();
}
void EQP::CPU::ST::Profiler::Dump(std::ostream &stream, int num) {
uint64_t total = 0;
std::vector<ProfilerNodeDump> sorted_vec;
sorted_vec.reserve(root_->GetNodes().size() + 1);
for(auto &iter : root_->GetNodes()) {
ProfilerNodeDump n;
n.name = iter.first;
n.node = iter.second;
sorted_vec.push_back(n);
total += iter.second->GetTime();
if(iter.second->GetStarted() > 0) {
total += GetCurrentTimer() - iter.second->GetStarted();
}
}
std::sort(sorted_vec.begin(), sorted_vec.end(),
[](const ProfilerNodeDump& a, const ProfilerNodeDump& b) { return a.node->GetTime() > b.node->GetTime(); });
std::streamsize p = stream.precision();
double m_cycles = total / 1000.0;
stream << std::fixed;
stream.precision(2);
stream << m_cycles << "k cycles" << std::endl;
stream.precision(p);
int i = 0;
for(auto &iter : sorted_vec) {
if(num > 0 && i >= num) {
break;
}
iter.node->Dump(stream, iter.name, total, 1, num);
++i;
}
}
EQP::CPU::MT::Profiler::ThreadInfo::ThreadInfo() {
root_ = new ProfilerNode;
root_->SetParent(root_);
current_ = root_;
}
EQP::CPU::MT::Profiler::ThreadInfo::~ThreadInfo() {
delete root_;
}
EQP::CPU::MT::Profiler::Profiler() {
imp_ = new impl;
imp_->identifier_ = CreateUUID();
}
EQP::CPU::MT::Profiler::~Profiler() {
delete imp_;
}
std::string EQP::CPU::MT::Profiler::EventStarted(const char *func, const char *name) {
std::string cur_name = func;
if(name) {
cur_name += " - ";
cur_name += name;
}
ThreadInfo *ti = nullptr;
std::lock_guard<std::mutex> lg(imp_->lock_);
auto ti_search = imp_->nodes_.find(std::this_thread::get_id());
if(ti_search == imp_->nodes_.end()) {
ti = new ThreadInfo;
imp_->nodes_[std::this_thread::get_id()] = ti;
} else {
ti = ti_search->second;
}
auto search = ti->current_->GetNodes().find(cur_name);
if(search != ti->current_->GetNodes().end()) {
ti->current_ = search->second;
}
else {
ProfilerNode *t = new ProfilerNode;
t->SetParent(ti->current_);
ti->current_->GetNodes()[cur_name] = t;
ti->current_ = t;
}
ti->current_->GetCount()++;
ti->current_->SetStarted(GetCurrentTimer());
return imp_->identifier_;
}
void EQP::CPU::MT::Profiler::EventFinished(uint64_t time, std::string ident) {
ThreadInfo *ti = nullptr;
std::lock_guard<std::mutex> lg(imp_->lock_);
if(ident.compare(imp_->identifier_) != 0) {
return;
}
auto ti_search = imp_->nodes_.find(std::this_thread::get_id());
if(ti_search == imp_->nodes_.end()) {
return;
}
else {
ti = ti_search->second;
}
ti->current_->SetStarted(0);
ti->current_->GetTime() += time;
ti->current_ = ti->current_->GetParent();
}
void EQP::CPU::MT::Profiler::Clear() {
std::lock_guard<std::mutex> lg(imp_->lock_);
for(auto &iter : imp_->nodes_) {
delete iter.second;
}
imp_->nodes_.clear();
imp_->identifier_ = CreateUUID();
}
void EQP::CPU::MT::Profiler::Dump(std::ostream &stream, int num) {
std::lock_guard<std::mutex> lg(imp_->lock_);
for(auto &iter : imp_->nodes_) {
uint64_t total = 0;
std::vector<ProfilerNodeDump> sorted_vec;
sorted_vec.reserve(iter.second->root_->GetNodes().size() + 1);
for(auto &t_iter : iter.second->root_->GetNodes()) {
ProfilerNodeDump n;
n.name = t_iter.first;
n.node = t_iter.second;
sorted_vec.push_back(n);
total += t_iter.second->GetTime();
if(t_iter.second->GetStarted() > 0) {
total += GetCurrentTimer() - t_iter.second->GetStarted();
}
}
std::sort(sorted_vec.begin(), sorted_vec.end(),
[](const ProfilerNodeDump& a, const ProfilerNodeDump& b) { return a.node->GetTime() > b.node->GetTime(); });
std::streamsize p = stream.precision();
double m_cycles = total / 1000.0;
stream << std::fixed;
stream.precision(2);
stream << "Thread: " << iter.first << ", " << m_cycles << "k cycles" << std::endl;
stream.precision(p);
int i = 0;
for(auto &t_iter : sorted_vec) {
if(num > 0 && i >= num) {
break;
}
t_iter.node->Dump(stream, t_iter.name, total, 1, num);
++i;
}
stream << std::endl;
}
}
+112
View File
@@ -0,0 +1,112 @@
#pragma once
#ifdef EQPERF_ENABLED
#include <string>
#include <fstream>
#include <time.h>
#include "eqp_profile_event.h"
#include "eqp_profiler_node.h"
#define eqp_comb_fin(x, y) x##y
#define eqp_comb(x, y) eqp_comb_fin(x, y)
#ifndef EQP_MULTITHREAD
#define _eqp EQP::CPU::ST::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__);
#define _eqpn(x) EQP::CPU::ST::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__, x);
#define _eqp_clear() EQP::CPU::ST::GetProfiler().Clear()
#define _eqp_dump(strm, count) EQP::CPU::ST::GetProfiler().Dump(strm, count)
#define _eqp_dump_file(name) char time_str[128]; \
time_t result = time(nullptr); \
strftime(time_str, sizeof(time_str), "%Y_%m_%d_%H_%M_%S", localtime(&result)); \
std::string prof_name = "./profile/"; \
prof_name += name; \
prof_name += "_"; \
prof_name += time_str; \
prof_name += ".log"; \
std::ofstream profile_out(prof_name, std::ofstream::out); \
if(profile_out.good()) { \
_eqp_dump(profile_out, 10); \
}
#else
#define _eqp EQP::CPU::MT::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__);
#define _eqpn(x) EQP::CPU::MT::Event eqp_comb(eq_perf_event_, __LINE__) (__PRETTY_FUNCTION__, x);
#define _eqp_clear() EQP::CPU::MT::GetProfiler().Clear()
#define _eqp_dump(strm, count) EQP::CPU::MT::GetProfiler().Dump(strm, count)
#define _eqp_dump_file(name) char time_str[128]; \
time_t result = time(nullptr); \
strftime(time_str, sizeof(time_str), "%Y_%m_%d_%H_%M_%S", localtime(&result)); \
std::string prof_name = "./profile/"; \
prof_name += name; \
prof_name += "_"; \
prof_name += time_str; \
prof_name += ".log"; \
std::ofstream profile_out(prof_name, std::ofstream::out); \
if(profile_out.good()) { \
_eqp_dump(profile_out, 10); \
}
#endif
namespace EQP
{
namespace CPU
{
namespace ST
{
class EQP_EXPORT Profiler
{
typedef EQP::CPU::ProfilerNode Node;
public:
Profiler();
~Profiler();
std::string EventStarted(const char *func, const char *name);
void EventFinished(uint64_t time, std::string ident);
void Dump(std::ostream &stream, int num = 0);
void Clear();
private:
Node *root_;
Node *current_;
std::string identifier_;
};
EQP_EXPORT Profiler &GetProfiler();
}
namespace MT
{
class EQP_EXPORT Profiler
{
typedef EQP::CPU::ProfilerNode Node;
class ThreadInfo {
public:
ThreadInfo();
~ThreadInfo();
Node *root_;
Node *current_;
};
public:
Profiler();
~Profiler();
std::string EventStarted(const char *func, const char *name);
void EventFinished(uint64_t time, std::string ident);
void Dump(std::ostream &stream, int num = 0);
void Clear();
private:
struct impl;
impl *imp_;
};
EQP_EXPORT Profiler &GetProfiler();
}
} // CPU
} // EQP
#else
#define _eqp
#define _eqpn(x)
#define _eqp_clear()
#define _eqp_dump(strm, count)
#endif
+66
View File
@@ -0,0 +1,66 @@
#include "eqp_profiler_node.h"
#include "eqp_profile_timer.h"
#include <iostream>
#include <iomanip>
#include <algorithm>
EQP::CPU::ProfilerNode::ProfilerNode() {
count_ = 0;
time_ = 0;
started_ = 0;
parent_ = nullptr;;
}
EQP::CPU::ProfilerNode::~ProfilerNode() {
for(auto &iter : nodes_) {
delete iter.second;
}
}
void EQP::CPU::ProfilerNode::Dump(std::ostream &stream, const std::string &func, uint64_t total_time, int node_level, int num) {
if(node_level >= 1) {
stream << std::setw(node_level * 4) << " ";
}
double m_cycles = static_cast<double>(time_);
if(started_) {
m_cycles += GetCurrentTimer() - started_;
}
double percentage = m_cycles * 100 / static_cast<double>(total_time);
m_cycles = m_cycles / 1000.0;
double m_avg_cycles = m_cycles / count_;
std::streamsize p = stream.precision();
stream << std::fixed;
stream.precision(2);
stream << m_cycles << "k cycles, " << count_ << " calls, " << m_avg_cycles << "k cycles avg, ";
stream << func.c_str() << " ";
stream << percentage << "%";
stream << std::endl;
stream.precision(p);
std::vector<ProfilerNodeDump> sorted_vec;
sorted_vec.reserve(nodes_.size() + 1);
for(auto &iter : nodes_) {
ProfilerNodeDump n;
n.name = iter.first;
n.node = iter.second;
sorted_vec.push_back(n);
}
std::sort(sorted_vec.begin(), sorted_vec.end(),
[](const ProfilerNodeDump& a, const ProfilerNodeDump& b) { return a.node->GetTime() > b.node->GetTime(); });
int i = 0;
for(auto &iter : sorted_vec) {
if(num > 0 && i >= num) {
break;
}
iter.node->Dump(stream, iter.name, total_time, node_level + 1, num);
++i;
}
}
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include <unordered_map>
#include <string>
#include <stdint.h>
namespace EQP
{
namespace CPU
{
class ProfilerNode
{
public:
ProfilerNode();
~ProfilerNode();
inline void SetCount(uint64_t c) { count_ = c; }
inline uint64_t& GetCount() { return count_; }
inline void SetTime(uint64_t t) { time_ = t; }
inline uint64_t& GetTime() { return time_; }
inline void SetStarted(uint64_t t) { started_ = t; }
inline uint64_t& GetStarted() { return started_; }
inline void SetParent(ProfilerNode *p) { parent_ = p; }
inline ProfilerNode* GetParent() { return parent_; }
inline std::unordered_map<std::string, ProfilerNode*>& GetNodes() { return nodes_; }
void Dump(std::ostream &stream, const std::string &func, uint64_t total_time, int node_level, int num);
private:
uint64_t count_;
uint64_t time_;
uint64_t started_;
ProfilerNode *parent_;
std::unordered_map<std::string, ProfilerNode*> nodes_;
};
struct ProfilerNodeDump
{
std::string name;
ProfilerNode *node;
};
} // CPU
} // EQP
+4 -3
View File
@@ -6,7 +6,6 @@ SET(eqlogin_sources
config.cpp
database_mysql.cpp
database_postgresql.cpp
error_log.cpp
main.cpp
server_manager.cpp
world_server.cpp
@@ -26,7 +25,6 @@ SET(eqlogin_headers
database_postgresql.h
encryption.h
eq_crypto_api.h
error_log.h
login_server.h
login_structures.h
options.h
@@ -43,15 +41,17 @@ ADD_EXECUTABLE(loginserver ${eqlogin_sources} ${eqlogin_headers})
INSTALL(TARGETS loginserver RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
TARGET_LINK_LIBRARIES(loginserver common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE})
TARGET_LINK_LIBRARIES(loginserver common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE})
IF(MSVC)
SET_TARGET_PROPERTIES(loginserver PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(loginserver "Ws2_32.lib")
TARGET_LINK_LIBRARIES(loginserver "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(loginserver "WS2_32")
TARGET_LINK_LIBRARIES(loginserver "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@@ -62,6 +62,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(loginserver "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(loginserver "pthread")
TARGET_LINK_LIBRARIES(loginserver "uuid")
TARGET_LINK_LIBRARIES(loginserver "EQEmuAuthCrypto")
TARGET_LINK_LIBRARIES(loginserver "cryptopp")
ADD_DEFINITIONS(-fPIC)
+30 -23
View File
@@ -16,16 +16,16 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "client.h"
#include "error_log.h"
#include "login_server.h"
#include "login_structures.h"
#include "../common/misc_functions.h"
#include "../common/eqemu_logsys.h"
extern ErrorLog *server_log;
extern LoginServer server;
Client::Client(std::shared_ptr<EQStream> c, LSClientVersion v)
{
_eqp
connection = c;
version = v;
status = cs_not_sent_session_ready;
@@ -36,12 +36,13 @@ Client::Client(std::shared_ptr<EQStream> c, LSClientVersion v)
bool Client::Process()
{
_eqp
EQApplicationPacket *app = connection->PopPacket();
while(app)
{
if(server.options.IsTraceOn())
{
server_log->Log(log_network, "Application packet received from client (size %u)", app->Size());
Log.Out(Logs::General, Logs::Netcode, "Application packet received from client (size %u)", app->Size());
}
if(server.options.IsDumpInPacketsOn())
@@ -55,7 +56,7 @@ bool Client::Process()
{
if(server.options.IsTraceOn())
{
server_log->Log(log_network, "Session ready received from client.");
Log.Out(Logs::General, Logs::Netcode, "Session ready received from client.");
}
Handle_SessionReady((const char*)app->pBuffer, app->Size());
break;
@@ -64,13 +65,13 @@ bool Client::Process()
{
if(app->Size() < 20)
{
server_log->Log(log_network_error, "Login received but it is too small, discarding.");
Log.Out(Logs::General, Logs::Netcode, "Login received but it is too small, discarding.");
break;
}
if(server.options.IsTraceOn())
{
server_log->Log(log_network, "Login received from client.");
Log.Out(Logs::General, Logs::Netcode, "Login received from client.");
}
Handle_Login((const char*)app->pBuffer, app->Size());
@@ -80,7 +81,7 @@ bool Client::Process()
{
if(server.options.IsTraceOn())
{
server_log->Log(log_network, "Server list request received from client.");
Log.Out(Logs::General, Logs::Netcode, "Server list request received from client.");
}
SendServerListPacket();
@@ -90,7 +91,7 @@ bool Client::Process()
{
if(app->Size() < sizeof(PlayEverquestRequest_Struct))
{
server_log->Log(log_network_error, "Play received but it is too small, discarding.");
Log.Out(Logs::General, Logs::Netcode, "Play received but it is too small, discarding.");
break;
}
@@ -101,7 +102,7 @@ bool Client::Process()
{
char dump[64];
app->build_header_dump(dump);
server_log->Log(log_network_error, "Recieved unhandled application packet from the client: %s.", dump);
Log.Out(Logs::General, Logs::Netcode, "Recieved unhandled application packet from the client: %s.", dump);
}
}
@@ -114,22 +115,23 @@ bool Client::Process()
void Client::Handle_SessionReady(const char* data, unsigned int size)
{
_eqp
if(status != cs_not_sent_session_ready)
{
server_log->Log(log_network_error, "Session ready received again after already being received.");
Log.Out(Logs::General, Logs::Netcode, "Session ready received again after already being received.");
return;
}
if(size < sizeof(unsigned int))
{
server_log->Log(log_network_error, "Session ready was too small.");
Log.Out(Logs::General, Logs::Netcode, "Session ready was too small.");
return;
}
unsigned int mode = *((unsigned int*)data);
if(mode == (unsigned int)lm_from_world)
{
server_log->Log(log_network, "Session ready indicated logged in from world(unsupported feature), disconnecting.");
Log.Out(Logs::General, Logs::Netcode, "Session ready indicated logged in from world(unsupported feature), disconnecting.");
connection->Close();
return;
}
@@ -175,15 +177,16 @@ void Client::Handle_SessionReady(const char* data, unsigned int size)
void Client::Handle_Login(const char* data, unsigned int size)
{
_eqp
if(status != cs_waiting_for_login)
{
server_log->Log(log_network_error, "Login received after already having logged in.");
Log.Out(Logs::General, Logs::Netcode, "Login received after already having logged in.");
return;
}
if((size - 12) % 8 != 0)
{
server_log->Log(log_network_error, "Login received packet of size: %u, this would cause a block corruption, discarding.", size);
Log.Out(Logs::General, Logs::Netcode, "Login received packet of size: %u, this would cause a block corruption, discarding.", size);
return;
}
@@ -204,8 +207,8 @@ void Client::Handle_Login(const char* data, unsigned int size)
if(server.options.IsTraceOn())
{
server_log->Log(log_client, "User: %s", e_user.c_str());
server_log->Log(log_client, "Hash: %s", e_hash.c_str());
Log.Out(Logs::General, Logs::LoginServer, "User: %s", e_user.c_str());
Log.Out(Logs::General, Logs::LoginServer, "Hash: %s", e_hash.c_str());
}
server.eq_crypto->DeleteHeap(e_buffer);
@@ -218,8 +221,8 @@ void Client::Handle_Login(const char* data, unsigned int size)
if(server.options.IsTraceOn())
{
server_log->Log(log_client, "User: %s", e_user.c_str());
server_log->Log(log_client, "Hash: %s", e_hash.c_str());
Log.Out(Logs::General, Logs::LoginServer, "User: %s", e_user.c_str());
Log.Out(Logs::General, Logs::LoginServer, "Hash: %s", e_hash.c_str());
}
_HeapDeleteCharBuffer(e_buffer);
@@ -228,7 +231,7 @@ void Client::Handle_Login(const char* data, unsigned int size)
bool result;
if(server.db->GetLoginDataFromAccountName(e_user, d_pass_hash, d_account_id) == false)
{
server_log->Log(log_client_error, "Error logging in, user %s does not exist in the database.", e_user.c_str());
Log.Out(Logs::General, Logs::Error, "Error logging in, user %s does not exist in the database.", e_user.c_str());
result = false;
}
else
@@ -329,9 +332,10 @@ void Client::Handle_Login(const char* data, unsigned int size)
void Client::Handle_Play(const char* data)
{
_eqp
if(status != cs_logged_in)
{
server_log->Log(log_client_error, "Client sent a play request when they either were not logged in, discarding.");
Log.Out(Logs::General, Logs::Error, "Client sent a play request when they either were not logged in, discarding.");
return;
}
@@ -341,7 +345,7 @@ void Client::Handle_Play(const char* data)
if(server.options.IsTraceOn())
{
server_log->Log(log_network, "Play received from client, server number %u sequence %u.", server_id_in, sequence_in);
Log.Out(Logs::General, Logs::Netcode, "Play received from client, server number %u sequence %u.", server_id_in, sequence_in);
}
this->play_server_id = (unsigned int)play->ServerNumber;
@@ -352,6 +356,7 @@ void Client::Handle_Play(const char* data)
void Client::SendServerListPacket()
{
_eqp
EQApplicationPacket *outapp = server.SM->CreateServerListPacket(this);
if(server.options.IsDumpOutPacketsOn())
@@ -365,10 +370,11 @@ void Client::SendServerListPacket()
void Client::SendPlayResponse(EQApplicationPacket *outapp)
{
_eqp
if(server.options.IsTraceOn())
{
server_log->Log(log_network_trace, "Sending play response for %s.", GetAccountName().c_str());
server_log->LogPacket(log_network_trace, (const char*)outapp->pBuffer, outapp->size);
Log.Out(Logs::Detail, Logs::Netcode, "Sending play response for %s.", GetAccountName().c_str());
//server_log->LogPacket(log_network_trace, (const char*)outapp->pBuffer, outapp->size);
}
connection->QueuePacket(outapp);
status = cs_logged_in;
@@ -376,6 +382,7 @@ void Client::SendPlayResponse(EQApplicationPacket *outapp)
void Client::GenerateKey()
{
_eqp
key.clear();
int count = 0;
while(count < 10)
+20 -14
View File
@@ -16,32 +16,32 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "client_manager.h"
#include "error_log.h"
#include "login_server.h"
#include "../common/eqemu_logsys.h"
extern ErrorLog *server_log;
extern LoginServer server;
extern bool run_server;
ClientManager::ClientManager()
{
_eqp
int titanium_port = atoi(server.config->GetVariable("Titanium", "port").c_str());
titanium_stream = new EQStreamFactory(LoginStream, titanium_port);
titanium_ops = new RegularOpcodeManager;
if(!titanium_ops->LoadOpcodes(server.config->GetVariable("Titanium", "opcodes").c_str()))
{
server_log->Log(log_error, "ClientManager fatal error: couldn't load opcodes for Titanium file %s.",
Log.Out(Logs::Detail, Logs::Error, "ClientManager fatal error: couldn't load opcodes for Titanium file %s.",
server.config->GetVariable("Titanium", "opcodes").c_str());
run_server = false;
}
if(titanium_stream->Open())
{
server_log->Log(log_network, "ClientManager listening on Titanium stream.");
Log.Out(Logs::General, Logs::Netcode, "ClientManager listening on Titanium stream.");
}
else
{
server_log->Log(log_error, "ClientManager fatal error: couldn't open Titanium stream.");
Log.Out(Logs::Detail, Logs::Error, "ClientManager fatal error: couldn't open Titanium stream.");
run_server = false;
}
@@ -50,24 +50,25 @@ ClientManager::ClientManager()
sod_ops = new RegularOpcodeManager;
if(!sod_ops->LoadOpcodes(server.config->GetVariable("SoD", "opcodes").c_str()))
{
server_log->Log(log_error, "ClientManager fatal error: couldn't load opcodes for SoD file %s.",
Log.Out(Logs::Detail, Logs::Error, "ClientManager fatal error: couldn't load opcodes for SoD file %s.",
server.config->GetVariable("SoD", "opcodes").c_str());
run_server = false;
}
if(sod_stream->Open())
{
server_log->Log(log_network, "ClientManager listening on SoD stream.");
Log.Out(Logs::General, Logs::Netcode, "ClientManager listening on SoD stream.");
}
else
{
server_log->Log(log_error, "ClientManager fatal error: couldn't open SoD stream.");
Log.Out(Logs::Detail, Logs::Error, "ClientManager fatal error: couldn't open SoD stream.");
run_server = false;
}
}
ClientManager::~ClientManager()
{
_eqp
if(titanium_stream)
{
titanium_stream->Close();
@@ -93,13 +94,14 @@ ClientManager::~ClientManager()
void ClientManager::Process()
{
_eqp
ProcessDisconnect();
std::shared_ptr<EQStream> cur = titanium_stream->Pop();
while(cur)
{
struct in_addr in;
in.s_addr = cur->GetRemoteIP();
server_log->Log(log_network, "New Titanium client connection from %s:%d", inet_ntoa(in), ntohs(cur->GetRemotePort()));
Log.Out(Logs::General, Logs::Netcode, "New Titanium client connection from %s:%d", inet_ntoa(in), ntohs(cur->GetRemotePort()));
cur->SetOpcodeManager(&titanium_ops);
Client *c = new Client(cur, cv_titanium);
@@ -112,7 +114,7 @@ void ClientManager::Process()
{
struct in_addr in;
in.s_addr = cur->GetRemoteIP();
server_log->Log(log_network, "New SoD client connection from %s:%d", inet_ntoa(in), ntohs(cur->GetRemotePort()));
Log.Out(Logs::General, Logs::Netcode, "New SoD client connection from %s:%d", inet_ntoa(in), ntohs(cur->GetRemotePort()));
cur->SetOpcodeManager(&sod_ops);
Client *c = new Client(cur, cv_sod);
@@ -125,7 +127,7 @@ void ClientManager::Process()
{
if((*iter)->Process() == false)
{
server_log->Log(log_client, "Client had a fatal error and had to be removed from the login.");
Log.Out(Logs::General, Logs::LoginServer, "Client had a fatal error and had to be removed from the login.");
delete (*iter);
iter = clients.erase(iter);
}
@@ -138,13 +140,14 @@ void ClientManager::Process()
void ClientManager::ProcessDisconnect()
{
_eqp
list<Client*>::iterator iter = clients.begin();
while(iter != clients.end())
{
std::shared_ptr<EQStream> c = (*iter)->GetConnection();
if(c->CheckClosed())
{
server_log->Log(log_network, "Client disconnected from the server, removing client.");
Log.Out(Logs::General, Logs::Netcode, "Client disconnected from the server, removing client.");
delete (*iter);
iter = clients.erase(iter);
}
@@ -157,6 +160,7 @@ void ClientManager::ProcessDisconnect()
void ClientManager::UpdateServerList()
{
_eqp
list<Client*>::iterator iter = clients.begin();
while(iter != clients.end())
{
@@ -167,12 +171,13 @@ void ClientManager::UpdateServerList()
void ClientManager::RemoveExistingClient(unsigned int account_id)
{
_eqp
list<Client*>::iterator iter = clients.begin();
while(iter != clients.end())
{
if((*iter)->GetAccountID() == account_id)
{
server_log->Log(log_network, "Client attempting to log in and existing client already logged in, removing existing client.");
Log.Out(Logs::General, Logs::Netcode, "Client attempting to log in and existing client already logged in, removing existing client.");
delete (*iter);
iter = clients.erase(iter);
}
@@ -185,6 +190,7 @@ void ClientManager::RemoveExistingClient(unsigned int account_id)
Client *ClientManager::GetClient(unsigned int account_id)
{
_eqp
Client *cur = nullptr;
int count = 0;
list<Client*>::iterator iter = clients.begin();
@@ -200,7 +206,7 @@ Client *ClientManager::GetClient(unsigned int account_id)
if(count > 1)
{
server_log->Log(log_client_error, "More than one client with a given account_id existed in the client list.");
Log.Out(Logs::General, Logs::Error, "More than one client with a given account_id existed in the client list.");
}
return cur;
}
+8 -6
View File
@@ -17,9 +17,8 @@
*/
#include "../common/global_define.h"
#include "config.h"
#include "error_log.h"
#include "../common/eqemu_logsys.h"
extern ErrorLog *server_log;
/**
* Retrieves the variable we want from our title or theme
* First gets the map from the title
@@ -27,6 +26,7 @@ extern ErrorLog *server_log;
*/
std::string Config::GetVariable(std::string title, std::string parameter)
{
_eqp
std::map<std::string, std::map<std::string, std::string> >::iterator iter = vars.find(title);
if(iter != vars.end())
{
@@ -46,9 +46,10 @@ std::string Config::GetVariable(std::string title, std::string parameter)
*/
void Config::Parse(const char *file_name)
{
_eqp
if(file_name == nullptr)
{
server_log->Log(log_error, "Config::Parse(), file_name passed was null.");
Log.Out(Logs::Detail, Logs::Error, "Config::Parse(), file_name passed was null.");
return;
}
@@ -71,7 +72,7 @@ void Config::Parse(const char *file_name)
++iter;
if(iter == tokens.end())
{
server_log->Log(log_error, "Config::Parse(), EOF before title done parsing.");
Log.Out(Logs::Detail, Logs::Error, "Config::Parse(), EOF before title done parsing.");
fclose(input);
vars.clear();
return;
@@ -104,7 +105,7 @@ void Config::Parse(const char *file_name)
mode++;
if((*iter).compare("=") != 0)
{
server_log->Log(log_error, "Config::Parse(), invalid parse token where = should be.");
Log.Out(Logs::Detail, Logs::Error, "Config::Parse(), invalid parse token where = should be.");
fclose(input);
vars.clear();
return;
@@ -133,7 +134,7 @@ void Config::Parse(const char *file_name)
}
else
{
server_log->Log(log_error, "Config::Parse(), file was unable to be opened for parsing.");
Log.Out(Logs::Detail, Logs::Error, "Config::Parse(), file was unable to be opened for parsing.");
}
}
@@ -144,6 +145,7 @@ void Config::Parse(const char *file_name)
*/
void Config::Tokenize(FILE *input, std::list<std::string> &tokens)
{
_eqp
char c = fgetc(input);
std::string lexeme;
+23 -16
View File
@@ -20,16 +20,16 @@
#ifdef EQEMU_MYSQL_ENABLED
#include "database_mysql.h"
#include "error_log.h"
#include "login_server.h"
#include "../common/eqemu_logsys.h"
extern ErrorLog *server_log;
extern LoginServer server;
#pragma comment(lib, "mysqlclient.lib")
DatabaseMySQL::DatabaseMySQL(string user, string pass, string host, string port, string name)
{
_eqp
this->user = user;
this->pass = pass;
this->host = host;
@@ -43,18 +43,19 @@ DatabaseMySQL::DatabaseMySQL(string user, string pass, string host, string port,
if(!mysql_real_connect(db, host.c_str(), user.c_str(), pass.c_str(), name.c_str(), atoi(port.c_str()), nullptr, 0))
{
mysql_close(db);
server_log->Log(log_database, "Failed to connect to MySQL database. Error: %s", mysql_error(db));
Log.Out(Logs::General, Logs::Database,"Failed to connect to MySQL database. Error: %s", mysql_error(db));
exit(1);
}
}
else
{
server_log->Log(log_database, "Failed to create db object in MySQL database.");
Log.Out(Logs::General, Logs::Database,"Failed to create db object in MySQL database.");
}
}
DatabaseMySQL::~DatabaseMySQL()
{
_eqp
if(db)
{
mysql_close(db);
@@ -63,6 +64,7 @@ DatabaseMySQL::~DatabaseMySQL()
bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id)
{
_eqp
if(!db)
{
return false;
@@ -77,7 +79,7 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u
if(mysql_query(db, query.str().c_str()) != 0)
{
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query failed: %s", query.str().c_str());
return false;
}
@@ -94,13 +96,14 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u
}
}
server_log->Log(log_database, "Mysql query returned no result: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query returned no result: %s", query.str().c_str());
return false;
}
bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id,
unsigned int &trusted, string &list_desc, string &account, string &password)
{
_eqp
if(!db)
{
return false;
@@ -122,7 +125,7 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un
if(mysql_query(db, query.str().c_str()) != 0)
{
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query failed: %s", query.str().c_str());
return false;
}
@@ -147,7 +150,7 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un
if(mysql_query(db, query.str().c_str()) != 0)
{
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query failed: %s", query.str().c_str());
return false;
}
@@ -163,19 +166,20 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un
}
}
server_log->Log(log_database, "Mysql query returned no result: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query returned no result: %s", query.str().c_str());
return false;
}
return true;
}
}
server_log->Log(log_database, "Mysql query returned no result: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query returned no result: %s", query.str().c_str());
return false;
}
void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address)
{
_eqp
if(!db)
{
return;
@@ -189,12 +193,13 @@ void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address)
if(mysql_query(db, query.str().c_str()) != 0)
{
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query failed: %s", query.str().c_str());
}
}
void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string password, string email)
{
_eqp
if(!db)
{
return;
@@ -208,12 +213,13 @@ void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string pas
if(mysql_query(db, query.str().c_str()) != 0)
{
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query failed: %s", query.str().c_str());
}
}
void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, string ip_address)
{
_eqp
if(!db)
{
return;
@@ -233,12 +239,13 @@ void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, s
if(mysql_query(db, query.str().c_str()) != 0)
{
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query failed: %s", query.str().c_str());
}
}
bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name, unsigned int &id)
{
_eqp
if(!db)
{
return false;
@@ -258,7 +265,7 @@ bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name,
if(mysql_query(db, query.str().c_str()) != 0)
{
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query failed: %s", query.str().c_str());
return false;
}
@@ -277,13 +284,13 @@ bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name,
if(mysql_query(db, query.str().c_str()) != 0)
{
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
Log.Out(Logs::General, Logs::Database,"Mysql query failed: %s", query.str().c_str());
return false;
}
return true;
}
}
server_log->Log(log_database, "World registration did not exist in the database for %s %s", long_name.c_str(), short_name.c_str());
Log.Out(Logs::General, Logs::Database,"World registration did not exist in the database for %s %s", long_name.c_str(), short_name.c_str());
return false;
}
+13 -7
View File
@@ -22,24 +22,25 @@
#include "database_postgresql.h"
#include "error_log.h"
#include "login_server.h"
#include "../common/eqemu_logsys.h"
extern ErrorLog *server_log;
extern LoginServer server;
#pragma comment(lib, "libpq.lib")
DatabasePostgreSQL::DatabasePostgreSQL(string user, string pass, string host, string port, string name)
{
_eqp
db = nullptr;
db = PQsetdbLogin(host.c_str(), port.c_str(), nullptr, nullptr, name.c_str(), user.c_str(), pass.c_str());
if(!db)
{
server_log->Log(log_database, "Failed to connect to PostgreSQL Database.");
Log.Out(Logs::General, Logs::Database,"Failed to connect to PostgreSQL Database.");
}
if(PQstatus(db) != CONNECTION_OK)
{
server_log->Log(log_database, "Failed to connect to PostgreSQL Database.");
Log.Out(Logs::General, Logs::Database,"Failed to connect to PostgreSQL Database.");
PQfinish(db);
db = nullptr;
}
@@ -47,6 +48,7 @@ DatabasePostgreSQL::DatabasePostgreSQL(string user, string pass, string host, st
DatabasePostgreSQL::~DatabasePostgreSQL()
{
_eqp
if(db)
{
PQfinish(db);
@@ -55,6 +57,7 @@ DatabasePostgreSQL::~DatabasePostgreSQL()
bool DatabasePostgreSQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id)
{
_eqp
if(!db)
{
return false;
@@ -83,7 +86,7 @@ bool DatabasePostgreSQL::GetLoginDataFromAccountName(string name, string &passwo
char *error = PQresultErrorMessage(res);
if(strlen(error) > 0)
{
server_log->Log(log_database, "Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
Log.Out(Logs::General, Logs::Database,"Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
PQclear(res);
return false;
}
@@ -103,6 +106,7 @@ bool DatabasePostgreSQL::GetLoginDataFromAccountName(string name, string &passwo
bool DatabasePostgreSQL::GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id,
unsigned int &trusted, string &list_desc, string &account, string &password)
{
_eqp
if(!db)
{
return false;
@@ -135,7 +139,7 @@ bool DatabasePostgreSQL::GetWorldRegistration(string long_name, string short_nam
char *error = PQresultErrorMessage(res);
if(strlen(error) > 0)
{
server_log->Log(log_database, "Database error in DatabasePostgreSQL::GetWorldRegistration(): %s", error);
Log.Out(Logs::General, Logs::Database,"Database error in DatabasePostgreSQL::GetWorldRegistration(): %s", error);
PQclear(res);
return false;
}
@@ -160,6 +164,7 @@ bool DatabasePostgreSQL::GetWorldRegistration(string long_name, string short_nam
void DatabasePostgreSQL::UpdateLSAccountData(unsigned int id, string ip_address)
{
_eqp
if(!db)
{
return;
@@ -188,13 +193,14 @@ void DatabasePostgreSQL::UpdateLSAccountData(unsigned int id, string ip_address)
char *error = PQresultErrorMessage(res);
if(strlen(error) > 0)
{
server_log->Log(log_database, "Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
Log.Out(Logs::General, Logs::Database,"Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
}
PQclear(res);
}
void DatabasePostgreSQL::UpdateWorldRegistration(unsigned int id, string long_name, string ip_address)
{
_eqp
if(!db)
{
return;
@@ -225,7 +231,7 @@ void DatabasePostgreSQL::UpdateWorldRegistration(unsigned int id, string long_na
char *error = PQresultErrorMessage(res);
if(strlen(error) > 0)
{
server_log->Log(log_database, "Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
Log.Out(Logs::General, Logs::Database,"Database error in DatabasePostgreSQL::GetLoginDataFromAccountName(): %s", error);
}
PQclear(res);
}
+13 -7
View File
@@ -16,17 +16,16 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../common/global_define.h"
#include "../common/eqemu_logsys.h"
#include "encryption.h"
#include "error_log.h"
#include <string>
extern ErrorLog *server_log;
bool Encryption::LoadCrypto(std::string name)
{
_eqp
if(!Load(name.c_str()))
{
server_log->Log(log_error, "Failed to load %s from the operating system.", name.c_str());
Log.Out(Logs::Detail, Logs::Error, "Failed to load %s from the operating system.", name.c_str());
return false;
}
else
@@ -34,21 +33,21 @@ bool Encryption::LoadCrypto(std::string name)
encrypt_func = (DLLFUNC_Encrypt)GetSym("Encrypt");
if(encrypt_func == NULL)
{
server_log->Log(log_error, "Failed to attach Encrypt.");
Log.Out(Logs::Detail, Logs::Error, "Failed to attach Encrypt.");
Unload();
return false;
}
decrypt_func = (DLLFUNC_DecryptUsernamePassword)GetSym("DecryptUsernamePassword");
if(decrypt_func == NULL)
{
server_log->Log(log_error, "Failed to attach DecryptUsernamePassword.");
Log.Out(Logs::Detail, Logs::Error, "Failed to attach DecryptUsernamePassword.");
Unload();
return false;
}
delete_func = (DLLFUNC_HeapDelete)GetSym("_HeapDeleteCharBuffer");
if(delete_func == NULL)
{
server_log->Log(log_error, "Failed to attach _HeapDeleteCharBuffer.");
Log.Out(Logs::Detail, Logs::Error, "Failed to attach _HeapDeleteCharBuffer.");
Unload();
return false;
}
@@ -58,6 +57,7 @@ bool Encryption::LoadCrypto(std::string name)
char *Encryption::DecryptUsernamePassword(const char* encrypted_buffer, unsigned int buffer_size, int mode)
{
_eqp
if(decrypt_func)
{
return decrypt_func(encrypted_buffer, buffer_size, mode);
@@ -67,6 +67,7 @@ char *Encryption::DecryptUsernamePassword(const char* encrypted_buffer, unsigned
char *Encryption::Encrypt(const char* buffer, unsigned int buffer_size, unsigned int &out_size)
{
_eqp
if(encrypt_func)
{
return encrypt_func(buffer, buffer_size, out_size);
@@ -76,6 +77,7 @@ char *Encryption::Encrypt(const char* buffer, unsigned int buffer_size, unsigned
void Encryption::DeleteHeap(char *buffer)
{
_eqp
if(delete_func)
{
delete_func(buffer);
@@ -84,6 +86,7 @@ void Encryption::DeleteHeap(char *buffer)
bool Encryption::Load(const char *name)
{
_eqp
SetLastError(0);
#ifdef UNICODE
int name_length = strlen(name);
@@ -111,6 +114,7 @@ bool Encryption::Load(const char *name)
void Encryption::Unload()
{
_eqp
if(h_dll)
{
FreeLibrary(h_dll);
@@ -120,6 +124,7 @@ void Encryption::Unload()
bool Encryption::GetSym(const char *name, void **sym)
{
_eqp
if(Loaded())
{
*sym = GetProcAddress(h_dll, name);
@@ -133,6 +138,7 @@ bool Encryption::GetSym(const char *name, void **sym)
void *Encryption::GetSym(const char *name)
{
_eqp
if(Loaded())
{
return GetProcAddress(h_dll, name);
-210
View File
@@ -1,210 +0,0 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
#include "error_log.h"
const char *eqLogTypes[_log_largest_type] =
{
"Debug",
"Error",
"Database",
"Network",
"Network Trace",
"Network Error",
"World",
"World Error",
"Client",
"Client Error"
};
ErrorLog::ErrorLog(const char* file_name)
{
log_mutex = new Mutex();
error_log = fopen(file_name, "w");
}
ErrorLog::~ErrorLog()
{
log_mutex->lock();
if(error_log)
{
fclose(error_log);
}
log_mutex->unlock();
delete log_mutex;
}
void ErrorLog::Log(eqLogType type, const char *message, ...)
{
if(type >= _log_largest_type)
{
return;
}
va_list argptr;
char *buffer = new char[4096];
va_start(argptr, message);
vsnprintf(buffer, 4096, message, argptr);
va_end(argptr);
time_t m_clock;
struct tm *m_time;
time(&m_clock);
m_time = localtime(&m_clock);
log_mutex->lock();
printf("[%s] [%02d.%02d.%02d - %02d:%02d:%02d] %s\n",
eqLogTypes[type],
m_time->tm_mon+1,
m_time->tm_mday,
m_time->tm_year%100,
m_time->tm_hour,
m_time->tm_min,
m_time->tm_sec,
buffer);
if(error_log)
{
fprintf(error_log, "[%s] [%02d.%02d.%02d - %02d:%02d:%02d] %s\n",
eqLogTypes[type],
m_time->tm_mon+1,
m_time->tm_mday,
m_time->tm_year%100,
m_time->tm_hour,
m_time->tm_min,
m_time->tm_sec,
buffer);
fflush(error_log);
}
log_mutex->unlock();
delete[] buffer;
}
void ErrorLog::LogPacket(eqLogType type, const char *data, size_t size)
{
if(type >= _log_largest_type)
{
return;
}
log_mutex->lock();
time_t m_clock;
struct tm *m_time;
time(&m_clock);
m_time = localtime(&m_clock);
log_mutex->lock();
printf("[%s] [%02d.%02d.%02d - %02d:%02d:%02d] dumping packet of size %u:\n",
eqLogTypes[type],
m_time->tm_mon+1,
m_time->tm_mday,
m_time->tm_year%100,
m_time->tm_hour,
m_time->tm_min,
m_time->tm_sec,
(unsigned int)size);
if(error_log)
{
fprintf(error_log, "[%s] [%02d.%02d.%02d - %02d:%02d:%02d] dumping packet of size %u\n",
eqLogTypes[type],
m_time->tm_mon+1,
m_time->tm_mday,
m_time->tm_year%100,
m_time->tm_hour,
m_time->tm_min,
m_time->tm_sec,
(unsigned int)size);
}
char ascii[17]; //16 columns + 1 null term
memset(ascii, 0, 17);
size_t j = 0;
size_t i = 0;
for(; i < size; ++i)
{
if(i % 16 == 0)
{
if(i != 0)
{
printf(" | %s\n", ascii);
if(error_log)
{
fprintf(error_log, " | %s\n", ascii);
}
}
printf("%.4u: ", (unsigned int)i);
memset(ascii, 0, 17);
j = 0;
}
else if(i % 8 == 0)
{
printf("- ");
if(error_log)
{
fprintf(error_log, "- ");
}
}
printf("%02X ", (unsigned int)data[i]);
if(error_log)
{
fprintf(error_log, "%02X ", (unsigned int)data[i]);
}
if(data[i] >= 32 && data[i] < 127)
{
ascii[j++] = data[i];
}
else
{
ascii[j++] = '.';
}
}
size_t k = (i - 1) % 16;
if(k < 8)
{
printf(" ");
if(error_log)
{
fprintf(error_log, " ");
}
}
for(size_t h = k + 1; h < 16; ++h)
{
printf(" ");
if(error_log)
{
fprintf(error_log, " ");
}
}
printf(" | %s\n", ascii);
if(error_log)
{
fprintf(error_log, " | %s\n", ascii);
fflush(error_log);
}
log_mutex->unlock();
}
-79
View File
@@ -1,79 +0,0 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef EQEMU_ERROR_LOG_H
#define EQEMU_ERROR_LOG_H
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <string>
#include "../common/mutex.h"
/**
* Dictates the log type specified in ErrorLog for Log(...)
*/
enum eqLogType
{
log_debug,
log_error,
log_database,
log_network,
log_network_trace,
log_network_error,
log_world,
log_world_error,
log_client,
log_client_error,
_log_largest_type
};
/**
* Basic error logging class.
* Thread safe logging class that records time and date to both a file and to console(if exists).
*/
class ErrorLog
{
public:
/**
* Constructor: opens the log file for writing and creates our mutex for writing to the log.
*/
ErrorLog(const char* file_name);
/**
* Closes the file and destroys the mutex.
*/
~ErrorLog();
/**
* Writes to the log system a variable message.
*/
void Log(eqLogType type, const char *message, ...);
/**
* Writes to the log system a packet.
*/
void LogPacket(eqLogType type, const char *data, size_t size);
protected:
Mutex *log_mutex;
FILE* error_log;
};
#endif
-1
View File
@@ -18,7 +18,6 @@
#ifndef EQEMU_LOGINSERVER_H
#define EQEMU_LOGINSERVER_H
#include "error_log.h"
#include "config.h"
#include "database.h"
#include "database_mysql.h"
+62 -50
View File
@@ -26,38 +26,60 @@
#include "login_server.h"
#include <time.h>
#include <stdlib.h>
#include <signal.h>
#include <string>
#include <sstream>
#include <fstream>
TimeoutManager timeout_manager;
LoginServer server;
EQEmuLogSys Log;
ErrorLog *server_log;
bool run_server = true;
void CatchSignal(int sig_num)
{
_eqp_dump_file("loginserver");
}
int main()
{
RegisterExecutablePlatform(ExePlatformLogin);
set_exception_handler();
_eqp
//Create our error log, is of format login_<number>.log
time_t current_time = time(nullptr);
std::stringstream log_name(std::stringstream::in | std::stringstream::out);
#ifdef WIN32
log_name << ".\\logs\\login_" << (unsigned int)current_time << ".log";
#else
log_name << "./logs/login_" << (unsigned int)current_time << ".log";
#endif
server_log = new ErrorLog(log_name.str().c_str());
server_log->Log(log_debug, "Logging System Init.");
Log.LoadLogSettingsDefaults();
//log_settings
Log.log_settings[Logs::LogCategory::Crash].log_to_file = true;
Log.log_settings[Logs::LogCategory::Error].log_to_console = true;
Log.log_settings[Logs::LogCategory::Error].log_to_file = true;
Log.log_settings[Logs::LogCategory::Debug].log_to_console = true;
Log.log_settings[Logs::LogCategory::Debug].log_to_file = true;
Log.log_settings[Logs::LogCategory::Database].log_to_console = true;
Log.log_settings[Logs::LogCategory::Database].log_to_file = true;
Log.log_settings[Logs::LogCategory::World_Server].log_to_console = true;
Log.log_settings[Logs::LogCategory::World_Server].log_to_file = true;
Log.log_settings[Logs::LogCategory::Netcode].log_to_console = true;
Log.log_settings[Logs::LogCategory::Netcode].log_to_file = true;
Log.file_logs_enabled = true;
Log.StartFileLogs();
if(signal(SIGINT, CatchSignal) == SIG_ERR) {
Log.Out(Logs::Detail, Logs::Error, "Could not set signal handler");
return 1;
}
if(signal(SIGTERM, CatchSignal) == SIG_ERR) {
Log.Out(Logs::Detail, Logs::Error, "Could not set signal handler");
return 1;
}
if(signal(SIGBREAK, CatchSignal) == SIG_ERR) {
Log.Out(Logs::Detail, Logs::Error, "Could not set signal handler");
return 1;
}
//Create our subsystem and parse the ini file.
server.config = new Config();
server_log->Log(log_debug, "Config System Init.");
Log.Out(Logs::General, Logs::Debug, "Config System Init.");
server.config->Parse("login.ini");
//Parse unregistered allowed option.
@@ -142,7 +164,7 @@ int main()
if(server.config->GetVariable("database", "subsystem").compare("MySQL") == 0)
{
#ifdef EQEMU_MYSQL_ENABLED
server_log->Log(log_debug, "MySQL Database Init.");
Log.Out(Logs::General, Logs::Debug, "MySQL Database Init.");
server.db = (Database*)new DatabaseMySQL(
server.config->GetVariable("database", "user"),
server.config->GetVariable("database", "password"),
@@ -154,7 +176,7 @@ int main()
else if(server.config->GetVariable("database", "subsystem").compare("PostgreSQL") == 0)
{
#ifdef EQEMU_POSTGRESQL_ENABLED
server_log->Log(log_debug, "PostgreSQL Database Init.");
Log.Out(Logs::General, Logs::Debug, "PostgreSQL Database Init.");
server.db = (Database*)new DatabasePostgreSQL(
server.config->GetVariable("database", "user"),
server.config->GetVariable("database", "password"),
@@ -167,75 +189,67 @@ int main()
//Make sure our database got created okay, otherwise cleanup and exit.
if(!server.db)
{
server_log->Log(log_error, "Database Initialization Failure.");
server_log->Log(log_debug, "Config System Shutdown.");
Log.Out(Logs::Detail, Logs::Error, "Database Initialization Failure.");
Log.Out(Logs::General, Logs::Debug, "Config System Shutdown.");
delete server.config;
server_log->Log(log_debug, "Log System Shutdown.");
delete server_log;
return 1;
}
#if WIN32
//initialize our encryption.
server_log->Log(log_debug, "Encryption Initialize.");
Log.Out(Logs::General, Logs::Debug, "Encryption Initialize.");
server.eq_crypto = new Encryption();
if(server.eq_crypto->LoadCrypto(server.config->GetVariable("security", "plugin")))
{
server_log->Log(log_debug, "Encryption Loaded Successfully.");
Log.Out(Logs::General, Logs::Debug, "Encryption Loaded Successfully.");
}
else
{
//We can't run without encryption, cleanup and exit.
server_log->Log(log_error, "Encryption Failed to Load.");
server_log->Log(log_debug, "Database System Shutdown.");
Log.Out(Logs::Detail, Logs::Error, "Encryption Failed to Load.");
Log.Out(Logs::General, Logs::Debug, "Database System Shutdown.");
delete server.db;
server_log->Log(log_debug, "Config System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Config System Shutdown.");
delete server.config;
server_log->Log(log_debug, "Log System Shutdown.");
delete server_log;
return 1;
}
#endif
//create our server manager.
server_log->Log(log_debug, "Server Manager Initialize.");
Log.Out(Logs::General, Logs::Debug, "Server Manager Initialize.");
server.SM = new ServerManager();
if(!server.SM)
{
//We can't run without a server manager, cleanup and exit.
server_log->Log(log_error, "Server Manager Failed to Start.");
Log.Out(Logs::Detail, Logs::Error, "Server Manager Failed to Start.");
#ifdef WIN32
server_log->Log(log_debug, "Encryption System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Encryption System Shutdown.");
delete server.eq_crypto;
#endif
server_log->Log(log_debug, "Database System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Database System Shutdown.");
delete server.db;
server_log->Log(log_debug, "Config System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Config System Shutdown.");
delete server.config;
server_log->Log(log_debug, "Log System Shutdown.");
delete server_log;
return 1;
}
//create our client manager.
server_log->Log(log_debug, "Client Manager Initialize.");
Log.Out(Logs::General, Logs::Debug, "Client Manager Initialize.");
server.CM = new ClientManager();
if(!server.CM)
{
//We can't run without a client manager, cleanup and exit.
server_log->Log(log_error, "Client Manager Failed to Start.");
server_log->Log(log_debug, "Server Manager Shutdown.");
Log.Out(Logs::Detail, Logs::Error, "Client Manager Failed to Start.");
Log.Out(Logs::General, Logs::Debug, "Server Manager Shutdown.");
delete server.SM;
#ifdef WIN32
server_log->Log(log_debug, "Encryption System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Encryption System Shutdown.");
delete server.eq_crypto;
#endif
server_log->Log(log_debug, "Database System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Database System Shutdown.");
delete server.db;
server_log->Log(log_debug, "Config System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Config System Shutdown.");
delete server.config;
server_log->Log(log_debug, "Log System Shutdown.");
delete server_log;
return 1;
}
@@ -247,30 +261,28 @@ int main()
#endif
#endif
server_log->Log(log_debug, "Server Started.");
Log.Out(Logs::General, Logs::Debug, "Server Started.");
while(run_server)
{
Timer::SetCurrentTime();
server.CM->Process();
server.SM->Process();
Sleep(100);
Sleep(50);
}
server_log->Log(log_debug, "Server Shutdown.");
server_log->Log(log_debug, "Client Manager Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Server Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Client Manager Shutdown.");
delete server.CM;
server_log->Log(log_debug, "Server Manager Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Server Manager Shutdown.");
delete server.SM;
#ifdef WIN32
server_log->Log(log_debug, "Encryption System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Encryption System Shutdown.");
delete server.eq_crypto;
#endif
server_log->Log(log_debug, "Database System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Database System Shutdown.");
delete server.db;
server_log->Log(log_debug, "Config System Shutdown.");
Log.Out(Logs::General, Logs::Debug, "Config System Shutdown.");
delete server.config;
server_log->Log(log_debug, "Log System Shutdown.");
delete server_log;
return 0;
}
+17 -9
View File
@@ -17,33 +17,34 @@
*/
#include "server_manager.h"
#include "login_server.h"
#include "error_log.h"
#include "login_structures.h"
#include "../common/eqemu_logsys.h"
#include <stdlib.h>
extern ErrorLog *server_log;
extern LoginServer server;
extern bool run_server;
ServerManager::ServerManager()
{
_eqp
char error_buffer[TCPConnection_ErrorBufferSize];
int listen_port = atoi(server.config->GetVariable("options", "listen_port").c_str());
tcps = new EmuTCPServer(listen_port, true);
if(tcps->Open(listen_port, error_buffer))
{
server_log->Log(log_network, "ServerManager listening on port %u", listen_port);
Log.Out(Logs::General, Logs::Netcode, "ServerManager listening on port %u", listen_port);
}
else
{
server_log->Log(log_error, "ServerManager fatal error opening port on %u: %s", listen_port, error_buffer);
Log.Out(Logs::Detail, Logs::Error, "ServerManager fatal error opening port on %u: %s", listen_port, error_buffer);
run_server = false;
}
}
ServerManager::~ServerManager()
{
_eqp
if(tcps)
{
tcps->Close();
@@ -53,18 +54,19 @@ ServerManager::~ServerManager()
void ServerManager::Process()
{
_eqp
ProcessDisconnect();
EmuTCPConnection *tcp_c = nullptr;
while(tcp_c = tcps->NewQueuePop())
{
in_addr tmp;
tmp.s_addr = tcp_c->GetrIP();
server_log->Log(log_network, "New world server connection from %s:%d", inet_ntoa(tmp), tcp_c->GetrPort());
Log.Out(Logs::General, Logs::Netcode, "New world server connection from %s:%d", inet_ntoa(tmp), tcp_c->GetrPort());
WorldServer *cur = GetServerByAddress(tcp_c->GetrIP());
if(cur)
{
server_log->Log(log_network, "World server already existed for %s, removing existing connection and updating current.", inet_ntoa(tmp));
Log.Out(Logs::General, Logs::Netcode, "World server already existed for %s, removing existing connection and updating current.", inet_ntoa(tmp));
cur->GetConnection()->Free();
cur->SetConnection(tcp_c);
cur->Reset();
@@ -81,7 +83,7 @@ void ServerManager::Process()
{
if((*iter)->Process() == false)
{
server_log->Log(log_world, "World server %s had a fatal error and had to be removed from the login.", (*iter)->GetLongName().c_str());
Log.Out(Logs::General, Logs::World_Server, "World server %s had a fatal error and had to be removed from the login.", (*iter)->GetLongName().c_str());
delete (*iter);
iter = world_servers.erase(iter);
}
@@ -94,6 +96,7 @@ void ServerManager::Process()
void ServerManager::ProcessDisconnect()
{
_eqp
list<WorldServer*>::iterator iter = world_servers.begin();
while(iter != world_servers.end())
{
@@ -102,7 +105,7 @@ void ServerManager::ProcessDisconnect()
{
in_addr tmp;
tmp.s_addr = c->GetrIP();
server_log->Log(log_network, "World server disconnected from the server, removing server and freeing connection.");
Log.Out(Logs::General, Logs::Netcode, "World server disconnected from the server, removing server and freeing connection.");
c->Free();
delete (*iter);
iter = world_servers.erase(iter);
@@ -116,6 +119,7 @@ void ServerManager::ProcessDisconnect()
WorldServer* ServerManager::GetServerByAddress(unsigned int address)
{
_eqp
list<WorldServer*>::iterator iter = world_servers.begin();
while(iter != world_servers.end())
{
@@ -131,6 +135,7 @@ WorldServer* ServerManager::GetServerByAddress(unsigned int address)
EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c)
{
_eqp
unsigned int packet_size = sizeof(ServerListHeader_Struct);
unsigned int server_count = 0;
in_addr in;
@@ -268,6 +273,7 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c)
void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int client_account_id)
{
_eqp
list<WorldServer*>::iterator iter = world_servers.begin();
bool found = false;
while(iter != world_servers.end())
@@ -292,12 +298,13 @@ void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int
if(!found && server.options.IsTraceOn())
{
server_log->Log(log_client_error, "Client requested a user to world but supplied an invalid id of %u.", server_id);
Log.Out(Logs::General, Logs::Error, "Client requested a user to world but supplied an invalid id of %u.", server_id);
}
}
bool ServerManager::ServerExists(string l_name, string s_name, WorldServer *ignore)
{
_eqp
list<WorldServer*>::iterator iter = world_servers.begin();
while(iter != world_servers.end())
{
@@ -319,6 +326,7 @@ bool ServerManager::ServerExists(string l_name, string s_name, WorldServer *igno
void ServerManager::DestroyServerByName(string l_name, string s_name, WorldServer *ignore)
{
_eqp
list<WorldServer*>::iterator iter = world_servers.begin();
while(iter != world_servers.end())
{
+51 -45
View File
@@ -16,15 +16,15 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "world_server.h"
#include "error_log.h"
#include "login_server.h"
#include "login_structures.h"
#include "../common/eqemu_logsys.h"
extern ErrorLog *server_log;
extern LoginServer server;
WorldServer::WorldServer(EmuTCPConnection *c)
{
_eqp
connection = c;
zones_booted = 0;
players_online = 0;
@@ -39,6 +39,7 @@ WorldServer::WorldServer(EmuTCPConnection *c)
WorldServer::~WorldServer()
{
_eqp
if(connection)
{
connection->Free();
@@ -47,6 +48,7 @@ WorldServer::~WorldServer()
void WorldServer::Reset()
{
_eqp
zones_booted = 0;
players_online = 0;
status = 0;
@@ -59,12 +61,13 @@ void WorldServer::Reset()
bool WorldServer::Process()
{
_eqp
ServerPacket *app = nullptr;
while(app = connection->PopPacket())
{
if(server.options.IsWorldTraceOn())
{
server_log->Log(log_network_trace, "Application packet received from server: 0x%.4X, (size %u)", app->opcode, app->size);
Log.Out(Logs::Detail, Logs::Netcode, "Application packet received from server: 0x%.4X, (size %u)", app->opcode, app->size);
}
if(server.options.IsDumpInPacketsOn())
@@ -78,14 +81,14 @@ bool WorldServer::Process()
{
if(app->size < sizeof(ServerNewLSInfo_Struct))
{
server_log->Log(log_network_error, "Received application packet from server that had opcode ServerOP_NewLSInfo, "
Log.Out(Logs::General, Logs::Netcode, "Received application packet from server that had opcode ServerOP_NewLSInfo, "
"but was too small. Discarded to avoid buffer overrun.");
break;
}
if(server.options.IsWorldTraceOn())
{
server_log->Log(log_network_trace, "New Login Info Recieved.");
Log.Out(Logs::Detail, Logs::Netcode, "New Login Info Recieved.");
}
ServerNewLSInfo_Struct *info = (ServerNewLSInfo_Struct*)app->pBuffer;
@@ -96,14 +99,14 @@ bool WorldServer::Process()
{
if(app->size < sizeof(ServerLSStatus_Struct))
{
server_log->Log(log_network_error, "Recieved application packet from server that had opcode ServerOP_LSStatus, "
Log.Out(Logs::General, Logs::Netcode, "Recieved application packet from server that had opcode ServerOP_LSStatus, "
"but was too small. Discarded to avoid buffer overrun.");
break;
}
if(server.options.IsWorldTraceOn())
{
server_log->Log(log_network_trace, "World Server Status Recieved.");
Log.Out(Logs::Detail, Logs::Netcode, "World Server Status Recieved.");
}
ServerLSStatus_Struct *ls_status = (ServerLSStatus_Struct*)app->pBuffer;
@@ -127,7 +130,7 @@ bool WorldServer::Process()
{
if(app->size < sizeof(UsertoWorldResponse_Struct))
{
server_log->Log(log_network_error, "Recieved application packet from server that had opcode ServerOP_UsertoWorldResp, "
Log.Out(Logs::General, Logs::Netcode, "Recieved application packet from server that had opcode ServerOP_UsertoWorldResp, "
"but was too small. Discarded to avoid buffer overrun.");
break;
}
@@ -137,21 +140,21 @@ bool WorldServer::Process()
//While keeping world server spam with multiple servers connected almost impossible.
if(server.options.IsTraceOn())
{
server_log->Log(log_network_trace, "User-To-World Response received.");
Log.Out(Logs::Detail, Logs::Netcode, "User-To-World Response received.");
}
UsertoWorldResponse_Struct *utwr = (UsertoWorldResponse_Struct*)app->pBuffer;
server_log->Log(log_client, "Trying to find client with user id of %u.", utwr->lsaccountid);
Log.Out(Logs::General, Logs::LoginServer, "Trying to find client with user id of %u.", utwr->lsaccountid);
Client *c = server.CM->GetClient(utwr->lsaccountid);
if(c)
{
server_log->Log(log_client, "Found client with user id of %u and account name of %s.", utwr->lsaccountid, c->GetAccountName().c_str());
Log.Out(Logs::General, Logs::LoginServer, "Found client with user id of %u and account name of %s.", utwr->lsaccountid, c->GetAccountName().c_str());
EQApplicationPacket *outapp = new EQApplicationPacket(OP_PlayEverquestResponse, sizeof(PlayEverquestResponse_Struct));
PlayEverquestResponse_Struct *per = (PlayEverquestResponse_Struct*)outapp->pBuffer;
per->Sequence = c->GetPlaySequence();
per->ServerNumber = c->GetPlayServerID();
server_log->Log(log_client, "Found sequence and play of %u %u", c->GetPlaySequence(), c->GetPlayServerID());
server_log->LogPacket(log_network_trace, (const char*)outapp->pBuffer, outapp->size);
Log.Out(Logs::General, Logs::LoginServer, "Found sequence and play of %u %u", c->GetPlaySequence(), c->GetPlayServerID());
//server_log->LogPacket(log_network_trace, (const char*)outapp->pBuffer, outapp->size);
if(utwr->response > 0)
{
@@ -180,9 +183,9 @@ bool WorldServer::Process()
if(server.options.IsTraceOn())
{
server_log->Log(log_network_trace, "Sending play response with following data, allowed %u, sequence %u, server number %u, message %u",
Log.Out(Logs::Detail, Logs::Netcode, "Sending play response with following data, allowed %u, sequence %u, server number %u, message %u",
per->Allowed, per->Sequence, per->ServerNumber, per->Message);
server_log->LogPacket(log_network_trace, (const char*)outapp->pBuffer, outapp->size);
//server_log->LogPacket(log_network_trace, (const char*)outapp->pBuffer, outapp->size);
}
if(server.options.IsDumpOutPacketsOn())
@@ -195,7 +198,7 @@ bool WorldServer::Process()
}
else
{
server_log->Log(log_client_error, "Recieved User-To-World Response for %u but could not find the client referenced!.", utwr->lsaccountid);
Log.Out(Logs::General, Logs::Error, "Recieved User-To-World Response for %u but could not find the client referenced!.", utwr->lsaccountid);
}
break;
}
@@ -203,16 +206,16 @@ bool WorldServer::Process()
{
if(app->size < sizeof(ServerLSAccountUpdate_Struct))
{
server_log->Log(log_network_error, "Recieved application packet from server that had opcode ServerLSAccountUpdate_Struct, "
Log.Out(Logs::General, Logs::Netcode, "Recieved application packet from server that had opcode ServerLSAccountUpdate_Struct, "
"but was too small. Discarded to avoid buffer overrun.");
break;
}
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate packet received from: %s", short_name.c_str());
Log.Out(Logs::Detail, Logs::Netcode, "ServerOP_LSAccountUpdate packet received from: %s", short_name.c_str());
ServerLSAccountUpdate_Struct *lsau = (ServerLSAccountUpdate_Struct*)app->pBuffer;
if(trusted)
{
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate update processed for: %s", lsau->useraccount);
Log.Out(Logs::Detail, Logs::Netcode, "ServerOP_LSAccountUpdate update processed for: %s", lsau->useraccount);
string name;
string password;
string email;
@@ -225,7 +228,7 @@ bool WorldServer::Process()
}
default:
{
server_log->Log(log_network_error, "Recieved application packet from server that had an unknown operation code 0x%.4X.", app->opcode);
Log.Out(Logs::General, Logs::Netcode, "Recieved application packet from server that had an unknown operation code 0x%.4X.", app->opcode);
}
}
@@ -237,9 +240,10 @@ bool WorldServer::Process()
void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
_eqp
if(logged_in)
{
server_log->Log(log_network_error, "WorldServer::Handle_NewLSInfo called but the login server was already marked as logged in, aborting.");
Log.Out(Logs::General, Logs::Netcode, "WorldServer::Handle_NewLSInfo called but the login server was already marked as logged in, aborting.");
return;
}
@@ -249,7 +253,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_network_error, "Handle_NewLSInfo error, account name was too long.");
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, account name was too long.");
return;
}
@@ -259,7 +263,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_network_error, "Handle_NewLSInfo error, account password was too long.");
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, account password was too long.");
return;
}
@@ -269,7 +273,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_network_error, "Handle_NewLSInfo error, long name was too long.");
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, long name was too long.");
return;
}
@@ -279,7 +283,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_network_error, "Handle_NewLSInfo error, short name was too long.");
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, short name was too long.");
return;
}
@@ -287,7 +291,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
if(strlen(i->local_address) == 0)
{
server_log->Log(log_network_error, "Handle_NewLSInfo error, local address was null, defaulting to localhost");
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, local address was null, defaulting to localhost");
local_ip = "127.0.0.1";
}
else
@@ -297,7 +301,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_network_error, "Handle_NewLSInfo error, local address was too long.");
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, local address was too long.");
return;
}
@@ -308,7 +312,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
in_addr in;
in.s_addr = GetConnection()->GetrIP();
remote_ip = inet_ntoa(in);
server_log->Log(log_network_error, "Handle_NewLSInfo error, remote address was null, defaulting to stream address %s.", remote_ip.c_str());
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, remote address was null, defaulting to stream address %s.", remote_ip.c_str());
}
else
{
@@ -320,7 +324,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
in_addr in;
in.s_addr = GetConnection()->GetrIP();
remote_ip = inet_ntoa(in);
server_log->Log(log_network_error, "Handle_NewLSInfo error, remote address was too long, defaulting to stream address %s.", remote_ip.c_str());
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, remote address was too long, defaulting to stream address %s.", remote_ip.c_str());
}
if(strlen(i->serverversion) <= 64)
@@ -329,7 +333,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_network_error, "Handle_NewLSInfo error, server version was too long.");
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, server version was too long.");
return;
}
@@ -339,7 +343,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_network_error, "Handle_NewLSInfo error, protocol version was too long.");
Log.Out(Logs::General, Logs::Netcode, "Handle_NewLSInfo error, protocol version was too long.");
return;
}
@@ -350,7 +354,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
if(server.SM->ServerExists(long_name, short_name, this))
{
server_log->Log(log_world_error, "World tried to login but there already exists a server that has that name.");
Log.Out(Logs::General, Logs::Error, "World tried to login but there already exists a server that has that name.");
return;
}
}
@@ -358,7 +362,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
if(server.SM->ServerExists(long_name, short_name, this))
{
server_log->Log(log_world_error, "World tried to login but there already exists a server that has that name.");
Log.Out(Logs::General, Logs::Error, "World tried to login but there already exists a server that has that name.");
server.SM->DestroyServerByName(long_name, short_name, this);
}
}
@@ -378,7 +382,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
if(s_acct_name.size() == 0 || s_acct_pass.size() == 0)
{
server_log->Log(log_world, "Server %s(%s) successfully logged into account that had no user/password requirement.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) successfully logged into account that had no user/password requirement.",
long_name.c_str(), short_name.c_str());
authorized = true;
SetRuntimeID(s_id);
@@ -387,7 +391,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else if(s_acct_name.compare(account_name) == 0 && s_acct_pass.compare(account_password) == 0)
{
server_log->Log(log_world, "Server %s(%s) successfully logged in.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) successfully logged in.",
long_name.c_str(), short_name.c_str());
authorized = true;
SetRuntimeID(s_id);
@@ -395,7 +399,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
desc = s_desc;
if(s_trusted)
{
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate sent to world");
Log.Out(Logs::Detail, Logs::Netcode, "ServerOP_LSAccountUpdate sent to world");
trusted = true;
ServerPacket *outapp = new ServerPacket(ServerOP_LSAccountUpdate, 0);
connection->SendPacket(outapp);
@@ -403,21 +407,21 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_world, "Server %s(%s) attempted to log in but account and password did not match the entry in the database, and only"
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) attempted to log in but account and password did not match the entry in the database, and only"
" registered servers are allowed.", long_name.c_str(), short_name.c_str());
return;
}
}
else
{
server_log->Log(log_world, "Server %s(%s) attempted to log in but database couldn't find an entry and only registered servers are allowed.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) attempted to log in but database couldn't find an entry and only registered servers are allowed.",
long_name.c_str(), short_name.c_str());
return;
}
}
else
{
server_log->Log(log_world, "Server %s(%s) did not attempt to log in but only registered servers are allowed.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) did not attempt to log in but only registered servers are allowed.",
long_name.c_str(), short_name.c_str());
return;
}
@@ -437,7 +441,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
if(s_acct_name.compare(account_name) == 0 && s_acct_pass.compare(account_password) == 0)
{
server_log->Log(log_world, "Server %s(%s) successfully logged in.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) successfully logged in.",
long_name.c_str(), short_name.c_str());
authorized = true;
SetRuntimeID(s_id);
@@ -445,7 +449,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
desc = s_desc;
if(s_trusted)
{
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate sent to world");
Log.Out(Logs::Detail, Logs::Netcode, "ServerOP_LSAccountUpdate sent to world");
trusted = true;
ServerPacket *outapp = new ServerPacket(ServerOP_LSAccountUpdate, 0);
connection->SendPacket(outapp);
@@ -454,7 +458,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
else
{
// this is the first of two cases where we should deny access even if unregistered is allowed
server_log->Log(log_world, "Server %s(%s) attempted to log in but account and password did not match the entry in the database.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) attempted to log in but account and password did not match the entry in the database.",
long_name.c_str(), short_name.c_str());
}
}
@@ -463,12 +467,12 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
if(s_acct_name.size() > 0 || s_acct_pass.size() > 0)
{
// this is the second of two cases where we should deny access even if unregistered is allowed
server_log->Log(log_world, "Server %s(%s) did not attempt to log in but this server requires a password.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) did not attempt to log in but this server requires a password.",
long_name.c_str(), short_name.c_str());
}
else
{
server_log->Log(log_world, "Server %s(%s) did not attempt to log in but unregistered servers are allowed.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) did not attempt to log in but unregistered servers are allowed.",
long_name.c_str(), short_name.c_str());
authorized = true;
SetRuntimeID(s_id);
@@ -478,7 +482,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
server_log->Log(log_world, "Server %s(%s) attempted to log in but database couldn't find an entry but unregistered servers are allowed.",
Log.Out(Logs::General, Logs::World_Server, "Server %s(%s) attempted to log in but database couldn't find an entry but unregistered servers are allowed.",
long_name.c_str(), short_name.c_str());
if(server.db->CreateWorldRegistration(long_name, short_name, s_id))
{
@@ -501,6 +505,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
void WorldServer::Handle_LSStatus(ServerLSStatus_Struct *s)
{
_eqp
players_online = s->num_players;
zones_booted = s->num_zones;
status = s->status;
@@ -508,6 +513,7 @@ void WorldServer::Handle_LSStatus(ServerLSStatus_Struct *s)
void WorldServer::SendClientAuth(unsigned int ip, string account, string key, unsigned int account_id)
{
_eqp
ServerPacket *outapp = new ServerPacket(ServerOP_LSClientAuth, sizeof(ServerLSClientAuth));
ServerLSClientAuth* slsca = (ServerLSClientAuth*)outapp->pBuffer;
+4 -2
View File
@@ -21,15 +21,17 @@ INSTALL(TARGETS queryserv RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
ADD_DEFINITIONS(-DQSERV)
TARGET_LINK_LIBRARIES(queryserv common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
TARGET_LINK_LIBRARIES(queryserv common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
IF(MSVC)
SET_TARGET_PROPERTIES(queryserv PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(queryserv "Ws2_32.lib")
TARGET_LINK_LIBRARIES(queryserv "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(queryserv "WS2_32")
TARGET_LINK_LIBRARIES(queryserv "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@@ -40,7 +42,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(queryserv "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(queryserv "pthread")
ADD_DEFINITIONS(-fPIC)
TARGET_LINK_LIBRARIES(queryserv "uuid")
ENDIF(UNIX)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+26 -8
View File
@@ -50,6 +50,7 @@
Database::Database ()
{
_eqp
DBInitVars();
}
@@ -59,12 +60,14 @@ Establish a connection to a mysql database with the supplied parameters
Database::Database(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
{
_eqp
DBInitVars();
Connect(host, user, passwd, database, port);
}
bool Database::Connect(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
{
_eqp
uint32 errnum= 0;
char errbuf[MYSQL_ERRMSG_SIZE];
if (!Open(host, user, passwd, database, port, &errnum, errbuf))
@@ -82,12 +85,13 @@ bool Database::Connect(const char* host, const char* user, const char* passwd, c
}
void Database::DBInitVars() {
_eqp
}
void Database::HandleMysqlError(uint32 errnum) {
_eqp
}
/*
@@ -96,10 +100,11 @@ Close the connection to the database
*/
Database::~Database()
{
_eqp
}
void Database::AddSpeech(const char* from, const char* to, const char* message, uint16 minstatus, uint32 guilddbid, uint8 type) {
_eqp
char *escapedFrom = new char[strlen(from) * 2 + 1];
char *escapedTo = new char[strlen(to) * 2 + 1];
char *escapedMessage = new char[strlen(message) * 2 + 1];
@@ -124,7 +129,7 @@ void Database::AddSpeech(const char* from, const char* to, const char* message,
}
void Database::LogPlayerTrade(QSPlayerLogTrade_Struct* QS, uint32 detailCount) {
_eqp
std::string query = StringFormat("INSERT INTO `qs_player_trade_record` SET `time` = NOW(), "
"`char1_id` = '%i', `char1_pp` = '%i', `char1_gp` = '%i', "
"`char1_sp` = '%i', `char1_cp` = '%i', `char1_items` = '%i', "
@@ -165,7 +170,7 @@ void Database::LogPlayerTrade(QSPlayerLogTrade_Struct* QS, uint32 detailCount) {
}
void Database::LogPlayerHandin(QSPlayerLogHandin_Struct* QS, uint32 detailCount) {
_eqp
std::string query = StringFormat("INSERT INTO `qs_player_handin_record` SET `time` = NOW(), "
"`quest_id` = '%i', `char_id` = '%i', `char_pp` = '%i', "
"`char_gp` = '%i', `char_sp` = '%i', `char_cp` = '%i', "
@@ -206,7 +211,7 @@ void Database::LogPlayerHandin(QSPlayerLogHandin_Struct* QS, uint32 detailCount)
}
void Database::LogPlayerNPCKill(QSPlayerLogNPCKill_Struct* QS, uint32 members){
_eqp
std::string query = StringFormat("INSERT INTO `qs_player_npc_kill_record` "
"SET `npc_id` = '%i', `type` = '%i', "
"`zone_id` = '%i', `time` = NOW()",
@@ -237,7 +242,7 @@ void Database::LogPlayerNPCKill(QSPlayerLogNPCKill_Struct* QS, uint32 members){
}
void Database::LogPlayerDelete(QSPlayerLogDelete_Struct* QS, uint32 items) {
_eqp
std::string query = StringFormat("INSERT INTO `qs_player_delete_record` SET `time` = NOW(), "
"`char_id` = '%i', `stack_size` = '%i', `char_items` = '%i'",
QS->char_id, QS->stack_size, QS->char_count, QS->char_count);
@@ -270,8 +275,8 @@ void Database::LogPlayerDelete(QSPlayerLogDelete_Struct* QS, uint32 items) {
}
void Database::LogPlayerMove(QSPlayerLogMove_Struct* QS, uint32 items) {
_eqp
/* These are item moves */
std::string query = StringFormat("INSERT INTO `qs_player_move_record` SET `time` = NOW(), "
"`char_id` = '%i', `from_slot` = '%i', `to_slot` = '%i', "
"`stack_size` = '%i', `char_items` = '%i', `postaction` = '%i'",
@@ -306,6 +311,7 @@ void Database::LogPlayerMove(QSPlayerLogMove_Struct* QS, uint32 items) {
}
void Database::LogMerchantTransaction(QSMerchantLogTransaction_Struct* QS, uint32 items) {
_eqp
/* Merchant transactions are from the perspective of the merchant, not the player -U */
std::string query = StringFormat("INSERT INTO `qs_merchant_transaction_record` SET `time` = NOW(), "
"`zone_id` = '%i', `merchant_id` = '%i', `merchant_pp` = '%i', "
@@ -347,6 +353,7 @@ void Database::LogMerchantTransaction(QSMerchantLogTransaction_Struct* QS, uint3
}
void Database::GeneralQueryReceive(ServerPacket *pack) {
_eqp
/*
These are general queries passed from anywhere in zone instead of packing structures and breaking them down again and again
*/
@@ -364,7 +371,8 @@ void Database::GeneralQueryReceive(ServerPacket *pack) {
safe_delete(queryBuffer);
}
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings){
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings) {
_eqp
std::string query =
"SELECT "
"log_category_id, "
@@ -386,6 +394,16 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings){
log_settings[log_category].log_to_file = atoi(row[3]);
log_settings[log_category].log_to_gmsay = atoi(row[4]);
/* Determine if any output method is enabled for the category
and set it to 1 so it can used to check if category is enabled */
const bool log_to_console = log_settings[log_category].log_to_console > 0;
const bool log_to_file = log_settings[log_category].log_to_file > 0;
const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0;
const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay;
if (is_category_enabled)
log_settings[log_category].is_category_enabled = 1;
/*
This determines whether or not the process needs to actually file log anything.
If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open
+11 -1
View File
@@ -12,6 +12,7 @@ extern Database database;
PlayerLookingForGuild::PlayerLookingForGuild(char *Name, char *Comments, uint32 Level, uint32 Class, uint32 AACount, uint32 Timezone, uint32 TimePosted)
{
_eqp
this->Name = Name;
this->Comments = Comments;
this->Level = Level;
@@ -23,6 +24,7 @@ PlayerLookingForGuild::PlayerLookingForGuild(char *Name, char *Comments, uint32
GuildLookingForPlayers::GuildLookingForPlayers(char *Name, char *Comments, uint32 FromLevel, uint32 ToLevel, uint32 Classes, uint32 AACount, uint32 Timezone, uint32 TimePosted)
{
_eqp
this->Name = Name;
this->Comments = Comments;
this->FromLevel = FromLevel;
@@ -35,6 +37,7 @@ GuildLookingForPlayers::GuildLookingForPlayers(char *Name, char *Comments, uint3
bool LFGuildManager::LoadDatabase()
{
_eqp
std::string query = "SELECT `type`,`name`,`comment`, "
"`fromlevel`, `tolevel`, `classes`, "
"`aacount`, `timezone`, `timeposted` FROM `lfguild`";
@@ -61,6 +64,7 @@ bool LFGuildManager::LoadDatabase()
void LFGuildManager::HandlePacket(ServerPacket *pack)
{
_eqp
char From[64];
pack->SetReadPosition(0);
@@ -150,6 +154,7 @@ void LFGuildManager::HandlePacket(ServerPacket *pack)
void LFGuildManager::SendPlayerMatches(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 FromLevel, uint32 ToLevel, uint32 MinAA, uint32 TimeZone, uint32 Classes)
{
_eqp
std::list<PlayerLookingForGuild>::iterator it;
std::list<PlayerLookingForGuild> Matches;
@@ -193,6 +198,7 @@ void LFGuildManager::SendPlayerMatches(uint32 FromZoneID, uint32 FromInstanceID,
void LFGuildManager::SendGuildMatches(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 Level, uint32 AAPoints, uint32 TimeZone, uint32 Class)
{
_eqp
std::list<GuildLookingForPlayers>::iterator it;
std::list<GuildLookingForPlayers> Matches;
@@ -232,6 +238,7 @@ void LFGuildManager::SendGuildMatches(uint32 FromZoneID, uint32 FromInstanceID,
void LFGuildManager::TogglePlayer(uint32 FromZoneID, uint32 FromInstanceID, char *From, uint32 Class, uint32 Level, uint32 AAPoints, char *Comments, uint32 Toggle, uint32 TimeZone)
{
_eqp
for(auto it = Players.begin(); it != Players.end(); ++it)
if(!strcasecmp((*it).Name.c_str(), From)) {
Players.erase(it);
@@ -273,6 +280,7 @@ void LFGuildManager::TogglePlayer(uint32 FromZoneID, uint32 FromInstanceID, char
void LFGuildManager::ToggleGuild(uint32 FromZoneID, uint32 FromInstanceID, char *From, char* GuildName, char *Comments, uint32 FromLevel, uint32 ToLevel, uint32 Classes, uint32 AACount, uint32 Toggle, uint32 TimeZone)
{
_eqp
for(auto it = Guilds.begin(); it != Guilds.end(); ++it)
if(!strcasecmp((*it).Name.c_str(), GuildName))
{
@@ -318,6 +326,7 @@ void LFGuildManager::ToggleGuild(uint32 FromZoneID, uint32 FromInstanceID, char
void LFGuildManager::ExpireEntries()
{
_eqp
for(auto it = Players.begin(); it != Players.end(); ++it)
{
if((*it).TimePosted + 604800 > (uint32)time(nullptr))
@@ -345,7 +354,7 @@ void LFGuildManager::ExpireEntries()
void LFGuildManager::SendPlayerStatus(uint32 FromZoneID, uint32 FromInstanceID, char *From)
{
_eqp
std::list<PlayerLookingForGuild>::iterator it;
for(it = Players.begin(); it != Players.end(); ++it)
@@ -373,6 +382,7 @@ void LFGuildManager::SendPlayerStatus(uint32 FromZoneID, uint32 FromInstanceID,
void LFGuildManager::SendGuildStatus(uint32 FromZoneID, uint32 FromInstanceID, char *From, char *GuildName)
{
_eqp
std::list<GuildLookingForPlayers>::iterator it;
for(it = Guilds.begin(); it != Guilds.end(); ++it)
+17 -18
View File
@@ -46,6 +46,8 @@ void CatchSignal(int sig_num) {
RunLoops = false;
if(worldserver)
worldserver->Disconnect();
_eqp_dump_file("queryserv");
}
int main() {
@@ -55,16 +57,6 @@ int main() {
Timer LFGuildExpireTimer(60000);
Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect
/* Load XML from eqemu_config.xml
<qsdatabase>
<host>127.0.0.1</host>
<port>3306</port>
<username>user</username>
<password>password</password>
<db>dbname</db>
</qsdatabase>
*/
Log.Out(Logs::General, Logs::QS_Server, "Starting EQEmu QueryServ.");
if (!queryservconfig::LoadConfig()) {
Log.Out(Logs::General, Logs::QS_Server, "Loading server configuration failed.");
@@ -99,6 +91,10 @@ int main() {
Log.Out(Logs::General, Logs::QS_Server, "Could not set signal handler");
return 1;
}
if(signal(SIGBREAK, CatchSignal) == SIG_ERR) {
Log.Out(Logs::General, Logs::QS_Server, "Could not set signal handler");
return 1;
}
/* Initial Connection to Worldserver */
worldserver = new WorldServer;
@@ -108,16 +104,19 @@ int main() {
lfguildmanager.LoadDatabase();
while(RunLoops) {
Timer::SetCurrentTime();
if(LFGuildExpireTimer.Check())
lfguildmanager.ExpireEntries();
{
_eqpn("Main loop")
Timer::SetCurrentTime();
if(LFGuildExpireTimer.Check())
lfguildmanager.ExpireEntries();
if (InterserverTimer.Check()) {
if (worldserver->TryReconnect() && (!worldserver->Connected()))
worldserver->AsyncConnect();
if (InterserverTimer.Check()) {
if (worldserver->TryReconnect() && (!worldserver->Connected()))
worldserver->AsyncConnect();
}
worldserver->Process();
timeout_manager.CheckTimeouts();
}
worldserver->Process();
timeout_manager.CheckTimeouts();
Sleep(100);
}
Log.CloseFileLogs();
+1
View File
@@ -23,6 +23,7 @@
queryservconfig *queryservconfig::_chat_config = nullptr;
std::string queryservconfig::GetByName(const std::string &var_name) const {
_eqp
return(EQEmuConfig::GetByName(var_name));
}
+4
View File
@@ -44,21 +44,25 @@ extern LFGuildManager lfguildmanager;
WorldServer::WorldServer()
: WorldConnection(EmuTCPConnection::packetModeQueryServ, Config->SharedKey.c_str())
{
_eqp
pTryReconnect = true;
}
WorldServer::~WorldServer()
{
_eqp
}
void WorldServer::OnConnected()
{
_eqp
Log.Out(Logs::Detail, Logs::QS_Server, "Connected to World.");
WorldConnection::OnConnected();
}
void WorldServer::Process()
{
_eqp
WorldConnection::Process();
if (!Connected())
return;
+4 -1
View File
@@ -23,15 +23,17 @@ ADD_EXECUTABLE(shared_memory ${shared_memory_sources} ${shared_memory_headers})
INSTALL(TARGETS shared_memory RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
TARGET_LINK_LIBRARIES(shared_memory common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
TARGET_LINK_LIBRARIES(shared_memory common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
IF(MSVC)
SET_TARGET_PROPERTIES(shared_memory PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(shared_memory "Ws2_32.lib")
TARGET_LINK_LIBRARIES(shared_memory "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(shared_memory "WS2_32")
TARGET_LINK_LIBRARIES(shared_memory "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@@ -42,6 +44,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(shared_memory "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(shared_memory "pthread")
TARGET_LINK_LIBRARIES(shared_memory "uuid")
ADD_DEFINITIONS(-fPIC)
ENDIF(UNIX)
+1
View File
@@ -24,6 +24,7 @@
#include "../common/eqemu_exception.h"
void LoadBaseData(SharedDatabase *database) {
_eqp
EQEmu::IPCMutex mutex("base_data");
mutex.Lock();
int records = (database->GetMaxBaseDataLevel() + 1);
+1
View File
@@ -25,6 +25,7 @@
#include "../common/item_struct.h"
void LoadItems(SharedDatabase *database) {
_eqp
EQEmu::IPCMutex mutex("items");
mutex.Lock();
+1
View File
@@ -26,6 +26,7 @@
#include "../common/loottable.h"
void LoadLoot(SharedDatabase *database) {
_eqp
EQEmu::IPCMutex mutex("loot");
mutex.Lock();
+26 -1
View File
@@ -17,6 +17,7 @@
*/
#include <stdio.h>
#include <signal.h>
#include "../common/eqemu_logsys.h"
#include "../common/global_define.h"
@@ -35,11 +36,36 @@
EQEmuLogSys Log;
void CatchSignal(int sig_num)
{
_eqp_dump_file("shared_memory");
}
void OnExit() {
CatchSignal(SIGBREAK);
}
int main(int argc, char **argv) {
_eqp
RegisterExecutablePlatform(ExePlatformSharedMemory);
Log.LoadLogSettingsDefaults();
set_exception_handler();
if(signal(SIGINT, CatchSignal) == SIG_ERR) {
Log.Out(Logs::Detail, Logs::Error, "Could not set signal handler");
return 1;
}
if(signal(SIGTERM, CatchSignal) == SIG_ERR) {
Log.Out(Logs::Detail, Logs::Error, "Could not set signal handler");
return 1;
}
if(signal(SIGBREAK, CatchSignal) == SIG_ERR) {
Log.Out(Logs::Detail, Logs::Error, "Could not set signal handler");
return 1;
}
atexit(OnExit);
Log.Out(Logs::General, Logs::Status, "Shared Memory Loader Program");
if(!EQEmuConfig::LoadConfig()) {
Log.Out(Logs::General, Logs::Error, "Unable to load configuration file.");
@@ -175,6 +201,5 @@ int main(int argc, char **argv) {
}
Log.CloseFileLogs();
return 0;
}
+1 -3
View File
@@ -25,15 +25,13 @@
#include "../common/faction.h"
void LoadFactions(SharedDatabase *database) {
_eqp
EQEmu::IPCMutex mutex("faction");
mutex.Lock();
uint32 lists = 0;
uint32 max_list = 0;
database->GetFactionListInfo(lists, max_list);
if(lists == 0) {
EQ_EXCEPT("Shared Memory", "Unable to get any factions from the database.");
}
uint32 size = static_cast<uint32>(EQEmu::FixedMemoryHashSet<NPCFactionList>::estimated_size(lists, max_list));
EQEmu::MemoryMappedFile mmf("shared/faction", size);
+1
View File
@@ -26,6 +26,7 @@
#include "../common/features.h"
void LoadSkillCaps(SharedDatabase *database) {
_eqp
EQEmu::IPCMutex mutex("skill_caps");
mutex.Lock();
+1
View File
@@ -25,6 +25,7 @@
#include "../common/spdat.h"
void LoadSpells(SharedDatabase *database) {
_eqp
EQEmu::IPCMutex mutex("spells");
mutex.Lock();
int records = database->GetMaxSpellID() + 1;
+4 -1
View File
@@ -20,17 +20,19 @@ SET(tests_headers
ADD_EXECUTABLE(tests ${tests_sources} ${tests_headers})
TARGET_LINK_LIBRARIES(tests common cppunit)
TARGET_LINK_LIBRARIES(tests common ${PERF_LIBS} cppunit)
INSTALL(TARGETS tests RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
IF(MSVC)
SET_TARGET_PROPERTIES(tests PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(tests "Ws2_32.lib")
TARGET_LINK_LIBRARIES(tests "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(tests "WS2_32")
TARGET_LINK_LIBRARIES(tests "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@@ -41,6 +43,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(tests "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(tests "pthread")
TARGET_LINK_LIBRARIES(tests "uuid")
ADD_DEFINITIONS(-fPIC)
ENDIF(UNIX)
+4 -1
View File
@@ -23,15 +23,17 @@ INSTALL(TARGETS ucs RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
ADD_DEFINITIONS(-DUCS)
TARGET_LINK_LIBRARIES(ucs common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
TARGET_LINK_LIBRARIES(ucs common ${PERF_LIBS} debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY})
IF(MSVC)
SET_TARGET_PROPERTIES(ucs PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
TARGET_LINK_LIBRARIES(ucs "Ws2_32.lib")
TARGET_LINK_LIBRARIES(ucs "rpcrt4")
ENDIF(MSVC)
IF(MINGW)
TARGET_LINK_LIBRARIES(ucs "WS2_32")
TARGET_LINK_LIBRARIES(ucs "rpcrt4")
ENDIF(MINGW)
IF(UNIX)
@@ -42,6 +44,7 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(ucs "rt")
ENDIF(NOT DARWIN)
TARGET_LINK_LIBRARIES(ucs "pthread")
TARGET_LINK_LIBRARIES(ucs "uuid")
ADD_DEFINITIONS(-fPIC)
ENDIF(UNIX)
+52 -141
View File
@@ -29,17 +29,13 @@ extern uint32 ChatMessagesSent;
ChatChannel::ChatChannel(std::string inName, std::string inOwner, std::string inPassword, bool inPermanent, int inMinimumStatus) :
DeleteTimer(0) {
_eqp
Name = inName;
Owner = inOwner;
Password = inPassword;
Permanent = inPermanent;
MinimumStatus = inMinimumStatus;
Moderated = false;
Log.Out(Logs::Detail, Logs::UCS_Server, "New ChatChannel created: Name: [%s], Owner: [%s], Password: [%s], MinStatus: %i",
@@ -48,36 +44,30 @@ ChatChannel::ChatChannel(std::string inName, std::string inOwner, std::string in
}
ChatChannel::~ChatChannel() {
_eqp
LinkedListIterator<Client*> iterator(ClientsInChannel);
iterator.Reset();
while(iterator.MoreElements())
iterator.RemoveCurrent(false);
}
ChatChannel* ChatChannelList::CreateChannel(std::string Name, std::string Owner, std::string Password, bool Permanent, int MinimumStatus) {
_eqp
ChatChannel *NewChannel = new ChatChannel(CapitaliseName(Name), Owner, Password, Permanent, MinimumStatus);
ChatChannels.Insert(NewChannel);
return NewChannel;
}
ChatChannel* ChatChannelList::FindChannel(std::string Name) {
_eqp
std::string NormalisedName = CapitaliseName(Name);
LinkedListIterator<ChatChannel*> iterator(ChatChannels);
iterator.Reset();
while(iterator.MoreElements()) {
ChatChannel *CurrentChannel = iterator.GetData();
if(CurrentChannel && (CurrentChannel->Name == NormalisedName))
return iterator.GetData();
@@ -88,8 +78,10 @@ ChatChannel* ChatChannelList::FindChannel(std::string Name) {
}
void ChatChannelList::SendAllChannels(Client *c) {
_eqp
if(!c) return;
if(!c)
return;
if(!c->CanListAllChannels()) {
c->GeneralChannelMessage("You do not have permission to list all the channels.");
@@ -99,23 +91,16 @@ void ChatChannelList::SendAllChannels(Client *c) {
c->GeneralChannelMessage("All current channels:");
int ChannelsInLine = 0;
LinkedListIterator<ChatChannel*> iterator(ChatChannels);
iterator.Reset();
std::string Message;
char CountString[10];
while(iterator.MoreElements()) {
ChatChannel *CurrentChannel = iterator.GetData();
if(!CurrentChannel || (CurrentChannel->GetMinStatus() > c->GetAccountStatus())) {
iterator.Advance();
continue;
}
@@ -123,19 +108,13 @@ void ChatChannelList::SendAllChannels(Client *c) {
Message += ", ";
sprintf(CountString, "(%i)", CurrentChannel->MemberCount(c->GetAccountStatus()));
Message += CurrentChannel->GetName();
Message += CountString;
ChannelsInLine++;
if(ChannelsInLine == 6) {
c->GeneralChannelMessage(Message);
ChannelsInLine = 0;
Message.clear();
}
@@ -148,19 +127,14 @@ void ChatChannelList::SendAllChannels(Client *c) {
}
void ChatChannelList::RemoveChannel(ChatChannel *Channel) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "RemoveChannel(%s)", Channel->GetName().c_str());
LinkedListIterator<ChatChannel*> iterator(ChatChannels);
iterator.Reset();
while(iterator.MoreElements()) {
if(iterator.GetData() == Channel) {
iterator.RemoveCurrent();
return;
}
@@ -169,11 +143,10 @@ void ChatChannelList::RemoveChannel(ChatChannel *Channel) {
}
void ChatChannelList::RemoveAllChannels() {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "RemoveAllChannels");
LinkedListIterator<ChatChannel*> iterator(ChatChannels);
iterator.Reset();
while(iterator.MoreElements())
@@ -181,17 +154,13 @@ void ChatChannelList::RemoveAllChannels() {
}
int ChatChannel::MemberCount(int Status) {
_eqp
int Count = 0;
LinkedListIterator<Client*> iterator(ClientsInChannel);
iterator.Reset();
while(iterator.MoreElements()) {
Client *ChannelClient = iterator.GetData();
if(ChannelClient && (!ChannelClient->GetHideMe() || (ChannelClient->GetAccountStatus() < Status)))
Count++;
@@ -202,7 +171,7 @@ int ChatChannel::MemberCount(int Status) {
}
void ChatChannel::SetPassword(std::string inPassword) {
_eqp
Password = inPassword;
if(Permanent)
@@ -213,7 +182,7 @@ void ChatChannel::SetPassword(std::string inPassword) {
}
void ChatChannel::SetOwner(std::string inOwner) {
_eqp
Owner = inOwner;
if(Permanent)
@@ -221,68 +190,59 @@ void ChatChannel::SetOwner(std::string inOwner) {
}
void ChatChannel::AddClient(Client *c) {
_eqp
if(!c) return;
if(!c)
return;
DeleteTimer.Disable();
if(IsClientInChannel(c)) {
Log.Out(Logs::Detail, Logs::UCS_Server, "Client %s already in channel %s", c->GetName().c_str(), GetName().c_str());
return;
}
bool HideMe = c->GetHideMe();
int AccountStatus = c->GetAccountStatus();
Log.Out(Logs::Detail, Logs::UCS_Server, "Adding %s to channel %s", c->GetName().c_str(), Name.c_str());
LinkedListIterator<Client*> iterator(ClientsInChannel);
iterator.Reset();
while(iterator.MoreElements()) {
Client *CurrentClient = iterator.GetData();
if(CurrentClient && CurrentClient->IsAnnounceOn())
if(!HideMe || (CurrentClient->GetAccountStatus() > AccountStatus))
CurrentClient->AnnounceJoin(this, c);
iterator.Advance();
}
ClientsInChannel.Insert(c);
}
bool ChatChannel::RemoveClient(Client *c) {
_eqp
if(!c) return false;
if(!c)
return false;
Log.Out(Logs::Detail, Logs::UCS_Server, "RemoveClient %s from channel %s", c->GetName().c_str(), GetName().c_str());
bool HideMe = c->GetHideMe();
int AccountStatus = c->GetAccountStatus();
int PlayersInChannel = 0;
LinkedListIterator<Client*> iterator(ClientsInChannel);
iterator.Reset();
while(iterator.MoreElements()) {
Client *CurrentClient = iterator.GetData();
if(CurrentClient == c) {
iterator.RemoveCurrent(false);
}
else if(CurrentClient) {
PlayersInChannel++;
if(CurrentClient->IsAnnounceOn())
@@ -295,12 +255,10 @@ bool ChatChannel::RemoveClient(Client *c) {
}
if((PlayersInChannel == 0) && !Permanent) {
if((Password.length() == 0) || (RuleI(Channels, DeleteTimer) == 0))
return false;
Log.Out(Logs::Detail, Logs::UCS_Server, "Starting delete timer for empty password protected channel %s", Name.c_str());
DeleteTimer.Start(RuleI(Channels, DeleteTimer) * 60000);
}
@@ -308,46 +266,40 @@ bool ChatChannel::RemoveClient(Client *c) {
}
void ChatChannel::SendOPList(Client *c) {
_eqp
if(!c) return;
if(!c)
return;
c->GeneralChannelMessage("Channel " + Name + " op-list: (Owner=" + Owner + ")");
std::list<std::string>::iterator Iterator;
for(Iterator = Moderators.begin(); Iterator != Moderators.end(); ++Iterator)
c->GeneralChannelMessage((*Iterator));
}
void ChatChannel::SendChannelMembers(Client *c) {
_eqp
if(!c) return;
if(!c)
return;
char CountString[10];
sprintf(CountString, "(%i)", MemberCount(c->GetAccountStatus()));
std::string Message = "Channel " + GetName();
Message += CountString;
Message += " members:";
c->GeneralChannelMessage(Message);
int AccountStatus = c->GetAccountStatus();
Message.clear();
int MembersInLine = 0;
LinkedListIterator<Client*> iterator(ClientsInChannel);
iterator.Reset();
while(iterator.MoreElements()) {
Client *ChannelClient = iterator.GetData();
// Don't list hidden characters with status higher or equal than the character requesting the list.
@@ -361,15 +313,11 @@ void ChatChannel::SendChannelMembers(Client *c) {
Message += ", ";
Message += ChannelClient->GetName();
MembersInLine++;
if(MembersInLine == 6) {
c->GeneralChannelMessage(Message);
MembersInLine = 0;
Message.clear();
}
@@ -378,23 +326,22 @@ void ChatChannel::SendChannelMembers(Client *c) {
if(MembersInLine > 0)
c->GeneralChannelMessage(Message);
}
void ChatChannel::SendMessageToChannel(std::string Message, Client* Sender) {
_eqp
if(!Sender) return;
if(!Sender)
return;
ChatMessagesSent++;
LinkedListIterator<Client*> iterator(ClientsInChannel);
iterator.Reset();
while(iterator.MoreElements()) {
Client *ChannelClient = iterator.GetData();
if(ChannelClient)
{
Log.Out(Logs::Detail, Logs::UCS_Server, "Sending message to %s from %s",
@@ -407,19 +354,16 @@ void ChatChannel::SendMessageToChannel(std::string Message, Client* Sender) {
}
void ChatChannel::SetModerated(bool inModerated) {
_eqp
Moderated = inModerated;
LinkedListIterator<Client*> iterator(ClientsInChannel);
iterator.Reset();
while(iterator.MoreElements()) {
Client *ChannelClient = iterator.GetData();
if(ChannelClient) {
if(Moderated)
ChannelClient->GeneralChannelMessage("Channel " + Name + " is now moderated.");
else
@@ -428,18 +372,17 @@ void ChatChannel::SetModerated(bool inModerated) {
iterator.Advance();
}
}
bool ChatChannel::IsClientInChannel(Client *c) {
_eqp
if(!c) return false;
if(!c)
return false;
LinkedListIterator<Client*> iterator(ClientsInChannel);
iterator.Reset();
while(iterator.MoreElements()) {
if(iterator.GetData() == c)
return true;
@@ -450,18 +393,18 @@ bool ChatChannel::IsClientInChannel(Client *c) {
}
ChatChannel *ChatChannelList::AddClientToChannel(std::string ChannelName, Client *c) {
_eqp
if(!c) return nullptr;
if(!c)
return nullptr;
if((ChannelName.length() > 0) && (isdigit(ChannelName[0]))) {
c->GeneralChannelMessage("The channel name can not begin with a number.");
return nullptr;
}
std::string NormalisedName, Password;
std::string::size_type Colon = ChannelName.find_first_of(":");
if(Colon == std::string::npos)
@@ -473,9 +416,7 @@ ChatChannel *ChatChannelList::AddClientToChannel(std::string ChannelName, Client
}
if((NormalisedName.length() > 64) || (Password.length() > 64)) {
c->GeneralChannelMessage("The channel name or password cannot exceed 64 characters.");
return nullptr;
}
@@ -487,11 +428,8 @@ ChatChannel *ChatChannelList::AddClientToChannel(std::string ChannelName, Client
RequiredChannel = CreateChannel(NormalisedName, c->GetName(), Password, false, 0);
if(RequiredChannel->GetMinStatus() > c->GetAccountStatus()) {
std::string Message = "You do not have the required account status to join channel " + NormalisedName;
c->GeneralChannelMessage(Message);
return nullptr;
}
@@ -499,19 +437,14 @@ ChatChannel *ChatChannelList::AddClientToChannel(std::string ChannelName, Client
return nullptr;
if(RequiredChannel->IsInvitee(c->GetName())) {
RequiredChannel->AddClient(c);
RequiredChannel->RemoveInvitee(c->GetName());
return RequiredChannel;
}
if(RequiredChannel->CheckPassword(Password) || RequiredChannel->IsOwner(c->GetName()) || RequiredChannel->IsModerator(c->GetName()) ||
c->IsChannelAdmin()) {
RequiredChannel->AddClient(c);
return RequiredChannel;
}
@@ -521,8 +454,10 @@ ChatChannel *ChatChannelList::AddClientToChannel(std::string ChannelName, Client
}
ChatChannel *ChatChannelList::RemoveClientFromChannel(std::string inChannelName, Client *c) {
_eqp
if(!c) return nullptr;
if(!c)
return nullptr;
std::string ChannelName = inChannelName;
@@ -530,7 +465,6 @@ ChatChannel *ChatChannelList::RemoveClientFromChannel(std::string inChannelName,
ChannelName = c->ChannelSlotName(atoi(inChannelName.c_str()));
ChatChannel *RequiredChannel = FindChannel(ChannelName);
if(!RequiredChannel)
return nullptr;
@@ -544,62 +478,53 @@ ChatChannel *ChatChannelList::RemoveClientFromChannel(std::string inChannelName,
}
void ChatChannelList::Process() {
_eqp
LinkedListIterator<ChatChannel*> iterator(ChatChannels);
iterator.Reset();
while(iterator.MoreElements()) {
ChatChannel *CurrentChannel = iterator.GetData();
if(CurrentChannel && CurrentChannel->ReadyToDelete()) {
Log.Out(Logs::Detail, Logs::UCS_Server, "Empty temporary password protected channel %s being destroyed.",
CurrentChannel->GetName().c_str());
RemoveChannel(CurrentChannel);
}
iterator.Advance();
}
}
void ChatChannel::AddInvitee(std::string Invitee) {
_eqp
if(!IsInvitee(Invitee)) {
Invitees.push_back(Invitee);
Log.Out(Logs::Detail, Logs::UCS_Server, "Added %s as invitee to channel %s", Invitee.c_str(), Name.c_str());
}
}
void ChatChannel::RemoveInvitee(std::string Invitee) {
_eqp
std::list<std::string>::iterator Iterator;
for(Iterator = Invitees.begin(); Iterator != Invitees.end(); ++Iterator) {
if((*Iterator) == Invitee) {
Invitees.erase(Iterator);
Log.Out(Logs::Detail, Logs::UCS_Server, "Removed %s as invitee to channel %s", Invitee.c_str(), Name.c_str());
return;
}
}
}
bool ChatChannel::IsInvitee(std::string Invitee) {
_eqp
std::list<std::string>::iterator Iterator;
for(Iterator = Invitees.begin(); Iterator != Invitees.end(); ++Iterator) {
if((*Iterator) == Invitee)
return true;
}
@@ -608,80 +533,66 @@ bool ChatChannel::IsInvitee(std::string Invitee) {
}
void ChatChannel::AddModerator(std::string Moderator) {
_eqp
if(!IsModerator(Moderator)) {
Moderators.push_back(Moderator);
Log.Out(Logs::Detail, Logs::UCS_Server, "Added %s as moderator to channel %s", Moderator.c_str(), Name.c_str());
}
}
void ChatChannel::RemoveModerator(std::string Moderator) {
_eqp
std::list<std::string>::iterator Iterator;
for(Iterator = Moderators.begin(); Iterator != Moderators.end(); ++Iterator) {
if((*Iterator) == Moderator) {
Moderators.erase(Iterator);
Log.Out(Logs::Detail, Logs::UCS_Server, "Removed %s as moderator to channel %s", Moderator.c_str(), Name.c_str());
return;
}
}
}
bool ChatChannel::IsModerator(std::string Moderator) {
_eqp
std::list<std::string>::iterator Iterator;
for(Iterator = Moderators.begin(); Iterator != Moderators.end(); ++Iterator) {
if((*Iterator) == Moderator)
return true;
}
return false;
}
void ChatChannel::AddVoice(std::string inVoiced) {
_eqp
if(!HasVoice(inVoiced)) {
Voiced.push_back(inVoiced);
Log.Out(Logs::Detail, Logs::UCS_Server, "Added %s as voiced to channel %s", inVoiced.c_str(), Name.c_str());
}
}
void ChatChannel::RemoveVoice(std::string inVoiced) {
_eqp
std::list<std::string>::iterator Iterator;
for(Iterator = Voiced.begin(); Iterator != Voiced.end(); ++Iterator) {
if((*Iterator) == inVoiced) {
Voiced.erase(Iterator);
Log.Out(Logs::Detail, Logs::UCS_Server, "Removed %s as voiced to channel %s", inVoiced.c_str(), Name.c_str());
return;
}
}
}
bool ChatChannel::HasVoice(std::string inVoiced) {
_eqp
std::list<std::string>::iterator Iterator;
for(Iterator = Voiced.begin(); Iterator != Voiced.end(); ++Iterator) {
if((*Iterator) == inVoiced)
return true;
}
@@ -690,9 +601,9 @@ bool ChatChannel::HasVoice(std::string inVoiced) {
}
std::string CapitaliseName(std::string inString) {
_eqp
std::string NormalisedName = inString;
for(unsigned int i = 0; i < NormalisedName.length(); i++) {
if(i == 0)
+74 -10
View File
@@ -43,8 +43,10 @@ extern uint32 ChatMessagesSent;
extern uint32 MailMessagesSent;
int LookupCommand(const char *ChatCommand) {
_eqp
if(!ChatCommand) return -1;
if(!ChatCommand)
return -1;
for(int i = 0; i < CommandEndOfList; i++) {
@@ -56,6 +58,7 @@ int LookupCommand(const char *ChatCommand) {
}
void Client::SendUptime() {
_eqp
uint32 ms = Timer::GetCurrentTime();
uint32 d = ms / 86400000;
@@ -77,6 +80,7 @@ void Client::SendUptime() {
}
std::vector<std::string> ParseRecipients(std::string RecipientString) {
_eqp
// This method parses the Recipient List in the mailto command, which can look like this example:
//
@@ -235,6 +239,7 @@ std::vector<std::string> ParseRecipients(std::string RecipientString) {
}
static void ProcessMailTo(Client *c, std::string MailMessage) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "MAILTO: From %s, %s", c->MailBoxName().c_str(), MailMessage.c_str());
@@ -351,9 +356,11 @@ static void ProcessMailTo(Client *c, std::string MailMessage) {
}
static void ProcessMailTo(Client *c, std::string from, std::string subject, std::string message) {
_eqp
}
static void ProcessSetMessageStatus(std::string SetMessageCommand) {
_eqp
int MessageNumber;
@@ -397,6 +404,7 @@ static void ProcessSetMessageStatus(std::string SetMessageCommand) {
}
static void ProcessCommandBuddy(Client *c, std::string Buddy) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "Received buddy command with parameters %s", Buddy.c_str());
c->GeneralChannelMessage("Buddy list modified");
@@ -426,6 +434,7 @@ static void ProcessCommandBuddy(Client *c, std::string Buddy) {
}
static void ProcessCommandIgnore(Client *c, std::string Ignoree) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "Received ignore command with parameters %s", Ignoree.c_str());
c->GeneralChannelMessage("Ignore list modified");
@@ -468,7 +477,8 @@ static void ProcessCommandIgnore(Client *c, std::string Ignoree) {
}
Clientlist::Clientlist(int ChatPort) {
_eqp
chatsf = new EQStreamFactory(ChatStream, ChatPort, 45000);
ChatOpMgr = new RegularOpcodeManager;
@@ -486,6 +496,7 @@ Clientlist::Clientlist(int ChatPort) {
}
Client::Client(std::shared_ptr<EQStream> eqs) {
_eqp
ClientStream = eqs;
@@ -518,6 +529,7 @@ Client::Client(std::shared_ptr<EQStream> eqs) {
}
Client::~Client() {
_eqp
CloseConnection();
@@ -537,6 +549,7 @@ Client::~Client() {
}
void Client::CloseConnection() {
_eqp
ClientStream->RemoveData();
@@ -546,8 +559,10 @@ void Client::CloseConnection() {
}
void Clientlist::CheckForStaleConnections(Client *c) {
_eqp
if(!c) return;
if(!c)
return;
std::list<Client*>::iterator Iterator;
@@ -573,6 +588,7 @@ void Clientlist::CheckForStaleConnections(Client *c) {
}
void Clientlist::Process() {
_eqp
std::shared_ptr<EQStream> eqs;
@@ -731,6 +747,7 @@ void Clientlist::Process() {
void Clientlist::ProcessOPMailCommand(Client *c, std::string CommandString)
{
_eqp
if(CommandString.length() == 0)
return;
@@ -885,7 +902,7 @@ void Clientlist::ProcessOPMailCommand(Client *c, std::string CommandString)
}
void Clientlist::CloseAllConnections() {
_eqp
std::list<Client*>::iterator Iterator;
@@ -898,8 +915,10 @@ void Clientlist::CloseAllConnections() {
}
void Client::AddCharacter(int CharID, const char *CharacterName, int Level) {
_eqp
if(!CharacterName) return;
if(!CharacterName)
return;
Log.Out(Logs::Detail, Logs::UCS_Server, "Adding character %s with ID %i for %s", CharacterName, CharID, GetName().c_str());
CharacterEntry NewCharacter;
NewCharacter.CharID = CharID;
@@ -910,6 +929,7 @@ void Client::AddCharacter(int CharID, const char *CharacterName, int Level) {
}
void Client::SendMailBoxes() {
_eqp
int Count = Characters.size();
@@ -945,6 +965,7 @@ void Client::SendMailBoxes() {
}
Client *Clientlist::FindCharacter(std::string CharacterName) {
_eqp
std::list<Client*>::iterator Iterator;
@@ -959,8 +980,10 @@ Client *Clientlist::FindCharacter(std::string CharacterName) {
}
void Client::AddToChannelList(ChatChannel *JoinedChannel) {
_eqp
if(!JoinedChannel) return;
if(!JoinedChannel)
return;
for(int i = 0; i < MAX_JOINED_CHANNELS; i++)
if(JoinedChannels[i] == nullptr) {
@@ -971,6 +994,7 @@ void Client::AddToChannelList(ChatChannel *JoinedChannel) {
}
void Client::RemoveFromChannelList(ChatChannel *JoinedChannel) {
_eqp
for(int i = 0; i < MAX_JOINED_CHANNELS; i++)
if(JoinedChannels[i] == JoinedChannel) {
@@ -987,6 +1011,7 @@ void Client::RemoveFromChannelList(ChatChannel *JoinedChannel) {
}
int Client::ChannelCount() {
_eqp
int NumberOfChannels = 0;
@@ -999,6 +1024,7 @@ int Client::ChannelCount() {
}
void Client::JoinChannels(std::string ChannelNameList) {
_eqp
for (auto &elem : ChannelNameList) {
if (elem == '%') {
@@ -1104,6 +1130,7 @@ void Client::JoinChannels(std::string ChannelNameList) {
}
void Client::LeaveChannels(std::string ChannelNameList) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "Client: %s leaving channels %s", GetName().c_str(), ChannelNameList.c_str());
@@ -1189,6 +1216,7 @@ void Client::LeaveChannels(std::string ChannelNameList) {
}
void Client::LeaveAllChannels(bool SendUpdatedChannelList) {
_eqp
for (auto &elem : JoinedChannels) {
@@ -1206,6 +1234,7 @@ void Client::LeaveAllChannels(bool SendUpdatedChannelList) {
void Client::ProcessChannelList(std::string Input) {
_eqp
if(Input.length() == 0) {
@@ -1230,6 +1259,7 @@ void Client::ProcessChannelList(std::string Input) {
void Client::SendChannelList() {
_eqp
std::string ChannelMessage;
@@ -1273,6 +1303,7 @@ void Client::SendChannelList() {
void Client::SendChannelMessage(std::string Message)
{
_eqp
std::string::size_type MessageStart = Message.find_first_of(" ");
@@ -1372,6 +1403,7 @@ void Client::SendChannelMessage(std::string Message)
}
void Client::SendChannelMessageByNumber(std::string Message) {
_eqp
std::string::size_type MessageStart = Message.find_first_of(" ");
@@ -1484,8 +1516,10 @@ void Client::SendChannelMessageByNumber(std::string Message) {
}
void Client::SendChannelMessage(std::string ChannelName, std::string Message, Client *Sender) {
_eqp
if(!Sender) return;
if(!Sender)
return;
std::string FQSenderName = WorldShortName + "." + Sender->GetName();
@@ -1512,6 +1546,8 @@ void Client::SendChannelMessage(std::string ChannelName, std::string Message, Cl
void Client::ToggleAnnounce(std::string State)
{
_eqp
if(State == "")
Announce = !Announce;
else if(State == "on")
@@ -1530,8 +1566,10 @@ void Client::ToggleAnnounce(std::string State)
}
void Client::AnnounceJoin(ChatChannel *Channel, Client *c) {
_eqp
if(!Channel || !c) return;
if(!Channel || !c)
return;
int PacketLength = Channel->GetName().length() + c->GetName().length() + 2;
@@ -1549,8 +1587,10 @@ void Client::AnnounceJoin(ChatChannel *Channel, Client *c) {
}
void Client::AnnounceLeave(ChatChannel *Channel, Client *c) {
_eqp
if(!Channel || !c) return;
if(!Channel || !c)
return;
int PacketLength = Channel->GetName().length() + c->GetName().length() + 2;
@@ -1568,8 +1608,10 @@ void Client::AnnounceLeave(ChatChannel *Channel, Client *c) {
}
void Client::GeneralChannelMessage(const char *Characters) {
_eqp
if(!Characters) return;
if(!Characters)
return;
std::string Message = Characters;
@@ -1578,6 +1620,7 @@ void Client::GeneralChannelMessage(const char *Characters) {
}
void Client::GeneralChannelMessage(std::string Message) {
_eqp
auto outapp = new EQApplicationPacket(OP_ChannelMessage, Message.length() + 3);
char *PacketBuffer = (char *)outapp->pBuffer;
@@ -1591,6 +1634,7 @@ void Client::GeneralChannelMessage(std::string Message) {
}
void Client::SetChannelPassword(std::string ChannelPassword) {
_eqp
std::string::size_type PasswordStart = ChannelPassword.find_first_not_of(" ");
@@ -1655,6 +1699,7 @@ void Client::SetChannelPassword(std::string ChannelPassword) {
}
void Client::SetChannelOwner(std::string CommandString) {
_eqp
std::string::size_type PlayerStart = CommandString.find_first_not_of(" ");
@@ -1718,6 +1763,7 @@ void Client::SetChannelOwner(std::string CommandString) {
}
void Client::OPList(std::string CommandString) {
_eqp
std::string::size_type ChannelStart = CommandString.find_first_not_of(" ");
@@ -1743,6 +1789,7 @@ void Client::OPList(std::string CommandString) {
}
void Client::ChannelInvite(std::string CommandString) {
_eqp
std::string::size_type PlayerStart = CommandString.find_first_not_of(" ");
@@ -1829,6 +1876,7 @@ void Client::ChannelInvite(std::string CommandString) {
}
void Client::ChannelModerate(std::string CommandString) {
_eqp
std::string::size_type ChannelStart = CommandString.find_first_not_of(" ");
@@ -1871,6 +1919,7 @@ void Client::ChannelModerate(std::string CommandString) {
}
void Client::ChannelGrantModerator(std::string CommandString) {
_eqp
std::string::size_type PlayerStart = CommandString.find_first_not_of(" ");
@@ -1954,6 +2003,7 @@ void Client::ChannelGrantModerator(std::string CommandString) {
}
void Client::ChannelGrantVoice(std::string CommandString) {
_eqp
std::string::size_type PlayerStart = CommandString.find_first_not_of(" ");
@@ -2041,6 +2091,7 @@ void Client::ChannelGrantVoice(std::string CommandString) {
}
void Client::ChannelKick(std::string CommandString) {
_eqp
std::string::size_type PlayerStart = CommandString.find_first_not_of(" ");
@@ -2131,6 +2182,7 @@ void Client::ChannelKick(std::string CommandString) {
}
void Client::ToggleInvites() {
_eqp
AllowInvites = !AllowInvites;
@@ -2142,6 +2194,7 @@ void Client::ToggleInvites() {
}
std::string Client::ChannelSlotName(int SlotNumber) {
_eqp
if((SlotNumber < 1 ) || (SlotNumber > MAX_JOINED_CHANNELS))
return "";
@@ -2154,6 +2207,7 @@ std::string Client::ChannelSlotName(int SlotNumber) {
}
void Client::SendHelp() {
_eqp
GeneralChannelMessage("Chat Channel Commands:");
@@ -2164,6 +2218,8 @@ void Client::SendHelp() {
void Client::AccountUpdate()
{
_eqp
if(AccountGrabUpdateTimer)
{
if(AccountGrabUpdateTimer->Check(false))
@@ -2175,6 +2231,7 @@ void Client::AccountUpdate()
}
void Client::SetConnectionType(char c) {
_eqp
switch(c)
{
@@ -2212,6 +2269,7 @@ void Client::SetConnectionType(char c) {
}
Client *Clientlist::IsCharacterOnline(std::string CharacterName) {
_eqp
// This method is used to determine if the character we are a sending an email to is connected to the mailserver,
// so we can send them a new email notification.
@@ -2240,6 +2298,7 @@ Client *Clientlist::IsCharacterOnline(std::string CharacterName) {
}
int Client::GetMailBoxNumber(std::string CharacterName) {
_eqp
for(unsigned int i = 0; i < Characters.size(); i++)
if(Characters[i].Name == CharacterName)
@@ -2249,6 +2308,7 @@ int Client::GetMailBoxNumber(std::string CharacterName) {
}
void Client::SendNotification(int MailBoxNumber, std::string Subject, std::string From, int MessageID) {
_eqp
char TimeStamp[100];
@@ -2282,6 +2342,7 @@ void Client::SendNotification(int MailBoxNumber, std::string Subject, std::strin
}
void Client::ChangeMailBox(int NewMailBox) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "%s Change to mailbox %i", MailBoxName().c_str(), NewMailBox);
@@ -2302,6 +2363,7 @@ void Client::ChangeMailBox(int NewMailBox) {
}
void Client::SendFriends() {
_eqp
std::vector<std::string> Friends, Ignorees;
@@ -2355,6 +2417,7 @@ void Client::SendFriends() {
}
std::string Client::MailBoxName() {
_eqp
if((Characters.size() == 0) || (CurrentMailBox > (Characters.size() - 1)))
{
@@ -2372,6 +2435,7 @@ std::string Client::MailBoxName() {
}
int Client::GetCharID() {
_eqp
if(Characters.size() == 0)
return 0;
+35 -4
View File
@@ -55,6 +55,7 @@ extern uint32 MailMessagesSent;
Database::Database ()
{
_eqp
DBInitVars();
}
@@ -64,12 +65,14 @@ Establish a connection to a mysql database with the supplied parameters
Database::Database(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
{
_eqp
DBInitVars();
Connect(host, user, passwd, database, port);
}
bool Database::Connect(const char* host, const char* user, const char* passwd, const char* database, uint32 port)
{
_eqp
uint32 errnum= 0;
char errbuf[MYSQL_ERRMSG_SIZE];
if (!Open(host, user, passwd, database, port, &errnum, errbuf))
@@ -87,12 +90,11 @@ bool Database::Connect(const char* host, const char* user, const char* passwd, c
}
void Database::DBInitVars() {
_eqp
}
void Database::HandleMysqlError(uint32 errnum) {
_eqp
}
/*
@@ -101,9 +103,11 @@ Close the connection to the database
*/
Database::~Database()
{
_eqp
}
void Database::GetAccountStatus(Client *client) {
_eqp
std::string query = StringFormat("SELECT `status`, `hideme`, `karma`, `revoked` "
"FROM `account` WHERE `id` = '%i' LIMIT 1",
@@ -134,6 +138,7 @@ void Database::GetAccountStatus(Client *client) {
}
int Database::FindAccount(const char *characterName, Client *client) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "FindAccount for character %s", characterName);
@@ -174,6 +179,7 @@ int Database::FindAccount(const char *characterName, Client *client) {
}
bool Database::VerifyMailKey(std::string characterName, int IPAddress, std::string MailKey) {
_eqp
std::string query = StringFormat("SELECT `mailkey` FROM `character_data` WHERE `name`='%s' LIMIT 1",
characterName.c_str());
@@ -201,6 +207,7 @@ bool Database::VerifyMailKey(std::string characterName, int IPAddress, std::stri
}
int Database::FindCharacter(const char *characterName) {
_eqp
char *safeCharName = RemoveApostrophes(characterName);
std::string query = StringFormat("SELECT `id` FROM `character_data` WHERE `name`='%s' LIMIT 1", safeCharName);
@@ -224,6 +231,7 @@ int Database::FindCharacter(const char *characterName) {
}
bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_len) {
_eqp
std::string query = StringFormat("SELECT `value` FROM `variables` WHERE `varname` = '%s'", varname);
auto results = QueryDatabase(query);
@@ -242,6 +250,7 @@ bool Database::GetVariable(const char* varname, char* varvalue, uint16 varvalue_
}
bool Database::LoadChatChannels() {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "Loading chat channels from the database.");
@@ -263,6 +272,7 @@ bool Database::LoadChatChannels() {
}
void Database::SetChannelPassword(std::string channelName, std::string password) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "Database::SetChannelPassword(%s, %s)", channelName.c_str(), password.c_str());
@@ -272,6 +282,7 @@ void Database::SetChannelPassword(std::string channelName, std::string password)
}
void Database::SetChannelOwner(std::string channelName, std::string owner) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "Database::SetChannelOwner(%s, %s)", channelName.c_str(), owner.c_str());
@@ -281,6 +292,7 @@ void Database::SetChannelOwner(std::string channelName, std::string owner) {
}
void Database::SendHeaders(Client *client) {
_eqp
int unknownField2 = 25015275;
int unknownField3 = 1;
@@ -368,6 +380,7 @@ void Database::SendHeaders(Client *client) {
}
void Database::SendBody(Client *client, int messageNumber) {
_eqp
int characterID = FindCharacter(client->MailBoxName().c_str());
@@ -415,6 +428,7 @@ void Database::SendBody(Client *client, int messageNumber) {
}
bool Database::SendMail(std::string recipient, std::string from, std::string subject, std::string body, std::string recipientsString) {
_eqp
int characterID;
std::string characterName;
@@ -474,6 +488,7 @@ bool Database::SendMail(std::string recipient, std::string from, std::string sub
}
void Database::SetMessageStatus(int messageNumber, int status) {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "SetMessageStatus %i %i", messageNumber, status);
@@ -488,6 +503,7 @@ void Database::SetMessageStatus(int messageNumber, int status) {
}
void Database::ExpireMail() {
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "Expiring mail...");
@@ -530,6 +546,7 @@ void Database::ExpireMail() {
}
void Database::AddFriendOrIgnore(int charID, int type, std::string name) {
_eqp
std::string query = StringFormat("INSERT INTO `friends` (`charid`, `type`, `name`) "
"VALUES('%i', %i, '%s')",
@@ -541,6 +558,7 @@ void Database::AddFriendOrIgnore(int charID, int type, std::string name) {
}
void Database::RemoveFriendOrIgnore(int charID, int type, std::string name) {
_eqp
std::string query = StringFormat("DELETE FROM `friends` WHERE `charid` = %i "
"AND `type` = %i AND `name` = '%s'",
@@ -554,6 +572,7 @@ void Database::RemoveFriendOrIgnore(int charID, int type, std::string name) {
}
void Database::GetFriendsAndIgnore(int charID, std::vector<std::string> &friends, std::vector<std::string> &ignorees) {
_eqp
std::string query = StringFormat("select `type`, `name` FROM `friends` WHERE `charid`=%i", charID);
auto results = QueryDatabase(query);
@@ -578,7 +597,9 @@ void Database::GetFriendsAndIgnore(int charID, std::vector<std::string> &friends
}
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings){
void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings) {
_eqp
std::string query =
"SELECT "
"log_category_id, "
@@ -600,6 +621,16 @@ void Database::LoadLogSettings(EQEmuLogSys::LogSettings* log_settings){
log_settings[log_category].log_to_file = atoi(row[3]);
log_settings[log_category].log_to_gmsay = atoi(row[4]);
/* Determine if any output method is enabled for the category
and set it to 1 so it can used to check if category is enabled */
const bool log_to_console = log_settings[log_category].log_to_console > 0;
const bool log_to_file = log_settings[log_category].log_to_file > 0;
const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0;
const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay;
if (is_category_enabled)
log_settings[log_category].is_category_enabled = 1;
/*
This determines whether or not the process needs to actually file log anything.
If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open
+20 -12
View File
@@ -19,13 +19,13 @@
#include "../common/eqemu_logsys.h"
#include "../common/global_define.h"
#include "clientlist.h"
#include "../common/opcodemgr.h"
#include "../common/eq_stream_factory.h"
#include "../common/rulesys.h"
#include "../common/servertalk.h"
#include "../common/platform.h"
#include "../common/crash.h"
#include "clientlist.h"
#include "database.h"
#include "ucsconfig.h"
#include "chatchannel.h"
@@ -55,6 +55,8 @@ void CatchSignal(int sig_num) {
if(worldserver)
worldserver->Disconnect();
_eqp_dump_file("ucs");
}
std::string GetMailPrefix() {
@@ -138,28 +140,33 @@ int main() {
Log.Out(Logs::General, Logs::UCS_Server, "Could not set signal handler");
return 1;
}
if(signal(SIGBREAK, CatchSignal) == SIG_ERR) {
Log.Out(Logs::General, Logs::UCS_Server, "Could not set signal handler");
return 1;
}
worldserver = new WorldServer;
worldserver->Connect();
while(RunLoops) {
{
_eqpn("Main loop");
Timer::SetCurrentTime();
Timer::SetCurrentTime();
CL->Process();
CL->Process();
if(ChannelListProcessTimer.Check())
ChannelList->Process();
if(ChannelListProcessTimer.Check())
ChannelList->Process();
if (InterserverTimer.Check()) {
if (worldserver->TryReconnect() && (!worldserver->Connected()))
worldserver->AsyncConnect();
}
worldserver->Process();
if (InterserverTimer.Check()) {
if (worldserver->TryReconnect() && (!worldserver->Connected()))
worldserver->AsyncConnect();
timeout_manager.CheckTimeouts();
}
worldserver->Process();
timeout_manager.CheckTimeouts();
Sleep(100);
}
@@ -172,6 +179,7 @@ int main() {
}
void UpdateWindowTitle(char* iNewTitle) {
_eqp
#ifdef _WINDOWS
char tmp[500];
if (iNewTitle) {
+1
View File
@@ -23,6 +23,7 @@
ucsconfig *ucsconfig::_chat_config = nullptr;
std::string ucsconfig::GetByName(const std::string &var_name) const {
_eqp
return(EQEmuConfig::GetByName(var_name));
}
+4
View File
@@ -43,21 +43,25 @@ void ProcessMailTo(Client *c, std::string from, std::string subject, std::string
WorldServer::WorldServer()
: WorldConnection(EmuTCPConnection::packetModeUCS, Config->SharedKey.c_str())
{
_eqp
pTryReconnect = true;
}
WorldServer::~WorldServer()
{
_eqp
}
void WorldServer::OnConnected()
{
_eqp
Log.Out(Logs::Detail, Logs::UCS_Server, "Connected to World.");
WorldConnection::OnConnected();
}
void WorldServer::Process()
{
_eqp
WorldConnection::Process();
if (!Connected())
+1 -1
View File
@@ -129,7 +129,7 @@ OP_GuildInviteAccept=0x78a5
OP_GuildDemote=0x3100
OP_GuildPromote=0x2945
OP_GuildPublicNote=0x3c2c
OP_GuildManageBanker=0x096d # Was 0x0737
OP_GuildManageBanker=0x389c # Was 0x096d
OP_GuildBank=0x2ab0 # Was 0x10c3
OP_SetGuildRank=0x3599
OP_GuildUpdateURLAndChannel=0x7851
+16 -15
View File
@@ -128,7 +128,7 @@ OP_GuildInviteAccept=0x7053
OP_GuildDemote=0x2d4e
OP_GuildPromote=0x6a98
OP_GuildPublicNote=0x5053
OP_GuildManageBanker=0x748f
OP_GuildManageBanker=0x3f35
OP_GuildBank=0x5134
OP_SetGuildRank=0x0b9c
OP_GuildUpdateURLAndChannel=0x2958
@@ -353,21 +353,22 @@ OP_Marquee=0x502e
OP_ItemRecastDelay=0x15a9
#OP_OpenInventory=0x0000 # Likely does not exist in RoF -U
OP_DzQuit=0x205f
OP_DzListTimers=0x0398
OP_DzAddPlayer=0x59ca
OP_DzRemovePlayer=0x4701
OP_DzSwapPlayer=0x1abc
OP_DzMakeLeader=0x405b
OP_DzPlayerList=0x543d
OP_DzJoinExpeditionConfirm=0x14c6
OP_DzJoinExpeditionReply=0x7f4b
OP_DzExpeditionInfo=0x4f7e
OP_DzExpeditionList=0x9119
OP_DzMemberStatus=0xb2e3
OP_DzLeaderStatus=0x32f0
# Expeditions
OP_DzAddPlayer=0x4701
OP_DzRemovePlayer=0x1abc
OP_DzSwapPlayer=0x405b
OP_DzMakeLeader=0x543d
OP_DzPlayerList=0x14c6
OP_DzJoinExpeditionConfirm=0x7f4b
OP_DzJoinExpeditionReply=0x1950
OP_DzListTimers=0x7b68
OP_DzExpeditionInfo=0x9119
OP_DzExpeditionList=0x205f
OP_DzQuit=0xb2e3
OP_DzMemberStatus=0x32f0
OP_DzLeaderStatus=0x3de9
OP_DzMemberList=0x5ae4
OP_DzExpeditionEndsWarning=0x383c
OP_DzMemberList=0x3de9
OP_DzCompass=0x3e0e
OP_DzChooseZone=0x0b7d

Some files were not shown because too many files have changed in this diff Show More