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