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.3 by root, Sun Sep 3 00:18:42 2006 UTC vs.
Revision 1.4 by root, Sat Sep 9 22:54:31 2006 UTC

1/*
2 * static char *rcsid_c_party_c =
3 * "$Id: c_party.C,v 1.3 2006/09/03 00:18:42 root Exp $";
4 */
5 1
6/* 2/*
7 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
8 4
9 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
26 The authors can be reached via e-mail at crossfire-devel@real-time.com 22 The authors can be reached via e-mail at crossfire-devel@real-time.com
27*/ 23*/
28 24
29#include <global.h> 25#include <global.h>
30#ifndef __CEXTRACT__ 26#ifndef __CEXTRACT__
31#include <sproto.h> 27# include <sproto.h>
32#endif 28#endif
33#include <spells.h> 29#include <spells.h>
34 30
35#ifdef COZY_SERVER 31#ifdef COZY_SERVER
36// used for pet monster logic etc. 32// used for pet monster logic etc.
33int
37int same_party (partylist *a, partylist *b) 34same_party (partylist *a, partylist *b)
38{ 35{
39 return a == b && a; 36 return a == b && a;
40} 37}
41#endif 38#endif
42 39
43static partylist * firstparty=NULL; /* Keeps track of first party in list */ 40static partylist *firstparty = NULL; /* Keeps track of first party in list */
44static partylist * lastparty=NULL; /*Keeps track of last party in list */ 41static partylist *lastparty = NULL; /*Keeps track of last party in list */
45 42
43partylist *
46partylist* get_firstparty(void) 44get_firstparty (void)
47{ 45{
48 return firstparty; 46 return firstparty;
49} 47}
50 48
51void remove_party(partylist *target_party); 49void remove_party (partylist *target_party);
52 50
53/* Forms the party struct for a party called 'params'. it is the responsibility 51/* 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 52 * of the caller to ensure that the name is unique, and that it is placed in the
55 * main party list correctly */ 53 * main party list correctly */
54static partylist *
56static partylist *form_party(object *op, const char *params) { 55form_party (object *op, const char *params)
57 56{
58 partylist * newparty; 57 partylist *newparty;
59 58
60 newparty = (partylist *)malloc(sizeof(partylist)); 59 newparty = (partylist *) malloc (sizeof (partylist));
61 newparty->partyname = strdup_local(params); 60 newparty->partyname = strdup_local (params);
62 newparty->total_exp=0; 61 newparty->total_exp = 0;
63 newparty->kills=0; 62 newparty->kills = 0;
64 newparty->passwd[0] = '\0'; 63 newparty->passwd[0] = '\0';
65 newparty->next = NULL; 64 newparty->next = NULL;
66 newparty->partyleader = strdup_local(op->name); 65 newparty->partyleader = strdup_local (op->name);
67 new_draw_info_format(NDI_UNIQUE, 0, op, 66 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; 67 op->contr->party = newparty;
68
70 return newparty; 69 return newparty;
71} 70}
72 71
72void
73void remove_party(partylist *target_party) { 73remove_party (partylist *target_party)
74{
74 partylist *tmpparty; 75 partylist *tmpparty;
75 partylist *previousparty; 76 partylist *previousparty;
76 partylist *nextparty; 77 partylist *nextparty;
77 player *pl; 78 player *pl;
79
80 if (firstparty == NULL)
78 81 {
79 if (firstparty==NULL) {
80 LOG(llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", 82 LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname);
83 return;
84 }
85
86 for (pl = first_player; pl != NULL; pl = pl->next)
87 if (pl->party == target_party)
88 pl->party = NULL;
89
90 /* special case-ism for parties at the beginning and end of the list */
91 if (target_party == firstparty)
92 {
93 firstparty = firstparty->next;
94
95 if (target_party->partyleader)
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
81 target_party->partyname); 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)
126 {
127 previousparty = tmpparty;
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);
82 return; 137 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 } 138 }
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} 139}
120 140
121/* Remove unused parties, this could be made to scale a lot better. */ 141/* Remove unused parties, this could be made to scale a lot better. */
142void
122void obsolete_parties(void) { 143obsolete_parties (void)
144{
123 int player_count; 145 int player_count;
124 player *pl; 146 player *pl;
125 partylist *party; 147 partylist *party;
126 partylist* next = NULL; 148 partylist *next = NULL;
127 149
150 if (!firstparty)
128 if (!firstparty) return; /* we can't obsolete parties if there aren't any */ 151 return; /* we can't obsolete parties if there aren't any */
129 for (party=firstparty; party!=NULL; party=next) { 152 for (party = firstparty; party != NULL; party = next)
153 {
130 next = party->next; 154 next = party->next;
131 player_count=0; 155 player_count = 0;
132 for (pl=first_player;pl!=NULL;pl=pl->next) 156 for (pl = first_player; pl != NULL; pl = pl->next)
133 if (pl->party==party) player_count++; 157 if (pl->party == party)
158 player_count++;
134 if (player_count == 0) 159 if (player_count == 0)
135 remove_party(party); 160 remove_party (party);
136 } 161 }
137} 162}
138 163
139#ifdef PARTY_KILL_LOG 164#ifdef PARTY_KILL_LOG
165void
140void add_kill_to_party(partylist *party, char *killer, char *dead, long exp) 166add_kill_to_party (partylist *party, char *killer, char *dead, long exp)
141{ 167{
142 int i,pos; 168 int i, pos;
143 169
144 if(party==NULL) return; 170 if (party == NULL)
171 return;
145 if(party->kills>=PARTY_KILL_LOG) 172 if (party->kills >= PARTY_KILL_LOG)
146 { 173 {
147 pos=PARTY_KILL_LOG-1; 174 pos = PARTY_KILL_LOG - 1;
148 for(i=0;i<PARTY_KILL_LOG-1;i++) 175 for (i = 0; i < PARTY_KILL_LOG - 1; i++)
149 memcpy(&(party->party_kills[i]),&(party->party_kills[i+1]), 176 party->party_kills[i] = party->party_kills[i + 1];
150 sizeof(party->party_kills[0]));
151 } 177 }
152 else 178 else
153 pos=party->kills; 179 pos = party->kills;
154 party->kills++; 180 party->kills++;
155 party->total_exp+=exp; 181 party->total_exp += exp;
156 party->party_kills[pos].exp=exp; 182 party->party_kills[pos].exp = exp;
157 strncpy(party->party_kills[pos].killer,killer,MAX_NAME); 183 strncpy (party->party_kills[pos].killer, killer, MAX_NAME);
158 strncpy(party->party_kills[pos].dead,dead,MAX_NAME); 184 strncpy (party->party_kills[pos].dead, dead, MAX_NAME);
159 party->party_kills[pos].killer[MAX_NAME]=0; 185 party->party_kills[pos].killer[MAX_NAME] = 0;
160 party->party_kills[pos].dead[MAX_NAME]=0; 186 party->party_kills[pos].dead[MAX_NAME] = 0;
161} 187}
162#endif 188#endif
163 189
190int
164int confirm_party_password(object *op) { 191confirm_party_password (object *op)
192{
165 partylist *tmppartylist; 193 partylist *tmppartylist;
194
166 for(tmppartylist = firstparty; tmppartylist != NULL;tmppartylist = tmppartylist->next) { 195 for (tmppartylist = firstparty; tmppartylist != NULL; tmppartylist = tmppartylist->next)
196 {
167 if(!strcmp(op->contr->party_to_join->partyname, tmppartylist->partyname)) { 197 if (!strcmp (op->contr->party_to_join->partyname, tmppartylist->partyname))
198 {
168 if(strcmp(op->contr->write_buf+1,tmppartylist->passwd) == 0) 199 if (strcmp (op->contr->write_buf + 1, tmppartylist->passwd) == 0)
169 return 0; 200 return 0;
170 else 201 else
171 return 1; 202 return 1;
172 } 203 }
173 } 204 }
174 return 1; 205 return 1;
175} 206}
176 207
208void
177void receive_party_password(object *op, char k) { 209receive_party_password (object *op, char k)
178 210{
211
179 if(confirm_party_password(op) == 0) { 212 if (confirm_party_password (op) == 0)
213 {
180 partylist* joined_party = op->contr->party_to_join; 214 partylist *joined_party = op->contr->party_to_join;
181 char buf[ MAX_BUF ]; 215 char buf[MAX_BUF];
216
182 op->contr->party = op->contr->party_to_join; 217 op->contr->party = op->contr->party_to_join;
183 op->contr->party_to_join = NULL; 218 op->contr->party_to_join = NULL;
184 new_draw_info_format(NDI_UNIQUE, 0,op, 219 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 ); 220 snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, joined_party->partyname);
187 send_party_message( op, buf ); 221 send_party_message (op, buf);
188 op->contr->state = ST_PLAYING; 222 op->contr->state = ST_PLAYING;
189 return; 223 return;
190 } 224 }
191 else { 225 else
226 {
192 new_draw_info(NDI_UNIQUE, 0,op,"You entered the wrong password"); 227 new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password");
193 op->contr->party_to_join = NULL; 228 op->contr->party_to_join = NULL;
194 op->contr->state = ST_PLAYING; 229 op->contr->state = ST_PLAYING;
195 return; 230 return;
196 } 231 }
197} 232}
198 233
234void
199void send_party_message(object *op,char *msg) 235send_party_message (object *op, char *msg)
200{ 236{
201 player *pl; 237 player *pl;
238
202 for(pl=first_player;pl!=NULL;pl=pl->next) 239 for (pl = first_player; pl != NULL; pl = pl->next)
203 if(pl->ob->contr->party==op->contr->party && pl->ob!=op) 240 if (pl->ob->contr->party == op->contr->party && pl->ob != op)
204 new_draw_info(NDI_WHITE, 0, pl->ob, msg); 241 new_draw_info (NDI_WHITE, 0, pl->ob, msg);
205} 242}
206 243
244int
207int command_gsay(object *op, char *params) 245command_gsay (object *op, char *params)
208{ 246{
209 char party_params[MAX_BUF]; 247 char party_params[MAX_BUF];
210 248
211 if (!params) return 0; 249 if (!params)
250 return 0;
212 strcpy(party_params, "say "); 251 strcpy (party_params, "say ");
213 strcat(party_params,params); 252 strcat (party_params, params);
214 command_party(op,party_params); 253 command_party (op, party_params);
215 return 0; 254 return 0;
216} 255}
217 256
218 257
258int
219int command_party (object *op, char *params) 259command_party (object *op, char *params)
220{ 260{
221 char buf[MAX_BUF]; 261 char buf[MAX_BUF];
222 partylist *tmpparty, *oldparty; /* For iterating over linked list */ 262 partylist *tmpparty, *oldparty; /* For iterating over linked list */
223 char * currentparty; /* For iterating over linked list */ 263 char *currentparty; /* For iterating over linked list */
224 264
225 if(params == NULL) { 265 if (params == NULL)
266 {
226 if(op->contr->party==NULL) { 267 if (op->contr->party == NULL)
268 {
227 new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party."); 269 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"); 270 new_draw_info (NDI_UNIQUE, 0, op, "For help try: party help");
271 }
272 else
229 } 273 {
230 else {
231 currentparty = op->contr->party->partyname; 274 currentparty = op->contr->party->partyname;
232 new_draw_info_format(NDI_UNIQUE, 0, op, 275 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 } 276 }
235 return 1; 277 return 1;
236 } 278 }
237 if(strcmp(params, "help")==0) { 279 if (strcmp (params, "help") == 0)
280 {
238 new_draw_info(NDI_UNIQUE, 0,op,"To form a party type: party form <partyname>"); 281 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>"); 282 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."); 283 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"); 284 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"); 285 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>"); 286 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"); 287 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>"); 288 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"); 289 new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who");
247#ifdef PARTY_KILL_LOG 290#ifdef PARTY_KILL_LOG
248 new_draw_info(NDI_UNIQUE, 0,op,"To see what you've killed, type: party kills"); 291 new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills");
249#endif 292#endif
250 return 1; 293 return 1;
251 } 294 }
252#ifdef PARTY_KILL_LOG 295#ifdef PARTY_KILL_LOG
253 if(!strncmp(params, "kills",5)) 296 if (!strncmp (params, "kills", 5))
254 { 297 {
255 int i,max; 298 int i, max;
256 char chr; 299 char chr;
257 char buffer[80]; 300 char buffer[80];
258 float exp; 301 float exp;
259 302
260 if(op->contr->party==NULL) 303 if (op->contr->party == NULL)
261 { 304 {
262 new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party."); 305 new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party.");
263 return 1; 306 return 1;
264 } 307 }
265 tmpparty = op->contr->party; 308 tmpparty = op->contr->party;
266 if(!tmpparty->kills) 309 if (!tmpparty->kills)
267 { 310 {
268 new_draw_info(NDI_UNIQUE,0,op,"You haven't killed anything yet."); 311 new_draw_info (NDI_UNIQUE, 0, op, "You haven't killed anything yet.");
269 return 1; 312 return 1;
270 } 313 }
271 max=tmpparty->kills-1; 314 max = tmpparty->kills - 1;
272 if(max>PARTY_KILL_LOG-1) max=PARTY_KILL_LOG-1; 315 if (max > PARTY_KILL_LOG - 1)
273 new_draw_info(NDI_UNIQUE,0,op, 316 max = PARTY_KILL_LOG - 1;
274 "Killed | Killer| Exp"); 317 new_draw_info (NDI_UNIQUE, 0, op, "Killed | Killer| Exp");
275 new_draw_info(NDI_UNIQUE,0,op, 318 new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------");
276 "----------------+----------------+--------");
277 for(i=0;i<=max;i++) 319 for (i = 0; i <= max; i++)
278 { 320 {
279 exp=tmpparty->party_kills[i].exp; 321 exp = tmpparty->party_kills[i].exp;
280 chr=' '; 322 chr = ' ';
281 if(exp>1000000) { exp/=1000000; chr='M'; } 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)
370 {
371 int player_count;
372 player *pl;
373
374 params += 5;
375 if (op->contr->party)
376 oldparty = op->contr->party;
377 else
378 oldparty = NULL;
379
380 if (firstparty)
381 {
382 for (tmpparty = firstparty; tmpparty != NULL; tmpparty = tmpparty->next)
383 {
384 if (!strcmp (tmpparty->partyname, params))
385 {
386 new_draw_info_format (NDI_UNIQUE, 0, op, "The party %s already exists, pick another name", params);
387 return 1;
388 }
389 }
390 lastparty->next = form_party (op, params);
391 lastparty = lastparty->next;
392 }
393 else
394 {
395 firstparty = form_party (op, params);
396 lastparty = firstparty;
397 }
398 /*
399 * The player might have previously been a member of a party, if so, he will be leaving
400 * it, so check if there are any other members and if not, delete the party
401 */
402 player_count = 0;
403 if (oldparty)
404 {
405 for (pl = first_player; pl->next != NULL; pl = pl->next)
406 {
407 if (pl->party == oldparty)
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 {
446 if (pl->ob->contr->own_title[0] != '\0')
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
458 if (strncmp (params, "passwd ", 7) == 0)
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);
485 return 0;
486 }
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 {
532 new_draw_info_format (NDI_UNIQUE, 0, op, "Party: %s does not exist. You must form it first", params);
533 return 1;
534 }
282 else 535 else
283 if(exp>1000) { exp/=1000; chr='k'; } 536 {
284 sprintf(buffer,"%16s|%16s|%6.1f%c", 537 if (op->contr->party == firstparty)
285 tmpparty->party_kills[i].dead, 538 {
286 tmpparty->party_kills[i].killer,exp,chr); 539 new_draw_info_format (NDI_UNIQUE, 0, op, "You are already in party: %s", firstparty->partyname);
287 new_draw_info(NDI_UNIQUE,0,op,buffer); 540 return 1;
541 }
542 /* found party player wants to join */
543 if (firstparty->passwd[0] == '\0')
544 {
545 op->contr->party = firstparty;
546 new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s", firstparty->partyname);
547 snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, firstparty->partyname);
548 send_party_message (op, buf);
549 return 0;
550 }
551 else
552 {
553 get_party_password (op, firstparty);
554 return 0;
555 }
556 }
557 }
558
559 tmpparty = firstparty;
560 while (tmpparty != NULL)
288 } 561 {
289 exp=tmpparty->total_exp; 562 if (strcmp (tmpparty->partyname, params) == 0)
290 chr=' '; 563 {
291 if(exp>1000000) { exp/=1000000; chr='M'; } 564 if (op->contr->party == tmpparty)
565 {
566 new_draw_info_format (NDI_UNIQUE, 0, op, "You are already a member of party: %s", tmpparty->partyname);
567 return 1;
568 }
569 else
570 {
571 if (tmpparty->passwd[0] == '\0')
572 {
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 }
585 }
292 else 586 else
293 if(exp>1000) { exp/=1000; chr='k'; } 587 tmpparty = tmpparty->next;
294 new_draw_info(NDI_UNIQUE,0,op, 588 }
295 "----------------+----------------+--------"); 589
296 sprintf(buffer,"Totals: %d kills, %.1f%c exp",tmpparty->kills, 590 new_draw_info_format (NDI_UNIQUE, 0, op, "Party %s does not exist. You must form it first.", params);
297 exp,chr);
298 new_draw_info(NDI_UNIQUE,0,op,buffer);
299 return 1; 591 return 1;
300 } 592 } /* join */
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 593
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>"); 594 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>"); 595 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."); 596 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"); 597 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"); 598 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>"); 599 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"); 600 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>"); 601 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"); 602 new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who");
531#ifdef PARTY_KILL_LOG 603#ifdef PARTY_KILL_LOG
532 new_draw_info(NDI_UNIQUE, 0,op,"To see what you've killed, type: party kills"); 604 new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills");
533#endif 605#endif
534 return 1; 606 return 1;
535} 607}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines