Compare commits

..

3 Commits

Author SHA1 Message Date
c3f4cc0e42 clean up mutex 2025-09-06 21:43:05 -05:00
a2183bf2d0 clean up debug 2025-09-06 21:20:01 -05:00
101c1217b2 Clean up common_defines 2025-09-06 21:13:13 -05:00
42 changed files with 1136 additions and 1605 deletions

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
@ -7,7 +7,7 @@
#ifndef LWORLD_H
#define LWORLD_H
#include "../common/Mutex.h"
#include "../common/mutex.h"
#define ERROR_BADPASSWORD "Bad password"
#define INVALID_ACCOUNT "Invalid Server Account."
@ -63,7 +63,7 @@ public:
~LWorld();
static bool CheckServerName(const char* name);
bool Process();
void SendPacket(ServerPacket* pack);
void Message(const char* to, const char* message, ...);
@ -118,7 +118,7 @@ public:
void SendDeleteCharacter( int32 char_id, int32 account_id );
bool IsDevelServer(){ return devel_server; }
inline int8 GetMaxWorldLevel() { return world_max_level; }
bool IsInit;
@ -166,7 +166,7 @@ public:
LWorldList();
~LWorldList();
LWorld* FindByID(int32 WorldID);
LWorld* FindByID(int32 WorldID);
LWorld* FindByIP(int32 ip);
LWorld* FindByAddress(char* address);
LWorld* FindByLink(TCPConnection* in_link, int32 in_id);
@ -197,7 +197,7 @@ public:
void InitWorlds();
void Shutdown();
bool WriteXML();
int32 GetCount(ConType type);
void PopulateWorldList(http::response<http::string_body>& res);
@ -229,7 +229,7 @@ private:
int32 NextID;
LinkedList<LWorld*> list;
map<int32,LWorld*> worldmap;
TCPServer* tcplistener;

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
@ -21,7 +21,7 @@
#include "../common/types.h"
#include "../common/MiscFunctions.h"
#include "../common/servertalk.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "PacketHeaders.h"
#include "LoginAccount.h"
#include "LWorld.h"
@ -93,4 +93,4 @@ public:
DatabaseNew dbLogin;
};
#endif
#endif

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
@ -35,7 +35,7 @@
#include "../common/ConfigReader.h"
#include "../common/Log.h"
#include "../common/JsonParser.h"
#include "../common/Common_Defines.h"
#include "../common/defines.h"
#ifdef WIN32
#define snprintf _snprintf
@ -74,7 +74,7 @@ int main(int argc, char** argv){
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
LogWrite(LOGIN__DEBUG, 0, "Login", "[DEBUG] Entering main() method - net.cpp:72");
if (signal(SIGINT, CatchSignal) == SIG_ERR) {
cerr << "Could not set signal handler" << endl;
}
@ -91,7 +91,7 @@ int main(int argc, char** argv){
return 1;
net.InitWebServer(net.GetWebLoginAddress(), net.GetWebLoginPort(), net.GetWebCertFile(), net.GetWebKeyFile(), net.GetWebKeyPassword(), net.GetWebHardcodeUser(), net.GetWebHardcodePassword());
const char* structList[] = { "CommonStructs.xml", "LoginStructs.xml" };
for (int s = 0; s < sizeof(structList) / sizeof(const char*); s++)
@ -105,11 +105,11 @@ int main(int argc, char** argv){
return 1;
}
}
LogWrite(INIT__INFO, 0, "Init", "Initialize World List..");
world_list.Init();
if(eqsf.listen_ip_address)
LogWrite(INIT__INFO, 0, "Init", "Login server listening on %s port %i", eqsf.listen_ip_address, net.GetPort());
else
@ -125,7 +125,7 @@ int main(int argc, char** argv){
}
net.login_running = true;
net.login_uptime = getCurrentTimestamp();
net.UpdateWindowTitle();
EQStream* eqs;
Timer* TimeoutTimer = new Timer(5000);
@ -204,7 +204,7 @@ void NetConnection::HitKey(int keyhit)
}
}
#endif
void CatchSignal(int sig_num) {
cout << "Got signal " << sig_num << endl;
RunLoops = false;
@ -219,12 +219,12 @@ bool NetConnection::ReadLoginConfig() {
}
std::string serverport = parser.getValue("loginconfig.serverport");
std::string serverip = parser.getValue("loginconfig.serverip");
if (!parser.convertStringToUnsignedShort(serverport, port)) {
LogWrite(INIT__ERROR, 0, "Init", "Failed to translate loginconfig.serverport..");
return false;
}
if(serverip.size() > 0) {
eqsf.listen_ip_address = new char[serverip.size() + 1];
strcpy(eqsf.listen_ip_address, serverip.c_str());
@ -233,31 +233,31 @@ bool NetConnection::ReadLoginConfig() {
safe_delete(eqsf.listen_ip_address);
eqsf.listen_ip_address = nullptr;
}
std::string acctcreate_str = parser.getValue("loginconfig.accountcreation");
int16 allow_acct = 0;
parser.convertStringToUnsignedShort(acctcreate_str, allow_acct);
allowAccountCreation = allow_acct > 0 ? true : false;
std::string expflag_str = parser.getValue("loginconfig.expansionflag");
parser.convertStringToUnsignedInt(expflag_str, expansionFlag);
std::string citiesflag_str = parser.getValue("loginconfig.citiesflag");
parser.convertStringToUnsignedChar(citiesflag_str, citiesFlag);
std::string defaultsublevel_str = parser.getValue("loginconfig.defaultsubscriptionlevel");
parser.convertStringToUnsignedInt(defaultsublevel_str, defaultSubscriptionLevel);
std::string enableraces_str = parser.getValue("loginconfig.enabledraces");
parser.convertStringToUnsignedInt(enableraces_str, enabledRaces);
web_loginaddress = parser.getValue("loginconfig.webloginaddress");
web_certfile = parser.getValue("loginconfig.webcertfile");
web_keyfile = parser.getValue("loginconfig.webkeyfile");
web_keypassword = parser.getValue("loginconfig.webkeypassword");
web_hardcodeuser = parser.getValue("loginconfig.webhardcodeuser");
web_hardcodepassword = parser.getValue("loginconfig.webhardcodepassword");
std::string webloginport_str = parser.getValue("loginconfig.webloginport");
parser.convertStringToUnsignedShort(webloginport_str, web_loginport);
@ -355,7 +355,7 @@ void NetConnection::InitWebServer(std::string web_ipaddr, int16 web_port, std::s
if(web_ipaddr.size() > 0 && web_port > 0) {
try {
login_webserver = new WebServer(web_ipaddr, web_port, cert_file, key_file, key_password, hardcode_user, hardcode_password);
login_webserver->register_route("/status", NetConnection::Web_loginhandle_status);
login_webserver->register_route("/worlds", NetConnection::Web_loginhandle_worlds);
login_webserver->run();
@ -365,4 +365,4 @@ void NetConnection::InitWebServer(std::string web_ipaddr, int16 web_port, std::s
LogWrite(INIT__ERROR, 0, "Init", "Login Web Server failed to listen on %s:%u due to reason %s", web_ipaddr.c_str(), web_port, e.what());
}
}
}
}

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
@ -22,7 +22,7 @@ along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
#define ACHIEVEMENTS_H_
#include "../../common/types.h"
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../Items/Items.h"
#include <map>
#include <vector>
@ -139,7 +139,7 @@ public:
private:
Mutex mutex_achievements;
map<int32, Achievement *> achievements;
bool m_packetsCreated;
};
@ -173,4 +173,4 @@ public:
private:
map<int32, AchievementUpdate *> achievement_updates;
};
#endif
#endif

View File

@ -6,7 +6,7 @@
#include <vector>
#include "../../common/types.h"
#include "../../common/EQPacket.h"
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../client.h"
#include "ChatChannel.h"
@ -25,7 +25,7 @@ CREATING A CHANNEL
-- OP_RemoteCmdMsg --
3/14/2012 20:17:06
192.168.1.198 -> 69.174.200.73
0000: 00 09 05 9A 2A 0E 00 0F 00 63 75 73 74 6F 6D 20 ....*....custom
0000: 00 09 05 9A 2A 0E 00 0F 00 63 75 73 74 6F 6D 20 ....*....custom
0010 70 61 73 73 77 6F 72 64 password
@ -34,7 +34,7 @@ TALKING IN A CHANNEL
[11:52.23] <@Xinux> -- OP_RemoteCmdMsg --
[11:52.23] <@Xinux> 3/14/2012 20:17:25
[11:52.23] <@Xinux> 192.168.1.198 -> 69.174.200.73
[11:52.23] <@Xinux> 0000: 00 09 06 2D 2A 11 00 21 00 63 75 73 74 6F 6D 20 ...-*..!.custom
[11:52.23] <@Xinux> 0000: 00 09 06 2D 2A 11 00 21 00 63 75 73 74 6F 6D 20 ...-*..!.custom
[11:52.23] <@Xinux> 0010: 20 74 68 69 73 20 69 73 20 6D 79 20 63 75 73 74 this is my cust
[11:52.23] <@Xinux> 0020 6F 6D 20 63 68 61 6E 6E 65 6C om channel
@ -44,7 +44,7 @@ TALKING IN A CHANNEL
[08:37.46] <@Xinux_Work> 00 4B 6F 65 63 68 6F 68 00 02 00 00 00 00 01 00 .Koechoh........
[08:37.46] <@Xinux_Work> 00 00 22 00 18 00 62 65 74 74 65 72 20 74 68 61 .."...better tha
[08:37.46] <@Xinux_Work> 6E 20 61 20 72 65 64 20 6F 6E 65 20 3A 50 09 00 n a red one :P..
[08:37.46] <@Xinux_Work> 4C 65 76 65 6C 5F 31 2D 39 01 01 00 00 Level_1-9....
[08:37.46] <@Xinux_Work> 4C 65 76 65 6C 5F 31 2D 39 01 01 00 00 Level_1-9....
OTHERS LEAVING AND JOINING A CHANNEL

View File

