9
3

Guild.cpp 80 KB

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