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