9
3

World.cpp 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131
  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. ReloadHouseData(ph);
  1697. m_playerHouses[house_id][char_id] = ph;
  1698. }
  1699. MPlayerHouses.releasewritelock(__FUNCTION__, __LINE__);
  1700. }
  1701. void World::ReloadHouseData(PlayerHouse* ph)
  1702. {
  1703. database.LoadDeposits(ph);
  1704. database.LoadHistory(ph);
  1705. }
  1706. PlayerHouse* World::GetPlayerHouseByHouseID(int32 char_id, int32 house_id) {
  1707. PlayerHouse* ret = 0;
  1708. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1709. if (m_playerHouses.count(house_id) > 0 && m_playerHouses[house_id].count(char_id) > 0)
  1710. ret = m_playerHouses[house_id][char_id];
  1711. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1712. return ret;
  1713. }
  1714. PlayerHouse* World::GetPlayerHouseByUniqueID(int64 unique_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->unique_id == unique_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. PlayerHouse* World::GetPlayerHouseByInstanceID(int32 instance_id) {
  1733. PlayerHouse* ret = 0;
  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. map<int32, PlayerHouse*>::iterator itr2;
  1738. for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
  1739. if (itr2->second->instance_id == instance_id) {
  1740. ret = itr2->second;
  1741. break;
  1742. }
  1743. }
  1744. if (ret)
  1745. break;
  1746. }
  1747. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1748. return ret;
  1749. }
  1750. vector<PlayerHouse*> World::GetAllPlayerHouses(int32 char_id) {
  1751. vector<PlayerHouse*> ret;
  1752. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1753. map<int32, map<int32, PlayerHouse*> >::iterator itr;
  1754. for (itr = m_playerHouses.begin(); itr != m_playerHouses.end(); itr++) {
  1755. if (itr->second.count(char_id) > 0)
  1756. ret.push_back(itr->second[char_id]);
  1757. }
  1758. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1759. return ret;
  1760. }
  1761. vector<PlayerHouse*> World::GetAllPlayerHousesByHouseID(int32 house_id) {
  1762. vector<PlayerHouse*> ret;
  1763. MPlayerHouses.readlock(__FUNCTION__, __LINE__);
  1764. if (m_houseZones.count(house_id) > 0) {
  1765. map<int32, PlayerHouse*>::iterator itr;
  1766. for (itr = m_playerHouses[house_id].begin(); itr != m_playerHouses[house_id].end(); itr++)
  1767. ret.push_back(itr->second);
  1768. }
  1769. MPlayerHouses.releasereadlock(__FUNCTION__, __LINE__);
  1770. return ret;
  1771. }
  1772. void World::PopulateTOVStatMap() {
  1773. //This function populates a map that converts changed CoE to ToV stats
  1774. tov_itemstat_conversion[0] = TOV_ITEM_STAT_HPREGEN;
  1775. tov_itemstat_conversion[1] = TOV_ITEM_STAT_MANAREGEN;
  1776. tov_itemstat_conversion[2] = TOV_ITEM_STAT_HPREGENPPT;
  1777. tov_itemstat_conversion[3] = TOV_ITEM_STAT_MPREGENPPT;
  1778. tov_itemstat_conversion[4] = TOV_ITEM_STAT_COMBATHPREGENPPT;
  1779. tov_itemstat_conversion[5] = TOV_ITEM_STAT_COMBATMPREGENPPT;
  1780. tov_itemstat_conversion[6] = TOV_ITEM_STAT_MAXHP;
  1781. tov_itemstat_conversion[7] = TOV_ITEM_STAT_MAXHPPERC;
  1782. tov_itemstat_conversion[8] = TOV_ITEM_STAT_MAXHPPERCFINAL;
  1783. tov_itemstat_conversion[9] = TOV_ITEM_STAT_SPEED;
  1784. tov_itemstat_conversion[10] = TOV_ITEM_STAT_SLOW;
  1785. tov_itemstat_conversion[11] = TOV_ITEM_STAT_MOUNTSPEED;
  1786. tov_itemstat_conversion[12] = TOV_ITEM_STAT_MOUNTAIRSPEED;
  1787. tov_itemstat_conversion[13] = TOV_ITEM_STAT_LEAPSPEED;
  1788. tov_itemstat_conversion[14] = TOV_ITEM_STAT_LEAPTIME;
  1789. tov_itemstat_conversion[15] = TOV_ITEM_STAT_GLIDEEFFICIENCY;
  1790. tov_itemstat_conversion[16] = TOV_ITEM_STAT_OFFENSIVESPEED;
  1791. tov_itemstat_conversion[17] = TOV_ITEM_STAT_ATTACKSPEED;
  1792. tov_itemstat_conversion[18] = 698;
  1793. tov_itemstat_conversion[19] = TOV_ITEM_STAT_MAXMANA;
  1794. tov_itemstat_conversion[20] = TOV_ITEM_STAT_MAXMANAPERC;
  1795. tov_itemstat_conversion[21] = TOV_ITEM_STAT_MAXATTPERC;
  1796. tov_itemstat_conversion[22] = TOV_ITEM_STAT_BLURVISION;
  1797. tov_itemstat_conversion[23] = TOV_ITEM_STAT_MAGICLEVELIMMUNITY;
  1798. tov_itemstat_conversion[24] = TOV_ITEM_STAT_HATEGAINMOD;
  1799. tov_itemstat_conversion[25] = TOV_ITEM_STAT_COMBATEXPMOD;
  1800. tov_itemstat_conversion[26] = TOV_ITEM_STAT_TRADESKILLEXPMOD;
  1801. tov_itemstat_conversion[27] = TOV_ITEM_STAT_ACHIEVEMENTEXPMOD;
  1802. tov_itemstat_conversion[28] = TOV_ITEM_STAT_SIZEMOD;
  1803. tov_itemstat_conversion[29] = TOV_ITEM_STAT_DPS;
  1804. tov_itemstat_conversion[30] = 698;
  1805. tov_itemstat_conversion[31] = TOV_ITEM_STAT_STEALTH;
  1806. tov_itemstat_conversion[32] = TOV_ITEM_STAT_INVIS;
  1807. tov_itemstat_conversion[33] = TOV_ITEM_STAT_SEESTEALTH;
  1808. tov_itemstat_conversion[34] = TOV_ITEM_STAT_SEEINVIS;
  1809. tov_itemstat_conversion[35] = TOV_ITEM_STAT_EFFECTIVELEVELMOD;
  1810. tov_itemstat_conversion[36] = TOV_ITEM_STAT_RIPOSTECHANCE;
  1811. tov_itemstat_conversion[37] = TOV_ITEM_STAT_PARRYCHANCE;
  1812. tov_itemstat_conversion[38] = TOV_ITEM_STAT_DODGECHANCE;
  1813. tov_itemstat_conversion[39] = TOV_ITEM_STAT_AEAUTOATTACKCHANCE;
  1814. tov_itemstat_conversion[40] = 698;
  1815. tov_itemstat_conversion[41] = TOV_ITEM_STAT_MULTIATTACKCHANCE;
  1816. tov_itemstat_conversion[42] = 698;
  1817. tov_itemstat_conversion[43] = 698;
  1818. tov_itemstat_conversion[44] = 698;
  1819. tov_itemstat_conversion[45] = TOV_ITEM_STAT_SPELLMULTIATTACKCHANCE;
  1820. tov_itemstat_conversion[46] = 698;
  1821. tov_itemstat_conversion[47] = TOV_ITEM_STAT_FLURRY;
  1822. tov_itemstat_conversion[48] = 698;
  1823. tov_itemstat_conversion[49] = TOV_ITEM_STAT_MELEEDAMAGEMULTIPLIER;
  1824. tov_itemstat_conversion[50] = TOV_ITEM_STAT_EXTRAHARVESTCHANCE;
  1825. tov_itemstat_conversion[51] = TOV_ITEM_STAT_EXTRASHIELDBLOCKCHANCE;
  1826. tov_itemstat_conversion[52] = TOV_ITEM_STAT_ITEMHPREGENPPT;
  1827. tov_itemstat_conversion[53] = TOV_ITEM_STAT_ITEMPPREGENPPT;
  1828. tov_itemstat_conversion[54] = TOV_ITEM_STAT_MELEECRITCHANCE;
  1829. tov_itemstat_conversion[55] = TOV_ITEM_STAT_CRITAVOIDANCE;
  1830. tov_itemstat_conversion[56] = TOV_ITEM_STAT_BENEFICIALCRITCHANCE;
  1831. tov_itemstat_conversion[57] = TOV_ITEM_STAT_CRITBONUS;
  1832. tov_itemstat_conversion[58] = 698;
  1833. tov_itemstat_conversion[59] = TOV_ITEM_STAT_POTENCY;
  1834. tov_itemstat_conversion[60] = 698;
  1835. tov_itemstat_conversion[61] = TOV_ITEM_STAT_UNCONSCIOUSHPMOD;
  1836. tov_itemstat_conversion[62] = TOV_ITEM_STAT_ABILITYREUSESPEED;
  1837. tov_itemstat_conversion[63] = TOV_ITEM_STAT_ABILITYRECOVERYSPEED;
  1838. tov_itemstat_conversion[64] = TOV_ITEM_STAT_ABILITYCASTINGSPEED;
  1839. tov_itemstat_conversion[65] = TOV_ITEM_STAT_SPELLREUSESPEED;
  1840. tov_itemstat_conversion[66] = TOV_ITEM_STAT_MELEEWEAPONRANGE;
  1841. tov_itemstat_conversion[67] = TOV_ITEM_STAT_RANGEDWEAPONRANGE;
  1842. tov_itemstat_conversion[68] = TOV_ITEM_STAT_FALLINGDAMAGEREDUCTION;
  1843. tov_itemstat_conversion[69] = TOV_ITEM_STAT_RIPOSTEDAMAGE;
  1844. tov_itemstat_conversion[70] = TOV_ITEM_STAT_MINIMUMDEFLECTIONCHANCE;
  1845. tov_itemstat_conversion[71] = TOV_ITEM_STAT_MOVEMENTWEAVE;
  1846. tov_itemstat_conversion[72] = TOV_ITEM_STAT_COMBATHPREGEN;
  1847. tov_itemstat_conversion[73] = TOV_ITEM_STAT_COMBATMANAREGEN;
  1848. tov_itemstat_conversion[74] = TOV_ITEM_STAT_CONTESTSPEEDBOOST;
  1849. tov_itemstat_conversion[75] = TOV_ITEM_STAT_TRACKINGAVOIDANCE;
  1850. tov_itemstat_conversion[76] = TOV_ITEM_STAT_STEALTHINVISSPEEDMOD;
  1851. tov_itemstat_conversion[77] = TOV_ITEM_STAT_LOOT_COIN;
  1852. tov_itemstat_conversion[78] = TOV_ITEM_STAT_ARMORMITIGATIONINCREASE;
  1853. tov_itemstat_conversion[79] = TOV_ITEM_STAT_AMMOCONSERVATION;
  1854. tov_itemstat_conversion[80] = TOV_ITEM_STAT_STRIKETHROUGH;
  1855. tov_itemstat_conversion[81] = TOV_ITEM_STAT_STATUSBONUS;
  1856. tov_itemstat_conversion[82] = TOV_ITEM_STAT_ACCURACY;
  1857. tov_itemstat_conversion[83] = TOV_ITEM_STAT_COUNTERSTRIKE;
  1858. tov_itemstat_conversion[84] = TOV_ITEM_STAT_SHIELDBASH;
  1859. tov_itemstat_conversion[85] = TOV_ITEM_STAT_WEAPONDAMAGEBONUS;
  1860. tov_itemstat_conversion[86] = 698;
  1861. tov_itemstat_conversion[87] = TOV_ITEM_STAT_WEAPONDAMAGEBONUSMELEEONLY;
  1862. tov_itemstat_conversion[88] = TOV_ITEM_STAT_ADDITIONALRIPOSTECHANCE;
  1863. tov_itemstat_conversion[89] = TOV_ITEM_STAT_PVPTOUGHNESS;
  1864. tov_itemstat_conversion[90] = TOV_ITEM_STAT_PVPLETHALITY;
  1865. tov_itemstat_conversion[91] = TOV_ITEM_STAT_STAMINABONUS;
  1866. tov_itemstat_conversion[92] = TOV_ITEM_STAT_WISDOMMITBONUS;
  1867. tov_itemstat_conversion[93] = TOV_ITEM_STAT_HEALRECEIVE;
  1868. tov_itemstat_conversion[94] = TOV_ITEM_STAT_HEALRECEIVEPERC;
  1869. tov_itemstat_conversion[95] = TOV_ITEM_STAT_PVPCRITICALMITIGATION;
  1870. tov_itemstat_conversion[96] = TOV_ITEM_STAT_BASEAVOIDANCEBONUS;
  1871. tov_itemstat_conversion[97] = TOV_ITEM_STAT_INCOMBATSAVAGERYREGEN;
  1872. tov_itemstat_conversion[98] = TOV_ITEM_STAT_OUTOFCOMBATSAVAGERYREGEN;
  1873. tov_itemstat_conversion[99] = TOV_ITEM_STAT_SAVAGERYREGEN;
  1874. tov_itemstat_conversion[100] = TOV_ITEM_STAT_SAVAGERYGAINMOD;
  1875. tov_itemstat_conversion[101] = TOV_ITEM_STAT_MAXSAVAGERYLEVEL;
  1876. }
  1877. int32 World::LoadItemBlueStats() {
  1878. Query query;
  1879. MYSQL_ROW row;
  1880. int32 count = 0;
  1881. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT version_range1,version_range2,emu_stat,name,stat from itemstats");
  1882. if (result && mysql_num_rows(result) > 0) {
  1883. while (result && (row = mysql_fetch_row(result))) {
  1884. count++;
  1885. if (atoi(row[0]) >= 63119) //KA
  1886. ka_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1887. else if (atoi(row[0]) >= 57101) // ToV
  1888. tov_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1889. else if (atoi(row[0]) >= 1193) // CoE
  1890. coe_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1891. else if (atoi(row[0]) >= 1096) // DoV
  1892. dov_itemstat_conversion[atoi(row[2])] = atoi(row[4]);
  1893. }
  1894. }
  1895. return count;
  1896. }
  1897. sint16 World::GetItemStatTOVValue(sint16 subtype) {
  1898. return (tov_itemstat_conversion[subtype] - 600);
  1899. }
  1900. sint16 World::GetItemStatDOVValue(sint16 subtype) {
  1901. return (dov_itemstat_conversion[subtype] - 600);
  1902. }
  1903. sint16 World::GetItemStatCOEValue(sint16 subtype) {
  1904. return (coe_itemstat_conversion[subtype] - 600);
  1905. }
  1906. sint16 World::GetItemStatKAValue(sint16 subtype) {
  1907. return (ka_itemstat_conversion[subtype] - 600);
  1908. }
  1909. bool World::CheckTempBugCRC(char* msg)
  1910. {
  1911. MBugReport.writelock();
  1912. sint32 crc = GetItemNameCrc(std::string(msg));
  1913. if (bug_report_crc.count(crc) > 0)
  1914. {
  1915. MBugReport.releasewritelock();
  1916. return true;
  1917. }
  1918. else
  1919. bug_report_crc.insert(make_pair(crc, true));
  1920. MBugReport.releasewritelock();
  1921. return false;
  1922. }
  1923. #ifdef WIN32
  1924. ulong World::GetCurrentThreadID(){
  1925. return GetCurrentThreadId();
  1926. }
  1927. int64 World::GetThreadUsageCPUTime(){
  1928. HANDLE handle = GetCurrentThread();
  1929. int64 lpCreationTime;
  1930. int64 lpExitTime;
  1931. int64 lpKernelTime;
  1932. int64 lpUserTime;
  1933. if(GetThreadTimes(handle, (FILETIME*)&lpCreationTime, (FILETIME*)&lpExitTime, (FILETIME*)&lpKernelTime, (FILETIME*)&lpUserTime))
  1934. return lpKernelTime + lpUserTime;
  1935. return 0;
  1936. }
  1937. #else
  1938. #endif