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.20 by root, Sun Jul 1 05:00:19 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines