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