ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_party.C
(Generate patch)

Comparing deliantra/server/server/c_party.C (file contents):
Revision 1.2 by root, Tue Aug 29 08:01:37 2006 UTC vs.
Revision 1.19 by root, Mon May 28 21:28:35 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines