World.cpp 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613
  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. #include <boost/algorithm/string.hpp>
  48. MasterQuestList master_quest_list;
  49. MasterItemList master_item_list;
  50. MasterSpellList master_spell_list;
  51. MasterTraitList master_trait_list;
  52. MasterHeroicOPList master_ho_list;
  53. MasterSkillList master_skill_list;
  54. MasterFactionList master_faction_list;
  55. MasterCollectionList master_collection_list;
  56. MasterAchievementList master_achievement_list;
  57. MasterRecipeList master_recipe_list;
  58. MasterRecipeBookList master_recipebook_list;
  59. MasterTradeskillEventsList master_tradeskillevent_list;
  60. MasterAAList master_aa_list;
  61. MasterRaceTypeList race_types_list;
  62. MasterAANodeList master_tree_nodes;
  63. ClientList client_list;
  64. ZoneList zone_list;
  65. ZoneAuth zone_auth;
  66. int32 Spawn::next_id = 1;
  67. int32 WorldDatabase::next_id = 0;
  68. Commands commands;
  69. Variables variables;
  70. VisualStates visual_states;
  71. Appearances master_appearance_list;
  72. Classes classes;
  73. Races races;
  74. map<int16,OpcodeManager*>EQOpcodeManager;
  75. map<int16, int16> EQOpcodeVersions;
  76. WorldDatabase database;
  77. GuildList guild_list;
  78. IRC irc;
  79. Chat chat;
  80. extern ConfigReader configReader;
  81. extern LoginServer loginserver;
  82. extern World world;
  83. extern RuleManager rule_manager;
  84. 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), watchdog_timer(10000) {
  85. save_time_timer.Start();
  86. time_tick_timer.Start();
  87. vitality_timer.Start();
  88. player_stats_timer.Start();
  89. server_stats_timer.Start();
  90. //remove_grouped_player.Start();
  91. guilds_timer.Start();
  92. lotto_players_timer.Start();
  93. watchdog_timer.Start();
  94. xp_rate = -1;
  95. ts_xp_rate = -1;
  96. vitality_frequency = 0xFFFFFFFF;
  97. vitality_amount = -1;
  98. last_checked_time = 0;
  99. items_loaded = false;
  100. spells_loaded = false;
  101. achievments_loaded = false;
  102. merchant_inventory_items.clear();
  103. MHouseZones.SetName("World::m_houseZones");
  104. MPlayerHouses.SetName("World::m_playerHouses");
  105. MWorldMaps.SetName("World::MWorldMaps");
  106. MWorldRegionMaps.SetName("World::MWorldRegionMaps");
  107. }
  108. World::~World(){
  109. // 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
  110. DeleteSpawns();
  111. if(database.GetStatus() == database.Connected)
  112. WriteServerStatistics();
  113. RemoveServerStatistics();
  114. DeleteMerchantsInfo();
  115. MutexMap<int32, LottoPlayer*>::iterator itr = lotto_players.begin();
  116. while (itr.Next())
  117. safe_delete(itr->second);
  118. map<int32, HouseZone*>::iterator itr2;
  119. for (itr2 = m_houseZones.begin(); itr2 != m_houseZones.end(); itr2++)
  120. safe_delete(itr2->second);
  121. m_houseZones.clear();
  122. tov_itemstat_conversion.clear();
  123. PurgeStartingLists();
  124. map<std::string, RegionMapRange*>::iterator itr3;
  125. for (itr3 = region_maps.begin(); itr3 != region_maps.end(); itr3++)
  126. safe_delete(itr3->second);
  127. map<std::string, MapRange*>::iterator itr4;
  128. for (itr4 = maps.begin(); itr4 != maps.end(); itr4++)
  129. safe_delete(itr4->second);
  130. }
  131. void World::init(){
  132. WorldDatabase::next_id = database.GetMaxHotBarID();
  133. LogWrite(COMMAND__DEBUG, 1, "Command", "-Loading Commands...");
  134. database.LoadCommandList();
  135. LogWrite(COMMAND__DEBUG, 1, "Command", "-Load Commands complete!");
  136. LogWrite(FACTION__DEBUG, 1, "Faction", "-Loading Factions...");
  137. database.LoadFactionList();
  138. LogWrite(FACTION__DEBUG, 1, "Faction", "-Load Factions complete!...");
  139. LogWrite(SKILL__DEBUG, 1, "Skill", "-Loading Skills...");
  140. database.LoadSkills();
  141. LogWrite(SKILL__DEBUG, 1, "Skill", "-Load Skills complete...");
  142. LogWrite(WORLD__DEBUG, 1, "World", "-Loading `variables`...");
  143. database.LoadGlobalVariables();
  144. LogWrite(WORLD__DEBUG, 1, "World", "-Load `variables` complete!");
  145. LogWrite(WORLD__DEBUG, 1, "World", "-Loading `appearances`...");
  146. database.LoadAppearanceMasterList();
  147. LogWrite(WORLD__DEBUG, 1, "World", "-Load `appearances` complete!");
  148. LogWrite(WORLD__DEBUG, 1, "World", "-Loading `visual_states`...");
  149. database.LoadVisualStates();
  150. LogWrite(WORLD__DEBUG, 1, "World", "-Load `visual states` complete!");
  151. LoadStartingLists();
  152. LogWrite(WORLD__DEBUG, 1, "World", "-Setting system parameters...");
  153. Variable* var = variables.FindVariable("gametime");
  154. const char* time_string = 0;
  155. char default_time[] = "0/0/3800 8:30";
  156. if(var)
  157. time_string = var->GetValue();
  158. if(!time_string)
  159. time_string = default_time;
  160. int year, month, day, hour, minute;
  161. sscanf (time_string, "%d/%d/%d %d:%d", &month, &day, &year, &hour, &minute);
  162. LogWrite(WORLD__DEBUG, 3, "World", "--Setting World Time to %s...", time_string);
  163. world_time.month = month;
  164. world_time.day = day;
  165. world_time.year = year;
  166. world_time.hour = hour;
  167. world_time.minute = minute;
  168. LogWrite(WORLD__DEBUG, 3, "World", "--Loading Vitality Information...");
  169. LoadVitalityInformation();
  170. LogWrite(WORLD__DEBUG, 3, "World", "--Loading Server Statistics...");
  171. database.LoadServerStatistics();
  172. LogWrite(WORLD__DEBUG, 3, "World", "--Setting Server Start Time...");
  173. UpdateServerStatistic(STAT_SERVER_START_TIME, Timer::GetUnixTimeStamp(), true);
  174. LogWrite(WORLD__DEBUG, 3, "World", "--Resetting Accepted Connections to 0...");
  175. UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 0, true);
  176. LogWrite(WORLD__DEBUG, 3, "World", "--Resetting Active Zones to 0...");
  177. UpdateServerStatistic(STAT_SERVER_NUM_ACTIVE_ZONES, 0, true);
  178. // Clear all online players at server startup
  179. LogWrite(WORLD__DEBUG, 3, "World", "--Resetting characters online flags...");
  180. database.ToggleCharacterOnline();
  181. LogWrite(WORLD__DEBUG, 1, "World", "-Set system parameters complete!");
  182. LogWrite(RULESYS__DEBUG, 1, "Rules", "-Loading Rule Sets...");
  183. database.LoadRuleSets();
  184. LogWrite(RULESYS__DEBUG, 1, "Rules", "-Load Rule Sets complete!");
  185. LogWrite(CHAT__DEBUG, 1, "IRC", "-Starting IRC thread...");
  186. LoadItemBlueStats();
  187. //PopulateTOVStatMap();
  188. group_buff_updates.Start(rule_manager.GetGlobalRule(R_Client, GroupSpellsTimer)->GetInt32());
  189. irc.Start();
  190. }
  191. PacketStruct* World::GetWorldTime(int16 version){
  192. MWorldTime.readlock(__FUNCTION__, __LINE__);
  193. PacketStruct* packet = configReader.getStruct("WS_GameWorldTime", version);
  194. if(packet){
  195. packet->setDataByName("year", world_time.year);
  196. packet->setDataByName("month", world_time.month);
  197. packet->setDataByName("day", world_time.day);
  198. packet->setDataByName("hour", world_time.hour);
  199. packet->setDataByName("minute", world_time.minute);
  200. packet->setDataByName("unknown", 250);
  201. packet->setDataByName("unix_time", Timer::GetUnixTimeStamp());
  202. packet->setDataByName("unknown2", 1);
  203. }
  204. MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  205. return packet;
  206. }
  207. float World::GetXPRate(){
  208. xp_rate = rule_manager.GetGlobalRule(R_Player, XPMultiplier)->GetFloat();
  209. LogWrite(WORLD__DEBUG, 0, "World", "Setting Global XP Rate to: %.2f", xp_rate);
  210. return xp_rate;
  211. }
  212. float World::GetTSXPRate(){
  213. ts_xp_rate = rule_manager.GetGlobalRule(R_Player, TSXPMultiplier)->GetFloat();
  214. LogWrite(WORLD__DEBUG, 0, "World", "Setting Global Tradeskill XP Rate to: %.2f", ts_xp_rate);
  215. return ts_xp_rate;
  216. }
  217. void World::Process(){
  218. if(last_checked_time > Timer::GetCurrentTime2())
  219. return;
  220. last_checked_time = Timer::GetCurrentTime2() + 1000;
  221. if(save_time_timer.Check())
  222. {
  223. MWorldTime.readlock(__FUNCTION__, __LINE__);
  224. database.SaveWorldTime(&world_time);
  225. MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  226. }
  227. if(time_tick_timer.Check())
  228. {
  229. MWorldTime.writelock(__FUNCTION__, __LINE__);
  230. WorldTimeTick();
  231. MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  232. }
  233. if(vitality_timer.Check())
  234. UpdateVitality();
  235. if (player_stats_timer.Check())
  236. WritePlayerStatistics();
  237. if (server_stats_timer.Check())
  238. WriteServerStatistics();
  239. /*if(remove_grouped_player.Check())
  240. CheckRemoveGroupedPlayer();*/
  241. if (group_buff_updates.Check())
  242. GetGroupManager()->UpdateGroupBuffs();
  243. if (guilds_timer.Check())
  244. SaveGuilds();
  245. if (lotto_players_timer.Check())
  246. CheckLottoPlayers();
  247. if(watchdog_timer.Check())
  248. zone_list.WatchdogHeartbeat();
  249. }
  250. vector<Variable*>* World::GetClientVariables(){
  251. return variables.GetVariables("cl_");
  252. }
  253. void World::LoadVitalityInformation()
  254. {
  255. int32 timestamp = Timer::GetUnixTimeStamp();
  256. int32 diff = 0;
  257. // fetch vitalitytimer value from `variables` table
  258. Variable* timer_var = variables.FindVariable("vitalitytimer");
  259. if(timer_var)
  260. {
  261. try
  262. {
  263. diff = timestamp - atoul(timer_var->GetValue());
  264. diff *= 1000; //convert seconds to milliseconds
  265. }
  266. catch(...)
  267. {
  268. LogWrite(WORLD__ERROR, 0, "World", "Error parsing vitalitytimer, value: %s", timer_var->GetValue());
  269. }
  270. }
  271. // Now using Rules System to set vitality parameters
  272. vitality_amount = rule_manager.GetGlobalRule(R_Player, VitalityAmount)->GetFloat();
  273. vitality_frequency = rule_manager.GetGlobalRule(R_Player, VitalityFrequency)->GetInt32();
  274. vitality_frequency *= 1000; //convert seconds to milliseconds
  275. if(diff >= vitality_frequency)
  276. UpdateVitality(); //update now
  277. else
  278. vitality_timer.SetTimer(vitality_frequency - diff);
  279. }
  280. void World::UpdateVitality()
  281. {
  282. // push new vitalitytimer to `variables` table
  283. database.UpdateVitality(Timer::GetUnixTimeStamp(), vitality_amount);
  284. if(vitality_timer.GetDuration() != vitality_frequency)
  285. vitality_timer.SetTimer(vitality_frequency);
  286. zone_list.UpdateVitality(vitality_amount);
  287. }
  288. void ZoneList::UpdateVitality(float amount)
  289. {
  290. list<ZoneServer*>::iterator zone_iter;
  291. ZoneServer* tmp = 0;
  292. MZoneList.readlock(__FUNCTION__, __LINE__);
  293. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++)
  294. {
  295. tmp = *zone_iter;
  296. if(tmp)
  297. tmp->UpdateVitality(amount);
  298. }
  299. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  300. }
  301. void ZoneList::SendTimeUpdate()
  302. {
  303. list<ZoneServer*>::iterator zone_iter;
  304. ZoneServer* tmp = 0;
  305. MZoneList.readlock(__FUNCTION__, __LINE__);
  306. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++)
  307. {
  308. tmp = *zone_iter;
  309. if(tmp && !tmp->isZoneShuttingDown())
  310. tmp->WorldTimeUpdateTrigger();
  311. }
  312. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  313. }
  314. // should already be ran inside MWorldTime
  315. void World::WorldTimeTick(){
  316. world_time.minute++;
  317. //I know it looks complicated, but the nested ifs are to avoid checking all of them every 3 seconds
  318. if(world_time.minute >= 60){ // >= in case of bad time from db
  319. world_time.minute = 0;
  320. world_time.hour++;
  321. if(world_time.hour >= 24){
  322. world_time.hour = 0;
  323. world_time.day++;
  324. if(world_time.day>=30){
  325. world_time.day = 0;
  326. world_time.month++;
  327. if(world_time.month >= 12){
  328. world_time.month = 0;
  329. world_time.year++;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. ZoneList::ZoneList() {
  336. MZoneList.SetName("ZoneList::MZoneList");
  337. }
  338. ZoneList::~ZoneList() {
  339. list<ZoneServer*>::iterator zone_iter;
  340. ZoneServer* zs = 0;
  341. for(zone_iter=zlist.begin(); zone_iter!=zlist.end();){
  342. zs = *zone_iter;
  343. zone_iter = zlist.erase(zone_iter);
  344. safe_delete(zs);
  345. }
  346. }
  347. void ZoneList::CheckFriendList(Client* client) {
  348. LogWrite(WORLD__DEBUG, 0, "World", "Sending FriendList...");
  349. MClientList.lock();
  350. map<string,Client*>::iterator itr;
  351. for(itr = client_map.begin(); itr != client_map.end(); itr++){
  352. if(itr->second != client && itr->second){
  353. if(itr->second->GetPlayer()->IsFriend(client->GetPlayer()->GetName())){
  354. itr->second->SendFriendList();
  355. itr->second->Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Friend: %s has logged in.", client->GetPlayer()->GetName());
  356. }
  357. }
  358. }
  359. MClientList.unlock();
  360. }
  361. void ZoneList::CheckFriendZoned(Client* client){
  362. MClientList.lock();
  363. map<string,Client*>::iterator itr;
  364. for(itr = client_map.begin(); itr != client_map.end(); itr++){
  365. if(itr->second != client && itr->second){
  366. if(itr->second->GetPlayer()->IsFriend(client->GetPlayer()->GetName())){
  367. itr->second->SendFriendList();
  368. }
  369. }
  370. }
  371. MClientList.unlock();
  372. }
  373. bool ZoneList::HandleGlobalChatMessage(Client* from, char* to, int16 channel, const char* message, const char* channel_name){
  374. if (!from) {
  375. LogWrite(WORLD__ERROR, 0, "World", "HandleGlobalChatMessage() called with an invalid client");
  376. return false;
  377. }
  378. if(channel == CHANNEL_PRIVATE_TELL){
  379. Client* find_client = zone_list.GetClientByCharName(to);
  380. if(!find_client || find_client->GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  381. return false;
  382. else if(find_client == from)
  383. {
  384. from->Message(CHANNEL_COLOR_RED,"You must be very lonely...(ERROR: Cannot send tell to self)");
  385. }
  386. else
  387. {
  388. const char* whoto = find_client->GetPlayer()->GetName();
  389. find_client->HandleTellMessage(from, message, whoto);
  390. from->HandleTellMessage(from, message, whoto);
  391. if (find_client->GetPlayer()->get_character_flag(CF_AFK)) {
  392. find_client->HandleTellMessage(find_client, find_client->GetPlayer()->GetAwayMessage().c_str(),whoto);
  393. from->HandleTellMessage(find_client, find_client->GetPlayer()->GetAwayMessage().c_str(),whoto);
  394. }
  395. }
  396. }
  397. else if(channel == CHANNEL_GROUP_SAY) {
  398. GroupMemberInfo* gmi = from->GetPlayer()->GetGroupMemberInfo();
  399. if(gmi)
  400. world.GetGroupManager()->GroupMessage(gmi->group_id, message);
  401. }
  402. else{
  403. list<ZoneServer*>::iterator zone_iter;
  404. ZoneServer* zs = 0;
  405. MZoneList.readlock(__FUNCTION__, __LINE__);
  406. for(zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  407. zs = *zone_iter;
  408. if(zs)
  409. zs->HandleChatMessage(from->GetPlayer(), to, channel, message, 0, channel_name);
  410. }
  411. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  412. }
  413. return true;
  414. }
  415. void ZoneList::LoadSpellProcess(){
  416. list<ZoneServer*>::iterator zone_iter;
  417. ZoneServer* zone = 0;
  418. MZoneList.readlock(__FUNCTION__, __LINE__);
  419. for (zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  420. zone = *zone_iter;
  421. if (zone)
  422. zone->LoadSpellProcess();
  423. }
  424. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  425. }
  426. void ZoneList::DeleteSpellProcess(){
  427. list<ZoneServer*>::iterator zone_iter;
  428. ZoneServer* zone = 0;
  429. MZoneList.readlock(__FUNCTION__, __LINE__);
  430. for (zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  431. zone = *zone_iter;
  432. if (zone)
  433. zone->DeleteSpellProcess();
  434. }
  435. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  436. }
  437. void ZoneList::HandleGlobalBroadcast(const char* message) {
  438. list<ZoneServer*>::iterator zone_iter;
  439. ZoneServer* zone = 0;
  440. MZoneList.readlock(__FUNCTION__, __LINE__);
  441. for (zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  442. zone = *zone_iter;
  443. if (zone)
  444. zone->HandleBroadcast(message);
  445. }
  446. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  447. }
  448. void ZoneList::HandleGlobalAnnouncement(const char* message) {
  449. list<ZoneServer*>::iterator zone_iter;
  450. ZoneServer* zone = 0;
  451. MZoneList.readlock(__FUNCTION__, __LINE__);
  452. for (zone_iter=zlist.begin(); zone_iter!=zlist.end();zone_iter++){
  453. zone = *zone_iter;
  454. if (zone)
  455. zone->HandleAnnouncement(message);
  456. }
  457. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  458. }
  459. int32 ZoneList::Count(){
  460. return zlist.size();
  461. }
  462. void ZoneList::Add(ZoneServer* zone) {
  463. MZoneList.writelock(__FUNCTION__, __LINE__);
  464. zlist.push_back(zone);
  465. MZoneList.releasewritelock(__FUNCTION__, __LINE__);
  466. }
  467. void ZoneList::Remove(ZoneServer* zone) {
  468. MZoneList.writelock(__FUNCTION__, __LINE__);
  469. zlist.remove(zone);
  470. MZoneList.releasewritelock(__FUNCTION__, __LINE__);
  471. }
  472. ZoneServer* ZoneList::Get(const char* zone_name, bool loadZone, bool skip_existing_zones) {
  473. list<ZoneServer*>::iterator zone_iter;
  474. ZoneServer* tmp = 0;
  475. ZoneServer* ret = 0;
  476. if(!skip_existing_zones) {
  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. }
  489. if(!ret )
  490. {
  491. if ( loadZone )
  492. {
  493. ret = new ZoneServer(zone_name, true);
  494. database.LoadZoneInfo(ret);
  495. ret->Init();
  496. }
  497. }
  498. else if(ret && loadZone) {
  499. ret->IncrementIncomingClients();
  500. }
  501. return ret;
  502. }
  503. ZoneServer* ZoneList::Get(int32 id, bool loadZone, bool skip_existing_zones) {
  504. list<ZoneServer*>::iterator zone_iter;
  505. ZoneServer* tmp = 0;
  506. ZoneServer* ret = 0;
  507. if(!skip_existing_zones) {
  508. MZoneList.readlock(__FUNCTION__, __LINE__);
  509. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  510. tmp = *zone_iter;
  511. if(!tmp->isZoneShuttingDown() && !tmp->IsInstanceZone() && tmp->GetZoneID() == id){
  512. if(tmp->NumPlayers() < 30 || tmp->IsCityZone())
  513. ret = tmp;
  514. break;
  515. }
  516. }
  517. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  518. }
  519. if(ret)
  520. tmp = ret;
  521. else if (loadZone) {
  522. string zonename = database.GetZoneName(id);
  523. if(zonename.length() >0){
  524. tmp = new ZoneServer(zonename.c_str());
  525. database.LoadZoneInfo(tmp);
  526. tmp->Init();
  527. }
  528. }
  529. return tmp;
  530. }
  531. void ZoneList::SendZoneList(Client* client) {
  532. list<ZoneServer*>::iterator zone_iter;
  533. ZoneServer* tmp = 0;
  534. MZoneList.readlock(__FUNCTION__, __LINE__);
  535. int zonesListed = 0;
  536. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  537. tmp = *zone_iter;
  538. if ( zonesListed > 20 )
  539. {
  540. client->Message(CHANNEL_COLOR_YELLOW,"Reached max zone list of 20.");
  541. break;
  542. }
  543. zonesListed++;
  544. client->Message(CHANNEL_COLOR_YELLOW,"Zone(ID): %s(%i), Instance ID: %i, Description: %s.",tmp->GetZoneName(),tmp->GetZoneID(),
  545. tmp->GetInstanceID(),tmp->GetZoneDescription());
  546. }
  547. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  548. }
  549. ZoneServer* ZoneList::GetByInstanceID(int32 id, int32 zone_id, bool skip_existing_zones) {
  550. list<ZoneServer*>::iterator zone_iter;
  551. ZoneServer* tmp = 0;
  552. ZoneServer* ret = 0;
  553. if(!skip_existing_zones) {
  554. MZoneList.readlock(__FUNCTION__, __LINE__);
  555. if ( id > 0 )
  556. {
  557. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  558. tmp = *zone_iter;
  559. if(tmp->GetInstanceID() == id){
  560. ret = tmp;
  561. break;
  562. }
  563. }
  564. }
  565. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  566. }
  567. if(ret)
  568. tmp = ret;
  569. else if ( zone_id > 0 ){
  570. string zonename = database.GetZoneName(zone_id);
  571. if(zonename.length() > 0){
  572. tmp = new ZoneServer(zonename.c_str());
  573. // the player is trying to preload an already existing instance but it isn't loaded
  574. if ( id > 0 )
  575. tmp->SetupInstance(id);
  576. database.LoadZoneInfo(tmp);
  577. tmp->Init();
  578. }
  579. }
  580. return tmp;
  581. }
  582. ZoneServer* ZoneList::GetByLowestPopulation(int32 zone_id) {
  583. ZoneServer* ret = 0;
  584. ZoneServer* zone = 0;
  585. int32 clients = 0;
  586. list<ZoneServer*>::iterator itr;
  587. MZoneList.readlock(__FUNCTION__, __LINE__);
  588. if (zone_id) {
  589. for (itr = zlist.begin(); itr != zlist.end(); itr++) {
  590. zone = *itr;
  591. if (zone) {
  592. // check the zone id's
  593. if (zone->GetZoneID() == zone_id) {
  594. // check this zones client count
  595. if (clients == 0 || zone->GetClientCount() < clients) {
  596. ret = zone;
  597. clients = zone->GetClientCount();
  598. }
  599. }
  600. }
  601. }
  602. }
  603. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  604. return ret;
  605. }
  606. bool ZoneList::ClientConnected(int32 account_id){
  607. bool ret = false;
  608. map<string, Client*>::iterator itr;
  609. MClientList.lock();
  610. for(itr=client_map.begin(); itr != client_map.end(); itr++){
  611. if(itr->second && itr->second->GetAccountID() == account_id && itr->second->getConnection() && itr->second->getConnection()->GetState() != CLOSING && itr->second->getConnection()->GetState() != CLOSED && (itr->second->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) == 0){
  612. ret = true;
  613. break;
  614. }
  615. else if(!itr->second){
  616. client_map.erase(itr);
  617. if(client_map.size() > 0){
  618. itr=client_map.begin();
  619. if(itr == client_map.end()){
  620. if(itr->second && itr->second->GetAccountID() == account_id && (itr->second->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) == 0)
  621. ret = true;
  622. break;
  623. }
  624. }
  625. else
  626. break;
  627. }
  628. }
  629. MClientList.unlock();
  630. return ret;
  631. }
  632. void ZoneList::RemoveClientZoneReference(ZoneServer* zone){
  633. map<string, Client*>::iterator itr;
  634. MClientList.lock();
  635. for(itr=client_map.begin(); itr != client_map.end(); itr++){
  636. if(itr->second) {
  637. if(itr->second->GetCurrentZone() == zone) {
  638. itr->second->SetCurrentZone(nullptr);
  639. }
  640. if(itr->second->GetZoningDestination() == zone) {
  641. itr->second->SetZoningDestination(nullptr);
  642. }
  643. }
  644. }
  645. MClientList.unlock();
  646. list<ZoneServer*>::iterator zone_iter;
  647. ZoneServer* tmp = 0;
  648. MZoneList.readlock(__FUNCTION__, __LINE__);
  649. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  650. tmp = *zone_iter;
  651. if(tmp)
  652. tmp->RemoveClientsFromZone(zone);
  653. }
  654. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  655. }
  656. void ZoneList::ReloadClientQuests(){
  657. list<ZoneServer*>::iterator zone_iter;
  658. ZoneServer* tmp = 0;
  659. MZoneList.readlock(__FUNCTION__, __LINE__);
  660. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  661. tmp = *zone_iter;
  662. if(tmp)
  663. tmp->ReloadClientQuests();
  664. }
  665. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  666. }
  667. void ZoneList::ProcessWhoQuery(vector<string>* queries, ZoneServer* zone, vector<Entity*>* players, bool isGM){
  668. Entity* player = 0;
  669. bool add_player = true;
  670. bool found_match = false;
  671. int8 lower = 0;
  672. int8 upper = 0;
  673. vector<Entity*> tmpPlayers;
  674. vector<Entity*>::iterator spawn_iter;
  675. if(!zone->isZoneShuttingDown()){
  676. tmpPlayers = zone->GetPlayers();
  677. for(spawn_iter = tmpPlayers.begin(); spawn_iter!=tmpPlayers.end(); spawn_iter++){
  678. player = *spawn_iter;
  679. add_player = true;
  680. Client* find_client = zone_list.GetClientByCharName(player->GetName());
  681. if (find_client == NULL) continue;
  682. int flags = find_client->GetPlayer()->GetInfoStruct()->get_flags();
  683. int flags2 = find_client->GetPlayer()->GetInfoStruct()->get_flags2();
  684. for(int32 i=0;add_player && queries && i<queries->size();i++){
  685. found_match = false;
  686. if(queries->at(i) == "ALL")
  687. continue;
  688. if(queries->at(i).length() > 3 && classes.GetClassID(queries->at(i).c_str()) > 0){
  689. if(player->GetAdventureClass() != classes.GetClassID(queries->at(i).c_str()))
  690. add_player = false;
  691. found_match = true;
  692. }
  693. else if(queries->at(i).length() > 2 && races.GetRaceID(queries->at(i).c_str()) > 0){
  694. if(player->GetRace() != races.GetRaceID(queries->at(i).c_str()))
  695. add_player = false;
  696. found_match = true;
  697. }
  698. if(!found_match && queries->at(i) == "GOOD"){
  699. if(player->GetDeity() != 1)
  700. add_player = false;
  701. found_match = true;
  702. }
  703. else if(!found_match && queries->at(i) == "EVIL"){
  704. if(player->GetDeity() == 1)
  705. add_player = false;
  706. found_match = true;
  707. }
  708. if((queries->at(i) == "GUIDE") && (find_client->GetAdminStatus() > 0) && ((find_client->GetAdminStatus() >> 4) < 5))
  709. found_match = true;
  710. else if((queries->at(i) == "GM") && ((find_client->GetAdminStatus() >> 4) > 4))
  711. found_match = true;
  712. else if((queries->at(i) == "LFG") && (flags & (1 << CF_LFG)))
  713. found_match = true;
  714. else if((queries->at(i) == "LFW") && (flags & (1 << CF_LFW)))
  715. found_match = true;
  716. else if((queries->at(i) == "ROLEPLAYING") && (flags & (1 << CF_ROLEPLAYING)))
  717. found_match = true;
  718. else if(strspn(queries->at(i).c_str(),"0123456789") == queries->at(i).length()){
  719. try{
  720. if(lower == 0)
  721. lower = atoi(queries->at(i).c_str());
  722. else
  723. upper = atoi(queries->at(i).c_str());
  724. }
  725. catch(...){}
  726. found_match = true;
  727. }
  728. if(!found_match){
  729. string name = string(player->GetName());
  730. name = ToUpper(name);
  731. if(name.find(queries->at(i)) == name.npos)
  732. add_player = false;
  733. }
  734. }
  735. if(lower > 0 && upper > 0){
  736. if(player->GetLevel() < lower || player->GetLevel() > upper)
  737. add_player = false;
  738. }
  739. else if(lower > 0){
  740. if(player->GetLevel() != lower)
  741. add_player = false;
  742. }
  743. if((flags2 & (1 << (CF_GM_HIDDEN - 32))) && !isGM) {
  744. add_player = false;
  745. found_match = true;
  746. }
  747. if(add_player)
  748. players->push_back(player);
  749. }
  750. }
  751. }
  752. void ZoneList::ProcessWhoQuery(const char* query, Client* client){
  753. list<ZoneServer*>::iterator zone_iter;
  754. vector<Entity*> players;
  755. vector<Entity*>::iterator spawn_iter;
  756. Entity* player = 0;
  757. //for now display all clients
  758. bool all = false;
  759. vector<string>* queries = 0;
  760. bool isGM = ((client->GetAdminStatus() >> 4) > 4);
  761. if(query){
  762. string query_string = string(query);
  763. query_string = ToUpper(query_string);
  764. queries = SplitString(query_string, ' ');
  765. }
  766. if(queries && queries->size() > 0 && queries->at(0) == "ALL")
  767. all = true;
  768. if(all){
  769. MZoneList.readlock(__FUNCTION__, __LINE__);
  770. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  771. ZoneServer* tmp = *zone_iter;
  772. ProcessWhoQuery(queries, tmp, &players, isGM);
  773. }
  774. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  775. }
  776. else{
  777. ProcessWhoQuery(queries, client->GetCurrentZone(), &players, isGM);
  778. }
  779. PacketStruct* packet = configReader.getStruct("WS_WhoQueryReply", client->GetVersion());
  780. if(packet){
  781. packet->setDataByName("account_id", client->GetAccountID());
  782. packet->setDataByName("unknown", 0xFFFFFFFF);
  783. int8 num_characters = players.size();
  784. int8 max_who_results = 10;
  785. int8 max_who_results_status_override = 100;
  786. Variable* var = variables.FindVariable("max_who_results_status_override");
  787. if ( var ){
  788. max_who_results_status_override = atoi(var->GetValue());
  789. }
  790. // AdnaeDMorte
  791. if ( client->GetAdminStatus() >= max_who_results_status_override ){
  792. client->Message(CHANNEL_COLOR_RED, "** ADMIN-MODE ** ");
  793. }
  794. Variable* var1 = variables.FindVariable("max_who_results");
  795. if ( var1 ){
  796. max_who_results = atoi(var1->GetValue());
  797. }
  798. if(num_characters > max_who_results && client->GetAdminStatus() < max_who_results_status_override){
  799. num_characters = max_who_results;
  800. packet->setDataByName("response", 3); //response 1 = error message, 3 == capped
  801. }
  802. else
  803. packet->setDataByName("response", 2);
  804. packet->setArrayLengthByName("num_characters", num_characters);
  805. packet->setDataByName("unknown10", 1);
  806. int i=0;
  807. for(spawn_iter = players.begin(); spawn_iter!=players.end(); spawn_iter++, i++){
  808. if(i == num_characters)
  809. break;
  810. player = *spawn_iter;
  811. Client* find_client = zone_list.GetClientByCharName(player->GetName());
  812. int flags = find_client->GetPlayer()->GetInfoStruct()->get_flags();
  813. int flags2 = find_client->GetPlayer()->GetInfoStruct()->get_flags2();
  814. packet->setArrayDataByName("char_name", player->GetName(), i);
  815. packet->setArrayDataByName("level", player->GetLevel(), i);
  816. packet->setArrayDataByName("admin_level", ((flags2 & (1 << (CF_HIDE_STATUS - 32))) && !isGM)?0:(find_client->GetAdminStatus() >> 4), i);
  817. packet->setArrayDataByName("class", player->GetAdventureClass(), i);
  818. packet->setArrayDataByName("unknown4", 0xFF, i); //probably tradeskill class
  819. packet->setArrayDataByName("flags", (((flags >> CF_ANONYMOUS) & 1) << 0 ) |
  820. (((flags >> CF_LFG) & 1) << 1 ) |
  821. (((flags >> CF_ANONYMOUS) & 1) << 2 ) |
  822. /*(((flags >> CF_HIDDEN) & 1) << 3 ) |*/
  823. (((flags >> CF_ROLEPLAYING) & 1) << 4 ) |
  824. (((flags >> CF_AFK) & 1) << 5 ) |
  825. (((flags >> CF_LFW) & 1) << 6 ) /*|
  826. (((flags >> CF_NOTA) & 1) << 7 )*/, i);
  827. packet->setArrayDataByName("race", player->GetRace(), i);
  828. if(player->GetZone() && player->GetZone()->GetZoneDescription())
  829. packet->setArrayDataByName("zone", player->GetZone()->GetZoneDescription(), i);
  830. if(player->appearance.sub_title) {
  831. int32 sub_title_length = strlen(player->appearance.sub_title);
  832. char tmp_title[255];
  833. int32 index = 0;
  834. int32 index_tmp = 0;
  835. while (index < sub_title_length) {
  836. if (player->appearance.sub_title[index] != '<' && player->appearance.sub_title[index] != '>') {
  837. memcpy(tmp_title + index_tmp, player->appearance.sub_title + index, 1);
  838. index_tmp++;
  839. }
  840. index++;
  841. }
  842. tmp_title[index_tmp] = '\0';
  843. packet->setArrayDataByName("guild", tmp_title, i);
  844. }
  845. }
  846. client->QueuePacket(packet->serialize());
  847. safe_delete(packet);
  848. }
  849. }
  850. bool ZoneList::DepopFinished(){
  851. list<ZoneServer*>::iterator zone_iter;
  852. MZoneList.readlock(__FUNCTION__, __LINE__);
  853. bool finished_depop = true;
  854. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  855. if(!(*zone_iter)->FinishedDepop())
  856. finished_depop = false;
  857. }
  858. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  859. return finished_depop;
  860. }
  861. void ZoneList::Depop(){
  862. list<ZoneServer*>::iterator zone_iter;
  863. MZoneList.readlock(__FUNCTION__, __LINE__);
  864. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  865. (*zone_iter)->Depop();
  866. }
  867. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  868. }
  869. void ZoneList::Repop(){
  870. list<ZoneServer*>::iterator zone_iter;
  871. MZoneList.readlock(__FUNCTION__, __LINE__);
  872. for(zone_iter=zlist.begin(); zone_iter!=zlist.end(); zone_iter++){
  873. (*zone_iter)->Depop(false, true);
  874. }
  875. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  876. }
  877. void ZoneList::ReloadSpawns() {
  878. MZoneList.readlock(__FUNCTION__, __LINE__);
  879. list<ZoneServer*>::iterator itr;
  880. for (itr = zlist.begin(); itr != zlist.end(); itr++)
  881. (*itr)->ReloadSpawns();
  882. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  883. }
  884. bool World::ReportBug(string data, char* player_name, int32 account_id, const char* spawn_name, int32 spawn_id, int32 zone_id){
  885. //loginserver
  886. vector<string> list;
  887. int32 offset = 0;
  888. int32 old_offset = 0;
  889. while((offset = data.find(7, old_offset+1)) < 0xFFFFFFFF){
  890. if(old_offset > 0)
  891. list.push_back(data.substr(old_offset+1, offset-old_offset-1));
  892. else
  893. list.push_back(data.substr(old_offset, offset));
  894. old_offset = offset;
  895. }
  896. if(list.size() > 0 && list.size() < 7){
  897. string output = "Invalid bug list:\n";
  898. for(int32 i=0;i<list.size();i++)
  899. output = output.append("\t").append(list[i]).append("\n");
  900. LogWrite(WORLD__ERROR, 0, "World", "%s", output.c_str());
  901. return false;
  902. }
  903. ServerPacket* outpack = new ServerPacket(ServerOP_BugReport, sizeof(BugReport));
  904. BugReport* report = (BugReport*)outpack->pBuffer;
  905. if (list.size() < 7) {
  906. strncpy(report->category, "AutoBug", 7);
  907. strncpy(report->subcategory, "AutoGenerate", 12);
  908. strncpy(report->causes_crash, "N", 1);
  909. strncpy(report->reproducible, "Y", 1);
  910. strncpy(report->summary, data.c_str(), data.length() > 127 ? 127 : data.length());
  911. strncpy(report->description, data.c_str(), data.length() > 1999 ? 1999 : data.length());
  912. strncpy(report->version, "CUR", 3);
  913. }
  914. else
  915. {
  916. strncpy(report->category, list[0].c_str(), list[0].length() > 63 ? 63 : list[0].length());
  917. strncpy(report->subcategory, list[1].c_str(), list[1].length() > 63 ? 63 : list[1].length());
  918. strncpy(report->causes_crash, list[2].c_str(), list[2].length() > 63 ? 63 : list[2].length());
  919. strncpy(report->reproducible, list[3].c_str(), list[3].length() > 63 ? 63 : list[3].length());
  920. strncpy(report->summary, list[4].c_str(), list[4].length() > 127 ? 127 : list[4].length());
  921. strncpy(report->description, list[5].c_str(), list[5].length() > 1999 ? 1999 : list[5].length());
  922. strncpy(report->version, list[6].c_str(), list[6].length() > 31 ? 31 : list[6].length());
  923. }
  924. strncpy(report->player, player_name, strlen(player_name) > 63 ? 63 : strlen(player_name));
  925. strncpy(report->spawn_name, spawn_name, strlen(spawn_name) > 63 ? 63 : strlen(spawn_name));
  926. report->spawn_id = spawn_id;
  927. report->account_id = account_id;
  928. report->zone_id = zone_id;
  929. loginserver.SendPacket(outpack);
  930. 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);
  931. safe_delete(outpack);
  932. return true;
  933. }
  934. void ZoneList::WritePlayerStatistics() {
  935. list<ZoneServer*>::iterator zone_itr;
  936. MZoneList.readlock(__FUNCTION__, __LINE__);
  937. for (zone_itr = zlist.begin(); zone_itr != zlist.end(); zone_itr++)
  938. (*zone_itr)->WritePlayerStatistics();
  939. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  940. }
  941. void ZoneList::ShutDownZones(){
  942. LogWrite(WORLD__INFO, 0, "World", "Shutting down all zones, please wait...");
  943. list<ZoneServer*>::iterator zone_itr;
  944. int32 size = 0;
  945. MZoneList.readlock(__FUNCTION__, __LINE__);
  946. for (zone_itr = zlist.begin(); zone_itr != zlist.end(); zone_itr++){
  947. (*zone_itr)->Shutdown();
  948. }
  949. size = zlist.size();
  950. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  951. while(size > 0){
  952. Sleep(10);
  953. MZoneList.readlock(__FUNCTION__, __LINE__);
  954. size = zlist.size();
  955. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  956. }
  957. LogWrite(WORLD__INFO, 0, "World", "Zone shutdown complete");
  958. }
  959. void ZoneList::ReloadMail() {
  960. map<string, Client*>::iterator itr;
  961. MClientList.writelock(__FUNCTION__, __LINE__);
  962. for (itr = client_map.begin(); itr != client_map.end(); itr++) {
  963. itr->second->GetPlayer()->DeleteMail();
  964. database.LoadPlayerMail(itr->second);
  965. }
  966. MClientList.releasewritelock(__FUNCTION__, __LINE__);
  967. }
  968. void World::AddSpawnScript(int32 id, const char* name){
  969. MSpawnScripts.lock();
  970. if(name)
  971. spawn_scripts[id] = string(name);
  972. MSpawnScripts.unlock();
  973. }
  974. void World::AddSpawnEntryScript(int32 id, const char* name){
  975. MSpawnScripts.lock();
  976. if(name)
  977. spawnentry_scripts[id] = string(name);
  978. MSpawnScripts.unlock();
  979. }
  980. void World::AddSpawnLocationScript(int32 id, const char* name){
  981. MSpawnScripts.lock();
  982. if(name)
  983. spawnlocation_scripts[id] = string(name);
  984. MSpawnScripts.unlock();
  985. }
  986. void World::AddZoneScript(int32 id, const char* name) {
  987. MZoneScripts.lock();
  988. if (name)
  989. zone_scripts[id] = string(name);
  990. MZoneScripts.unlock();
  991. }
  992. const char* World::GetSpawnScript(int32 id){
  993. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  994. const char* ret = 0;
  995. MSpawnScripts.lock();
  996. if(spawn_scripts.count(id) > 0)
  997. ret = spawn_scripts[id].c_str();
  998. MSpawnScripts.unlock();
  999. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  1000. return ret;
  1001. }
  1002. const char* World::GetSpawnEntryScript(int32 id){
  1003. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  1004. const char* ret = 0;
  1005. MSpawnScripts.lock();
  1006. if(spawnentry_scripts.count(id) > 0)
  1007. ret = spawnentry_scripts[id].c_str();
  1008. MSpawnScripts.unlock();
  1009. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  1010. return ret;
  1011. }
  1012. const char* World::GetSpawnLocationScript(int32 id){
  1013. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  1014. const char* ret = 0;
  1015. MSpawnScripts.lock();
  1016. if(spawnlocation_scripts.count(id) > 0)
  1017. ret = spawnlocation_scripts[id].c_str();
  1018. MSpawnScripts.unlock();
  1019. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  1020. return ret;
  1021. }
  1022. const char* World::GetZoneScript(int32 id) {
  1023. const char* ret = 0;
  1024. MZoneScripts.lock();
  1025. if (zone_scripts.count(id) > 0)
  1026. ret = zone_scripts[id].c_str();
  1027. MZoneScripts.unlock();
  1028. return ret;
  1029. }
  1030. void World::ResetSpawnScripts(){
  1031. MSpawnScripts.lock();
  1032. spawn_scripts.clear();
  1033. spawnentry_scripts.clear();
  1034. spawnlocation_scripts.clear();
  1035. MSpawnScripts.unlock();
  1036. }
  1037. void World::ResetZoneScripts() {
  1038. MZoneScripts.lock();
  1039. zone_scripts.clear();
  1040. MZoneScripts.unlock();
  1041. }
  1042. vector<MerchantItemInfo>* World::GetMerchantItemList(int32 merchant_id, int8 merchant_type, Player* player)
  1043. {
  1044. vector<MerchantItemInfo>* ret = 0;
  1045. MMerchantList.lock();
  1046. if(merchant_info.count(merchant_id) > 0)
  1047. {
  1048. MerchantInfo* info = merchant_info[merchant_id];
  1049. vector<MerchantItemInfo>::iterator itr;
  1050. int32 inventory_id = 0;
  1051. Item* item = 0;
  1052. for(int i=info->inventory_ids.size()-1;i>=0;i--)
  1053. {
  1054. inventory_id = info->inventory_ids[i];
  1055. if(merchant_inventory_items.count(inventory_id) > 0)
  1056. {
  1057. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++)
  1058. {
  1059. if(!ret)
  1060. ret = new vector<MerchantItemInfo>;
  1061. item = master_item_list.GetItem((*itr).item_id);
  1062. // if NOT spell merchant, OR
  1063. // skill req is any skill, OR player has the skill, AND
  1064. // skill req2 is any skill, OR player has the skill2
  1065. 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)) ) ) )
  1066. (*ret).push_back(*itr);
  1067. }
  1068. }
  1069. }
  1070. }
  1071. MMerchantList.unlock();
  1072. return ret;
  1073. }
  1074. vector<MerchantItemInfo>* World::GetMerchantList(int32 merchant_id){
  1075. vector<MerchantItemInfo>* ret = 0;
  1076. MMerchantList.lock();
  1077. if(merchant_info.count(merchant_id) > 0){
  1078. MerchantInfo* info = merchant_info[merchant_id];
  1079. map<int32, int16>::iterator itr;
  1080. int32 inventory_id = 0;
  1081. for(int i=info->inventory_ids.size()-1;i>=0;i--){
  1082. inventory_id = info->inventory_ids[i];
  1083. if(merchant_inventory_items.count(inventory_id) > 0){
  1084. ret = &merchant_inventory_items[inventory_id];
  1085. }
  1086. }
  1087. }
  1088. MMerchantList.unlock();
  1089. return ret;
  1090. }
  1091. void World::AddMerchantItem(int32 inventory_id, MerchantItemInfo ItemInfo){
  1092. MMerchantList.lock();
  1093. merchant_inventory_items[inventory_id].push_back(ItemInfo);
  1094. MMerchantList.unlock();
  1095. }
  1096. void World::DeleteMerchantItems(){
  1097. MMerchantList.lock();
  1098. merchant_inventory_items.clear();
  1099. MMerchantList.unlock();
  1100. }
  1101. void World::RemoveMerchantItem(int32 inventory_id, int32 item_id){
  1102. MMerchantList.lock();
  1103. if(merchant_inventory_items.count(inventory_id) > 0) {
  1104. vector<MerchantItemInfo>::iterator itr;
  1105. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1106. if ((*itr).item_id == item_id) {
  1107. merchant_inventory_items[inventory_id].erase(itr);
  1108. break;
  1109. }
  1110. }
  1111. }
  1112. MMerchantList.unlock();
  1113. }
  1114. int16 World::GetMerchantItemQuantity(int32 merchant_id, int32 item_id){
  1115. int16 amount = 0;
  1116. int32 inventory_id = GetInventoryID(merchant_id, item_id);
  1117. if(inventory_id > 0){
  1118. MMerchantList.lock();
  1119. vector<MerchantItemInfo>::iterator itr;
  1120. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1121. if ((*itr).item_id == item_id)
  1122. amount = (*itr).quantity;
  1123. }
  1124. MMerchantList.unlock();
  1125. }
  1126. return amount;
  1127. }
  1128. int32 World::GetInventoryID(int32 merchant_id, int32 item_id){
  1129. int32 ret = 0;
  1130. MMerchantList.lock();
  1131. if(merchant_info.count(merchant_id) > 0){
  1132. MerchantInfo* info = merchant_info[merchant_id];
  1133. vector<MerchantItemInfo>::iterator itr;
  1134. int32 inventory_id = 0;
  1135. for(int i=info->inventory_ids.size()-1;i>=0;i--){
  1136. inventory_id = info->inventory_ids[i];
  1137. if(merchant_inventory_items.count(inventory_id) > 0){
  1138. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1139. if((*itr).item_id == item_id){
  1140. ret = inventory_id;
  1141. break;
  1142. }
  1143. }
  1144. if(ret > 0)
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. MMerchantList.unlock();
  1150. return ret;
  1151. }
  1152. void World::DecreaseMerchantQuantity(int32 merchant_id, int32 item_id, int16 amount){
  1153. int16 total_left = GetMerchantItemQuantity(merchant_id, item_id);
  1154. if(total_left > 0 && total_left < 0xFF){
  1155. int32 inventory_id = GetInventoryID(merchant_id, item_id);
  1156. if(inventory_id > 0){
  1157. MMerchantList.lock();
  1158. vector<MerchantItemInfo>::iterator itr;
  1159. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1160. if ((*itr).item_id == item_id) {
  1161. if(total_left <= amount) {
  1162. merchant_inventory_items[inventory_id].erase(itr);
  1163. amount = 0;
  1164. break;
  1165. }
  1166. else
  1167. (*itr).quantity -= amount;
  1168. amount = (*itr).quantity;
  1169. }
  1170. }
  1171. MMerchantList.unlock();
  1172. }
  1173. }
  1174. }
  1175. MerchantInfo* World::GetMerchantInfo(int32 merchant_id){
  1176. MerchantInfo* ret = 0;
  1177. MMerchantList.lock();
  1178. if(merchant_info.count(merchant_id) > 0)
  1179. ret = merchant_info[merchant_id];
  1180. MMerchantList.unlock();
  1181. return ret;
  1182. }
  1183. void World::AddMerchantInfo(int32 merchant_id, MerchantInfo* info){
  1184. MMerchantList.lock();
  1185. if(merchant_info.count(merchant_id) > 0){
  1186. safe_delete(merchant_info[merchant_id]);
  1187. }
  1188. merchant_info[merchant_id] = info;
  1189. MMerchantList.unlock();
  1190. }
  1191. map<int32, MerchantInfo*>* World::GetMerchantInfo() {
  1192. return &merchant_info;
  1193. }
  1194. void World::DeleteMerchantsInfo(){
  1195. MMerchantList.lock();
  1196. map<int32, MerchantInfo*>::iterator itr;
  1197. for(itr = merchant_info.begin(); itr != merchant_info.end(); itr++){
  1198. safe_delete(itr->second);
  1199. }
  1200. merchant_info.clear();
  1201. MMerchantList.unlock();
  1202. }
  1203. void World::DeleteSpawns(){
  1204. //reloading = true;
  1205. //ClearLootTables();
  1206. /*
  1207. map<int32, NPC*>::iterator npc_list_iter;
  1208. for(npc_list_iter=npc_list.begin();npc_list_iter!=npc_list.end();npc_list_iter++) {
  1209. safe_delete(npc_list_iter->second);
  1210. }
  1211. npc_list.clear();
  1212. map<int32, Object*>::iterator object_list_iter;
  1213. for(object_list_iter=object_list.begin();object_list_iter!=object_list.end();object_list_iter++) {
  1214. safe_delete(object_list_iter->second);
  1215. }
  1216. object_list.clear();
  1217. map<int32, GroundSpawn*>::iterator groundspawn_list_iter;
  1218. for(groundspawn_list_iter=groundspawn_list.begin();groundspawn_list_iter!=groundspawn_list.end();groundspawn_list_iter++) {
  1219. safe_delete(groundspawn_list_iter->second);
  1220. }
  1221. groundspawn_list.clear();
  1222. map<int32, Widget*>::iterator widget_list_iter;
  1223. for(widget_list_iter=widget_list.begin();widget_list_iter!=widget_list.end();widget_list_iter++) {
  1224. safe_delete(widget_list_iter->second);
  1225. }
  1226. widget_list.clear();
  1227. map<int32, Sign*>::iterator sign_list_iter;
  1228. for(sign_list_iter=sign_list.begin();sign_list_iter!=sign_list.end();sign_list_iter++) {
  1229. safe_delete(sign_list_iter->second);
  1230. }
  1231. sign_list.clear();*/
  1232. map<int32, AppearanceData*>::iterator appearance_list_iter;
  1233. for(appearance_list_iter=npc_appearance_list.begin();appearance_list_iter!=npc_appearance_list.end();appearance_list_iter++) {
  1234. safe_delete(appearance_list_iter->second);
  1235. }
  1236. npc_appearance_list.clear();
  1237. /*
  1238. map<int32, vector<EntityCommand*>* >::iterator command_list_iter;
  1239. for(command_list_iter=entity_command_list.begin();command_list_iter!=entity_command_list.end();command_list_iter++) {
  1240. vector<EntityCommand*>* v = command_list_iter->second;
  1241. if(v){
  1242. for(int32 i=0;i<v->size();i++){
  1243. safe_delete(v->at(i));
  1244. }
  1245. safe_delete(v);
  1246. }
  1247. }
  1248. entity_command_list.clear();
  1249. */
  1250. //DeleteGroundSpawnItems();
  1251. //DeleteTransporters();
  1252. //DeleteTransporterMaps();
  1253. }
  1254. void World::ReloadGuilds() {
  1255. guild_list.GetGuilds()->clear(true);
  1256. database.LoadGuilds();
  1257. }
  1258. int8 World::GetClassID(const char* name){
  1259. return classes.GetClassID(name);
  1260. }
  1261. void World::WritePlayerStatistics() {
  1262. zone_list.WritePlayerStatistics();
  1263. }
  1264. void World::WriteServerStatistics() {
  1265. map<int32, Statistic*>::iterator itr;
  1266. Statistic* stat = 0;
  1267. for (itr = server_statistics.begin(); itr != server_statistics.end(); itr++) {
  1268. stat = itr->second;
  1269. if (stat->save_needed) {
  1270. stat->save_needed = false;
  1271. database.WriteServerStatistic(stat);
  1272. }
  1273. }
  1274. database.WriteServerStatisticsNeededQueries();
  1275. }
  1276. void World::AddServerStatistic(int32 stat_id, sint32 stat_value, int32 stat_date) {
  1277. if (server_statistics.count(stat_id) == 0) {
  1278. Statistic* stat = new Statistic;
  1279. stat->stat_id = stat_id;
  1280. stat->stat_value = stat_value;
  1281. stat->stat_date = stat_date;
  1282. stat->save_needed = false;
  1283. server_statistics[stat_id] = stat;
  1284. }
  1285. }
  1286. void World::UpdateServerStatistic(int32 stat_id, sint32 stat_value, bool overwrite) {
  1287. if (server_statistics.count(stat_id) == 0)
  1288. AddServerStatistic(stat_id, stat_value, 0);
  1289. Statistic* stat = server_statistics[stat_id];
  1290. overwrite == true ? stat->stat_value = stat_value : stat->stat_value += stat_value;
  1291. stat->stat_date = Timer::GetUnixTimeStamp();
  1292. stat->save_needed = true;
  1293. }
  1294. sint32 World::GetServerStatisticValue(int32 stat_id) {
  1295. if (server_statistics.count(stat_id) > 0)
  1296. return server_statistics[stat_id]->stat_value;
  1297. return 0;
  1298. }
  1299. void World::RemoveServerStatistics() {
  1300. map<int32, Statistic*>::iterator stat_itr;
  1301. for (stat_itr = server_statistics.begin(); stat_itr != server_statistics.end(); stat_itr++)
  1302. safe_delete(stat_itr->second);
  1303. server_statistics.clear();
  1304. }
  1305. void World::SendGroupQuests(PlayerGroup* group, Client* client){
  1306. return;
  1307. /*if(!group)
  1308. return;
  1309. GroupMemberInfo* info = 0;
  1310. MGroups.readlock(__FUNCTION__, __LINE__);
  1311. deque<GroupMemberInfo*>::iterator itr;
  1312. for(itr = group->members.begin(); itr != group->members.end(); itr++){
  1313. info = *itr;
  1314. if(info->client){
  1315. LogWrite(PLAYER__DEBUG, 0, "Player", "Send Quest Journal...");
  1316. info->client->SendQuestJournal(false, client);
  1317. client->SendQuestJournal(false, info->client);
  1318. }
  1319. }
  1320. MGroups.releasereadlock(__FUNCTION__, __LINE__);*/
  1321. }
  1322. /*void World::CheckRemoveGroupedPlayer(){
  1323. map<GroupMemberInfo*, int32>::iterator itr;
  1324. GroupMemberInfo* found = 0;
  1325. MGroups.readlock(__FUNCTION__, __LINE__);
  1326. for(itr = group_removal_pending.begin(); itr != group_removal_pending.end(); itr++){
  1327. if(itr->second < Timer::GetCurrentTime2()){
  1328. found = itr->first;
  1329. break;
  1330. }
  1331. }
  1332. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  1333. if(found){
  1334. if(!found->client || (found->client && found->client->IsConnected() == false))
  1335. DeleteGroupMember(found);
  1336. else{
  1337. MGroups.writelock(__FUNCTION__, __LINE__);
  1338. group_removal_pending.erase(found);
  1339. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  1340. }
  1341. }
  1342. }*/
  1343. bool World::RejoinGroup(Client* client, int32 group_id){
  1344. if (!group_id) // no need if no group id!
  1345. return false;
  1346. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1347. PlayerGroup* group = world.GetGroupManager()->GetGroup(group_id);
  1348. deque<GroupMemberInfo*>* members = 0;
  1349. if (group)
  1350. members = group->GetMembers();
  1351. string name = string(client->GetPlayer()->GetName());
  1352. if (!members)
  1353. {
  1354. // group does not exist!
  1355. Query query;
  1356. query.AddQueryAsync(client->GetCharacterID(), &database, Q_INSERT, "UPDATE characters set group_id = 0 where id = %u",
  1357. client->GetCharacterID());
  1358. LogWrite(PLAYER__ERROR, 0, "Player", "Group did not exist for player %s to group id %i, async query to group_id = 0.", name.c_str(), group_id);
  1359. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1360. return false;
  1361. }
  1362. deque<GroupMemberInfo*>::iterator itr;
  1363. GroupMemberInfo* info = 0;
  1364. bool match = false;
  1365. group->MGroupMembers.writelock();
  1366. for (itr = members->begin(); itr != members->end(); itr++) {
  1367. info = *itr;
  1368. if (info && info->name == name)
  1369. {
  1370. info->client = client;
  1371. info->member = client->GetPlayer();
  1372. client->GetPlayer()->SetGroup(group);
  1373. client->GetPlayer()->SetGroupMemberInfo(info);
  1374. client->GetPlayer()->UpdateGroupMemberInfo(true, true);
  1375. LogWrite(PLAYER__DEBUG, 0, "Player", "Identified group match for player %s to group id %u", name.c_str(), group_id);
  1376. match = true;
  1377. break;
  1378. }
  1379. }
  1380. group->MGroupMembers.releasewritelock();
  1381. // must be done after cause it needs a readlock
  1382. if (match)
  1383. group->SendGroupUpdate();
  1384. if (!match)
  1385. LogWrite(PLAYER__ERROR, 0, "Player", "Identified group match for player %s to group id %u, however the player name was not present in the group! May be an old group id that has been re-used.", name.c_str(), group_id);
  1386. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1387. return match;
  1388. }
  1389. void World::AddBonuses(Item* item, ItemStatsValues* values, int16 type, sint32 value, Entity* entity){
  1390. if(values){
  1391. if(item && entity && entity->IsPlayer())
  1392. {
  1393. int32 effective_level = entity->GetInfoStructUInt("effective_level");
  1394. if(effective_level && effective_level < entity->GetLevel() && item->details.recommended_level > effective_level)
  1395. {
  1396. int32 diff = item->details.recommended_level - effective_level;
  1397. float tmpValue = (float)value;
  1398. value = (sint32)(float)(tmpValue / (1.0f + ((float)diff * .05f)));
  1399. }
  1400. }
  1401. switch(type){
  1402. case ITEM_STAT_STR:{
  1403. values->str += value;
  1404. break;
  1405. }
  1406. case ITEM_STAT_STA:{
  1407. values->sta += value;
  1408. break;
  1409. }
  1410. case ITEM_STAT_AGI:{
  1411. values->agi += value;
  1412. break;
  1413. }
  1414. case ITEM_STAT_WIS:{
  1415. values->wis += value;
  1416. break;
  1417. }
  1418. case ITEM_STAT_INT:{
  1419. values->int_ += value;
  1420. break;
  1421. }
  1422. case ITEM_STAT_VS_SLASH:{
  1423. values->vs_slash += value;
  1424. break;
  1425. }
  1426. case ITEM_STAT_VS_CRUSH:{
  1427. values->vs_crush += value;
  1428. break;
  1429. }
  1430. case ITEM_STAT_VS_PIERCE:{
  1431. values->vs_pierce += value;
  1432. break;
  1433. }
  1434. case ITEM_STAT_VS_HEAT:{
  1435. values->vs_heat += value;
  1436. break;
  1437. }
  1438. case ITEM_STAT_VS_COLD:{
  1439. values->vs_cold += value;
  1440. break;
  1441. }
  1442. case ITEM_STAT_VS_MAGIC:{
  1443. values->vs_magic += value;
  1444. break;
  1445. }
  1446. case ITEM_STAT_VS_MENTAL:{
  1447. values->vs_mental += value;
  1448. break;
  1449. }
  1450. case ITEM_STAT_VS_DIVINE:{
  1451. values->vs_divine += value;
  1452. break;
  1453. }
  1454. case ITEM_STAT_VS_DISEASE:{
  1455. values->vs_disease += value;
  1456. break;
  1457. }
  1458. case ITEM_STAT_VS_POISON:{
  1459. values->vs_poison += value;
  1460. break;
  1461. }
  1462. case ITEM_STAT_HEALTH:{
  1463. values->health += value;
  1464. break;
  1465. }
  1466. case ITEM_STAT_POWER:{
  1467. values->power += value;
  1468. break;
  1469. }
  1470. case ITEM_STAT_CONCENTRATION:{
  1471. values->concentration += value;
  1472. break;
  1473. }
  1474. case ITEM_STAT_ABILITY_MODIFIER:{
  1475. values->ability_modifier += value;
  1476. break;
  1477. }
  1478. case ITEM_STAT_CRITICALMITIGATION:{
  1479. values->criticalmitigation += value;
  1480. break;
  1481. }
  1482. case ITEM_STAT_EXTRASHIELDBLOCKCHANCE:{
  1483. values->extrashieldblockchance += value;
  1484. break;
  1485. }
  1486. case ITEM_STAT_BENEFICIALCRITCHANCE:{
  1487. values->beneficialcritchance += value;
  1488. break;
  1489. }
  1490. case ITEM_STAT_CRITBONUS:{
  1491. values->critbonus += value;
  1492. break;
  1493. }
  1494. case ITEM_STAT_POTENCY:{
  1495. values->potency += value;
  1496. break;
  1497. }
  1498. case ITEM_STAT_HATEGAINMOD:{
  1499. values->hategainmod += value;
  1500. break;
  1501. }
  1502. case ITEM_STAT_ABILITYREUSESPEED:{
  1503. values->abilityreusespeed += value;
  1504. break;
  1505. }
  1506. case ITEM_STAT_ABILITYCASTINGSPEED:{
  1507. values->abilitycastingspeed += value;
  1508. break;
  1509. }
  1510. case ITEM_STAT_ABILITYRECOVERYSPEED:{
  1511. values->abilityrecoveryspeed += value;
  1512. break;
  1513. }
  1514. case ITEM_STAT_SPELLREUSESPEED:{
  1515. values->spellreusespeed += value;
  1516. break;
  1517. }
  1518. case ITEM_STAT_SPELLMULTIATTACKCHANCE:{
  1519. values->spellmultiattackchance += value;
  1520. break;
  1521. }
  1522. case ITEM_STAT_DPS:{
  1523. values->dps += value;
  1524. break;
  1525. }
  1526. case ITEM_STAT_ATTACKSPEED:{
  1527. values->attackspeed += value;
  1528. break;
  1529. }
  1530. case ITEM_STAT_MULTIATTACKCHANCE:{
  1531. values->multiattackchance += value;
  1532. break;
  1533. }
  1534. case ITEM_STAT_AEAUTOATTACKCHANCE:{
  1535. values->aeautoattackchance += value;
  1536. break;
  1537. }
  1538. case ITEM_STAT_STRIKETHROUGH:{
  1539. values->strikethrough += value;
  1540. break;
  1541. }
  1542. case ITEM_STAT_ACCURACY:{
  1543. values->accuracy += value;
  1544. break;
  1545. }
  1546. /*case ITEM_STAT_OFFENSIVESPEED:{
  1547. values->offensivespeed += value;
  1548. break;
  1549. }*/
  1550. default: {
  1551. if (entity) {
  1552. entity->MStats.lock();
  1553. entity->stats[type] += value;
  1554. entity->MStats.unlock();
  1555. }
  1556. break;
  1557. }
  1558. }
  1559. }
  1560. }
  1561. void World::CreateGuild(const char* guild_name, Client* leader, int32 group_id) {
  1562. deque<GroupMemberInfo*>::iterator itr;
  1563. GroupMemberInfo* gmi;
  1564. Guild *guild;
  1565. assert(guild_name);
  1566. guild = new Guild();
  1567. guild->SetName(guild_name);
  1568. guild->SetFormedDate(Timer::GetUnixTimeStamp());
  1569. database.LoadGuildDefaultRanks(guild);
  1570. database.LoadGuildDefaultEventFilters(guild);
  1571. database.SaveGuild(guild, true);
  1572. database.SaveGuildEvents(guild);
  1573. database.SaveGuildRanks(guild);
  1574. database.SaveGuildEventFilters(guild);
  1575. database.SaveGuildRecruiting(guild);
  1576. guild_list.AddGuild(guild);
  1577. if (leader && !leader->GetPlayer()->GetGuild())
  1578. guild->AddNewGuildMember(leader, 0, GUILD_RANK_LEADER);
  1579. database.SaveGuildMembers(guild);
  1580. if (leader && group_id > 0) {
  1581. GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1582. PlayerGroup* group = world.GetGroupManager()->GetGroup(group_id);
  1583. if (group)
  1584. {
  1585. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  1586. deque<GroupMemberInfo*>* members = group->GetMembers();
  1587. for (itr = members->begin(); itr != members->end(); itr++) {
  1588. gmi = *itr;
  1589. if (gmi->client && gmi->client != leader && !gmi->client->GetPlayer()->GetGuild())
  1590. guild->InvitePlayer(gmi->client, leader->GetPlayer()->GetName());
  1591. }
  1592. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  1593. }
  1594. GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1595. }
  1596. }
  1597. void World::SaveGuilds() {
  1598. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  1599. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  1600. while (itr.Next()) {
  1601. Guild* guild = itr.second;
  1602. if (guild->GetSaveNeeded())
  1603. database.SaveGuild(guild);
  1604. if (guild->GetMemberSaveNeeded())
  1605. database.SaveGuildMembers(guild);
  1606. if (guild->GetEventsSaveNeeded())
  1607. database.SaveGuildEvents(guild);
  1608. if (guild->GetRanksSaveNeeded())
  1609. database.SaveGuildRanks(guild);
  1610. if (guild->GetEventFiltersSaveNeeded())
  1611. database.SaveGuildEventFilters(guild);
  1612. if (guild->GetPointsHistorySaveNeeded())
  1613. database.SaveGuildPointsHistory(guild);
  1614. if (guild->GetRecruitingSaveNeeded())
  1615. database.SaveGuildRecruiting(guild);
  1616. }
  1617. }
  1618. void World::PickRandomLottoDigits(int32* digits) {
  1619. if (digits) {
  1620. for (int32 i = 0; i < 6; i++) {
  1621. bool found = true;
  1622. int32 num = 0;
  1623. while (found) {
  1624. num = ((int32)rand() % 36) + 1;
  1625. for (int32 j = 0; j < 6; j++) {
  1626. if (digits[j] == num)
  1627. break;
  1628. if (j == 5)
  1629. found = false;
  1630. }
  1631. }
  1632. digits[i] = num;
  1633. }
  1634. }
  1635. }
  1636. void World::AddLottoPlayer(int32 character_id, int32 end_time) {
  1637. LottoPlayer* lp;
  1638. if (lotto_players.count(character_id) == 0) {
  1639. lp = new LottoPlayer;
  1640. lotto_players.Put(character_id, lp);
  1641. }
  1642. else
  1643. lp = lotto_players.Get(character_id);
  1644. lp->end_time = end_time;
  1645. lp->num_matches = 0;
  1646. lp->set = false;
  1647. }
  1648. void World::RemoveLottoPlayer(int32 character_id) {
  1649. if (lotto_players.count(character_id) > 0)
  1650. lotto_players.erase(character_id, false, true);
  1651. }
  1652. void World::SetLottoPlayerNumMatches(int32 character_id, int8 num_matches) {
  1653. if (lotto_players.count(character_id) > 0) {
  1654. lotto_players.Get(character_id)->num_matches = num_matches;
  1655. lotto_players.Get(character_id)->set = true;
  1656. }
  1657. }
  1658. void World::CheckLottoPlayers() {
  1659. MutexMap<int32, LottoPlayer*>::iterator itr = lotto_players.begin();
  1660. while (itr.Next()) {
  1661. LottoPlayer* lp = itr->second;
  1662. if (Timer::GetCurrentTime2() >= lp->end_time && lp->set) {
  1663. int8 num_matches = lp->num_matches;
  1664. LogWrite(PLAYER__DEBUG, 0, "Player", "Num matches: %u", lp->num_matches);
  1665. Client* client = zone_list.GetClientByCharID(itr->first);
  1666. if (client && num_matches >= 2) {
  1667. if (num_matches == 2) {
  1668. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 10 silver.");
  1669. client->SendPopupMessage(0, "Congratulations! You have won 10 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1670. client->GetPlayer()->AddCoins(1000);
  1671. client->GetPlayer()->GetZone()->SendCastSpellPacket(869, client->GetPlayer());
  1672. }
  1673. else if (num_matches == 3) {
  1674. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 50 silver.");
  1675. client->SendPopupMessage(0, "Congratulations! You have won 50 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1676. client->GetPlayer()->AddCoins(5000);
  1677. client->GetPlayer()->GetZone()->SendCastSpellPacket(870, client->GetPlayer());
  1678. }
  1679. else if (num_matches == 4) {
  1680. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 2 gold 50 silver.");
  1681. client->SendPopupMessage(0, "Congratulations! You have won 2 gold 50 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1682. client->GetPlayer()->AddCoins(25000);
  1683. client->GetPlayer()->GetZone()->SendCastSpellPacket(871, client->GetPlayer());
  1684. }
  1685. else if (num_matches == 5) {
  1686. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 25 gold.");
  1687. client->SendPopupMessage(0, "Congratulations! You have won 25 gold!", "", 2, 0xFF, 0xFF, 0x99);
  1688. client->GetPlayer()->AddCoins(250000);
  1689. client->GetPlayer()->GetZone()->SendCastSpellPacket(872, client->GetPlayer());
  1690. }
  1691. else if (num_matches == 6) {
  1692. Variable* var = variables.FindVariable("gambling_current_jackpot");
  1693. if (var) {
  1694. int64 jackpot = 0;
  1695. try {
  1696. jackpot = atoul(var->GetValue());
  1697. }
  1698. catch (...) {
  1699. jackpot = 10000;
  1700. }
  1701. char coin_message[128];
  1702. char message[512];
  1703. char announcement[512];
  1704. memset(coin_message, 0, sizeof(coin_message));
  1705. memset(message, 0, sizeof(message));
  1706. memset(announcement, 0, sizeof(announcement));
  1707. sprintf(coin_message, "%s", client->GetCoinMessage(jackpot).c_str());
  1708. sprintf(message, "Congratulations! You have won %s!", coin_message);
  1709. sprintf(announcement, "%s as won the jackpot containing a total of %s!", client->GetPlayer()->GetName(), coin_message);
  1710. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", coin_message);
  1711. client->SendPopupMessage(0, message, "", 2, 0xFF, 0xFF, 0x99);
  1712. zone_list.HandleGlobalAnnouncement(announcement);
  1713. client->GetPlayer()->AddCoins(jackpot);
  1714. client->GetPlayer()->GetZone()->SendCastSpellPacket(843, client->GetPlayer());
  1715. client->GetPlayer()->GetZone()->SendCastSpellPacket(1413, client->GetPlayer());
  1716. }
  1717. }
  1718. }
  1719. RemoveLottoPlayer(itr->first);
  1720. }
  1721. }
  1722. }
  1723. 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) {
  1724. MHouseZones.writelock(__FUNCTION__, __LINE__);
  1725. if (m_houseZones.count(id) == 0) {
  1726. HouseZone* hz = new HouseZone;
  1727. //ZeroMemory(hz, sizeof(HouseZone));
  1728. hz->id = id;
  1729. hz->name = name;
  1730. hz->cost_coin = cost_coins;
  1731. hz->cost_status = cost_status;
  1732. hz->upkeep_coin = upkeep_coins;
  1733. hz->upkeep_status = upkeep_status;
  1734. hz->vault_slots = vault_slots;
  1735. hz->alignment = alignment;
  1736. hz->guild_level = guild_level;
  1737. hz->zone_id = zone_id;
  1738. hz->exit_zone_id = exit_zone_id;
  1739. hz->exit_x = exit_x;
  1740. hz->exit_y = exit_y;
  1741. hz->exit_z = exit_z;
  1742. hz->exit_heading = exit_heading;
  1743. m_houseZones[id] = hz;
  1744. }
  1745. else {
  1746. LogWrite(WORLD__ERROR, 0, "Housing", "Duplicate house id (%u) for %s", id, name.c_str());
  1747. }
  1748. MHouseZones.releasewritelock(__FUNCTION__, __LINE__);
  1749. }
  1750. HouseZone* World::GetHouseZone(int32 id) {
  1751. HouseZone* ret = 0;
  1752. MHouseZones.readlock(__FUNCTION__, __LINE__);
  1753. if (m_houseZones.count(id) > 0)
  1754. ret = m_houseZones[id];
  1755. MHouseZones.releasereadlock(__FUNCTION__, __LINE__);
  1756. return ret;
  1757. }
  1758. 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) {
  1759. MPlayerHouses.writelock(__FUNCTION__, __LINE__);
  1760. if (m_playerHouses.count(house_id) == 0 || m_playerHouses[house_id].count(char_id) == 0) {
  1761. PlayerHouse* ph = new PlayerHouse;
  1762. ph->house_id = house_id;
  1763. ph->unique_id = unique_id;
  1764. ph->instance_id = instance_id;
  1765. ph->escrow_coins = escrow_coins;
  1766. ph->escrow_status = escrow_status;
  1767. ph->upkeep_due = upkeep_due;
  1768. ph->player_name = player_name;
  1769. ReloadHouseData(ph);
  1770. m_playerHouses[house_id][char_id] = ph;
  1771. }
  1772. MPlayerHouses.releasewritelock(__FUNCTION__, __LINE__);
  1773. }
  1774. void World::ReloadHouseData(PlayerHouse* ph)
  1775. {
  1776. database.LoadDeposits(ph);
  1777. database.LoadHistory(ph);
  1778. }
  1779. PlayerHouse* World::GetPlayerHouseByHouseID(int32 char_id, int32 house_id) {
  1780. PlayerHouse* ret = 0;
  1781. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1782. if (m_playerHouses.count(house_id) > 0 && m_playerHouses[house_id].count(char_id) > 0)
  1783. ret = m_playerHouses[house_id][char_id];
  1784. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1785. return ret;
  1786. }
  1787. PlayerHouse* World::GetPlayerHouseByUniqueID(int64 unique_id) {
  1788. PlayerHouse* ret = 0;
  1789. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1790. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1791. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1792. map<int32, PlayerHouse*>::iterator itr2;
  1793. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  1794. if (itr2->second->unique_id == unique_id) {
  1795. ret = itr2->second;
  1796. break;
  1797. }
  1798. }
  1799. if (ret)
  1800. break;
  1801. }
  1802. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1803. return ret;
  1804. }
  1805. PlayerHouse* World::GetPlayerHouseByInstanceID(int32 instance_id) {
  1806. PlayerHouse* ret = 0;
  1807. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1808. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1809. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1810. map<int32, PlayerHouse*>::iterator itr2;
  1811. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  1812. if (itr2->second->instance_id == instance_id) {
  1813. ret = itr2->second;
  1814. break;
  1815. }
  1816. }
  1817. if (ret)
  1818. break;
  1819. }
  1820. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1821. return ret;
  1822. }
  1823. vector<PlayerHouse*> World::GetAllPlayerHouses(int32 char_id) {
  1824. vector<PlayerHouse*> ret;
  1825. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1826. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1827. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1828. if (itr->second.count(char_id) > 0)
  1829. ret.push_back(itr->second[char_id]);
  1830. }
  1831. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1832. return ret;
  1833. }
  1834. vector<PlayerHouse*> World::GetAllPlayerHousesByHouseID(int32 house_id) {
  1835. vector<PlayerHouse*> ret;
  1836. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1837. if (m_houseZones.count(house_id) > 0) {
  1838. map<int32, PlayerHouse*>::iterator itr;
  1839. for (itr = m_playerHouses[house_id].begin(); itr != m_playerHouses[house_id].end(); itr++)
  1840. ret.push_back(itr->second);
  1841. }
  1842. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1843. return ret;
  1844. }
  1845. void World::PopulateTOVStatMap() {
  1846. //This function populates a map that converts changed CoE to ToV stats
  1847. tov_itemstat_conversion[0] = TOV_ITEM_STAT_HPREGEN;
  1848. tov_itemstat_conversion[1] = TOV_ITEM_STAT_MANAREGEN;
  1849. tov_itemstat_conversion[2] = TOV_ITEM_STAT_HPREGENPPT;
  1850. tov_itemstat_conversion[3] = TOV_ITEM_STAT_MPREGENPPT;
  1851. tov_itemstat_conversion[4] = TOV_ITEM_STAT_COMBATHPREGENPPT;
  1852. tov_itemstat_conversion[5] = TOV_ITEM_STAT_COMBATMPREGENPPT;
  1853. tov_itemstat_conversion[6] = TOV_ITEM_STAT_MAXHP;
  1854. tov_itemstat_conversion[7] = TOV_ITEM_STAT_MAXHPPERC;
  1855. tov_itemstat_conversion[8] = TOV_ITEM_STAT_MAXHPPERCFINAL;
  1856. tov_itemstat_conversion[9] = TOV_ITEM_STAT_SPEED;
  1857. tov_itemstat_conversion[10] = TOV_ITEM_STAT_SLOW;
  1858. tov_itemstat_conversion[11] = TOV_ITEM_STAT_MOUNTSPEED;
  1859. tov_itemstat_conversion[12] = TOV_ITEM_STAT_MOUNTAIRSPEED;
  1860. tov_itemstat_conversion[13] = TOV_ITEM_STAT_LEAPSPEED;
  1861. tov_itemstat_conversion[14] = TOV_ITEM_STAT_LEAPTIME;
  1862. tov_itemstat_conversion[15] = TOV_ITEM_STAT_GLIDEEFFICIENCY;
  1863. tov_itemstat_conversion[16] = TOV_ITEM_STAT_OFFENSIVESPEED;
  1864. tov_itemstat_conversion[17] = TOV_ITEM_STAT_ATTACKSPEED;
  1865. tov_itemstat_conversion[18] = 698;
  1866. tov_itemstat_conversion[19] = TOV_ITEM_STAT_MAXMANA;
  1867. tov_itemstat_conversion[20] = TOV_ITEM_STAT_MAXMANAPERC;
  1868. tov_itemstat_conversion[21] = TOV_ITEM_STAT_MAXATTPERC;
  1869. tov_itemstat_conversion[22] = TOV_ITEM_STAT_BLURVISION;
  1870. tov_itemstat_conversion[23] = TOV_ITEM_STAT_MAGICLEVELIMMUNITY;
  1871. tov_itemstat_conversion[24] = TOV_ITEM_STAT_HATEGAINMOD;
  1872. tov_itemstat_conversion[25] = TOV_ITEM_STAT_COMBATEXPMOD;
  1873. tov_itemstat_conversion[26] = TOV_ITEM_STAT_TRADESKILLEXPMOD;
  1874. tov_itemstat_conversion[27] = TOV_ITEM_STAT_ACHIEVEMENTEXPMOD;
  1875. tov_itemstat_conversion[28] = TOV_ITEM_STAT_SIZEMOD;
  1876. tov_itemstat_conversion[29] = TOV_ITEM_STAT_DPS;
  1877. tov_itemstat_conversion[30] = 698;
  1878. tov_itemstat_conversion[31] = TOV_ITEM_STAT_STEALTH;
  1879. tov_itemstat_conversion[32] = TOV_ITEM_STAT_INVIS;
  1880. tov_itemstat_conversion[33] = TOV_ITEM_STAT_SEESTEALTH;
  1881. tov_itemstat_conversion[34] = TOV_ITEM_STAT_SEEINVIS;
  1882. tov_itemstat_conversion[35] = TOV_ITEM_STAT_EFFECTIVELEVELMOD;
  1883. tov_itemstat_conversion[36] = TOV_ITEM_STAT_RIPOSTECHANCE;
  1884. tov_itemstat_conversion[37] = TOV_ITEM_STAT_PARRYCHANCE;
  1885. tov_itemstat_conversion[38] = TOV_ITEM_STAT_DODGECHANCE;
  1886. tov_itemstat_conversion[39] = TOV_ITEM_STAT_AEAUTOATTACKCHANCE;
  1887. tov_itemstat_conversion[40] = 698;
  1888. tov_itemstat_conversion[41] = TOV_ITEM_STAT_MULTIATTACKCHANCE;
  1889. tov_itemstat_conversion[42] = 698;
  1890. tov_itemstat_conversion[43] = 698;
  1891. tov_itemstat_conversion[44] = 698;
  1892. tov_itemstat_conversion[45] = TOV_ITEM_STAT_SPELLMULTIATTACKCHANCE;
  1893. tov_itemstat_conversion[46] = 698;
  1894. tov_itemstat_conversion[47] = TOV_ITEM_STAT_FLURRY;
  1895. tov_itemstat_conversion[48] = 698;
  1896. tov_itemstat_conversion[49] = TOV_ITEM_STAT_MELEEDAMAGEMULTIPLIER;
  1897. tov_itemstat_conversion[50] = TOV_ITEM_STAT_EXTRAHARVESTCHANCE;
  1898. tov_itemstat_conversion[51] = TOV_ITEM_STAT_EXTRASHIELDBLOCKCHANCE;
  1899. tov_itemstat_conversion[52] = TOV_ITEM_STAT_ITEMHPREGENPPT;
  1900. tov_itemstat_conversion[53] = TOV_ITEM_STAT_ITEMPPREGENPPT;
  1901. tov_itemstat_conversion[54] = TOV_ITEM_STAT_MELEECRITCHANCE;
  1902. tov_itemstat_conversion[55] = TOV_ITEM_STAT_CRITAVOIDANCE;
  1903. tov_itemstat_conversion[56] = TOV_ITEM_STAT_BENEFICIALCRITCHANCE;
  1904. tov_itemstat_conversion[57] = TOV_ITEM_STAT_CRITBONUS;
  1905. tov_itemstat_conversion[58] = 698;
  1906. tov_itemstat_conversion[59] = TOV_ITEM_STAT_POTENCY;
  1907. tov_itemstat_conversion[60] = 698;
  1908. tov_itemstat_conversion[61] = TOV_ITEM_STAT_UNCONSCIOUSHPMOD;
  1909. tov_itemstat_conversion[62] = TOV_ITEM_STAT_ABILITYREUSESPEED;
  1910. tov_itemstat_conversion[63] = TOV_ITEM_STAT_ABILITYRECOVERYSPEED;
  1911. tov_itemstat_conversion[64] = TOV_ITEM_STAT_ABILITYCASTINGSPEED;
  1912. tov_itemstat_conversion[65] = TOV_ITEM_STAT_SPELLREUSESPEED;
  1913. tov_itemstat_conversion[66] = TOV_ITEM_STAT_MELEEWEAPONRANGE;
  1914. tov_itemstat_conversion[67] = TOV_ITEM_STAT_RANGEDWEAPONRANGE;
  1915. tov_itemstat_conversion[68] = TOV_ITEM_STAT_FALLINGDAMAGEREDUCTION;
  1916. tov_itemstat_conversion[69] = TOV_ITEM_STAT_RIPOSTEDAMAGE;
  1917. tov_itemstat_conversion[70] = TOV_ITEM_STAT_MINIMUMDEFLECTIONCHANCE;
  1918. tov_itemstat_conversion[71] = TOV_ITEM_STAT_MOVEMENTWEAVE;
  1919. tov_itemstat_conversion[72] = TOV_ITEM_STAT_COMBATHPREGEN;
  1920. tov_itemstat_conversion[73] = TOV_ITEM_STAT_COMBATMANAREGEN;
  1921. tov_itemstat_conversion[74] = TOV_ITEM_STAT_CONTESTSPEEDBOOST;
  1922. tov_itemstat_conversion[75] = TOV_ITEM_STAT_TRACKINGAVOIDANCE;
  1923. tov_itemstat_conversion[76] = TOV_ITEM_STAT_STEALTHINVISSPEEDMOD;
  1924. tov_itemstat_conversion[77] = TOV_ITEM_STAT_LOOT_COIN;
  1925. tov_itemstat_conversion[78] = TOV_ITEM_STAT_ARMORMITIGATIONINCREASE;
  1926. tov_itemstat_conversion[79] = TOV_ITEM_STAT_AMMOCONSERVATION;
  1927. tov_itemstat_conversion[80] = TOV_ITEM_STAT_STRIKETHROUGH;
  1928. tov_itemstat_conversion[81] = TOV_ITEM_STAT_STATUSBONUS;
  1929. tov_itemstat_conversion[82] = TOV_ITEM_STAT_ACCURACY;
  1930. tov_itemstat_conversion[83] = TOV_ITEM_STAT_COUNTERSTRIKE;
  1931. tov_itemstat_conversion[84] = TOV_ITEM_STAT_SHIELDBASH;
  1932. tov_itemstat_conversion[85] = TOV_ITEM_STAT_WEAPONDAMAGEBONUS;
  1933. tov_itemstat_conversion[86] = 698;
  1934. tov_itemstat_conversion[87] = TOV_ITEM_STAT_WEAPONDAMAGEBONUSMELEEONLY;
  1935. tov_itemstat_conversion[88] = TOV_ITEM_STAT_ADDITIONALRIPOSTECHANCE;
  1936. tov_itemstat_conversion[89] = TOV_ITEM_STAT_PVPTOUGHNESS;
  1937. tov_itemstat_conversion[90] = TOV_ITEM_STAT_PVPLETHALITY;
  1938. tov_itemstat_conversion[91] = TOV_ITEM_STAT_STAMINABONUS;
  1939. tov_itemstat_conversion[92] = TOV_ITEM_STAT_WISDOMMITBONUS;
  1940. tov_itemstat_conversion[93] = TOV_ITEM_STAT_HEALRECEIVE;
  1941. tov_itemstat_conversion[94] = TOV_ITEM_STAT_HEALRECEIVEPERC;
  1942. tov_itemstat_conversion[95] = TOV_ITEM_STAT_PVPCRITICALMITIGATION;
  1943. tov_itemstat_conversion[96] = TOV_ITEM_STAT_BASEAVOIDANCEBONUS;
  1944. tov_itemstat_conversion[97] = TOV_ITEM_STAT_INCOMBATSAVAGERYREGEN;
  1945. tov_itemstat_conversion[98] = TOV_ITEM_STAT_OUTOFCOMBATSAVAGERYREGEN;
  1946. tov_itemstat_conversion[99] = TOV_ITEM_STAT_SAVAGERYREGEN;
  1947. tov_itemstat_conversion[100] = TOV_ITEM_STAT_SAVAGERYGAINMOD;
  1948. tov_itemstat_conversion[101] = TOV_ITEM_STAT_MAXSAVAGERYLEVEL;
  1949. }
  1950. int32 World::LoadItemBlueStats() {
  1951. Query query;
  1952. MYSQL_ROW row;
  1953. int32 count = 0;
  1954. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT version_range1,version_range2,emu_stat,name,stat from itemstats");
  1955. if (result && mysql_num_rows(result) > 0) {
  1956. while (result && (row = mysql_fetch_row(result))) {
  1957. count++;
  1958. if (atoi(row[0]) >= 63119) //KA
  1959. ka_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1960. else if (atoi(row[0]) >= 57101) // ToV
  1961. tov_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1962. else if (atoi(row[0]) >= 1193) // CoE
  1963. coe_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1964. else if (atoi(row[0]) >= 1096) // DoV
  1965. dov_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1966. }
  1967. }
  1968. return count;
  1969. }
  1970. sint64 World::newValue = 0;
  1971. sint16 World::GetItemStatAOMValue(sint16 subtype) {
  1972. sint16 tmp_subtype = subtype;
  1973. // this is ugly for now cause I didn't want to map it all out, see a better way later but a lot of these are just slightly shifted
  1974. if(subtype > 39)
  1975. {
  1976. // 88 needs to be something else (crit mitigation)
  1977. // 19 needs to be something else (ability reuse speed) which is 62
  1978. if(subtype == 21) // ITEM_STAT_MAXATTPERC
  1979. tmp_subtype = 20;
  1980. else if(subtype == 41) // flurry
  1981. tmp_subtype = 39;
  1982. else if(subtype == 47) // flurry
  1983. tmp_subtype = 41;
  1984. else if(subtype == 49) // flurry
  1985. tmp_subtype = 42;
  1986. else if(subtype == 51) // ITEM_STAT_EXTRASHIELDBLOCKCHANCE
  1987. tmp_subtype = 44;
  1988. //tmp_subtype = 43 is bountiful harvest
  1989. else if(subtype == 54 && subtype <= 57) // ITEM_STAT_MELEECRITCHANCE
  1990. tmp_subtype = subtype - 7;
  1991. else if(subtype == 59) // ITEM_STAT_POTENCY
  1992. tmp_subtype = 51;
  1993. else if(subtype >= 61 && subtype <= 85) // ITEM_STAT_RANGEDWEAPONRANGE
  1994. tmp_subtype = subtype - 9; //
  1995. else if(subtype >= 86 && subtype <= 101) // ITEM_STAT_WEAPONDAMAGEBONUSMELEEONLY
  1996. tmp_subtype = subtype - 8; //
  1997. else if(subtype == 102) // ITEM_STAT_SPELLWEAPONDAMAGEBONUS
  1998. tmp_subtype = 77; //
  1999. else if(subtype >= 103 && subtype <= 110)
  2000. tmp_subtype = subtype - 9;
  2001. else if(subtype == 122) // ITEM_STAT_ABILITYDOUBLECASTCHANCE
  2002. tmp_subtype = 40; //
  2003. else if(subtype == 124) // ITEM_STAT_STATUSEARNED
  2004. tmp_subtype = 27; //
  2005. else
  2006. tmp_subtype += 1;
  2007. // 80 serves as ranged weapon range increase, but so does 58?
  2008. }
  2009. else if((subtype > 18 && subtype < 28) || subtype > 30) // max mana was 18
  2010. tmp_subtype = subtype - 1;
  2011. else if(subtype == 5)
  2012. tmp_subtype = 46;
  2013. else if(subtype == 4)
  2014. tmp_subtype = 45;
  2015. LogWrite(PLAYER__DEBUG, 0, "Player", "Convert type: %i -> %i", subtype, tmp_subtype);
  2016. return tmp_subtype;
  2017. }
  2018. sint16 World::GetItemStatTOVValue(sint16 subtype) {
  2019. return (tov_itemstat_conversion[subtype] - 600);
  2020. }
  2021. sint16 World::GetItemStatDOVValue(sint16 subtype) {
  2022. return (dov_itemstat_conversion[subtype] - 600);
  2023. }
  2024. sint16 World::GetItemStatCOEValue(sint16 subtype) {
  2025. return (coe_itemstat_conversion[subtype] - 600);
  2026. }
  2027. sint16 World::GetItemStatKAValue(sint16 subtype) {
  2028. return (ka_itemstat_conversion[subtype] - 600);
  2029. }
  2030. bool World::CheckTempBugCRC(char* msg)
  2031. {
  2032. MBugReport.writelock();
  2033. sint32 crc = GetItemNameCrc(std::string(msg));
  2034. if (bug_report_crc.count(crc) > 0)
  2035. {
  2036. MBugReport.releasewritelock();
  2037. return true;
  2038. }
  2039. else
  2040. bug_report_crc.insert(make_pair(crc, true));
  2041. MBugReport.releasewritelock();
  2042. return false;
  2043. }
  2044. #ifdef WIN32
  2045. ulong World::GetCurrentThreadID(){
  2046. return GetCurrentThreadId();
  2047. }
  2048. int64 World::GetThreadUsageCPUTime(){
  2049. HANDLE handle = GetCurrentThread();
  2050. int64 lpCreationTime;
  2051. int64 lpExitTime;
  2052. int64 lpKernelTime;
  2053. int64 lpUserTime;
  2054. if(GetThreadTimes(handle, (FILETIME*)&lpCreationTime, (FILETIME*)&lpExitTime, (FILETIME*)&lpKernelTime, (FILETIME*)&lpUserTime))
  2055. return lpKernelTime + lpUserTime;
  2056. return 0;
  2057. }
  2058. #else
  2059. #endif
  2060. void World::SyncCharacterAbilities(Client* client)
  2061. {
  2062. MStartingLists.readlock();
  2063. int8 baseClass = classes.GetBaseClass(client->GetPlayer()->GetAdventureClass());
  2064. int8 secondaryClass = classes.GetSecondaryBaseClass(client->GetPlayer()->GetAdventureClass());
  2065. int8 actualClass = client->GetPlayer()->GetAdventureClass();
  2066. int8 baseRace = client->GetPlayer()->GetRace();
  2067. bool reloadSpells = false;
  2068. multimap<int8, multimap<int8, StartingSkill>*>::iterator skill_itr = starting_skills.begin();
  2069. multimap<int8, multimap<int8, StartingSpell>*>::iterator spell_itr = starting_spells.begin();
  2070. bool isComplete = false;
  2071. int8 wait_iterations = 0; // wait 5 iterations and give up if db takes too long
  2072. do
  2073. {
  2074. bool isProcessing = false;
  2075. if (skill_itr != starting_skills.end())
  2076. {
  2077. isProcessing = true;
  2078. // race = 255 is wildcard all, otherwise needs to match the race id
  2079. if (skill_itr->first == 255 || skill_itr->first == baseRace)
  2080. {
  2081. multimap<int8, StartingSkill>::iterator child_itr;
  2082. for (child_itr = skill_itr->second->begin(); child_itr != skill_itr->second->end(); child_itr++)
  2083. {
  2084. // class = 255 is wildcard all, otherwise needs to match the class id
  2085. if (child_itr->first == 255 ||
  2086. child_itr->first == baseClass ||
  2087. child_itr->first == secondaryClass ||
  2088. child_itr->first == actualClass)
  2089. {
  2090. if (!client->GetPlayer()->skill_list.HasSkill(child_itr->second.skill_id))
  2091. {
  2092. Query query;
  2093. LogWrite(PLAYER__DEBUG, 0, "Player", "Adding skill %i for race: %i, class: %i for char_id: %u", child_itr->second.skill_id, baseRace, baseClass, client->GetCharacterID());
  2094. query.AddQueryAsync(client->GetCharacterID(), &database, Q_INSERT, "INSERT IGNORE INTO character_skills (char_id, skill_id, current_val, max_val) VALUES (%u, %u, %u, %u)",
  2095. client->GetCharacterID(), child_itr->second.skill_id, child_itr->second.current_val, child_itr->second.max_val);
  2096. client->GetPlayer()->AddSkill(child_itr->second.skill_id, child_itr->second.current_val, child_itr->second.max_val);
  2097. }
  2098. }
  2099. }
  2100. }
  2101. skill_itr++;
  2102. }
  2103. if (spell_itr != starting_spells.end())
  2104. {
  2105. isProcessing = true;
  2106. // race = 255 is wildcard all, otherwise needs to match the race id
  2107. if (spell_itr->first == 255 || spell_itr->first == baseRace)
  2108. {
  2109. multimap<int8, StartingSpell>::iterator child_itr;
  2110. for (child_itr = spell_itr->second->begin(); child_itr != spell_itr->second->end(); child_itr++)
  2111. {
  2112. // class = 255 is wildcard all, otherwise needs to match the class id
  2113. if (child_itr->first == 255 ||
  2114. child_itr->first == baseClass ||
  2115. child_itr->first == secondaryClass ||
  2116. child_itr->first == actualClass)
  2117. {
  2118. if (!client->GetPlayer()->HasSpell(child_itr->second.spell_id, child_itr->second.tier, true))
  2119. {
  2120. Query query;
  2121. LogWrite(PLAYER__DEBUG, 0, "Player", "Adding spell %i for race: %i, class: %i for char_id: %u", child_itr->second.spell_id, baseRace, baseClass, client->GetCharacterID());
  2122. // knowledge_slot is a signed int in the DB
  2123. query.AddQueryAsync(client->GetCharacterID(), &database, Q_INSERT, "INSERT IGNORE INTO character_spells (char_id, spell_id, tier, knowledge_slot) VALUES (%u, %u, %u, %i)",
  2124. client->GetCharacterID(), child_itr->second.spell_id, child_itr->second.tier, child_itr->second.knowledge_slot);
  2125. // reload spells, we don't know the spellbook or timer info
  2126. reloadSpells = true;
  2127. }
  2128. }
  2129. }
  2130. }
  2131. spell_itr++;
  2132. }
  2133. // poor mans async kill just in case, we don't want a client stuck here, they can get the spells on next zone
  2134. if (!isProcessing)
  2135. {
  2136. bool isDBActive = database.IsActiveQuery(client->GetCharacterID());
  2137. if (isDBActive && wait_iterations < 5)
  2138. {
  2139. wait_iterations++;
  2140. }
  2141. else
  2142. isComplete = true;
  2143. }
  2144. } while (!isComplete);
  2145. MStartingLists.releasereadlock();
  2146. if (reloadSpells)
  2147. database.LoadCharacterSpells(client->GetCharacterID(), client->GetPlayer());
  2148. }
  2149. void World::LoadStartingLists()
  2150. {
  2151. LogWrite(WORLD__DEBUG, 1, "World", "-Loading `starting_skills`...");
  2152. database.LoadStartingSkills(this);
  2153. LogWrite(WORLD__DEBUG, 1, "World", "-Loading `starting_spells`...");
  2154. database.LoadStartingSpells(this);
  2155. }
  2156. void World::PurgeStartingLists()
  2157. {
  2158. MStartingLists.writelock();
  2159. multimap<int8, multimap<int8, StartingSkill>*>::iterator skill_itr;
  2160. for (skill_itr = starting_skills.begin(); skill_itr != starting_skills.end(); skill_itr++)
  2161. {
  2162. multimap<int8, StartingSkill>* tmpMap = skill_itr->second;
  2163. safe_delete(tmpMap);
  2164. }
  2165. starting_skills.clear();
  2166. multimap<int8, multimap<int8, StartingSpell>*>::iterator spell_itr;
  2167. for (spell_itr = starting_spells.begin(); spell_itr != starting_spells.end(); spell_itr++)
  2168. {
  2169. multimap<int8, StartingSpell>* tmpMap = spell_itr->second;
  2170. safe_delete(tmpMap);
  2171. }
  2172. starting_spells.clear();
  2173. MStartingLists.releasewritelock();
  2174. }
  2175. void World::SetReloadingSubsystem(string subsystem) {
  2176. MReloadingSubsystems.lock();
  2177. reloading_subsystems[subsystem] = Timer::GetCurrentTime2();
  2178. MReloadingSubsystems.unlock();
  2179. }
  2180. void World::RemoveReloadingSubSystem(string subsystem) {
  2181. MReloadingSubsystems.lock();
  2182. if (reloading_subsystems.count(subsystem) > 0)
  2183. reloading_subsystems.erase(subsystem);
  2184. MReloadingSubsystems.unlock();
  2185. }
  2186. bool World::IsReloadingSubsystems() {
  2187. bool result = false;
  2188. MReloadingSubsystems.lock();
  2189. result = reloading_subsystems.size() > 0;
  2190. MReloadingSubsystems.unlock();
  2191. return result;
  2192. }
  2193. map<string, int32> World::GetOldestReloadingSubsystem() {
  2194. map<string, int32> result;
  2195. MReloadingSubsystems.lock();
  2196. int32 current_time = Timer::GetCurrentTime2();
  2197. map<string, int32>::iterator itr;
  2198. int32 oldest = current_time;
  2199. string oldestname = "";
  2200. for (itr = reloading_subsystems.begin(); itr != reloading_subsystems.end(); itr++) {
  2201. if (itr->second < oldest)
  2202. oldestname = itr->first;
  2203. }
  2204. result[oldestname] = oldest;
  2205. MReloadingSubsystems.unlock();
  2206. return result;
  2207. }
  2208. void ZoneList::WatchdogHeartbeat()
  2209. {
  2210. list<ZoneServer*>::iterator zone_iter;
  2211. ZoneServer* tmp = 0;
  2212. MZoneList.writelock(__FUNCTION__, __LINE__);
  2213. bool match = false;
  2214. for (zone_iter = zlist.begin(); zone_iter != zlist.end(); zone_iter++)
  2215. {
  2216. tmp = *zone_iter;
  2217. if (tmp)
  2218. {
  2219. int32 curTime = Timer::GetCurrentTime2();
  2220. sint64 diff = (sint64)curTime - (sint64)tmp->GetWatchdogTime();
  2221. if (diff > 120000)
  2222. {
  2223. LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung for %i milliseconds.. attempting to cancel threads...", tmp->GetZoneName(), diff);
  2224. #ifndef WIN32
  2225. tmp->CancelThreads();
  2226. zlist.erase(zone_iter);
  2227. safe_delete(tmp);
  2228. #endif
  2229. MZoneList.releasewritelock(__FUNCTION__, __LINE__);
  2230. match = true;
  2231. break;
  2232. }
  2233. else if (diff > 90000 && !tmp->isZoneShuttingDown())
  2234. {
  2235. tmp->SetWatchdogTime(Timer::GetCurrentTime2()); // reset so we don't continuously flood this heartbeat
  2236. map<string, int32> oldest_process = world.GetOldestReloadingSubsystem();
  2237. if (oldest_process.size() > 0) {
  2238. map<string, int32>::iterator itr = oldest_process.begin();
  2239. if(itr != oldest_process.end())
  2240. LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung for %i milliseconds.. while waiting for %s to reload...attempting shutdown", tmp->GetZoneName(), diff, itr->first);
  2241. else
  2242. LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung for %i milliseconds... attempting shutdown", tmp->GetZoneName(), diff);
  2243. }
  2244. else
  2245. LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung for %i milliseconds.. attempting shutdown", tmp->GetZoneName(), diff);
  2246. tmp->Shutdown();
  2247. }
  2248. else if (diff > 30000)
  2249. {
  2250. if (world.IsReloadingSubsystems()) {
  2251. if (world.GetSuppressedWarningTime() == 0) {
  2252. world.SetSuppressedWarning();
  2253. map<string, int32> oldest_process = world.GetOldestReloadingSubsystem();
  2254. if (oldest_process.size() > 0) {
  2255. map<string, int32>::iterator itr = oldest_process.begin();
  2256. if(itr != oldest_process.end())
  2257. LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung for %i milliseconds.. while waiting for %s to reload...", tmp->GetZoneName(), diff, itr->first);
  2258. else
  2259. LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung for %i milliseconds...", tmp->GetZoneName(), diff);
  2260. }
  2261. }
  2262. continue;
  2263. }
  2264. }
  2265. else if (diff > 60000 && !tmp->isZoneShuttingDown())
  2266. {
  2267. if (world.IsReloadingSubsystems())
  2268. continue;
  2269. LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung for %i milliseconds.. attempting shutdown", tmp->GetZoneName(), diff);
  2270. tmp->Shutdown();
  2271. }
  2272. }
  2273. }
  2274. if(!match)
  2275. MZoneList.releasewritelock(__FUNCTION__, __LINE__);
  2276. }
  2277. void World::LoadRegionMaps(std::string zoneFile)
  2278. {
  2279. string zoneToLower(zoneFile);
  2280. boost::algorithm::to_lower(zoneToLower);
  2281. MWorldRegionMaps.writelock();
  2282. std::map<std::string, RegionMapRange*>::iterator itr;
  2283. itr = region_maps.find(zoneToLower);
  2284. if (itr == region_maps.end())
  2285. {
  2286. RegionMapRange* newRange = new RegionMapRange();
  2287. newRange->AddVersionRange(zoneFile);
  2288. region_maps.insert(make_pair(zoneToLower, newRange));
  2289. }
  2290. MWorldRegionMaps.releasewritelock();
  2291. }
  2292. RegionMap* World::GetRegionMap(std::string zoneFile, int32 client_version)
  2293. {
  2294. string zoneToLower(zoneFile);
  2295. boost::algorithm::to_lower(zoneToLower);
  2296. MWorldRegionMaps.readlock();
  2297. std::map<std::string, RegionMapRange*>::iterator itr;
  2298. itr = region_maps.find(zoneToLower);
  2299. if ( itr != region_maps.end())
  2300. {
  2301. std::map<VersionRange*, RegionMap*>::iterator rmitr;
  2302. rmitr = itr->second->FindRegionByVersion(client_version);
  2303. if ( rmitr != itr->second->GetRangeEnd())
  2304. {
  2305. MWorldRegionMaps.releasereadlock();
  2306. return rmitr->second;
  2307. }
  2308. }
  2309. MWorldRegionMaps.releasereadlock();
  2310. return nullptr;
  2311. }
  2312. void World::LoadMaps(std::string zoneFile)
  2313. {
  2314. string zoneToLower(zoneFile);
  2315. boost::algorithm::to_lower(zoneToLower);
  2316. MWorldMaps.writelock();
  2317. std::map<std::string, MapRange*>::iterator itr;
  2318. itr = maps.find(zoneToLower);
  2319. if (itr == maps.end())
  2320. {
  2321. MapRange* newRange = new MapRange();
  2322. newRange->AddVersionRange(zoneFile);
  2323. maps.insert(make_pair(zoneToLower, newRange));
  2324. }
  2325. MWorldMaps.releasewritelock();
  2326. }
  2327. Map* World::GetMap(std::string zoneFile, int32 client_version)
  2328. {
  2329. string zoneToLower(zoneFile);
  2330. boost::algorithm::to_lower(zoneToLower);
  2331. MWorldMaps.readlock();
  2332. std::map<std::string, MapRange*>::iterator itr;
  2333. itr = maps.find(zoneToLower);
  2334. if ( itr != maps.end())
  2335. {
  2336. std::map<VersionRange*, Map*>::iterator rmitr;
  2337. rmitr = itr->second->FindMapByVersion(client_version);
  2338. if ( rmitr != itr->second->GetRangeEnd())
  2339. {
  2340. MWorldMaps.releasereadlock();
  2341. return rmitr->second;
  2342. }
  2343. }
  2344. MWorldMaps.releasereadlock();
  2345. return nullptr;
  2346. }
  2347. void World::SendTimeUpdate()
  2348. {
  2349. zone_list.SendTimeUpdate();
  2350. }