World.cpp 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <assert.h>
  17. #include "World.h"
  18. #include "Items/Items.h"
  19. #include "Items/Items_ToV.h"
  20. #include "Items/Items_DoV.h"
  21. #include "Spells.h"
  22. #include "client.h"
  23. #include "WorldDatabase.h"
  24. #include "../common/debug.h"
  25. #include "races.h"
  26. #include "classes.h"
  27. #include "VisualStates.h"
  28. #include "Appearances.h"
  29. #include "Skills.h"
  30. #include "LoginServer.h"
  31. #include "Quests.h"
  32. #include "Factions.h"
  33. #include "Guilds/Guild.h"
  34. #include "Collections/Collections.h"
  35. #include "Achievements/Achievements.h"
  36. #include "Recipes/Recipe.h"
  37. #include "Rules/Rules.h"
  38. #include "IRC/IRC.h"
  39. #include "../common/Log.h"
  40. #include "Traits/Traits.h"
  41. #include "Chat/Chat.h"
  42. #include "Tradeskills/Tradeskills.h"
  43. #include "AltAdvancement/AltAdvancement.h"
  44. #include "LuaInterface.h"
  45. #include "HeroicOp/HeroicOp.h"
  46. #include "RaceTypes/RaceTypes.h"
  47. MasterQuestList master_quest_list;
  48. MasterItemList master_item_list;
  49. MasterSpellList master_spell_list;
  50. MasterTraitList master_trait_list;
  51. MasterHeroicOPList master_ho_list;
  52. MasterSkillList master_skill_list;
  53. MasterFactionList master_faction_list;
  54. MasterCollectionList master_collection_list;
  55. MasterAchievementList master_achievement_list;
  56. MasterRecipeList master_recipe_list;
  57. MasterRecipeBookList master_recipebook_list;
  58. MasterTradeskillEventsList master_tradeskillevent_list;
  59. MasterAAList master_aa_list;
  60. MasterRaceTypeList race_types_list;
  61. MasterAANodeList master_tree_nodes;
  62. ClientList client_list;
  63. ZoneList zone_list;
  64. ZoneAuth zone_auth;
  65. int32 Spawn::next_id = 1;
  66. int32 WorldDatabase::next_id = 0;
  67. Commands commands;
  68. Variables variables;
  69. VisualStates visual_states;
  70. Appearances master_appearance_list;
  71. Classes classes;
  72. Races races;
  73. map<int16,OpcodeManager*>EQOpcodeManager;
  74. map<int16, int16> EQOpcodeVersions;
  75. WorldDatabase database;
  76. GuildList guild_list;
  77. IRC irc;
  78. Chat chat;
  79. extern ConfigReader configReader;
  80. extern LoginServer loginserver;
  81. extern World world;
  82. extern RuleManager rule_manager;
  83. World::World() : save_time_timer(300000), time_tick_timer(3000), vitality_timer(3600000), player_stats_timer(60000), server_stats_timer(60000), /*remove_grouped_player(30000),*/ guilds_timer(60000), lotto_players_timer(500) {
  84. save_time_timer.Start();
  85. time_tick_timer.Start();
  86. vitality_timer.Start();
  87. player_stats_timer.Start();
  88. server_stats_timer.Start();
  89. //remove_grouped_player.Start();
  90. guilds_timer.Start();
  91. lotto_players_timer.Start();
  92. xp_rate = -1;
  93. ts_xp_rate = -1;
  94. vitality_frequency = 0xFFFFFFFF;
  95. vitality_amount = -1;
  96. last_checked_time = 0;
  97. items_loaded = false;
  98. spells_loaded = false;
  99. achievments_loaded = false;
  100. merchant_inventory_items.clear();
  101. MHouseZones.SetName("World::m_houseZones");
  102. MPlayerHouses.SetName("World::m_playerHouses");
  103. }
  104. World::~World(){
  105. // At this point the log system is already shut down so no calls to LogWrite are allowed in any of the functions called by this deconstructor
  106. DeleteSpawns();
  107. if(database.GetStatus() == database.Connected)
  108. WriteServerStatistics();
  109. RemoveServerStatistics();
  110. DeleteMerchantsInfo();
  111. MutexMap<int32, LottoPlayer*>::iterator itr = lotto_players.begin();
  112. while (itr.Next())
  113. safe_delete(itr->second);
  114. map<int32, HouseZone*>::iterator itr2;
  115. for (itr2 = m_houseZones.begin(); itr2 != m_houseZones.end(); itr2++)
  116. safe_delete(itr2->second);
  117. m_houseZones.clear();
  118. tov_itemstat_conversion.clear();
  119. }
  120. void World::init(){
  121. WorldDatabase::next_id = database.GetMaxHotBarID();
  122. LogWrite(COMMAND__DEBUG, 1, "Command", "-Loading Commands...");
  123. database.LoadCommandList();
  124. LogWrite(COMMAND__DEBUG, 1, "Command", "-Load Commands complete!");
  125. LogWrite(FACTION__DEBUG, 1, "Faction", "-Loading Factions...");
  126. database.LoadFactionList();
  127. LogWrite(FACTION__DEBUG, 1, "Faction", "-Load Factions complete!...");
  128. LogWrite(SKILL__DEBUG, 1, "Skill", "-Loading Skills...");
  129. database.LoadSkills();
  130. LogWrite(SKILL__DEBUG, 1, "Skill", "-Load Skills complete...");
  131. LogWrite(WORLD__DEBUG, 1, "World", "-Loading `variables`...");
  132. database.LoadGlobalVariables();
  133. LogWrite(WORLD__DEBUG, 1, "World", "-Load `variables` complete!");
  134. LogWrite(WORLD__DEBUG, 1, "World", "-Loading `appearances`...");
  135. database.LoadAppearanceMasterList();
  136. LogWrite(WORLD__DEBUG, 1, "World", "-Load `appearances` complete!");
  137. LogWrite(WORLD__DEBUG, 1, "World", "-Loading `visual_states`...");
  138. database.LoadVisualStates();
  139. LogWrite(WORLD__DEBUG, 1, "World", "-Load `visual states` complete!");
  140. LogWrite(WORLD__DEBUG, 1, "World", "-Setting system parameters...");
  141. Variable* var = variables.FindVariable("gametime");
  142. const char* time_string = 0;
  143. char default_time[] = "0/0/3800 8:30";
  144. if(var)
  145. time_string = var->GetValue();
  146. if(!time_string)
  147. time_string = default_time;
  148. int year, month, day, hour, minute;
  149. sscanf (time_string, "%d/%d/%d %d:%d", &month, &day, &year, &hour, &minute);
  150. LogWrite(WORLD__DEBUG, 3, "World", "--Setting World Time to %s...", time_string);
  151. world_time.month = month;
  152. world_time.day = day;
  153. world_time.year = year;
  154. world_time.hour = hour;
  155. world_time.minute = minute;
  156. LogWrite(WORLD__DEBUG, 3, "World", "--Loading Vitality Information...");
  157. LoadVitalityInformation();
  158. LogWrite(WORLD__DEBUG, 3, "World", "--Loading Server Statistics...");
  159. database.LoadServerStatistics();
  160. LogWrite(WORLD__DEBUG, 3, "World", "--Setting Server Start Time...");
  161. UpdateServerStatistic(STAT_SERVER_START_TIME, Timer::GetUnixTimeStamp(), true);
  162. LogWrite(WORLD__DEBUG, 3, "World", "--Resetting Accepted Connections to 0...");
  163. UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 0, true);
  164. LogWrite(WORLD__DEBUG, 3, "World", "--Resetting Active Zones to 0...");
  165. UpdateServerStatistic(STAT_SERVER_NUM_ACTIVE_ZONES, 0, true);
  166. // Clear all online players at server startup
  167. LogWrite(WORLD__DEBUG, 3, "World", "--Resetting characters online flags...");
  168. database.ToggleCharacterOnline();
  169. LogWrite(WORLD__DEBUG, 1, "World", "-Set system parameters complete!");
  170. LogWrite(RULESYS__DEBUG, 1, "Rules", "-Loading Rule Sets...");
  171. database.LoadRuleSets();
  172. LogWrite(RULESYS__DEBUG, 1, "Rules", "-Load Rule Sets complete!");
  173. LogWrite(CHAT__DEBUG, 1, "IRC", "-Starting IRC thread...");
  174. LoadItemBlueStats();
  175. //PopulateTOVStatMap();
  176. group_buff_updates.Start(rule_manager.GetGlobalRule(R_Client, GroupSpellsTimer)->GetInt32());
  177. irc.Start();
  178. }
  179. PacketStruct* World::GetWorldTime(int16 version){
  180. PacketStruct* packet = configReader.getStruct("WS_GameWorldTime", version);
  181. if(packet){
  182. packet->setDataByName("year", world_time.year);
  183. packet->setDataByName("month", world_time.month);
  184. packet->setDataByName("day", world_time.day);
  185. packet->setDataByName("hour", world_time.hour);
  186. packet->setDataByName("minute", world_time.minute);
  187. packet->setDataByName("unknown", 250);
  188. packet->setDataByName("unix_time", Timer::GetUnixTimeStamp());
  189. packet->setDataByName("unknown2", 1);
  190. }
  191. return packet;
  192. }
  193. float World::GetXPRate(){
  194. if(xp_rate >= 0)
  195. return xp_rate;
  196. xp_rate = rule_manager.GetGlobalRule(R_Player, XPMultiplier)->GetFloat();
  197. LogWrite(WORLD__DEBUG, 0, "World", "Setting Global XP Rate to: %.2f", xp_rate);
  198. return xp_rate;
  199. }
  200. float World::GetTSXPRate()
  201. {
  202. if(ts_xp_rate >= 0)
  203. return ts_xp_rate;
  204. ts_xp_rate = rule_manager.GetGlobalRule(R_Player, TSXPMultiplier)->GetFloat();
  205. LogWrite(WORLD__DEBUG, 0, "World", "Setting Global Tradeskill XP Rate to: %.2f", ts_xp_rate);
  206. return ts_xp_rate;
  207. }
  208. void World::Process(){
  209. if(last_checked_time > Timer::GetCurrentTime2())
  210. return;
  211. last_checked_time = Timer::GetCurrentTime2() + 1000;
  212. if(save_time_timer.Check())
  213. database.SaveWorldTime(&world_time);
  214. if(time_tick_timer.Check())
  215. WorldTimeTick();
  216. if(vitality_timer.Check())
  217. UpdateVitality();
  218. if (player_stats_timer.Check())
  219. WritePlayerStatistics();
  220. if (server_stats_timer.Check())
  221. WriteServerStatistics();
  222. /*if(remove_grouped_player.Check())
  223. CheckRemoveGroupedPlayer();*/
  224. if (group_buff_updates.Check())
  225. GetGroupManager()->UpdateGroupBuffs();
  226. if (guilds_timer.Check())
  227. SaveGuilds();
  228. if (lotto_players_timer.Check())
  229. CheckLottoPlayers();
  230. }
  231. vector<Variable*>* World::GetClientVariables(){
  232. return variables.GetVariables("cl_");
  233. }
  234. void World::LoadVitalityInformation()
  235. {
  236. int32 timestamp = Timer::GetUnixTimeStamp();
  237. int32 diff = 0;
  238. // fetch vitalitytimer value from `variables` table
  239. Variable* timer_var = variables.FindVariable("vitalitytimer");
  240. if(timer_var)
  241. {
  242. try
  243. {
  244. diff = timestamp - atoul(timer_var->GetValue());
  245. diff *= 1000; //convert seconds to milliseconds
  246. }
  247. catch(...)
  248. {
  249. LogWrite(WORLD__ERROR, 0, "World", "Error parsing vitalitytimer, value: %s", timer_var->GetValue());
  250. }
  251. }
  252. // Now using Rules System to set vitality parameters
  253. vitality_amount = rule_manager.GetGlobalRule(R_Player, VitalityAmount)->GetFloat();
  254. vitality_frequency = rule_manager.GetGlobalRule(R_Player, VitalityFrequency)->GetInt32();
  255. vitality_frequency *= 1000; //convert seconds to milliseconds
  256. if(diff >= vitality_frequency)
  257. UpdateVitality(); //update now
  258. else
  259. vitality_timer.SetTimer(vitality_frequency - diff);
  260. }
  261. void World::UpdateVitality()
  262. {
  263. // push new vitalitytimer to `variables` table
  264. database.UpdateVitality(Timer::GetUnixTimeStamp(), vitality_amount);
  265. if(vitality_timer.GetDuration() != vitality_frequency)
  266. vitality_timer.SetTimer(vitality_frequency);
  267. zone_list.UpdateVitality(vitality_amount);
  268. }
  269. void ZoneList::UpdateVitality(float amount)
  270. {
  271. list<ZoneServer*>::iterator zone_iter;
  272. ZoneServer* tmp = 0;
  273. MZoneList.readlock(__FUNCTION__, __LINE__);
  274. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++)
  275. {
  276. tmp = *zone_iter;
  277. if(tmp)
  278. tmp->UpdateVitality(amount);
  279. }
  280. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  281. }
  282. void World::WorldTimeTick(){
  283. world_time.minute++;
  284. //I know it looks complicated, but the nested ifs are to avoid checking all of them every 3 seconds
  285. if(world_time.minute >= 60){ // >= in case of bad time from db
  286. world_time.minute = 0;
  287. world_time.hour++;
  288. if(world_time.hour >= 24){
  289. world_time.hour = 0;
  290. world_time.day++;
  291. if(world_time.day>=30){
  292. world_time.day = 0;
  293. world_time.month++;
  294. if(world_time.month >= 12){
  295. world_time.month = 0;
  296. world_time.year++;
  297. }
  298. }
  299. }
  300. }
  301. }
  302. ZoneList::ZoneList() {
  303. MZoneList.SetName("ZoneList::MZoneList");
  304. }
  305. ZoneList::~ZoneList() {
  306. list<ZoneServer*>::iterator zone_iter;
  307. ZoneServer* zs = 0;
  308. for(zone_iter=zlist.begin(); zone_iter!=zlist.end();){
  309. zs = *zone_iter;
  310. zone_iter = zlist.erase(zone_iter);
  311. safe_delete(zs);
  312. }
  313. }
  314. void ZoneList::CheckFriendList(Client* client) {
  315. LogWrite(WORLD__DEBUG, 0, "World", "Sending FriendList...");
  316. MClientList.lock();
  317. map<string,Client*>::iterator itr;
  318. for(itr = client_map.begin(); itr != client_map.end(); itr++){
  319. if(itr->second != client && itr->second){
  320. if(itr->second->GetPlayer()->IsFriend(client->GetPlayer()->GetName())){
  321. itr->second->SendFriendList();
  322. itr->second->Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Friend: %s has logged in.", client->GetPlayer()->GetName());
  323. }
  324. }
  325. }
  326. MClientList.unlock();
  327. }
  328. void ZoneList::CheckFriendZoned(Client* client){
  329. MClientList.lock();
  330. map<string,Client*>::iterator itr;
  331. for(itr = client_map.begin(); itr != client_map.end(); itr++){
  332. if(itr->second != client && itr->second){
  333. if(itr->second->GetPlayer()->IsFriend(client->GetPlayer()->GetName())){
  334. itr->second->SendFriendList();
  335. }
  336. }
  337. }
  338. MClientList.unlock();
  339. }
  340. bool ZoneList::HandleGlobalChatMessage(Client* from, char* to, int16 channel, const char* message, const char* channel_name){
  341. if (!from) {
  342. LogWrite(WORLD__ERROR, 0, "World", "HandleGlobalChatMessage() called with an invalid client");
  343. return false;
  344. }
  345. if(channel == CHANNEL_TELL){
  346. Client* find_client = zone_list.GetClientByCharName(to);
  347. if(!find_client || find_client->GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  348. return false;
  349. else if(find_client == from)
  350. {
  351. from->Message(CHANNEL_COLOR_RED,"You must be very lonely...(ERROR: Cannot send tell to self)");
  352. }
  353. else
  354. {
  355. PacketStruct* packet = configReader.getStruct("WS_HearChat", from->GetVersion());
  356. if(packet){
  357. packet->setMediumStringByName("from", from->GetPlayer()->GetName());
  358. packet->setMediumStringByName("to", find_client->GetPlayer()->GetName());
  359. packet->setDataByName("channel", CHANNEL_TELL);
  360. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  361. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  362. packet->setDataByName("unknown2", 1, 1);
  363. packet->setDataByName("show_bubble", 1);
  364. packet->setDataByName("understood", 1);
  365. packet->setDataByName("time", 2);
  366. packet->setMediumStringByName("message", message);
  367. if(channel_name)
  368. packet->setMediumStringByName("channel_name", channel_name);
  369. EQ2Packet* outpacket = packet->serialize();
  370. //DumpPacket(outpacket);
  371. find_client->QueuePacket(outpacket->Copy());
  372. from->QueuePacket(outpacket);
  373. safe_delete(packet);
  374. }
  375. if (find_client->GetPlayer()->get_character_flag(CF_AFK)) {
  376. PacketStruct* packet2 = configReader.getStruct("WS_HearChat", from->GetVersion());
  377. if (packet2) {
  378. packet2->setMediumStringByName("from", find_client->GetPlayer()->GetName());
  379. packet2->setMediumStringByName("to", from->GetPlayer()->GetName());
  380. packet2->setDataByName("channel", CHANNEL_TELL);
  381. packet2->setDataByName("from_spawn_id", 0xFFFFFFFF);
  382. packet2->setDataByName("to_spawn_id", 0xFFFFFFFF);
  383. packet2->setDataByName("unknown2", 1, 1);
  384. packet2->setDataByName("show_bubble", 1);
  385. packet2->setDataByName("understood", 1);
  386. packet2->setDataByName("time", 2);
  387. packet2->setMediumStringByName("message", find_client->GetPlayer()->GetAwayMessage().c_str());
  388. if (channel_name)
  389. packet2->setMediumStringByName("channel_name", channel_name);
  390. EQ2Packet* outpacket = packet2->serialize();
  391. from->QueuePacket(outpacket->Copy());
  392. find_client->QueuePacket(outpacket);
  393. safe_delete(packet2);
  394. }
  395. }
  396. }
  397. }
  398. else if(channel == CHANNEL_GROUP) {
  399. GroupMemberInfo* gmi = from->GetPlayer()->GetGroupMemberInfo();
  400. if(gmi)
  401. world.GetGroupManager()->GroupMessage(gmi->group_id, message);
  402. }
  403. else{
  404. list<ZoneServer*>::iterator zone_iter;
  405. ZoneServer* zs = 0;
  406. MZoneList.readlock(__FUNCTION__, __LINE__);
  407. for(zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  408. zs = *zone_iter;
  409. if(zs)
  410. zs->HandleChatMessage(from->GetPlayer(), to, channel, message, 0, channel_name);
  411. }
  412. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  413. }
  414. return true;
  415. }
  416. void ZoneList::LoadSpellProcess(){
  417. list<ZoneServer*>::iterator zone_iter;
  418. ZoneServer* zone = 0;
  419. MZoneList.readlock(__FUNCTION__, __LINE__);
  420. for (zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  421. zone = *zone_iter;
  422. if (zone)
  423. zone->LoadSpellProcess();
  424. }
  425. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  426. }
  427. void ZoneList::DeleteSpellProcess(){
  428. list<ZoneServer*>::iterator zone_iter;
  429. ZoneServer* zone = 0;
  430. MZoneList.readlock(__FUNCTION__, __LINE__);
  431. for (zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  432. zone = *zone_iter;
  433. if (zone)
  434. zone->DeleteSpellProcess();
  435. }
  436. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  437. }
  438. void ZoneList::HandleGlobalBroadcast(const char* message) {
  439. list<ZoneServer*>::iterator zone_iter;
  440. ZoneServer* zone = 0;
  441. MZoneList.readlock(__FUNCTION__, __LINE__);
  442. for (zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  443. zone = *zone_iter;
  444. if (zone)
  445. zone->HandleBroadcast(message);
  446. }
  447. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  448. }
  449. void ZoneList::HandleGlobalAnnouncement(const char* message) {
  450. list<ZoneServer*>::iterator zone_iter;
  451. ZoneServer* zone = 0;
  452. MZoneList.readlock(__FUNCTION__, __LINE__);
  453. for (zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  454. zone = *zone_iter;
  455. if (zone)
  456. zone->HandleAnnouncement(message);
  457. }
  458. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  459. }
  460. int32 ZoneList::Count(){
  461. return zlist.size();
  462. }
  463. void ZoneList::Add(ZoneServer* zone) {
  464. MZoneList.writelock(__FUNCTION__, __LINE__);
  465. zlist.push_back(zone);
  466. MZoneList.releasewritelock(__FUNCTION__, __LINE__);
  467. }
  468. void ZoneList::Remove(ZoneServer* zone) {
  469. MZoneList.writelock(__FUNCTION__, __LINE__);
  470. zlist.remove(zone);
  471. MZoneList.releasewritelock(__FUNCTION__, __LINE__);
  472. }
  473. ZoneServer* ZoneList::Get(const char* zone_name, bool loadZone) {
  474. list<ZoneServer*>::iterator zone_iter;
  475. ZoneServer* tmp = 0;
  476. ZoneServer* ret = 0;
  477. MZoneList.readlock(__FUNCTION__, __LINE__);
  478. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  479. tmp = *zone_iter;
  480. if (!tmp->isZoneShuttingDown() && !tmp->IsInstanceZone() && strlen(zone_name) == strlen(tmp->GetZoneName()) &&
  481. strncasecmp(tmp->GetZoneName(), zone_name, strlen(zone_name))==0){
  482. if(tmp->NumPlayers() < 30 || tmp->IsCityZone())
  483. ret = tmp;
  484. break;
  485. }
  486. }
  487. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  488. if(!ret )
  489. {
  490. if ( loadZone )
  491. {
  492. ret = new ZoneServer(zone_name);
  493. database.LoadZoneInfo(ret);
  494. ret->Init();
  495. }
  496. }
  497. return ret;
  498. }
  499. ZoneServer* ZoneList::Get(int32 id, bool loadZone) {
  500. list<ZoneServer*>::iterator zone_iter;
  501. ZoneServer* tmp = 0;
  502. ZoneServer* ret = 0;
  503. MZoneList.readlock(__FUNCTION__, __LINE__);
  504. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  505. tmp = *zone_iter;
  506. if(!tmp->isZoneShuttingDown() && !tmp->IsInstanceZone() && tmp->GetZoneID() == id){
  507. if(tmp->NumPlayers() < 30 || tmp->IsCityZone())
  508. ret = tmp;
  509. break;
  510. }
  511. }
  512. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  513. if(ret)
  514. tmp = ret;
  515. else if (loadZone) {
  516. string* zonename = database.GetZoneName(id);
  517. if(zonename){
  518. tmp = new ZoneServer(zonename->c_str());
  519. database.LoadZoneInfo(tmp);
  520. tmp->Init();
  521. safe_delete(zonename);
  522. }
  523. }
  524. return tmp;
  525. }
  526. void ZoneList::SendZoneList(Client* client) {
  527. list<ZoneServer*>::iterator zone_iter;
  528. ZoneServer* tmp = 0;
  529. MZoneList.readlock(__FUNCTION__, __LINE__);
  530. int zonesListed = 0;
  531. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  532. tmp = *zone_iter;
  533. if ( zonesListed > 20 )
  534. {
  535. client->Message(CHANNEL_COLOR_YELLOW,"Reached max zone list of 20.");
  536. break;
  537. }
  538. zonesListed++;
  539. client->Message(CHANNEL_COLOR_YELLOW,"Zone(ID): %s(%i), Instance ID: %i, Description: %s.",tmp->GetZoneName(),tmp->GetZoneID(),
  540. tmp->GetInstanceID(),tmp->GetZoneDescription());
  541. }
  542. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  543. }
  544. ZoneServer* ZoneList::GetByInstanceID(int32 id, int32 zone_id) {
  545. list<ZoneServer*>::iterator zone_iter;
  546. ZoneServer* tmp = 0;
  547. ZoneServer* ret = 0;
  548. MZoneList.readlock(__FUNCTION__, __LINE__);
  549. if ( id > 0 )
  550. {
  551. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  552. tmp = *zone_iter;
  553. if(tmp->GetInstanceID() == id){
  554. ret = tmp;
  555. break;
  556. }
  557. }
  558. }
  559. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  560. if(ret)
  561. tmp = ret;
  562. else if ( zone_id > 0 ){
  563. string* zonename = database.GetZoneName(zone_id);
  564. if(zonename){
  565. tmp = new ZoneServer(zonename->c_str());
  566. // the player is trying to preload an already existing instance but it isn't loaded
  567. if ( id > 0 )
  568. tmp->SetupInstance(id);
  569. database.LoadZoneInfo(tmp);
  570. tmp->Init();
  571. safe_delete(zonename);
  572. }
  573. }
  574. return tmp;
  575. }
  576. ZoneServer* ZoneList::GetByLowestPopulation(int32 zone_id) {
  577. ZoneServer* ret = 0;
  578. ZoneServer* zone = 0;
  579. int32 clients = 0;
  580. list<ZoneServer*>::iterator itr;
  581. MZoneList.readlock(__FUNCTION__, __LINE__);
  582. if (zone_id) {
  583. for (itr = zlist.begin(); itr != zlist.end(); itr++) {
  584. zone = *itr;
  585. if (zone) {
  586. // check the zone id's
  587. if (zone->GetZoneID() == zone_id) {
  588. // check this zones client count
  589. if (clients == 0 || zone->GetClientCount() < clients) {
  590. ret = zone;
  591. clients = zone->GetClientCount();
  592. }
  593. }
  594. }
  595. }
  596. }
  597. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  598. return ret;
  599. }
  600. bool ZoneList::ClientConnected(int32 account_id){
  601. bool ret = false;
  602. map<string, Client*>::iterator itr;
  603. MClientList.lock();
  604. for(itr=client_map.begin(); itr != client_map.end(); itr++){
  605. if(itr->second && itr->second->GetAccountID() == account_id && (itr->second->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) == 0){
  606. ret = true;
  607. break;
  608. }
  609. else if(!itr->second){
  610. client_map.erase(itr);
  611. if(client_map.size() > 0){
  612. itr=client_map.begin();
  613. if(itr == client_map.end()){
  614. if(itr->second && itr->second->GetAccountID() == account_id && (itr->second->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) == 0)
  615. ret = true;
  616. break;
  617. }
  618. }
  619. else
  620. break;
  621. }
  622. }
  623. MClientList.unlock();
  624. return ret;
  625. }
  626. void ZoneList::ReloadClientQuests(){
  627. list<ZoneServer*>::iterator zone_iter;
  628. ZoneServer* tmp = 0;
  629. MZoneList.readlock(__FUNCTION__, __LINE__);
  630. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  631. tmp = *zone_iter;
  632. if(tmp)
  633. tmp->ReloadClientQuests();
  634. }
  635. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  636. }
  637. void ZoneList::ProcessWhoQuery(vector<string>* queries, ZoneServer* zone, vector<Entity*>* players, bool isGM){
  638. Entity* player = 0;
  639. bool add_player = true;
  640. bool found_match = false;
  641. int8 lower = 0;
  642. int8 upper = 0;
  643. vector<Entity*> tmpPlayers;
  644. vector<Entity*>::iterator spawn_iter;
  645. if(!zone->isZoneShuttingDown()){
  646. tmpPlayers = zone->GetPlayers();
  647. for(spawn_iter = tmpPlayers.begin(); spawn_iter!=tmpPlayers.end(); spawn_iter++){
  648. player = *spawn_iter;
  649. add_player = true;
  650. Client* find_client = zone_list.GetClientByCharName(player->GetName());
  651. if (find_client == NULL) continue;
  652. int flags = find_client->GetPlayer()->GetInfoStruct()->flags;
  653. int flags2 = find_client->GetPlayer()->GetInfoStruct()->flags2;
  654. for(int32 i=0;add_player && queries && i<queries->size();i++){
  655. found_match = false;
  656. if(queries->at(i) == "ALL")
  657. continue;
  658. if(queries->at(i).length() > 3 && classes.GetClassID(queries->at(i).c_str()) > 0){
  659. if(player->GetAdventureClass() != classes.GetClassID(queries->at(i).c_str()))
  660. add_player = false;
  661. found_match = true;
  662. }
  663. else if(queries->at(i).length() > 2 && races.GetRaceID(queries->at(i).c_str()) > 0){
  664. if(player->GetRace() != races.GetRaceID(queries->at(i).c_str()))
  665. add_player = false;
  666. found_match = true;
  667. }
  668. if(!found_match && queries->at(i) == "GOOD"){
  669. if(player->GetDeity() != 1)
  670. add_player = false;
  671. found_match = true;
  672. }
  673. else if(!found_match && queries->at(i) == "EVIL"){
  674. if(player->GetDeity() == 1)
  675. add_player = false;
  676. found_match = true;
  677. }
  678. if((queries->at(i) == "GUIDE") && (find_client->GetAdminStatus() > 0) && ((find_client->GetAdminStatus() >> 4) < 5))
  679. found_match = true;
  680. else if((queries->at(i) == "GM") && ((find_client->GetAdminStatus() >> 4) > 4))
  681. found_match = true;
  682. else if((queries->at(i) == "LFG") && (flags & (1 << CF_LFG)))
  683. found_match = true;
  684. else if((queries->at(i) == "LFW") && (flags & (1 << CF_LFW)))
  685. found_match = true;
  686. else if((queries->at(i) == "ROLEPLAYING") && (flags & (1 << CF_ROLEPLAYING)))
  687. found_match = true;
  688. else if(strspn(queries->at(i).c_str(),"0123456789") == queries->at(i).length()){
  689. try{
  690. if(lower == 0)
  691. lower = atoi(queries->at(i).c_str());
  692. else
  693. upper = atoi(queries->at(i).c_str());
  694. }
  695. catch(...){}
  696. found_match = true;
  697. }
  698. if(!found_match){
  699. string name = string(player->GetName());
  700. name = ToUpper(name);
  701. if(name.find(queries->at(i)) == name.npos)
  702. add_player = false;
  703. }
  704. }
  705. if(lower > 0 && upper > 0){
  706. if(player->GetLevel() < lower || player->GetLevel() > upper)
  707. add_player = false;
  708. }
  709. else if(lower > 0){
  710. if(player->GetLevel() != lower)
  711. add_player = false;
  712. }
  713. if((flags2 & (1 << (CF_GM_HIDDEN - 32))) && !isGM) {
  714. add_player = false;
  715. found_match = true;
  716. }
  717. if(add_player)
  718. players->push_back(player);
  719. }
  720. }
  721. }
  722. void ZoneList::ProcessWhoQuery(const char* query, Client* client){
  723. list<ZoneServer*>::iterator zone_iter;
  724. vector<Entity*> players;
  725. vector<Entity*>::iterator spawn_iter;
  726. Entity* player = 0;
  727. //for now display all clients
  728. bool all = false;
  729. vector<string>* queries = 0;
  730. bool isGM = ((client->GetAdminStatus() >> 4) > 4);
  731. if(query){
  732. string query_string = string(query);
  733. query_string = ToUpper(query_string);
  734. queries = SplitString(query_string, ' ');
  735. }
  736. if(queries && queries->size() > 0 && queries->at(0) == "ALL")
  737. all = true;
  738. if(all){
  739. MZoneList.readlock(__FUNCTION__, __LINE__);
  740. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  741. ZoneServer* tmp = *zone_iter;
  742. ProcessWhoQuery(queries, tmp, &players, isGM);
  743. }
  744. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  745. }
  746. else{
  747. ProcessWhoQuery(queries, client->GetCurrentZone(), &players, isGM);
  748. }
  749. PacketStruct* packet = configReader.getStruct("WS_WhoQueryReply", client->GetVersion());
  750. if(packet){
  751. packet->setDataByName("account_id", client->GetAccountID());
  752. packet->setDataByName("unknown", 0xFFFFFFFF);
  753. int8 num_characters = players.size();
  754. int8 max_who_results = 10;
  755. int8 max_who_results_status_override = 100;
  756. Variable* var = variables.FindVariable("max_who_results_status_override");
  757. if ( var ){
  758. max_who_results_status_override = atoi(var->GetValue());
  759. }
  760. // AdnaeDMorte
  761. if ( client->GetAdminStatus() >= max_who_results_status_override ){
  762. client->Message(CHANNEL_COLOR_RED, "** ADMIN-MODE ** ");
  763. }
  764. Variable* var1 = variables.FindVariable("max_who_results");
  765. if ( var1 ){
  766. max_who_results = atoi(var1->GetValue());
  767. }
  768. if(num_characters > max_who_results && client->GetAdminStatus() < max_who_results_status_override){
  769. num_characters = max_who_results;
  770. packet->setDataByName("response", 3); //response 1 = error message, 3 == capped
  771. }
  772. else
  773. packet->setDataByName("response", 2);
  774. packet->setArrayLengthByName("num_characters", num_characters);
  775. packet->setDataByName("unknown10", 1);
  776. int i=0;
  777. for(spawn_iter = players.begin(); spawn_iter!=players.end(); spawn_iter++, i++){
  778. if(i == num_characters)
  779. break;
  780. player = *spawn_iter;
  781. Client* find_client = zone_list.GetClientByCharName(player->GetName());
  782. int flags = find_client->GetPlayer()->GetInfoStruct()->flags;
  783. int flags2 = find_client->GetPlayer()->GetInfoStruct()->flags2;
  784. packet->setArrayDataByName("char_name", player->GetName(), i);
  785. packet->setArrayDataByName("level", player->GetLevel(), i);
  786. packet->setArrayDataByName("admin_level", ((flags2 & (1 << (CF_HIDE_STATUS - 32))) && !isGM)?0:(find_client->GetAdminStatus() >> 4), i);
  787. packet->setArrayDataByName("class", player->GetAdventureClass(), i);
  788. packet->setArrayDataByName("unknown4", 0xFF, i); //probably tradeskill class
  789. packet->setArrayDataByName("flags", (((flags >> CF_ANONYMOUS) & 1) << 0 ) |
  790. (((flags >> CF_LFG) & 1) << 1 ) |
  791. (((flags >> CF_ANONYMOUS) & 1) << 2 ) |
  792. /*(((flags >> CF_HIDDEN) & 1) << 3 ) |*/
  793. (((flags >> CF_ROLEPLAYING) & 1) << 4 ) |
  794. (((flags >> CF_AFK) & 1) << 5 ) |
  795. (((flags >> CF_LFW) & 1) << 6 ) /*|
  796. (((flags >> CF_NOTA) & 1) << 7 )*/, i);
  797. packet->setArrayDataByName("race", player->GetRace(), i);
  798. if(player->GetZone() && player->GetZone()->GetZoneDescription())
  799. packet->setArrayDataByName("zone", player->GetZone()->GetZoneDescription(), i);
  800. if(player->appearance.sub_title) {
  801. int32 sub_title_length = strlen(player->appearance.sub_title);
  802. char tmp_title[255];
  803. int32 index = 0;
  804. int32 index_tmp = 0;
  805. while (index < sub_title_length) {
  806. if (player->appearance.sub_title[index] != '<' && player->appearance.sub_title[index] != '>') {
  807. memcpy(tmp_title + index_tmp, player->appearance.sub_title + index, 1);
  808. index_tmp++;
  809. }
  810. index++;
  811. }
  812. tmp_title[index_tmp] = '\0';
  813. packet->setArrayDataByName("guild", tmp_title, i);
  814. }
  815. }
  816. client->QueuePacket(packet->serialize());
  817. safe_delete(packet);
  818. }
  819. }
  820. bool ZoneList::DepopFinished(){
  821. list<ZoneServer*>::iterator zone_iter;
  822. MZoneList.readlock(__FUNCTION__, __LINE__);
  823. bool finished_depop = true;
  824. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  825. if(!(*zone_iter)->FinishedDepop())
  826. finished_depop = false;
  827. }
  828. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  829. return finished_depop;
  830. }
  831. void ZoneList::Depop(){
  832. list<ZoneServer*>::iterator zone_iter;
  833. MZoneList.readlock(__FUNCTION__, __LINE__);
  834. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  835. (*zone_iter)->Depop();
  836. }
  837. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  838. }
  839. void ZoneList::Repop(){
  840. list<ZoneServer*>::iterator zone_iter;
  841. MZoneList.readlock(__FUNCTION__, __LINE__);
  842. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  843. (*zone_iter)->Depop(false, true);
  844. }
  845. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  846. }
  847. void ZoneList::ReloadSpawns() {
  848. MZoneList.readlock(__FUNCTION__, __LINE__);
  849. list<ZoneServer*>::iterator itr;
  850. for (itr = zlist.begin(); itr != zlist.end(); itr++)
  851. (*itr)->ReloadSpawns();
  852. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  853. }
  854. bool World::ReportBug(string data, char* player_name, int32 account_id, const char* spawn_name, int32 spawn_id, int32 zone_id){
  855. //loginserver
  856. vector<string> list;
  857. int32 offset = 0;
  858. int32 old_offset = 0;
  859. while((offset = data.find(7, old_offset+1)) < 0xFFFFFFFF){
  860. if(old_offset > 0)
  861. list.push_back(data.substr(old_offset+1, offset-old_offset-1));
  862. else
  863. list.push_back(data.substr(old_offset, offset));
  864. old_offset = offset;
  865. }
  866. if(list.size() > 0 && list.size() < 7){
  867. string output = "Invalid bug list:\n";
  868. for(int32 i=0;i<list.size();i++)
  869. output = output.append("\t").append(list[i]).append("\n");
  870. LogWrite(WORLD__ERROR, 0, "World", "%s", output.c_str());
  871. return false;
  872. }
  873. ServerPacket* outpack = new ServerPacket(ServerOP_BugReport, sizeof(BugReport));
  874. BugReport* report = (BugReport*)outpack->pBuffer;
  875. if (list.size() < 7) {
  876. strncpy(report->category, "AutoBug", 7);
  877. strncpy(report->subcategory, "AutoGenerate", 12);
  878. strncpy(report->causes_crash, "N", 1);
  879. strncpy(report->reproducible, "Y", 1);
  880. strncpy(report->summary, data.c_str(), data.length() > 127 ? 127 : data.length());
  881. strncpy(report->description, data.c_str(), data.length() > 1999 ? 1999 : data.length());
  882. strncpy(report->version, "CUR", 3);
  883. }
  884. else
  885. {
  886. strncpy(report->category, list[0].c_str(), list[0].length() > 63 ? 63 : list[0].length());
  887. strncpy(report->subcategory, list[1].c_str(), list[1].length() > 63 ? 63 : list[1].length());
  888. strncpy(report->causes_crash, list[2].c_str(), list[2].length() > 63 ? 63 : list[2].length());
  889. strncpy(report->reproducible, list[3].c_str(), list[3].length() > 63 ? 63 : list[3].length());
  890. strncpy(report->summary, list[4].c_str(), list[4].length() > 127 ? 127 : list[4].length());
  891. strncpy(report->description, list[5].c_str(), list[5].length() > 1999 ? 1999 : list[5].length());
  892. strncpy(report->version, list[6].c_str(), list[6].length() > 31 ? 31 : list[6].length());
  893. }
  894. strncpy(report->player, player_name, strlen(player_name) > 63 ? 63 : strlen(player_name));
  895. strncpy(report->spawn_name, spawn_name, strlen(spawn_name) > 63 ? 63 : strlen(spawn_name));
  896. report->spawn_id = spawn_id;
  897. report->account_id = account_id;
  898. report->zone_id = zone_id;
  899. loginserver.SendPacket(outpack);
  900. database.SaveBugReport(report->category, report->subcategory, report->causes_crash, report->reproducible, report->summary, report->description, report->version, report->player, account_id, spawn_name, spawn_id, zone_id);
  901. safe_delete(outpack);
  902. return true;
  903. }
  904. void ZoneList::WritePlayerStatistics() {
  905. list<ZoneServer*>::iterator zone_itr;
  906. MZoneList.readlock(__FUNCTION__, __LINE__);
  907. for (zone_itr = zlist.begin(); zone_itr != zlist.end(); zone_itr++)
  908. (*zone_itr)->WritePlayerStatistics();
  909. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  910. }
  911. void ZoneList::ShutDownZones(){
  912. LogWrite(WORLD__INFO, 0, "World", "Shutting down all zones, please wait...");
  913. list<ZoneServer*>::iterator zone_itr;
  914. int32 size = 0;
  915. MZoneList.readlock(__FUNCTION__, __LINE__);
  916. for (zone_itr = zlist.begin(); zone_itr != zlist.end(); zone_itr++){
  917. (*zone_itr)->Shutdown();
  918. }
  919. size = zlist.size();
  920. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  921. while(size > 0){
  922. Sleep(10);
  923. MZoneList.readlock(__FUNCTION__, __LINE__);
  924. size = zlist.size();
  925. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  926. }
  927. LogWrite(WORLD__INFO, 0, "World", "Zone shutdown complete");
  928. }
  929. void ZoneList::ReloadMail() {
  930. map<string, Client*>::iterator itr;
  931. MClientList.writelock(__FUNCTION__, __LINE__);
  932. for (itr = client_map.begin(); itr != client_map.end(); itr++) {
  933. itr->second->GetPlayer()->DeleteMail();
  934. database.LoadPlayerMail(itr->second);
  935. }
  936. MClientList.releasewritelock(__FUNCTION__, __LINE__);
  937. }
  938. void World::AddSpawnScript(int32 id, const char* name){
  939. MSpawnScripts.lock();
  940. if(name)
  941. spawn_scripts[id] = string(name);
  942. MSpawnScripts.unlock();
  943. }
  944. void World::AddSpawnEntryScript(int32 id, const char* name){
  945. MSpawnScripts.lock();
  946. if(name)
  947. spawnentry_scripts[id] = string(name);
  948. MSpawnScripts.unlock();
  949. }
  950. void World::AddSpawnLocationScript(int32 id, const char* name){
  951. MSpawnScripts.lock();
  952. if(name)
  953. spawnlocation_scripts[id] = string(name);
  954. MSpawnScripts.unlock();
  955. }
  956. void World::AddZoneScript(int32 id, const char* name) {
  957. MZoneScripts.lock();
  958. if (name)
  959. zone_scripts[id] = string(name);
  960. MZoneScripts.unlock();
  961. }
  962. const char* World::GetSpawnScript(int32 id){
  963. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  964. const char* ret = 0;
  965. MSpawnScripts.lock();
  966. if(spawn_scripts.count(id) > 0)
  967. ret = spawn_scripts[id].c_str();
  968. MSpawnScripts.unlock();
  969. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  970. return ret;
  971. }
  972. const char* World::GetSpawnEntryScript(int32 id){
  973. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  974. const char* ret = 0;
  975. MSpawnScripts.lock();
  976. if(spawnentry_scripts.count(id) > 0)
  977. ret = spawnentry_scripts[id].c_str();
  978. MSpawnScripts.unlock();
  979. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  980. return ret;
  981. }
  982. const char* World::GetSpawnLocationScript(int32 id){
  983. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  984. const char* ret = 0;
  985. MSpawnScripts.lock();
  986. if(spawnlocation_scripts.count(id) > 0)
  987. ret = spawnlocation_scripts[id].c_str();
  988. MSpawnScripts.unlock();
  989. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  990. return ret;
  991. }
  992. const char* World::GetZoneScript(int32 id) {
  993. const char* ret = 0;
  994. MZoneScripts.lock();
  995. if (zone_scripts.count(id) > 0)
  996. ret = zone_scripts[id].c_str();
  997. MZoneScripts.unlock();
  998. return ret;
  999. }
  1000. void World::ResetSpawnScripts(){
  1001. MSpawnScripts.lock();
  1002. spawn_scripts.clear();
  1003. spawnentry_scripts.clear();
  1004. spawnlocation_scripts.clear();
  1005. MSpawnScripts.unlock();
  1006. }
  1007. void World::ResetZoneScripts() {
  1008. MZoneScripts.lock();
  1009. zone_scripts.clear();
  1010. MZoneScripts.unlock();
  1011. }
  1012. vector<MerchantItemInfo>* World::GetMerchantItemList(int32 merchant_id, int8 merchant_type, Player* player)
  1013. {
  1014. vector<MerchantItemInfo>* ret = 0;
  1015. MMerchantList.lock();
  1016. if(merchant_info.count(merchant_id) > 0)
  1017. {
  1018. MerchantInfo* info = merchant_info[merchant_id];
  1019. vector<MerchantItemInfo>::iterator itr;
  1020. int32 inventory_id = 0;
  1021. Item* item = 0;
  1022. for(int i=info->inventory_ids.size()-1;i>=0;i--)
  1023. {
  1024. inventory_id = info->inventory_ids[i];
  1025. if(merchant_inventory_items.count(inventory_id) > 0)
  1026. {
  1027. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++)
  1028. {
  1029. if(!ret)
  1030. ret = new vector<MerchantItemInfo>;
  1031. item = master_item_list.GetItem((*itr).item_id);
  1032. // if NOT spell merchant, OR
  1033. // skill req is any skill, OR player has the skill, AND
  1034. // skill req2 is any skill, OR player has the skill2
  1035. if(item && ( (merchant_type & MERCHANT_TYPE_SPELLS) == 0 || ( (item->generic_info.skill_req1 == 0xFFFFFFFF || player->GetSkills()->HasSkill(item->generic_info.skill_req1)) && (item->generic_info.skill_req2 == 0xFFFFFFFF || player->GetSkills()->HasSkill(item->generic_info.skill_req2)) ) ) )
  1036. (*ret).push_back(*itr);
  1037. }
  1038. }
  1039. }
  1040. }
  1041. MMerchantList.unlock();
  1042. return ret;
  1043. }
  1044. vector<MerchantItemInfo>* World::GetMerchantList(int32 merchant_id){
  1045. vector<MerchantItemInfo>* ret = 0;
  1046. MMerchantList.lock();
  1047. if(merchant_info.count(merchant_id) > 0){
  1048. MerchantInfo* info = merchant_info[merchant_id];
  1049. map<int32, int16>::iterator itr;
  1050. int32 inventory_id = 0;
  1051. for(int i=info->inventory_ids.size()-1;i>=0;i--){
  1052. inventory_id = info->inventory_ids[i];
  1053. if(merchant_inventory_items.count(inventory_id) > 0){
  1054. ret = &merchant_inventory_items[inventory_id];
  1055. }
  1056. }
  1057. }
  1058. MMerchantList.unlock();
  1059. return ret;
  1060. }
  1061. void World::AddMerchantItem(int32 inventory_id, MerchantItemInfo ItemInfo){
  1062. MMerchantList.lock();
  1063. merchant_inventory_items[inventory_id].push_back(ItemInfo);
  1064. MMerchantList.unlock();
  1065. }
  1066. void World::DeleteMerchantItems(){
  1067. MMerchantList.lock();
  1068. merchant_inventory_items.clear();
  1069. MMerchantList.unlock();
  1070. }
  1071. void World::RemoveMerchantItem(int32 inventory_id, int32 item_id){
  1072. MMerchantList.lock();
  1073. if(merchant_inventory_items.count(inventory_id) > 0) {
  1074. vector<MerchantItemInfo>::iterator itr;
  1075. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1076. if ((*itr).item_id == item_id) {
  1077. merchant_inventory_items[inventory_id].erase(itr);
  1078. break;
  1079. }
  1080. }
  1081. }
  1082. MMerchantList.unlock();
  1083. }
  1084. int16 World::GetMerchantItemQuantity(int32 merchant_id, int32 item_id){
  1085. int16 amount = 0;
  1086. int32 inventory_id = GetInventoryID(merchant_id, item_id);
  1087. if(inventory_id > 0){
  1088. MMerchantList.lock();
  1089. vector<MerchantItemInfo>::iterator itr;
  1090. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1091. if ((*itr).item_id == item_id)
  1092. amount = (*itr).quantity;
  1093. }
  1094. MMerchantList.unlock();
  1095. }
  1096. return amount;
  1097. }
  1098. int32 World::GetInventoryID(int32 merchant_id, int32 item_id){
  1099. int32 ret = 0;
  1100. MMerchantList.lock();
  1101. if(merchant_info.count(merchant_id) > 0){
  1102. MerchantInfo* info = merchant_info[merchant_id];
  1103. vector<MerchantItemInfo>::iterator itr;
  1104. int32 inventory_id = 0;
  1105. for(int i=info->inventory_ids.size()-1;i>=0;i--){
  1106. inventory_id = info->inventory_ids[i];
  1107. if(merchant_inventory_items.count(inventory_id) > 0){
  1108. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1109. if((*itr).item_id == item_id){
  1110. ret = inventory_id;
  1111. break;
  1112. }
  1113. }
  1114. if(ret > 0)
  1115. break;
  1116. }
  1117. }
  1118. }
  1119. MMerchantList.unlock();
  1120. return ret;
  1121. }
  1122. void World::DecreaseMerchantQuantity(int32 merchant_id, int32 item_id, int16 amount){
  1123. int16 total_left = GetMerchantItemQuantity(merchant_id, item_id);
  1124. if(total_left > 0 && total_left < 0xFFFF){
  1125. int32 inventory_id = GetInventoryID(merchant_id, item_id);
  1126. if(inventory_id > 0){
  1127. MMerchantList.lock();
  1128. vector<MerchantItemInfo>::iterator itr;
  1129. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1130. if ((*itr).item_id == item_id) {
  1131. if(total_left <= amount) {
  1132. merchant_inventory_items[inventory_id].erase(itr);
  1133. amount = 0;
  1134. break;
  1135. }
  1136. else
  1137. (*itr).quantity -= amount;
  1138. amount = (*itr).quantity;
  1139. }
  1140. }
  1141. MMerchantList.unlock();
  1142. }
  1143. }
  1144. }
  1145. MerchantInfo* World::GetMerchantInfo(int32 merchant_id){
  1146. MerchantInfo* ret = 0;
  1147. MMerchantList.lock();
  1148. if(merchant_info.count(merchant_id) > 0)
  1149. ret = merchant_info[merchant_id];
  1150. MMerchantList.unlock();
  1151. return ret;
  1152. }
  1153. void World::AddMerchantInfo(int32 merchant_id, MerchantInfo* info){
  1154. MMerchantList.lock();
  1155. if(merchant_info.count(merchant_id) > 0){
  1156. safe_delete(merchant_info[merchant_id]);
  1157. }
  1158. merchant_info[merchant_id] = info;
  1159. MMerchantList.unlock();
  1160. }
  1161. map<int32, MerchantInfo*>* World::GetMerchantInfo() {
  1162. return &merchant_info;
  1163. }
  1164. void World::DeleteMerchantsInfo(){
  1165. MMerchantList.lock();
  1166. map<int32, MerchantInfo*>::iterator itr;
  1167. for(itr = merchant_info.begin(); itr != merchant_info.end(); itr++){
  1168. safe_delete(itr->second);
  1169. }
  1170. merchant_info.clear();
  1171. MMerchantList.unlock();
  1172. }
  1173. void World::DeleteSpawns(){
  1174. //reloading = true;
  1175. //ClearLootTables();
  1176. /*
  1177. map<int32, NPC*>::iterator npc_list_iter;
  1178. for(npc_list_iter=npc_list.begin();npc_list_iter!=npc_list.end();npc_list_iter++) {
  1179. safe_delete(npc_list_iter->second);
  1180. }
  1181. npc_list.clear();
  1182. map<int32, Object*>::iterator object_list_iter;
  1183. for(object_list_iter=object_list.begin();object_list_iter!=object_list.end();object_list_iter++) {
  1184. safe_delete(object_list_iter->second);
  1185. }
  1186. object_list.clear();
  1187. map<int32, GroundSpawn*>::iterator groundspawn_list_iter;
  1188. for(groundspawn_list_iter=groundspawn_list.begin();groundspawn_list_iter!=groundspawn_list.end();groundspawn_list_iter++) {
  1189. safe_delete(groundspawn_list_iter->second);
  1190. }
  1191. groundspawn_list.clear();
  1192. map<int32, Widget*>::iterator widget_list_iter;
  1193. for(widget_list_iter=widget_list.begin();widget_list_iter!=widget_list.end();widget_list_iter++) {
  1194. safe_delete(widget_list_iter->second);
  1195. }
  1196. widget_list.clear();
  1197. map<int32, Sign*>::iterator sign_list_iter;
  1198. for(sign_list_iter=sign_list.begin();sign_list_iter!=sign_list.end();sign_list_iter++) {
  1199. safe_delete(sign_list_iter->second);
  1200. }
  1201. sign_list.clear();*/
  1202. map<int32, AppearanceData*>::iterator appearance_list_iter;
  1203. for(appearance_list_iter=npc_appearance_list.begin();appearance_list_iter!=npc_appearance_list.end();appearance_list_iter++) {
  1204. safe_delete(appearance_list_iter->second);
  1205. }
  1206. npc_appearance_list.clear();
  1207. /*
  1208. map<int32, vector<EntityCommand*>* >::iterator command_list_iter;
  1209. for(command_list_iter=entity_command_list.begin();command_list_iter!=entity_command_list.end();command_list_iter++) {
  1210. vector<EntityCommand*>* v = command_list_iter->second;
  1211. if(v){
  1212. for(int32 i=0;i<v->size();i++){
  1213. safe_delete(v->at(i));
  1214. }
  1215. safe_delete(v);
  1216. }
  1217. }
  1218. entity_command_list.clear();
  1219. */
  1220. //DeleteGroundSpawnItems();
  1221. //DeleteTransporters();
  1222. //DeleteTransporterMaps();
  1223. }
  1224. void World::ReloadGuilds() {
  1225. guild_list.GetGuilds()->clear(true);
  1226. database.LoadGuilds();
  1227. }
  1228. int8 World::GetClassID(const char* name){
  1229. return classes.GetClassID(name);
  1230. }
  1231. void World::WritePlayerStatistics() {
  1232. zone_list.WritePlayerStatistics();
  1233. }
  1234. void World::WriteServerStatistics() {
  1235. map<int32, Statistic*>::iterator itr;
  1236. Statistic* stat = 0;
  1237. for (itr = server_statistics.begin(); itr != server_statistics.end(); itr++) {
  1238. stat = itr->second;
  1239. if (stat->save_needed) {
  1240. stat->save_needed = false;
  1241. database.WriteServerStatistic(stat);
  1242. }
  1243. }
  1244. database.WriteServerStatisticsNeededQueries();
  1245. }
  1246. void World::AddServerStatistic(int32 stat_id, sint32 stat_value, int32 stat_date) {
  1247. if (server_statistics.count(stat_id) == 0) {
  1248. Statistic* stat = new Statistic;
  1249. stat->stat_id = stat_id;
  1250. stat->stat_value = stat_value;
  1251. stat->stat_date = stat_date;
  1252. stat->save_needed = false;
  1253. server_statistics[stat_id] = stat;
  1254. }
  1255. }
  1256. void World::UpdateServerStatistic(int32 stat_id, sint32 stat_value, bool overwrite) {
  1257. if (server_statistics.count(stat_id) == 0)
  1258. AddServerStatistic(stat_id, stat_value, 0);
  1259. Statistic* stat = server_statistics[stat_id];
  1260. overwrite == true ? stat->stat_value = stat_value : stat->stat_value += stat_value;
  1261. stat->stat_date = Timer::GetUnixTimeStamp();
  1262. stat->save_needed = true;
  1263. }
  1264. sint32 World::GetServerStatisticValue(int32 stat_id) {
  1265. if (server_statistics.count(stat_id) > 0)
  1266. return server_statistics[stat_id]->stat_value;
  1267. return 0;
  1268. }
  1269. void World::RemoveServerStatistics() {
  1270. map<int32, Statistic*>::iterator stat_itr;
  1271. for (stat_itr = server_statistics.begin(); stat_itr != server_statistics.end(); stat_itr++)
  1272. safe_delete(stat_itr->second);
  1273. server_statistics.clear();
  1274. }
  1275. void World::SendGroupQuests(PlayerGroup* group, Client* client){
  1276. return;
  1277. /*if(!group)
  1278. return;
  1279. GroupMemberInfo* info = 0;
  1280. MGroups.readlock(__FUNCTION__, __LINE__);
  1281. deque<GroupMemberInfo*>::iterator itr;
  1282. for(itr = group->members.begin(); itr != group->members.end(); itr++){
  1283. info = *itr;
  1284. if(info->client){
  1285. LogWrite(PLAYER__DEBUG, 0, "Player", "Send Quest Journal...");
  1286. info->client->SendQuestJournal(false, client);
  1287. client->SendQuestJournal(false, info->client);
  1288. }
  1289. }
  1290. MGroups.releasereadlock(__FUNCTION__, __LINE__);*/
  1291. }
  1292. /*void World::CheckRemoveGroupedPlayer(){
  1293. map<GroupMemberInfo*, int32>::iterator itr;
  1294. GroupMemberInfo* found = 0;
  1295. MGroups.readlock(__FUNCTION__, __LINE__);
  1296. for(itr = group_removal_pending.begin(); itr != group_removal_pending.end(); itr++){
  1297. if(itr->second < Timer::GetCurrentTime2()){
  1298. found = itr->first;
  1299. break;
  1300. }
  1301. }
  1302. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  1303. if(found){
  1304. if(!found->client || (found->client && found->client->IsConnected() == false))
  1305. DeleteGroupMember(found);
  1306. else{
  1307. MGroups.writelock(__FUNCTION__, __LINE__);
  1308. group_removal_pending.erase(found);
  1309. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  1310. }
  1311. }
  1312. }*/
  1313. void World::RejoinGroup(Client* client){
  1314. /*map<GroupMemberInfo*, int32>::iterator itr;
  1315. GroupMemberInfo* found = 0;
  1316. string name = string(client->GetPlayer()->GetName());
  1317. MGroups.readlock(__FUNCTION__, __LINE__);
  1318. PlayerGroup* group = 0;
  1319. for(int i = player_groups.size()-1;!found && i >= 0;i--){
  1320. group = player_groups[i];
  1321. for(int x=group->members.size()-1;x>=0; x--){
  1322. if(group->members[x]->name == name){
  1323. found = group->members[x];
  1324. break;
  1325. }
  1326. }
  1327. }
  1328. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  1329. if(found){
  1330. found->client = client;
  1331. client->GetPlayer()->SetGroup(found->group);
  1332. client->GetPlayer()->SetGroupMemberInfo(found);
  1333. }*/
  1334. }
  1335. void World::AddBonuses(ItemStatsValues* values, int16 type, sint32 value, Entity* entity){
  1336. if(values){
  1337. switch(type){
  1338. case ITEM_STAT_STR:{
  1339. values->str += value;
  1340. break;
  1341. }
  1342. case ITEM_STAT_STA:{
  1343. values->sta += value;
  1344. break;
  1345. }
  1346. case ITEM_STAT_AGI:{
  1347. values->agi += value;
  1348. break;
  1349. }
  1350. case ITEM_STAT_WIS:{
  1351. values->wis += value;
  1352. break;
  1353. }
  1354. case ITEM_STAT_INT:{
  1355. values->int_ += value;
  1356. break;
  1357. }
  1358. case ITEM_STAT_VS_SLASH:{
  1359. values->vs_slash += value;
  1360. break;
  1361. }
  1362. case ITEM_STAT_VS_CRUSH:{
  1363. values->vs_crush += value;
  1364. break;
  1365. }
  1366. case ITEM_STAT_VS_PIERCE:{
  1367. values->vs_pierce += value;
  1368. break;
  1369. }
  1370. case ITEM_STAT_VS_HEAT:{
  1371. values->vs_heat += value;
  1372. break;
  1373. }
  1374. case ITEM_STAT_VS_COLD:{
  1375. values->vs_cold += value;
  1376. break;
  1377. }
  1378. case ITEM_STAT_VS_MAGIC:{
  1379. values->vs_magic += value;
  1380. break;
  1381. }
  1382. case ITEM_STAT_VS_MENTAL:{
  1383. values->vs_mental += value;
  1384. break;
  1385. }
  1386. case ITEM_STAT_VS_DIVINE:{
  1387. values->vs_divine += value;
  1388. break;
  1389. }
  1390. case ITEM_STAT_VS_DISEASE:{
  1391. values->vs_disease += value;
  1392. break;
  1393. }
  1394. case ITEM_STAT_VS_POISON:{
  1395. values->vs_poison += value;
  1396. break;
  1397. }
  1398. case ITEM_STAT_HEALTH:{
  1399. values->health += value;
  1400. break;
  1401. }
  1402. case ITEM_STAT_POWER:{
  1403. values->power += value;
  1404. break;
  1405. }
  1406. case ITEM_STAT_CONCENTRATION:{
  1407. values->concentration += value;
  1408. break;
  1409. }
  1410. case ITEM_STAT_ABILITY_MODIFIER:{
  1411. values->ability_modifier += value;
  1412. break;
  1413. }
  1414. case ITEM_STAT_CRITICALMITIGATION:{
  1415. values->criticalmitigation += value;
  1416. break;
  1417. }
  1418. case ITEM_STAT_EXTRASHIELDBLOCKCHANCE:{
  1419. values->extrashieldblockchance += value;
  1420. break;
  1421. }
  1422. case ITEM_STAT_BENEFICIALCRITCHANCE:{
  1423. values->beneficialcritchance += value;
  1424. break;
  1425. }
  1426. case ITEM_STAT_CRITBONUS:{
  1427. values->critbonus += value;
  1428. break;
  1429. }
  1430. /*case ITEM_STAT_POTENCY:{
  1431. values->potency += value;
  1432. break;
  1433. }*/
  1434. case ITEM_STAT_HATEGAINMOD:{
  1435. values->hategainmod += value;
  1436. break;
  1437. }
  1438. case ITEM_STAT_ABILITYREUSESPEED:{
  1439. values->abilityreusespeed += value;
  1440. break;
  1441. }
  1442. case ITEM_STAT_ABILITYCASTINGSPEED:{
  1443. values->abilitycastingspeed += value;
  1444. break;
  1445. }
  1446. case ITEM_STAT_ABILITYRECOVERYSPEED:{
  1447. values->abilityrecoveryspeed += value;
  1448. break;
  1449. }
  1450. case ITEM_STAT_SPELLREUSESPEED:{
  1451. values->spellreusespeed += value;
  1452. break;
  1453. }
  1454. case ITEM_STAT_SPELLMULTIATTACKCHANCE:{
  1455. values->spellmultiattackchance += value;
  1456. break;
  1457. }
  1458. case ITEM_STAT_DPS:{
  1459. values->dps += value;
  1460. break;
  1461. }
  1462. case ITEM_STAT_ATTACKSPEED:{
  1463. values->attackspeed += value;
  1464. break;
  1465. }
  1466. case ITEM_STAT_MULTIATTACKCHANCE:{
  1467. values->multiattackchance += value;
  1468. break;
  1469. }
  1470. case ITEM_STAT_AEAUTOATTACKCHANCE:{
  1471. values->aeautoattackchance += value;
  1472. break;
  1473. }
  1474. case ITEM_STAT_STRIKETHROUGH:{
  1475. values->strikethrough += value;
  1476. break;
  1477. }
  1478. case ITEM_STAT_ACCURACY:{
  1479. values->accuracy += value;
  1480. break;
  1481. }
  1482. /*case ITEM_STAT_OFFENSIVESPEED:{
  1483. values->offensivespeed += value;
  1484. break;
  1485. }*/
  1486. default: {
  1487. if (entity)
  1488. entity->stats[type] += value;
  1489. break;
  1490. }
  1491. }
  1492. }
  1493. }
  1494. void World::CreateGuild(const char* guild_name, Client* leader, int32 group_id) {
  1495. deque<GroupMemberInfo*>::iterator itr;
  1496. GroupMemberInfo* gmi;
  1497. Guild *guild;
  1498. assert(guild_name);
  1499. guild = new Guild();
  1500. guild->SetName(guild_name);
  1501. guild->SetFormedDate(Timer::GetUnixTimeStamp());
  1502. database.LoadGuildDefaultRanks(guild);
  1503. database.LoadGuildDefaultEventFilters(guild);
  1504. database.SaveGuild(guild, true);
  1505. database.SaveGuildEvents(guild);
  1506. database.SaveGuildRanks(guild);
  1507. database.SaveGuildEventFilters(guild);
  1508. database.SaveGuildRecruiting(guild);
  1509. guild_list.AddGuild(guild);
  1510. if (leader && !leader->GetPlayer()->GetGuild())
  1511. guild->AddNewGuildMember(leader, 0, GUILD_RANK_LEADER);
  1512. database.SaveGuildMembers(guild);
  1513. if (leader && group_id > 0) {
  1514. GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1515. deque<GroupMemberInfo*>* members = GetGroupManager()->GetGroupMembers(group_id);
  1516. for (itr = members->begin(); itr != members->end(); itr++) {
  1517. gmi = *itr;
  1518. if (gmi->client && gmi->client != leader && !gmi->client->GetPlayer()->GetGuild())
  1519. guild->InvitePlayer(gmi->client, leader->GetPlayer()->GetName());
  1520. }
  1521. GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1522. }
  1523. }
  1524. void World::SaveGuilds() {
  1525. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  1526. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  1527. while (itr.Next()) {
  1528. Guild* guild = itr.second;
  1529. if (guild->GetSaveNeeded())
  1530. database.SaveGuild(guild);
  1531. if (guild->GetMemberSaveNeeded())
  1532. database.SaveGuildMembers(guild);
  1533. if (guild->GetEventsSaveNeeded())
  1534. database.SaveGuildEvents(guild);
  1535. if (guild->GetRanksSaveNeeded())
  1536. database.SaveGuildRanks(guild);
  1537. if (guild->GetEventFiltersSaveNeeded())
  1538. database.SaveGuildEventFilters(guild);
  1539. if (guild->GetPointsHistorySaveNeeded())
  1540. database.SaveGuildPointsHistory(guild);
  1541. if (guild->GetRecruitingSaveNeeded())
  1542. database.SaveGuildRecruiting(guild);
  1543. }
  1544. }
  1545. void World::PickRandomLottoDigits(int32* digits) {
  1546. if (digits) {
  1547. for (int32 i = 0; i < 6; i++) {
  1548. bool found = true;
  1549. int32 num = 0;
  1550. while (found) {
  1551. num = ((int32)rand() % 36) + 1;
  1552. for (int32 j = 0; j < 6; j++) {
  1553. if (digits[j] == num)
  1554. break;
  1555. if (j == 5)
  1556. found = false;
  1557. }
  1558. }
  1559. digits[i] = num;
  1560. }
  1561. }
  1562. }
  1563. void World::AddLottoPlayer(int32 character_id, int32 end_time) {
  1564. LottoPlayer* lp;
  1565. if (lotto_players.count(character_id) == 0) {
  1566. lp = new LottoPlayer;
  1567. lotto_players.Put(character_id, lp);
  1568. }
  1569. else
  1570. lp = lotto_players.Get(character_id);
  1571. lp->end_time = end_time;
  1572. lp->num_matches = 0;
  1573. lp->set = false;
  1574. }
  1575. void World::RemoveLottoPlayer(int32 character_id) {
  1576. if (lotto_players.count(character_id) > 0)
  1577. lotto_players.erase(character_id, false, true);
  1578. }
  1579. void World::SetLottoPlayerNumMatches(int32 character_id, int8 num_matches) {
  1580. if (lotto_players.count(character_id) > 0) {
  1581. lotto_players.Get(character_id)->num_matches = num_matches;
  1582. lotto_players.Get(character_id)->set = true;
  1583. }
  1584. }
  1585. void World::CheckLottoPlayers() {
  1586. MutexMap<int32, LottoPlayer*>::iterator itr = lotto_players.begin();
  1587. while (itr.Next()) {
  1588. LottoPlayer* lp = itr->second;
  1589. if (Timer::GetCurrentTime2() >= lp->end_time && lp->set) {
  1590. int8 num_matches = lp->num_matches;
  1591. LogWrite(PLAYER__DEBUG, 0, "Player", "Num matches: %u", lp->num_matches);
  1592. Client* client = zone_list.GetClientByCharID(itr->first);
  1593. if (client && num_matches >= 2) {
  1594. if (num_matches == 2) {
  1595. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 10 silver.");
  1596. client->SendPopupMessage(0, "Congratulations! You have won 10 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1597. client->GetPlayer()->AddCoins(1000);
  1598. client->GetPlayer()->GetZone()->SendCastSpellPacket(869, client->GetPlayer());
  1599. }
  1600. else if (num_matches == 3) {
  1601. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 50 silver.");
  1602. client->SendPopupMessage(0, "Congratulations! You have won 50 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1603. client->GetPlayer()->AddCoins(5000);
  1604. client->GetPlayer()->GetZone()->SendCastSpellPacket(870, client->GetPlayer());
  1605. }
  1606. else if (num_matches == 4) {
  1607. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 2 gold 50 silver.");
  1608. client->SendPopupMessage(0, "Congratulations! You have won 2 gold 50 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1609. client->GetPlayer()->AddCoins(25000);
  1610. client->GetPlayer()->GetZone()->SendCastSpellPacket(871, client->GetPlayer());
  1611. }
  1612. else if (num_matches == 5) {
  1613. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 25 gold.");
  1614. client->SendPopupMessage(0, "Congratulations! You have won 25 gold!", "", 2, 0xFF, 0xFF, 0x99);
  1615. client->GetPlayer()->AddCoins(250000);
  1616. client->GetPlayer()->GetZone()->SendCastSpellPacket(872, client->GetPlayer());
  1617. }
  1618. else if (num_matches == 6) {
  1619. Variable* var = variables.FindVariable("gambling_current_jackpot");
  1620. if (var) {
  1621. int64 jackpot = 0;
  1622. try {
  1623. jackpot = atoul(var->GetValue());
  1624. }
  1625. catch (...) {
  1626. jackpot = 10000;
  1627. }
  1628. char coin_message[128];
  1629. char message[512];
  1630. char announcement[512];
  1631. memset(coin_message, 0, sizeof(coin_message));
  1632. memset(message, 0, sizeof(message));
  1633. memset(announcement, 0, sizeof(announcement));
  1634. sprintf(coin_message, "%s", client->GetCoinMessage(jackpot).c_str());
  1635. sprintf(message, "Congratulations! You have won %s!", coin_message);
  1636. sprintf(announcement, "%s as won the jackpot containing a total of %s!", client->GetPlayer()->GetName(), coin_message);
  1637. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", coin_message);
  1638. client->SendPopupMessage(0, message, "", 2, 0xFF, 0xFF, 0x99);
  1639. zone_list.HandleGlobalAnnouncement(announcement);
  1640. client->GetPlayer()->AddCoins(jackpot);
  1641. client->GetPlayer()->GetZone()->SendCastSpellPacket(843, client->GetPlayer());
  1642. client->GetPlayer()->GetZone()->SendCastSpellPacket(1413, client->GetPlayer());
  1643. }
  1644. }
  1645. }
  1646. RemoveLottoPlayer(itr->first);
  1647. }
  1648. }
  1649. }
  1650. void World::AddHouseZone(int32 id, string name, int64 cost_coins, int32 cost_status, int64 upkeep_coins, int32 upkeep_status, int8 vault_slots, int8 alignment, int8 guild_level, int32 zone_id, int32 exit_zone_id, float exit_x, float exit_y, float exit_z, float exit_heading) {
  1651. MHouseZones.writelock(__FUNCTION__, __LINE__);
  1652. if (m_houseZones.count(id) == 0) {
  1653. HouseZone* hz = new HouseZone;
  1654. //ZeroMemory(hz, sizeof(HouseZone));
  1655. hz->id = id;
  1656. hz->name = name;
  1657. hz->cost_coin = cost_coins;
  1658. hz->cost_status = cost_status;
  1659. hz->upkeep_coin = upkeep_coins;
  1660. hz->upkeep_status = upkeep_status;
  1661. hz->vault_slots = vault_slots;
  1662. hz->alignment = alignment;
  1663. hz->guild_level = guild_level;
  1664. hz->zone_id = zone_id;
  1665. hz->exit_zone_id = exit_zone_id;
  1666. hz->exit_x = exit_x;
  1667. hz->exit_y = exit_y;
  1668. hz->exit_z = exit_z;
  1669. hz->exit_heading = exit_heading;
  1670. m_houseZones[id] = hz;
  1671. }
  1672. else {
  1673. LogWrite(WORLD__ERROR, 0, "Housing", "Duplicate house id (%u) for %s", id, name.c_str());
  1674. }
  1675. MHouseZones.releasewritelock(__FUNCTION__, __LINE__);
  1676. }
  1677. HouseZone* World::GetHouseZone(int32 id) {
  1678. HouseZone* ret = 0;
  1679. MHouseZones.readlock(__FUNCTION__, __LINE__);
  1680. if (m_houseZones.count(id) > 0)
  1681. ret = m_houseZones[id];
  1682. MHouseZones.releasereadlock(__FUNCTION__, __LINE__);
  1683. return ret;
  1684. }
  1685. void World::AddPlayerHouse(int32 char_id, int32 house_id, int64 unique_id, int32 instance_id, int32 upkeep_due, int64 escrow_coins, int32 escrow_status, string player_name) {
  1686. MPlayerHouses.writelock(__FUNCTION__, __LINE__);
  1687. if (m_playerHouses.count(house_id) == 0 || m_playerHouses[house_id].count(char_id) == 0) {
  1688. PlayerHouse* ph = new PlayerHouse;
  1689. ph->house_id = house_id;
  1690. ph->unique_id = unique_id;
  1691. ph->instance_id = instance_id;
  1692. ph->escrow_coins = escrow_coins;
  1693. ph->escrow_status = escrow_status;
  1694. ph->upkeep_due = upkeep_due;
  1695. ph->player_name = player_name;
  1696. m_playerHouses[house_id][char_id] = ph;
  1697. }
  1698. MPlayerHouses.releasewritelock(__FUNCTION__, __LINE__);
  1699. }
  1700. PlayerHouse* World::GetPlayerHouseByHouseID(int32 char_id, int32 house_id) {
  1701. PlayerHouse* ret = 0;
  1702. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1703. if (m_playerHouses.count(house_id) > 0 && m_playerHouses[house_id].count(char_id) > 0)
  1704. ret = m_playerHouses[house_id][char_id];
  1705. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1706. return ret;
  1707. }
  1708. PlayerHouse* World::GetPlayerHouseByUniqueID(int64 unique_id) {
  1709. PlayerHouse* ret = 0;
  1710. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1711. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1712. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1713. map<int32, PlayerHouse*>::iterator itr2;
  1714. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  1715. if (itr2->second->unique_id == unique_id) {
  1716. ret = itr2->second;
  1717. break;
  1718. }
  1719. }
  1720. if (ret)
  1721. break;
  1722. }
  1723. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1724. return ret;
  1725. }
  1726. PlayerHouse* World::GetPlayerHouseByInstanceID(int32 instance_id) {
  1727. PlayerHouse* ret = 0;
  1728. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1729. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1730. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1731. map<int32, PlayerHouse*>::iterator itr2;
  1732. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  1733. if (itr2->second->instance_id == instance_id) {
  1734. ret = itr2->second;
  1735. break;
  1736. }
  1737. }
  1738. if (ret)
  1739. break;
  1740. }
  1741. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1742. return ret;
  1743. }
  1744. vector<PlayerHouse*> World::GetAllPlayerHouses(int32 char_id) {
  1745. vector<PlayerHouse*> ret;
  1746. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1747. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1748. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1749. if (itr->second.count(char_id) > 0)
  1750. ret.push_back(itr->second[char_id]);
  1751. }
  1752. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1753. return ret;
  1754. }
  1755. vector<PlayerHouse*> World::GetAllPlayerHousesByHouseID(int32 house_id) {
  1756. vector<PlayerHouse*> ret;
  1757. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1758. if (m_houseZones.count(house_id) > 0) {
  1759. map<int32, PlayerHouse*>::iterator itr;
  1760. for (itr = m_playerHouses[house_id].begin(); itr != m_playerHouses[house_id].end(); itr++)
  1761. ret.push_back(itr->second);
  1762. }
  1763. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1764. return ret;
  1765. }
  1766. void World::PopulateTOVStatMap() {
  1767. //This function populates a map that converts changed CoE to ToV stats
  1768. tov_itemstat_conversion[0] = TOV_ITEM_STAT_HPREGEN;
  1769. tov_itemstat_conversion[1] = TOV_ITEM_STAT_MANAREGEN;
  1770. tov_itemstat_conversion[2] = TOV_ITEM_STAT_HPREGENPPT;
  1771. tov_itemstat_conversion[3] = TOV_ITEM_STAT_MPREGENPPT;
  1772. tov_itemstat_conversion[4] = TOV_ITEM_STAT_COMBATHPREGENPPT;
  1773. tov_itemstat_conversion[5] = TOV_ITEM_STAT_COMBATMPREGENPPT;
  1774. tov_itemstat_conversion[6] = TOV_ITEM_STAT_MAXHP;
  1775. tov_itemstat_conversion[7] = TOV_ITEM_STAT_MAXHPPERC;
  1776. tov_itemstat_conversion[8] = TOV_ITEM_STAT_MAXHPPERCFINAL;
  1777. tov_itemstat_conversion[9] = TOV_ITEM_STAT_SPEED;
  1778. tov_itemstat_conversion[10] = TOV_ITEM_STAT_SLOW;
  1779. tov_itemstat_conversion[11] = TOV_ITEM_STAT_MOUNTSPEED;
  1780. tov_itemstat_conversion[12] = TOV_ITEM_STAT_MOUNTAIRSPEED;
  1781. tov_itemstat_conversion[13] = TOV_ITEM_STAT_LEAPSPEED;
  1782. tov_itemstat_conversion[14] = TOV_ITEM_STAT_LEAPTIME;
  1783. tov_itemstat_conversion[15] = TOV_ITEM_STAT_GLIDEEFFICIENCY;
  1784. tov_itemstat_conversion[16] = TOV_ITEM_STAT_OFFENSIVESPEED;
  1785. tov_itemstat_conversion[17] = TOV_ITEM_STAT_ATTACKSPEED;
  1786. tov_itemstat_conversion[18] = 698;
  1787. tov_itemstat_conversion[19] = TOV_ITEM_STAT_MAXMANA;
  1788. tov_itemstat_conversion[20] = TOV_ITEM_STAT_MAXMANAPERC;
  1789. tov_itemstat_conversion[21] = TOV_ITEM_STAT_MAXATTPERC;
  1790. tov_itemstat_conversion[22] = TOV_ITEM_STAT_BLURVISION;
  1791. tov_itemstat_conversion[23] = TOV_ITEM_STAT_MAGICLEVELIMMUNITY;
  1792. tov_itemstat_conversion[24] = TOV_ITEM_STAT_HATEGAINMOD;
  1793. tov_itemstat_conversion[25] = TOV_ITEM_STAT_COMBATEXPMOD;
  1794. tov_itemstat_conversion[26] = TOV_ITEM_STAT_TRADESKILLEXPMOD;
  1795. tov_itemstat_conversion[27] = TOV_ITEM_STAT_ACHIEVEMENTEXPMOD;
  1796. tov_itemstat_conversion[28] = TOV_ITEM_STAT_SIZEMOD;
  1797. tov_itemstat_conversion[29] = TOV_ITEM_STAT_DPS;
  1798. tov_itemstat_conversion[30] = 698;
  1799. tov_itemstat_conversion[31] = TOV_ITEM_STAT_STEALTH;
  1800. tov_itemstat_conversion[32] = TOV_ITEM_STAT_INVIS;
  1801. tov_itemstat_conversion[33] = TOV_ITEM_STAT_SEESTEALTH;
  1802. tov_itemstat_conversion[34] = TOV_ITEM_STAT_SEEINVIS;
  1803. tov_itemstat_conversion[35] = TOV_ITEM_STAT_EFFECTIVELEVELMOD;
  1804. tov_itemstat_conversion[36] = TOV_ITEM_STAT_RIPOSTECHANCE;
  1805. tov_itemstat_conversion[37] = TOV_ITEM_STAT_PARRYCHANCE;
  1806. tov_itemstat_conversion[38] = TOV_ITEM_STAT_DODGECHANCE;
  1807. tov_itemstat_conversion[39] = TOV_ITEM_STAT_AEAUTOATTACKCHANCE;
  1808. tov_itemstat_conversion[40] = 698;
  1809. tov_itemstat_conversion[41] = TOV_ITEM_STAT_MULTIATTACKCHANCE;
  1810. tov_itemstat_conversion[42] = 698;
  1811. tov_itemstat_conversion[43] = 698;
  1812. tov_itemstat_conversion[44] = 698;
  1813. tov_itemstat_conversion[45] = TOV_ITEM_STAT_SPELLMULTIATTACKCHANCE;
  1814. tov_itemstat_conversion[46] = 698;
  1815. tov_itemstat_conversion[47] = TOV_ITEM_STAT_FLURRY;
  1816. tov_itemstat_conversion[48] = 698;
  1817. tov_itemstat_conversion[49] = TOV_ITEM_STAT_MELEEDAMAGEMULTIPLIER;
  1818. tov_itemstat_conversion[50] = TOV_ITEM_STAT_EXTRAHARVESTCHANCE;
  1819. tov_itemstat_conversion[51] = TOV_ITEM_STAT_EXTRASHIELDBLOCKCHANCE;
  1820. tov_itemstat_conversion[52] = TOV_ITEM_STAT_ITEMHPREGENPPT;
  1821. tov_itemstat_conversion[53] = TOV_ITEM_STAT_ITEMPPREGENPPT;
  1822. tov_itemstat_conversion[54] = TOV_ITEM_STAT_MELEECRITCHANCE;
  1823. tov_itemstat_conversion[55] = TOV_ITEM_STAT_CRITAVOIDANCE;
  1824. tov_itemstat_conversion[56] = TOV_ITEM_STAT_BENEFICIALCRITCHANCE;
  1825. tov_itemstat_conversion[57] = TOV_ITEM_STAT_CRITBONUS;
  1826. tov_itemstat_conversion[58] = 698;
  1827. tov_itemstat_conversion[59] = TOV_ITEM_STAT_POTENCY;
  1828. tov_itemstat_conversion[60] = 698;
  1829. tov_itemstat_conversion[61] = TOV_ITEM_STAT_UNCONSCIOUSHPMOD;
  1830. tov_itemstat_conversion[62] = TOV_ITEM_STAT_ABILITYREUSESPEED;
  1831. tov_itemstat_conversion[63] = TOV_ITEM_STAT_ABILITYRECOVERYSPEED;
  1832. tov_itemstat_conversion[64] = TOV_ITEM_STAT_ABILITYCASTINGSPEED;
  1833. tov_itemstat_conversion[65] = TOV_ITEM_STAT_SPELLREUSESPEED;
  1834. tov_itemstat_conversion[66] = TOV_ITEM_STAT_MELEEWEAPONRANGE;
  1835. tov_itemstat_conversion[67] = TOV_ITEM_STAT_RANGEDWEAPONRANGE;
  1836. tov_itemstat_conversion[68] = TOV_ITEM_STAT_FALLINGDAMAGEREDUCTION;
  1837. tov_itemstat_conversion[69] = TOV_ITEM_STAT_RIPOSTEDAMAGE;
  1838. tov_itemstat_conversion[70] = TOV_ITEM_STAT_MINIMUMDEFLECTIONCHANCE;
  1839. tov_itemstat_conversion[71] = TOV_ITEM_STAT_MOVEMENTWEAVE;
  1840. tov_itemstat_conversion[72] = TOV_ITEM_STAT_COMBATHPREGEN;
  1841. tov_itemstat_conversion[73] = TOV_ITEM_STAT_COMBATMANAREGEN;
  1842. tov_itemstat_conversion[74] = TOV_ITEM_STAT_CONTESTSPEEDBOOST;
  1843. tov_itemstat_conversion[75] = TOV_ITEM_STAT_TRACKINGAVOIDANCE;
  1844. tov_itemstat_conversion[76] = TOV_ITEM_STAT_STEALTHINVISSPEEDMOD;
  1845. tov_itemstat_conversion[77] = TOV_ITEM_STAT_LOOT_COIN;
  1846. tov_itemstat_conversion[78] = TOV_ITEM_STAT_ARMORMITIGATIONINCREASE;
  1847. tov_itemstat_conversion[79] = TOV_ITEM_STAT_AMMOCONSERVATION;
  1848. tov_itemstat_conversion[80] = TOV_ITEM_STAT_STRIKETHROUGH;
  1849. tov_itemstat_conversion[81] = TOV_ITEM_STAT_STATUSBONUS;
  1850. tov_itemstat_conversion[82] = TOV_ITEM_STAT_ACCURACY;
  1851. tov_itemstat_conversion[83] = TOV_ITEM_STAT_COUNTERSTRIKE;
  1852. tov_itemstat_conversion[84] = TOV_ITEM_STAT_SHIELDBASH;
  1853. tov_itemstat_conversion[85] = TOV_ITEM_STAT_WEAPONDAMAGEBONUS;
  1854. tov_itemstat_conversion[86] = 698;
  1855. tov_itemstat_conversion[87] = TOV_ITEM_STAT_WEAPONDAMAGEBONUSMELEEONLY;
  1856. tov_itemstat_conversion[88] = TOV_ITEM_STAT_ADDITIONALRIPOSTECHANCE;
  1857. tov_itemstat_conversion[89] = TOV_ITEM_STAT_PVPTOUGHNESS;
  1858. tov_itemstat_conversion[90] = TOV_ITEM_STAT_PVPLETHALITY;
  1859. tov_itemstat_conversion[91] = TOV_ITEM_STAT_STAMINABONUS;
  1860. tov_itemstat_conversion[92] = TOV_ITEM_STAT_WISDOMMITBONUS;
  1861. tov_itemstat_conversion[93] = TOV_ITEM_STAT_HEALRECEIVE;
  1862. tov_itemstat_conversion[94] = TOV_ITEM_STAT_HEALRECEIVEPERC;
  1863. tov_itemstat_conversion[95] = TOV_ITEM_STAT_PVPCRITICALMITIGATION;
  1864. tov_itemstat_conversion[96] = TOV_ITEM_STAT_BASEAVOIDANCEBONUS;
  1865. tov_itemstat_conversion[97] = TOV_ITEM_STAT_INCOMBATSAVAGERYREGEN;
  1866. tov_itemstat_conversion[98] = TOV_ITEM_STAT_OUTOFCOMBATSAVAGERYREGEN;
  1867. tov_itemstat_conversion[99] = TOV_ITEM_STAT_SAVAGERYREGEN;
  1868. tov_itemstat_conversion[100] = TOV_ITEM_STAT_SAVAGERYGAINMOD;
  1869. tov_itemstat_conversion[101] = TOV_ITEM_STAT_MAXSAVAGERYLEVEL;
  1870. }
  1871. int32 World::LoadItemBlueStats() {
  1872. Query query;
  1873. MYSQL_ROW row;
  1874. int32 count = 0;
  1875. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT version_range1,version_range2,emu_stat,name,stat from itemstats");
  1876. if (result && mysql_num_rows(result) > 0) {
  1877. while (result && (row = mysql_fetch_row(result))) {
  1878. count++;
  1879. if (atoi(row[0]) >= 63119) //KA
  1880. ka_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1881. else if (atoi(row[0]) >= 57101) // ToV
  1882. tov_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1883. else if (atoi(row[0]) >= 1193) // CoE
  1884. coe_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1885. else if (atoi(row[0]) >= 1096) // DoV
  1886. dov_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1887. }
  1888. }
  1889. return count;
  1890. }
  1891. sint16 World::GetItemStatTOVValue(sint16 subtype) {
  1892. return (tov_itemstat_conversion[subtype] - 600);
  1893. }
  1894. sint16 World::GetItemStatDOVValue(sint16 subtype) {
  1895. return (dov_itemstat_conversion[subtype] - 600);
  1896. }
  1897. sint16 World::GetItemStatCOEValue(sint16 subtype) {
  1898. return (coe_itemstat_conversion[subtype] - 600);
  1899. }
  1900. sint16 World::GetItemStatKAValue(sint16 subtype) {
  1901. return (ka_itemstat_conversion[subtype] - 600);
  1902. }
  1903. bool World::CheckTempBugCRC(char* msg)
  1904. {
  1905. MBugReport.writelock();
  1906. sint32 crc = GetItemNameCrc(std::string(msg));
  1907. if (bug_report_crc.count(crc) > 0)
  1908. {
  1909. MBugReport.releasewritelock();
  1910. return true;
  1911. }
  1912. else
  1913. bug_report_crc.insert(make_pair(crc, true));
  1914. MBugReport.releasewritelock();
  1915. return false;
  1916. }
  1917. #ifdef WIN32
  1918. ulong World::GetCurrentThreadID(){
  1919. return GetCurrentThreadId();
  1920. }
  1921. int64 World::GetThreadUsageCPUTime(){
  1922. HANDLE handle = GetCurrentThread();
  1923. int64 lpCreationTime;
  1924. int64 lpExitTime;
  1925. int64 lpKernelTime;
  1926. int64 lpUserTime;
  1927. if(GetThreadTimes(handle, (FILETIME*)&lpCreationTime, (FILETIME*)&lpExitTime, (FILETIME*)&lpKernelTime, (FILETIME*)&lpUserTime))
  1928. return lpKernelTime + lpUserTime;
  1929. return 0;
  1930. }
  1931. #else
  1932. #endif