World.cpp 74 KB

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