Guild.cpp 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451
  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 <string.h>
  17. #include <math.h>
  18. #include <assert.h>
  19. #include "Guild.h"
  20. #include "../Player.h"
  21. #include "../client.h"
  22. #include "../World.h"
  23. #include "../zoneserver.h"
  24. #include "../WorldDatabase.h"
  25. #include "../../common/Log.h"
  26. #include "../Rules/Rules.h"
  27. #include "../Web/PeerManager.h"
  28. extern ConfigReader configReader;
  29. extern ZoneList zone_list;
  30. extern WorldDatabase database;
  31. extern World world;
  32. extern RuleManager rule_manager;
  33. extern PeerManager peer_manager;
  34. /***************************************************************************************************************************************************
  35. * GUILD
  36. ***************************************************************************************************************************************************/
  37. Guild::Guild() {
  38. id = 0;
  39. memset(name, 0, sizeof(name));
  40. level = 1;
  41. formed_date = 0;
  42. memset(motd, 0, sizeof(motd));
  43. exp_current = 111;
  44. exp_to_next_level = 2521;
  45. recruiting_min_level = 1;
  46. recruiting_play_style = GUILD_RECRUITING_PLAYSTYLE_NONE;
  47. recruiting_flags.Put(GUILD_RECRUITING_FLAG_TRAINING, 0);
  48. recruiting_flags.Put(GUILD_RECRUITING_FLAG_FIGHTERS, 0);
  49. recruiting_flags.Put(GUILD_RECRUITING_FLAG_PRIESTS, 0);
  50. recruiting_flags.Put(GUILD_RECRUITING_FLAG_SCOUTS, 0);
  51. recruiting_flags.Put(GUILD_RECRUITING_FLAG_MAGES, 0);
  52. recruiting_flags.Put(GUILD_RECRUITING_FLAG_TRADESKILLERS, 0);
  53. recruiting_desc_tags.Put(0, GUILD_RECRUITING_DESC_TAG_NONE);
  54. recruiting_desc_tags.Put(1, GUILD_RECRUITING_DESC_TAG_NONE);
  55. recruiting_desc_tags.Put(2, GUILD_RECRUITING_DESC_TAG_NONE);
  56. recruiting_desc_tags.Put(3, GUILD_RECRUITING_DESC_TAG_NONE);
  57. banks[0].name = "Bank 1";
  58. banks[1].name = "Bank 2";
  59. banks[2].name = "Bank 3";
  60. banks[3].name = "Bank 4";
  61. save_needed = false;
  62. member_save_needed = false;
  63. events_save_needed = false;
  64. ranks_save_needed = false;
  65. event_filters_save_needed = false;
  66. points_history_save_needed = false;
  67. recruiting_save_needed = false;
  68. mMembers.SetName("Guild::members");
  69. }
  70. Guild::~Guild() {
  71. map<int32, GuildMember*>::iterator guild_member_itr;
  72. mMembers.writelock(__FUNCTION__, __LINE__);
  73. for (guild_member_itr = members.begin(); guild_member_itr != members.end(); guild_member_itr++) {
  74. deque<PointHistory*>::iterator point_history_itr;
  75. for (point_history_itr = guild_member_itr->second->point_history.begin(); point_history_itr != guild_member_itr->second->point_history.end(); point_history_itr++)
  76. safe_delete(*point_history_itr);
  77. safe_delete_array(guild_member_itr->second->recruiter_picture_data);
  78. safe_delete(guild_member_itr->second);
  79. }
  80. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  81. deque<GuildEvent*>::iterator guild_events_itr;
  82. for (guild_events_itr = guild_events.begin(); guild_events_itr != guild_events.end(); guild_events_itr++)
  83. safe_delete(*guild_events_itr);
  84. MutexMap<int8, MutexMap<int8, int8>*>::iterator permissions_itr = permissions.begin();
  85. while (permissions_itr.Next())
  86. safe_delete(permissions_itr.second);
  87. MutexMap<int8, MutexMap<int8, int8>*>::iterator filter_itr = event_filters.begin();
  88. while (filter_itr.Next())
  89. safe_delete(filter_itr.second);
  90. for (int32 i = 0; i < 4; i++) {
  91. deque<GuildBankEvent*>::iterator bank_event_itr;
  92. for (bank_event_itr = banks[i].events.begin(); bank_event_itr != banks[i].events.end(); bank_event_itr++)
  93. safe_delete(*bank_event_itr);
  94. }
  95. }
  96. void Guild::SetName(const char* name, bool send_packet) {
  97. assert(name);
  98. strncpy(this->name, name, sizeof(this->name));
  99. if (send_packet) {
  100. LogWrite(GUILD__DEBUG, 1, "Guilds", "Setting Guild Name to '%s'...", name);
  101. SendGuildUpdate();
  102. save_needed = true;
  103. }
  104. }
  105. void Guild::SetLevel(int8 level, bool send_packet) {
  106. this->level = level;
  107. if (send_packet) {
  108. LogWrite(GUILD__DEBUG, 1, "Guilds", "Setting Guild Level to %i...", level);
  109. SendGuildUpdate();
  110. save_needed = true;
  111. }
  112. }
  113. void Guild::SetMOTD(const char *motd, bool send_packet) {
  114. assert(motd);
  115. strncpy(this->motd, motd, sizeof(this->motd));
  116. if (send_packet) {
  117. LogWrite(GUILD__DEBUG, 1, "Guilds", "Setting Guild MOTD text:\n'%s'", motd);
  118. SendGuildUpdate();
  119. save_needed = true;
  120. }
  121. }
  122. void Guild::SetEXPCurrent(int64 exp, bool send_packet) {
  123. exp_current = exp;
  124. if (send_packet) {
  125. LogWrite(GUILD__DEBUG, 1, "Guilds", "Setting Guild Current XP to %u", exp);
  126. SendGuildUpdate();
  127. save_needed = true;
  128. }
  129. }
  130. void Guild::AddEXPCurrent(sint64 exp, bool send_packet) {
  131. bool ret = false;
  132. char message[128];
  133. char adjective[16];
  134. int8 guild_max_level = rule_manager.GetGlobalRule(R_Guild, MaxLevel)->GetInt8();
  135. if (exp > 0 && level < guild_max_level) {
  136. exp_current += exp;
  137. if (exp_current >= exp_to_next_level) {
  138. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild %s Level UP! New Level: %i (current XP: %ul)", name, level, exp_current);
  139. int64 left_over = exp_current - exp_to_next_level;
  140. level++;
  141. exp_to_next_level *= 2;
  142. exp_current = left_over;
  143. AddNewGuildEvent(GUILD_EVENT_GUILD_LEVEL_UP, "The guild gained a level and is now level %u.", Timer::GetUnixTimeStamp(), true, level);
  144. SendMessageToGuild(GUILD_EVENT_GUILD_LEVEL_UP, "The guild gained a level and is now level %u.", level);
  145. if (level % 10 == 0) {
  146. if (level == 10)
  147. strncpy(adjective, "bold", sizeof(adjective));
  148. else if (level == 20)
  149. strncpy(adjective, "daring", sizeof(adjective));
  150. else if (level == 30)
  151. strncpy(adjective, "gallant", sizeof(adjective));
  152. else if (level == 40)
  153. strncpy(adjective, "noble", sizeof(adjective));
  154. else if (level == 50)
  155. strncpy(adjective, "heroic", sizeof(adjective));
  156. else if (level == 60)
  157. strncpy(adjective, "lordly", sizeof(adjective));
  158. else if (level == 70)
  159. strncpy(adjective, "legendary", sizeof(adjective));
  160. else if (level == 80)
  161. strncpy(adjective, "epic", sizeof(adjective));
  162. else
  163. strncpy(adjective, "too uber for cheerios", sizeof(adjective) - 1);
  164. sprintf(message, "The %s guild <%s> has attained level %u", adjective, name, level);
  165. zone_list.HandleGlobalAnnouncement(message);
  166. }
  167. }
  168. save_needed = true;
  169. ret = true;
  170. }
  171. else if (exp < 0) {
  172. }
  173. if (ret && send_packet)
  174. SendGuildUpdate();
  175. }
  176. void Guild::SetEXPToNextLevel(int64 exp, bool send_packet) {
  177. exp_to_next_level = exp;
  178. if (send_packet) {
  179. LogWrite(GUILD__DEBUG, 1, "Guilds", "Guild XP to next level: %ul", exp_to_next_level);
  180. SendGuildUpdate();
  181. save_needed = true;
  182. }
  183. }
  184. void Guild::SetRecruitingShortDesc(const char* new_desc, bool send_packet) {
  185. assert(new_desc);
  186. recruiting_short_desc = string(new_desc);
  187. if (send_packet) {
  188. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting short desc:\n%s", recruiting_short_desc.c_str());
  189. SendGuildUpdate();
  190. recruiting_save_needed = true;
  191. }
  192. }
  193. void Guild::SetRecruitingFullDesc(const char* new_desc, bool send_packet) {
  194. assert(new_desc);
  195. recruiting_full_desc = string(new_desc);
  196. if (send_packet) {
  197. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting full desc:\n%s", recruiting_full_desc.c_str());
  198. SendGuildUpdate();
  199. recruiting_save_needed = true;
  200. }
  201. }
  202. void Guild::SetRecruitingMinLevel(int8 new_level, bool send_packet) {
  203. recruiting_min_level = new_level;
  204. if (send_packet) {
  205. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting min_level: %i", recruiting_min_level);
  206. SendGuildUpdate();
  207. recruiting_save_needed = true;
  208. }
  209. }
  210. void Guild::SetRecruitingPlayStyle(int8 new_play_style, bool send_packet) {
  211. recruiting_play_style = new_play_style;
  212. if (send_packet) {
  213. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting play style: %i", recruiting_play_style);
  214. SendGuildUpdate();
  215. recruiting_save_needed = true;
  216. }
  217. }
  218. bool Guild::SetRecruitingDescTag(int8 index, int8 tag, bool send_packet) {
  219. bool ret = false;
  220. if (index <= 3) {
  221. recruiting_desc_tags.Put(index, tag);
  222. ret = true;
  223. }
  224. if (ret && send_packet) {
  225. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting descriptive tag index: %i, tag: %i", index, tag);
  226. SendGuildUpdate();
  227. recruiting_save_needed = true;
  228. }
  229. return ret;
  230. }
  231. int8 Guild::GetRecruitingDescTag(int8 index) {
  232. int8 ret = 0;
  233. if (index <= 3)
  234. ret = recruiting_desc_tags.Get(index);
  235. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Recruiting descriptive tag index: %i, value: %i", index, ret);
  236. return ret;
  237. }
  238. bool Guild::SetPermission(int8 rank, int8 permission, int8 value, bool send_packet, bool save_needed) {
  239. bool ret = false;
  240. if (value == 0 || value == 1) {
  241. if (permissions.count(rank) == 0)
  242. permissions.Put(rank, new MutexMap<int8, int8>);
  243. permissions.Get(rank)->Put(permission, value);
  244. ret = true;
  245. }
  246. if (ret && send_packet) {
  247. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Permissions - Rank: %i, Permission: %i, Value: %i", rank, permission, value);
  248. SendGuildUpdate();
  249. if(save_needed)
  250. ranks_save_needed = true;
  251. }
  252. return ret;
  253. }
  254. int8 Guild::GetPermission(int8 rank, int8 permission) {
  255. int8 ret = 0;
  256. if (permissions.count(rank) > 0 && permissions.Get(rank)->count(permission) > 0)
  257. ret = permissions.Get(rank)->Get(permission);
  258. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Permissions - Rank: %i, Permission: %i, Value: %i", rank, permission, ret);
  259. return ret;
  260. }
  261. bool Guild::SetEventFilter(int8 event_id, int8 category, int8 value, bool send_packet, bool save_needed) {
  262. bool ret = false;
  263. if ((category == GUILD_EVENT_FILTER_CATEGORY_RETAIN_HISTORY || category == GUILD_EVENT_FILTER_CATEGORY_BROADCAST) && (value == 0 || value == 1)) {
  264. if (event_filters.count(event_id) == 0)
  265. event_filters.Put(event_id, new MutexMap<int8, int8>);
  266. event_filters.Get(event_id)->Put(category, value);
  267. ret = true;
  268. }
  269. if (ret && send_packet) {
  270. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Event Filter - EventID: %i, Category: %i, Value: %i", event_id, category, value);
  271. SendGuildUpdate();
  272. if(save_needed)
  273. event_filters_save_needed = true;
  274. }
  275. return ret;
  276. }
  277. int8 Guild::GetEventFilter(int8 event_id, int8 category) {
  278. int8 ret = 0;
  279. if (event_filters.count(event_id) > 0 && event_filters.Get(event_id)->count(category) > 0) {
  280. ret = event_filters.Get(event_id)->Get(category);
  281. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Event Filter - EventID: %i, Category: %i, Value: %i", event_id, category, ret);
  282. }
  283. return ret;
  284. }
  285. int32 Guild::GetNumUniqueAccounts() {
  286. map<int32, GuildMember *>::iterator itr;
  287. map<int32, bool> accounts;
  288. mMembers.readlock(__FUNCTION__, __LINE__);
  289. if (members.size() > 0) {
  290. for (itr = members.begin(); itr != members.end(); itr++) {
  291. if (accounts.count(itr->second->account_id) == 0)
  292. accounts[itr->second->account_id] = true;
  293. }
  294. }
  295. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  296. LogWrite(GUILD__DEBUG, 1, "Guilds", "Found %i Unique Account(s) in Guild", accounts.size());
  297. return accounts.size();
  298. }
  299. int32 Guild::GetNumRecruiters() {
  300. map<int32, GuildMember*>::iterator itr;
  301. int32 ret = 0;
  302. mMembers.readlock(__FUNCTION__, __LINE__);
  303. for (itr = members.begin(); itr != members.end(); itr++) {
  304. if (itr->second->recruiter_id > 0 && (itr->second->member_flags & GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD))
  305. ret++;
  306. }
  307. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  308. LogWrite(GUILD__DEBUG, 1, "Guilds", "Found %i Recruiter(s) in Guild", ret);
  309. return ret;
  310. }
  311. int32 Guild::GetNextRecruiterID() {
  312. map<int32, GuildMember*>::iterator itr;
  313. map<int32, bool> tmp;
  314. int32 i, ret = 0;
  315. mMembers.readlock(__FUNCTION__, __LINE__);
  316. for (itr = members.begin(); itr != members.end(); itr++) {
  317. if (itr->second->recruiter_id > 0)
  318. tmp[itr->second->recruiter_id] = true;
  319. }
  320. for (i = 1; i < 0xFFFFFFFF; i++) {
  321. if (tmp.count(i) == 0) {
  322. ret = i;
  323. break;
  324. }
  325. }
  326. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  327. LogWrite(GUILD__DEBUG, 1, "Guilds", "Next Guild Recruiter ID: %i", ret);
  328. return ret;
  329. }
  330. int64 Guild::GetNextEventID() {
  331. GuildEvent *ge;
  332. int64 ret = 1;
  333. if (guild_events.size() > 0) {
  334. ge = guild_events.front();
  335. ret = ge->event_id + 1;
  336. }
  337. LogWrite(GUILD__DEBUG, 1, "Guilds", "Next Guild Event ID: %i", ret);
  338. return ret;
  339. }
  340. GuildMember * Guild::GetGuildMemberOnline(Client *client) {
  341. map<int32, GuildMember*>::iterator itr;
  342. GuildMember *ret = 0;
  343. assert(client);
  344. mMembers.readlock(__FUNCTION__, __LINE__);
  345. for (itr = members.begin(); itr != members.end(); itr++) {
  346. if (itr->second->character_id == client->GetCharacterID()) {
  347. ret = itr->second;
  348. break;
  349. }
  350. }
  351. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  352. LogWrite(GUILD__DEBUG, 3, "Guilds", "Guild Member Online: %s", ret->name);
  353. return ret;
  354. }
  355. GuildMember * Guild::GetGuildMember(Player *player) {
  356. assert(player);
  357. return GetGuildMember(player->GetCharacterID());
  358. }
  359. GuildMember * Guild::GetGuildMember(int32 character_id) {
  360. GuildMember *ret = 0;
  361. mMembers.readlock(__FUNCTION__, __LINE__);
  362. if (members.count(character_id) > 0)
  363. ret = members[character_id];
  364. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  365. LogWrite(GUILD__DEBUG, 1, "Guilds", "%s: %i", __FUNCTION__, character_id);
  366. return ret;
  367. }
  368. GuildMember * Guild::GetGuildMember(const char *player_name) {
  369. map<int32, GuildMember*>::iterator itr;
  370. GuildMember *ret = 0;
  371. assert(player_name);
  372. mMembers.readlock(__FUNCTION__, __LINE__);
  373. for (itr = members.begin(); itr != members.end(); itr++) {
  374. if (!strncmp(player_name, itr->second->name, sizeof(itr->second->name))) {
  375. ret = itr->second;
  376. break;
  377. }
  378. }
  379. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  380. LogWrite(GUILD__DEBUG, 1, "Guilds", "%s: %s", __FUNCTION__, player_name);
  381. return ret;
  382. }
  383. vector<GuildMember *> * Guild::GetGuildRecruiters() {
  384. map<int32, GuildMember*>::iterator itr;
  385. vector<GuildMember *> *ret = 0;
  386. mMembers.readlock(__FUNCTION__, __LINE__);
  387. for (itr = members.begin(); itr != members.end(); itr++) {
  388. if (itr->second->recruiter_id > 0 && (itr->second->member_flags & GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD)) {
  389. if (!ret)
  390. ret = new vector<GuildMember *>;
  391. ret->push_back(itr->second);
  392. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Recruiter '%s' (%i)", itr->second->name, itr->second->recruiter_id);
  393. }
  394. }
  395. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  396. return ret;
  397. }
  398. GuildEvent * Guild::GetGuildEvent(int64 event_id) {
  399. deque<GuildEvent*>::iterator itr;
  400. GuildEvent* ret = 0;
  401. for (itr = guild_events.begin(); itr != guild_events.end(); itr++) {
  402. if ((*itr)->event_id == event_id) {
  403. ret = *itr;
  404. break;
  405. }
  406. }
  407. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Event: %s (%lli)", ret->description.c_str(), ret->event_id);
  408. return ret;
  409. }
  410. bool Guild::SetRankName(int8 rank, const char *name, bool send_packet) {
  411. assert(name);
  412. ranks.Put(rank, string(name));
  413. if (send_packet) {
  414. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set Guild Rank Name: %s (%i)", name, rank);
  415. SendGuildUpdate();
  416. ranks_save_needed = true;
  417. }
  418. return true;
  419. }
  420. const char * Guild::GetRankName(int8 rank) {
  421. if (ranks.count(rank) > 0) {
  422. LogWrite(GUILD__DEBUG, 0, "Guilds", "Get Guild Rank Name: %s (%i)", ranks.Get(rank).c_str(), rank);
  423. return ranks.Get(rank).c_str();
  424. }
  425. return 0;
  426. }
  427. bool Guild::SetRecruitingFlag(int8 flag, int8 value, bool send_packet) {
  428. bool ret = false;
  429. if (recruiting_flags.count(flag) > 0 && (value == 0 || value == 1)) {
  430. recruiting_flags.Put(flag, value);
  431. ret = true;
  432. }
  433. if (ret && send_packet) {
  434. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set Guild Recruiting Flag: %i, Value: %i", flag, value);
  435. SendGuildUpdate();
  436. recruiting_save_needed = true;
  437. }
  438. return ret;
  439. }
  440. int8 Guild::GetRecruitingFlag(int8 flag) {
  441. int8 value = 0;
  442. if (recruiting_flags.count(flag) > 0)
  443. value = recruiting_flags.Get(flag);
  444. LogWrite(GUILD__DEBUG, 0, "Guilds", "Get Guild Recruiting Flag: %i, Value: %i", flag, value);
  445. return value;
  446. }
  447. bool Guild::SetGuildRecruiter(Client* client, const char* name, bool value, bool send_packet) {
  448. GuildMember *gm;
  449. const char *awarder_name;
  450. assert(client);
  451. assert(name);
  452. if (!(gm = GetGuildMember(name)))
  453. return false;
  454. awarder_name = client->GetPlayer()->GetName();
  455. if (value) {
  456. gm->recruiter_id = GetNextRecruiterID();
  457. AddNewGuildEvent(GUILD_EVENT_BECOMES_RECRUITER, "%s awarded %s Guild Recruiting Permission.", Timer::GetUnixTimeStamp(), true, awarder_name, name);
  458. SendMessageToGuild(GUILD_EVENT_BECOMES_RECRUITER, "%s awarded %s Guild Recruiting Permission.", awarder_name, name);
  459. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s makes %s a guild recruiter.", awarder_name, name);
  460. }
  461. else {
  462. gm->recruiter_id = 0;
  463. AddNewGuildEvent(GUILD_EVENT_NO_LONGER_RECRUITER, "%s revoked %s's Guild Recruiting Permission.", Timer::GetUnixTimeStamp(), true, awarder_name, name);
  464. SendMessageToGuild(GUILD_EVENT_NO_LONGER_RECRUITER, "%s revoked %s's Guild Recruiting Permission.", awarder_name, name);
  465. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s removes %s from guild recruiters.", awarder_name, name);
  466. }
  467. if (send_packet) {
  468. SendGuildMember(gm);
  469. member_save_needed = true;
  470. }
  471. return true;
  472. }
  473. bool Guild::SetGuildRecruiterDescription(Client *client, const char *description, bool send_packet) {
  474. GuildMember *gm;
  475. assert(client);
  476. assert(description);
  477. if (!(gm = GetGuildMember(client->GetPlayer())))
  478. return false;
  479. gm->recruiter_description = string(description);
  480. if (send_packet) {
  481. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set guild recruiter description:\n%s", gm->recruiter_description.c_str());
  482. SendGuildRecruiterInfo(client, client->GetPlayer());
  483. member_save_needed = true;
  484. }
  485. return true;
  486. }
  487. bool Guild::ToggleGuildRecruiterAdventureClass(Client *client, bool send_packet) {
  488. GuildMember *gm;
  489. assert(client);
  490. if (!(gm = GetGuildMember(client->GetPlayer())))
  491. return false;
  492. gm->recruiting_show_adventure_class = (gm->recruiting_show_adventure_class == 0 ? 1 : 0);
  493. if (send_packet) {
  494. LogWrite(GUILD__DEBUG, 0, "Guilds", "Toggle guild recruiter adventure class = %i", gm->recruiting_show_adventure_class);
  495. SendGuildRecruiterInfo(client, client->GetPlayer());
  496. }
  497. return true;
  498. }
  499. bool Guild::SetGuildMemberNote(const char *name, const char *note, bool send_packet) {
  500. GuildMember *gm;
  501. assert(name);
  502. assert(note);
  503. if (!(gm = GetGuildMember(name)))
  504. return false;
  505. gm->note = string(note);
  506. if (send_packet) {
  507. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set guild member note:\n%s", gm->note.c_str());
  508. SendGuildMember(gm);
  509. member_save_needed = true;
  510. }
  511. return true;
  512. }
  513. bool Guild::SetGuildOfficerNote(const char *name, const char *note, bool send_packet) {
  514. GuildMember *gm;
  515. assert(name);
  516. assert(note);
  517. if (!(gm = GetGuildMember(name)))
  518. return false;
  519. gm->officer_note = string(note);
  520. if (send_packet) {
  521. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set guild officer note:\n%s", gm->officer_note.c_str());
  522. SendGuildMember(gm);
  523. member_save_needed = true;
  524. }
  525. return true;
  526. }
  527. bool Guild::AddNewGuildMember(Client *client, const char *invited_by, int8 rank) {
  528. Player *player;
  529. GuildMember *gm;
  530. assert(client);
  531. player = client->GetPlayer();
  532. assert(player);
  533. if (members.count(player->GetCharacterID()) == 0 && !player->GetGuild() && ((Player*)player)->GetClient()) {
  534. gm = new GuildMember;
  535. gm->account_id = ((Player*)player)->GetClient()->GetAccountID();
  536. gm->character_id = player->GetCharacterID();
  537. strncpy(gm->name, player->GetName(), sizeof(gm->name));
  538. gm->guild_status = 0;
  539. gm->points = 0.0;
  540. gm->adventure_class = player->GetAdventureClass();
  541. gm->adventure_level = player->GetLevel();
  542. gm->tradeskill_class = player->GetTradeskillClass();
  543. gm->tradeskill_level = player->GetTSLevel();
  544. gm->rank = rank;
  545. gm->zone = string(player->GetZone()->GetZoneDescription());
  546. gm->join_date = Timer::GetUnixTimeStamp();
  547. gm->last_login_date = gm->join_date;
  548. gm->recruiter_id = 0;
  549. gm->member_flags = GUILD_MEMBER_FLAGS_NOTIFY_LOGINS;
  550. gm->recruiting_show_adventure_class = 1;
  551. gm->recruiter_picture_data_size = 0;
  552. gm->recruiter_picture_data = 0;
  553. mMembers.writelock(__FUNCTION__, __LINE__);
  554. members[player->GetCharacterID()] = gm;
  555. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  556. player->SetGuild(this);
  557. string subtitle;
  558. subtitle.append("<").append(GetName()).append(">");
  559. player->SetSubTitle(subtitle.c_str());
  560. if (invited_by)
  561. client->SimpleMessage(CHANNEL_NARRATIVE, "You accept the invite into the guild.");
  562. else {
  563. client->SimpleMessage(CHANNEL_NARRATIVE, "You have formed the guild.");
  564. LogWrite(GUILD__DEBUG, 0, "Guilds", "New Guild formed: %s", GetName());
  565. }
  566. client->PlaySound("ui_joined");
  567. SendGuildUpdate(client);
  568. SendGuildMember(gm);
  569. SendGuildMOTD(client);
  570. SendGuildEventList(client);
  571. SendGuildBankEventList(client);
  572. SendAllGuildEvents(client);
  573. SendGuildMemberList(client);
  574. if(client->GetVersion() > 561)
  575. client->GetCurrentZone()->SendUpdateTitles(client->GetPlayer());
  576. if (invited_by) {
  577. AddNewGuildEvent(GUILD_EVENT_MEMBER_JOINS, "%s has accepted %s's invitation to join %s.", Timer::GetUnixTimeStamp(), true, player->GetName(), invited_by, GetName());
  578. SendMessageToGuild(GUILD_EVENT_MEMBER_JOINS, "%s has accepted %s's invitation to join %s.", player->GetName(), invited_by, GetName());
  579. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s invited %s to join guild: %s", invited_by, player->GetName(), GetName());
  580. }
  581. member_save_needed = true;
  582. peer_manager.sendPeersAddGuildMember(gm->character_id, GetID(), (invited_by != nullptr) ? std::string(invited_by) : "", gm->join_date, rank);
  583. }
  584. return true;
  585. }
  586. bool Guild::AddNewGuildMember(int32 characterID, const char *invited_by, int32 join_timestamp, int8 rank) {
  587. GuildMember *gm;
  588. if (members.count(characterID) == 0) {
  589. gm = new GuildMember;
  590. bool foundMember = peer_manager.GetClientGuildDetails(characterID, gm);
  591. if(!foundMember) {
  592. LogWrite(GUILD__ERROR, 0, "Guilds", "FAILED TO FIND MEMBER: %s invited %s to join guild: %s", invited_by, gm->name, GetName());
  593. safe_delete(gm);
  594. return false;
  595. }
  596. gm->rank = rank;
  597. gm->join_date = join_timestamp;
  598. gm->last_login_date = gm->join_date;
  599. mMembers.writelock(__FUNCTION__, __LINE__);
  600. members[characterID] = gm;
  601. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  602. if (invited_by) {
  603. AddNewGuildEvent(GUILD_EVENT_MEMBER_JOINS, "%s has accepted %s's invitation to join %s.", Timer::GetUnixTimeStamp(), true, gm->name, invited_by, GetName());
  604. SendMessageToGuild(GUILD_EVENT_MEMBER_JOINS, "%s has accepted %s's invitation to join %s.", gm->name, invited_by, GetName());
  605. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s invited %s to join guild: %s", invited_by, gm->name, GetName());
  606. }
  607. }
  608. return true;
  609. }
  610. bool Guild::AddGuildMember(GuildMember *guild_member) {
  611. assert(guild_member);
  612. mMembers.writelock(__FUNCTION__, __LINE__);
  613. assert(members.count(guild_member->character_id) == 0);
  614. members[guild_member->character_id] = guild_member;
  615. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  616. // spammy
  617. LogWrite(GUILD__DEBUG, 5, "Guilds", "Added Player: %s (%i) to Guild: %s", guild_member->name, guild_member->character_id, GetName());
  618. return true;
  619. }
  620. void Guild::RemoveGuildMember(int32 character_id, bool send_packet) {
  621. GuildMember *gm = 0;
  622. Client *client;
  623. mMembers.writelock(__FUNCTION__, __LINE__);
  624. if (members.count(character_id) > 0) {
  625. gm = members[character_id];
  626. members.erase(gm->character_id);
  627. }
  628. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  629. if (gm) {
  630. LogWrite(GUILD__DEBUG, 0, "Guilds", "Remove Player: %s (%i) from Guild: %s", members[character_id]->name, character_id, GetName());
  631. if ((client = zone_list.GetClientByCharID(character_id))) {
  632. client->GetPlayer()->SetGuild(0);
  633. client->GetPlayer()->SetSubTitle("");
  634. client->GetCurrentZone()->SendUpdateTitles(client->GetPlayer());
  635. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You were removed from the guild.");
  636. }
  637. database.DeleteGuildMember(this, gm->character_id);
  638. if (send_packet) {
  639. SendGuildMemberLeave(gm->character_id);
  640. SendGuildUpdate();
  641. SendGuildMemberList();
  642. }
  643. AddNewGuildEvent(GUILD_EVENT_MEMBER_LEAVES, "%s left the guild.", Timer::GetUnixTimeStamp(), true, gm->name);
  644. SendMessageToGuild(GUILD_EVENT_MEMBER_LEAVES, "%s left the guild.", gm->name);
  645. safe_delete_array(gm->recruiter_picture_data);
  646. safe_delete(gm);
  647. }
  648. }
  649. void Guild::RemoveAllGuildMembers() {
  650. map<int32, GuildMember *>::iterator itr;
  651. Client *client;
  652. mMembers.writelock(__FUNCTION__, __LINE__);
  653. for (itr = members.begin(); itr != members.end(); itr++) {
  654. if ((client = zone_list.GetClientByCharID(itr->second->character_id))) {
  655. client->GetPlayer()->SetGuild(0);
  656. client->GetPlayer()->SetSubTitle("");
  657. }
  658. safe_delete(itr->second);
  659. }
  660. members.clear();
  661. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  662. LogWrite(GUILD__DEBUG, 0, "Guilds", "Removed ALL members from Guild: %s", GetName());
  663. }
  664. bool Guild::DemoteGuildMember(Client *client, const char *name, bool send_packet) {
  665. GuildMember *gm;
  666. const char *demoter_name;
  667. bool ret = false;
  668. assert(client);
  669. assert(name);
  670. mMembers.readlock(__FUNCTION__, __LINE__);
  671. if ((gm = GetGuildMember(name)) && gm->rank != GUILD_RANK_RECRUIT) {
  672. demoter_name = client->GetPlayer()->GetName();
  673. gm->rank++;
  674. AddNewGuildEvent(GUILD_EVENT_MEMBER_DEMOTED, "%s has demoted %s to %s.", Timer::GetUnixTimeStamp(), true, demoter_name, name, ranks.Get(gm->rank).c_str());
  675. SendMessageToGuild(GUILD_EVENT_MEMBER_DEMOTED, "%s has demoted %s to %s.", demoter_name, name, ranks.Get(gm->rank).c_str());
  676. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s demoted %s to %s in Guild: %s", demoter_name, name, ranks.Get(gm->rank).c_str(), GetName());
  677. ret = true;
  678. if (send_packet) {
  679. SendGuildMember(gm);
  680. SendGuildMemberList();
  681. member_save_needed = true;
  682. }
  683. }
  684. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  685. return ret;
  686. }
  687. bool Guild::PromoteGuildMember(Client *client, const char *name, bool send_packet) {
  688. GuildMember *gm;
  689. const char *promoter_name;
  690. bool ret = false;
  691. assert(client);
  692. assert(name);
  693. mMembers.readlock(__FUNCTION__, __LINE__);
  694. if ((gm = GetGuildMember(name)) && gm->rank != GUILD_RANK_LEADER) {
  695. promoter_name = client->GetPlayer()->GetName();
  696. gm->rank--;
  697. AddNewGuildEvent(GUILD_EVENT_MEMBER_PROMOTED, "%s has promoted %s to %s.", Timer::GetUnixTimeStamp(), true, promoter_name, name, ranks.Get(gm->rank).c_str());
  698. SendMessageToGuild(GUILD_EVENT_MEMBER_PROMOTED, "%s has promoted %s to %s.", promoter_name, name, ranks.Get(gm->rank).c_str());
  699. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s promoted %s to %s in Guild: %s", promoter_name, name, ranks.Get(gm->rank).c_str(), GetName());
  700. if (send_packet) {
  701. SendGuildMember(gm);
  702. SendGuildMemberList();
  703. member_save_needed = true;
  704. }
  705. }
  706. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  707. return ret;
  708. }
  709. int32 Guild::KickGuildMember(Client *client, const char *name, bool send_packet) {
  710. GuildMember *gm;
  711. Client *kicked_client;
  712. const char *kicker_name;
  713. int32 character_id = 0;
  714. assert(client);
  715. assert(name);
  716. if (!(gm = GetGuildMember(name)))
  717. return 0;
  718. kicker_name = client->GetPlayer()->GetName();
  719. character_id = gm->character_id;
  720. if (!strncmp(kicker_name, gm->name, sizeof(gm->name))) {
  721. AddNewGuildEvent(GUILD_EVENT_MEMBER_LEAVES, "%s left the guild.", Timer::GetUnixTimeStamp(), true, gm->name);
  722. SendMessageToGuild(GUILD_EVENT_MEMBER_LEAVES, "%s left the guild.", gm->name);
  723. LogWrite(GUILD__DEBUG, 0, "Guilds", "Player: %s has left guild: %s", gm->name, GetName());
  724. }
  725. else {
  726. AddNewGuildEvent(GUILD_EVENT_MEMBER_LEAVES, "%s kicked %s from the guild.", Timer::GetUnixTimeStamp(), true, kicker_name, gm->name);
  727. SendMessageToGuild(GUILD_EVENT_MEMBER_LEAVES, "%s kicked %s from the guild.", kicker_name, gm->name);
  728. LogWrite(GUILD__DEBUG, 0, "Guilds", "Player: %s was kicked from guild: %s by %s.", gm->name, GetName(), kicker_name);
  729. }
  730. if ((kicked_client = zone_list.GetClientByCharID(gm->character_id))) {
  731. kicked_client->GetPlayer()->SetGuild(0);
  732. kicked_client->GetPlayer()->SetSubTitle("");
  733. if (!strncmp(client->GetPlayer()->GetName(), gm->name, sizeof(gm->name)))
  734. kicked_client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You left the guild.");
  735. else
  736. kicked_client->Message(CHANNEL_COLOR_YELLOW, "You were kicked from the guild by %s.", kicker_name);
  737. }
  738. mMembers.writelock(__FUNCTION__, __LINE__);
  739. members.erase(gm->character_id);
  740. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  741. database.DeleteGuildMember(this, gm->character_id);
  742. if (send_packet) {
  743. SendGuildMemberLeave(gm->character_id);
  744. SendGuildUpdate();
  745. SendGuildMemberList();
  746. }
  747. safe_delete_array(gm->recruiter_picture_data);
  748. safe_delete(gm);
  749. return character_id;
  750. }
  751. bool Guild::InvitePlayer(Client *client, const char *name, bool send_packet) {
  752. Client *client_invite;
  753. Player *player_invite;
  754. PacketStruct *packet;
  755. assert(client);
  756. assert(name);
  757. if (!(client_invite = zone_list.GetClientByCharName(string(name)))) {
  758. client->Message(CHANNEL_NARRATIVE, "%s couldn't be found.", name);
  759. LogWrite(GUILD__WARNING, 0, "Guilds", "Attempted to invite %s to guild %s: Player Not Found", name, GetName());
  760. return false;
  761. }
  762. player_invite = client_invite->GetPlayer();
  763. if (player_invite->GetGuild()) {
  764. client->Message(CHANNEL_NARRATIVE, "%s is already in a guild.", player_invite->GetName());
  765. LogWrite(GUILD__WARNING, 0, "Guilds", "Attempted to invite %s to guild %s: Already in a guild", player_invite->GetName(), GetName());
  766. return false;
  767. }
  768. if (client_invite->GetPendingGuildInvite()->guild) {
  769. client->Message(CHANNEL_NARRATIVE, "%s is already considering joining a guild.", player_invite->GetName());
  770. LogWrite(GUILD__WARNING, 0, "Guilds", "Attempted to invite %s to guild %s: Pending Invite elsewhere", player_invite->GetName(), GetName());
  771. return false;
  772. }
  773. if (!(packet = configReader.getStruct("WS_ReceiveOffer", client_invite->GetVersion())))
  774. return false;
  775. packet->setDataByName("type", 2);
  776. packet->setMediumStringByName("name", client->GetPlayer()->GetName());
  777. packet->setDataByName("unknown2", 1);
  778. packet->setMediumStringByName("guild_name", GetName());
  779. client_invite->QueuePacket(packet->serialize());
  780. client->Message(CHANNEL_NARRATIVE, "You have invited %s to join %s.", player_invite->GetName(), GetName());
  781. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s invited %s to guild %s", client->GetPlayer()->GetName(), player_invite->GetName(), GetName());
  782. client_invite->SetPendingGuildInvite(this, client->GetPlayer());
  783. safe_delete(packet);
  784. return true;
  785. }
  786. bool Guild::AddPointsToAll(Client *client, float points, const char *comment, bool send_packet) {
  787. map<int32, GuildMember *>::iterator itr;
  788. vector<int32> character_ids;
  789. GuildMember *gm;
  790. Client *client_to;
  791. assert(client);
  792. mMembers.readlock(__FUNCTION__, __LINE__);
  793. for (itr = members.begin(); itr != members.end(); itr++) {
  794. gm = itr->second;
  795. if (!permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_RECEIVE_POINTS)) {
  796. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not allowed to receive points! Skipping...", gm->character_id);
  797. continue;
  798. }
  799. gm->points += points;
  800. character_ids.push_back(gm->character_id);
  801. AddPointHistory(gm, Timer::GetUnixTimeStamp(), client->GetPlayer()->GetName(), points, comment);
  802. if ((client_to = zone_list.GetClientByCharID(gm->character_id)))
  803. {
  804. client_to->Message(CHANNEL_GUILD_CHAT, "%s increased your guild member points by %.1f.", client->GetPlayer()->GetName(), points);
  805. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild: %s", GetName());
  806. LogWrite(GUILD__DEBUG, 0, "Guilds", "\tAwarded By: %s +%.1f pts to Player: %s", client->GetPlayer()->GetName(), points, gm->name);
  807. }
  808. SendGuildMember(gm); //tmp
  809. }
  810. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  811. client->Message(CHANNEL_GUILD_CHAT, "Points modified for %u guild members.", character_ids.size());
  812. if (send_packet) {
  813. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s modified points for %u members. Reason: %s", client->GetPlayer()->GetName(), character_ids.size(), points, comment);
  814. SendGuildModification(points, &character_ids);
  815. member_save_needed = true;
  816. points_history_save_needed = true;
  817. }
  818. return true;
  819. }
  820. bool Guild::AddPointsToAllOnline(Client *client, float points, const char *comment, bool send_packet) {
  821. map<int32, GuildMember *>::iterator itr;
  822. vector<int32> character_ids;
  823. GuildMember *gm;
  824. Client *client_to;
  825. assert(client);
  826. mMembers.readlock(__FUNCTION__, __LINE__);
  827. for (itr = members.begin(); itr != members.end(); itr++) {
  828. gm = itr->second;
  829. if (!(client_to = zone_list.GetClientByCharID(gm->character_id))) {
  830. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not online to receive points! Skipping...", gm->character_id);
  831. continue;
  832. }
  833. if (!permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_RECEIVE_POINTS)) {
  834. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not allowed to receive points! Skipping...", gm->character_id);
  835. continue;
  836. }
  837. gm->points += points;
  838. character_ids.push_back(gm->character_id);
  839. AddPointHistory(gm, Timer::GetUnixTimeStamp(), client->GetPlayer()->GetName(), points, comment);
  840. client_to->Message(CHANNEL_GUILD_CHAT, "%s increased your guild member points by %.1f.", client->GetPlayer()->GetName(), points);
  841. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild: %s", GetName());
  842. LogWrite(GUILD__DEBUG, 0, "Guilds", "\tAwarded By: %s +%.1f pts to Player: %s", client->GetPlayer()->GetName(), points, gm->name);
  843. SendGuildMember(gm); //tmp
  844. }
  845. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  846. client->Message(CHANNEL_GUILD_CHAT, "Points modified for %u guild members.", character_ids.size());
  847. if (send_packet) {
  848. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s modified points for %u members. Reason: %s", client->GetPlayer()->GetName(), character_ids.size(), points, comment);
  849. SendGuildModification(points, &character_ids);
  850. member_save_needed = true;
  851. points_history_save_needed = true;
  852. }
  853. return true;
  854. }
  855. bool Guild::AddPointsToGroup(Client *client, float points, const char *comment, bool send_packet) {
  856. deque<GroupMemberInfo*>::iterator itr;
  857. deque<GroupMemberInfo*>* group_members;
  858. vector<int32> character_ids;
  859. GroupMemberInfo *gmi;
  860. GuildMember *gm;
  861. assert(client);
  862. if (!client->GetPlayer()->GetGroupMemberInfo()) {
  863. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Cannot assign points because you aren't in a group.");
  864. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s tried to assign points for group and failed: Not in a group", client->GetPlayer()->GetName());
  865. return false;
  866. }
  867. mMembers.readlock(__FUNCTION__, __LINE__);
  868. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  869. PlayerGroup* group = world.GetGroupManager()->GetGroup(client->GetPlayer()->GetGroupMemberInfo()->group_id);
  870. if (group)
  871. {
  872. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  873. deque<GroupMemberInfo*>* group_members = group->GetMembers();
  874. for (itr = group_members->begin(); itr != group_members->end(); itr++) {
  875. gmi = *itr;
  876. if (!gmi->client)
  877. continue;
  878. if (gmi->client->GetPlayer()->GetGuild() != this) {
  879. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not in guild to receive group points! Skipping...", gmi->client->GetPlayer()->GetCharacterID());
  880. continue;
  881. }
  882. if (!(gm = members[gmi->client->GetCharacterID()]) || !permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_RECEIVE_POINTS)) {
  883. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not allowed to receive points! Skipping...", gm->character_id);
  884. continue;
  885. }
  886. gm->points += points;
  887. character_ids.push_back(gm->character_id);
  888. AddPointHistory(gm, Timer::GetUnixTimeStamp(), client->GetPlayer()->GetName(), points, comment);
  889. gmi->client->Message(CHANNEL_GUILD_CHAT, "%s increased your guild member points by %.1f.", client->GetPlayer()->GetName(), points);
  890. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild: %s", GetName());
  891. LogWrite(GUILD__DEBUG, 0, "Guilds", "\tAwarded By: %s +%.1f pts to Player: %s", client->GetPlayer()->GetName(), points, gm->name);
  892. SendGuildMember(gm); //tmp
  893. }
  894. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  895. }
  896. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  897. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  898. client->Message(CHANNEL_GUILD_CHAT, "Points modified for %u guild members.", character_ids.size());
  899. if (send_packet) {
  900. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s modified points for %u members. Reason: %s", client->GetPlayer()->GetName(), character_ids.size(), points, comment);
  901. SendGuildModification(points, &character_ids);
  902. member_save_needed = true;
  903. points_history_save_needed = true;
  904. }
  905. return true;
  906. }
  907. bool Guild::AddPointsToRaid(Client *client, float points, const char *comment, bool send_packet) {
  908. assert(client);
  909. LogWrite(MISC__TODO, 1, "TODO", "Implement Raiding\n%s, %s, %i", __FILE__, __FUNCTION__, __LINE__);
  910. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Cannot assign points because you aren't in a raid.");
  911. return false;
  912. }
  913. bool Guild::AddPointsToGuildMember(Client *client, float points, const char *name, const char *comment, bool send_packet) {
  914. vector<int32> character_ids;
  915. GuildMember *gm;
  916. Client *client_to;
  917. assert(client);
  918. assert(name);
  919. if (!(gm = GetGuildMember(name)))
  920. return false;
  921. mMembers.readlock(__FUNCTION__, __LINE__);
  922. if (!permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_RECEIVE_POINTS)) {
  923. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  924. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not allowed to receive points! Skipping...", gm->character_id);
  925. client->Message(CHANNEL_GUILD_CHAT, "%s does not have permission to receive guild points.", gm->name);
  926. return false;
  927. }
  928. gm->points += points;
  929. character_ids.push_back(gm->character_id);
  930. if ((client_to = zone_list.GetClientByCharID(gm->character_id))) {
  931. client_to->Message(CHANNEL_GUILD_CHAT, "%s increased your guild member points by %.1f.", client->GetPlayer()->GetName(), points);
  932. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild: %s", GetName());
  933. LogWrite(GUILD__DEBUG, 0, "Guilds", "\tAwarded By: %s +%.1f pts to Player: %s", client->GetPlayer()->GetName(), points, gm->name);
  934. }
  935. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s modified points for 1 guild member. Reason: %s", client->GetPlayer()->GetName(), comment);
  936. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Points modified for 1 guild member.");
  937. AddPointHistory(gm, Timer::GetUnixTimeStamp(), client->GetPlayer()->GetName(), points, comment);
  938. if (send_packet) {
  939. SendGuildMember(gm); //tmp
  940. SendGuildModification(points, &character_ids);
  941. member_save_needed = true;
  942. points_history_save_needed = true;
  943. }
  944. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  945. return true;
  946. }
  947. bool Guild::AddPointHistory(GuildMember *guild_member, int32 date, const char *modified_by, float points, const char *comment, bool new_point_history) {
  948. PointHistory *ph, *ph_delete;
  949. deque<PointHistory *> *ph_list;
  950. assert(guild_member);
  951. assert(modified_by);
  952. ph = new PointHistory;
  953. ph->date = date;
  954. ph->modified_by = string(modified_by);
  955. ph->points = points;
  956. if (comment)
  957. ph->comment = string(comment);
  958. ph->saved_needed = new_point_history;
  959. mMembers.readlock(__FUNCTION__, __LINE__);
  960. ph_list = &guild_member->point_history;
  961. if (ph_list->size() == GUILD_MAX_POINT_HISTORY) {
  962. ph_delete = ph_list->back();
  963. database.DeleteGuildPointHistory(this, guild_member->character_id, ph_delete);
  964. safe_delete(ph_delete);
  965. ph_list->pop_back();
  966. }
  967. ph_list->push_front(ph);
  968. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  969. return true;
  970. }
  971. void Guild::ViewGuildMemberPoints(Client *client, const char * name) {
  972. deque<PointHistory *> *ph_list;
  973. deque<PointHistory *>::iterator itr;
  974. PointHistory *ph;
  975. GuildMember *gm;
  976. PacketStruct *packet;
  977. int32 i;
  978. assert(client);
  979. assert(name);
  980. if (!(gm = GetGuildMember(name)))
  981. return;
  982. if (!(packet = configReader.getStruct("WS_RequestGuildEventDetails", client->GetVersion())))
  983. return;
  984. mMembers.readlock(__FUNCTION__, __LINE__);
  985. ph_list = &gm->point_history;
  986. i = 0;
  987. packet->setDataByName("account_id", client->GetAccountID());
  988. packet->setDataByName("character_id", client->GetCharacterID());
  989. packet->setDataByName("guild_id", id);
  990. packet->setArrayLengthByName("num_events", ph_list->size());
  991. // this log entry may be excessive... test it out.
  992. LogWrite(GUILD__DEBUG, 0, "Guilds", "account_id: %i, character_id: %i, guild_id: %i, num_events: %i", client->GetAccountID(), client->GetCharacterID(), id, ph_list->size());
  993. for (itr = ph_list->begin(); itr != ph_list->end(); itr++) {
  994. ph = *itr;
  995. packet->setArrayDataByName("date", ph->date, i);
  996. packet->setArrayDataByName("modified_by", ph->modified_by.c_str(), i);
  997. packet->setArrayDataByName("comment", ph->comment.c_str(), i);
  998. packet->setArrayDataByName("points", ph->points, i);
  999. // this log entry may be excessive... test it out.
  1000. LogWrite(GUILD__DEBUG, 0, "Guilds", "date: %i, modified_by: %i, comment: %i, points: %.1f", ph->date, ph->modified_by.c_str(), ph->comment.c_str(), ph->points);
  1001. i++;
  1002. }
  1003. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1004. //DumpPacket(packet->serialize());
  1005. client->QueuePacket(packet->serialize());
  1006. safe_delete(packet);
  1007. }
  1008. bool Guild::ChangeMemberFlag(Client *client, int8 member_flag, int8 value, bool send_packet) {
  1009. GuildMember *gm;
  1010. bool ret = false;
  1011. assert (client);
  1012. if (!(gm = GetGuildMemberOnline(client)))
  1013. return false;
  1014. mMembers.readlock(__FUNCTION__, __LINE__);
  1015. switch (member_flag) {
  1016. case GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD: {
  1017. if (value > 0 && !(gm->member_flags & GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD)) {
  1018. gm->member_flags += GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD;
  1019. ret = true;
  1020. }
  1021. else if (value == 0 && gm->member_flags & GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD) {
  1022. gm->member_flags -= GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD;
  1023. ret = true;
  1024. }
  1025. break;
  1026. }
  1027. case GUILD_MEMBER_FLAGS_NOTIFY_LOGINS: {
  1028. if (value > 0 && !(gm->member_flags & GUILD_MEMBER_FLAGS_NOTIFY_LOGINS)) {
  1029. gm->member_flags += GUILD_MEMBER_FLAGS_NOTIFY_LOGINS;
  1030. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Guild online notifications are now enabled.");
  1031. ret = true;
  1032. }
  1033. else if (value == 0 && gm->member_flags & GUILD_MEMBER_FLAGS_NOTIFY_LOGINS) {
  1034. gm->member_flags -= GUILD_MEMBER_FLAGS_NOTIFY_LOGINS;
  1035. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Guild online notifications are now disabled.");
  1036. ret = true;
  1037. }
  1038. break;
  1039. }
  1040. case GUILD_MEMBER_FLAGS_DONT_GENERATE_EVENTS: {
  1041. if (value > 1 && !(gm->member_flags & GUILD_MEMBER_FLAGS_DONT_GENERATE_EVENTS)) {
  1042. gm->member_flags += GUILD_MEMBER_FLAGS_DONT_GENERATE_EVENTS;
  1043. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Guild events are now disabled for this character.");
  1044. ret = true;
  1045. }
  1046. else if (value == 0 && gm->member_flags & GUILD_MEMBER_FLAGS_DONT_GENERATE_EVENTS) {
  1047. gm->member_flags -= GUILD_MEMBER_FLAGS_DONT_GENERATE_EVENTS;
  1048. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Guild events are now enabled for this character.");
  1049. ret = true;
  1050. }
  1051. break;
  1052. }
  1053. default:
  1054. break;
  1055. }
  1056. if (ret && send_packet) {
  1057. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild Member Flag '%i' changed to %i", member_flag, value);
  1058. member_save_needed = true;
  1059. SendGuildMember(client, gm);
  1060. }
  1061. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1062. return ret;
  1063. }
  1064. bool Guild::UpdateGuildStatus(Player *player ,int32 Status) {
  1065. GuildMember *gm;
  1066. assert(player);
  1067. assert(members.count(player->GetCharacterID()) > 0);
  1068. mMembers.readlock(__FUNCTION__, __LINE__);
  1069. gm = members[player->GetCharacterID()];
  1070. gm->guild_status += Status;
  1071. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1072. member_save_needed = true;
  1073. return true;
  1074. }
  1075. bool Guild::UpdateGuildMemberInfo(Player *player) {
  1076. GuildMember *gm;
  1077. assert(player);
  1078. assert(members.count(player->GetCharacterID()) > 0);
  1079. LogWrite(GUILD__DEBUG, 0, "Guilds", "Updating Guild Member Info for Player: %i", player->GetCharacterID());
  1080. mMembers.readlock(__FUNCTION__, __LINE__);
  1081. gm = members[player->GetCharacterID()];
  1082. gm->adventure_class = player->GetAdventureClass();
  1083. gm->adventure_level = player->GetLevel();
  1084. gm->tradeskill_class = player->GetTradeskillClass();
  1085. gm->tradeskill_level = player->GetTSLevel();
  1086. gm->zone = string(player->GetZone()->GetZoneDescription());
  1087. gm->last_login_date = database.GetCharacterTimeStamp(player->GetCharacterID());
  1088. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1089. return true;
  1090. }
  1091. void Guild::AddGuildEvent(int64 event_id, int32 type, const char *description, int32 date, int8 locked) {
  1092. LogWrite(GUILD__DEBUG, 3, "Guilds", "Guild: %s", GetName());
  1093. LogWrite(GUILD__DEBUG, 3, "Guilds", "Add Guild Event: %lli, %i, %s", event_id, type, string(description).c_str());
  1094. GuildEvent *ge;
  1095. assert(description);
  1096. // assert(event_filters.Get(type)->Get(GUILD_EVENT_FILTER_CATEGORY_RETAIN_HISTORY));
  1097. assert(guild_events.size() < GUILD_MAX_EVENTS);
  1098. ge = new GuildEvent;
  1099. ge->event_id = event_id;
  1100. ge->type = type;
  1101. ge->description = string(description);
  1102. ge->date = date;
  1103. ge->locked = locked;
  1104. ge->save_needed = false;
  1105. guild_events.push_back(ge);
  1106. }
  1107. void Guild::AddNewGuildEvent(int32 type, const char *description, int32 date, bool send_packet, ...) {
  1108. deque<GuildEvent *>::reverse_iterator itr;
  1109. GuildEvent *ge, *current_ge;
  1110. char buffer[4096];
  1111. va_list argptr;
  1112. assert(description);
  1113. va_start(argptr, send_packet);
  1114. vsnprintf(buffer, sizeof(buffer), description, argptr);
  1115. va_end(argptr);
  1116. ge = new GuildEvent;
  1117. ge->event_id = GetNextEventID();
  1118. ge->type = type;
  1119. ge->description = string(buffer);
  1120. ge->date = date;
  1121. ge->locked = 0;
  1122. if (!event_filters.Get(type)->Get(GUILD_EVENT_FILTER_CATEGORY_RETAIN_HISTORY)) {
  1123. database.SaveHiddenGuildEvent(this, ge);
  1124. return;
  1125. }
  1126. if (guild_events.size() == GUILD_MAX_EVENTS) {
  1127. for (itr = guild_events.rbegin(); itr != guild_events.rend(); itr++) {
  1128. current_ge = *itr;
  1129. if (current_ge->locked == 0) {
  1130. database.ArchiveGuildEvent(this, current_ge);
  1131. safe_delete(current_ge);
  1132. guild_events.erase(--itr.base());
  1133. guild_events.push_front(ge);
  1134. break;
  1135. }
  1136. }
  1137. }
  1138. else
  1139. guild_events.push_front(ge);
  1140. if (send_packet) {
  1141. LogWrite(GUILD__DEBUG, 0, "Guilds", "Some Add New Guild Event thing happened, not sure what...");
  1142. SendNewGuildEvent(ge);
  1143. ge->save_needed = true;
  1144. events_save_needed = true;
  1145. }
  1146. }
  1147. bool Guild::LockGuildEvent(int64 event_id, bool lock, bool send_packet) {
  1148. bool ret = false;
  1149. GuildEvent* ge = GetGuildEvent(event_id);
  1150. if (ge) {
  1151. if (lock) {
  1152. ge->locked = 1;
  1153. if (send_packet)
  1154. SendGuildEventAction(GUILD_EVENT_ACTION_LOCK, ge);
  1155. }
  1156. else {
  1157. ge->locked = 0;
  1158. if (send_packet)
  1159. SendGuildEventAction(GUILD_EVENT_ACTION_UNLOCK, ge);
  1160. }
  1161. ret = true;
  1162. }
  1163. if (ret && send_packet) {
  1164. LogWrite(GUILD__DEBUG, 0, "Guilds", "Toggle guild event lock, EventID: %lli, value: %i", event_id, lock);
  1165. ge->save_needed = true;
  1166. events_save_needed = true;
  1167. }
  1168. return ret;
  1169. }
  1170. bool Guild::DeleteGuildEvent(int64 event_id, bool send_packet) {
  1171. bool ret = false;
  1172. deque<GuildEvent*>::iterator itr;
  1173. for (itr = guild_events.begin(); itr != guild_events.end(); itr++) {
  1174. GuildEvent* ge = *itr;
  1175. if (ge->event_id == event_id) {
  1176. if (send_packet)
  1177. SendGuildEventAction(GUILD_EVENT_ACTION_DELETE, ge);
  1178. database.DeleteGuildEvent(this, ge->event_id);
  1179. safe_delete(ge);
  1180. guild_events.erase(itr);
  1181. ret = true;
  1182. break;
  1183. }
  1184. }
  1185. LogWrite(GUILD__DEBUG, 0, "Guilds", "Delete guild event, EventID: %lli", event_id);
  1186. return ret;
  1187. }
  1188. int32 Guild::GetPermissionsPacketValue(int8 rank, int32 start, int32 end) {
  1189. int32 ret = 0;
  1190. for (int32 i = start; i <= end; i++) {
  1191. if (permissions.count(rank) > 0 && permissions.Get(rank)->count(i) > 0 && permissions.Get(rank)->Get(i)) {
  1192. if (i >= 0 && i <= 31)
  1193. ret += (int32)pow(2.0, (double)i);
  1194. else if (i >= 32 && i <= 63)
  1195. ret += (int32)pow(2.0, (double)(i - 32));
  1196. }
  1197. }
  1198. return ret;
  1199. }
  1200. int32 Guild::GetEventFilterPacketValue(int8 category, int32 start, int32 end) {
  1201. int32 ret = 0;
  1202. for (int32 i = start; i <= end; i++) {
  1203. if (event_filters.count(i) > 0 && event_filters.Get(i)->count(category) > 0 && event_filters.Get(i)->Get(category)) {
  1204. if (i >= 0 && i <= 31)
  1205. ret += (int32)pow(2.0, (double)i);
  1206. else if (i >= 32 && i <= 63)
  1207. ret += (int32)pow(2.0, (double)(i - 32));
  1208. else if (i >= 64 && i <= 95)
  1209. ret += (int32)pow(2.0, (double)(i - 64));
  1210. }
  1211. }
  1212. return ret;
  1213. }
  1214. int8 Guild::GetRecruitingLookingForPacketValue() {
  1215. int8 ret = 0;
  1216. MutexMap<int8, int8>::iterator itr = recruiting_flags.begin();
  1217. while (itr.Next()) {
  1218. if (itr.second)
  1219. ret += (int8)pow(2.0, (double)itr.first);
  1220. }
  1221. return ret;
  1222. }
  1223. void Guild::SendGuildMOTD(Client* client) {
  1224. if (client && strlen(motd) > 0)
  1225. client->Message(CHANNEL_GUILD_MOTD, "Guild MOTD: %s", motd);
  1226. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild MOTD.\n'%s'", motd);
  1227. }
  1228. void Guild::SendGuildEventList() {
  1229. map<int32, GuildMember*>::iterator itr;
  1230. Client *client;
  1231. mMembers.readlock(__FUNCTION__, __LINE__);
  1232. for (itr = members.begin(); itr != members.end(); itr++) {
  1233. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1234. SendGuildEventList(client);
  1235. }
  1236. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1237. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild Event List (%s).", __FUNCTION__);
  1238. }
  1239. void Guild::SendGuildEventList(Client* client) {
  1240. if (client) {
  1241. PacketStruct* packet = configReader.getStruct("WS_GuildEventList", client->GetVersion());
  1242. if (packet) {
  1243. packet->setDataByName("account_id", client->GetAccountID());
  1244. packet->setArrayLengthByName("num_events", guild_events.size());
  1245. deque<GuildEvent*>::iterator itr;
  1246. int32 i = 0;
  1247. for (itr = guild_events.begin(); itr != guild_events.end(); itr++) {
  1248. packet->setArrayDataByName("event_id", (*itr)->event_id, i);
  1249. packet->setArrayDataByName("locked", (*itr)->locked, i);
  1250. i++;
  1251. }
  1252. client->QueuePacket(packet->serialize());
  1253. //DumpPacket(packet->serialize());
  1254. safe_delete(packet);
  1255. }
  1256. }
  1257. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild Event List (%s).", __FUNCTION__);
  1258. }
  1259. void Guild::SendGuildEventDetails() {
  1260. map<int32, GuildMember*>::iterator itr;
  1261. Client *client;
  1262. mMembers.readlock(__FUNCTION__, __LINE__);
  1263. for (itr = members.begin(); itr != members.end(); itr++) {
  1264. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1265. SendGuildEventDetails(client);
  1266. }
  1267. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1268. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild Event Details (%s).", __FUNCTION__);
  1269. }
  1270. void Guild::SendGuildEventDetails(Client* client) {
  1271. if (client) {
  1272. PacketStruct* packet = configReader.getStruct("WS_GuildEventDetails", client->GetVersion());
  1273. if (packet) {
  1274. deque<GuildEvent*>::iterator itr;
  1275. int32 i = 0;
  1276. for (itr = guild_events.begin(); itr != guild_events.end(); itr++) {
  1277. packet->setArrayDataByName("event_id", (*itr)->event_id, i);
  1278. i++;
  1279. }
  1280. client->QueuePacket(packet->serialize());
  1281. safe_delete(packet);
  1282. }
  1283. }
  1284. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild Event Details (%s).", __FUNCTION__);
  1285. }
  1286. void Guild::SendAllGuildEvents() {
  1287. map<int32, GuildMember*>::iterator itr;
  1288. Client *client;
  1289. mMembers.readlock(__FUNCTION__, __LINE__);
  1290. for (itr = members.begin(); itr != members.end(); itr++) {
  1291. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1292. SendAllGuildEvents(client);
  1293. }
  1294. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1295. LogWrite(GUILD__DEBUG, 0, "Guilds", "Sent ALL guild Events (%s).", __FUNCTION__);
  1296. }
  1297. void Guild::SendAllGuildEvents(Client* client) {
  1298. if (client) {
  1299. deque<GuildEvent*>::iterator itr;
  1300. for (itr = guild_events.begin(); itr != guild_events.end(); itr++)
  1301. SendOldGuildEvent(client, *itr);
  1302. }
  1303. LogWrite(GUILD__DEBUG, 0, "Guilds", "Sent ALL guild Events (%s).", __FUNCTION__);
  1304. }
  1305. void Guild::SendOldGuildEvent(Client* client, GuildEvent* guild_event) {
  1306. if (client && guild_event) {
  1307. PacketStruct* packet = configReader.getStruct("WS_RequestGuildInfo", client->GetVersion());
  1308. if (packet) {
  1309. packet->setDataByName("account_id", client->GetAccountID());
  1310. packet->setDataByName("event_id", guild_event->event_id);
  1311. packet->setDataByName("date", guild_event->date);
  1312. packet->setDataByName("type", guild_event->type);
  1313. packet->setMediumStringByName("description", guild_event->description.c_str());
  1314. client->QueuePacket(packet->serialize());
  1315. safe_delete(packet);
  1316. }
  1317. }
  1318. LogWrite(GUILD__DEBUG, 3, "Guilds", "Sent OLD guild Events.");
  1319. }
  1320. void Guild::SendNewGuildEvent(GuildEvent* guild_event) {
  1321. map<int32, GuildMember *>::iterator itr;
  1322. Client *client;
  1323. assert (guild_event);
  1324. mMembers.readlock(__FUNCTION__, __LINE__);
  1325. for (itr = members.begin(); itr != members.end(); itr++) {
  1326. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1327. SendNewGuildEvent(client, guild_event);
  1328. }
  1329. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1330. LogWrite(GUILD__DEBUG, 0, "Guilds", "Sent NEW guild Events. (%s)", __FUNCTION__);
  1331. }
  1332. void Guild::SendNewGuildEvent(Client* client, GuildEvent* guild_event) {
  1333. if (client && guild_event) {
  1334. PacketStruct* packet = configReader.getStruct("WS_GuildEventAdd", client->GetVersion());
  1335. if (packet) {
  1336. packet->setDataByName("account_id", client->GetAccountID());
  1337. packet->setDataByName("event_id", guild_event->event_id);
  1338. packet->setDataByName("type", guild_event->type);
  1339. packet->setDataByName("date", guild_event->date);
  1340. packet->setDataByName("description", guild_event->description.c_str());
  1341. //DumpPacket(packet->serialize());
  1342. client->QueuePacket(packet->serialize());
  1343. safe_delete(packet);
  1344. }
  1345. }
  1346. LogWrite(GUILD__DEBUG, 0, "Guilds", "Sent NEW guild Events. (%s)", __FUNCTION__);
  1347. }
  1348. void Guild::SendGuildEventAction(int8 action, GuildEvent* guild_event) {
  1349. map<int32, GuildMember *>::iterator itr;
  1350. Client *client;
  1351. assert(guild_event);
  1352. mMembers.readlock(__FUNCTION__, __LINE__);
  1353. for (itr = members.begin(); itr != members.end(); itr++) {
  1354. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1355. SendGuildEventAction(client, action, guild_event);
  1356. }
  1357. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1358. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild events Action. (%s)", __FUNCTION__);
  1359. }
  1360. void Guild::SendGuildEventAction(Client* client, int8 action, GuildEvent* guild_event) {
  1361. if (guild_event) {
  1362. PacketStruct* packet = configReader.getStruct("WS_GuildEventAction", client->GetVersion());
  1363. if (packet) {
  1364. packet->setDataByName("account_id", client->GetAccountID());
  1365. packet->setDataByName("event_id", guild_event->event_id);
  1366. packet->setDataByName("action", action);
  1367. client->QueuePacket(packet->serialize());
  1368. safe_delete(packet);
  1369. }
  1370. }
  1371. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild events Action. (%s)", __FUNCTION__);
  1372. }
  1373. void Guild::SendGuildBankEventList() {
  1374. map<int32, GuildMember*>::iterator itr;
  1375. Client *client;
  1376. mMembers.readlock(__FUNCTION__, __LINE__);
  1377. for (itr = members.begin(); itr != members.end(); itr++) {
  1378. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1379. SendGuildBankEventList(client);
  1380. }
  1381. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1382. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild bank events list. (%s)", __FUNCTION__);
  1383. }
  1384. void Guild::SendGuildBankEventList(Client* client) {
  1385. if (client) {
  1386. for (int32 i = 0; i < 4; i++) {
  1387. PacketStruct* packet = configReader.getStruct("WS_GuildBankEventList", client->GetVersion());
  1388. if (packet) {
  1389. packet->setDataByName("account_id", client->GetAccountID());
  1390. packet->setDataByName("bank_number", i);
  1391. packet->setArrayLengthByName("num_events", banks[i].events.size());
  1392. deque<GuildBankEvent*>::iterator itr;
  1393. for (itr = banks[i].events.begin(); itr != banks[i].events.end(); itr++)
  1394. packet->setArrayDataByName("event_id", (*itr)->event_id, i);
  1395. //DumpPacket(packet->serialize());
  1396. client->QueuePacket(packet->serialize());
  1397. safe_delete(packet);
  1398. }
  1399. }
  1400. }
  1401. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild bank events list. (%s)", __FUNCTION__);
  1402. }
  1403. void Guild::SendGuildUpdate() {
  1404. map<int32, GuildMember*>::iterator itr;
  1405. Client *client;
  1406. LogWrite(GUILD__DEBUG, 1, "Guilds", "SendGuildUpdate to all guild member clients online... (%s)", __FUNCTION__);
  1407. mMembers.readlock(__FUNCTION__, __LINE__);
  1408. for (itr = members.begin(); itr != members.end(); itr++) {
  1409. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1410. SendGuildUpdate(client);
  1411. }
  1412. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1413. }
  1414. void Guild::SendGuildUpdate(Client* client) {
  1415. if (client) {
  1416. LogWrite(GUILD__DEBUG, 1, "Guilds", "SendGuildUpdate to client online... (%s)", __FUNCTION__);
  1417. PacketStruct* packet = configReader.getStruct("WS_GuildUpdate", client->GetVersion());
  1418. if (packet) {
  1419. packet->setMediumStringByName("guild_name", GetName());
  1420. packet->setMediumStringByName("guild_motd", motd);
  1421. packet->setDataByName("guild_id", id);
  1422. packet->setDataByName("guild_level", level);
  1423. packet->setDataByName("unknown", 1);
  1424. packet->setDataByName("formed_date", formed_date);
  1425. packet->setDataByName("unique_accounts", GetNumUniqueAccounts());
  1426. packet->setDataByName("num_members", members.size());
  1427. packet->setDataByName("exp_current", exp_current);
  1428. packet->setDataByName("exp_to_next_level", exp_to_next_level);
  1429. packet->setDataByName("event_filter_retain1", GetEventFilterPacketValue(GUILD_EVENT_FILTER_CATEGORY_RETAIN_HISTORY, 0, 31));
  1430. packet->setDataByName("event_filter_retain2", GetEventFilterPacketValue(GUILD_EVENT_FILTER_CATEGORY_RETAIN_HISTORY, 32, 63));
  1431. packet->setDataByName("event_filter_retain3", GetEventFilterPacketValue(GUILD_EVENT_FILTER_CATEGORY_RETAIN_HISTORY, 63, 92));
  1432. packet->setDataByName("event_filter_retain4", 0);
  1433. packet->setDataByName("event_filter_broadcast1", GetEventFilterPacketValue(GUILD_EVENT_FILTER_CATEGORY_BROADCAST, 0, 31));
  1434. packet->setDataByName("event_filter_broadcast2", GetEventFilterPacketValue(GUILD_EVENT_FILTER_CATEGORY_BROADCAST, 32, 63));
  1435. packet->setDataByName("event_filter_broadcast3", GetEventFilterPacketValue(GUILD_EVENT_FILTER_CATEGORY_BROADCAST, 64, 92));
  1436. packet->setDataByName("event_filter_broadcast4", 0);
  1437. packet->setDataByName("recruiting_looking_for", GetRecruitingLookingForPacketValue());
  1438. packet->setDataByName("recruiting_desc_tag1", GetRecruitingDescTag(0));
  1439. packet->setDataByName("recruiting_desc_tag2", GetRecruitingDescTag(1));
  1440. packet->setDataByName("recruiting_desc_tag3", GetRecruitingDescTag(2));
  1441. packet->setDataByName("recruiting_desc_tag4", GetRecruitingDescTag(3));
  1442. packet->setDataByName("recruiting_playstyle", recruiting_play_style);
  1443. packet->setDataByName("recruiting_min_level", recruiting_min_level);
  1444. packet->setMediumStringByName("recuiting_short_description", recruiting_short_desc.c_str());
  1445. packet->setMediumStringByName("recruiting_full_description", recruiting_full_desc.c_str());
  1446. packet->setMediumStringByName("rank0_name", ranks.Get(GUILD_RANK_LEADER).c_str());
  1447. packet->setDataByName("rank0_permissions1", GetPermissionsPacketValue(GUILD_RANK_LEADER, 0, 31));
  1448. packet->setDataByName("rank0_permissions2", GetPermissionsPacketValue(GUILD_RANK_LEADER, 32, 44));
  1449. packet->setDataByName("rank0_permissions_unused", 0);
  1450. packet->setMediumStringByName("rank1_name", ranks.Get(GUILD_RANK_SENIOR_OFFICER).c_str());
  1451. packet->setDataByName("rank1_permissions1", GetPermissionsPacketValue(GUILD_RANK_SENIOR_OFFICER, 0, 31));
  1452. packet->setDataByName("rank1_permissions2", GetPermissionsPacketValue(GUILD_RANK_SENIOR_OFFICER, 32, 44));
  1453. packet->setDataByName("rank1_permissions_unused", 0);
  1454. packet->setMediumStringByName("rank2_name", ranks.Get(GUILD_RANK_OFFICER).c_str());
  1455. packet->setDataByName("rank2_permissions1", GetPermissionsPacketValue(GUILD_RANK_OFFICER, 0, 31));
  1456. packet->setDataByName("rank2_permissions2", GetPermissionsPacketValue(GUILD_RANK_OFFICER, 32, 44));
  1457. packet->setDataByName("rank2_permissions_unused", 0);
  1458. packet->setMediumStringByName("rank3_name", ranks.Get(GUILD_RANK_SENIOR_MEMBER).c_str());
  1459. packet->setDataByName("rank3_permissions1", GetPermissionsPacketValue(GUILD_RANK_SENIOR_MEMBER, 0, 31));
  1460. packet->setDataByName("rank3_permissions2", GetPermissionsPacketValue(GUILD_RANK_SENIOR_MEMBER, 32, 44));
  1461. packet->setDataByName("rank3_permissions_unused", 0);
  1462. packet->setMediumStringByName("rank4_name", ranks.Get(GUILD_RANK_MEMBER).c_str());
  1463. packet->setDataByName("rank4_permissions1", GetPermissionsPacketValue(GUILD_RANK_MEMBER, 0, 31));
  1464. packet->setDataByName("rank4_permissions2", GetPermissionsPacketValue(GUILD_RANK_MEMBER, 32, 44));
  1465. packet->setDataByName("rank4_permissions_unused", 0);
  1466. packet->setMediumStringByName("rank5_name", ranks.Get(GUILD_RANK_JUNIOR_MEMBER).c_str());
  1467. packet->setDataByName("rank5_permissions1", GetPermissionsPacketValue(GUILD_RANK_JUNIOR_MEMBER, 0, 31));
  1468. packet->setDataByName("rank5_permissions2", GetPermissionsPacketValue(GUILD_RANK_JUNIOR_MEMBER, 32, 44));
  1469. packet->setDataByName("rank5_permissions_unused", 0);
  1470. packet->setMediumStringByName("rank6_name", ranks.Get(GUILD_RANK_INITIATE).c_str());
  1471. packet->setDataByName("rank6_permissions1", GetPermissionsPacketValue(GUILD_RANK_INITIATE, 0, 31));
  1472. packet->setDataByName("rank6_permissions2", GetPermissionsPacketValue(GUILD_RANK_INITIATE, 32, 44));
  1473. packet->setDataByName("rank6_permissions_unused", 0);
  1474. packet->setMediumStringByName("rank7_name", ranks.Get(GUILD_RANK_RECRUIT).c_str());
  1475. packet->setDataByName("rank7_permissions1", GetPermissionsPacketValue(GUILD_RANK_RECRUIT, 0, 31));
  1476. packet->setDataByName("rank7_permissions2", GetPermissionsPacketValue(GUILD_RANK_RECRUIT, 32, 44));
  1477. packet->setDataByName("rank7_permissions_unused", 0);
  1478. packet->setMediumStringByName("bank1_name", banks[0].name.c_str());
  1479. packet->setMediumStringByName("bank2_name", banks[1].name.c_str());
  1480. packet->setMediumStringByName("bank3_name", banks[2].name.c_str());
  1481. packet->setMediumStringByName("bank4_name", banks[3].name.c_str());
  1482. //DumpPacket(packet->serialize());
  1483. client->QueuePacket(packet->serialize());
  1484. safe_delete(packet);
  1485. }
  1486. }
  1487. }
  1488. void Guild::SendGuildMemberList() {
  1489. map<int32, GuildMember*>::iterator itr;
  1490. Client *client;
  1491. mMembers.readlock(__FUNCTION__, __LINE__);
  1492. for (itr = members.begin(); itr != members.end(); itr++) {
  1493. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1494. SendGuildMemberList(client);
  1495. }
  1496. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1497. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild member list to all clients.");
  1498. }
  1499. void Guild::SendGuildMemberList(Client* client) {
  1500. map<int32, GuildMember *>::iterator itr;
  1501. GuildMember *gm;
  1502. if (client) {
  1503. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild member list to a client.");
  1504. PacketStruct* packet = configReader.getStruct("WS_GuildMembershipResponse", client->GetVersion());
  1505. if (packet) {
  1506. packet->setDataByName("guild_id", id);
  1507. packet->setDataByName("character_id_to", client->GetCharacterID());
  1508. mMembers.readlock(__FUNCTION__, __LINE__);
  1509. packet->setArrayLengthByName("num_members", members.size());
  1510. int32 i = 0;
  1511. for (itr = members.begin(); itr != members.end(); itr++) {
  1512. gm = itr->second;
  1513. packet->setArrayDataByName("account_id", gm->account_id, i);
  1514. packet->setArrayDataByName("character_id", gm->character_id, i);
  1515. packet->setArrayDataByName("name", gm->name, i);
  1516. packet->setArrayDataByName("unknown2", 0, i);
  1517. packet->setArrayDataByName("unknown3", 1, i);
  1518. packet->setArrayDataByName("adventure_class", gm->adventure_class, i);
  1519. packet->setArrayDataByName("adventure_level", gm->adventure_level, i);
  1520. packet->setArrayDataByName("tradeskill_class", gm->tradeskill_class, i);
  1521. packet->setArrayDataByName("tradeskill_level", gm->tradeskill_level, i);
  1522. packet->setArrayDataByName("rank", gm->rank, i);
  1523. packet->setArrayDataByName("member_flags", gm->member_flags, i);
  1524. packet->setArrayDataByName("join_date", gm->join_date, i);
  1525. packet->setArrayDataByName("guild_status", gm->guild_status, i);
  1526. packet->setArrayDataByName("last_login", gm->last_login_date, i);
  1527. packet->setArrayDataByName("recruiter_id", gm->recruiter_id, i);
  1528. packet->setArrayDataByName("points", gm->points, i);
  1529. if (zone_list.GetClientByCharID(gm->character_id))
  1530. packet->setArrayDataByName("zone", gm->zone.c_str(), i);
  1531. packet->setArrayDataByName("note", gm->note.c_str(), i);
  1532. packet->setArrayDataByName("officer_note", gm->officer_note.c_str(), i);
  1533. i++;
  1534. }
  1535. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1536. //DumpPacket(packet->serialize());
  1537. //packet->PrintPacket();
  1538. EQ2Packet* pack = packet->serialize();
  1539. //DumpPacket(pack);
  1540. client->QueuePacket(pack);
  1541. safe_delete(packet);
  1542. }
  1543. }
  1544. }
  1545. void Guild::SendGuildMember(Player* player, bool include_zone) {
  1546. map<int32, GuildMember *>::iterator itr;
  1547. Client *client;
  1548. GuildMember *gm;
  1549. assert(player);
  1550. mMembers.readlock(__FUNCTION__, __LINE__);
  1551. if (members.count(player->GetCharacterID()) > 0) {
  1552. gm = members[player->GetCharacterID()];
  1553. for (itr = members.begin(); itr != members.end(); itr++) {
  1554. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1555. SendGuildMember(client, gm, include_zone);
  1556. }
  1557. }
  1558. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1559. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild member.");
  1560. }
  1561. void Guild::SendGuildMember(GuildMember* gm, bool include_zone) {
  1562. map<int32, GuildMember *>::iterator itr;
  1563. Client *client;
  1564. assert(gm);
  1565. mMembers.readlock(__FUNCTION__, __LINE__);
  1566. for (itr = members.begin(); itr != members.end(); itr++) {
  1567. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1568. SendGuildMember(client, gm, include_zone);
  1569. }
  1570. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1571. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild member.");
  1572. }
  1573. void Guild::SendGuildMember(Client* client, GuildMember* gm, bool include_zone) {
  1574. if (client && gm) {
  1575. PacketStruct* packet = configReader.getStruct("WS_JoinGuildNotify", client->GetVersion());
  1576. if (packet) {
  1577. packet->setDataByName("guild_id", id);
  1578. packet->setDataByName("character_id", gm->character_id);
  1579. packet->setDataByName("account_id", gm->account_id);
  1580. packet->setMediumStringByName("name", gm->name);
  1581. packet->setDataByName("unknown2", 0);
  1582. packet->setDataByName("unknown3", 1);
  1583. packet->setDataByName("adventure_class", gm->adventure_class);
  1584. packet->setDataByName("adventure_level", gm->adventure_level);
  1585. packet->setDataByName("tradeskill_class", gm->tradeskill_class);
  1586. packet->setDataByName("tradeskill_level", gm->tradeskill_level);
  1587. packet->setDataByName("rank", gm->rank);
  1588. packet->setDataByName("member_flags", gm->member_flags);
  1589. packet->setDataByName("join_date", gm->join_date);
  1590. packet->setDataByName("guild_status", gm->guild_status);
  1591. packet->setDataByName("last_login", gm->last_login_date);
  1592. packet->setDataByName("recruiter_id", gm->recruiter_id);
  1593. packet->setDataByName("points", gm->points);
  1594. packet->setMediumStringByName("note", gm->note.c_str());
  1595. packet->setMediumStringByName("officer_note", gm->officer_note.c_str());
  1596. if (include_zone && zone_list.GetClientByCharID(gm->character_id)) {
  1597. packet->setMediumStringByName("zone", gm->zone.c_str());
  1598. //DumpPacket(packet->serialize());
  1599. }
  1600. client->QueuePacket(packet->serialize());
  1601. safe_delete(packet);
  1602. }
  1603. }
  1604. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild member to a client.");
  1605. }
  1606. void Guild::SendGuildModification(float points, vector<int32>* character_ids) {
  1607. map<int32, GuildMember *>::iterator itr;
  1608. Client *client;
  1609. if (character_ids) {
  1610. mMembers.readlock(__FUNCTION__, __LINE__);
  1611. for (itr = members.begin(); itr != members.end(); itr++) {
  1612. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1613. SendGuildModification(client, points, character_ids);
  1614. }
  1615. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1616. }
  1617. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild modification to all clients.");
  1618. }
  1619. void Guild::SendGuildModification(Client* client, float points, vector<int32>* character_ids) {
  1620. if (client && character_ids) {
  1621. PacketStruct* packet = configReader.getStruct("WS_ModifyGuild", client->GetVersion());
  1622. if (packet) {
  1623. packet->setDataByName("guild_id", id);
  1624. packet->setDataByName("unknown2", 0xFFFFFFFF);
  1625. packet->setDataByName("points", points);
  1626. packet->setArrayLengthByName("num_character_ids", character_ids->size());
  1627. for (int32 i = 0; i < character_ids->size(); i++)
  1628. packet->setArrayDataByName("character_id", character_ids->at(i), i);
  1629. client->QueuePacket(packet->serialize());
  1630. safe_delete(packet);
  1631. }
  1632. }
  1633. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild modification to a client.");
  1634. }
  1635. void Guild::GuildMemberLogin(Client *client, bool first_login) {
  1636. map<int32, GuildMember*>::iterator itr;
  1637. Client *client_to;
  1638. char buf[128];
  1639. assert(client);
  1640. UpdateGuildMemberInfo(client->GetPlayer());
  1641. if (first_login)
  1642. SendGuildMOTD(client);
  1643. SendGuildUpdate(client);
  1644. if (first_login)
  1645. SendGuildMember(client->GetPlayer(), false);
  1646. SendGuildRecruiterInfo(client, client->GetPlayer());
  1647. SendGuildEventList(client);
  1648. SendGuildBankEventList(client);
  1649. SendGuildMember(client->GetPlayer());
  1650. SendGuildEventDetails(client);
  1651. uchar blah5[] = {/*0xFF,0x09,0x01,*/0x01,0x00,0x00,0x00,0x00,0x00,0x00};
  1652. uchar blah6[] = {/*0xFF,0x09,0x01,*/0x01,0x00,0x00,0x00,0x01,0x00,0x00};
  1653. uchar blah7[] = {/*0xFF,0x09,0x01,*/0x01,0x00,0x00,0x00,0x02,0x00,0x00};
  1654. uchar blah8[] = {/*0xFF,0x09,0x01,*/0x01,0x00,0x00,0x00,0x03,0x00,0x00};
  1655. //DumpPacket(blah5, sizeof(blah5));
  1656. //DumpPacket(blah6, sizeof(blah6));
  1657. //DumpPacket(blah7, sizeof(blah7));
  1658. //DumpPacket(blah8, sizeof(blah8));
  1659. client->QueuePacket(new EQ2Packet(OP_RequestGuildBankEventDetailsMs, blah5, sizeof(blah5)));
  1660. client->QueuePacket(new EQ2Packet(OP_RequestGuildBankEventDetailsMs, blah6, sizeof(blah6)));
  1661. client->QueuePacket(new EQ2Packet(OP_RequestGuildBankEventDetailsMs, blah7, sizeof(blah7)));
  1662. client->QueuePacket(new EQ2Packet(OP_RequestGuildBankEventDetailsMs, blah8, sizeof(blah8)));
  1663. if (first_login)
  1664. SendAllGuildEvents(client);
  1665. SendGuildMemberList(client);
  1666. if (first_login) {
  1667. snprintf(buf, sizeof(buf), "Guildmate: %s has logged in", client->GetPlayer()->GetName());
  1668. mMembers.readlock(__FUNCTION__, __LINE__);
  1669. for (itr = members.begin(); itr != members.end(); itr++) {
  1670. if ((client_to = zone_list.GetClientByCharID(itr->second->character_id)))
  1671. client_to->SimpleMessage(CHANNEL_GUILD_MEMBER_ONLINE, buf);
  1672. }
  1673. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1674. }
  1675. if (first_login){
  1676. uchar blah1[] = {/*0xFF,0x09,0x01,*/0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  1677. uchar blah2[] = {/*0xFF,0x09,0x01,*/0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00};
  1678. uchar blah3[] = {/*0xFF,0x09,0x01,*/0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00};
  1679. uchar blah4[] = {/*0xFF,0x09,0x01,*/0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00};
  1680. //DumpPacket(blah1, sizeof(blah1));
  1681. //DumpPacket(blah2, sizeof(blah2));
  1682. //DumpPacket(blah3, sizeof(blah3));
  1683. //DumpPacket(blah4, sizeof(blah4));
  1684. client->QueuePacket(new EQ2Packet(OP_GuildBankUpdateMsg, blah1, sizeof(blah1)));
  1685. client->QueuePacket(new EQ2Packet(OP_GuildBankUpdateMsg, blah2, sizeof(blah2)));
  1686. client->QueuePacket(new EQ2Packet(OP_GuildBankUpdateMsg, blah3, sizeof(blah3)));
  1687. client->QueuePacket(new EQ2Packet(OP_GuildBankUpdateMsg, blah4, sizeof(blah4)));
  1688. }
  1689. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild Member logged in.");
  1690. }
  1691. void Guild::GuildMemberLogoff(Player *player) {
  1692. map<int32, GuildMember*>::iterator itr;
  1693. GuildMember *gm;
  1694. Client *client;
  1695. char buf[128];
  1696. assert(player);
  1697. mMembers.readlock(__FUNCTION__, __LINE__);
  1698. if ((gm = GetGuildMember(player))) {
  1699. snprintf(buf, sizeof(buf), "Guildmate: %s has logged out", player->GetName());
  1700. gm->zone.clear();
  1701. for (itr = members.begin(); itr != members.end(); itr++) {
  1702. if ((client = zone_list.GetClientByCharID(itr->second->character_id))) {
  1703. SendGuildMember(client, gm, false);
  1704. client->SimpleMessage(CHANNEL_GUILD_MEMBER_ONLINE, buf);
  1705. }
  1706. }
  1707. }
  1708. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1709. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild Member logged out.");
  1710. }
  1711. void Guild::SendGuildMemberLeave(int32 character_id) {
  1712. map<int32, GuildMember*>::iterator itr;
  1713. Client *client;
  1714. mMembers.readlock(__FUNCTION__, __LINE__);
  1715. for (itr = members.begin(); itr != members.end(); itr++) {
  1716. if ((client = zone_list.GetClientByCharID(itr->second->character_id)))
  1717. SendGuildMemberLeave(client, character_id);
  1718. }
  1719. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1720. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild member left the guild to all clients.");
  1721. }
  1722. void Guild::SendGuildMemberLeave(Client* client, int32 character_id) {
  1723. PacketStruct* packet = configReader.getStruct("WS_LeaveGuildNotify", client->GetVersion());
  1724. if (packet) {
  1725. packet->setDataByName("guild_id", id);
  1726. packet->setDataByName("character_id", character_id);
  1727. client->QueuePacket(packet->serialize());
  1728. safe_delete(packet);
  1729. }
  1730. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild member left the guild to a client.");
  1731. }
  1732. void Guild::SendGuildRecruitingDetails(Client* client) {
  1733. if (client) {
  1734. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild recruiting details to a client.");
  1735. PacketStruct* packet = configReader.getStruct("WS_GuildRecruitingDetails", client->GetVersion());
  1736. if (packet) {
  1737. vector<GuildMember*>* recruiters = GetGuildRecruiters();
  1738. vector<GuildMember*>::iterator itr;
  1739. packet->setDataByName("guild_id", id);
  1740. packet->setDataByName("recruiting_full_description", recruiting_full_desc.c_str());
  1741. if (recruiters) {
  1742. int32 i = 0;
  1743. packet->setArrayLengthByName("num_recruiters", recruiters->size());
  1744. for (itr = recruiters->begin(); itr != recruiters->end(); itr++) {
  1745. GuildMember* gm = *itr;
  1746. packet->setArrayDataByName("adventure_class", gm->adventure_class, i);
  1747. packet->setArrayDataByName("adventure_level", gm->adventure_level, i);
  1748. packet->setArrayDataByName("tradeskill_class", gm->tradeskill_class, i);
  1749. packet->setArrayDataByName("tradeskill_level", gm->tradeskill_level, i);
  1750. packet->setArrayDataByName("show_adventure_class", gm->recruiting_show_adventure_class, i);
  1751. packet->setArrayDataByName("unknown2", 4, i);
  1752. packet->setArrayDataByName("unknown3", 2, i);
  1753. packet->setSubArrayLengthByName("num_bytes", gm->recruiter_picture_data_size, i);
  1754. if (gm->recruiter_picture_data_size > 0) {
  1755. for (int16 j = 0; j < gm->recruiter_picture_data_size; j++)
  1756. packet->setSubArrayDataByName("picture_byte", gm->recruiter_picture_data[j], i, j);
  1757. }
  1758. packet->setArrayDataByName("char_name", gm->name, i);
  1759. packet->setArrayDataByName("recruiter_description", gm->recruiter_description.c_str(), i);
  1760. i++;
  1761. }
  1762. safe_delete(recruiters);
  1763. }
  1764. //DumpPacket(packet->serialize());
  1765. client->QueuePacket(packet->serialize());
  1766. safe_delete(packet);
  1767. }
  1768. }
  1769. }
  1770. void Guild::SendGuildRecruitingImages(Client* client) {
  1771. if (client) {
  1772. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild recruiting images to a client.");
  1773. PacketStruct* packet = configReader.getStruct("WS_GuildRecruitingImage", client->GetVersion());
  1774. if (packet) {
  1775. vector<GuildMember*>* recruiters = GetGuildRecruiters();
  1776. packet->setDataByName("guild_id", id);
  1777. if (recruiters && recruiters->size() > 0) {
  1778. GuildMember* gm = recruiters->at(0);
  1779. packet->setArrayLengthByName("num_bytes", gm->recruiter_picture_data_size);
  1780. if (gm->recruiter_picture_data_size > 0) {
  1781. for (int16 i = 0; i < gm->recruiter_picture_data_size; i++)
  1782. packet->setArrayDataByName("picture_byte", gm->recruiter_picture_data[i], i);
  1783. }
  1784. safe_delete(recruiters);
  1785. }
  1786. client->QueuePacket(packet->serialize());
  1787. safe_delete(packet);
  1788. }
  1789. }
  1790. }
  1791. void Guild::SendGuildRecruiterInfo(Client* client, Player* player) {
  1792. if (client && player) {
  1793. LogWrite(GUILD__DEBUG, 1, "Guilds", "Sent guild recruiter info to a client.");
  1794. GuildMember* gm = GetGuildMember(player);
  1795. if (gm) {
  1796. PacketStruct* packet = configReader.getStruct("WS_GuildRecruitingMemberInfo", client->GetVersion());
  1797. if (packet) {
  1798. packet->setDataByName("character_id", gm->character_id);
  1799. packet->setDataByName("unknown", 1);
  1800. packet->setDataByName("adventure_class", gm->adventure_class);
  1801. packet->setDataByName("adventure_level", gm->adventure_level);
  1802. packet->setDataByName("tradeskill_class", gm->tradeskill_class);
  1803. packet->setDataByName("tradeskill_level", gm->tradeskill_level);
  1804. packet->setDataByName("show_adventure_class", gm->recruiting_show_adventure_class);
  1805. packet->setDataByName("unknown3", 0);
  1806. // hack!
  1807. gm->recruiter_picture_data_size = 0;
  1808. packet->setArrayLengthByName("num_bytes", gm->recruiter_picture_data_size);
  1809. if (gm->recruiter_picture_data_size > 0) {
  1810. for (int16 i = 0; i < gm->recruiter_picture_data_size; i++)
  1811. packet->setArrayDataByName("picture_byte", gm->recruiter_picture_data[i], i);
  1812. }
  1813. packet->setMediumStringByName("recruiter_name", gm->name);
  1814. packet->setMediumStringByName("recruiter_description", gm->recruiter_description.c_str());
  1815. //DumpPacket(packet->serialize());
  1816. client->QueuePacket(packet->serialize());
  1817. safe_delete(packet);
  1818. }
  1819. }
  1820. }
  1821. }
  1822. bool Guild::HandleGuildSay(Client* sender, const char* message) {
  1823. map<int32, GuildMember *>::iterator itr;
  1824. GuildMember *gm;
  1825. Client *client;
  1826. assert(sender);
  1827. assert(message);
  1828. if (!(gm = GetGuildMemberOnline(sender)))
  1829. return false;
  1830. if (!permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_SPEAK_IN_GUILD_CHAT)) {
  1831. sender->SimpleMessage(CHANNEL_NARRATIVE, "You do not have permission to speak in guild chat.");
  1832. return false;
  1833. }
  1834. mMembers.readlock(__FUNCTION__, __LINE__);
  1835. for (itr = members.begin(); itr != members.end(); itr++) {
  1836. if (!(client = zone_list.GetClientByCharID(itr->second->character_id)))
  1837. continue;
  1838. if (permissions.Get(itr->second->rank)->Get(GUILD_PERMISSIONS_SEE_GUILD_CHAT))
  1839. client->GetCurrentZone()->HandleChatMessage(client, sender->GetPlayer(), client->GetPlayer()->GetName(), CHANNEL_GUILD_SAY, message, 0, 0, false, sender->GetPlayer()->GetCurrentLanguage());
  1840. }
  1841. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1842. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild Say");
  1843. return true;
  1844. }
  1845. void Guild::HandleGuildSay(std::string senderName, const char* message, int8 language) {
  1846. map<int32, GuildMember *>::iterator itr;
  1847. GuildMember *gm;
  1848. assert(message);
  1849. Client* client = 0;
  1850. mMembers.readlock(__FUNCTION__, __LINE__);
  1851. for (itr = members.begin(); itr != members.end(); itr++) {
  1852. if (!(client = zone_list.GetClientByCharID(itr->second->character_id)))
  1853. continue;
  1854. if (permissions.Get(itr->second->rank)->Get(GUILD_PERMISSIONS_SEE_GUILD_CHAT))
  1855. client->GetCurrentZone()->HandleChatMessage(senderName, client->GetPlayer()->GetName(), CHANNEL_GUILD_SAY, message, 0, 0, language);
  1856. }
  1857. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1858. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild Say");
  1859. }
  1860. bool Guild::HandleOfficerSay(Client* sender, const char* message) {
  1861. map<int32, GuildMember *>::iterator itr;
  1862. GuildMember *gm;
  1863. Client *client;
  1864. assert(sender);
  1865. assert(message);
  1866. if (!(gm = GetGuildMemberOnline(sender)))
  1867. return false;
  1868. if (!permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_SPEAK_IN_OFFICER_CHAT)) {
  1869. sender->SimpleMessage(CHANNEL_NARRATIVE, "You do not have permission to speak in officer chat.");
  1870. return false;
  1871. }
  1872. mMembers.readlock(__FUNCTION__, __LINE__);
  1873. for (itr = members.begin(); itr != members.end(); itr++) {
  1874. if (!(client = zone_list.GetClientByCharID(itr->second->character_id)))
  1875. continue;
  1876. if (permissions.Get(itr->second->rank)->Get(GUILD_PERMISSIONS_SEE_OFFICER_CHAT))
  1877. client->GetCurrentZone()->HandleChatMessage(client, sender->GetPlayer(), client->GetPlayer()->GetName(), CHANNEL_OFFICER_SAY, message, 0, 0, false, sender->GetPlayer()->GetCurrentLanguage());
  1878. }
  1879. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1880. LogWrite(GUILD__DEBUG, 0, "Guilds", "Officer Say");
  1881. return true;
  1882. }
  1883. void Guild::HandleOfficerSay(std::string senderName, const char* message, int8 language) {
  1884. map<int32, GuildMember *>::iterator itr;
  1885. Client *client;
  1886. mMembers.readlock(__FUNCTION__, __LINE__);
  1887. for (itr = members.begin(); itr != members.end(); itr++) {
  1888. if (!(client = zone_list.GetClientByCharID(itr->second->character_id)))
  1889. continue;
  1890. if (permissions.Get(itr->second->rank)->Get(GUILD_PERMISSIONS_SEE_OFFICER_CHAT))
  1891. client->GetCurrentZone()->HandleChatMessage(senderName, client->GetPlayer()->GetName(), CHANNEL_OFFICER_SAY, message, 0, 0, language);
  1892. }
  1893. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1894. LogWrite(GUILD__DEBUG, 0, "Guilds", "Officer Say");
  1895. }
  1896. void Guild::SendMessageToGuild(int8 event_type, const char* message, ...) {
  1897. map<int32, GuildMember *>::iterator itr;
  1898. Client *client;
  1899. va_list argptr;
  1900. char buffer[4096];
  1901. va_start(argptr, message);
  1902. vsnprintf(buffer, sizeof(buffer), message, argptr);
  1903. va_end(argptr);
  1904. mMembers.readlock(__FUNCTION__, __LINE__);
  1905. for (itr = members.begin(); itr != members.end(); itr++) {
  1906. if (!(client = zone_list.GetClientByCharID(itr->second->character_id)))
  1907. continue;
  1908. if (event_filters.Get(itr->second->rank)->Get(GUILD_EVENT_FILTER_CATEGORY_BROADCAST))
  1909. client->SimpleMessage(CHANNEL_GUILD_EVENT, buffer);
  1910. }
  1911. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1912. LogWrite(GUILD__DEBUG, 0, "Guilds", "Sent message to entire guild.");
  1913. }
  1914. void Guild::SendGuildChatMessage(const char* message, ...) {
  1915. map<int32, GuildMember *>::iterator itr;
  1916. Client *client;
  1917. va_list argptr;
  1918. char buffer[4096];
  1919. va_start(argptr, message);
  1920. vsnprintf(buffer, sizeof(buffer), message, argptr);
  1921. va_end(argptr);
  1922. mMembers.readlock(__FUNCTION__, __LINE__);
  1923. for (itr = members.begin(); itr != members.end(); itr++) {
  1924. if (!(client = zone_list.GetClientByCharID(itr->second->character_id)))
  1925. continue;
  1926. if (event_filters.Get(itr->second->rank)->Get(GUILD_EVENT_FILTER_CATEGORY_BROADCAST))
  1927. client->SimpleMessage(CHANNEL_GUILD_CHAT, buffer);
  1928. }
  1929. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  1930. LogWrite(GUILD__DEBUG, 0, "Guilds", "Sent message to entire guild.");
  1931. }
  1932. string Guild::GetEpicMobDeathMessage(const char* player_name, const char* mob_name) {
  1933. char message[256];
  1934. int8 choice;
  1935. assert(player_name);
  1936. assert(mob_name);
  1937. choice = (rand() % 5) + 1;
  1938. if (choice == 1)
  1939. snprintf(message, sizeof(message), "%s was slain by %s in a thunderous engagement!", mob_name, player_name);
  1940. else if (choice == 2)
  1941. snprintf(message, sizeof(message), "%s was slain by %s in a titanic struggle!", mob_name, player_name);
  1942. else if (choice == 3)
  1943. snprintf(message, sizeof(message), "%s was slain by %s's heroic might!", mob_name, player_name);
  1944. else if (choice == 4)
  1945. snprintf(message, sizeof(message), "%s slew %s in an earth shaking battle!", player_name, mob_name);
  1946. else
  1947. snprintf(message, sizeof(message), "%s slew %s in a heroic clash!", player_name, mob_name);
  1948. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild Epic Mob Death message sent.");
  1949. return string(message);
  1950. }
  1951. /***************************************************************************************************************************************************************
  1952. * GUILDLIST
  1953. ***************************************************************************************************************************************************************/
  1954. GuildList::GuildList() {
  1955. }
  1956. GuildList::~GuildList() {
  1957. MutexMap<int32, Guild*>::iterator itr = guild_list.begin();
  1958. while (itr.Next())
  1959. safe_delete(itr.second);
  1960. }
  1961. bool GuildList::AddGuild(Guild* guild) {
  1962. bool ret = false;
  1963. if (guild && guild_list.count(guild->GetID()) == 0) {
  1964. guild_list.Put(guild->GetID(), guild);
  1965. ret = true;
  1966. }
  1967. return ret;
  1968. }
  1969. Guild* GuildList::GetGuild(int32 guild_id) {
  1970. Guild* ret = 0;
  1971. if (guild_list.count(guild_id) > 0)
  1972. ret = guild_list.Get(guild_id);
  1973. return ret;
  1974. }
  1975. Guild* GuildList::GetGuild(const char* guild_name) {
  1976. Guild* ret = 0;
  1977. MutexMap<int32, Guild*>::iterator itr = guild_list.begin();
  1978. while (itr.Next()) {
  1979. if (strncasecmp(itr.second->GetName(), guild_name, strlen(guild_name)) == 0) {
  1980. ret = itr.second;
  1981. break;
  1982. }
  1983. }
  1984. return ret;
  1985. }
  1986. bool GuildList::RemoveGuild(Guild* guild, bool delete_data) {
  1987. bool ret = false;
  1988. if (guild && guild_list.count(guild->GetID()) > 0) {
  1989. guild_list.erase(guild->GetID(), false, delete_data);
  1990. ret = true;
  1991. }
  1992. return ret;
  1993. }
  1994. bool GuildList::RemoveGuild(int32 guild_id, bool delete_data) {
  1995. bool ret = false;
  1996. if (guild_list.count(guild_id) > 0) {
  1997. guild_list.erase(guild_id, false, delete_data);
  1998. ret = true;
  1999. }
  2000. return ret;
  2001. }