World.cpp 66 KB

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