@ -2,7 +2,7 @@
#define COLLECTIONS_H_
#include "../../common/types.h"
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../Items/Items.h"
#include <map>
#include <vector>
@ -104,4 +104,4 @@ private:
map<int32, Collection *> collections;
};
#endif
#endif

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2005 - 2026 EQ2EMulator Development Team (http://www.eq2emu.com formerly http://www.eq2emulator.net)
@ -20,7 +20,7 @@
#ifndef __EQ2_ENTITY__
#define __EQ2_ENTITY__
#include "Spawn.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "Skills.h"
#include "MutexList.h"
#include "MutexVector.h"
@ -57,9 +57,9 @@ struct MaintainedEffects{
char name[60]; //name of the spell
int32 target;
int8 target_type;
int32 spell_id;
int32 inherited_spell_id;
int32 slot_pos;
int32 spell_id;
int32 inherited_spell_id;
int32 slot_pos;
int16 icon;
int16 icon_backdrop;
int8 conc_used;
@ -70,8 +70,8 @@ struct MaintainedEffects{
};
struct SpellEffects{
int32 spell_id;
int32 inherited_spell_id;
int32 spell_id;
int32 inherited_spell_id;
Entity* caster;
float total_time;
int32 expire_timestamp;
@ -82,8 +82,8 @@ struct SpellEffects{
};
struct DetrimentalEffects {
int32 spell_id;
int32 inherited_spell_id;
int32 spell_id;
int32 inherited_spell_id;
Entity* caster;
int32 expire_timestamp;
int16 icon;
@ -238,11 +238,11 @@ struct InfoStruct{
pet_movement_ = 0;
pet_behavior_ = 0;
vision_ = 0;
redlight_ = 0;
greenlight_ = 0;
bluelight_ = 0;
breathe_underwater_ = 0;
biography_ = std::string("");
drunk_ = 0;
@ -260,7 +260,7 @@ struct InfoStruct{
interaction_flag_ = 0;
tag1_ = 0;
mood_ = 0;
range_last_attack_time_ = 0;
primary_last_attack_time_ = 0;
secondary_last_attack_time_ = 0;
@ -281,20 +281,20 @@ struct InfoStruct{
primary_weapon_delay_ = 0;
secondary_weapon_delay_ = 0;
ranged_weapon_delay_ = 0;
override_primary_weapon_ = 0;
override_secondary_weapon_ = 0;
override_ranged_weapon_ = 0;
friendly_target_npc_ = 0;
last_claim_time_ = 0;
engaged_encounter_ = 0;
lockable_encounter_ = 1;
first_world_login_ = 0;
reload_player_spells_ = 0;
group_loot_method_ = 1;
group_loot_items_rarity_ = 0;
group_auto_split_ = 1;
@ -304,10 +304,10 @@ struct InfoStruct{
group_solo_autolock_ = 0;
group_auto_loot_method_ = 0;
assist_auto_attack_ = 0;
action_state_ = std::string("");
combat_action_state_ = std::string("");
max_spell_reduction_ = .1f;
max_spell_reduction_override_ = 0;
max_chase_distance_ = 0.0f;
@ -433,10 +433,10 @@ struct InfoStruct{
spell_reuse_speed_ = oldStruct->get_spell_reuse_speed();
spell_multi_attack_ = oldStruct->get_spell_multi_attack();
dps_ = oldStruct->get_dps();
size_mod_ = oldStruct->get_size_mod();
ignore_size_mod_calc_ = oldStruct->get_ignore_size_mod_calc();
dps_multiplier_ = oldStruct->get_dps_multiplier();
attackspeed_ = oldStruct->get_attackspeed();
haste_ = oldStruct->get_haste();
@ -456,11 +456,11 @@ struct InfoStruct{
pet_movement_ = oldStruct->get_pet_movement();
pet_behavior_ = oldStruct->get_pet_behavior();
vision_ = oldStruct->get_vision();
redlight_ = oldStruct->get_redlight();
greenlight_ = oldStruct->get_greenlight();
bluelight_ = oldStruct->get_bluelight();
breathe_underwater_ = oldStruct->get_breathe_underwater();
biography_ = std::string(oldStruct->get_biography());
drunk_ = oldStruct->get_drunk();
@ -478,7 +478,7 @@ struct InfoStruct{
interaction_flag_ = oldStruct->get_interaction_flag();
tag1_ = oldStruct->get_tag1();
mood_ = oldStruct->get_mood();
range_last_attack_time_ = oldStruct->get_range_last_attack_time();
primary_last_attack_time_ = oldStruct->get_primary_last_attack_time();;
secondary_last_attack_time_ = oldStruct->get_secondary_last_attack_time();;
@ -499,22 +499,22 @@ struct InfoStruct{
primary_weapon_delay_ = oldStruct->get_primary_weapon_delay();
secondary_weapon_delay_ = oldStruct->get_secondary_weapon_delay();
ranged_weapon_delay_ = oldStruct->get_ranged_weapon_delay();
override_primary_weapon_ = oldStruct->get_override_primary_weapon();
override_secondary_weapon_ = oldStruct->get_override_secondary_weapon();
override_ranged_weapon_ = oldStruct->get_override_ranged_weapon();
friendly_target_npc_ = oldStruct->get_friendly_target_npc();
last_claim_time_ = oldStruct->get_last_claim_time();
engaged_encounter_ = oldStruct->get_engaged_encounter();
lockable_encounter_ = oldStruct->get_lockable_encounter();
first_world_login_ = oldStruct->get_first_world_login();
reload_player_spells_ = oldStruct->get_reload_player_spells();
action_state_ = oldStruct->get_action_state();
combat_action_state_ = oldStruct->get_combat_action_state();
group_loot_method_ = oldStruct->get_group_loot_method();
group_loot_items_rarity_ = oldStruct->get_group_loot_items_rarity();
group_auto_split_ = oldStruct->get_group_auto_split();
@ -524,7 +524,7 @@ struct InfoStruct{
group_solo_autolock_ = oldStruct->get_group_solo_autolock();
group_auto_loot_method_ = oldStruct->get_group_auto_loot_method();
assist_auto_attack_ = oldStruct->get_assist_auto_attack();
max_spell_reduction_ = oldStruct->get_max_spell_reduction();
max_spell_reduction_override_ = oldStruct->get_max_spell_reduction_override();
max_chase_distance_ = oldStruct->get_max_chase_distance();
@ -538,7 +538,7 @@ struct InfoStruct{
int8 get_gender() { std::lock_guard<std::mutex> lk(classMutex); return gender_; }
int16 get_level() { std::lock_guard<std::mutex> lk(classMutex); return level_; }
int16 get_max_level() { std::lock_guard<std::mutex> lk(classMutex); return max_level_; }
int16 get_effective_level() { std::lock_guard<std::mutex> lk(classMutex); return effective_level_; }
int16 get_effective_level() { std::lock_guard<std::mutex> lk(classMutex); return effective_level_; }
int16 get_tradeskill_level() { std::lock_guard<std::mutex> lk(classMutex); return tradeskill_level_; }
int16 get_tradeskill_max_level() { std::lock_guard<std::mutex> lk(classMutex); return tradeskill_max_level_; }
@ -559,7 +559,7 @@ struct InfoStruct{
float get_parry() { std::lock_guard<std::mutex> lk(classMutex); return parry_; }
float get_parry_base() { std::lock_guard<std::mutex> lk(classMutex); return parry_base_; }
int16 get_max_avoidance() { std::lock_guard<std::mutex> lk(classMutex); return max_avoidance_; }
float get_deflection() { std::lock_guard<std::mutex> lk(classMutex); return deflection_; }
@ -608,7 +608,7 @@ struct InfoStruct{
int32 get_weight() { std::lock_guard<std::mutex> lk(classMutex); return weight_; }
int32 get_max_weight() { std::lock_guard<std::mutex> lk(classMutex); return max_weight_; }
//SpellEffects* & get_spell_effects() { std::lock_guard<std::mutex> lk(classMutex); return spell_effects_; }
//MaintainedEffects* & get_maintained_effects() { std::lock_guard<std::mutex> lk(classMutex); return maintained_effects_; }
int8 get_tradeskill_class1() { std::lock_guard<std::mutex> lk(classMutex); return tradeskill_class1_; }
@ -638,7 +638,7 @@ struct InfoStruct{
int16 get_mitigation_skill1() { std::lock_guard<std::mutex> lk(classMutex); return mitigation_skill1_; }
int16 get_mitigation_skill2() { std::lock_guard<std::mutex> lk(classMutex); return mitigation_skill2_; }
int16 get_mitigation_skill3() { std::lock_guard<std::mutex> lk(classMutex); return mitigation_skill3_; }
int16 get_mitigation_pve() { std::lock_guard<std::mutex> lk(classMutex); return mitigation_pve_; }
int16 get_mitigation_pvp() { std::lock_guard<std::mutex> lk(classMutex); return mitigation_pvp_; }
@ -681,11 +681,11 @@ struct InfoStruct{
int8 get_pet_movement() { std::lock_guard<std::mutex> lk(classMutex); return pet_movement_; }
int8 get_pet_behavior() { std::lock_guard<std::mutex> lk(classMutex); return pet_behavior_; }
int32 get_vision() { std::lock_guard<std::mutex> lk(classMutex); return vision_; }
int32 get_redlight() { std::lock_guard<std::mutex> lk(classMutex); return redlight_; }
int32 get_greenlight() { std::lock_guard<std::mutex> lk(classMutex); return greenlight_; }
int32 get_bluelight() { std::lock_guard<std::mutex> lk(classMutex); return bluelight_; }
int8 get_breathe_underwater() { std::lock_guard<std::mutex> lk(classMutex); return breathe_underwater_; }
std::string get_biography() { std::lock_guard<std::mutex> lk(classMutex); return biography_; }
float get_drunk() { std::lock_guard<std::mutex> lk(classMutex); return drunk_; }
@ -708,11 +708,11 @@ struct InfoStruct{
int32 get_range_last_attack_time() { std::lock_guard<std::mutex> lk(classMutex); return range_last_attack_time_; }
int32 get_primary_last_attack_time() { std::lock_guard<std::mutex> lk(classMutex); return primary_last_attack_time_; }
int32 get_secondary_last_attack_time() { std::lock_guard<std::mutex> lk(classMutex); return secondary_last_attack_time_; }
int16 get_primary_attack_delay() { std::lock_guard<std::mutex> lk(classMutex); return primary_attack_delay_; }
int16 get_secondary_attack_delay() { std::lock_guard<std::mutex> lk(classMutex); return secondary_attack_delay_; }
int16 get_ranged_attack_delay() { std::lock_guard<std::mutex> lk(classMutex); return ranged_attack_delay_; }
int8 get_primary_weapon_type() { std::lock_guard<std::mutex> lk(classMutex); return primary_weapon_type_; }
int8 get_secondary_weapon_type() { std::lock_guard<std::mutex> lk(classMutex); return secondary_weapon_type_; }
int8 get_ranged_weapon_type() { std::lock_guard<std::mutex> lk(classMutex); return ranged_weapon_type_; }
@ -730,21 +730,21 @@ struct InfoStruct{
int16 get_primary_weapon_delay() { std::lock_guard<std::mutex> lk(classMutex); return primary_weapon_delay_; }
int16 get_secondary_weapon_delay() { std::lock_guard<std::mutex> lk(classMutex); return secondary_weapon_delay_; }
int16 get_ranged_weapon_delay() { std::lock_guard<std::mutex> lk(classMutex); return ranged_weapon_delay_; }
int8 get_override_primary_weapon() { std::lock_guard<std::mutex> lk(classMutex); return override_primary_weapon_; }
int8 get_override_secondary_weapon() { std::lock_guard<std::mutex> lk(classMutex); return override_secondary_weapon_; }
int8 get_override_ranged_weapon() { std::lock_guard<std::mutex> lk(classMutex); return override_ranged_weapon_; }
int8 get_friendly_target_npc() { std::lock_guard<std::mutex> lk(classMutex); return friendly_target_npc_; }
int32 get_last_claim_time() { std::lock_guard<std::mutex> lk(classMutex); return last_claim_time_; }
int8 get_engaged_encounter() { std::lock_guard<std::mutex> lk(classMutex); return engaged_encounter_; }
int8 get_lockable_encounter() { std::lock_guard<std::mutex> lk(classMutex); return lockable_encounter_; }
int8 get_first_world_login() { std::lock_guard<std::mutex> lk(classMutex); return first_world_login_; }
int8 get_reload_player_spells() { std::lock_guard<std::mutex> lk(classMutex); return reload_player_spells_; }
int8 get_group_loot_method() { std::lock_guard<std::mutex> lk(classMutex); return group_loot_method_; }
int8 get_group_loot_items_rarity() { std::lock_guard<std::mutex> lk(classMutex); return group_loot_items_rarity_; }
int8 get_group_auto_split() { std::lock_guard<std::mutex> lk(classMutex); return group_auto_split_; }
@ -754,18 +754,18 @@ struct InfoStruct{
int8 get_group_solo_autolock() { std::lock_guard<std::mutex> lk(classMutex); return group_solo_autolock_; }
int8 get_group_auto_loot_method() { std::lock_guard<std::mutex> lk(classMutex); return group_auto_loot_method_; }
int8 get_assist_auto_attack() { std::lock_guard<std::mutex> lk(classMutex); return assist_auto_attack_; }
std::string get_action_state() { std::lock_guard<std::mutex> lk(classMutex); return action_state_; }
std::string get_combat_action_state() { std::lock_guard<std::mutex> lk(classMutex); return combat_action_state_; }
float get_max_spell_reduction() { std::lock_guard<std::mutex> lk(classMutex); return max_spell_reduction_; }
int8 get_max_spell_reduction_override() { std::lock_guard<std::mutex> lk(classMutex); return max_spell_reduction_override_; }
float get_max_chase_distance() { std::lock_guard<std::mutex> lk(classMutex); return max_chase_distance_; }
void set_name(std::string value) { std::lock_guard<std::mutex> lk(classMutex); name_ = value; }
void set_deity(std::string value) { std::lock_guard<std::mutex> lk(classMutex); deity_ = value; }
void set_class1(int8 value) { std::lock_guard<std::mutex> lk(classMutex); class1_ = value; }
@ -910,11 +910,11 @@ struct InfoStruct{
void set_status_points(int32 value) { std::lock_guard<std::mutex> lk(classMutex); status_points_ = value; }
void add_status_points(int32 value) { std::lock_guard<std::mutex> lk(classMutex); if((sint64)status_points_ + value < 0) status_points_ = 0; else status_points_ += value; }
bool subtract_status_points(int32 value) { std::lock_guard<std::mutex> lk(classMutex); if(value > status_points_) return false; status_points_ -= value; return true; }
void set_mitigation_skill1(int16 value) { std::lock_guard<std::mutex> lk(classMutex); mitigation_skill1_ = value; }
void set_mitigation_skill2(int16 value) { std::lock_guard<std::mutex> lk(classMutex); mitigation_skill2_ = value; }
void set_mitigation_skill3(int16 value) { std::lock_guard<std::mutex> lk(classMutex); mitigation_skill3_ = value; }
void set_mitigation_pve(int16 value) { std::lock_guard<std::mutex> lk(classMutex); mitigation_pve_ = value; }
void set_mitigation_pvp(int16 value) { std::lock_guard<std::mutex> lk(classMutex); mitigation_pvp_ = value; }
@ -956,13 +956,13 @@ struct InfoStruct{
void set_strikethrough(float value) { std::lock_guard<std::mutex> lk(classMutex); strikethrough_ = value; }
void set_accuracy(float value) { std::lock_guard<std::mutex> lk(classMutex); accuracy_ = value; }
void set_offensivespeed(float value) { std::lock_guard<std::mutex> lk(classMutex); offensivespeed_ = value; }
// crash client if float values above 1.0 are sent
void set_rain(float value) { std::lock_guard<std::mutex> lk(classMutex); if(value > 1.0f) value = 1.0f; else if(value < 0.0f) value = 0.0f; rain_ = value; }
void set_wind(float value) { std::lock_guard<std::mutex> lk(classMutex); if(value > 1.0f) value = 1.0f; else if(value < 0.0f) value = 0.0f; wind_ = value; }
void set_max_chase_distance(float value) { std::lock_guard<std::mutex> lk(classMutex); max_chase_distance_ = value; }
void add_block_chance(float value) { std::lock_guard<std::mutex> lk(classMutex); if(block_chance_ + value < 0.0f) block_chance_ = 0.0f; else block_chance_ += value; }
void add_uncontested_parry(float value) { std::lock_guard<std::mutex> lk(classMutex); if(uncontested_parry_ + value < 0.0f) uncontested_parry_ = 0.0f; else uncontested_parry_ += value; }
void add_uncontested_block(float value) { std::lock_guard<std::mutex> lk(classMutex); if(uncontested_block_ + value < 0.0f) uncontested_block_ = 0.0f; else uncontested_block_ += value; }
@ -1005,11 +1005,11 @@ struct InfoStruct{
void set_max_weight(int32 value) { std::lock_guard<std::mutex> lk(classMutex); max_weight_ = value; }
void set_vision(int32 value) { std::lock_guard<std::mutex> lk(classMutex); vision_ = value; }
void set_redlight(int32 value) { std::lock_guard<std::mutex> lk(classMutex); redlight_ = value; }
void set_greenlight(int32 value) { std::lock_guard<std::mutex> lk(classMutex); greenlight_ = value; }
void set_bluelight(int32 value) { std::lock_guard<std::mutex> lk(classMutex); bluelight_ = value; }
void set_breathe_underwater(int8 value) { std::lock_guard<std::mutex> lk(classMutex); breathe_underwater_ = value; }
void set_drunk(float value) { std::lock_guard<std::mutex> lk(classMutex); drunk_ = value; }
@ -1033,7 +1033,7 @@ struct InfoStruct{
void set_range_last_attack_time(int32 value) { std::lock_guard<std::mutex> lk(classMutex); range_last_attack_time_ = value; }
void set_primary_last_attack_time(int32 value) { std::lock_guard<std::mutex> lk(classMutex); primary_last_attack_time_ = value; }
void set_secondary_last_attack_time(int32 value) { std::lock_guard<std::mutex> lk(classMutex); secondary_last_attack_time_ = value; }
void set_primary_attack_delay(int16 value) { std::lock_guard<std::mutex> lk(classMutex); primary_attack_delay_ = value; }
void set_secondary_attack_delay(int16 value) { std::lock_guard<std::mutex> lk(classMutex); secondary_attack_delay_ = value; }
void set_ranged_attack_delay(int16 value) { std::lock_guard<std::mutex> lk(classMutex); ranged_attack_delay_ = value; }
@ -1041,34 +1041,34 @@ struct InfoStruct{
void set_primary_weapon_type(int8 value) { std::lock_guard<std::mutex> lk(classMutex); primary_weapon_type_ = value; }
void set_secondary_weapon_type(int8 value) { std::lock_guard<std::mutex> lk(classMutex); secondary_weapon_type_ = value; }
void set_ranged_weapon_type(int8 value) { std::lock_guard<std::mutex> lk(classMutex); ranged_weapon_type_ = value; }
void set_primary_weapon_damage_low(int32 value) { std::lock_guard<std::mutex> lk(classMutex); primary_weapon_damage_low_ = value; }
void set_primary_weapon_damage_high(int32 value) { std::lock_guard<std::mutex> lk(classMutex); primary_weapon_damage_high_ = value; }
void set_secondary_weapon_damage_low(int32 value) { std::lock_guard<std::mutex> lk(classMutex); secondary_weapon_damage_low_ = value; }
void set_secondary_weapon_damage_high(int32 value) { std::lock_guard<std::mutex> lk(classMutex); secondary_weapon_damage_high_ = value; }
void set_ranged_weapon_damage_low(int32 value) { std::lock_guard<std::mutex> lk(classMutex); ranged_weapon_damage_low_ = value; }
void set_ranged_weapon_damage_high(int32 value) { std::lock_guard<std::mutex> lk(classMutex); ranged_weapon_damage_high_ = value; }
void set_wield_type(int8 value) { std::lock_guard<std::mutex> lk(classMutex); wield_type_ = value; }
void set_attack_type(int8 value) { std::lock_guard<std::mutex> lk(classMutex); attack_type_ = value; }
void set_primary_weapon_delay(int16 value) { std::lock_guard<std::mutex> lk(classMutex); primary_weapon_delay_ = value; }
void set_secondary_weapon_delay(int16 value) { std::lock_guard<std::mutex> lk(classMutex); secondary_weapon_delay_ = value; }
void set_ranged_weapon_delay(int16 value) { std::lock_guard<std::mutex> lk(classMutex); ranged_weapon_delay_ = value; }
void set_override_primary_weapon(int8 value) { std::lock_guard<std::mutex> lk(classMutex); override_primary_weapon_ = value; }
void set_override_secondary_weapon(int8 value) { std::lock_guard<std::mutex> lk(classMutex); override_secondary_weapon_ = value; }
void set_override_ranged_weapon(int8 value) { std::lock_guard<std::mutex> lk(classMutex); override_ranged_weapon_ = value; }
void set_friendly_target_npc(int8 value) { std::lock_guard<std::mutex> lk(classMutex); friendly_target_npc_ = value; }
void set_last_claim_time(int32 value) { std::lock_guard<std::mutex> lk(classMutex); last_claim_time_ = value; }
void set_engaged_encounter(int8 value) { std::lock_guard<std::mutex> lk(classMutex); engaged_encounter_ = value; }
void set_lockable_encounter(int8 value) { std::lock_guard<std::mutex> lk(classMutex); lockable_encounter_ = value; }
void set_first_world_login(int8 value) { std::lock_guard<std::mutex> lk(classMutex); first_world_login_ = value; }
void set_reload_player_spells(int8 value) { std::lock_guard<std::mutex> lk(classMutex); reload_player_spells_ = value; }
void set_group_loot_method(int8 value) { std::lock_guard<std::mutex> lk(classMutex); if(value <= GroupLootMethod::METHOD_MAX_COUNT) group_loot_method_ = value; }
void set_group_loot_items_rarity(int8 value) { std::lock_guard<std::mutex> lk(classMutex); group_loot_items_rarity_ = value; }
void set_group_auto_split(int8 value) { std::lock_guard<std::mutex> lk(classMutex); group_auto_split_ = value; }
@ -1077,17 +1077,17 @@ struct InfoStruct{
void set_group_lock_method(int8 value) { std::lock_guard<std::mutex> lk(classMutex); group_lock_method_ = value; }
void set_group_solo_autolock(int8 value) { std::lock_guard<std::mutex> lk(classMutex); group_solo_autolock_ = value; }
void set_group_auto_loot_method(int8 value) { std::lock_guard<std::mutex> lk(classMutex); group_auto_loot_method_ = value; }
void set_assist_auto_attack(int8 value) { std::lock_guard<std::mutex> lk(classMutex); assist_auto_attack_ = value; }
void set_action_state(std::string value) { std::lock_guard<std::mutex> lk(classMutex); action_state_ = value; }
void set_combat_action_state(std::string value) { std::lock_guard<std::mutex> lk(classMutex); combat_action_state_ = value; }
void set_max_spell_reduction(float value) { std::lock_guard<std::mutex> lk(classMutex); max_spell_reduction_ = value; }
void set_max_spell_reduction_override(int8 value) { std::lock_guard<std::mutex> lk(classMutex); max_spell_reduction_override_ = value; }
void ResetEffects(Spawn* spawn)
{
for(int i=0;i<45;i++){
@ -1099,8 +1099,8 @@ struct InfoStruct{
maintained_effects[i].spell = nullptr;
}
spell_effects[i].icon = 0;
spell_effects[i].spell_id = 0xFFFFFFFF;
spell_effects[i].icon = 0;
spell_effects[i].spell_id = 0xFFFFFFFF;
spell_effects[i].inherited_spell_id = 0;
spell_effects[i].icon_backdrop = 0;
spell_effects[i].tier = 0;
@ -1109,7 +1109,7 @@ struct InfoStruct{
spell_effects[i].spell = nullptr;
}
}
// maintained via their own mutex
SpellEffects spell_effects[45];
MaintainedEffects maintained_effects[30];
@ -1129,7 +1129,7 @@ private:
int16 effective_level_;
int16 tradeskill_level_;
int16 tradeskill_max_level_;
int8 cur_concentration_;
int8 max_concentration_;
int8 max_concentration_base_;
@ -1187,7 +1187,7 @@ private:
int32 bank_coin_silver_;
int32 bank_coin_gold_;
int32 bank_coin_plat_;
int32 status_points_;
std::string deity_;
int32 weight_;
@ -1282,7 +1282,7 @@ private:
int8 interaction_flag_;
int8 tag1_;
int16 mood_;
int32 range_last_attack_time_;
int32 primary_last_attack_time_;
int32 secondary_last_attack_time_;
@ -1303,20 +1303,20 @@ private:
int16 primary_weapon_delay_;
int16 secondary_weapon_delay_;
int16 ranged_weapon_delay_;
int8 override_primary_weapon_;
int8 override_secondary_weapon_;
int8 override_ranged_weapon_;
int8 friendly_target_npc_;
int32 last_claim_time_;
int8 engaged_encounter_;
int8 lockable_encounter_;
int8 first_world_login_;
int8 reload_player_spells_;
int8 group_loot_method_;
int8 group_loot_items_rarity_;
int8 group_auto_split_;
@ -1325,15 +1325,15 @@ private:
int8 group_lock_method_;
int8 group_solo_autolock_;
int8 group_auto_loot_method_;
int8 assist_auto_attack_;
std::string action_state_;
std::string combat_action_state_;
float max_spell_reduction_;
int8 max_spell_reduction_override_;
float max_chase_distance_;
};
@ -1347,7 +1347,7 @@ struct WardInfo {
int32 DamageAbsorptionPercentage;
int32 DamageAbsorptionMaxHealthPercent;
int32 RedirectDamagePercent;
int32 LastRedirectDamage;
int32 LastAbsorbedDamage;
@ -1355,9 +1355,9 @@ struct WardInfo {
int32 MaxHitCount;
bool AbsorbAllDamage; // damage is always absorbed, usually spells based on hits, when we pass damage in AddWard as 0 this will be set to true
bool RoundTriggered;
bool DeleteWard; // removal after process CheckWard while loop
};
@ -1458,7 +1458,7 @@ public:
float CalculateBonusMod();
float CalculateDPSMultiplier();
float CalculateCastingSpeedMod();
InfoStruct* GetInfoStruct();
int16 GetStr();
@ -1549,7 +1549,7 @@ public:
bool IsDualWield();
bool BehindTarget(Spawn* target);
bool FlankingTarget(Spawn* target);
void GetWeaponDamage(Item* item, int32* low_damage, int32* high_damage);
void ChangePrimaryWeapon();
void ChangeSecondaryWeapon();
@ -1585,7 +1585,7 @@ public:
bool EngagedInCombat();
virtual void InCombat(bool val);
void RefreshRegen(bool override_ = false);
bool IsCasting();
void IsCasting(bool val);
void SetMount(int16 mount_id, int8 red = 0xFF, int8 green = 0xFF, int8 blue = 0xFF, bool setUpdateFlags = true)
@ -1615,7 +1615,7 @@ public:
std::lock_guard<std::mutex> lk(MEquipment);
if(slot >= NUM_SLOTS)
return;
SetInfo(&equipment.equip_id[slot], type);
SetInfo(&equipment.color[slot].red, red);
SetInfo(&equipment.color[slot].green, green);
@ -1689,16 +1689,16 @@ public:
}
void SetSogaHairType(int16 new_val, bool setUpdateFlags = true){
SetInfo(&features.soga_hair_type, new_val, setUpdateFlags);
}
}
void SetSogaFacialHairType(int16 new_val, bool setUpdateFlags = true){
SetInfo(&features.soga_hair_face_type, new_val, setUpdateFlags);
}
}
void SetSogaChestType(int16 new_val, bool setUpdateFlags = true){
SetInfo(&features.soga_chest_type, new_val, setUpdateFlags);
}
}
void SetSogaLegType(int16 new_val, bool setUpdateFlags = true){
SetInfo(&features.soga_legs_type, new_val, setUpdateFlags);
}
}
void SetSkinColor(EQ2_Color color){
SetInfo(&features.skin_color, color);
}
@ -1711,11 +1711,11 @@ public:
void SetSogaModelColor(EQ2_Color color){
SetInfo(&features.soga_model_color, color);
}
void SetCombatVoice(int16 val, bool setUpdateFlags = true) {
SetInfo(&features.combat_voice, val, setUpdateFlags);
void SetCombatVoice(int16 val, bool setUpdateFlags = true) {
SetInfo(&features.combat_voice, val, setUpdateFlags);
}
void SetEmoteVoice(int16 val, bool setUpdateFlags = true) {
SetInfo(&features.emote_voice, val, setUpdateFlags);
void SetEmoteVoice(int16 val, bool setUpdateFlags = true) {
SetInfo(&features.emote_voice, val, setUpdateFlags);
}
int16 GetCombatVoice(){ return features.combat_voice; }
int16 GetEmoteVoice(){ return features.emote_voice; }
@ -1776,10 +1776,10 @@ public:
}
EQ2_Color* GetMountColor(){
return &features.mount_color;
}
}
// should only be accessed through MEquipment mutex
EQ2_Equipment equipment;
CharFeatures features;
CharFeatures features;
void AddSpellBonus(LuaSpell* spell, int16 type, float value, int64 class_req =0, vector<int16> race_req = vector<int16>(), vector<int16> faction_req = vector<int16>());
BonusValues* GetSpellBonus(int32 spell_id);
@ -2017,7 +2017,7 @@ public:
int32 CalculateFormulaByStat(int32 value, int16 stat);
int32 CalculateFormulaBonus(int32 value, float percent_bonus);
float CalculateSpellDamageReduction(float spellDamage, float resistancePercentage, int16 attackerLevel);
float GetStat(int32 item_stat) {
float item_chance_or_skill = 0.0f;
MStats.lock();
@ -2025,11 +2025,11 @@ public:
MStats.unlock();
return item_chance_or_skill;
}
bool IsEngagedInEncounter(Spawn** res = nullptr);
bool IsEngagedBySpawnID(int32 id);
void SendControlEffectDetailsToClient(Client* client);
std::string GetControlEffectName(int8 control_effect_type) {
switch(control_effect_type) {
case CONTROL_EFFECT_TYPE_MEZ: {
@ -2098,9 +2098,9 @@ public:
}
}
}
void TerminateTrade();
void CalculateMaxReduction();
// when PacketStruct is fixed for C++17 this should become a shared_mutex and handle read/write lock
std::mutex MEquipment;
@ -2178,7 +2178,7 @@ private:
map<string, boost::function<sint32()> > get_sint32_funcs;
map<string, boost::function<sint16()> > get_sint16_funcs;
map<string, boost::function<sint8()> > get_sint8_funcs;
map<string, boost::function<std::string()> > get_string_funcs;
// SETs
@ -2192,9 +2192,9 @@ private:
map<string, boost::function<void(sint32)> > set_sint32_funcs;
map<string, boost::function<void(sint16)> > set_sint16_funcs;
map<string, boost::function<void(sint8)> > set_sint8_funcs;
map<string, boost::function<void(std::string)> > set_string_funcs;
mutable std::shared_mutex propertiesMutex;
};

View File

@ -4,7 +4,7 @@
#define EQ2_FACTIONS
#include "../common/ConfigReader.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
struct Faction {
int32 id;
@ -119,4 +119,3 @@ private:
map<int32, int8> faction_percent;
};
#endif

View File

@ -5,7 +5,7 @@
#include "Spawn.h"
#include "client.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
class GroundSpawn : public Spawn {
public:
@ -53,7 +53,7 @@ public:
string GetHarvestSpellType();
string GetHarvestSpellName();
void HandleUse(Client* client, string type);
void SetRandomizeHeading(bool val) { randomize_heading = val; }
bool GetRandomizeHeading() { return randomize_heading; }
private:
@ -66,4 +66,3 @@ private:
bool randomize_heading;
};
#endif

View File

@ -7,7 +7,7 @@
#include <vector>
#include <deque>
#include <map>
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../MutexMap.h"
using namespace std;

View File

@ -7,7 +7,7 @@
#include "../common/linked_list.h"
#include "../common/timer.h"
#include "../common/queue.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "../common/TCPConnection.h"
#include <deque>
#include "MutexMap.h"

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2005 - 2026 EQ2EMulator Development Team (http://www.eq2emu.com formerly http://www.eq2emulator.net)
@ -27,7 +27,7 @@
#include "Spawn.h"
#include "Spells.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "Quests.h"
#include "zoneserver.h"
#include "client.h"
@ -123,17 +123,17 @@ struct LuaSpell{
ZoneServer* zone;
int16 initial_caster_level;
bool is_loaded_recast;
std::unordered_set<std::string> modified_fields;
std::unordered_set<std::string> modified_fields;
mutable std::shared_mutex spell_modify_mutex;
void AddTarget(int32 target_id) {
std::unique_lock lock(targets_mutex);
bool hasTarget = std::find(targets.begin(), targets.end(), target_id) != targets.end();
if(!hasTarget)
targets.push_back(target_id);
}
int32 GetPrimaryTargetID() const {
std::shared_lock lock(targets_mutex);
return targets.empty() ? -1 : targets[0];
@ -151,22 +151,22 @@ struct LuaSpell{
std::shared_lock lock(targets_mutex);
return targets;
}
bool HasNoTargets() const {
std::shared_lock lock(targets_mutex);
return targets.empty();
}
int32 GetTargetCount() const {
std::shared_lock lock(targets_mutex);
return static_cast<int32>(targets.size());
}
bool HasTarget(int32 id) const {
std::shared_lock lock(targets_mutex);
return std::find(targets.begin(), targets.end(), id) != targets.end();
}
bool HasAnyTarget(const std::vector<int32>& ids) const {
std::shared_lock lock(targets_mutex);
return std::any_of(
@ -188,12 +188,12 @@ struct LuaSpell{
v.erase(std::remove(v.begin(), v.end(), target_id), v.end());
removed_targets.push_back(target_id);
}
void AddRemoveTarget(int32 target_id) {
std::unique_lock lock(targets_mutex);
removed_targets.push_back(target_id);
}
void SwapTargets(std::vector<int32>& new_targets) {
std::unique_lock lock(targets_mutex);
targets.swap(new_targets);
@ -204,15 +204,15 @@ struct LuaSpell{
targets.clear();
removed_targets.clear();
}
std::multimap<int32, int8> GetCharIDTargets() const {
std::shared_lock lock(char_id_targets_mutex);
return char_id_targets;
}
void AddCharIDTarget(int32 char_id, int8 value) {
std::unique_lock lock(char_id_targets_mutex);
bool exists = false;
auto range = char_id_targets.equal_range(char_id);
for (auto it = range.first; it != range.second; ++it) {
@ -221,7 +221,7 @@ struct LuaSpell{
break;
}
}
if(!exists)
char_id_targets.insert({char_id, value});
}
@ -230,7 +230,7 @@ struct LuaSpell{
std::shared_lock lock(char_id_targets_mutex);
return char_id_targets.empty();
}
void RemoveCharIDTarget(int32 char_id) {
std::unique_lock lock(char_id_targets_mutex);
char_id_targets.erase(char_id); // removes all entries with that key
@ -252,7 +252,7 @@ struct LuaSpell{
std::unique_lock lock(char_id_targets_mutex);
char_id_targets.clear();
}
void MarkFieldModified(const std::string& field) {
std::unique_lock lock(spell_modify_mutex);
modified_fields.insert(field);
@ -267,12 +267,12 @@ struct LuaSpell{
std::unique_lock lock(spell_modify_mutex);
modified_fields.clear();
}
std::unordered_set<std::string> GetModifiedFieldsCopy() const {
std::shared_lock lock(spell_modify_mutex);
return modified_fields; // safe shallow copy
}
bool SetSpellDataGeneric(const std::string& field, int value) {
return SetSpellDataGeneric(field, std::to_string(value));
}
@ -284,7 +284,7 @@ struct LuaSpell{
bool SetSpellDataGeneric(const std::string& field, bool value) {
return SetSpellDataGeneric(field, value ? "1" : "0");
}
bool SetSpellDataGeneric(const std::string& field, const std::string& value) {
auto it = SpellFieldGenericSetters.find(field);
if (it == SpellFieldGenericSetters.end())
@ -296,9 +296,9 @@ struct LuaSpell{
it->second(spell, value);
return true;
}
bool SetSpellDataIndex(int idx, const std::string& value, const std::string& value2 = "");
bool SetSpellDataIndex(int idx, int value, int value2) {
return SetSpellDataIndex(idx, std::to_string(value), std::to_string(value2));
}
@ -450,7 +450,7 @@ public:
Skill* GetSkill(lua_State* state, int8 arg_num = 1);
LuaSpell* GetSpell(lua_State* state, int8 arg_num = 1);
vector<ConversationOption>* GetConversation(lua_State* state, int8 arg_num = 1);
vector<OptionWindowOption>* GetOptionWindow(lua_State* state, int8 arg_num = 1);
int8 GetInt8Value(lua_State* state, int8 arg_num = 1);
int16 GetInt16Value(lua_State* state, int8 arg_num = 1);
@ -497,7 +497,7 @@ public:
lua_State* GetRegionScript(const char* name, bool create_new = true, bool use = false);
LuaSpell* GetSpellScript(const char* name, bool create_new = true, bool use = true);
LuaSpell* CreateSpellScript(const char* name, lua_State* existState);
Quest* LoadQuest(int32 id, const char* name, const char* type, const char* zone, int8 level, const char* description, char* script_name);
const char* GetScriptName(lua_State* state);
@ -547,7 +547,7 @@ public:
void SetLuaSystemReloading(bool val) { lua_system_reloading = val; }
bool IsLuaSystemReloading() { return lua_system_reloading; }
void AddPendingSpellDelete(LuaSpell* spell);
void AddCustomSpell(LuaSpell* spell);
@ -558,10 +558,10 @@ public:
LuaSpell* FindCustomSpell(int32 id);
int32 GetFreeCustomSpellID();
void SetLuaUserDataStale(void* ptr);
bool IsLuaUserDataValid(void* ptr);
private:
bool shutting_down;
bool lua_system_reloading;
@ -615,7 +615,7 @@ private:
Mutex MCustomSpell;
Mutex MRegionScripts;
Mutex MSpellScripts;
mutable std::shared_mutex MLUAUserData;
};
#endif

View File

@ -4,12 +4,12 @@
#define MUTEXHELPER_H
#include "../common/timer.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include <list>
#include <map>
template<typename T>
class IsPointer {
class IsPointer {
public:
static bool ValidPointer(T key){
return false;
@ -74,7 +74,7 @@ private:
};
template<typename T>
class IsPointer<T*> {
class IsPointer<T*> {
public:
static bool ValidPointer(T* key){
return true;
@ -117,7 +117,7 @@ private:
int type;
KeyT key;
ValueT value;
unsigned int time;
unsigned int time;
};
template<typename T>
@ -149,7 +149,7 @@ public:
Sleep(1);
}
if(has_pending_deletes && (force || (Timer::GetCurrentTime2() > next_delete_attempt && access_count == 0))){
changing = true;
changing = true;
while(access_count > 0){
Sleep(1);
}
@ -179,7 +179,7 @@ private:
volatile bool changing;
volatile int access_count;
volatile unsigned int next_delete_attempt;
volatile bool has_pending_deletes;
volatile bool has_pending_deletes;
std::map<T, unsigned int> pending_deletes;
};
#endif

View File

@ -21,7 +21,7 @@
#define RECIPE_H_
#include "../../common/types.h"
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../classes.h"
#include <string.h>
@ -34,7 +34,7 @@ struct RecipeComp
{
int32 RecipeComp;
};
struct RecipeProducts {
int32 product_id;
@ -107,7 +107,7 @@ public:
bool CanUseRecipeByClass(Item* item, int8 class_id) {
/* any can use bit combination of 1+2
adornments = 1
artisan = 2
artisan = 2
*/
return item->generic_info.tradeskill_classes < 4 || (1 << class_id) & item->generic_info.tradeskill_classes;
}
@ -137,7 +137,7 @@ public:
///<param name="itemID">Item id of the component</param>
///<param name="slot">Slot id for this component</param>
void AddBuildComp(int32 itemID, int8 slot, bool preferred = 0);
// int8 = slot, vector = itemid
map<int8, vector<int32> > components;
@ -146,7 +146,7 @@ public:
int8 GetHighestStage() { return highestStage; }
void SetHighestStage(int8 val) { highestStage = val; }
int8 GetTotalBuildComponents();
bool ProvidedAllRequiredComponents(Client* client, vector<Item*>* player_components, vector<pair<int32,int16>>* player_component_pair_qty);
bool PlayerHasComponentByItemID(Client* client, vector<Item*>* player_components, vector<pair<int32,int16>>* player_component_pair_qty, int32 item_id, int8 required_qty);
@ -189,7 +189,7 @@ private:
int16 fuel_comp_qty;
int16 primary_comp_qty;
int8 highestStage;
};
class MasterRecipeList {
@ -203,12 +203,12 @@ public:
void ClearRecipes();
int32 Size();
EQ2Packet* GetRecipePacket(int32 recipe_id, Client *client = 0, bool display = false, int8 packet_type = 0);
/// <summary>Gets all the recipes for the given book name</summary>
/// <param name="book_name">Book name to get recipes for</param>
/// <returns>A vector of all the recipes for the given book</returns>
vector<Recipe*> GetRecipes(const char* book_name);
/// <summary>Gets a recipe with the given name</summary>
/// <param name='name'>The name of the recipe to get</param>
/// <returns>Recipe* whos name matches the given name</returns>

View File

@ -22,7 +22,7 @@
#include <string.h>
#include <map>
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../../common/types.h"
using namespace std;
@ -213,7 +213,7 @@ enum RuleType {
UseMapUnderworldCoords,
MapUnderworldCoordOffset,
SharedZoneMaxPlayers,
/* LOOT */
LootRadius,
AutoDisarmChest, // if enabled disarm only works if you right click and disarm, clicking and opening chest won't attempt auto disarm
@ -222,7 +222,7 @@ enum RuleType {
AllowChestUnlockByDropTime,
ChestUnlockedTimeTrap,
AllowChestUnlockByTrapTime,
/* SPELLS */
NoInterruptBaseChance,
EnableFizzleSpells,
@ -367,4 +367,4 @@ private:
map<int32, RuleSet *> zone_rule_sets; /* references to a zone's rule set. map<zone id, rule set> */
};
#endif
#endif

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2005 - 2026 EQ2EMulator Development Team (http://www.eq2emu.com formerly http://www.eq2emulator.net)
@ -38,7 +38,7 @@
#include "Zone/map.h"
#include "Zone/region_map.h"
#include "Zone/region_map_v1.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "MutexList.h"
#include <deque>
#include <memory> // needed for LS to compile properly on linux
@ -59,7 +59,7 @@
#define DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG2 0xEA
#define DAMAGE_PACKET_RESULT_NO_DAMAGE 0
#define DAMAGE_PACKET_RESULT_SUCCESSFUL 1
#define DAMAGE_PACKET_RESULT_SUCCESSFUL 1
#define DAMAGE_PACKET_RESULT_MISS 4
#define DAMAGE_PACKET_RESULT_DODGE 8
#define DAMAGE_PACKET_RESULT_PARRY 12
@ -426,8 +426,8 @@ public:
void SetEmoteState(int8 new_val, bool updateFlags = true){
SetInfo(&appearance.emote_state, new_val, updateFlags);
}
void SetName(const char* new_name, bool updateFlags = true){
SetInfo(appearance.name, new_name, updateFlags);
void SetName(const char* new_name, bool updateFlags = true){
SetInfo(appearance.name, new_name, updateFlags);
}
void SetPrefixTitle(const char* new_prefix_title, bool updateFlags = true) {
SetInfo(appearance.prefix_title, new_prefix_title, updateFlags);
@ -441,14 +441,14 @@ public:
void SetLastName(const char* new_last_name, bool updateFlags = true) {
SetInfo(appearance.last_name, new_last_name, updateFlags);
}
void SetAdventureClass(int8 new_class, bool updateFlags = true) {
SetInfo(&appearance.adventure_class, new_class, updateFlags);
void SetAdventureClass(int8 new_class, bool updateFlags = true) {
SetInfo(&appearance.adventure_class, new_class, updateFlags);
}
void SetTradeskillClass(int8 new_class, bool updateFlags = true) {
SetInfo(&appearance.tradeskill_class, new_class, updateFlags);
void SetTradeskillClass(int8 new_class, bool updateFlags = true) {
SetInfo(&appearance.tradeskill_class, new_class, updateFlags);
}
void SetSize(int16 new_size, bool updateFlags = true) {
SetPos(&size, new_size, updateFlags);
void SetSize(int16 new_size, bool updateFlags = true) {
SetPos(&size, new_size, updateFlags);
}
void SetSpeedX(float speed_x, bool updateFlags = true) {
SetPos(&appearance.pos.SpeedX, speed_x, updateFlags);
@ -459,14 +459,14 @@ public:
void SetSpeedZ(float speed_z, bool updateFlags = true) {
SetPos(&appearance.pos.SpeedZ, speed_z, updateFlags);
}
void SetX(float x, bool updateFlags = true){
SetPos(&appearance.pos.X, x, updateFlags);
void SetX(float x, bool updateFlags = true){
SetPos(&appearance.pos.X, x, updateFlags);
}
void SetY(float y, bool updateFlags = true, bool disableYMapFix = false);
void SetZ(float z, bool updateFlags = true){
void SetZ(float z, bool updateFlags = true){
SetPos(&appearance.pos.Z, z, updateFlags);
}
void SetHeading(sint16 dir1, sint16 dir2, bool updateFlags = true){
void SetHeading(sint16 dir1, sint16 dir2, bool updateFlags = true){
SetPos(&appearance.pos.Dir1, dir1, false); // we set the update for heading on the second direction do not duplicate the process
SetPos(&appearance.pos.Dir2, dir2, updateFlags);
}
@ -500,22 +500,22 @@ public:
roll = (roll - 180) * 64;
SetPos(&appearance.pos.Roll, (sint16)roll, updateFlags);
}
void SetVisualState(int16 state, bool updateFlags = true){
void SetVisualState(int16 state, bool updateFlags = true){
SetInfo(&appearance.visual_state, state, updateFlags);
}
void SetActionState(int16 state, bool updateFlags = true){
void SetActionState(int16 state, bool updateFlags = true){
SetInfo(&appearance.action_state, state, updateFlags);
}
void SetMoodState(int16 state, bool updateFlags = true){
void SetMoodState(int16 state, bool updateFlags = true){
SetInfo(&appearance.mood_state, state, updateFlags);
}
void SetInitialState(int16 state, bool updateFlags = true){
void SetInitialState(int16 state, bool updateFlags = true){
SetPos(&appearance.pos.state, state, updateFlags);
}
void SetActivityStatus(int16 state, bool updateFlags = true){
void SetActivityStatus(int16 state, bool updateFlags = true){
SetInfo(&appearance.activity_status, state, updateFlags);
}
void SetCollisionRadius(int32 radius, bool updateFlags = true){
void SetCollisionRadius(int32 radius, bool updateFlags = true){
SetPos(&appearance.pos.collision_radius, radius, updateFlags);
}
int16 GetCollisionRadius(){
@ -550,10 +550,10 @@ public:
}
virtual void SetLevel(int16 level, bool setUpdateFlags = true){
SetInfo(&appearance.level, level, setUpdateFlags);
}
}
void SetTSLevel(int16 tradeskill_level, bool setUpdateFlags = true){
SetInfo(&appearance.tradeskill_level, tradeskill_level, setUpdateFlags);
}
}
void SetGender(int8 gender, bool setUpdateFlags = true){
SetInfo(&appearance.gender, gender, setUpdateFlags);
}
@ -571,7 +571,7 @@ public:
}
void SetShowCommandIcon(int8 new_val, bool setUpdateFlags = true){
SetVis(&appearance.show_command_icon, new_val, setUpdateFlags);
}
}
void SetShowHandIcon(int8 new_val, bool setUpdateFlags = true){
SetVis(&appearance.display_hand_icon, new_val, setUpdateFlags);
}
@ -641,7 +641,7 @@ public:
int8 GetShowCommandIcon(){
return appearance.show_command_icon;
}
char* GetName(){
char* GetName(){
return appearance.name;
}
char* GetPrefixTitle(){
@ -656,11 +656,11 @@ public:
char* GetLastName() {
return appearance.last_name;
}
int8 GetAdventureClass() {
return appearance.adventure_class;
int8 GetAdventureClass() {
return appearance.adventure_class;
}
int8 GetTradeskillClass() {
return appearance.tradeskill_class;
int8 GetTradeskillClass() {
return appearance.tradeskill_class;
}
float GetDestinationX(){
return appearance.pos.X2;
@ -680,14 +680,14 @@ public:
float GetDestinationY(){
return appearance.pos.Y2;
}
float GetY(){
return appearance.pos.Y;
float GetY(){
return appearance.pos.Y;
}
float GetDestinationZ(){
return appearance.pos.Z2;
}
float GetZ(){
return appearance.pos.Z;
float GetZ(){
return appearance.pos.Z;
}
float GetHeading(){
float heading = 0;
@ -698,7 +698,7 @@ public:
else
heading += 180;
}
return heading;
return heading;
}
float GetPitch(){
float pitch = 0;
@ -709,7 +709,7 @@ public:
else
pitch += 180;
}
return pitch;
return pitch;
}
float GetRoll(){
float roll = 0;
@ -720,7 +720,7 @@ public:
else
roll += 180;
}
return roll;
return roll;
}
int32 GetID(){
return id;
@ -745,7 +745,7 @@ public:
sint32 GetTotalPowerBaseInstance();
float GetHPRatio() { return GetHP() == 0 || GetTotalHP() == 0 ? 0 : ((float) GetHP() / GetTotalHP() * 100); }
int GetIntHPRatio() { return GetTotalHP() == 0 ? 0 : static_cast<int>(GetHPRatio()); }
sint32 GetTotalSavagery();
sint32 GetSavagery();
sint32 GetTotalDissonance();
@ -794,7 +794,7 @@ public:
bool Alive(){ return is_alive; }
void SetAlive(bool val) { is_alive = val; }
int16 GetLevel(){
return appearance.level;
}
@ -867,7 +867,7 @@ public:
int16 GetModelType(){
return appearance.model_type;
}
bool IsFlyingCreature();
bool IsWaterCreature();
bool InWater();
@ -875,7 +875,7 @@ public:
void SetFlyingCreature();
void SetWaterCreature();
void SetPrimaryCommand(const char* name, const char* command, float distance = 10);
void SetPrimaryCommands(vector<EntityCommand*>* commands);
void SetSecondaryCommands(vector<EntityCommand*>* commands);
@ -905,7 +905,7 @@ public:
virtual bool IsBot() { return false; }
bool HasInfoChanged(){ return info_changed; }
bool HasPositionChanged(){ return position_changed; }
bool HasPositionChanged(){ return position_changed; }
bool HasTarget(){ return target ? true : false; }
int32 GetRespawnTime();
@ -946,7 +946,7 @@ public:
void SetTrapTriggered(bool triggered, int32 state) {
if(!trap_triggered && triggered)
trap_opened_time = Timer::GetCurrentTime2();
trap_triggered = triggered;
trap_state = state;
}
@ -1015,10 +1015,10 @@ public:
MLootItems.lock();
loot_item_count = loot_items.size();
MLootItems.unlock();
return loot_item_count;
}
void ClearNonBodyLoot() {
MLootItems.lock();
@ -1035,7 +1035,7 @@ public:
}
MLootItems.unlock();
}
int32 GetLootCoins() {
LockLoot();
int32 coins = loot_coins;
@ -1045,9 +1045,9 @@ public:
void SetLootCoins(int32 val, bool lockloot = true) {
if(lockloot)
LockLoot();
loot_coins = val;
if(lockloot)
UnlockLoot();
}
@ -1078,7 +1078,7 @@ public:
id_lock.unlock();
return NextID();
}
id_lock.unlock();
return ret;
}
@ -1102,7 +1102,7 @@ public:
void UpdateEncounterState(int8 new_state);
void CheckEncounterState(Entity* victim, bool test_auto_lock = false);
void AddTargetToEncounter(Entity* entity);
void SendSpawnChanges(bool val){ send_spawn_changes = val; }
void SetSpawnGroupID(int32 id);
int32 GetSpawnGroupID();
@ -1158,7 +1158,7 @@ public:
bool IsRunning();
void CalculateRunningLocation(bool stop = false);
void RunToLocation(float x, float y, float z, float following_x = 0, float following_y = 0, float following_z = 0);
MovementLocation* GetCurrentRunningLocation();
MovementLocation* GetLastRunningLocation();
void NewWaypointChange(MovementLocation* data);
@ -1174,7 +1174,7 @@ public:
bool NeedsToResumeMovement(){ return attack_resume_needed; }
void NeedsToResumeMovement(bool val) { attack_resume_needed = val; }
bool HasMovementLoop(){ return movement_loop.size() > 0; }
bool HasMovementLocations() {
bool HasMovementLocations() {
bool hasLocations = false;
MMovementLocations.lock_shared();
hasLocations = movement_locations ? movement_locations->size() > 0 : false;
@ -1216,7 +1216,7 @@ public:
bool is_water_creature;
bool is_flying_creature;
int32 trigger_widget_id;
std::atomic<bool> following;
bool IsPet() { return is_pet; }
void SetPet(bool val) { is_pet = val; }
@ -1324,7 +1324,7 @@ public:
{
pickup_unique_item_id = uniqueid;
}
void SetHouseCharacterID(int32 charid)
{
house_character_id = charid;
@ -1340,11 +1340,11 @@ public:
RegionMap* GetRegionMap() { return region_map; }
Map* GetMap() { return current_map; }
std::map<int32,TimedGridData> established_grid_id;
void DeleteRegion(Region_Node* inNode, ZBSP_Node* rootNode);
bool InRegion(Region_Node* inNode, ZBSP_Node* rootNode);
int32 GetRegionType(Region_Node* inNode, ZBSP_Node* rootNode);
float SpawnAngle(Spawn* target, float selfx, float selfz);
bool BehindSpawn(Spawn *target, float selfx, float selfz)
{ return (!target || target == this) ? false : SpawnAngle(target, selfx, selfz) > 90.0f; }
@ -1361,7 +1361,7 @@ public:
virtual bool IsPauseMovementTimerActive();
bool IsTransportSpawn() { return is_transport_spawn; }
void SetTransportSpawn(bool val) { is_transport_spawn = val; }
sint64 GetRailID() { return rail_id; }
void SetRailID(sint64 val) { rail_id = val; }
void AddRailPassenger(int32 char_id);
@ -1375,23 +1375,23 @@ public:
int32 GetLootTier() { return loot_tier; }
void SetLootTier(int32 tier) { loot_tier = tier; }
int32 GetLootDropType() { return loot_drop_type; }
void SetLootDropType(int32 type) { loot_drop_type = type; }
void SetDeletedSpawn(bool val) { deleted_spawn = val; }
bool IsDeletedSpawn() { return deleted_spawn; }
int32 InsertRegionToSpawn(Region_Node* node, ZBSP_Node* bsp_root, WaterRegionType regionType, bool in_region = true);
bool HasRegionTracked(Region_Node* node, ZBSP_Node* bsp_root, bool in_region);
int8 GetArrowColor(int8 spawn_level);
void AddIgnoredWidget(int32 id);
void SendGroupUpdate();
void OverrideLootMethod(GroupLootMethod newMethod) { loot_method = newMethod; }
void SetLootMethod(GroupLootMethod method, int8 item_rarity = 0, int32 group_id = 0);
int32 GetLootGroupID() { return loot_group_id; }
@ -1413,7 +1413,7 @@ public:
void GetSpawnLottoEntries(int32 item_id, std::map<int32, int32>* out_entries);
void GetLootItemsList(std::vector<int32>* out_entries);
void GetSpawnNeedGreedEntries(int32 item_id, bool need_item, std::map<int32, int32>* out_entries);
bool HasLootWindowCompleted();
bool IsLootWindowComplete() { return is_loot_complete; }
void SetLootDispensed() { is_loot_dispensed = true; }
@ -1421,18 +1421,18 @@ public:
std::map<int32, bool>* GetLootWindowList() { return &loot_complete; }
void StartLootTimer(Spawn* looter);
void CloseLoot(Spawn* sender);
void SetLootName(char* name) {
if(name != nullptr) {
loot_name = std::string(name);
loot_name = std::string(name);
}
}
const char* GetLootName() { return loot_name.c_str(); }
bool IsItemInLootTier(Item* item);
void DistributeGroupLoot_RoundRobin(std::vector<int32>* item_list, bool roundRobinTrashLoot = false); // trash loot is what falls under the item tier requirement by group options
void CalculateInitialVelocity(float heading, float distanceHorizontal, float distanceVertical, float distanceDepth, float duration);
glm::vec3 CalculateProjectilePosition(glm::vec3 initialVelocity, float time);
bool CalculateSpawnProjectilePosition(float x, float y, float z);
@ -1441,10 +1441,10 @@ public:
mutable std::shared_mutex MIgnoredWidgets;
std::map<int32, bool> ignored_widgets;
EquipmentItemList equipment_list;
EquipmentItemList appearance_equipment_list;
protected:
bool has_quests_required;
@ -1463,7 +1463,7 @@ protected:
int32 movement_start_time;
Mutex MMovementLoop;
map<int32, int8> allowed_access;
vector<int32> quest_ids;
vector<int32> quest_ids;
int32 database_id;
int32 packet_num;
int32 target;
@ -1485,7 +1485,7 @@ protected:
void CheckProximities();
Timer pause_timer;
bool IsKnockedBack() { return knocked_back; }
private:
int32 loot_group_id;
@ -1497,12 +1497,12 @@ private:
int32 loot_coins;
std::multimap<int32, int32> lotto_items;
std::multimap<int32, std::pair<int32, bool>> need_greed_items;
std::map<int32, bool> loot_complete;
bool is_loot_complete;
bool is_loot_dispensed;
std::string loot_name;
bool trap_triggered;
int32 trap_state;
int32 chest_drop_time;
@ -1590,8 +1590,7 @@ private:
int32 knocked_back_end_time;
float knocked_angle;
glm::vec3 knocked_velocity;
};
#endif

View File

@ -11,7 +11,7 @@
#include "../common/MiscFunctions.h"
#include "client.h"
#include "classes.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "AltAdvancement/AltAdvancement.h"
#include <lua.hpp>
@ -368,7 +368,7 @@ public:
vector<SpellDisplayEffect*> effects;
vector<LUAData*> lua_data;
mutable std::shared_mutex MSpellInfo;
private:
bool stay_locked = false;
@ -380,7 +380,7 @@ private:
bool copied_spell;
SpellData* spell;
//vector<SpellDisplayEffect*> effects;
vector <LevelArray*> levels;
};
@ -404,7 +404,7 @@ public:
EQ2Packet* GetSpecialSpellPacket(int32 id, int8 tier, Client* client = 0, bool display = false, int8 packet_type = 0);
void AddSpell(int32 id, int8 tier, Spell* spell);
Mutex MMasterSpellList;
/// <summary>Gets the correct spell error value for the given version</summary>
/// <param name='version'>Client version</param>
/// <param name='error_index'>ID of the error</param>
@ -417,13 +417,13 @@ public:
/// <param name='error_value'>Value for the error</param>
void AddSpellError(int16 version, int8 error_index, int16 error_value);
int32 GetNewMaxSpellID() {
int32 GetNewMaxSpellID() {
int32 id = 0;
MMasterSpellList.lock();
max_spell_id++;
id = max_spell_id;
MMasterSpellList.unlock();
return id;
return id;
}
private:
/// <summary>Helper function that gets the closest version in the spell_errors map that is less then or equal to the given version</summary>
@ -435,4 +435,3 @@ private:
int32 max_spell_id;
};
#endif

View File

@ -6,7 +6,7 @@
#include <string>
#include <map>
#include <vector>
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "../common/types.h"
using namespace std;
@ -25,7 +25,7 @@ public:
const char* GetName() {return name;}
int8 GetPrefix() {return prefix;}
bool GetSaveNeeded() {return save_needed;}
private:
sint32 id;
int8 prefix;
@ -63,4 +63,4 @@ private:
vector<Title*> player_titles_list;
Mutex MPlayerTitleMutex;
};
#endif
#endif

View File

@ -4,7 +4,7 @@
#define __EQ2_TRADESKILLS__
#include "../../common/types.h"
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../Items/Items.h"
#include <map>
class Player;
@ -86,13 +86,13 @@ public:
/// <param name='function'>Function name that is releasing the lock</param>
/// <param name='line'>Line number that is releasing the lock</param>
void ReleaseReadLock(const char* function = (const char*)0, int32 line = 0) { m_tradeskills.releasereadlock(function, line); }
int32 GetTechniqueSuccessAnim(int16 version, int32 technique);
int32 GetTechniqueFailureAnim(int16 version, int32 technique);
int32 GetTechniqueIdleAnim(int16 version, int32 technique);
int32 GetMissTargetAnim(int16 version);
int32 GetKillMissTargetAnim(int16 version);
void SetClientIdleVisualState(Client* client, Tradeskill* ts);
private:
/// <summary>Sends the creation window</summary>
@ -123,7 +123,7 @@ public:
/// <param name='technique'>The skill id of the technique</param>
/// <returns>Vector of TradeskillEvent* for the given technique</returns>
vector<TradeskillEvent*>* GetEventByTechnique(int32 technique);
/// <summary>Get the size of the event list</summary>
/// <returns>int32 containing the size of the list</returns>
int32 Size();

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
@ -23,7 +23,7 @@ along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
#include <vector>
#include <map>
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../../common/types.h"
#include "../../common/EQPacket.h"
@ -56,14 +56,14 @@ class MasterTraitList
public:
MasterTraitList();
~MasterTraitList();
bool IdentifyNextTrait(Client* client, map <int8, vector<TraitData*> >* traitList, vector<TraitData*>* collectTraits, vector<TraitData*>* tieredTraits, std::map<int32, int8>* previousMatchedSpells, bool omitFoundMatches = false);
bool ChooseNextTrait(Client* client);
int16 GetSpellCount(Client* client, map <int8, vector<TraitData*> >* traits, bool onlyCharTraits = false);
bool IsPlayerAllowedTrait(Client* client, TraitData* trait);
bool GenerateTraitLists(Client* client, map <int8, map <int8, vector<TraitData*> > >* sortedTraitList, map <int8, vector<TraitData*> >* classTraining,
map <int8, vector<TraitData*> >* raceTraits, map <int8, vector<TraitData*> >* innateRaceTraits, map <int8, vector<TraitData*> >* focusEffects, int16 max_level = 0, int8 trait_group = 255);
/// <summary>Sorts the traits for the given client and creats and sends the trait packet.</summary>
/// <param name='client'>The Client calling this function</param>
/// <returns>EQ2Packet*</returns>
@ -79,7 +79,7 @@ public:
/// <summary>Get the trait data for the given spell.</summary>
/// <param name='spellID'>Spell ID to get trait data for.</param>
TraitData* GetTrait(int32 spellID);
/// <summary>Get the trait data for the given item.</summary>
/// <param name='itemID'>Item ID to map to the trait data.</param>
TraitData* GetTraitByItemID(int32 itemID);
@ -91,4 +91,4 @@ private:
Mutex MMasterTraitList;
};
#endif
#endif

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2005 - 2026 EQ2EMulator Development Team (http://www.eq2emu.com formerly http://www.eq2emulator.net)
@ -34,7 +34,7 @@
#include "../common/database.h"
#include "../common/types.h"
#include "../common/MiscFunctions.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "../common/DatabaseNew.h"
#include "client.h"
#include "Object.h"
@ -272,7 +272,7 @@ public:
bool SpawnGroupRemoveSpawn(Spawn* spawn, int32 group_id);
int32 CreateSpawnGroup(Spawn* spawn, string name);
void DeleteSpawnGroup(int32 id);
bool SetGroupSpawnChance(int32 id, float chance);
bool SetGroupSpawnChance(int32 id, float chance);
void LoadGroundSpawnEntries(ZoneServer* zone);
void LoadGroundSpawnItems(ZoneServer* zone);
void LoadSpawns(ZoneServer* zone);
@ -385,15 +385,15 @@ public:
int32 LoadQuests();
void LoadQuestDetails(Quest* quest);
bool DeleteCharacter(int32 account_id, int32 character_id);
int32 GetMaxHotBarID();
int8 CheckNameFilter(const char* name, int8 min_length = 4, int8 max_length = 15);
static int32 NextUniqueHotbarID(){
static int32 NextUniqueHotbarID(){
next_id++;
return next_id;
return next_id;
}
void LoadFogInit(string zone, PacketStruct* packet);
static int32 next_id;
@ -417,7 +417,7 @@ public:
bool DeleteInstanceSpawnRemoved(int32 instance_id, int32 spawn_location_entry_id);
bool DeleteCharacterFromInstance(int32 char_id, int32 instance_id);
bool LoadCharacterInstances(Client* client);
bool DeletePersistedRespawn(int32 zone_id, int32 spawn_location_entry_id);
int32 CreatePersistedRespawn(int32 spawn_location_entry_id, int32 spawn_type, int32 respawn_time, int32 zone_id);
map<int32,int32>* GetPersistedSpawns(int32 zone_id, int8 type);
@ -465,7 +465,7 @@ public:
void SavePlayerCollection(Client *client, Collection *collection);
void SavePlayerCollectionItems(Client *client, Collection *collection);
void SavePlayerCollectionItem(Client *client, Collection *collection, int32 item_id);
/* Commands */
map<int32, string>* GetSpawnTemplateListByName(const char* name);
map<int32, string>* GetSpawnTemplateListByID(int32 location_id);
@ -652,11 +652,11 @@ public:
void LoadStartingSpells(World* world);
void LoadVoiceOvers(World* world);
int32 CreateSpiritShard(const char* name, int32 level, int8 race, int8 gender, int8 adventure_class,
int32 CreateSpiritShard(const char* name, int32 level, int8 race, int8 gender, int8 adventure_class,
int16 model_type, int16 soga_model_type, int16 hair_type, int16 hair_face_type, int16 wing_type,
int16 chest_type, int16 legs_type, int16 soga_hair_type, int16 soga_hair_face_type, int8 hide_hood,
int16 size, int16 collision_radius, int16 action_state, int16 visual_state, int16 mood_state, int16 emote_state,
int16 pos_state, int16 activity_status, char* sub_title, char* prefix_title, char* suffix_title, char* lastname,
int16 chest_type, int16 legs_type, int16 soga_hair_type, int16 soga_hair_face_type, int8 hide_hood,
int16 size, int16 collision_radius, int16 action_state, int16 visual_state, int16 mood_state, int16 emote_state,
int16 pos_state, int16 activity_status, char* sub_title, char* prefix_title, char* suffix_title, char* lastname,
float x, float y, float z, float heading, int32 gridid, int32 charid, int32 zoneid, int32 instanceid);
bool DeleteSpiritShard(int32 id);
@ -666,7 +666,7 @@ public:
void LoadCharacterSpellEffects(int32 char_id, Client *client, int8 db_spell_type);
int32 GetMysqlExpCurve(int level);
bool RemoveBrokerItem(int32 cid, int64 uid, int32 quantity);
int32 LoadBrokerSellers(BrokerManager &broker);
int32 LoadBrokerItems(BrokerManager &broker);
@ -674,8 +674,8 @@ public:
void ClearSellerSession(int32 character_id);
void AddToSellerSession(int32 character_id, int64 amount);
int64 GetSellerSession(int32 character_id);
int64 GetSellerSession(int32 character_id);
bool UpdateHouseSpawnScript(int32 dbid, std::string scriptName);
private:
DatabaseNew database_new;
@ -686,4 +686,3 @@ private:
std::map<int32, int8> zone_instance_types;
};
#endif

View File

@ -1,7 +1,7 @@
#include <string>
#include <map>
#include <list>
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "../../common/types.h"
#pragma once
@ -114,7 +114,7 @@ private:
void SetupMutexes();
void InstantiateLists(bool parent);
void shuffleMap(ChestTrapList* list);
bool ChestTrapParent;

View File

@ -24,7 +24,7 @@
#include "../../common/types.h"
#include "../../common/MiscFunctions.h"
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
#include "position.h"
#include <stdio.h>
@ -87,20 +87,20 @@ public:
float GetMaxY() { return m_MaxY; }
float GetMinZ() { return m_MinZ; }
float GetMaxZ() { return m_MaxZ; }
bool isPointWithinMap(double x, double y, double z, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
return (x >= m_MinX && x <= m_MaxX && y >= m_MinY && y <= m_MaxY && z >= m_MinZ && z <= m_MaxZ);
}
void SetFileName(std::string newfile) { m_FileName = string(newfile); }
void MapMinMaxY(float y);
void MapGridMinMaxBorderArray(GridMapBorder* border, glm::vec3 a, glm::vec3 b, glm::vec3 c);
void MapGridMinMaxBorder(GridMapBorder* border, glm::vec3 a);
bool IsPointInGrid(GridMapBorder* border, glm::vec3 a, float radius);
std::vector<int32> GetGridsByPoint(glm::vec3 a, float radius);
GridMapBorder* GetMapGridBorder(int32 grid_id, bool instantiate_border = true);
std::map<int32, glm::vec3> widget_map;
std::map<int32, GridMapBorder*> grid_map_border;
private:
@ -137,7 +137,7 @@ public:
~MapRange();
void Clear();
void AddVersionRange(std::string zoneName);
map<VersionRange*, Map*>::iterator FindVersionRange(int32 min_version, int32 max_version);

View File

@ -1,7 +1,7 @@
#pragma once
#include <memory>
#include "../Entity.h"
#include "../../common/Mutex.h"
#include "../../common/mutex.h"
class Mob;
class Client;

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2005 - 2026 EQ2EMulator Development Team (http://www.eq2emu.com formerly http://www.eq2emulator.net)
@ -27,7 +27,7 @@ using namespace std;
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <algorithm>
#include <chrono>
#include <signal.h>
@ -44,9 +44,8 @@ using namespace std;
#include "../common/version.h"
#include "../common/EQEMuError.h"
#include "../common/opcodemgr.h"
#include "../common/Common_Defines.h"
#include "../common/defines.h"
#include "../common/JsonParser.h"
#include "../common/Common_Defines.h"
#include "LoginServer.h"
#include "Commands/Commands.h"
@ -169,7 +168,7 @@ int main(int argc, char** argv) {
#ifdef _DEBUG
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
if (signal(SIGINT, CatchSignal) == SIG_ERR) {
LogWrite(INIT__ERROR, 0, "Init", "Could not set signal handler");
return 0;
@ -188,12 +187,12 @@ int main(int argc, char** argv) {
return 0;
}
#endif
LogWrite(WORLD__DEBUG, 0, "World", "Randomizing World...");
srand(time(NULL));
net.ReadLoginINI(argc, argv);
// JA: Grouping all System (core) data loads together for timing purposes
LogWrite(WORLD__INFO, 0, "World", "Loading System Data...");
int32 t_now = Timer::GetUnixTimeStamp();
@ -214,10 +213,10 @@ int main(int argc, char** argv) {
LogWrite(INIT__ERROR, 0, "Init", "Loading opcodes failed. Make sure you have sourced the opcodes.sql file!");
return false;
}
if(version1 == 0) // we don't need to display version 0
continue;
if(prevString.size() > 0) {
if(prevString == missingOpcodesList) {
builtString += ", " + std::to_string(version1);
@ -275,26 +274,26 @@ int main(int argc, char** argv) {
#endif
#endif
}
if (!threadedLoad) {
LogWrite(ITEM__INFO, 0, "Items", "Loading Items...");
database.LoadItemList();
LogWrite(SPELL__INFO, 0, "Spells", "Loading Spells...");
database.LoadSpells();
LogWrite(SPELL__INFO, 0, "Spells", "Loading Spell Errors...");
database.LoadSpellErrors();
LogWrite(WORLD__INFO, 0, "Traits", "Loading Traits...");
database.LoadTraits();
LogWrite(QUEST__INFO, 0, "Quests", "Loading Quests...");
database.LoadQuests();
LogWrite(COLLECTION__INFO, 0, "Collect", "Loading Collections...");
database.LoadCollections();
LogWrite(MERCHANT__INFO, 0, "Merchants", "Loading Merchants...");
database.LoadMerchantInformation();
}
@ -305,7 +304,7 @@ int main(int argc, char** argv) {
database.LoadRecipes();
LogWrite(TRADESKILL__INFO, 0, "Tradeskills", "Loading Tradeskill Events...");
database.LoadTradeskillEvents();
LogWrite(SPELL__INFO, 0, "AA", "Loading Alternate Advancements...");
database.LoadAltAdvancements();
LogWrite(SPELL__INFO, 0, "AA", "Loading AA Tree Nodes...");
@ -326,7 +325,7 @@ int main(int argc, char** argv) {
LogWrite(LUA__INFO, 0, "LUA", "Loading Player Scripts...");
world.LoadPlayerScripts();
LogWrite(WORLD__INFO, 0, "World", "Loading House Zone Data...");
database.LoadHouseZones();
@ -345,17 +344,17 @@ int main(int argc, char** argv) {
LogWrite(WORLD__INFO, 0, "World", "Loading NPC Spells...");
database.LoadNPCSpells();
if (threadedLoad) {
LogWrite(WORLD__INFO, 0, "World", "Waiting for load threads to finish.");
while (!world.items_loaded || !world.spells_loaded)
Sleep(10);
LogWrite(WORLD__INFO, 0, "World", "Load threads finished.");
}
LogWrite(GUILD__INFO, 0, "Guilds", "Loading Guilds...");
database.LoadGuilds();
LogWrite(WORLD__INFO, 0, "World", "Loading Player House Data...");
database.LoadPlayerHouses();
@ -363,10 +362,10 @@ int main(int argc, char** argv) {
int ret_code = 0;
if (eqsf.Open(net.GetWorldPort())) {
world.world_loaded = true; // need this set ahead so peering starts sending data also
LogWrite(WORLD__INFO, 0, "World", "Loading Broker Data...");
database.LoadBrokerData(broker);
if (strlen(net.GetWorldAddress()) == 0)
LogWrite(NET__INFO, 0, "Net", "World server listening on port %i", net.GetWorldPort());
else
@ -374,7 +373,7 @@ int main(int argc, char** argv) {
if(strlen(net.GetInternalWorldAddress())>0)
LogWrite(NET__INFO, 0, "Net", "World server listening on: %s:%i", net.GetInternalWorldAddress(), net.GetWorldPort());
world.world_uptime = getCurrentTimestamp();
#ifdef WIN32
_beginthread(StartPeerPoll, 0, NULL);
@ -396,14 +395,14 @@ int main(int argc, char** argv) {
TimeoutTimer->Start();
EQStream* eqs = 0;
UpdateWindowTitle(0);
if(net.is_primary) {
database.LoadSpecialZones();
}
map<EQStream*, int32> connecting_clients;
map<EQStream*, int32>::iterator cc_itr;
LogWrite(WORLD__DEBUG, 0, "Thread", "Starting console command thread...");
#ifdef WIN32
_beginthread(EQ2ConsoleListener, 0, NULL);
@ -415,9 +414,9 @@ int main(int argc, char** argv) {
//
// just before starting loops, announce how to get console help (only to windows)
#ifdef WIN32
#ifdef WIN32
LogWrite(WORLD__INFO, 0, "Console", "Type 'help' or '?' and press enter for menu options.");
#endif
#endif
std::chrono::time_point<std::chrono::system_clock> frame_prev = std::chrono::system_clock::now();
@ -511,7 +510,7 @@ int main(int argc, char** argv) {
LogWrite(WORLD__DEBUG, 0, "World", "The world is ending!");
peer_https_pool.stopPolling();
LogWrite(WORLD__DEBUG, 0, "World", "Shutting down zones...");
zone_list.ShutDownZones();
@ -549,11 +548,11 @@ ThreadReturnType ItemLoad (void* tmp)
WorldDatabase db;
db.Init();
db.ConnectNewDatabase();
LogWrite(ITEM__INFO, 0, "Items", "Loading Items...");
db.LoadItemList();
db.ResetNextUniqueItemID();
// Relies on the item list so needs to be in the item thread
LogWrite(COLLECTION__INFO, 0, "Collect", "Loading Collections...");
db.LoadCollections();
@ -624,7 +623,7 @@ ThreadReturnType AchievmentLoad (void* tmp)
world->achievments_loaded = true;
LogWrite(WORLD__WARNING, 0, "Thread", "Achievement Loading Thread completed.");
mysql_thread_end();
THREAD_RETURN(NULL);
}
@ -649,14 +648,14 @@ ThreadReturnType StartPeerPoll (void* tmp)
ThreadReturnType EQ2ConsoleListener(void* tmp)
{
char cmd[300];
char cmd[300];
size_t i = 0;
size_t len;
while( RunLoops )
{
// Read in single line from "stdin"
memset( cmd, 0, sizeof( cmd ) );
memset( cmd, 0, sizeof( cmd ) );
if( fgets( cmd, 300, stdin ) == NULL )
continue;
@ -709,34 +708,34 @@ bool NetConnection::ReadLoginINI(int argc, char** argv) {
LogWrite(INIT__ERROR, 0, "Init", "loginserver.worldname was invalid or less than 4 characters..");
return false;
}
std::string worldaccount_str = parser.getValue("loginserver.account");
std::string worldpassword_str = parser.getValue("loginserver.password");
std::string worldaddress_str = parser.getValue("loginserver.worldaddress");
snprintf(worldname, sizeof(worldname), "%s", worldname_str.c_str());
snprintf(worldaccount, sizeof(worldaccount), "%s", worldaccount_str.c_str());
snprintf(worldpassword, sizeof(worldpassword), "%s", worldpassword_str.c_str());
snprintf(worldaddress, sizeof(worldaddress), "%s", worldaddress_str.c_str());
std::string logstats_str = parser.getValue("loginserver.logstats");
int16 logstats = 0;
parser.convertStringToUnsignedShort(logstats_str, logstats);
net.UpdateStats = logstats > 0 ? true : false;
std::string locked_str = parser.getValue("loginserver.locked");
int16 locked = 0;
parser.convertStringToUnsignedShort(locked_str, locked);
world_locked = locked > 0 ? true : false;
std::string worldport_str = parser.getValue("loginserver.worldport");
parser.convertStringToUnsignedShort(worldport_str, worldport);
for(int i=-1;i<=3;i++) {
std::string loginport_str = "";
std::string loginaddress_str = "";
if(i==-1) {
loginport_str = parser.getValue("loginserver.loginport");
loginaddress_str = parser.getValue("loginserver.loginserver");
@ -745,20 +744,20 @@ bool NetConnection::ReadLoginINI(int argc, char** argv) {
loginport_str = parser.getValue("loginserver.loginport" + std::to_string(i));
loginaddress_str = parser.getValue("loginserver.loginserver" + std::to_string(i));
}
if(loginport_str.size() < 1 || loginaddress_str.size() < 1)
continue;
parser.convertStringToUnsignedShort(loginport_str, loginport[i+1]);
snprintf(loginaddress[i+1], sizeof(loginaddress[i+1]), "%s", loginaddress_str.c_str());
LogWrite(INIT__INFO, 0, "Init", "Login Server %s:%u...", loginaddress[i+1], loginport[i+1]);
}
if(!loginaddress[0][0]) {
LogWrite(INIT__ERROR, 0, "Init", "loginserver.loginserver was missing..");
return false;
}
web_worldaddress = parser.getValue("worldserver.webaddress");
web_certfile = parser.getValue("worldserver.webcertfile");
web_keyfile = parser.getValue("worldserver.webkeyfile");
@ -797,19 +796,19 @@ bool NetConnection::ReadLoginINI(int argc, char** argv) {
break;
}
}
std::string webpeerpriority_str = parser.getValue("worldserver.peerpriority");
parser.convertStringToUnsignedShort(webpeerpriority_str, web_peerpriority);
peer_https_pool.init(web_certfile, web_keyfile);
std::string webloginport_str = parser.getValue("worldserver.webport");
parser.convertStringToUnsignedShort(webloginport_str, web_worldport);
std::string defaultstatus_str = parser.getValue("worldserver.defaultstatus");
parser.convertStringToUnsignedChar(defaultstatus_str, DEFAULTSTATUS);
// Define namespace for ease of use
namespace po = boost::program_options;
@ -847,16 +846,16 @@ bool NetConnection::ReadLoginINI(int argc, char** argv) {
web_worldport = webWorldPort;
if(worldPort)
worldport = worldPort;
if(worldAddress.size() > 0)
snprintf(worldaddress, sizeof(worldaddress), "%s", worldAddress.c_str());
if(internalWorldAddress.size() > 0)
snprintf(internalworldaddress, sizeof(internalworldaddress), "%s", internalWorldAddress.c_str());
if(webWorldAddress.size() > 0)
web_worldaddress = webWorldAddress;
LogWrite(INIT__DEBUG, 0, "Init", "%s read...", MAIN_CONFIG_FILE);
LoginServerInfo=1;
return true;
@ -898,7 +897,7 @@ void UpdateWindowTitle(char* iNewTitle) {
string servername = net.GetWorldName();
snprintf(tmp, sizeof(tmp), "%s (%s), Version: %s: %i Clients(s) in %i Zones(s)", EQ2EMU_MODULE, servername.c_str(), CURRENT_VERSION, numclients, numzones);
}
// Zero terminate ([max - 1] = 0) the string to prevent a warning
// Zero terminate ([max - 1] = 0) the string to prevent a warning
tmp[499] = 0;
#ifdef WIN32
SetConsoleTitle(tmp);
@ -1030,7 +1029,7 @@ ThreadReturnType StartDiscord(void* tmp)
#endif
bool enablediscord = rule_manager.GetGlobalRule(R_Discord, DiscordEnabled)->GetBool();
if(enablediscord == false) {
LogWrite(INIT__INFO, 0,"Discord","Bot Disabled By Rule...");
THREAD_RETURN(NULL);
@ -1045,14 +1044,14 @@ ThreadReturnType StartDiscord(void* tmp)
}
dpp::cluster bot(bottoken, dpp::i_default_intents | dpp::i_message_content);
//if we have debug on, go ahead and show DPP logs.
#ifdef DEBUG
bot.on_log([&bot](const dpp::log_t & event) {
std::cout << "[" << dpp::utility::loglevel(event.severity) << "] " << event.message << "\n";
});
#endif
bot.on_message_create([&bot](const dpp::message_create_t& event) {
if (event.msg.author.is_bot() == false) {
std::string chanid = event.msg.channel_id.str();
@ -1071,7 +1070,7 @@ ThreadReturnType StartDiscord(void* tmp)
//wait 30s for reconnect. prevents hammering discord and a potential ban.
std::this_thread::sleep_for(std::chrono::milliseconds(30000));
}
THREAD_RETURN(NULL);
}
#endif
#endif

View File

@ -1,4 +1,4 @@
/*
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2005 - 2026 EQ2EMulator Development Team (http://www.eq2emu.com formerly http://www.eq2emulator.net)
@ -30,7 +30,7 @@
#include "../common/servertalk.h"
#include "../common/TCPConnection.h"
#include "WorldTCPConnection.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "../common/DataBuffer.h"
#include "net.h"
#include "Player.h"
@ -279,7 +279,7 @@ class ZoneServer {
public:
ZoneServer(const char* file);
~ZoneServer();
void IncrementIncomingClients();
void DecrementIncomingClients();
void Init();
@ -287,31 +287,31 @@ public:
bool SpawnProcess();
ZoneInfoSlideStruct* GenerateSlideStruct(float unknown1a, float unknown1b, int32 unknown2a, int32 unknown2b, int32 unknown3, int32 unknown4, const char* slide, const char* voiceover, int32 key1, int32 key2);
void AddZoneInfoSlideStructTransitionInfo(ZoneInfoSlideStruct* info, int32 x, int32 y, float zoom, float transition_time);
void AddZoneInfoSlideStructTransitionInfo(ZoneInfoSlideStruct* info, int32 x, int32 y, float zoom, float transition_time);
vector<ZoneInfoSlideStruct*>* GenerateTutorialSlides();
void LoadRevivePoints(vector<RevivePoint*>* revive_points);
vector<RevivePoint*>* GetRevivePoints(Client* client);
RevivePoint* GetRevivePoint(int32 id);
void AddClient(Client* client);
void SimpleMessage(int8 type, const char* message, Spawn* from, float distance, bool send_to_sender = true);
void HandleChatMessage(Spawn* from, const char* to, int16 channel, const char* message, float distance = 0, const char* channel_name = 0, bool show_bubble = true, int32 language = 0);
void HandleChatMessage(Client* client, Spawn* from, const char* to, int16 channel, const char* message, float distance = 0, const char* channel_name = 0, bool show_bubble = true, int32 language = 0);
void HandleChatMessage(Client* client, std::string fromName, const char* to, int16 channel, const char* message, float distance = 0, const char* channel_name = 0, int32 language = 0);
void HandleChatMessage(std::string fromName, const char* to, int16 channel, const char* message, float distance, const char* channel_name, int32 language);
void HandleBroadcast(const char* message);
void HandleAnnouncement(const char* message);
int16 SetSpawnTargetable(Spawn* spawn, float distance);
int16 SetSpawnTargetable(int32 spawn_id);
void ApplySetSpawnCommand(Client* client, Spawn* target, int8 type, const char* value);
void SetSpawnCommand(Spawn* spawn, int8 type, char* value, Client* client = 0);
void SetSpawnCommand(int32 spawn_id, int8 type, char* value, Client* client = 0);
void AddLoot(NPC* npc, Spawn* killer = nullptr, GroupLootMethod loot_method = GroupLootMethod::METHOD_FFA, int8 item_rarity = 0, int32 group_id = 0);
NPC* AddNPCSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
Object* AddObjectSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
GroundSpawn* AddGroundSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
@ -320,16 +320,16 @@ public:
void AddSpawn(Spawn* spawn);
void RemoveDeadEnemyList(Spawn* spawn);
void RemoveDeadSpawn(Spawn* spawn);
void AddSpawnGroupLocation(int32 group_id, int32 location_id, int32 spawn_location_id);
void AddSpawnGroupAssociation(int32 group_id1, int32 group_id2);
void AddSpawnGroupChance(int32 group_id, float percent);
void RemoveSpawn(Spawn* spawn, bool delete_spawn = true, bool respawn = true, bool lock = true, bool erase_from_spawn_list = true, bool lock_spell_process = false);
void ProcessSpawnLocations();
void SendQuestUpdates(Client* client, Spawn* spawn = 0);
EQ2Packet* GetZoneInfoPacket(Client* client);
Spawn* FindSpawn(Player* searcher, const char* name);
bool CallSpawnScript(Spawn* npc, int8 type, Spawn* spawn = 0, const char* message = 0, bool is_door_open = false, sint32 input_value = 0, sint32* return_value = 0);
@ -339,7 +339,7 @@ public:
void HandleEmote(Spawn* originator, string name, Spawn* opt_target = nullptr, bool no_target = false);
Spawn* GetSpawnByDatabaseID(int32 id);
Spawn* GetSpawnByID(int32 id, bool spawnListLocked=false);
void PlaySoundFile(Client* client, const char* name, float origin_x, float origin_y, float origin_z);
void SendZoneSpawns(Client* client);
void StartZoneInitialSpawnThread(Client* client);
@ -348,28 +348,28 @@ public:
void SendSpawnChanges(Spawn* spawn, Client* client, bool override_changes = false, bool override_vis_changes = false);
void SendSpawnChangesByDBID(int32 spawn_id, Client* client, bool override_changes = false, bool override_vis_changes = false);
void SendPlayerPositionChanges(Player* player);
void UpdateVitality(float amount);
vector<Entity*> GetPlayers();
void KillSpawn(bool spawnListLocked, Spawn* dead, Spawn* killer, bool send_packet = true, int8 type = 0, int8 damage_type = 0, int16 kill_blow_type = 0);
void SendDamagePacket(Spawn* attacker, Spawn* victim, int8 type1, int8 type2, int8 damage_type, int16 damage, const char* spell_name);
void SendHealPacket(Spawn* caster, Spawn* target, int16 type, int32 heal_amt, const char* spell_name);
void SendCastSpellPacket(LuaSpell* spell, Entity* caster, int32 spell_visual_override = 0, int16 casttime_override = 0xFFFF);
void SendCastSpellPacket(int32 spell_visual, Spawn* target, Spawn* caster = 0);
void SendCastEntityCommandPacket(EntityCommand* entity_command, int32 spawn_id, int32 target_id);
void TriggerCharSheetTimer();
/// <summary>Sends the game time packet to all connected clients</summary>
void SendTimeUpdateToAllClients();
void AddWidgetTimer(Spawn* widget, float time);
bool HasWidgetTimer(Spawn* widget);
void Despawn(Spawn* spawn, int32 timer);
void RepopSpawns(Client* client, Spawn* spawn);
bool AddCloseSpawnsToSpawnGroup(Spawn* spawn, float radius);
void Depop(bool respawns = false, bool repop = false);
@ -377,19 +377,19 @@ public:
Spawn* GetSpawnGroup(int32 id);
bool IsSpawnGroupAlive(int32 id);
void AddEnemyList(NPC* npc);
void ReloadClientQuests();
void SendAllSpawnsForLevelChange(Client* client);
void SendAllSpawnsForSeeInvisChange(Client* client);
void SendAllSpawnsForVisChange(Client* client, bool limitToEntities=true);
void AddLocationGrid(LocationGrid* grid);
void RemoveLocationGrids();
void DeleteTransporters();
void CheckTransporters(Client* client);
void WritePlayerStatistics();
bool SendRadiusSpawnInfo(Client* client, float radius);
@ -400,13 +400,13 @@ public:
volatile int8 initial_spawn_threads_active;
volatile bool client_thread_active;
void AddChangedSpawn(Spawn* spawn);
void AddDamagedSpawn(Spawn* spawn);
void AddDrowningVictim(Player* player);
void RemoveDrowningVictim(Player* player);
Client* GetDrowningVictim(Player* player);
void DeleteSpellProcess();
void LoadSpellProcess();
void LockAllSpells(Player* player);
@ -418,10 +418,10 @@ public:
void ProcessEntityCommand(EntityCommand* entity_command, Entity* caster, Spawn* target, bool lock = true);
void AddPlayerTracking(Player* player);
void RemovePlayerTracking(Player* player, int8 mode);
void SendUpdateTitles(Client *client, Title *suffix = 0, Title *prefix = 0);
void SendUpdateTitles(Spawn *spawn, Title *suffix = 0, Title *prefix = 0);
void RemoveTargetFromSpell(LuaSpell* spell, Spawn* target, bool remove_caster = false);
/// <summary>Set the rain levl in the zone</summary>
@ -434,16 +434,16 @@ public:
/// <summary>Handles zone-wide weather changes</summary>
void ProcessWeather();
Spawn* GetClosestTransportSpawn(float x, float y, float z);
Spawn* GetTransportByRailID(sint64 rail_id);
void ResurrectSpawn(Spawn* spawn, Client* client);
void HidePrivateSpawn(Spawn* spawn);
Client* GetClientByName(char* name);
Client* GetClientByCharID(int32 charid);
bool SetPlayerTargetByName(Client* originator, char* targetName, float distance);
std::vector<int32> GetGridsByLocation(Spawn* originator, glm::vec3 loc, float distance);
/// <summary>Gets spawns for a true AoE spell</summary>
@ -501,10 +501,10 @@ public:
****************************************************/
inline const char* GetZoneName() { return zone_name; }
void SetZoneName(char* new_zone) {
void SetZoneName(char* new_zone) {
if( strlen(new_zone) >= sizeof zone_name )
return;
strcpy(zone_name, new_zone);
strcpy(zone_name, new_zone);
}
inline const char* GetZoneFile() { return zone_file; }
void SetZoneFile(char* zone) {
@ -519,18 +519,18 @@ public:
strcpy(zonesky_file, zone);
}
inline const char* GetZoneDescription() { return zone_description; }
void SetZoneDescription(char* desc) {
void SetZoneDescription(char* desc) {
if( strlen(desc) >= sizeof zone_description )
return;
strncpy(zone_description, desc, 255);
strncpy(zone_description, desc, 255);
}
void SetUnderWorld(float under){ underworld = under; }
float GetUnderWorld(){ return underworld; }
inline int32 GetZoneID() { return zoneID; }
void SetZoneID(int32 new_id){ zoneID = new_id; }
inline bool IsCityZone() { return cityzone; }
inline bool AlwaysLoaded() { return always_loaded; }
inline bool DuplicatedZone() { return duplicated_zone; }
@ -553,7 +553,7 @@ public:
int32 GetInstanceID() { return instanceID; }
bool IsInstanceZone() { return isInstance; }
void SetInstanceID(int32 newInstanceID) { instanceID = newInstanceID; }
void SetShutdownTimer(int val){
void SetShutdownTimer(int val){
shutdownTimer.SetTimer(val*1000);
}
@ -564,7 +564,7 @@ public:
spawn_location_list[id] = spawnlocation;
MSpawnLocationList.releasewritelock(__FUNCTION__, __LINE__);
}
void SetInstanceType(int16 type) { InstanceType = (Instance_Type)type; if(type>0)isInstance=true; else isInstance=false; }
Instance_Type GetInstanceType() { return InstanceType; }
float GetSafeX(){ return safe_x; }
@ -595,7 +595,7 @@ public:
/// <summary>Returns the Tradeskill Manager for this zone</summary>
TradeskillMgr* GetTradeskillMgr() { return tradeskillMgr; }
// had to add these to access weather from Commands
bool isWeatherEnabled() { return weather_enabled; }
@ -720,7 +720,7 @@ public:
void StopSpawnScriptTimer(Spawn* spawn, std::string functionName);
Client* RemoveZoneServerFromClient(ZoneServer* zone);
void SendSubSpawnUpdates(SUBSPAWN_TYPES subtype);
bool HouseItemSpawnExists(int32 item_id);
void ProcessPendingSpawns();
@ -728,12 +728,12 @@ public:
void RemoveSpawnFromGrid(Spawn* spawn, int32 grid_id);
int32 GetSpawnCountInGrid(int32 grid_id);
void SendClientSpawnListInGrid(Client* client, int32 grid_id);
void AddIgnoredWidget(int32 id);
void AddIgnoredWidget(int32 id);
void AddRespawn(Spawn* spawn);
void AddRespawn(int32 locationID, int32 respawnTime);
void SendRespawnTimerList(Client* client);
private:
#ifndef WIN32
@ -815,7 +815,7 @@ private:
void InitWeather(); // never used outside zone server
///<summary>Dismiss all pets in the zone, useful when the spell process needs to be reloaded</summary>
void DismissAllPets(); // never used outside zone server
/* Mutex Lists */
std::map<int32, bool> changed_spawns; // int32 = spawn id
vector<Client*> clients;
@ -829,7 +829,7 @@ private:
set<SpawnScriptTimer*> remove_spawn_script_timers_list;
Mutex MRemoveSpawnScriptTimersList;
list<LocationTransportDestination*> transporter_locations;
/* Mutex Maps */
MutexMap<Client*, int32> drowning_victims;
MutexMap<int32, int32> movement_spawns; // 1st int32 = spawn id
@ -852,11 +852,11 @@ private:
map<int32, int32> widget_timers; // 1st int32 = spawn id
std::map<int32, GridMap*> grid_maps;
/* Mutexs */
mutable std::shared_mutex MGridMaps;
mutable std::shared_mutex MChangedSpawns;
Mutex m_enemy_faction_list;
Mutex m_npc_faction_list;
Mutex m_reverse_enemy_faction_list;
@ -875,7 +875,7 @@ private:
Mutex MSpawnDeleteList;
Mutex MClientList;
Mutex MIncomingClients;
/* Maps */
map<int32, int32> dead_spawns;
map<int32, vector<int32>* > enemy_faction_list;
@ -887,11 +887,11 @@ private:
/* Lists */
list<Spawn*> pending_spawn_list_add;
/* Specialized Lists to update specific scenarios */
std::map<int32, Spawn*> subspawn_list[SUBSPAWN_TYPES::MAX_SUBSPAWN_TYPE];
std::map<int32, int32> housing_spawn_map;
/* Vectors */
vector<RevivePoint*>* revive_points;
vector<int32> transport_spawns;
@ -899,7 +899,7 @@ private:
/* Classes */
SpellProcess* spellProcess;
TradeskillMgr* tradeskillMgr;
/* Timers */
Timer aggro_timer;
Timer charsheet_changes;
@ -923,7 +923,7 @@ private:
Timer queue_updates;
Timer shutdownDelayTimer;
Timer delete_timer;
/* Enums */
Instance_Type InstanceType;
@ -940,8 +940,8 @@ private:
bool always_loaded;
bool duplicated_zone;
int32 duplicated_id;
bool isInstance;
bool isInstance;
std::atomic<int32> pNumPlayers;
sint16 minimumStatus;
int16 minimumLevel;
@ -1025,17 +1025,17 @@ private:
Mutex MTransportMaps;
// Map <transport if, map name>
map<int32, string> m_transportMaps;
int32 watchdogTimestamp;
std::map<int32, int32> lua_queued_state_commands;
std::map<int32, std::map<std::string, float>> lua_spawn_update_command;
std::mutex MLuaQueueStateCmd;
mutable std::shared_mutex MIgnoredWidgets;
std::map<int32, bool> ignored_widgets;
Map* default_zone_map; // this is the map that npcs, ground spawns, so on use. May not be the same as the clients!
int32 groupraidMinLevel;
int32 groupraidMaxLevel;
int32 groupraidAvgLevel;
@ -1054,11 +1054,11 @@ public:
void AddNPC(int32 id, NPC* npc);
NPC* GetNPC(int32 id, bool override_loading = false) {
if((!reloading || override_loading) && npc_list.count(id) > 0)
return npc_list[id];
return npc_list[id];
else
return 0;
}
NPC* GetNewNPC(int32 id) {
NPC* GetNewNPC(int32 id) {
if(!reloading && npc_list.count(id) > 0)
return new NPC(npc_list[id]);
else
@ -1075,30 +1075,30 @@ public:
/* Objects */
void AddObject(int32 id, Object* object){ object_list[id] = object; }
Object* GetObject(int32 id, bool override_loading = false) {
Object* GetObject(int32 id, bool override_loading = false) {
if((!reloading || override_loading) && object_list.count(id) > 0)
return object_list[id];
return object_list[id];
else
return 0;
}
Object* GetNewObject(int32 id) {
if(!reloading && object_list.count(id) > 0)
return object_list[id]->Copy();
return object_list[id]->Copy();
else
return 0;
}
/* Signs */
void AddSign(int32 id, Sign* sign){ sign_list[id] = sign; }
Sign* GetSign(int32 id, bool override_loading = false) {
Sign* GetSign(int32 id, bool override_loading = false) {
if((!reloading || override_loading) && sign_list.count(id) > 0)
return sign_list[id];
return sign_list[id];
else
return 0;
}
Sign* GetNewSign(int32 id) {
if(!reloading && sign_list.count(id) > 0)
return sign_list[id]->Copy();
return sign_list[id]->Copy();
else
return 0;
}
@ -1141,7 +1141,7 @@ public:
/* Transporters */
void AddLocationTransporter(int32 zone_id, string message, float trigger_x, float trigger_y, float trigger_z, float trigger_radius, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading, int32 cost, int32 unique_id, bool force_zone);
void AddTransporter(int32 transport_id, int8 type, string name, string message, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading,
void AddTransporter(int32 transport_id, int8 type, string name, string message, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading,
int32 cost, int32 unique_id, int8 min_level, int8 max_level, int32 quest_req, int16 quest_step_req, int32 quest_complete, int32 map_x, int32 map_y, int32 expansion_flag, int32 holiday_flag, int32 min_client_version,
int32 max_client_version, int32 flight_path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color);
void GetTransporters(vector<TransportDestination*>* returnList, Client* client, int32 transport_id);
@ -1165,7 +1165,7 @@ public:
///<summary>Clears the list of transporter maps</summary>
void DeleteTransporterMaps();
void DeleteGlobalSpawns();
void ReloadSpawns();
@ -1187,7 +1187,7 @@ public:
int32 getGroupraidFirstLevel() const {
return groupraidFirstLevel;
}
void setGroupRaidLevels(int32 min_level, int32 max_level, int32 avg_level, int32 first_level) {
groupraidMinLevel = min_level;
groupraidMaxLevel = max_level;

View File

@ -1,15 +0,0 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
#define BASEDIR "./"
#ifndef DB_INI_FILE
#ifdef LOGIN
#define DB_INI_FILE BASEDIR "login_db.ini"
#else
#define DB_INI_FILE BASEDIR "world_db.ini"
#endif
#endif
#ifndef MAIN_CONFIG_FILE
#define MAIN_CONFIG_FILE BASEDIR "server_config.json"
#endif

View File

@ -8,7 +8,7 @@
#include <string>
#include <vector>
#include "xmlParser.h"
#include "Mutex.h"
#include "mutex.h"
using namespace std;
@ -28,8 +28,7 @@ public:
private:
Mutex MStructs;
vector<string> load_files;
map<string, vector<PacketStruct*>*> structs;
map<string, vector<PacketStruct*>*> structs;
//vector<PacketStruct*> structs;
};
#endif

View File

@ -6,7 +6,7 @@
#endif
#include "EQEMuError.h"
#include "linked_list.h"
#include "Mutex.h"
#include "mutex.h"
#include "MiscFunctions.h"
#include <stdio.h>
#include <string.h>
@ -53,7 +53,7 @@ void AddEQEMuError(eEQEMuError iError, bool iExitNow) {
}
iterator.Advance();
}
char* tmp = new char[6];
tmp[0] = 1;
tmp[5] = 0;
@ -110,5 +110,3 @@ void CheckEQEMuErrorAndPause() {
getchar();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@
// Project headers
#include "EQPacket.h"
#include "Mutex.h"
#include "mutex.h"
#include "opcodemgr.h"
#include "misc.h"
#include "crypto/crypto.h"

View File

@ -1,361 +0,0 @@
/*
EQ2Emulator: Everquest II Server Emulator
Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
This file is part of EQ2Emulator.
EQ2Emulator is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
EQ2Emulator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; 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 EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../common/Log.h"
#include "../common/debug.h"
#include "../common/Mutex.h"
Mutex::Mutex() {
readers = 0;
mlocked = false;
writing = false;
name = "";
#ifdef DEBUG
stack.clear();
#endif
//CSLock is a pointer so we can use a different attribute type on create
CSLock = new CriticalSection(MUTEX_ATTRIBUTE_RECURSIVE);
}
Mutex::~Mutex() {
safe_delete(CSLock);
#ifdef DEBUG
stack.clear();
#endif
}
void Mutex::SetName(string in_name) {
#ifdef DEBUG
name = in_name;
#endif
}
void Mutex::lock() {
#ifdef DEBUG
int i = 0;
#endif
if (name.length() > 0) {
while (mlocked) {
#ifdef DEBUG
if (i > MUTEX_TIMEOUT_MILLISECONDS) {
LogWrite(MUTEX__ERROR, 0, "Mutex", "Possible deadlock attempt by '%s'!", name.c_str());
return;
}
i++;
#endif
Sleep(1);
}
}
mlocked = true;
CSLock->lock();
}
bool Mutex::trylock() {
return CSLock->trylock();
}
void Mutex::unlock() {
CSLock->unlock();
mlocked = false;
}
void Mutex::readlock(const char* function, int32 line) {
#ifdef DEBUG
int32 i = 0;
#endif
while (true) {
//Loop until there isn't a writer, then we can read!
CSRead.lock();
if (!writing) {
readers++;
CSRead.unlock();
#ifdef DEBUG
CSStack.lock();
if (function)
stack[(string)function]++;
CSStack.unlock();
#endif
return;
}
CSRead.unlock();
#ifdef DEBUG
if (i > MUTEX_TIMEOUT_MILLISECONDS) {
LogWrite(MUTEX__ERROR, 0, "Mutex", "The mutex %s called from %s at line %u timed out waiting for a readlock!", name.c_str(), function ? function : "name_not_provided", line);
LogWrite(MUTEX__ERROR, 0, "Mutex", "The following functions had locks:");
map<string, int32>::iterator itr;
CSStack.lock();
for (itr = stack.begin(); itr != stack.end(); itr++) {
if (itr->second > 0 && itr->first.length() > 0)
LogWrite(MUTEX__ERROR, 0, "Mutex", "%s, number of locks = %u", itr->first.c_str(), itr->second);
}
CSStack.unlock();
i = 0;
continue;
}
i++;
#endif
Sleep(1);
}
}
void Mutex::releasereadlock(const char* function, int32 line) {
//Wait for the readcount lock
CSRead.lock();
//Lower the readcount by one, when readcount is 0 writers may start writing
readers--;
CSRead.unlock();
#ifdef DEBUG
CSStack.lock();
if (function) {
map<string, int32>::iterator itr = stack.find((string)function);
if (itr != stack.end()) {
if (--(itr->second) == 0) {
stack.erase(itr);
}
}
}
CSStack.unlock();
#endif
}
bool Mutex::tryreadlock(const char* function) {
//This returns true if able to instantly obtain a readlock, false if not
CSRead.lock();
if (!writing) {
readers++;
CSRead.unlock();
}
else {
CSRead.unlock();
return false;
}
#ifdef DEBUG
CSStack.lock();
if (function)
stack[(string)function]++;
CSStack.unlock();
#endif
return true;
}
void Mutex::writelock(const char* function, int32 line) {
//Wait until the writer lock becomes available, then we can be the only writer!
#ifdef DEBUG
int32 i = 0;
#endif
while (!CSWrite.trylock()) {
#ifdef DEBUG
if (i > MUTEX_TIMEOUT_MILLISECONDS) {
LogWrite(MUTEX__ERROR, 0, "Mutex", "The mutex %s called from %s at line %u timed out waiting on another writelock!", name.c_str(), function ? function : "name_not_provided", line);
LogWrite(MUTEX__ERROR, 0, "Mutex", "The following functions had locks:");
map<string, int32>::iterator itr;
CSStack.lock();
for (itr = stack.begin(); itr != stack.end(); itr++) {
if (itr->second > 0 && itr->first.length() > 0)
LogWrite(MUTEX__ERROR, 0, "Mutex", "%s, number of locks = %u", itr->first.c_str(), itr->second);
}
CSStack.unlock();
i = 0;
continue;
}
i++;
#endif
Sleep(1);
}
waitReaders(function, line);
#ifdef DEBUG
CSStack.lock();
if (function)
stack[(string)function]++;
CSStack.unlock();
#endif
}
void Mutex::releasewritelock(const char* function, int32 line) {
//Wait for the readcount lock
CSRead.lock();
//Readers are aloud again
writing = false;
CSRead.unlock();
//Allow other writers to write
CSWrite.unlock();
#ifdef DEBUG
CSStack.lock();
if (function) {
map<string, int32>::iterator itr = stack.find((string)function);
if (itr != stack.end()) {
if (--(itr->second) == 0) {
stack.erase(itr);
}
}
}
CSStack.unlock();
#endif
}
bool Mutex::trywritelock(const char* function) {
//This returns true if able to instantly obtain a writelock, false if not
if (CSWrite.trylock()) {
CSRead.lock();
if (readers == 0)
writing = true;
CSRead.unlock();
if (!writing) {
CSWrite.unlock();
return false;
}
}
else
return false;
#ifdef DEBUG
CSStack.lock();
if (function)
stack[(string)function]++;
CSStack.unlock();
#endif
return true;
}
void Mutex::waitReaders(const char* function, int32 line)
{
//Wait for all current readers to stop, then we can write!
#ifdef DEBUG
int32 i = 0;
#endif
while (true)
{
CSRead.lock();
if (readers == 0)
{
writing = true;
CSRead.unlock();
break;
}
CSRead.unlock();
#ifdef DEBUG
if (i > MUTEX_TIMEOUT_MILLISECONDS) {
LogWrite(MUTEX__ERROR, 0, "Mutex", "The mutex %s called from %s at line %u timed out while waiting on readers!", name.c_str(), function ? function : "name_not_provided", line);
LogWrite(MUTEX__ERROR, 0, "Mutex", "The following functions had locks:");
map<string, int32>::iterator itr;
CSStack.lock();
for (itr = stack.begin(); itr != stack.end(); itr++) {
if (itr->second > 0 && itr->first.length() > 0)
LogWrite(MUTEX__ERROR, 0, "Mutex", "%s, number of locks = %u", itr->first.c_str(), itr->second);
}
CSStack.unlock();
i = 0;
continue;
}
i++;
#endif
Sleep(1);
}
}
LockMutex::LockMutex(Mutex* in_mut, bool iLock) {
mut = in_mut;
locked = iLock;
if (locked) {
mut->lock();
}
}
LockMutex::~LockMutex() {
if (locked) {
mut->unlock();
}
}
void LockMutex::unlock() {
if (locked)
mut->unlock();
locked = false;
}
void LockMutex::lock() {
if (!locked)
mut->lock();
locked = true;
}
CriticalSection::CriticalSection(int attribute) {
#ifdef WIN32
InitializeCriticalSection(&CSMutex);
#else
pthread_mutexattr_init(&type_attribute);
switch (attribute)
{
case MUTEX_ATTRIBUTE_FAST:
pthread_mutexattr_settype(&type_attribute, PTHREAD_MUTEX_FAST_NP);
break;
case MUTEX_ATTRIBUTE_RECURSIVE:
pthread_mutexattr_settype(&type_attribute, PTHREAD_MUTEX_RECURSIVE_NP);
break;
case MUTEX_ATTRIBUTE_ERRORCHK:
pthread_mutexattr_settype(&type_attribute, PTHREAD_MUTEX_ERRORCHECK_NP);
break;
default:
LogWrite(MUTEX__DEBUG, 0, "Critical Section", "Invalid mutex attribute type! Using PTHREAD_MUTEX_FAST_NP");
pthread_mutexattr_settype(&type_attribute, PTHREAD_MUTEX_FAST_NP);
break;
}
pthread_mutex_init(&CSMutex, &type_attribute);
#endif
}
CriticalSection::~CriticalSection() {
#ifdef WIN32
DeleteCriticalSection(&CSMutex);
#else
pthread_mutex_destroy(&CSMutex);
pthread_mutexattr_destroy(&type_attribute);
#endif
}
void CriticalSection::lock() {
//Waits for a lock on this critical section
#ifdef WIN32
EnterCriticalSection(&CSMutex);
#else
pthread_mutex_lock(&CSMutex);
#endif
}
void CriticalSection::unlock() {
//Gets rid of one of the current thread's locks on this critical section
#ifdef WIN32
LeaveCriticalSection(&CSMutex);
#else
pthread_mutex_unlock(&CSMutex);
#endif
}
bool CriticalSection::trylock() {
//Returns true if able to instantly get a lock on this critical section, false if not
#ifdef WIN32
return TryEnterCriticalSection(&CSMutex);
#else
return (pthread_mutex_trylock(&CSMutex) == 0);
#endif
}

View File

@ -1,86 +0,0 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
#ifndef MYMUTEX_H
#define MYMUTEX_H
#ifdef WIN32
#include <WinSock2.h>
#include <windows.h>
#else
#include <pthread.h>
#include "../common/unix.h"
#endif
#include "../common/types.h"
#include <string>
#include <map>
#define MUTEX_ATTRIBUTE_FAST 1
#define MUTEX_ATTRIBUTE_RECURSIVE 2
#define MUTEX_ATTRIBUTE_ERRORCHK 3
#define MUTEX_TIMEOUT_MILLISECONDS 10000
class CriticalSection {
public:
CriticalSection(int attribute = MUTEX_ATTRIBUTE_FAST);
~CriticalSection();
void lock();
void unlock();
bool trylock();
private:
#ifdef WIN32
CRITICAL_SECTION CSMutex;
#else
pthread_mutex_t CSMutex;
pthread_mutexattr_t type_attribute;
#endif
};
class Mutex {
public:
Mutex();
~Mutex();
void lock();
void unlock();
bool trylock();
void readlock(const char* function = 0, int32 line = 0);
void releasereadlock(const char* function = 0, int32 line = 0);
bool tryreadlock(const char* function = 0);
void writelock(const char* function = 0, int32 line = 0);
void releasewritelock(const char* function = 0, int32 line = 0);
bool trywritelock(const char* function = 0);
void waitReaders(const char* function = 0, int32 line = 0);
void SetName(string in_name);
private:
CriticalSection CSRead;
CriticalSection CSWrite;
CriticalSection* CSLock;
#ifdef DEBUG //Used for debugging only
CriticalSection CSStack;
map<string, int32> stack;
#endif
int readers;
bool writing;
volatile bool mlocked;
string name;
};
class LockMutex {
public:
LockMutex(Mutex* in_mut, bool iLock = true);
~LockMutex();
void unlock();
void lock();
private:
bool locked;
Mutex* mut;
};
#endif

View File

@ -30,7 +30,7 @@
#endif
#include "types.h"
#include "Mutex.h"
#include "mutex.h"
#include "linked_list.h"
#include "queue.h"
#include "servertalk.h"
@ -139,7 +139,7 @@ protected:
bool GetAsyncConnect();
bool SetAsyncConnect(bool iValue);
char* charAsyncConnect;
#ifdef WIN32
friend class TCPConnection;
#endif

View File

@ -14,7 +14,7 @@
#include "linked_list.h"
#include "EQStream.h"
#include "MiscFunctions.h"
#include "Mutex.h"
#include "mutex.h"
#include <string>
#include <vector>
#include <map>
@ -46,7 +46,7 @@ public:
void AddActiveQuery(Query* query);
bool IsActiveQuery(int32 id, Query* skip=0);
void PingAsyncDatabase();
void AddPeerActiveQuery(int32 charID);
void RemovePeerActiveQuery(int32 charID);
#endif
@ -138,7 +138,7 @@ public:
*row = mysql_fetch_row(result);
if(row && result && field_num < mysql_num_fields(result))
return *row[field_num];
else
else
return NULL;
}
void NextRow(){

View File

@ -10,7 +10,7 @@
#endif
#include <mysql.h>
#include "../common/types.h"
#include "../common/Mutex.h"
#include "../common/mutex.h"
#include "../common/linked_list.h"
#include "../common/queue.h"
#include "../common/timer.h"
@ -38,7 +38,7 @@ public:
char* getEscapeString(const char* from_string);
string getSafeEscapeString(const char* from_string);
string getSafeEscapeString(string* from_string);
protected:
bool Open(const char* iHost, const char* iUser, const char* iPassword, const char* iDatabase, int32 iPort, int32* errnum = 0, char* errbuf = 0, bool iCompress = false, bool iSSL = false);
bool ReadDBINI(char *host, char *user, char *pass, char *db, unsigned int* port, bool* compress, bool *items);
@ -48,7 +48,7 @@ private:
MYSQL mysql;
Mutex MDatabase;
eStatus pStatus;
char* pHost;
char* pUser;
char* pPassword;
@ -58,5 +58,3 @@ private:
bool pSSL;
};
#endif

View File

@ -1,319 +0,0 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
/*
JA: File rendered obsolete (2011-08-12)
#include "debug.h"
#include <iostream>
using namespace std;
#include <time.h>
#include <string.h>
#ifdef WIN32
#include <process.h>
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#else
#include <sys/types.h>
#include <unistd.h>
#include <stdarg.h>
#endif
#include "../common/MiscFunctions.h"
EQEMuLog* LogFile = new EQEMuLog;
AutoDelete<EQEMuLog> adlf(&LogFile);
static const char* FileNames[EQEMuLog::MaxLogID] = { "logs/eq2emu", "logs/eq2emu", "logs/eq2emu_error", "logs/eq2emu_debug", "logs/eq2emu_quest", "logs/eq2emu_commands" };
static const char* LogNames[EQEMuLog::MaxLogID] = { "Status", "Normal", "Error", "Debug", "Quest", "Command" };
EQEMuLog::EQEMuLog() {
for (int i=0; i<MaxLogID; i++) {
fp[i] = 0;
#if EQDEBUG >= 2
pLogStatus[i] = 1 | 2;
#else
pLogStatus[i] = 0;
#endif
logCallbackFmt[i] = NULL;
logCallbackBuf[i] = NULL;
}
#if EQDEBUG < 2
pLogStatus[Status] = 3;
pLogStatus[Error] = 3;
pLogStatus[Debug] = 3;
pLogStatus[Quest] = 2;
pLogStatus[Commands] = 2;
#endif
}
EQEMuLog::~EQEMuLog() {
for (int i=0; i<MaxLogID; i++) {
if (fp[i])
fclose(fp[i]);
}
}
bool EQEMuLog::open(LogIDs id) {
if (id >= MaxLogID) {
return false;
}
LockMutex lock(&MOpen);
if (pLogStatus[id] & 4) {
return false;
}
if (fp[id]) {
return true;
}
char exename[200] = "";
#if defined(WORLD)
snprintf(exename, sizeof(exename), "_world");
#elif defined(ZONE)
snprintf(exename, sizeof(exename), "_zone");
#endif
char filename[200];
#ifndef NO_PIDLOG
snprintf(filename, sizeof(filename), "%s%s_%04i.log", FileNames[id], exename, getpid());
#else
snprintf(filename, sizeof(filename), "%s%s.log", FileNames[id], exename);
#endif
fp[id] = fopen(filename, "a");
if (!fp[id]) {
cerr << "Failed to open log file: " << filename << endl;
pLogStatus[id] |= 4; // set file state to error
return false;
}
fputs("---------------------------------------------\n",fp[id]);
return true;
}
bool EQEMuLog::write(LogIDs id, const char *fmt, ...) {
char buffer[4096];
if (!this) {
return false;
}
if (id >= MaxLogID) {
return false;
}
bool dofile = false;
if (pLogStatus[id] & 1) {
dofile = open(id);
}
if (!(dofile || pLogStatus[id] & 2))
return false;
LockMutex lock(&MLog[id]);
time_t aclock;
struct tm *newtime;
time( &aclock ); //Get time in seconds
newtime = localtime( &aclock ); //Convert time to struct
if (dofile){
#ifndef NO_PIDLOG
fprintf(fp[id], "[%04d%02d%02d %02d:%02d:%02d] ", newtime->tm_year+1900, newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
#else
fprintf(fp[id], "%04i [%04d%02d%02d %02d:%02d:%02d] ", getpid(), newtime->tm_year+1900, newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
#endif
}
va_list argptr;
va_start(argptr, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, argptr);
va_end(argptr);
if (dofile)
fprintf(fp[id], "%s\n", buffer);
if(logCallbackFmt[id]) {
msgCallbackFmt p = logCallbackFmt[id];
p(id, fmt, argptr );
}
if (pLogStatus[id] & 2) {
if (pLogStatus[id] & 8) {
fprintf(stderr, "[%04d%02d%02d %02d:%02d:%02d] [%s] ", newtime->tm_year+1900, newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec, LogNames[id]);
fprintf(stderr, "%s\n", buffer);
}
else {
fprintf(stdout, "[%04d%02d%02d %02d:%02d:%02d] [%s] ", newtime->tm_year+1900, newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec, LogNames[id]);
fprintf(stdout, "%s\n", buffer);
}
}
if (dofile)
fprintf(fp[id], "\n");
if (pLogStatus[id] & 2) {
if (pLogStatus[id] & 8)
fprintf(stderr, "\n");
else
fprintf(stdout, "\n");
}
if(dofile)
fflush(fp[id]);
return true;
}
bool EQEMuLog::writebuf(LogIDs id, const char *buf, int8 size, int32 count) {
if (!this) {
return false;
}
if (id >= MaxLogID) {
return false;
}
bool dofile = false;
if (pLogStatus[id] & 1) {
dofile = open(id);
}
if (!(dofile || pLogStatus[id] & 2))
return false;
LockMutex lock(&MLog[id]);
time_t aclock;
struct tm *newtime;
time( &aclock ); // Get time in seconds
newtime = localtime( &aclock ); // Convert time to struct
if (dofile){
#ifndef NO_PIDLOG
fprintf(fp[id], "[%02d.%02d. - %02d:%02d:%02d] ", newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
#else
fprintf(fp[id], "%04i [%02d.%02d. - %02d:%02d:%02d] ", getpid(), newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
#endif
}
if (dofile) {
fwrite(buf, size, count, fp[id]);
fprintf(fp[id], "\n");
}
if(logCallbackBuf[id]) {
msgCallbackBuf p = logCallbackBuf[id];
p(id, buf, size, count);
}
if (pLogStatus[id] & 2) {
if (pLogStatus[id] & 8) {
fprintf(stderr, "[%s] ", LogNames[id]);
fwrite(buf, size, count, stderr);
fprintf(stderr, "\n");
} else {
fprintf(stdout, "[%s] ", LogNames[id]);
fwrite(buf, size, count, stdout);
fprintf(stdout, "\n");
}
}
if(dofile)
fflush(fp[id]);
return true;
}
bool EQEMuLog::writeNTS(LogIDs id, bool dofile, const char *fmt, ...) {
char buffer[4096];
va_list argptr;
va_start(argptr, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, argptr);
va_end(argptr);
if (dofile)
fprintf(fp[id], "%s\n", buffer);
if (pLogStatus[id] & 2) {
if (pLogStatus[id] & 8)
fprintf(stderr, "%s\n", buffer);
else
fprintf(stdout, "%s\n", buffer);
}
return true;
};
bool EQEMuLog::Dump(LogIDs id, int8* data, int32 size, int32 cols, int32 skip) {
if (!this) {
#if EQDEBUG >= 10
cerr << "Error: Dump() from null pointer"<<endl;
#endif
return false;
}
if (size == 0)
return true;
if (!LogFile)
return false;
if (id >= MaxLogID)
return false;
bool dofile = false;
if (pLogStatus[id] & 1) {
dofile = open(id);
}
if (!(dofile || pLogStatus[id] & 2))
return false;
LockMutex lock(&MLog[id]);
write(id, "Dumping Packet: %i", size);
// Output as HEX
int j = 0; char* ascii = new char[cols+1]; memset(ascii, 0, cols+1);
int32 i;
for(i=skip; i<size; i++) {
if ((i-skip)%cols==0) {
if (i != skip)
writeNTS(id, dofile, " | %s\n", ascii);
writeNTS(id, dofile, "%4i: ", i-skip);
memset(ascii, 0, cols+1);
j = 0;
}
else if ((i-skip)%(cols/2) == 0) {
writeNTS(id, dofile, "- ");
}
writeNTS(id, dofile, "%02X ", (unsigned char)data[i]);
if (data[i] >= 32 && data[i] < 127)
ascii[j++] = data[i];
else
ascii[j++] = '.';
}
int32 k = ((i-skip)-1)%cols;
if (k < 8)
writeNTS(id, dofile, " ");
for (int32 h = k+1; h < cols; h++) {
writeNTS(id, dofile, " ");
}
writeNTS(id, dofile, " | %s\n", ascii);
if (dofile)
fflush(fp[id]);
safe_delete_array(ascii);
return true;
}
void EQEMuLog::SetCallback(LogIDs id, msgCallbackFmt proc) {
if (!this)
return;
if (id >= MaxLogID) {
return;
}
logCallbackFmt[id] = proc;
}
void EQEMuLog::SetCallback(LogIDs id, msgCallbackBuf proc) {
if (!this)
return;
if (id >= MaxLogID) {
return;
}
logCallbackBuf[id] = proc;
}
void EQEMuLog::SetAllCallbacks(msgCallbackFmt proc) {
if (!this)
return;
int r;
for(r = Status; r < MaxLogID; r++) {
SetCallback((LogIDs)r, proc);
}
}
void EQEMuLog::SetAllCallbacks(msgCallbackBuf proc) {
if (!this)
return;
int r;
for(r = Status; r < MaxLogID; r++) {
SetCallback((LogIDs)r, proc);
}
}
*/

View File

@ -1,7 +1,13 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
#ifndef EQDEBUG_H
#define EQDEBUG_H
#pragma once
#include <cstdio>
#include <cstdarg>
#include <cstdint>
#include <iostream>
#include <mutex>
// Debug Levels
/*
@ -16,55 +22,33 @@
#define EQDEBUG 1
#endif
#if defined(DEBUG) && defined(WIN32)
//#ifndef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#if (_MSC_VER < 1300)
#include <new>
#include <memory>
#define _CRTDBG_MAP_ALLOC
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
#endif
//#endif
#endif
#ifndef ThrowError
void CatchSignal(int);
#if defined(CATCH_CRASH) || defined(_EQDEBUG)
#define ThrowError(errstr) { cout << "Fatal error: " << errstr << " (" << __FILE__ << ", line " << __LINE__ << ")" << endl; LogWrite(WORLD__ERROR, 0, "Debug", "Thrown Error: %s (%s:%i)", errstr, __FILE__, __LINE__); throw errstr; }
#define ThrowError(errstr) { \
std::cout << "Fatal error: " << errstr << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl; \
LogWrite(WORLD__ERROR, 0, "Debug", "Thrown Error: %s (%s:%i)", errstr, __FILE__, __LINE__); \
throw errstr; \
}
#else
#define ThrowError(errstr) { cout << "Fatal error: " << errstr << " (" << __FILE__ << ", line " << __LINE__ << ")" << endl; LogWrite(WORLD__ERROR, 0, "Debug", "Thrown Error: %s (%s:%i)", errstr, __FILE__, __LINE__); CatchSignal(0); }
#define ThrowError(errstr) { \
std::cout << "Fatal error: " << errstr << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl; \
LogWrite(WORLD__ERROR, 0, "Debug", "Thrown Error: %s (%s:%i)", errstr, __FILE__, __LINE__); \
CatchSignal(0); \
}
#endif
#endif
#ifdef WIN32
// VS6 doesn't like the length of STL generated names: disabling
#pragma warning(disable:4786)
#endif
#define DebugBreak() if(0) {}
#ifndef WIN32
#define DebugBreak() if(0) {}
#endif
#ifdef WIN32
#include <WinSock2.h>
#include <windows.h>
#endif
#include "../common/Mutex.h"
#include <stdio.h>
#include <stdarg.h>
class EQEMuLog {
class EQEMuLog
{
public:
EQEMuLog();
~EQEMuLog();
enum LogIDs {
enum LogIDs
{
Status = 0, //this must stay the first entry in this list
Normal,
Error,
@ -73,54 +57,58 @@ public:
Commands,
MaxLogID
};
//these are callbacks called for each
typedef void (* msgCallbackBuf)(LogIDs id, const char *buf, int8 size, int32 count);
typedef void (* msgCallbackFmt)(LogIDs id, const char *fmt, va_list ap);
// Callbacks called for each log entry
using msgCallbackBuf = void (*)(LogIDs id, const char* buf, std::int8_t size, std::int32_t count);
using msgCallbackFmt = void (*)(LogIDs id, const char* fmt, va_list ap);
void SetAllCallbacks(msgCallbackFmt proc);
void SetAllCallbacks(msgCallbackBuf proc);
void SetCallback(LogIDs id, msgCallbackFmt proc);
void SetCallback(LogIDs id, msgCallbackBuf proc);
bool writebuf(LogIDs id, const char *buf, int8 size, int32 count);
bool write(LogIDs id, const char *fmt, ...);
bool Dump(LogIDs id, int8* data, int32 size, int32 cols=16, int32 skip=0);
bool writebuf(LogIDs id, const char* buf, std::int8_t size, std::int32_t count);
bool write(LogIDs id, const char* fmt, ...);
bool Dump(LogIDs id, std::uint8_t* data, std::int32_t size, std::int32_t cols = 16, std::int32_t skip = 0);
private:
bool open(LogIDs id);
bool writeNTS(LogIDs id, bool dofile, const char *fmt, ...); // no error checking, assumes is open, no locking, no timestamp, no newline
bool writeNTS(LogIDs id, bool dofile, const char* fmt, ...); // no error checking, assumes is open, no locking, no timestamp, no newline
std::mutex MOpen;
std::mutex MLog[MaxLogID];
FILE* fp[MaxLogID];
/* LogStatus: bitwise variable
1 = output to file
2 = output to stdout
4 = fopen error, dont retry
8 = use stderr instead (2 must be set)
*/
std::int8_t pLogStatus[MaxLogID];
Mutex MOpen;
Mutex MLog[MaxLogID];
FILE* fp[MaxLogID];
/* LogStatus: bitwise variable
1 = output to file
2 = output to stdout
4 = fopen error, dont retry
8 = use stderr instead (2 must be set)
*/
int8 pLogStatus[MaxLogID];
msgCallbackFmt logCallbackFmt[MaxLogID];
msgCallbackBuf logCallbackBuf[MaxLogID];
};
//extern EQEMuLog* LogFile;
#ifdef _EQDEBUG
class PerformanceMonitor {
class PerformanceMonitor
{
public:
PerformanceMonitor(sint64* ip) {
PerformanceMonitor(std::int64_t* ip)
{
p = ip;
QueryPerformanceCounter(&tmp);
}
~PerformanceMonitor() {
~PerformanceMonitor()
{
LARGE_INTEGER tmp2;
QueryPerformanceCounter(&tmp2);
*p += tmp2.QuadPart - tmp.QuadPart;
}
LARGE_INTEGER tmp;
sint64* p;
std::int64_t* p;
};
#endif
#endif

16
source/common/defines.h Normal file
View File

@ -0,0 +1,16 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
#define BASEDIR "./"
#ifndef DB_INI_FILE
#ifdef LOGIN
#define DB_INI_FILE BASEDIR "login_db.ini"
#else
#define DB_INI_FILE BASEDIR "world_db.ini"
#endif
#endif
#ifndef MAIN_CONFIG_FILE
#define MAIN_CONFIG_FILE BASEDIR "server_config.json"
#endif

238
source/common/mutex.cpp Normal file
View File

@ -0,0 +1,238 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
#include "mutex.h"
// CriticalSection implementation
CriticalSection::CriticalSection(int attribute) : mutex_type(attribute)
{
if (mutex_type == MUTEX_ATTRIBUTE_RECURSIVE) {
recursive_mutex = std::make_unique<std::recursive_mutex>();
} else {
regular_mutex = std::make_unique<std::mutex>();
}
}
void CriticalSection::lock()
{
if (recursive_mutex) {
recursive_mutex->lock();
} else {
regular_mutex->lock();
}
}
void CriticalSection::unlock()
{
if (recursive_mutex) {
recursive_mutex->unlock();
} else {
regular_mutex->unlock();
}
}
bool CriticalSection::trylock()
{
if (recursive_mutex) {
return recursive_mutex->try_lock();
} else {
return regular_mutex->try_lock();
}
}
// Mutex implementation
Mutex::Mutex() : name("")
{
#ifdef DEBUG
stack.clear();
#endif
}
void Mutex::SetName(std::string in_name)
{
name = in_name;
}
void Mutex::lock()
{
#ifdef DEBUG
if (!name.empty()) {
auto start = std::chrono::steady_clock::now();
while (!basic_mutex.try_lock()) {
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start).count();
if (elapsed > MUTEX_TIMEOUT_MILLISECONDS) {
LogWrite(MUTEX__ERROR, 0, "Mutex", "Possible deadlock attempt by '%s'!", name.c_str());
return;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
} else {
basic_mutex.lock();
}
#else
basic_mutex.lock();
#endif
}
bool Mutex::trylock()
{
return basic_mutex.try_lock();
}
void Mutex::unlock()
{
basic_mutex.unlock();
}
void Mutex::readlock([[maybe_unused]] const char* function, [[maybe_unused]] std::int32_t line)
{
#ifdef DEBUG
auto start = std::chrono::steady_clock::now();
while (!rw_mutex.try_lock_shared()) {
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start).count();
if (elapsed > MUTEX_TIMEOUT_MILLISECONDS) {
logDeadlock(function, line, "readlock");
start = std::chrono::steady_clock::now(); // Reset timer and continue
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
addDebugLock(function);
#else
rw_mutex.lock_shared();
#endif
}
void Mutex::releasereadlock([[maybe_unused]] const char* function, [[maybe_unused]] std::int32_t line)
{
rw_mutex.unlock_shared();
#ifdef DEBUG
removeDebugLock(function);
#endif
}
bool Mutex::tryreadlock([[maybe_unused]] const char* function)
{
bool result = rw_mutex.try_lock_shared();
#ifdef DEBUG
if (result && function) {
addDebugLock(function);
}
#endif
return result;
}
void Mutex::writelock([[maybe_unused]] const char* function, [[maybe_unused]] std::int32_t line)
{
#ifdef DEBUG
auto start = std::chrono::steady_clock::now();
while (!rw_mutex.try_lock()) {
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start).count();
if (elapsed > MUTEX_TIMEOUT_MILLISECONDS) {
logDeadlock(function, line, "writelock");
start = std::chrono::steady_clock::now(); // Reset timer and continue
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
addDebugLock(function);
#else
rw_mutex.lock();
#endif
}
void Mutex::releasewritelock([[maybe_unused]] const char* function, [[maybe_unused]] std::int32_t line)
{
rw_mutex.unlock();
#ifdef DEBUG
removeDebugLock(function);
#endif
}
bool Mutex::trywritelock([[maybe_unused]] const char* function)
{
bool result = rw_mutex.try_lock();
#ifdef DEBUG
if (result && function) {
addDebugLock(function);
}
#endif
return result;
}
void Mutex::waitReaders(const char* function, std::int32_t line)
{
// Wait until we can get a write lock (which means no readers)
writelock(function, line);
releasewritelock(function, line);
}
#ifdef DEBUG
void Mutex::addDebugLock(const char* function)
{
if (function) {
std::lock_guard<std::mutex> guard(debug_mutex);
stack[std::string(function)]++;
}
}
void Mutex::removeDebugLock(const char* function)
{
if (function) {
std::lock_guard<std::mutex> guard(debug_mutex);
auto itr = stack.find(std::string(function));
if (itr != stack.end()) {
if (--(itr->second) == 0) {
stack.erase(itr);
}
}
}
}
void Mutex::logDeadlock(const char* function, std::int32_t line, const char* lock_type)
{
LogWrite(MUTEX__ERROR, 0, "Mutex", "The mutex %s called from %s at line %u timed out waiting for a %s!",
name.c_str(), function ? function : "name_not_provided", line, lock_type);
LogWrite(MUTEX__ERROR, 0, "Mutex", "The following functions had locks:");
std::lock_guard<std::mutex> guard(debug_mutex);
for (const auto& [func_name, count] : stack) {
if (count > 0 && !func_name.empty()) {
LogWrite(MUTEX__ERROR, 0, "Mutex", "%s, number of locks = %u", func_name.c_str(), count);
}
}
}
#endif
// LockMutex implementation
LockMutex::LockMutex(Mutex* in_mut, bool iLock)
: locked(false), mut(in_mut)
{
if (mut && iLock) {
lock();
}
}
LockMutex::~LockMutex()
{
if (locked) {
unlock();
}
}
void LockMutex::lock()
{
if (mut && !locked) {
mut->lock();
locked = true;
}
}
void LockMutex::unlock()
{
if (mut && locked) {
mut->unlock();
locked = false;
}
}

83
source/common/mutex.h Normal file
View File

@ -0,0 +1,83 @@
// Copyright (C) 2007-2025 EQ2EMulator
// Licensed under GPL v3
#pragma once
#include <shared_mutex>
#include <mutex>
#include <string>
#include <map>
#include <cstdint>
#include <memory>
#include <chrono>
#define MUTEX_ATTRIBUTE_FAST 1
#define MUTEX_ATTRIBUTE_RECURSIVE 2
#define MUTEX_ATTRIBUTE_ERRORCHK 3
#define MUTEX_TIMEOUT_MILLISECONDS 10000
class CriticalSection
{
public:
CriticalSection(int attribute = MUTEX_ATTRIBUTE_FAST);
~CriticalSection() = default;
void lock();
void unlock();
bool trylock();
private:
std::unique_ptr<std::mutex> regular_mutex;
std::unique_ptr<std::recursive_mutex> recursive_mutex;
int mutex_type;
};
class Mutex
{
public:
Mutex();
~Mutex() = default;
void lock();
void unlock();
bool trylock();
void readlock(const char* function = nullptr, std::int32_t line = 0);
void releasereadlock(const char* function = nullptr, std::int32_t line = 0);
bool tryreadlock(const char* function = nullptr);
void writelock(const char* function = nullptr, std::int32_t line = 0);
void releasewritelock(const char* function = nullptr, std::int32_t line = 0);
bool trywritelock(const char* function = nullptr);
void waitReaders(const char* function = nullptr, std::int32_t line = 0);
void SetName(std::string in_name);
private:
std::shared_mutex rw_mutex;
std::mutex basic_mutex;
std::string name;
#ifdef DEBUG
std::mutex debug_mutex;
std::map<std::string, std::int32_t> stack;
void addDebugLock(const char* function);
void removeDebugLock(const char* function);
void logDeadlock(const char* function, std::int32_t line, const char* lock_type);
#endif
};
class LockMutex
{
public:
LockMutex(Mutex* in_mut, bool iLock = true);
~LockMutex();
void unlock();
void lock();
private:
bool locked;
Mutex* mut;
};

View File

@ -4,7 +4,7 @@
#define OPCODE_MANAGER_H
#include "types.h"
#include "Mutex.h"
#include "mutex.h"
#include "emu_opcodes.h"
#include <map>
@ -14,19 +14,19 @@ class OpcodeManager {
public:
OpcodeManager();
virtual ~OpcodeManager() {}
virtual bool Mutable() { return(false); }
virtual bool LoadOpcodes(const char *filename) = 0;
virtual bool LoadOpcodes(map<string, uint16>* eq, std::string* missingOpcodes = nullptr) = 0;
virtual bool ReloadOpcodes(const char *filename) = 0;
virtual uint16 EmuToEQ(const EmuOpcode emu_op) = 0;
virtual EmuOpcode EQToEmu(const uint16 eq_op) = 0;
static const char *EmuToName(const EmuOpcode emu_op);
const char *EQToName(const uint16 emu_op);
EmuOpcode NameSearch(const char *name);
//This has to be public for stupid visual studio
class OpcodeSetStrategy {
public:
@ -38,7 +38,7 @@ protected:
bool loaded; //true if all opcodes loaded
Mutex MOpcodes; //this only protects the local machine
//in a shared manager, this dosent protect others
static bool LoadOpcodesFile(const char *filename, OpcodeSetStrategy *s);
static bool LoadOpcodesMap(map<string, uint16>* eq, OpcodeSetStrategy *s, std::string* missingOpcodes = nullptr);
};
@ -55,14 +55,14 @@ public:
class SharedOpcodeManager : public OpcodeManager {
public:
virtual ~SharedOpcodeManager() {}
virtual bool LoadOpcodes(const char *filename);
virtual bool LoadOpcodes(map<string, uint16>* eq, std::string* missingOpcodes = nullptr);
virtual bool ReloadOpcodes(const char *filename);
virtual uint16 EmuToEQ(const EmuOpcode emu_op);
virtual EmuOpcode EQToEmu(const uint16 eq_op);
protected:
class SharedMemStrategy : public OpcodeManager::OpcodeSetStrategy {
public:
@ -77,18 +77,18 @@ class RegularOpcodeManager : public MutableOpcodeManager {
public:
RegularOpcodeManager();
virtual ~RegularOpcodeManager();
virtual bool Editable() { return(true); }
virtual bool LoadOpcodes(const char *filename);
virtual bool LoadOpcodes(map<string, uint16>* eq, std::string* missingOpcodes = nullptr);
virtual bool ReloadOpcodes(const char *filename);
virtual uint16 EmuToEQ(const EmuOpcode emu_op);
virtual EmuOpcode EQToEmu(const uint16 eq_op);
//implement our editing interface
virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op);
protected:
class NormalMemStrategy : public OpcodeManager::OpcodeSetStrategy {
public:
@ -96,7 +96,7 @@ protected:
void Set(EmuOpcode emu_op, uint16 eq_op);
};
friend class NormalMemStrategy;
uint16 *emu_to_eq;
EmuOpcode *eq_to_emu;
uint32 EQOpcodeCount;
@ -107,14 +107,14 @@ protected:
class NullOpcodeManager : public MutableOpcodeManager {
public:
NullOpcodeManager();
virtual bool LoadOpcodes(const char *filename);
virtual bool LoadOpcodes(map<string, uint16>* eq, std::string* missingOpcodes = nullptr);
virtual bool ReloadOpcodes(const char *filename);
virtual uint16 EmuToEQ(const EmuOpcode emu_op);
virtual EmuOpcode EQToEmu(const uint16 eq_op);
//fake it, just used for testing anyways
virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op) {}
};
@ -125,14 +125,14 @@ public:
class EmptyOpcodeManager : public MutableOpcodeManager {
public:
EmptyOpcodeManager();
virtual bool LoadOpcodes(const char *filename);
virtual bool LoadOpcodes(map<string, uint16>* eq, std::string* missingOpcodes = nullptr);
virtual bool ReloadOpcodes(const char *filename);
virtual uint16 EmuToEQ(const EmuOpcode emu_op);
virtual EmuOpcode EQToEmu(const uint16 eq_op);
//fake it, just used for testing anyways
virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op);
protected:
@ -141,5 +141,3 @@ protected:
};
#endif