Guild.cpp 80 KB

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