9
3

World.cpp 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094
  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() < 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. strncpy(report->category, list[0].c_str(), list[0].length() > 63 ? 63 : list[0].length());
  876. strncpy(report->subcategory, list[1].c_str(), list[1].length() > 63 ? 63 : list[1].length());
  877. strncpy(report->causes_crash, list[2].c_str(), list[2].length() > 63 ? 63 : list[2].length());
  878. strncpy(report->reproducible, list[3].c_str(), list[3].length() > 63 ? 63 : list[3].length());
  879. strncpy(report->summary, list[4].c_str(), list[4].length() > 127 ? 127 : list[4].length());
  880. strncpy(report->description, list[5].c_str(), list[5].length() > 1999 ? 1999 : list[5].length());
  881. strncpy(report->version, list[6].c_str(), list[6].length() > 31 ? 31 : list[6].length());
  882. strncpy(report->player, player_name, strlen(player_name) > 63 ? 63 : strlen(player_name));
  883. strncpy(report->spawn_name, spawn_name, strlen(spawn_name) > 63 ? 63 : strlen(spawn_name));
  884. report->spawn_id = spawn_id;
  885. report->account_id = account_id;
  886. report->zone_id = zone_id;
  887. loginserver.SendPacket(outpack);
  888. 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);
  889. safe_delete(outpack);
  890. return true;
  891. }
  892. void ZoneList::WritePlayerStatistics() {
  893. list<ZoneServer*>::iterator zone_itr;
  894. MZoneList.readlock(__FUNCTION__, __LINE__);
  895. for (zone_itr = zlist.begin(); zone_itr != zlist.end(); zone_itr++)
  896. (*zone_itr)->WritePlayerStatistics();
  897. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  898. }
  899. void ZoneList::ShutDownZones(){
  900. LogWrite(WORLD__INFO, 0, "World", "Shutting down all zones, please wait...");
  901. list<ZoneServer*>::iterator zone_itr;
  902. int32 size = 0;
  903. MZoneList.readlock(__FUNCTION__, __LINE__);
  904. for (zone_itr = zlist.begin(); zone_itr != zlist.end(); zone_itr++){
  905. (*zone_itr)->Shutdown();
  906. }
  907. size = zlist.size();
  908. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  909. while(size > 0){
  910. Sleep(10);
  911. MZoneList.readlock(__FUNCTION__, __LINE__);
  912. size = zlist.size();
  913. MZoneList.releasereadlock(__FUNCTION__, __LINE__);
  914. }
  915. LogWrite(WORLD__INFO, 0, "World", "Zone shutdown complete");
  916. }
  917. void ZoneList::ReloadMail() {
  918. map<string, Client*>::iterator itr;
  919. MClientList.writelock(__FUNCTION__, __LINE__);
  920. for (itr = client_map.begin(); itr != client_map.end(); itr++) {
  921. itr->second->GetPlayer()->DeleteMail();
  922. database.LoadPlayerMail(itr->second);
  923. }
  924. MClientList.releasewritelock(__FUNCTION__, __LINE__);
  925. }
  926. void World::AddSpawnScript(int32 id, const char* name){
  927. MSpawnScripts.lock();
  928. if(name)
  929. spawn_scripts[id] = string(name);
  930. MSpawnScripts.unlock();
  931. }
  932. void World::AddSpawnEntryScript(int32 id, const char* name){
  933. MSpawnScripts.lock();
  934. if(name)
  935. spawnentry_scripts[id] = string(name);
  936. MSpawnScripts.unlock();
  937. }
  938. void World::AddSpawnLocationScript(int32 id, const char* name){
  939. MSpawnScripts.lock();
  940. if(name)
  941. spawnlocation_scripts[id] = string(name);
  942. MSpawnScripts.unlock();
  943. }
  944. void World::AddZoneScript(int32 id, const char* name) {
  945. MZoneScripts.lock();
  946. if (name)
  947. zone_scripts[id] = string(name);
  948. MZoneScripts.unlock();
  949. }
  950. const char* World::GetSpawnScript(int32 id){
  951. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  952. const char* ret = 0;
  953. MSpawnScripts.lock();
  954. if(spawn_scripts.count(id) > 0)
  955. ret = spawn_scripts[id].c_str();
  956. MSpawnScripts.unlock();
  957. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  958. return ret;
  959. }
  960. const char* World::GetSpawnEntryScript(int32 id){
  961. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  962. const char* ret = 0;
  963. MSpawnScripts.lock();
  964. if(spawnentry_scripts.count(id) > 0)
  965. ret = spawnentry_scripts[id].c_str();
  966. MSpawnScripts.unlock();
  967. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  968. return ret;
  969. }
  970. const char* World::GetSpawnLocationScript(int32 id){
  971. LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
  972. const char* ret = 0;
  973. MSpawnScripts.lock();
  974. if(spawnlocation_scripts.count(id) > 0)
  975. ret = spawnlocation_scripts[id].c_str();
  976. MSpawnScripts.unlock();
  977. LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
  978. return ret;
  979. }
  980. const char* World::GetZoneScript(int32 id) {
  981. const char* ret = 0;
  982. MZoneScripts.lock();
  983. if (zone_scripts.count(id) > 0)
  984. ret = zone_scripts[id].c_str();
  985. MZoneScripts.unlock();
  986. return ret;
  987. }
  988. void World::ResetSpawnScripts(){
  989. MSpawnScripts.lock();
  990. spawn_scripts.clear();
  991. spawnentry_scripts.clear();
  992. spawnlocation_scripts.clear();
  993. MSpawnScripts.unlock();
  994. }
  995. void World::ResetZoneScripts() {
  996. MZoneScripts.lock();
  997. zone_scripts.clear();
  998. MZoneScripts.unlock();
  999. }
  1000. vector<MerchantItemInfo>* World::GetMerchantItemList(int32 merchant_id, int8 merchant_type, Player* player)
  1001. {
  1002. vector<MerchantItemInfo>* ret = 0;
  1003. MMerchantList.lock();
  1004. if(merchant_info.count(merchant_id) > 0)
  1005. {
  1006. MerchantInfo* info = merchant_info[merchant_id];
  1007. vector<MerchantItemInfo>::iterator itr;
  1008. int32 inventory_id = 0;
  1009. Item* item = 0;
  1010. for(int i=info->inventory_ids.size()-1;i>=0;i--)
  1011. {
  1012. inventory_id = info->inventory_ids[i];
  1013. if(merchant_inventory_items.count(inventory_id) > 0)
  1014. {
  1015. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++)
  1016. {
  1017. if(!ret)
  1018. ret = new vector<MerchantItemInfo>;
  1019. item = master_item_list.GetItem((*itr).item_id);
  1020. // if NOT spell merchant, OR
  1021. // skill req is any skill, OR player has the skill, AND
  1022. // skill req2 is any skill, OR player has the skill2
  1023. 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)) ) ) )
  1024. (*ret).push_back(*itr);
  1025. }
  1026. }
  1027. }
  1028. }
  1029. MMerchantList.unlock();
  1030. return ret;
  1031. }
  1032. vector<MerchantItemInfo>* World::GetMerchantList(int32 merchant_id){
  1033. vector<MerchantItemInfo>* ret = 0;
  1034. MMerchantList.lock();
  1035. if(merchant_info.count(merchant_id) > 0){
  1036. MerchantInfo* info = merchant_info[merchant_id];
  1037. map<int32, int16>::iterator itr;
  1038. int32 inventory_id = 0;
  1039. for(int i=info->inventory_ids.size()-1;i>=0;i--){
  1040. inventory_id = info->inventory_ids[i];
  1041. if(merchant_inventory_items.count(inventory_id) > 0){
  1042. ret = &merchant_inventory_items[inventory_id];
  1043. }
  1044. }
  1045. }
  1046. MMerchantList.unlock();
  1047. return ret;
  1048. }
  1049. void World::AddMerchantItem(int32 inventory_id, MerchantItemInfo ItemInfo){
  1050. MMerchantList.lock();
  1051. merchant_inventory_items[inventory_id].push_back(ItemInfo);
  1052. MMerchantList.unlock();
  1053. }
  1054. void World::DeleteMerchantItems(){
  1055. MMerchantList.lock();
  1056. merchant_inventory_items.clear();
  1057. MMerchantList.unlock();
  1058. }
  1059. void World::RemoveMerchantItem(int32 inventory_id, int32 item_id){
  1060. MMerchantList.lock();
  1061. if(merchant_inventory_items.count(inventory_id) > 0) {
  1062. vector<MerchantItemInfo>::iterator itr;
  1063. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1064. if ((*itr).item_id == item_id) {
  1065. merchant_inventory_items[inventory_id].erase(itr);
  1066. break;
  1067. }
  1068. }
  1069. }
  1070. MMerchantList.unlock();
  1071. }
  1072. int16 World::GetMerchantItemQuantity(int32 merchant_id, int32 item_id){
  1073. int16 amount = 0;
  1074. int32 inventory_id = GetInventoryID(merchant_id, item_id);
  1075. if(inventory_id > 0){
  1076. MMerchantList.lock();
  1077. vector<MerchantItemInfo>::iterator itr;
  1078. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1079. if ((*itr).item_id == item_id)
  1080. amount = (*itr).quantity;
  1081. }
  1082. MMerchantList.unlock();
  1083. }
  1084. return amount;
  1085. }
  1086. int32 World::GetInventoryID(int32 merchant_id, int32 item_id){
  1087. int32 ret = 0;
  1088. MMerchantList.lock();
  1089. if(merchant_info.count(merchant_id) > 0){
  1090. MerchantInfo* info = merchant_info[merchant_id];
  1091. vector<MerchantItemInfo>::iterator itr;
  1092. int32 inventory_id = 0;
  1093. for(int i=info->inventory_ids.size()-1;i>=0;i--){
  1094. inventory_id = info->inventory_ids[i];
  1095. if(merchant_inventory_items.count(inventory_id) > 0){
  1096. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1097. if((*itr).item_id == item_id){
  1098. ret = inventory_id;
  1099. break;
  1100. }
  1101. }
  1102. if(ret > 0)
  1103. break;
  1104. }
  1105. }
  1106. }
  1107. MMerchantList.unlock();
  1108. return ret;
  1109. }
  1110. void World::DecreaseMerchantQuantity(int32 merchant_id, int32 item_id, int16 amount){
  1111. int16 total_left = GetMerchantItemQuantity(merchant_id, item_id);
  1112. if(total_left > 0 && total_left < 0xFFFF){
  1113. int32 inventory_id = GetInventoryID(merchant_id, item_id);
  1114. if(inventory_id > 0){
  1115. MMerchantList.lock();
  1116. vector<MerchantItemInfo>::iterator itr;
  1117. for(itr = merchant_inventory_items[inventory_id].begin(); itr != merchant_inventory_items[inventory_id].end(); itr++){
  1118. if ((*itr).item_id == item_id) {
  1119. if(total_left <= amount) {
  1120. merchant_inventory_items[inventory_id].erase(itr);
  1121. amount = 0;
  1122. break;
  1123. }
  1124. else
  1125. (*itr).quantity -= amount;
  1126. amount = (*itr).quantity;
  1127. }
  1128. }
  1129. MMerchantList.unlock();
  1130. }
  1131. }
  1132. }
  1133. MerchantInfo* World::GetMerchantInfo(int32 merchant_id){
  1134. MerchantInfo* ret = 0;
  1135. MMerchantList.lock();
  1136. if(merchant_info.count(merchant_id) > 0)
  1137. ret = merchant_info[merchant_id];
  1138. MMerchantList.unlock();
  1139. return ret;
  1140. }
  1141. void World::AddMerchantInfo(int32 merchant_id, MerchantInfo* info){
  1142. MMerchantList.lock();
  1143. if(merchant_info.count(merchant_id) > 0){
  1144. safe_delete(merchant_info[merchant_id]);
  1145. }
  1146. merchant_info[merchant_id] = info;
  1147. MMerchantList.unlock();
  1148. }
  1149. map<int32, MerchantInfo*>* World::GetMerchantInfo() {
  1150. return &merchant_info;
  1151. }
  1152. void World::DeleteMerchantsInfo(){
  1153. MMerchantList.lock();
  1154. map<int32, MerchantInfo*>::iterator itr;
  1155. for(itr = merchant_info.begin(); itr != merchant_info.end(); itr++){
  1156. safe_delete(itr->second);
  1157. }
  1158. merchant_info.clear();
  1159. MMerchantList.unlock();
  1160. }
  1161. void World::DeleteSpawns(){
  1162. //reloading = true;
  1163. //ClearLootTables();
  1164. /*
  1165. map<int32, NPC*>::iterator npc_list_iter;
  1166. for(npc_list_iter=npc_list.begin();npc_list_iter!=npc_list.end();npc_list_iter++) {
  1167. safe_delete(npc_list_iter->second);
  1168. }
  1169. npc_list.clear();
  1170. map<int32, Object*>::iterator object_list_iter;
  1171. for(object_list_iter=object_list.begin();object_list_iter!=object_list.end();object_list_iter++) {
  1172. safe_delete(object_list_iter->second);
  1173. }
  1174. object_list.clear();
  1175. map<int32, GroundSpawn*>::iterator groundspawn_list_iter;
  1176. for(groundspawn_list_iter=groundspawn_list.begin();groundspawn_list_iter!=groundspawn_list.end();groundspawn_list_iter++) {
  1177. safe_delete(groundspawn_list_iter->second);
  1178. }
  1179. groundspawn_list.clear();
  1180. map<int32, Widget*>::iterator widget_list_iter;
  1181. for(widget_list_iter=widget_list.begin();widget_list_iter!=widget_list.end();widget_list_iter++) {
  1182. safe_delete(widget_list_iter->second);
  1183. }
  1184. widget_list.clear();
  1185. map<int32, Sign*>::iterator sign_list_iter;
  1186. for(sign_list_iter=sign_list.begin();sign_list_iter!=sign_list.end();sign_list_iter++) {
  1187. safe_delete(sign_list_iter->second);
  1188. }
  1189. sign_list.clear();*/
  1190. map<int32, AppearanceData*>::iterator appearance_list_iter;
  1191. for(appearance_list_iter=npc_appearance_list.begin();appearance_list_iter!=npc_appearance_list.end();appearance_list_iter++) {
  1192. safe_delete(appearance_list_iter->second);
  1193. }
  1194. npc_appearance_list.clear();
  1195. /*
  1196. map<int32, vector<EntityCommand*>* >::iterator command_list_iter;
  1197. for(command_list_iter=entity_command_list.begin();command_list_iter!=entity_command_list.end();command_list_iter++) {
  1198. vector<EntityCommand*>* v = command_list_iter->second;
  1199. if(v){
  1200. for(int32 i=0;i<v->size();i++){
  1201. safe_delete(v->at(i));
  1202. }
  1203. safe_delete(v);
  1204. }
  1205. }
  1206. entity_command_list.clear();
  1207. */
  1208. //DeleteGroundSpawnItems();
  1209. //DeleteTransporters();
  1210. //DeleteTransporterMaps();
  1211. }
  1212. void World::ReloadGuilds() {
  1213. guild_list.GetGuilds()->clear(true);
  1214. database.LoadGuilds();
  1215. }
  1216. int8 World::GetClassID(const char* name){
  1217. return classes.GetClassID(name);
  1218. }
  1219. void World::WritePlayerStatistics() {
  1220. zone_list.WritePlayerStatistics();
  1221. }
  1222. void World::WriteServerStatistics() {
  1223. map<int32, Statistic*>::iterator itr;
  1224. Statistic* stat = 0;
  1225. for (itr = server_statistics.begin(); itr != server_statistics.end(); itr++) {
  1226. stat = itr->second;
  1227. if (stat->save_needed) {
  1228. stat->save_needed = false;
  1229. database.WriteServerStatistic(stat);
  1230. }
  1231. }
  1232. database.WriteServerStatisticsNeededQueries();
  1233. }
  1234. void World::AddServerStatistic(int32 stat_id, sint32 stat_value, int32 stat_date) {
  1235. if (server_statistics.count(stat_id) == 0) {
  1236. Statistic* stat = new Statistic;
  1237. stat->stat_id = stat_id;
  1238. stat->stat_value = stat_value;
  1239. stat->stat_date = stat_date;
  1240. stat->save_needed = false;
  1241. server_statistics[stat_id] = stat;
  1242. }
  1243. }
  1244. void World::UpdateServerStatistic(int32 stat_id, sint32 stat_value, bool overwrite) {
  1245. if (server_statistics.count(stat_id) == 0)
  1246. AddServerStatistic(stat_id, stat_value, 0);
  1247. Statistic* stat = server_statistics[stat_id];
  1248. overwrite == true ? stat->stat_value = stat_value : stat->stat_value += stat_value;
  1249. stat->stat_date = Timer::GetUnixTimeStamp();
  1250. stat->save_needed = true;
  1251. }
  1252. sint32 World::GetServerStatisticValue(int32 stat_id) {
  1253. if (server_statistics.count(stat_id) > 0)
  1254. return server_statistics[stat_id]->stat_value;
  1255. return 0;
  1256. }
  1257. void World::RemoveServerStatistics() {
  1258. map<int32, Statistic*>::iterator stat_itr;
  1259. for (stat_itr = server_statistics.begin(); stat_itr != server_statistics.end(); stat_itr++)
  1260. safe_delete(stat_itr->second);
  1261. server_statistics.clear();
  1262. }
  1263. void World::SendGroupQuests(PlayerGroup* group, Client* client){
  1264. return;
  1265. /*if(!group)
  1266. return;
  1267. GroupMemberInfo* info = 0;
  1268. MGroups.readlock(__FUNCTION__, __LINE__);
  1269. deque<GroupMemberInfo*>::iterator itr;
  1270. for(itr = group->members.begin(); itr != group->members.end(); itr++){
  1271. info = *itr;
  1272. if(info->client){
  1273. LogWrite(PLAYER__DEBUG, 0, "Player", "Send Quest Journal...");
  1274. info->client->SendQuestJournal(false, client);
  1275. client->SendQuestJournal(false, info->client);
  1276. }
  1277. }
  1278. MGroups.releasereadlock(__FUNCTION__, __LINE__);*/
  1279. }
  1280. /*void World::CheckRemoveGroupedPlayer(){
  1281. map<GroupMemberInfo*, int32>::iterator itr;
  1282. GroupMemberInfo* found = 0;
  1283. MGroups.readlock(__FUNCTION__, __LINE__);
  1284. for(itr = group_removal_pending.begin(); itr != group_removal_pending.end(); itr++){
  1285. if(itr->second < Timer::GetCurrentTime2()){
  1286. found = itr->first;
  1287. break;
  1288. }
  1289. }
  1290. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  1291. if(found){
  1292. if(!found->client || (found->client && found->client->IsConnected() == false))
  1293. DeleteGroupMember(found);
  1294. else{
  1295. MGroups.writelock(__FUNCTION__, __LINE__);
  1296. group_removal_pending.erase(found);
  1297. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  1298. }
  1299. }
  1300. }*/
  1301. void World::RejoinGroup(Client* client){
  1302. /*map<GroupMemberInfo*, int32>::iterator itr;
  1303. GroupMemberInfo* found = 0;
  1304. string name = string(client->GetPlayer()->GetName());
  1305. MGroups.readlock(__FUNCTION__, __LINE__);
  1306. PlayerGroup* group = 0;
  1307. for(int i = player_groups.size()-1;!found && i >= 0;i--){
  1308. group = player_groups[i];
  1309. for(int x=group->members.size()-1;x>=0; x--){
  1310. if(group->members[x]->name == name){
  1311. found = group->members[x];
  1312. break;
  1313. }
  1314. }
  1315. }
  1316. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  1317. if(found){
  1318. found->client = client;
  1319. client->GetPlayer()->SetGroup(found->group);
  1320. client->GetPlayer()->SetGroupMemberInfo(found);
  1321. }*/
  1322. }
  1323. void World::AddBonuses(ItemStatsValues* values, int16 type, sint32 value, Entity* entity){
  1324. if(values){
  1325. switch(type){
  1326. case ITEM_STAT_STR:{
  1327. values->str += value;
  1328. break;
  1329. }
  1330. case ITEM_STAT_STA:{
  1331. values->sta += value;
  1332. break;
  1333. }
  1334. case ITEM_STAT_AGI:{
  1335. values->agi += value;
  1336. break;
  1337. }
  1338. case ITEM_STAT_WIS:{
  1339. values->wis += value;
  1340. break;
  1341. }
  1342. case ITEM_STAT_INT:{
  1343. values->int_ += value;
  1344. break;
  1345. }
  1346. case ITEM_STAT_VS_SLASH:{
  1347. values->vs_slash += value;
  1348. break;
  1349. }
  1350. case ITEM_STAT_VS_CRUSH:{
  1351. values->vs_crush += value;
  1352. break;
  1353. }
  1354. case ITEM_STAT_VS_PIERCE:{
  1355. values->vs_pierce += value;
  1356. break;
  1357. }
  1358. case ITEM_STAT_VS_HEAT:{
  1359. values->vs_heat += value;
  1360. break;
  1361. }
  1362. case ITEM_STAT_VS_COLD:{
  1363. values->vs_cold += value;
  1364. break;
  1365. }
  1366. case ITEM_STAT_VS_MAGIC:{
  1367. values->vs_magic += value;
  1368. break;
  1369. }
  1370. case ITEM_STAT_VS_MENTAL:{
  1371. values->vs_mental += value;
  1372. break;
  1373. }
  1374. case ITEM_STAT_VS_DIVINE:{
  1375. values->vs_divine += value;
  1376. break;
  1377. }
  1378. case ITEM_STAT_VS_DISEASE:{
  1379. values->vs_disease += value;
  1380. break;
  1381. }
  1382. case ITEM_STAT_VS_POISON:{
  1383. values->vs_poison += value;
  1384. break;
  1385. }
  1386. case ITEM_STAT_HEALTH:{
  1387. values->health += value;
  1388. break;
  1389. }
  1390. case ITEM_STAT_POWER:{
  1391. values->power += value;
  1392. break;
  1393. }
  1394. case ITEM_STAT_CONCENTRATION:{
  1395. values->concentration += value;
  1396. break;
  1397. }
  1398. case ITEM_STAT_ABILITY_MODIFIER:{
  1399. values->ability_modifier += value;
  1400. break;
  1401. }
  1402. case ITEM_STAT_CRITICALMITIGATION:{
  1403. values->criticalmitigation += value;
  1404. break;
  1405. }
  1406. case ITEM_STAT_EXTRASHIELDBLOCKCHANCE:{
  1407. values->extrashieldblockchance += value;
  1408. break;
  1409. }
  1410. case ITEM_STAT_BENEFICIALCRITCHANCE:{
  1411. values->beneficialcritchance += value;
  1412. break;
  1413. }
  1414. case ITEM_STAT_CRITBONUS:{
  1415. values->critbonus += value;
  1416. break;
  1417. }
  1418. /*case ITEM_STAT_POTENCY:{
  1419. values->potency += value;
  1420. break;
  1421. }*/
  1422. case ITEM_STAT_HATEGAINMOD:{
  1423. values->hategainmod += value;
  1424. break;
  1425. }
  1426. case ITEM_STAT_ABILITYREUSESPEED:{
  1427. values->abilityreusespeed += value;
  1428. break;
  1429. }
  1430. case ITEM_STAT_ABILITYCASTINGSPEED:{
  1431. values->abilitycastingspeed += value;
  1432. break;
  1433. }
  1434. case ITEM_STAT_ABILITYRECOVERYSPEED:{
  1435. values->abilityrecoveryspeed += value;
  1436. break;
  1437. }
  1438. case ITEM_STAT_SPELLREUSESPEED:{
  1439. values->spellreusespeed += value;
  1440. break;
  1441. }
  1442. case ITEM_STAT_SPELLMULTIATTACKCHANCE:{
  1443. values->spellmultiattackchance += value;
  1444. break;
  1445. }
  1446. case ITEM_STAT_DPS:{
  1447. values->dps += value;
  1448. break;
  1449. }
  1450. case ITEM_STAT_ATTACKSPEED:{
  1451. values->attackspeed += value;
  1452. break;
  1453. }
  1454. case ITEM_STAT_MULTIATTACKCHANCE:{
  1455. values->multiattackchance += value;
  1456. break;
  1457. }
  1458. case ITEM_STAT_AEAUTOATTACKCHANCE:{
  1459. values->aeautoattackchance += value;
  1460. break;
  1461. }
  1462. case ITEM_STAT_STRIKETHROUGH:{
  1463. values->strikethrough += value;
  1464. break;
  1465. }
  1466. case ITEM_STAT_ACCURACY:{
  1467. values->accuracy += value;
  1468. break;
  1469. }
  1470. /*case ITEM_STAT_OFFENSIVESPEED:{
  1471. values->offensivespeed += value;
  1472. break;
  1473. }*/
  1474. default: {
  1475. if (entity)
  1476. entity->stats[type] += value;
  1477. break;
  1478. }
  1479. }
  1480. }
  1481. }
  1482. void World::CreateGuild(const char* guild_name, Client* leader, int32 group_id) {
  1483. deque<GroupMemberInfo*>::iterator itr;
  1484. GroupMemberInfo* gmi;
  1485. Guild *guild;
  1486. assert(guild_name);
  1487. guild = new Guild();
  1488. guild->SetName(guild_name);
  1489. guild->SetFormedDate(Timer::GetUnixTimeStamp());
  1490. database.LoadGuildDefaultRanks(guild);
  1491. database.LoadGuildDefaultEventFilters(guild);
  1492. database.SaveGuild(guild, true);
  1493. database.SaveGuildEvents(guild);
  1494. database.SaveGuildRanks(guild);
  1495. database.SaveGuildEventFilters(guild);
  1496. database.SaveGuildRecruiting(guild);
  1497. guild_list.AddGuild(guild);
  1498. if (leader && !leader->GetPlayer()->GetGuild())
  1499. guild->AddNewGuildMember(leader, 0, GUILD_RANK_LEADER);
  1500. database.SaveGuildMembers(guild);
  1501. if (leader && group_id > 0) {
  1502. GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1503. deque<GroupMemberInfo*>* members = GetGroupManager()->GetGroupMembers(group_id);
  1504. for (itr = members->begin(); itr != members->end(); itr++) {
  1505. gmi = *itr;
  1506. if (gmi->client && gmi->client != leader && !gmi->client->GetPlayer()->GetGuild())
  1507. guild->InvitePlayer(gmi->client, leader->GetPlayer()->GetName());
  1508. }
  1509. GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1510. }
  1511. }
  1512. void World::SaveGuilds() {
  1513. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  1514. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  1515. while (itr.Next()) {
  1516. Guild* guild = itr.second;
  1517. if (guild->GetSaveNeeded())
  1518. database.SaveGuild(guild);
  1519. if (guild->GetMemberSaveNeeded())
  1520. database.SaveGuildMembers(guild);
  1521. if (guild->GetEventsSaveNeeded())
  1522. database.SaveGuildEvents(guild);
  1523. if (guild->GetRanksSaveNeeded())
  1524. database.SaveGuildRanks(guild);
  1525. if (guild->GetEventFiltersSaveNeeded())
  1526. database.SaveGuildEventFilters(guild);
  1527. if (guild->GetPointsHistorySaveNeeded())
  1528. database.SaveGuildPointsHistory(guild);
  1529. if (guild->GetRecruitingSaveNeeded())
  1530. database.SaveGuildRecruiting(guild);
  1531. }
  1532. }
  1533. void World::PickRandomLottoDigits(int32* digits) {
  1534. if (digits) {
  1535. for (int32 i = 0; i < 6; i++) {
  1536. bool found = true;
  1537. int32 num = 0;
  1538. while (found) {
  1539. num = ((int32)rand() % 36) + 1;
  1540. for (int32 j = 0; j < 6; j++) {
  1541. if (digits[j] == num)
  1542. break;
  1543. if (j == 5)
  1544. found = false;
  1545. }
  1546. }
  1547. digits[i] = num;
  1548. }
  1549. }
  1550. }
  1551. void World::AddLottoPlayer(int32 character_id, int32 end_time) {
  1552. LottoPlayer* lp;
  1553. if (lotto_players.count(character_id) == 0) {
  1554. lp = new LottoPlayer;
  1555. lotto_players.Put(character_id, lp);
  1556. }
  1557. else
  1558. lp = lotto_players.Get(character_id);
  1559. lp->end_time = end_time;
  1560. lp->num_matches = 0;
  1561. lp->set = false;
  1562. }
  1563. void World::RemoveLottoPlayer(int32 character_id) {
  1564. if (lotto_players.count(character_id) > 0)
  1565. lotto_players.erase(character_id, false, true);
  1566. }
  1567. void World::SetLottoPlayerNumMatches(int32 character_id, int8 num_matches) {
  1568. if (lotto_players.count(character_id) > 0) {
  1569. lotto_players.Get(character_id)->num_matches = num_matches;
  1570. lotto_players.Get(character_id)->set = true;
  1571. }
  1572. }
  1573. void World::CheckLottoPlayers() {
  1574. MutexMap<int32, LottoPlayer*>::iterator itr = lotto_players.begin();
  1575. while (itr.Next()) {
  1576. LottoPlayer* lp = itr->second;
  1577. if (Timer::GetCurrentTime2() >= lp->end_time && lp->set) {
  1578. int8 num_matches = lp->num_matches;
  1579. LogWrite(PLAYER__DEBUG, 0, "Player", "Num matches: %u", lp->num_matches);
  1580. Client* client = zone_list.GetClientByCharID(itr->first);
  1581. if (client && num_matches >= 2) {
  1582. if (num_matches == 2) {
  1583. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 10 silver.");
  1584. client->SendPopupMessage(0, "Congratulations! You have won 10 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1585. client->GetPlayer()->AddCoins(1000);
  1586. client->GetPlayer()->GetZone()->SendCastSpellPacket(869, client->GetPlayer());
  1587. }
  1588. else if (num_matches == 3) {
  1589. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 50 silver.");
  1590. client->SendPopupMessage(0, "Congratulations! You have won 50 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1591. client->GetPlayer()->AddCoins(5000);
  1592. client->GetPlayer()->GetZone()->SendCastSpellPacket(870, client->GetPlayer());
  1593. }
  1594. else if (num_matches == 4) {
  1595. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 2 gold 50 silver.");
  1596. client->SendPopupMessage(0, "Congratulations! You have won 2 gold 50 silver!", "", 2, 0xFF, 0xFF, 0x99);
  1597. client->GetPlayer()->AddCoins(25000);
  1598. client->GetPlayer()->GetZone()->SendCastSpellPacket(871, client->GetPlayer());
  1599. }
  1600. else if (num_matches == 5) {
  1601. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You receive 25 gold.");
  1602. client->SendPopupMessage(0, "Congratulations! You have won 25 gold!", "", 2, 0xFF, 0xFF, 0x99);
  1603. client->GetPlayer()->AddCoins(250000);
  1604. client->GetPlayer()->GetZone()->SendCastSpellPacket(872, client->GetPlayer());
  1605. }
  1606. else if (num_matches == 6) {
  1607. Variable* var = variables.FindVariable("gambling_current_jackpot");
  1608. if (var) {
  1609. int64 jackpot = 0;
  1610. try {
  1611. jackpot = atoul(var->GetValue());
  1612. }
  1613. catch (...) {
  1614. jackpot = 10000;
  1615. }
  1616. char coin_message[128];
  1617. char message[512];
  1618. char announcement[512];
  1619. memset(coin_message, 0, sizeof(coin_message));
  1620. memset(message, 0, sizeof(message));
  1621. memset(announcement, 0, sizeof(announcement));
  1622. sprintf(coin_message, "%s", client->GetCoinMessage(jackpot).c_str());
  1623. sprintf(message, "Congratulations! You have won %s!", coin_message);
  1624. sprintf(announcement, "%s as won the jackpot containing a total of %s!", client->GetPlayer()->GetName(), coin_message);
  1625. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", coin_message);
  1626. client->SendPopupMessage(0, message, "", 2, 0xFF, 0xFF, 0x99);
  1627. zone_list.HandleGlobalAnnouncement(announcement);
  1628. client->GetPlayer()->AddCoins(jackpot);
  1629. client->GetPlayer()->GetZone()->SendCastSpellPacket(843, client->GetPlayer());
  1630. client->GetPlayer()->GetZone()->SendCastSpellPacket(1413, client->GetPlayer());
  1631. }
  1632. }
  1633. }
  1634. RemoveLottoPlayer(itr->first);
  1635. }
  1636. }
  1637. }
  1638. 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) {
  1639. MHouseZones.writelock(__FUNCTION__, __LINE__);
  1640. if (m_houseZones.count(id) == 0) {
  1641. HouseZone* hz = new HouseZone;
  1642. //ZeroMemory(hz, sizeof(HouseZone));
  1643. hz->id = id;
  1644. hz->name = name;
  1645. hz->cost_coin = cost_coins;
  1646. hz->cost_status = cost_status;
  1647. hz->upkeep_coin = upkeep_coins;
  1648. hz->upkeep_status = upkeep_status;
  1649. hz->vault_slots = vault_slots;
  1650. hz->alignment = alignment;
  1651. hz->guild_level = guild_level;
  1652. hz->zone_id = zone_id;
  1653. hz->exit_zone_id = exit_zone_id;
  1654. hz->exit_x = exit_x;
  1655. hz->exit_y = exit_y;
  1656. hz->exit_z = exit_z;
  1657. hz->exit_heading = exit_heading;
  1658. m_houseZones[id] = hz;
  1659. }
  1660. else {
  1661. LogWrite(WORLD__ERROR, 0, "Housing", "Duplicate house id (%u) for %s", id, name.c_str());
  1662. }
  1663. MHouseZones.releasewritelock(__FUNCTION__, __LINE__);
  1664. }
  1665. HouseZone* World::GetHouseZone(int32 id) {
  1666. HouseZone* ret = 0;
  1667. MHouseZones.readlock(__FUNCTION__, __LINE__);
  1668. if (m_houseZones.count(id) > 0)
  1669. ret = m_houseZones[id];
  1670. MHouseZones.releasereadlock(__FUNCTION__, __LINE__);
  1671. return ret;
  1672. }
  1673. 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) {
  1674. MPlayerHouses.writelock(__FUNCTION__, __LINE__);
  1675. if (m_playerHouses.count(house_id) == 0 || m_playerHouses[house_id].count(char_id) == 0) {
  1676. PlayerHouse* ph = new PlayerHouse;
  1677. ph->house_id = house_id;
  1678. ph->unique_id = unique_id;
  1679. ph->instance_id = instance_id;
  1680. ph->escrow_coins = escrow_coins;
  1681. ph->escrow_status = escrow_status;
  1682. ph->upkeep_due = upkeep_due;
  1683. ph->player_name = player_name;
  1684. m_playerHouses[house_id][char_id] = ph;
  1685. }
  1686. MPlayerHouses.releasewritelock(__FUNCTION__, __LINE__);
  1687. }
  1688. PlayerHouse* World::GetPlayerHouseByHouseID(int32 char_id, int32 house_id) {
  1689. PlayerHouse* ret = 0;
  1690. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1691. if (m_playerHouses.count(house_id) > 0 && m_playerHouses[house_id].count(char_id) > 0)
  1692. ret = m_playerHouses[house_id][char_id];
  1693. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1694. return ret;
  1695. }
  1696. PlayerHouse* World::GetPlayerHouseByUniqueID(int64 unique_id) {
  1697. PlayerHouse* ret = 0;
  1698. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1699. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1700. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1701. map<int32, PlayerHouse*>::iterator itr2;
  1702. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  1703. if (itr2->second->unique_id == unique_id) {
  1704. ret = itr2->second;
  1705. break;
  1706. }
  1707. }
  1708. if (ret)
  1709. break;
  1710. }
  1711. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1712. return ret;
  1713. }
  1714. PlayerHouse* World::GetPlayerHouseByInstanceID(int32 instance_id) {
  1715. PlayerHouse* ret = 0;
  1716. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1717. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1718. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1719. map<int32, PlayerHouse*>::iterator itr2;
  1720. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  1721. if (itr2->second->instance_id == instance_id) {
  1722. ret = itr2->second;
  1723. break;
  1724. }
  1725. }
  1726. if (ret)
  1727. break;
  1728. }
  1729. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1730. return ret;
  1731. }
  1732. vector<PlayerHouse*> World::GetAllPlayerHouses(int32 char_id) {
  1733. vector<PlayerHouse*> ret;
  1734. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1735. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1736. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1737. if (itr->second.count(char_id) > 0)
  1738. ret.push_back(itr->second[char_id]);
  1739. }
  1740. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1741. return ret;
  1742. }
  1743. vector<PlayerHouse*> World::GetAllPlayerHousesByHouseID(int32 house_id) {
  1744. vector<PlayerHouse*> ret;
  1745. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1746. if (m_houseZones.count(house_id) > 0) {
  1747. map<int32, PlayerHouse*>::iterator itr;
  1748. for (itr = m_playerHouses[house_id].begin(); itr != m_playerHouses[house_id].end(); itr++)
  1749. ret.push_back(itr->second);
  1750. }
  1751. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1752. return ret;
  1753. }
  1754. void World::PopulateTOVStatMap() {
  1755. //This function populates a map that converts changed CoE to ToV stats
  1756. tov_itemstat_conversion[0] = TOV_ITEM_STAT_HPREGEN;
  1757. tov_itemstat_conversion[1] = TOV_ITEM_STAT_MANAREGEN;
  1758. tov_itemstat_conversion[2] = TOV_ITEM_STAT_HPREGENPPT;
  1759. tov_itemstat_conversion[3] = TOV_ITEM_STAT_MPREGENPPT;
  1760. tov_itemstat_conversion[4] = TOV_ITEM_STAT_COMBATHPREGENPPT;
  1761. tov_itemstat_conversion[5] = TOV_ITEM_STAT_COMBATMPREGENPPT;
  1762. tov_itemstat_conversion[6] = TOV_ITEM_STAT_MAXHP;
  1763. tov_itemstat_conversion[7] = TOV_ITEM_STAT_MAXHPPERC;
  1764. tov_itemstat_conversion[8] = TOV_ITEM_STAT_MAXHPPERCFINAL;
  1765. tov_itemstat_conversion[9] = TOV_ITEM_STAT_SPEED;
  1766. tov_itemstat_conversion[10] = TOV_ITEM_STAT_SLOW;
  1767. tov_itemstat_conversion[11] = TOV_ITEM_STAT_MOUNTSPEED;
  1768. tov_itemstat_conversion[12] = TOV_ITEM_STAT_MOUNTAIRSPEED;
  1769. tov_itemstat_conversion[13] = TOV_ITEM_STAT_LEAPSPEED;
  1770. tov_itemstat_conversion[14] = TOV_ITEM_STAT_LEAPTIME;
  1771. tov_itemstat_conversion[15] = TOV_ITEM_STAT_GLIDEEFFICIENCY;
  1772. tov_itemstat_conversion[16] = TOV_ITEM_STAT_OFFENSIVESPEED;
  1773. tov_itemstat_conversion[17] = TOV_ITEM_STAT_ATTACKSPEED;
  1774. tov_itemstat_conversion[18] = 698;
  1775. tov_itemstat_conversion[19] = TOV_ITEM_STAT_MAXMANA;
  1776. tov_itemstat_conversion[20] = TOV_ITEM_STAT_MAXMANAPERC;
  1777. tov_itemstat_conversion[21] = TOV_ITEM_STAT_MAXATTPERC;
  1778. tov_itemstat_conversion[22] = TOV_ITEM_STAT_BLURVISION;
  1779. tov_itemstat_conversion[23] = TOV_ITEM_STAT_MAGICLEVELIMMUNITY;
  1780. tov_itemstat_conversion[24] = TOV_ITEM_STAT_HATEGAINMOD;
  1781. tov_itemstat_conversion[25] = TOV_ITEM_STAT_COMBATEXPMOD;
  1782. tov_itemstat_conversion[26] = TOV_ITEM_STAT_TRADESKILLEXPMOD;
  1783. tov_itemstat_conversion[27] = TOV_ITEM_STAT_ACHIEVEMENTEXPMOD ;
  1784. tov_itemstat_conversion[28] = TOV_ITEM_STAT_SIZEMOD;
  1785. tov_itemstat_conversion[29] = TOV_ITEM_STAT_DPS;
  1786. tov_itemstat_conversion[30] = 698;
  1787. tov_itemstat_conversion[31] = TOV_ITEM_STAT_STEALTH;
  1788. tov_itemstat_conversion[32] = TOV_ITEM_STAT_INVIS;
  1789. tov_itemstat_conversion[33] = TOV_ITEM_STAT_SEESTEALTH;
  1790. tov_itemstat_conversion[34] = TOV_ITEM_STAT_SEEINVIS;
  1791. tov_itemstat_conversion[35] = TOV_ITEM_STAT_EFFECTIVELEVELMOD;
  1792. tov_itemstat_conversion[36] = TOV_ITEM_STAT_RIPOSTECHANCE;
  1793. tov_itemstat_conversion[37] = TOV_ITEM_STAT_PARRYCHANCE;
  1794. tov_itemstat_conversion[38] = TOV_ITEM_STAT_DODGECHANCE;
  1795. tov_itemstat_conversion[39] = TOV_ITEM_STAT_AEAUTOATTACKCHANCE;
  1796. tov_itemstat_conversion[40] = 698;
  1797. tov_itemstat_conversion[41] = TOV_ITEM_STAT_MULTIATTACKCHANCE;
  1798. tov_itemstat_conversion[42] = 698;
  1799. tov_itemstat_conversion[43] = 698;
  1800. tov_itemstat_conversion[44] = 698;
  1801. tov_itemstat_conversion[45] = TOV_ITEM_STAT_SPELLMULTIATTACKCHANCE;
  1802. tov_itemstat_conversion[46] = 698;
  1803. tov_itemstat_conversion[47] = TOV_ITEM_STAT_FLURRY;
  1804. tov_itemstat_conversion[48] = 698;
  1805. tov_itemstat_conversion[49] = TOV_ITEM_STAT_MELEEDAMAGEMULTIPLIER;
  1806. tov_itemstat_conversion[50] = TOV_ITEM_STAT_EXTRAHARVESTCHANCE;
  1807. tov_itemstat_conversion[51] = TOV_ITEM_STAT_EXTRASHIELDBLOCKCHANCE;
  1808. tov_itemstat_conversion[52] = TOV_ITEM_STAT_ITEMHPREGENPPT;
  1809. tov_itemstat_conversion[53] = TOV_ITEM_STAT_ITEMPPREGENPPT;
  1810. tov_itemstat_conversion[54] = TOV_ITEM_STAT_MELEECRITCHANCE;
  1811. tov_itemstat_conversion[55] = TOV_ITEM_STAT_CRITAVOIDANCE;
  1812. tov_itemstat_conversion[56] = TOV_ITEM_STAT_BENEFICIALCRITCHANCE;
  1813. tov_itemstat_conversion[57] = TOV_ITEM_STAT_CRITBONUS;
  1814. tov_itemstat_conversion[58] = 698;
  1815. tov_itemstat_conversion[59] = TOV_ITEM_STAT_POTENCY;
  1816. tov_itemstat_conversion[60] = 698;
  1817. tov_itemstat_conversion[61] = TOV_ITEM_STAT_UNCONSCIOUSHPMOD;
  1818. tov_itemstat_conversion[62] = TOV_ITEM_STAT_ABILITYREUSESPEED;
  1819. tov_itemstat_conversion[63] = TOV_ITEM_STAT_ABILITYRECOVERYSPEED;
  1820. tov_itemstat_conversion[64] = TOV_ITEM_STAT_ABILITYCASTINGSPEED;
  1821. tov_itemstat_conversion[65] = TOV_ITEM_STAT_SPELLREUSESPEED;
  1822. tov_itemstat_conversion[66] = TOV_ITEM_STAT_MELEEWEAPONRANGE;
  1823. tov_itemstat_conversion[67] = TOV_ITEM_STAT_RANGEDWEAPONRANGE;
  1824. tov_itemstat_conversion[68] = TOV_ITEM_STAT_FALLINGDAMAGEREDUCTION;
  1825. tov_itemstat_conversion[69] = TOV_ITEM_STAT_RIPOSTEDAMAGE;
  1826. tov_itemstat_conversion[70] = TOV_ITEM_STAT_MINIMUMDEFLECTIONCHANCE;
  1827. tov_itemstat_conversion[71] = TOV_ITEM_STAT_MOVEMENTWEAVE;
  1828. tov_itemstat_conversion[72] = TOV_ITEM_STAT_COMBATHPREGEN;
  1829. tov_itemstat_conversion[73] = TOV_ITEM_STAT_COMBATMANAREGEN;
  1830. tov_itemstat_conversion[74] = TOV_ITEM_STAT_CONTESTSPEEDBOOST;
  1831. tov_itemstat_conversion[75] = TOV_ITEM_STAT_TRACKINGAVOIDANCE;
  1832. tov_itemstat_conversion[76] = TOV_ITEM_STAT_STEALTHINVISSPEEDMOD;
  1833. tov_itemstat_conversion[77] = TOV_ITEM_STAT_LOOT_COIN;
  1834. tov_itemstat_conversion[78] = TOV_ITEM_STAT_ARMORMITIGATIONINCREASE;
  1835. tov_itemstat_conversion[79] = TOV_ITEM_STAT_AMMOCONSERVATION;
  1836. tov_itemstat_conversion[80] = TOV_ITEM_STAT_STRIKETHROUGH;
  1837. tov_itemstat_conversion[81] = TOV_ITEM_STAT_STATUSBONUS;
  1838. tov_itemstat_conversion[82] = TOV_ITEM_STAT_ACCURACY;
  1839. tov_itemstat_conversion[83] = TOV_ITEM_STAT_COUNTERSTRIKE;
  1840. tov_itemstat_conversion[84] = TOV_ITEM_STAT_SHIELDBASH;
  1841. tov_itemstat_conversion[85] = TOV_ITEM_STAT_WEAPONDAMAGEBONUS;
  1842. tov_itemstat_conversion[86] = 698;
  1843. tov_itemstat_conversion[87] = TOV_ITEM_STAT_WEAPONDAMAGEBONUSMELEEONLY;
  1844. tov_itemstat_conversion[88] = TOV_ITEM_STAT_ADDITIONALRIPOSTECHANCE;
  1845. tov_itemstat_conversion[89] = TOV_ITEM_STAT_PVPTOUGHNESS;
  1846. tov_itemstat_conversion[90] = TOV_ITEM_STAT_PVPLETHALITY;
  1847. tov_itemstat_conversion[91] = TOV_ITEM_STAT_STAMINABONUS;
  1848. tov_itemstat_conversion[92] = TOV_ITEM_STAT_WISDOMMITBONUS;
  1849. tov_itemstat_conversion[93] = TOV_ITEM_STAT_HEALRECEIVE;
  1850. tov_itemstat_conversion[94] = TOV_ITEM_STAT_HEALRECEIVEPERC;
  1851. tov_itemstat_conversion[95] = TOV_ITEM_STAT_PVPCRITICALMITIGATION;
  1852. tov_itemstat_conversion[96] = TOV_ITEM_STAT_BASEAVOIDANCEBONUS;
  1853. tov_itemstat_conversion[97] = TOV_ITEM_STAT_INCOMBATSAVAGERYREGEN;
  1854. tov_itemstat_conversion[98] = TOV_ITEM_STAT_OUTOFCOMBATSAVAGERYREGEN;
  1855. tov_itemstat_conversion[99] = TOV_ITEM_STAT_SAVAGERYREGEN;
  1856. tov_itemstat_conversion[100] = TOV_ITEM_STAT_SAVAGERYGAINMOD;
  1857. tov_itemstat_conversion[101] = TOV_ITEM_STAT_MAXSAVAGERYLEVEL;
  1858. }
  1859. int32 World::LoadItemBlueStats() {
  1860. Query query;
  1861. MYSQL_ROW row;
  1862. int32 count = 0;
  1863. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT version_range1,version_range2,emu_stat,name,stat from itemstats");
  1864. if (result && mysql_num_rows(result) > 0) {
  1865. while (result && (row = mysql_fetch_row(result))) {
  1866. count++;
  1867. if (atoi(row[0]) >= 63119) //KA
  1868. ka_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1869. else if (atoi(row[0]) >= 57101) // ToV
  1870. tov_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1871. else if (atoi(row[0]) >= 1193) // CoE
  1872. coe_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1873. else if (atoi(row[0]) >= 1096) // DoV
  1874. dov_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1875. }
  1876. }
  1877. return count;
  1878. }
  1879. sint16 World::GetItemStatTOVValue(sint16 subtype) {
  1880. return (tov_itemstat_conversion[subtype] - 600);
  1881. }
  1882. sint16 World::GetItemStatDOVValue(sint16 subtype) {
  1883. return (dov_itemstat_conversion[subtype] - 600);
  1884. }
  1885. sint16 World::GetItemStatCOEValue(sint16 subtype) {
  1886. return (coe_itemstat_conversion[subtype] - 600);
  1887. }
  1888. sint16 World::GetItemStatKAValue(sint16 subtype) {
  1889. return (ka_itemstat_conversion[subtype] - 600);
  1890. }
  1891. #ifdef WIN32
  1892. ulong World::GetCurrentThreadID(){
  1893. return GetCurrentThreadId();
  1894. }
  1895. int64 World::GetThreadUsageCPUTime(){
  1896. HANDLE handle = GetCurrentThread();
  1897. int64 lpCreationTime;
  1898. int64 lpExitTime;
  1899. int64 lpKernelTime;
  1900. int64 lpUserTime;
  1901. if(GetThreadTimes(handle, (FILETIME*)&lpCreationTime, (FILETIME*)&lpExitTime, (FILETIME*)&lpKernelTime, (FILETIME*)&lpUserTime))
  1902. return lpKernelTime + lpUserTime;
  1903. return 0;
  1904. }
  1905. #else
  1906. #endif