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

Comparing deliantra/server/server/c_party.C (file contents):
Revision 1.2 by root, Tue Aug 29 08:01:37 2006 UTC vs.
Revision 1.7 by root, Fri Nov 17 21:26:42 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines