Guild.cpp 80 KB

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