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.1 by elmex, Sun Aug 13 17:16:04 2006 UTC vs.
Revision 1.14 by root, Sun Jan 7 02:39:14 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines