1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <sproto.h> |
26 | #include <sproto.h> |
26 | #include <spells.h> |
27 | #include <spells.h> |
27 | |
28 | |
28 | static partylist *firstparty = NULL; /* Keeps track of first party in list */ |
29 | static partylist *firstparty; |
29 | static partylist *lastparty = NULL; /*Keeps track of last party in list */ |
|
|
30 | |
30 | |
31 | partylist * |
31 | partylist * |
32 | get_firstparty (void) |
32 | get_firstparty () |
33 | { |
33 | { |
34 | return firstparty; |
34 | return firstparty; |
35 | } |
35 | } |
36 | |
36 | |
37 | void remove_party (partylist *target_party); |
37 | static void |
38 | |
|
|
39 | /* Forms the party struct for a party called 'params'. it is the responsibility |
|
|
40 | * of the caller to ensure that the name is unique, and that it is placed in the |
|
|
41 | * main party list correctly */ |
|
|
42 | static partylist * |
|
|
43 | form_party (object *op, const char *params) |
|
|
44 | { |
|
|
45 | partylist *newparty; |
|
|
46 | |
|
|
47 | newparty = (partylist *) malloc (sizeof (partylist)); |
|
|
48 | newparty->partyname = strdup (params); |
|
|
49 | newparty->total_exp = 0; |
|
|
50 | newparty->kills = 0; |
|
|
51 | newparty->passwd[0] = '\0'; |
|
|
52 | newparty->next = NULL; |
|
|
53 | newparty->partyleader = strdup (op->name); |
|
|
54 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have formed party: %s", newparty->partyname); |
|
|
55 | op->contr->party = newparty; |
|
|
56 | |
|
|
57 | return newparty; |
|
|
58 | } |
|
|
59 | |
|
|
60 | void |
|
|
61 | remove_party (partylist *target_party) |
38 | remove_party (partylist *target_party) |
62 | { |
39 | { |
63 | partylist *tmpparty; |
|
|
64 | partylist *previousparty; |
|
|
65 | partylist *nextparty; |
|
|
66 | |
|
|
67 | if (firstparty == NULL) |
40 | if (firstparty == NULL) |
68 | { |
41 | { |
69 | LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); |
42 | LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); |
70 | return; |
43 | return; |
71 | } |
44 | } |
72 | |
45 | |
73 | for_all_players (pl) |
46 | for_all_players (pl) |
74 | if (pl->party == target_party) |
47 | if (pl->party == target_party) |
75 | pl->party = NULL; |
48 | pl->party = NULL; |
76 | |
49 | |
77 | /* special case-ism for parties at the beginning and end of the list */ |
50 | partylist **prevlink = &firstparty; |
78 | if (target_party == firstparty) |
|
|
79 | { |
|
|
80 | firstparty = firstparty->next; |
|
|
81 | |
51 | |
82 | if (target_party->partyleader) |
52 | for (partylist *p = firstparty; p; p = p->next) |
83 | free (target_party->partyleader); |
|
|
84 | |
|
|
85 | if (target_party->partyname) |
|
|
86 | free (target_party->partyname); |
|
|
87 | |
|
|
88 | free (target_party); |
|
|
89 | return; |
|
|
90 | } |
|
|
91 | else if (target_party == lastparty) |
|
|
92 | { |
|
|
93 | for (tmpparty = firstparty; tmpparty->next != NULL; tmpparty = tmpparty->next) |
|
|
94 | { |
|
|
95 | if (tmpparty->next == target_party) |
|
|
96 | { |
|
|
97 | lastparty = tmpparty; |
|
|
98 | |
|
|
99 | if (target_party->partyleader) |
|
|
100 | free (target_party->partyleader); |
|
|
101 | |
|
|
102 | if (target_party->partyname) |
|
|
103 | free (target_party->partyname); |
|
|
104 | |
|
|
105 | free (target_party); |
|
|
106 | lastparty->next = NULL; |
|
|
107 | return; |
|
|
108 | } |
|
|
109 | } |
|
|
110 | } |
|
|
111 | for (tmpparty = firstparty; tmpparty->next != NULL; tmpparty = tmpparty->next) |
|
|
112 | if (tmpparty->next == target_party) |
53 | if (p->next == target_party) |
113 | { |
54 | { |
114 | previousparty = tmpparty; |
55 | prevlink = &p->next; |
115 | nextparty = tmpparty->next->next; |
|
|
116 | /* this should be safe, because we already dealt with the lastparty case */ |
|
|
117 | |
|
|
118 | previousparty->next = nextparty; |
|
|
119 | if (target_party->partyleader) |
|
|
120 | free (target_party->partyleader); |
|
|
121 | if (target_party->partyname) |
|
|
122 | free (target_party->partyname); |
|
|
123 | free (target_party); |
|
|
124 | return; |
56 | break; |
125 | } |
57 | } |
|
|
58 | |
|
|
59 | *prevlink = target_party->next; |
|
|
60 | |
|
|
61 | free (target_party->partyleader); |
|
|
62 | free (target_party->partyname); |
|
|
63 | sfree (target_party); |
126 | } |
64 | } |
127 | |
65 | |
128 | /* Remove unused parties, this could be made to scale a lot better. */ |
66 | /* Remove unused parties, this could be made to scale a lot better. */ |
129 | void |
67 | void |
130 | obsolete_parties (void) |
68 | obsolete_parties () |
131 | { |
69 | { |
132 | int player_count; |
70 | int player_count; |
133 | partylist *party; |
71 | partylist *party; |
134 | partylist *next = NULL; |
72 | partylist *next = NULL; |
135 | |
73 | |
136 | if (!firstparty) |
74 | if (!firstparty) |
137 | return; /* we can't obsolete parties if there aren't any */ |
75 | return; /* we can't obsolete parties if there aren't any */ |
|
|
76 | |
138 | for (party = firstparty; party != NULL; party = next) |
77 | for (party = firstparty; party != NULL; party = next) |
139 | { |
78 | { |
140 | next = party->next; |
79 | next = party->next; |
141 | player_count = 0; |
80 | player_count = 0; |
142 | for_all_players (pl) |
81 | for_all_players (pl) |
… | |
… | |
171 | assign (party->party_kills[pos].dead, dead); |
110 | assign (party->party_kills[pos].dead, dead); |
172 | party->party_kills[pos].killer[MAX_NAME] = 0; |
111 | party->party_kills[pos].killer[MAX_NAME] = 0; |
173 | party->party_kills[pos].dead[MAX_NAME] = 0; |
112 | party->party_kills[pos].dead[MAX_NAME] = 0; |
174 | } |
113 | } |
175 | |
114 | |
176 | int |
115 | static int |
177 | confirm_party_password (object *op) |
116 | confirm_party_password (object *op) |
178 | { |
117 | { |
179 | partylist *tmppartylist; |
118 | partylist *tmppartylist; |
180 | |
119 | |
181 | for (tmppartylist = firstparty; tmppartylist != NULL; tmppartylist = tmppartylist->next) |
120 | for (tmppartylist = firstparty; tmppartylist != NULL; tmppartylist = tmppartylist->next) |
… | |
… | |
187 | else |
126 | else |
188 | return 1; |
127 | return 1; |
189 | } |
128 | } |
190 | } |
129 | } |
191 | return 1; |
130 | return 1; |
|
|
131 | } |
|
|
132 | |
|
|
133 | static void |
|
|
134 | send_party_message (object *op, const char *msg) |
|
|
135 | { |
|
|
136 | for_all_players (pl) |
|
|
137 | if (pl->ob->contr->party == op->contr->party && pl->ob != op) |
|
|
138 | pl->send_msg (NDI_UNIQUE, MSG_CHANNEL ("party"), msg); |
192 | } |
139 | } |
193 | |
140 | |
194 | void |
141 | void |
195 | receive_party_password (object *op, char k) |
142 | receive_party_password (object *op, char k) |
196 | { |
143 | { |
… | |
… | |
215 | op->contr->ns->state = ST_PLAYING; |
162 | op->contr->ns->state = ST_PLAYING; |
216 | return; |
163 | return; |
217 | } |
164 | } |
218 | } |
165 | } |
219 | |
166 | |
220 | void |
|
|
221 | send_party_message (object *op, char *msg) |
|
|
222 | { |
|
|
223 | for_all_players (pl) |
|
|
224 | if (pl->ob->contr->party == op->contr->party && pl->ob != op) |
|
|
225 | new_draw_info (NDI_WHITE, 0, pl->ob, msg); |
|
|
226 | } |
|
|
227 | |
|
|
228 | int |
167 | int |
229 | command_gsay (object *op, char *params) |
168 | command_gsay (object *op, char *params) |
230 | { |
169 | { |
231 | char party_params[MAX_BUF]; |
|
|
232 | |
|
|
233 | if (!params) |
170 | if (!params) |
234 | return 0; |
171 | return 0; |
235 | |
172 | |
236 | strcpy (party_params, "say "); |
|
|
237 | strcat (party_params, params); |
|
|
238 | command_party (op, party_params); |
173 | command_party (op, format ("say %s", params)); |
|
|
174 | |
239 | return 0; |
175 | return 0; |
240 | } |
176 | } |
241 | |
177 | |
242 | int |
178 | int |
243 | command_party (object *op, char *params) |
179 | command_party (object *op, char *params) |
244 | { |
180 | { |
245 | char buf[MAX_BUF]; |
181 | dynbuf_text &buf = msg_dynbuf; buf.clear (); |
246 | partylist *tmpparty, *oldparty; /* For iterating over linked list */ |
|
|
247 | char *currentparty; /* For iterating over linked list */ |
|
|
248 | |
182 | |
249 | if (params == NULL) |
183 | partylist *party = op->contr->party; |
250 | { |
|
|
251 | if (op->contr->party == NULL) |
|
|
252 | { |
|
|
253 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
254 | new_draw_info (NDI_UNIQUE, 0, op, "For help try: party help"); |
|
|
255 | } |
|
|
256 | else |
|
|
257 | { |
|
|
258 | currentparty = op->contr->party->partyname; |
|
|
259 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are a member of party %s.", currentparty); |
|
|
260 | } |
|
|
261 | return 1; |
|
|
262 | } |
|
|
263 | |
184 | |
|
|
185 | if (!params) |
|
|
186 | params = (char *)""; |
|
|
187 | |
264 | if (strcmp (params, "help") == 0) |
188 | if (!strcmp (params, "help")) |
265 | { |
189 | buf << "\n" |
266 | new_draw_info (NDI_UNIQUE, 0, op, "To form a party type: party form <partyname>"); |
190 | " - To form a party type: C<party form> <partyname>\n" |
267 | new_draw_info (NDI_UNIQUE, 0, op, "To join a party type: party join <partyname>"); |
191 | " - To join a party type: C<party join> <partyname>\n" |
268 | new_draw_info (NDI_UNIQUE, 0, op, "If the party has a passwd, it will you prompt you for it."); |
192 | " - If the party has a passwd, it will you prompt you for it.\n" |
269 | new_draw_info (NDI_UNIQUE, 0, op, "For a list of current parties type: party list"); |
193 | " - For a list of current parties type: C<party list>\n" |
270 | new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave"); |
194 | " - To leave a party type: C<party leave>\n" |
271 | new_draw_info (NDI_UNIQUE, 0, op, "To change a passwd for a party type: party passwd <password>"); |
195 | " - To change a passwd for a party type: C<party passwd> <password>\n" |
272 | new_draw_info (NDI_UNIQUE, 0, op, "There is an 8 character max"); |
196 | " - There is an 8 character max\n" |
273 | new_draw_info (NDI_UNIQUE, 0, op, "To talk to party members type: party say <msg>"); |
197 | " - To talk to party members type: C<party say> <msg>\n" |
274 | new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who"); |
198 | " - To see who is in your party: C<party who>\n" |
275 | new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills"); |
199 | " - To see what you've killed, type: C<party kills>\n"; |
276 | return 1; |
|
|
277 | } |
|
|
278 | |
|
|
279 | if (!strncmp (params, "kills", 5)) |
|
|
280 | { |
|
|
281 | int i, max; |
|
|
282 | char chr; |
|
|
283 | char buffer[80]; |
|
|
284 | float exp; |
|
|
285 | |
|
|
286 | if (op->contr->party == NULL) |
|
|
287 | { |
|
|
288 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
289 | return 1; |
|
|
290 | } |
|
|
291 | tmpparty = op->contr->party; |
|
|
292 | if (!tmpparty->kills) |
|
|
293 | { |
|
|
294 | new_draw_info (NDI_UNIQUE, 0, op, "You haven't killed anything yet."); |
|
|
295 | return 1; |
|
|
296 | } |
|
|
297 | max = tmpparty->kills - 1; |
|
|
298 | if (max > PARTY_KILL_LOG - 1) |
|
|
299 | max = PARTY_KILL_LOG - 1; |
|
|
300 | new_draw_info (NDI_UNIQUE, 0, op, "Killed | Killer| Exp"); |
|
|
301 | new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); |
|
|
302 | for (i = 0; i <= max; i++) |
|
|
303 | { |
|
|
304 | exp = tmpparty->party_kills[i].exp; |
|
|
305 | chr = ' '; |
|
|
306 | if (exp > 1000000) |
|
|
307 | { |
|
|
308 | exp /= 1000000; |
|
|
309 | chr = 'M'; |
|
|
310 | } |
|
|
311 | else if (exp > 1000) |
|
|
312 | { |
|
|
313 | exp /= 1000; |
|
|
314 | chr = 'k'; |
|
|
315 | } |
|
|
316 | sprintf (buffer, "%16s|%16s|%6.1f%c", tmpparty->party_kills[i].dead, tmpparty->party_kills[i].killer, exp, chr); |
|
|
317 | new_draw_info (NDI_UNIQUE, 0, op, buffer); |
|
|
318 | } |
|
|
319 | exp = tmpparty->total_exp; |
|
|
320 | chr = ' '; |
|
|
321 | if (exp > 1000000) |
|
|
322 | { |
|
|
323 | exp /= 1000000; |
|
|
324 | chr = 'M'; |
|
|
325 | } |
|
|
326 | else if (exp > 1000) |
|
|
327 | { |
|
|
328 | exp /= 1000; |
|
|
329 | chr = 'k'; |
|
|
330 | } |
|
|
331 | new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); |
|
|
332 | sprintf (buffer, "Totals: %d kills, %.1f%c exp", tmpparty->kills, exp, chr); |
|
|
333 | new_draw_info (NDI_UNIQUE, 0, op, buffer); |
|
|
334 | return 1; |
|
|
335 | } |
|
|
336 | |
|
|
337 | if (strncmp (params, "say ", 4) == 0) |
|
|
338 | { |
|
|
339 | if (op->contr->party == NULL) |
|
|
340 | { |
|
|
341 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
342 | return 1; |
|
|
343 | } |
|
|
344 | params += 4; |
|
|
345 | currentparty = op->contr->party->partyname; |
|
|
346 | snprintf (buf, MAX_BUF - 1, "[%s] %s says: %s", currentparty, &op->name, params); |
|
|
347 | send_party_message (op, buf); |
|
|
348 | new_draw_info_format (NDI_LT_GREEN | NDI_UNIQUE, 0, op, "[%s] You say: %s", currentparty, params); |
|
|
349 | return 1; |
|
|
350 | } |
|
|
351 | |
|
|
352 | if (strncmp (params, "form ", 5) == 0) |
200 | else if (strncmp (params, "form ", 5) == 0) |
353 | { |
201 | { |
354 | int player_count; |
|
|
355 | |
|
|
356 | params += 5; |
202 | params += 5; |
357 | if (op->contr->party) |
|
|
358 | oldparty = op->contr->party; |
|
|
359 | else |
|
|
360 | oldparty = NULL; |
|
|
361 | |
203 | |
362 | if (firstparty) |
204 | if (party) |
|
|
205 | buf << "You are already a member of party " << party->partyname << ". You must leave it first."; |
|
|
206 | else |
363 | { |
207 | { |
364 | for (tmpparty = firstparty; tmpparty != NULL; tmpparty = tmpparty->next) |
208 | for (partylist *tmpparty = firstparty; tmpparty; tmpparty = tmpparty->next) |
365 | { |
209 | { |
366 | if (!strcmp (tmpparty->partyname, params)) |
210 | if (!strcmp (tmpparty->partyname, params)) |
367 | { |
211 | { |
368 | new_draw_info_format (NDI_UNIQUE, 0, op, "The party %s already exists, pick another name", params); |
212 | buf << "The party " << tmpparty->partyname << " already exists, pick another name"; |
369 | return 1; |
213 | goto reply; |
370 | } |
214 | } |
371 | } |
215 | } |
372 | lastparty->next = form_party (op, params); |
216 | |
373 | lastparty = lastparty->next; |
217 | /* Forms the party struct for a party called 'params'. it is the responsibility |
374 | } |
218 | * of the caller to ensure that the name is unique, and that it is placed in the |
375 | else |
219 | * main party list correctly */ |
376 | { |
220 | |
377 | firstparty = form_party (op, params); |
221 | party = salloc0<partylist> (); |
|
|
222 | party->partyname = strdup (params); |
|
|
223 | party->total_exp = 0; |
|
|
224 | party->kills = 0; |
|
|
225 | party->passwd[0] = '\0'; |
|
|
226 | party->next = NULL; |
|
|
227 | party->partyleader = strdup (op->name); |
|
|
228 | |
|
|
229 | buf << "You have formed party: " << party->partyname << "."; |
|
|
230 | |
378 | lastparty = firstparty; |
231 | party->next = firstparty; |
379 | } |
232 | op->contr->party = firstparty = party; |
380 | /* |
|
|
381 | * The player might have previously been a member of a party, if so, he will be leaving |
|
|
382 | * it, so check if there are any other members and if not, delete the party |
|
|
383 | */ |
|
|
384 | player_count = 0; |
|
|
385 | if (oldparty) |
|
|
386 | { |
|
|
387 | for_all_players (pl) |
|
|
388 | if (pl->party == oldparty) |
|
|
389 | player_count++; |
|
|
390 | |
|
|
391 | if (player_count == 0) |
|
|
392 | remove_party (oldparty); |
|
|
393 | } |
|
|
394 | |
|
|
395 | return 0; |
|
|
396 | } /* form */ |
|
|
397 | |
|
|
398 | if (strcmp (params, "leave") == 0) |
|
|
399 | { |
|
|
400 | if (op->contr->party == NULL) |
|
|
401 | { |
|
|
402 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
403 | return 1; |
|
|
404 | } |
|
|
405 | currentparty = op->contr->party->partyname; |
|
|
406 | new_draw_info_format (NDI_UNIQUE, 0, op, "You leave party %s.", currentparty); |
|
|
407 | sprintf (buf, "%s leaves party %s.", &op->name, currentparty); |
|
|
408 | send_party_message (op, buf); |
|
|
409 | op->contr->party = NULL; |
|
|
410 | return 1; |
|
|
411 | } |
|
|
412 | |
|
|
413 | if (strcmp (params, "who") == 0) |
|
|
414 | { |
|
|
415 | tmpparty = op->contr->party; |
|
|
416 | if (op->contr->party == NULL) |
|
|
417 | { |
|
|
418 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
419 | return 1; |
|
|
420 | } |
|
|
421 | new_draw_info_format (NDI_UNIQUE, 0, op, "Members of party: %s.", op->contr->party->partyname); |
|
|
422 | for_all_players (pl) |
|
|
423 | if (pl->ob->contr->party == op->contr->party) |
|
|
424 | { |
|
|
425 | if (settings.set_title == TRUE) |
|
|
426 | { |
|
|
427 | if (pl->ob->contr->own_title[0] != '\0') |
|
|
428 | sprintf (buf, "%3d %s the %s", pl->ob->level, &pl->ob->name, pl->ob->contr->own_title); |
|
|
429 | else |
|
|
430 | sprintf (buf, "%3d %s the %s", pl->ob->level, &pl->ob->name, pl->ob->contr->title); |
|
|
431 | } |
|
|
432 | else |
|
|
433 | sprintf (buf, "%3d %s the %s", pl->ob->level, &pl->ob->name, pl->ob->contr->title); |
|
|
434 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
435 | } |
233 | } |
436 | return 1; |
234 | } |
437 | } /* leave */ |
235 | else if (strcmp (params, "list") == 0) |
|
|
236 | { |
|
|
237 | if (!firstparty) |
|
|
238 | buf << "There are no parties active right now"; |
|
|
239 | else |
|
|
240 | { |
|
|
241 | buf << "Party name Leader\n\n" |
|
|
242 | "---------- ------\n\n"; |
438 | |
243 | |
|
|
244 | for (partylist *p = firstparty; p; p = p->next) |
|
|
245 | buf.printf ("%-32s %s\n\n", p->partyname, p->partyleader); |
|
|
246 | } |
|
|
247 | } |
439 | if (strncmp (params, "passwd ", 7) == 0) |
248 | else if (strncmp (params, "join ", 5) == 0) |
440 | { |
249 | { |
441 | partylist *tmplist; |
|
|
442 | |
|
|
443 | params += 7; |
250 | params += 5; |
444 | |
251 | |
445 | if (op->contr->party == NULL) |
252 | /* Can't join a party cause non exist */ |
446 | { |
253 | if (!firstparty) |
447 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of a party"); |
254 | buf << "Party: " << params << " does not exist. You must form it first."; |
448 | return 1; |
255 | else if (party) |
449 | } |
256 | buf << "You are already a member of party " << party->partyname << ". You must leave it first."; |
450 | |
257 | else |
451 | if (strlen (params) > 8) |
258 | for (partylist *p = firstparty; p; p = p->next) |
452 | { |
259 | if (!strcmp (p->partyname, params)) |
453 | new_draw_info (NDI_UNIQUE, 0, op, "The password must not exceed 8 characters"); |
|
|
454 | return 1; |
|
|
455 | } |
|
|
456 | |
|
|
457 | tmplist = firstparty; |
|
|
458 | while (tmplist != NULL) |
|
|
459 | { |
|
|
460 | if (tmplist == op->contr->party) |
|
|
461 | { |
260 | { |
462 | strcpy (tmplist->passwd, params); |
261 | if (!*p->passwd) |
463 | new_draw_info_format (NDI_UNIQUE, 0, op, "The password for party %s is %s", tmplist->partyname, tmplist->passwd); |
262 | { |
464 | snprintf (buf, MAX_BUF, "Password for party %s is now %s, changed by %s", tmplist->partyname, tmplist->passwd, &op->name); |
263 | op->contr->party = p; |
|
|
264 | |
|
|
265 | buf << op->name << " joins party " << p->partyname << "."; |
465 | send_party_message (op, buf); |
266 | send_party_message (op, buf); |
466 | return 0; |
267 | buf.clear (); |
|
|
268 | |
|
|
269 | buf << "You have joined party: " << p->partyname << "."; |
467 | } |
270 | } |
468 | tmplist = tmplist->next; |
|
|
469 | } |
|
|
470 | return 0; |
|
|
471 | } /* passwd */ |
|
|
472 | |
|
|
473 | if (strcmp (params, "list") == 0) |
|
|
474 | { |
|
|
475 | partylist *tmplist; |
|
|
476 | |
|
|
477 | tmplist = firstparty; |
|
|
478 | |
|
|
479 | if (firstparty == NULL) |
|
|
480 | { |
|
|
481 | new_draw_info (NDI_UNIQUE, 0, op, "There are no parties active right now"); |
|
|
482 | return 1; |
|
|
483 | } |
|
|
484 | |
|
|
485 | new_draw_info (NDI_UNIQUE, 0, op, "Party name Leader"); |
|
|
486 | new_draw_info (NDI_UNIQUE, 0, op, "---------- ------"); |
|
|
487 | |
|
|
488 | while (tmplist != NULL) |
|
|
489 | { |
|
|
490 | new_draw_info_format (NDI_UNIQUE, 0, op, "%-32s %s", tmplist->partyname, tmplist->partyleader); |
|
|
491 | tmplist = tmplist->next; |
|
|
492 | } |
|
|
493 | return 0; |
|
|
494 | } /* list */ |
|
|
495 | |
|
|
496 | if (strncmp (params, "join ", 5) == 0) |
|
|
497 | { |
|
|
498 | |
|
|
499 | params += 5; |
|
|
500 | |
|
|
501 | /* Can't join a party cause non exist */ |
|
|
502 | if (firstparty == NULL) |
|
|
503 | { |
|
|
504 | new_draw_info_format (NDI_UNIQUE, 0, op, "Party: %s does not exist. You must form it first", params); |
|
|
505 | return 1; |
|
|
506 | } |
|
|
507 | |
|
|
508 | /* Special case if thier is only one party */ |
|
|
509 | if (firstparty->next == NULL) |
|
|
510 | { |
|
|
511 | if (strcmp (firstparty->partyname, params) != 0) |
|
|
512 | { |
271 | else |
513 | new_draw_info_format (NDI_UNIQUE, 0, op, "Party: %s does not exist. You must form it first", params); |
272 | get_party_password (op, p); |
514 | return 1; |
273 | |
|
|
274 | goto reply; |
515 | } |
275 | } |
516 | else |
276 | else |
|
|
277 | buf << "Party " << params << " does not exist. You must form it first."; |
|
|
278 | } |
|
|
279 | else if (!party) |
|
|
280 | buf << "You are not a member of any party.\n\n" |
|
|
281 | "For help try: C<party help>"; |
|
|
282 | else if (!*params) |
|
|
283 | buf << "You are a member of party " << party->partyname << "."; |
|
|
284 | else if (!strncmp (params, "kills", 5)) |
|
|
285 | { |
|
|
286 | if (!party->kills) |
|
|
287 | buf << "You haven't killed anything yet."; |
|
|
288 | else |
|
|
289 | { |
|
|
290 | int max = min (party->kills - 1, PARTY_KILL_LOG - 1); |
|
|
291 | |
|
|
292 | buf << " Killed | Killer| Exp\n" |
|
|
293 | << " ----------------+----------------+--------\n"; |
|
|
294 | |
|
|
295 | for (int i = 0; i <= max; i++) |
517 | { |
296 | { |
518 | if (op->contr->party == firstparty) |
297 | sint64 exp = party->party_kills[i].exp; |
|
|
298 | char suffix = ' '; |
|
|
299 | if (exp > 1000000) |
519 | { |
300 | { |
520 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are already in party: %s", firstparty->partyname); |
301 | exp /= 1000000; |
521 | return 1; |
302 | suffix = 'M'; |
522 | } |
303 | } |
523 | /* found party player wants to join */ |
304 | else if (exp > 1000) |
524 | if (firstparty->passwd[0] == '\0') |
|
|
525 | { |
305 | { |
526 | op->contr->party = firstparty; |
306 | exp /= 1000; |
527 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s", firstparty->partyname); |
307 | suffix = 'k'; |
528 | snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, firstparty->partyname); |
|
|
529 | send_party_message (op, buf); |
|
|
530 | return 0; |
|
|
531 | } |
308 | } |
532 | else |
309 | |
533 | { |
310 | buf.printf (" %16s|%16s|%6.1f%c\n", party->party_kills[i].dead, party->party_kills[i].killer, (double)exp, suffix); |
534 | get_party_password (op, firstparty); |
|
|
535 | return 0; |
|
|
536 | } |
|
|
537 | } |
311 | } |
538 | } |
|
|
539 | |
312 | |
540 | tmpparty = firstparty; |
313 | buf << " ----------------+----------------+--------\n"; |
541 | while (tmpparty != NULL) |
314 | |
542 | { |
|
|
543 | if (strcmp (tmpparty->partyname, params) == 0) |
|
|
544 | { |
315 | { |
545 | if (op->contr->party == tmpparty) |
316 | sint64 exp = party->total_exp; |
|
|
317 | char suffix = ' '; |
|
|
318 | |
|
|
319 | if (exp > 1000000) |
546 | { |
320 | { |
547 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are already a member of party: %s", tmpparty->partyname); |
321 | exp /= 1000000; |
548 | return 1; |
322 | suffix = 'M'; |
549 | } |
323 | } |
550 | else |
324 | else if (exp > 1000) |
551 | { |
325 | { |
552 | if (tmpparty->passwd[0] == '\0') |
326 | exp /= 1000; |
553 | { |
327 | suffix = 'k'; |
554 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s", tmpparty->partyname); |
|
|
555 | op->contr->party = tmpparty; |
|
|
556 | snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, tmpparty->partyname); |
|
|
557 | send_party_message (op, buf); |
|
|
558 | return 0; |
|
|
559 | } |
|
|
560 | else |
|
|
561 | { |
|
|
562 | get_party_password (op, tmpparty); |
|
|
563 | return 0; |
|
|
564 | } |
|
|
565 | } |
328 | } |
|
|
329 | |
|
|
330 | buf.printf (" Totals: %d kills, %.1f%c exp", party->kills, (double)exp, suffix); |
566 | } |
331 | } |
|
|
332 | } |
|
|
333 | } |
|
|
334 | else if (strncmp (params, "say ", 4) == 0) |
|
|
335 | { |
|
|
336 | params += 4; |
|
|
337 | |
|
|
338 | buf << "[" << party->partyname << "] " << op->name << " says: " << params; |
|
|
339 | send_party_message (op, buf); |
|
|
340 | buf.clear (); |
|
|
341 | |
|
|
342 | buf << "[" << party->partyname << "] You say: " << params; |
|
|
343 | } |
|
|
344 | else if (strcmp (params, "leave") == 0) |
|
|
345 | { |
|
|
346 | buf << op->name << " leaves party " << party->partyname << "."; |
|
|
347 | send_party_message (op, buf); |
|
|
348 | buf.clear (); |
|
|
349 | |
|
|
350 | buf << "You leave party " << party->partyname << "."; |
|
|
351 | |
|
|
352 | op->contr->party = 0; |
|
|
353 | obsolete_parties (); |
|
|
354 | } |
|
|
355 | else if (strcmp (params, "who") == 0) |
|
|
356 | { |
|
|
357 | buf << "Members of party " << party->partyname << ".\n"; |
|
|
358 | |
|
|
359 | for_all_players (pl) |
|
|
360 | if (pl->ob->contr->party == party) |
|
|
361 | buf.printf (" - %s/%d %s\n\n", &pl->ob->name, pl->ob->level, |
|
|
362 | *pl->ob->contr->own_title ? pl->ob->contr->own_title : pl->ob->contr->title); |
|
|
363 | } |
|
|
364 | else if (strncmp (params, "passwd ", 7) == 0) |
|
|
365 | { |
|
|
366 | params += 7; |
|
|
367 | |
|
|
368 | if (strlen (params) > 8) |
|
|
369 | buf << "The password must not exceed 8 characters"; |
567 | else |
370 | else |
568 | tmpparty = tmpparty->next; |
|
|
569 | } |
371 | { |
|
|
372 | strcpy (party->passwd, params); |
|
|
373 | buf << "The password for party " << party->partyname << " is set to B<" << params << "> by " << &op->name; |
|
|
374 | } |
|
|
375 | } |
|
|
376 | else |
|
|
377 | buf << "I did not understand your command. For help try: C<party help>"; |
570 | |
378 | |
571 | new_draw_info_format (NDI_UNIQUE, 0, op, "Party %s does not exist. You must form it first.", params); |
379 | reply: |
572 | return 1; |
380 | op->contr->send_msg (NDI_UNIQUE | NDI_REPLY, MSG_CHANNEL ("party"), buf); |
573 | } /* join */ |
|
|
574 | |
381 | |
575 | new_draw_info (NDI_UNIQUE, 0, op, "To form a party type: party form <partyname>"); |
|
|
576 | new_draw_info (NDI_UNIQUE, 0, op, "To join a party type: party join <partyname>"); |
|
|
577 | new_draw_info (NDI_UNIQUE, 0, op, "If the party has a passwd, it will you prompt you for it."); |
|
|
578 | new_draw_info (NDI_UNIQUE, 0, op, "For a list of current parties type: party list"); |
|
|
579 | new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave"); |
|
|
580 | new_draw_info (NDI_UNIQUE, 0, op, "To change a passwd for a party type: party passwd <password>"); |
|
|
581 | new_draw_info (NDI_UNIQUE, 0, op, "There is an 8 character max"); |
|
|
582 | new_draw_info (NDI_UNIQUE, 0, op, "To talk to party members type: party say <msg>"); |
|
|
583 | new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who"); |
|
|
584 | new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills"); |
|
|
585 | return 1; |
382 | return 1; |
586 | } |
383 | } |