9
3

World.cpp 81 KB

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