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