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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines