World.cpp 81 KB

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