9
3

Guild.cpp 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  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(GUILD__DEBUG, 0, "Guilds", "Guild %s Level UP! New Level: %i (current XP: %ul)", name, level, exp_current);
  134. int64 left_over = exp_current - exp_to_next_level;
  135. level++;
  136. exp_to_next_level *= 2;
  137. exp_current = left_over;
  138. AddNewGuildEvent(GUILD_EVENT_GUILD_LEVEL_UP, "The guild gained a level and is now level %u.", Timer::GetUnixTimeStamp(), true, level);
  139. SendMessageToGuild(GUILD_EVENT_GUILD_LEVEL_UP, "The guild gained a level and is now level %u.", level);
  140. if (level % 10 == 0) {
  141. if (level == 10)
  142. strncpy(adjective, "bold", sizeof(adjective));
  143. else if (level == 20)
  144. strncpy(adjective, "daring", sizeof(adjective));
  145. else if (level == 30)
  146. strncpy(adjective, "gallant", sizeof(adjective));
  147. else if (level == 40)
  148. strncpy(adjective, "noble", sizeof(adjective));
  149. else if (level == 50)
  150. strncpy(adjective, "heroic", sizeof(adjective));
  151. else if (level == 60)
  152. strncpy(adjective, "lordly", sizeof(adjective));
  153. else if (level == 70)
  154. strncpy(adjective, "legendary", sizeof(adjective));
  155. else if (level == 80)
  156. strncpy(adjective, "epic", sizeof(adjective));
  157. else
  158. strncpy(adjective, "too uber for cheerios", sizeof(adjective) - 1);
  159. sprintf(message, "The %s guild <%s> has attained level %u", adjective, name, level);
  160. zone_list.HandleGlobalAnnouncement(message);
  161. }
  162. }
  163. save_needed = true;
  164. ret = true;
  165. }
  166. else if (exp < 0) {
  167. }
  168. if (ret && send_packet)
  169. SendGuildUpdate();
  170. }
  171. void Guild::SetEXPToNextLevel(int64 exp, bool send_packet) {
  172. exp_to_next_level = exp;
  173. if (send_packet) {
  174. LogWrite(GUILD__DEBUG, 1, "Guilds", "Guild XP to next level: %ul", exp_to_next_level);
  175. SendGuildUpdate();
  176. save_needed = true;
  177. }
  178. }
  179. void Guild::SetRecruitingShortDesc(const char* new_desc, bool send_packet) {
  180. assert(new_desc);
  181. recruiting_short_desc = string(new_desc);
  182. if (send_packet) {
  183. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting short desc:\n%s", recruiting_short_desc.c_str());
  184. SendGuildUpdate();
  185. recruiting_save_needed = true;
  186. }
  187. }
  188. void Guild::SetRecruitingFullDesc(const char* new_desc, bool send_packet) {
  189. assert(new_desc);
  190. recruiting_full_desc = string(new_desc);
  191. if (send_packet) {
  192. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting full desc:\n%s", recruiting_full_desc.c_str());
  193. SendGuildUpdate();
  194. recruiting_save_needed = true;
  195. }
  196. }
  197. void Guild::SetRecruitingMinLevel(int8 new_level, bool send_packet) {
  198. recruiting_min_level = new_level;
  199. if (send_packet) {
  200. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting min_level: %i", recruiting_min_level);
  201. SendGuildUpdate();
  202. recruiting_save_needed = true;
  203. }
  204. }
  205. void Guild::SetRecruitingPlayStyle(int8 new_play_style, bool send_packet) {
  206. recruiting_play_style = new_play_style;
  207. if (send_packet) {
  208. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting play style: %i", recruiting_play_style);
  209. SendGuildUpdate();
  210. recruiting_save_needed = true;
  211. }
  212. }
  213. bool Guild::SetRecruitingDescTag(int8 index, int8 tag, bool send_packet) {
  214. bool ret = false;
  215. if (index <= 3) {
  216. recruiting_desc_tags.Put(index, tag);
  217. ret = true;
  218. }
  219. if (ret && send_packet) {
  220. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Recruiting descriptive tag index: %i, tag: %i", index, tag);
  221. SendGuildUpdate();
  222. recruiting_save_needed = true;
  223. }
  224. return ret;
  225. }
  226. int8 Guild::GetRecruitingDescTag(int8 index) {
  227. int8 ret = 0;
  228. if (index <= 3)
  229. ret = recruiting_desc_tags.Get(index);
  230. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Recruiting descriptive tag index: %i, value: %i", index, ret);
  231. return ret;
  232. }
  233. bool Guild::SetPermission(int8 rank, int8 permission, int8 value, bool send_packet) {
  234. bool ret = false;
  235. if (value == 0 || value == 1) {
  236. if (permissions.count(rank) == 0)
  237. permissions.Put(rank, new MutexMap<int8, int8>);
  238. permissions.Get(rank)->Put(permission, value);
  239. ret = true;
  240. }
  241. if (ret && send_packet) {
  242. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Permissions - Rank: %i, Permission: %i, Value: %i", rank, permission, value);
  243. SendGuildUpdate();
  244. ranks_save_needed = true;
  245. }
  246. return ret;
  247. }
  248. int8 Guild::GetPermission(int8 rank, int8 permission) {
  249. int8 ret = 0;
  250. if (permissions.count(rank) > 0 && permissions.Get(rank)->count(permission) > 0)
  251. ret = permissions.Get(rank)->Get(permission);
  252. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Permissions - Rank: %i, Permission: %i, Value: %i", rank, permission, ret);
  253. return ret;
  254. }
  255. bool Guild::SetEventFilter(int8 event_id, int8 category, int8 value, bool send_packet) {
  256. bool ret = false;
  257. if ((category == GUILD_EVENT_FILTER_CATEGORY_RETAIN_HISTORY || category == GUILD_EVENT_FILTER_CATEGORY_BROADCAST) && (value == 0 || value == 1)) {
  258. if (event_filters.count(event_id) == 0)
  259. event_filters.Put(event_id, new MutexMap<int8, int8>);
  260. event_filters.Get(event_id)->Put(category, value);
  261. ret = true;
  262. }
  263. if (ret && send_packet) {
  264. LogWrite(GUILD__DEBUG, 1, "Guilds", "Set Guild Event Filter - EventID: %i, Category: %i, Value: %i", event_id, category, value);
  265. SendGuildUpdate();
  266. event_filters_save_needed = true;
  267. }
  268. return ret;
  269. }
  270. int8 Guild::GetEventFilter(int8 event_id, int8 category) {
  271. int8 ret = 0;
  272. if (event_filters.count(event_id) > 0 && event_filters.Get(event_id)->count(category) > 0) {
  273. ret = event_filters.Get(event_id)->Get(category);
  274. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Event Filter - EventID: %i, Category: %i, Value: %i", event_id, category, ret);
  275. }
  276. return ret;
  277. }
  278. int32 Guild::GetNumUniqueAccounts() {
  279. map<int32, GuildMember *>::iterator itr;
  280. map<int32, bool> accounts;
  281. mMembers.readlock(__FUNCTION__, __LINE__);
  282. if (members.size() > 0) {
  283. for (itr = members.begin(); itr != members.end(); itr++) {
  284. if (accounts.count(itr->second->account_id) == 0)
  285. accounts[itr->second->account_id] = true;
  286. }
  287. }
  288. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  289. LogWrite(GUILD__DEBUG, 1, "Guilds", "Found %i Unique Account(s) in Guild", accounts.size());
  290. return accounts.size();
  291. }
  292. int32 Guild::GetNumRecruiters() {
  293. map<int32, GuildMember*>::iterator itr;
  294. int32 ret = 0;
  295. mMembers.readlock(__FUNCTION__, __LINE__);
  296. for (itr = members.begin(); itr != members.end(); itr++) {
  297. if (itr->second->recruiter_id > 0 && (itr->second->member_flags & GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD))
  298. ret++;
  299. }
  300. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  301. LogWrite(GUILD__DEBUG, 1, "Guilds", "Found %i Recruiter(s) in Guild", ret);
  302. return ret;
  303. }
  304. int32 Guild::GetNextRecruiterID() {
  305. map<int32, GuildMember*>::iterator itr;
  306. map<int32, bool> tmp;
  307. int32 i, ret = 0;
  308. mMembers.readlock(__FUNCTION__, __LINE__);
  309. for (itr = members.begin(); itr != members.end(); itr++) {
  310. if (itr->second->recruiter_id > 0)
  311. tmp[itr->second->recruiter_id] = true;
  312. }
  313. for (i = 1; i < 0xFFFFFFFF; i++) {
  314. if (tmp.count(i) == 0) {
  315. ret = i;
  316. break;
  317. }
  318. }
  319. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  320. LogWrite(GUILD__DEBUG, 1, "Guilds", "Next Guild Recruiter ID: %i", ret);
  321. return ret;
  322. }
  323. int64 Guild::GetNextEventID() {
  324. GuildEvent *ge;
  325. int64 ret = 1;
  326. if (guild_events.size() > 0) {
  327. ge = guild_events.front();
  328. ret = ge->event_id + 1;
  329. }
  330. LogWrite(GUILD__DEBUG, 1, "Guilds", "Next Guild Event ID: %i", ret);
  331. return ret;
  332. }
  333. GuildMember * Guild::GetGuildMemberOnline(Client *client) {
  334. map<int32, GuildMember*>::iterator itr;
  335. GuildMember *ret = 0;
  336. assert(client);
  337. mMembers.readlock(__FUNCTION__, __LINE__);
  338. for (itr = members.begin(); itr != members.end(); itr++) {
  339. if (itr->second->character_id == client->GetCharacterID()) {
  340. ret = itr->second;
  341. break;
  342. }
  343. }
  344. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  345. LogWrite(GUILD__DEBUG, 3, "Guilds", "Guild Member Online: %s", ret->name);
  346. return ret;
  347. }
  348. GuildMember * Guild::GetGuildMember(Player *player) {
  349. assert(player);
  350. return GetGuildMember(player->GetCharacterID());
  351. }
  352. GuildMember * Guild::GetGuildMember(int32 character_id) {
  353. GuildMember *ret = 0;
  354. mMembers.readlock(__FUNCTION__, __LINE__);
  355. if (members.count(character_id) > 0)
  356. ret = members[character_id];
  357. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  358. LogWrite(GUILD__DEBUG, 1, "Guilds", "%s: %i", __FUNCTION__, character_id);
  359. return ret;
  360. }
  361. GuildMember * Guild::GetGuildMember(const char *player_name) {
  362. map<int32, GuildMember*>::iterator itr;
  363. GuildMember *ret = 0;
  364. assert(player_name);
  365. mMembers.readlock(__FUNCTION__, __LINE__);
  366. for (itr = members.begin(); itr != members.end(); itr++) {
  367. if (!strncmp(player_name, itr->second->name, sizeof(itr->second->name))) {
  368. ret = itr->second;
  369. break;
  370. }
  371. }
  372. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  373. LogWrite(GUILD__DEBUG, 1, "Guilds", "%s: %s", __FUNCTION__, player_name);
  374. return ret;
  375. }
  376. vector<GuildMember *> * Guild::GetGuildRecruiters() {
  377. map<int32, GuildMember*>::iterator itr;
  378. vector<GuildMember *> *ret = 0;
  379. mMembers.readlock(__FUNCTION__, __LINE__);
  380. for (itr = members.begin(); itr != members.end(); itr++) {
  381. if (itr->second->recruiter_id > 0 && (itr->second->member_flags & GUILD_MEMBER_FLAGS_RECRUITING_FOR_GUILD)) {
  382. if (!ret)
  383. ret = new vector<GuildMember *>;
  384. ret->push_back(itr->second);
  385. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Recruiter '%s' (%i)", itr->second->name, itr->second->recruiter_id);
  386. }
  387. }
  388. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  389. return ret;
  390. }
  391. GuildEvent * Guild::GetGuildEvent(int64 event_id) {
  392. deque<GuildEvent*>::iterator itr;
  393. GuildEvent* ret = 0;
  394. for (itr = guild_events.begin(); itr != guild_events.end(); itr++) {
  395. if ((*itr)->event_id == event_id) {
  396. ret = *itr;
  397. break;
  398. }
  399. }
  400. LogWrite(GUILD__DEBUG, 1, "Guilds", "Get Guild Event: %s (%lli)", ret->description.c_str(), ret->event_id);
  401. return ret;
  402. }
  403. bool Guild::SetRankName(int8 rank, const char *name, bool send_packet) {
  404. assert(name);
  405. ranks.Put(rank, string(name));
  406. if (send_packet) {
  407. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set Guild Rank Name: %s (%i)", name, rank);
  408. SendGuildUpdate();
  409. ranks_save_needed = true;
  410. }
  411. return true;
  412. }
  413. const char * Guild::GetRankName(int8 rank) {
  414. if (ranks.count(rank) > 0) {
  415. LogWrite(GUILD__DEBUG, 0, "Guilds", "Get Guild Rank Name: %s (%i)", ranks.Get(rank).c_str(), rank);
  416. return ranks.Get(rank).c_str();
  417. }
  418. return 0;
  419. }
  420. bool Guild::SetRecruitingFlag(int8 flag, int8 value, bool send_packet) {
  421. bool ret = false;
  422. if (recruiting_flags.count(flag) > 0 && (value == 0 || value == 1)) {
  423. recruiting_flags.Put(flag, value);
  424. ret = true;
  425. }
  426. if (ret && send_packet) {
  427. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set Guild Recruiting Flag: %i, Value: %i", flag, value);
  428. SendGuildUpdate();
  429. recruiting_save_needed = true;
  430. }
  431. return ret;
  432. }
  433. int8 Guild::GetRecruitingFlag(int8 flag) {
  434. int8 value = 0;
  435. if (recruiting_flags.count(flag) > 0)
  436. value = recruiting_flags.Get(flag);
  437. LogWrite(GUILD__DEBUG, 0, "Guilds", "Get Guild Recruiting Flag: %i, Value: %i", flag, value);
  438. return value;
  439. }
  440. bool Guild::SetGuildRecruiter(Client* client, const char* name, bool value, bool send_packet) {
  441. GuildMember *gm;
  442. const char *awarder_name;
  443. assert(client);
  444. assert(name);
  445. if (!(gm = GetGuildMember(name)))
  446. return false;
  447. awarder_name = client->GetPlayer()->GetName();
  448. if (value) {
  449. gm->recruiter_id = GetNextRecruiterID();
  450. AddNewGuildEvent(GUILD_EVENT_BECOMES_RECRUITER, "%s awarded %s Guild Recruiting Permission.", Timer::GetUnixTimeStamp(), true, awarder_name, name);
  451. SendMessageToGuild(GUILD_EVENT_BECOMES_RECRUITER, "%s awarded %s Guild Recruiting Permission.", awarder_name, name);
  452. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s makes %s a guild recruiter.", awarder_name, name);
  453. }
  454. else {
  455. gm->recruiter_id = 0;
  456. AddNewGuildEvent(GUILD_EVENT_NO_LONGER_RECRUITER, "%s revoked %s's Guild Recruiting Permission.", Timer::GetUnixTimeStamp(), true, awarder_name, name);
  457. SendMessageToGuild(GUILD_EVENT_NO_LONGER_RECRUITER, "%s revoked %s's Guild Recruiting Permission.", awarder_name, name);
  458. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s removes %s from guild recruiters.", awarder_name, name);
  459. }
  460. if (send_packet) {
  461. SendGuildMember(gm);
  462. member_save_needed = true;
  463. }
  464. return true;
  465. }
  466. bool Guild::SetGuildRecruiterDescription(Client *client, const char *description, bool send_packet) {
  467. GuildMember *gm;
  468. assert(client);
  469. assert(description);
  470. if (!(gm = GetGuildMember(client->GetPlayer())))
  471. return false;
  472. gm->recruiter_description = string(description);
  473. if (send_packet) {
  474. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set guild recruiter description:\n%s", gm->recruiter_description.c_str());
  475. SendGuildRecruiterInfo(client, client->GetPlayer());
  476. member_save_needed = true;
  477. }
  478. return true;
  479. }
  480. bool Guild::ToggleGuildRecruiterAdventureClass(Client *client, bool send_packet) {
  481. GuildMember *gm;
  482. assert(client);
  483. if (!(gm = GetGuildMember(client->GetPlayer())))
  484. return false;
  485. gm->recruiting_show_adventure_class = (gm->recruiting_show_adventure_class == 0 ? 1 : 0);
  486. if (send_packet) {
  487. LogWrite(GUILD__DEBUG, 0, "Guilds", "Toggle guild recruiter adventure class = %i", gm->recruiting_show_adventure_class);
  488. SendGuildRecruiterInfo(client, client->GetPlayer());
  489. }
  490. return true;
  491. }
  492. bool Guild::SetGuildMemberNote(const char *name, const char *note, bool send_packet) {
  493. GuildMember *gm;
  494. assert(name);
  495. assert(note);
  496. if (!(gm = GetGuildMember(name)))
  497. return false;
  498. gm->note = string(note);
  499. if (send_packet) {
  500. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set guild member note:\n%s", gm->note.c_str());
  501. SendGuildMember(gm);
  502. member_save_needed = true;
  503. }
  504. return true;
  505. }
  506. bool Guild::SetGuildOfficerNote(const char *name, const char *note, bool send_packet) {
  507. GuildMember *gm;
  508. assert(name);
  509. assert(note);
  510. if (!(gm = GetGuildMember(name)))
  511. return false;
  512. gm->officer_note = string(note);
  513. if (send_packet) {
  514. LogWrite(GUILD__DEBUG, 0, "Guilds", "Set guild officer note:\n%s", gm->officer_note.c_str());
  515. SendGuildMember(gm);
  516. member_save_needed = true;
  517. }
  518. return true;
  519. }
  520. bool Guild::AddNewGuildMember(Client *client, const char *invited_by, int8 rank) {
  521. Player *player;
  522. GuildMember *gm;
  523. assert(client);
  524. player = client->GetPlayer();
  525. assert(player);
  526. if (members.count(player->GetCharacterID()) == 0 && !player->GetGuild() && ((Player*)player)->GetClient()) {
  527. gm = new GuildMember;
  528. gm->account_id = ((Player*)player)->GetClient()->GetAccountID();
  529. gm->character_id = player->GetCharacterID();
  530. strncpy(gm->name, player->GetName(), sizeof(gm->name));
  531. gm->guild_status = 0;
  532. gm->points = 0.0;
  533. gm->adventure_class = player->GetAdventureClass();
  534. gm->adventure_level = player->GetLevel();
  535. gm->tradeskill_class = player->GetTradeskillClass();
  536. gm->tradeskill_level = player->GetTSLevel();
  537. gm->rank = rank;
  538. gm->zone = string(player->GetZone()->GetZoneDescription());
  539. gm->join_date = Timer::GetUnixTimeStamp();
  540. gm->last_login_date = gm->join_date;
  541. gm->recruiter_id = 0;
  542. gm->member_flags = GUILD_MEMBER_FLAGS_NOTIFY_LOGINS;
  543. gm->recruiting_show_adventure_class = 1;
  544. gm->recruiter_picture_data_size = 0;
  545. gm->recruiter_picture_data = 0;
  546. mMembers.writelock(__FUNCTION__, __LINE__);
  547. members[player->GetCharacterID()] = gm;
  548. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  549. player->SetGuild(this);
  550. string subtitle;
  551. subtitle.append("<").append(GetName()).append(">");
  552. player->SetSubTitle(subtitle.c_str());
  553. if (invited_by)
  554. client->SimpleMessage(CHANNEL_NARRATIVE, "You accept the invite into the guild.");
  555. else {
  556. client->SimpleMessage(CHANNEL_NARRATIVE, "You have formed the guild.");
  557. LogWrite(GUILD__DEBUG, 0, "Guilds", "New Guild formed: %s", GetName());
  558. }
  559. client->PlaySound("ui_joined");
  560. SendGuildUpdate(client);
  561. SendGuildMember(gm);
  562. SendGuildMOTD(client);
  563. SendGuildEventList(client);
  564. SendGuildBankEventList(client);
  565. SendAllGuildEvents(client);
  566. SendGuildMemberList(client);
  567. if(client->GetVersion() > 561)
  568. client->GetCurrentZone()->SendUpdateTitles(client->GetPlayer());
  569. if (invited_by) {
  570. AddNewGuildEvent(GUILD_EVENT_MEMBER_JOINS, "%s has accepted %s's invitation to join %s.", Timer::GetUnixTimeStamp(), true, player->GetName(), invited_by, GetName());
  571. SendMessageToGuild(GUILD_EVENT_MEMBER_JOINS, "%s has accepted %s's invitation to join %s.", player->GetName(), invited_by, GetName());
  572. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s invited %s to join guild: %s", invited_by, player->GetName(), GetName());
  573. }
  574. member_save_needed = true;
  575. }
  576. return true;
  577. }
  578. bool Guild::AddGuildMember(GuildMember *guild_member) {
  579. assert(guild_member);
  580. mMembers.writelock(__FUNCTION__, __LINE__);
  581. assert(members.count(guild_member->character_id) == 0);
  582. members[guild_member->character_id] = guild_member;
  583. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  584. // spammy
  585. LogWrite(GUILD__DEBUG, 5, "Guilds", "Added Player: %s (%i) to Guild: %s", guild_member->name, guild_member->character_id, GetName());
  586. return true;
  587. }
  588. void Guild::RemoveGuildMember(int32 character_id, bool send_packet) {
  589. GuildMember *gm = 0;
  590. Client *client;
  591. mMembers.writelock(__FUNCTION__, __LINE__);
  592. if (members.count(character_id) > 0) {
  593. gm = members[character_id];
  594. members.erase(gm->character_id);
  595. }
  596. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  597. if (gm) {
  598. LogWrite(GUILD__DEBUG, 0, "Guilds", "Remove Player: %s (%i) from Guild: %s", members[character_id]->name, character_id, GetName());
  599. if ((client = zone_list.GetClientByCharID(character_id))) {
  600. client->GetPlayer()->SetGuild(0);
  601. client->GetPlayer()->SetSubTitle("");
  602. client->GetCurrentZone()->SendUpdateTitles(client->GetPlayer());
  603. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You were removed from the guild.");
  604. }
  605. database.DeleteGuildMember(this, gm->character_id);
  606. if (send_packet) {
  607. SendGuildMemberLeave(gm->character_id);
  608. SendGuildUpdate();
  609. SendGuildMemberList();
  610. }
  611. AddNewGuildEvent(GUILD_EVENT_MEMBER_LEAVES, "%s left the guild.", Timer::GetUnixTimeStamp(), true, gm->name);
  612. SendMessageToGuild(GUILD_EVENT_MEMBER_LEAVES, "%s left the guild.", gm->name);
  613. safe_delete_array(gm->recruiter_picture_data);
  614. safe_delete(gm);
  615. }
  616. }
  617. void Guild::RemoveAllGuildMembers() {
  618. map<int32, GuildMember *>::iterator itr;
  619. Client *client;
  620. mMembers.writelock(__FUNCTION__, __LINE__);
  621. for (itr = members.begin(); itr != members.end(); itr++) {
  622. if ((client = zone_list.GetClientByCharID(itr->second->character_id))) {
  623. client->GetPlayer()->SetGuild(0);
  624. client->GetPlayer()->SetSubTitle("");
  625. }
  626. safe_delete(itr->second);
  627. }
  628. members.clear();
  629. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  630. LogWrite(GUILD__DEBUG, 0, "Guilds", "Removed ALL members from Guild: %s", GetName());
  631. }
  632. bool Guild::DemoteGuildMember(Client *client, const char *name, bool send_packet) {
  633. GuildMember *gm;
  634. const char *demoter_name;
  635. bool ret = false;
  636. assert(client);
  637. assert(name);
  638. mMembers.readlock(__FUNCTION__, __LINE__);
  639. if ((gm = GetGuildMember(name)) && gm->rank != GUILD_RANK_RECRUIT) {
  640. demoter_name = client->GetPlayer()->GetName();
  641. gm->rank++;
  642. AddNewGuildEvent(GUILD_EVENT_MEMBER_DEMOTED, "%s has demoted %s to %s.", Timer::GetUnixTimeStamp(), true, demoter_name, name, ranks.Get(gm->rank).c_str());
  643. SendMessageToGuild(GUILD_EVENT_MEMBER_DEMOTED, "%s has demoted %s to %s.", demoter_name, name, ranks.Get(gm->rank).c_str());
  644. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s demoted %s to %s in Guild: %s", demoter_name, name, ranks.Get(gm->rank).c_str(), GetName());
  645. ret = true;
  646. if (send_packet) {
  647. SendGuildMember(gm);
  648. SendGuildMemberList();
  649. member_save_needed = true;
  650. }
  651. }
  652. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  653. return ret;
  654. }
  655. bool Guild::PromoteGuildMember(Client *client, const char *name, bool send_packet) {
  656. GuildMember *gm;
  657. const char *promoter_name;
  658. bool ret = false;
  659. assert(client);
  660. assert(name);
  661. mMembers.readlock(__FUNCTION__, __LINE__);
  662. if ((gm = GetGuildMember(name)) && gm->rank != GUILD_RANK_LEADER) {
  663. promoter_name = client->GetPlayer()->GetName();
  664. gm->rank--;
  665. AddNewGuildEvent(GUILD_EVENT_MEMBER_PROMOTED, "%s has promoted %s to %s.", Timer::GetUnixTimeStamp(), true, promoter_name, name, ranks.Get(gm->rank).c_str());
  666. SendMessageToGuild(GUILD_EVENT_MEMBER_PROMOTED, "%s has promoted %s to %s.", promoter_name, name, ranks.Get(gm->rank).c_str());
  667. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s promoted %s to %s in Guild: %s", promoter_name, name, ranks.Get(gm->rank).c_str(), GetName());
  668. if (send_packet) {
  669. SendGuildMember(gm);
  670. SendGuildMemberList();
  671. member_save_needed = true;
  672. }
  673. }
  674. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  675. return ret;
  676. }
  677. bool Guild::KickGuildMember(Client *client, const char *name, bool send_packet) {
  678. GuildMember *gm;
  679. Client *kicked_client;
  680. const char *kicker_name;
  681. assert(client);
  682. assert(name);
  683. if (!(gm = GetGuildMember(name)))
  684. return false;
  685. kicker_name = client->GetPlayer()->GetName();
  686. if (!strncmp(kicker_name, gm->name, sizeof(gm->name))) {
  687. AddNewGuildEvent(GUILD_EVENT_MEMBER_LEAVES, "%s left the guild.", Timer::GetUnixTimeStamp(), true, gm->name);
  688. SendMessageToGuild(GUILD_EVENT_MEMBER_LEAVES, "%s left the guild.", gm->name);
  689. LogWrite(GUILD__DEBUG, 0, "Guilds", "Player: %s has left guild: %s", gm->name, GetName());
  690. }
  691. else {
  692. AddNewGuildEvent(GUILD_EVENT_MEMBER_LEAVES, "%s kicked %s from the guild.", Timer::GetUnixTimeStamp(), true, kicker_name, gm->name);
  693. SendMessageToGuild(GUILD_EVENT_MEMBER_LEAVES, "%s kicked %s from the guild.", kicker_name, gm->name);
  694. LogWrite(GUILD__DEBUG, 0, "Guilds", "Player: %s was kicked from guild: %s by %s.", gm->name, GetName(), kicker_name);
  695. }
  696. if ((kicked_client = zone_list.GetClientByCharID(gm->character_id))) {
  697. kicked_client->GetPlayer()->SetGuild(0);
  698. kicked_client->GetPlayer()->SetSubTitle("");
  699. if (!strncmp(client->GetPlayer()->GetName(), gm->name, sizeof(gm->name)))
  700. kicked_client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You left the guild.");
  701. else
  702. kicked_client->Message(CHANNEL_COLOR_YELLOW, "You were kicked from the guild by %s.", kicker_name);
  703. }
  704. mMembers.writelock(__FUNCTION__, __LINE__);
  705. members.erase(gm->character_id);
  706. mMembers.releasewritelock(__FUNCTION__, __LINE__);
  707. database.DeleteGuildMember(this, gm->character_id);
  708. if (send_packet) {
  709. SendGuildMemberLeave(gm->character_id);
  710. SendGuildUpdate();
  711. SendGuildMemberList();
  712. }
  713. safe_delete_array(gm->recruiter_picture_data);
  714. safe_delete(gm);
  715. return true;
  716. }
  717. bool Guild::InvitePlayer(Client *client, const char *name, bool send_packet) {
  718. Client *client_invite;
  719. Player *player_invite;
  720. PacketStruct *packet;
  721. assert(client);
  722. assert(name);
  723. if (!(client_invite = zone_list.GetClientByCharName(string(name)))) {
  724. client->Message(CHANNEL_NARRATIVE, "%s couldn't be found.", name);
  725. LogWrite(GUILD__WARNING, 0, "Guilds", "Attempted to invite %s to guild %s: Player Not Found", name, GetName());
  726. return false;
  727. }
  728. player_invite = client_invite->GetPlayer();
  729. if (player_invite->GetGuild()) {
  730. client->Message(CHANNEL_NARRATIVE, "%s is already in a guild.", player_invite->GetName());
  731. LogWrite(GUILD__WARNING, 0, "Guilds", "Attempted to invite %s to guild %s: Already in a guild", player_invite->GetName(), GetName());
  732. return false;
  733. }
  734. if (client_invite->GetPendingGuildInvite()->guild) {
  735. client->Message(CHANNEL_NARRATIVE, "%s is already considering joining a guild.", player_invite->GetName());
  736. LogWrite(GUILD__WARNING, 0, "Guilds", "Attempted to invite %s to guild %s: Pending Invite elsewhere", player_invite->GetName(), GetName());
  737. return false;
  738. }
  739. if (!(packet = configReader.getStruct("WS_ReceiveOffer", client_invite->GetVersion())))
  740. return false;
  741. packet->setDataByName("type", 2);
  742. packet->setMediumStringByName("name", client->GetPlayer()->GetName());
  743. packet->setDataByName("unknown2", 1);
  744. packet->setMediumStringByName("guild_name", GetName());
  745. client_invite->QueuePacket(packet->serialize());
  746. client->Message(CHANNEL_NARRATIVE, "You have invited %s to join %s.", player_invite->GetName(), GetName());
  747. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s invited %s to guild %s", client->GetPlayer()->GetName(), player_invite->GetName(), GetName());
  748. client_invite->SetPendingGuildInvite(this, client->GetPlayer());
  749. safe_delete(packet);
  750. return true;
  751. }
  752. bool Guild::AddPointsToAll(Client *client, float points, const char *comment, bool send_packet) {
  753. map<int32, GuildMember *>::iterator itr;
  754. vector<int32> character_ids;
  755. GuildMember *gm;
  756. Client *client_to;
  757. assert(client);
  758. mMembers.readlock(__FUNCTION__, __LINE__);
  759. for (itr = members.begin(); itr != members.end(); itr++) {
  760. gm = itr->second;
  761. if (!permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_RECEIVE_POINTS)) {
  762. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not allowed to receive points! Skipping...", gm->character_id);
  763. continue;
  764. }
  765. gm->points += points;
  766. character_ids.push_back(gm->character_id);
  767. AddPointHistory(gm, Timer::GetUnixTimeStamp(), client->GetPlayer()->GetName(), points, comment);
  768. if ((client_to = zone_list.GetClientByCharID(gm->character_id)))
  769. {
  770. client_to->Message(CHANNEL_GUILD_CHAT, "%s increased your guild member points by %.1f.", client->GetPlayer()->GetName(), points);
  771. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild: %s", GetName());
  772. LogWrite(GUILD__DEBUG, 0, "Guilds", "\tAwarded By: %s +%.1f pts to Player: %s", client->GetPlayer()->GetName(), points, gm->name);
  773. }
  774. SendGuildMember(gm); //tmp
  775. }
  776. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  777. client->Message(CHANNEL_GUILD_CHAT, "Points modified for %u guild members.", character_ids.size());
  778. if (send_packet) {
  779. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s modified points for %u members. Reason: %s", client->GetPlayer()->GetName(), character_ids.size(), points, comment);
  780. SendGuildModification(points, &character_ids);
  781. member_save_needed = true;
  782. points_history_save_needed = true;
  783. }
  784. return true;
  785. }
  786. bool Guild::AddPointsToAllOnline(Client *client, float points, const char *comment, bool send_packet) {
  787. map<int32, GuildMember *>::iterator itr;
  788. vector<int32> character_ids;
  789. GuildMember *gm;
  790. Client *client_to;
  791. assert(client);
  792. mMembers.readlock(__FUNCTION__, __LINE__);
  793. for (itr = members.begin(); itr != members.end(); itr++) {
  794. gm = itr->second;
  795. if (!(client_to = zone_list.GetClientByCharID(gm->character_id))) {
  796. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not online to receive points! Skipping...", gm->character_id);
  797. continue;
  798. }
  799. if (!permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_RECEIVE_POINTS)) {
  800. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not allowed to receive points! Skipping...", gm->character_id);
  801. continue;
  802. }
  803. gm->points += points;
  804. character_ids.push_back(gm->character_id);
  805. AddPointHistory(gm, Timer::GetUnixTimeStamp(), client->GetPlayer()->GetName(), points, comment);
  806. client_to->Message(CHANNEL_GUILD_CHAT, "%s increased your guild member points by %.1f.", client->GetPlayer()->GetName(), points);
  807. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild: %s", GetName());
  808. LogWrite(GUILD__DEBUG, 0, "Guilds", "\tAwarded By: %s +%.1f pts to Player: %s", client->GetPlayer()->GetName(), points, gm->name);
  809. SendGuildMember(gm); //tmp
  810. }
  811. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  812. client->Message(CHANNEL_GUILD_CHAT, "Points modified for %u guild members.", character_ids.size());
  813. if (send_packet) {
  814. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s modified points for %u members. Reason: %s", client->GetPlayer()->GetName(), character_ids.size(), points, comment);
  815. SendGuildModification(points, &character_ids);
  816. member_save_needed = true;
  817. points_history_save_needed = true;
  818. }
  819. return true;
  820. }
  821. bool Guild::AddPointsToGroup(Client *client, float points, const char *comment, bool send_packet) {
  822. deque<GroupMemberInfo*>::iterator itr;
  823. deque<GroupMemberInfo*>* group_members;
  824. vector<int32> character_ids;
  825. GroupMemberInfo *gmi;
  826. GuildMember *gm;
  827. assert(client);
  828. if (!client->GetPlayer()->GetGroupMemberInfo()) {
  829. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Cannot assign points because you aren't in a group.");
  830. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s tried to assign points for group and failed: Not in a group", client->GetPlayer()->GetName());
  831. return false;
  832. }
  833. mMembers.readlock(__FUNCTION__, __LINE__);
  834. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  835. PlayerGroup* group = world.GetGroupManager()->GetGroup(client->GetPlayer()->GetGroupMemberInfo()->group_id);
  836. if (group)
  837. {
  838. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  839. deque<GroupMemberInfo*>* group_members = group->GetMembers();
  840. for (itr = group_members->begin(); itr != group_members->end(); itr++) {
  841. gmi = *itr;
  842. if (!gmi->client)
  843. continue;
  844. if (gmi->client->GetPlayer()->GetGuild() != this) {
  845. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not in guild to receive group points! Skipping...", gmi->client->GetPlayer()->GetCharacterID());
  846. continue;
  847. }
  848. if (!(gm = members[gmi->client->GetCharacterID()]) || !permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_RECEIVE_POINTS)) {
  849. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not allowed to receive points! Skipping...", gm->character_id);
  850. continue;
  851. }
  852. gm->points += points;
  853. character_ids.push_back(gm->character_id);
  854. AddPointHistory(gm, Timer::GetUnixTimeStamp(), client->GetPlayer()->GetName(), points, comment);
  855. gmi->client->Message(CHANNEL_GUILD_CHAT, "%s increased your guild member points by %.1f.", client->GetPlayer()->GetName(), points);
  856. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild: %s", GetName());
  857. LogWrite(GUILD__DEBUG, 0, "Guilds", "\tAwarded By: %s +%.1f pts to Player: %s", client->GetPlayer()->GetName(), points, gm->name);
  858. SendGuildMember(gm); //tmp
  859. }
  860. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  861. }
  862. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  863. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  864. client->Message(CHANNEL_GUILD_CHAT, "Points modified for %u guild members.", character_ids.size());
  865. if (send_packet) {
  866. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s modified points for %u members. Reason: %s", client->GetPlayer()->GetName(), character_ids.size(), points, comment);
  867. SendGuildModification(points, &character_ids);
  868. member_save_needed = true;
  869. points_history_save_needed = true;
  870. }
  871. return true;
  872. }
  873. bool Guild::AddPointsToRaid(Client *client, float points, const char *comment, bool send_packet) {
  874. assert(client);
  875. LogWrite(MISC__TODO, 1, "TODO", "Implement Raiding\n%s, %s, %i", __FILE__, __FUNCTION__, __LINE__);
  876. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Cannot assign points because you aren't in a raid.");
  877. return false;
  878. }
  879. bool Guild::AddPointsToGuildMember(Client *client, float points, const char *name, const char *comment, bool send_packet) {
  880. vector<int32> character_ids;
  881. GuildMember *gm;
  882. Client *client_to;
  883. assert(client);
  884. assert(name);
  885. if (!(gm = GetGuildMember(name)))
  886. return false;
  887. mMembers.readlock(__FUNCTION__, __LINE__);
  888. if (!permissions.Get(gm->rank)->Get(GUILD_PERMISSIONS_RECEIVE_POINTS)) {
  889. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  890. LogWrite(GUILD__DEBUG, 0, "Guilds", "PlayerID: %i not allowed to receive points! Skipping...", gm->character_id);
  891. client->Message(CHANNEL_GUILD_CHAT, "%s does not have permission to receive guild points.", gm->name);
  892. return false;
  893. }
  894. gm->points += points;
  895. character_ids.push_back(gm->character_id);
  896. if ((client_to = zone_list.GetClientByCharID(gm->character_id))) {
  897. client_to->Message(CHANNEL_GUILD_CHAT, "%s increased your guild member points by %.1f.", client->GetPlayer()->GetName(), points);
  898. LogWrite(GUILD__DEBUG, 0, "Guilds", "Guild: %s", GetName());
  899. LogWrite(GUILD__DEBUG, 0, "Guilds", "\tAwarded By: %s +%.1f pts to Player: %s", client->GetPlayer()->GetName(), points, gm->name);
  900. }
  901. LogWrite(GUILD__DEBUG, 0, "Guilds", "%s modified points for 1 guild member. Reason: %s", client->GetPlayer()->GetName(), comment);
  902. client->SimpleMessage(CHANNEL_GUILD_CHAT, "Points modified for 1 guild member.");
  903. AddPointHistory(gm, Timer::GetUnixTimeStamp(), client->GetPlayer()->GetName(), points, comment);
  904. if (send_packet) {
  905. SendGuildMember(gm); //tmp
  906. SendGuildModification(points, &character_ids);
  907. member_save_needed = true;
  908. points_history_save_needed = true;
  909. }
  910. mMembers.releasereadlock(__FUNCTION__, __LINE__);
  911. return true;
  912. }
  913. bool Guild::AddPointHistory(GuildMember *guild_member, int32 date, const char *modified_by, float points, const char *comment, bool new_point_history) {
  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_GUILD_CHAT, "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_GUILD_CHAT, "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_GUILD_CHAT, "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_GUILD_CHAT, "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_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_NARRATIVE, "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_SAY, message, 0, 0, false, sender->GetPlayer()->GetCurrentLanguage());
  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_NARRATIVE, "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_SAY, message, 0, 0, false, sender->GetPlayer()->GetCurrentLanguage());
  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_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. }