Crossfire Server, Trunk
c_party.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <string.h>
22 
23 #include "sproto.h"
24 #include "spells.h"
25 
38 static int confirm_party_password(object *op, const char *password) {
39  const partylist *party;
40 
41  party = party_find(op->contr->party_to_join->partyname);
42  return party == NULL || !party_confirm_password(party, password);
43 }
44 
53 void receive_party_password(object *op, const char *password) {
54  if (confirm_party_password(op, password) == 0) {
55  party_join(op, op->contr->party_to_join);
56  op->contr->party_to_join = NULL;
58  return;
59  }
60 
62  "You entered the wrong password");
63  op->contr->party_to_join = NULL;
65 }
66 
75 void command_gsay(object *op, const char *params) {
76  char party_params[MAX_BUF];
77 
78  if (*params == '\0') {
80  return;
81  }
82  strcpy(party_params, "say ");
83  strcat(party_params, params);
84  command_party(op, party_params);
85 }
86 
97 void command_party(object *op, const char *params) {
98  char buf[MAX_BUF];
99 
100  if (*params == '\0') {
101  if (op->contr->party == NULL) {
103  "You are not a member of any party. "
104  "For help try: party help");
105  } else {
107  "You are a member of party %s.",
108  op->contr->party->partyname);
109  }
110  return;
111  }
112  if (strcmp(params, "help") == 0) {
113  command_help(op, "party");
114  return;
115  }
116 #ifdef PARTY_KILL_LOG
117  if (!strncmp(params, "kills", 5)) {
118  int i, max;
119  char chr;
120  float exp;
121  partylist *tmpparty;
122 
123  if (op->contr->party == NULL) {
125  "You are not a member of any party.");
126  return;
127  }
128  tmpparty = op->contr->party;
129  if (!tmpparty->kills) {
131  "You haven't killed anything yet.");
132  return;
133  }
134  max = tmpparty->kills-1;
135  if (max > PARTY_KILL_LOG-1)
136  max = PARTY_KILL_LOG-1;
138  "[fixed]Killed | Killer| Exp\n----------------+----------------+--------"
139  "Killed | Killer| Exp\n----------------+----------------+--------");
140 
141 
142  for (i = 0; i <= max; i++) {
143  exp = tmpparty->party_kills[i].exp;
144  chr = ' ';
145  if (exp > 1000000) {
146  exp /= 1000000;
147  chr = 'M';
148  } else if (exp > 1000) {
149  exp /= 1000;
150  chr = 'k';
151  }
152 
154  "[fixed]%16s|%16s|%6.1f%c",
155  tmpparty->party_kills[i].dead,
156  tmpparty->party_kills[i].killer, exp, chr);
157  }
158  exp = tmpparty->total_exp;
159  chr = ' ';
160  if (exp > 1000000) {
161  exp /= 1000000;
162  chr = 'M';
163  } else if (exp > 1000) {
164  exp /= 1000;
165  chr = 'k';
166  }
167 
169  "[fixed]----------------+----------------+--------");
171  "Totals: %d kills, %.1f%c exp", tmpparty->kills,
172  exp, chr);
173  return;
174  }
175 #endif /* PARTY_KILL_LOG */
176  if (strncmp(params, "say ", 4) == 0) {
177  if (op->contr->party == NULL) {
179  "You are not a member of any party.");
180  return;
181  }
182  params += 4;
183  snprintf(buf, MAX_BUF-1, "<%s> %s says: %s", op->contr->party->partyname, op->name, params);
186  "<%s> You say: %s",
187  op->contr->party->partyname, params);
188  return;
189  }
190 
191  if (strncmp(params, "form ", 5) == 0) {
192  params += 5;
193 
194  if (party_form(op, params) == NULL) {
196  "The party %s already exists, pick another name",
197  params);
198  return;
199  }
200  return;
201  } /* form */
202 
203  if (strcmp(params, "leave") == 0) {
204  if (op->contr->party == NULL) {
206  "You are not a member of any party.");
207  return;
208  }
209  party_leave(op);
210  return;
211  }
212  if (strcmp(params, "who") == 0) {
213  if (op->contr->party == NULL) {
215  "You are not a member of any party.");
216  return;
217  }
218  list_players(op, NULL, op->contr->party);
219  return;
220  } /* leave */
221 
222  if (strncmp(params, "passwd ", 7) == 0) {
223  params += 7;
224 
225  if (op->contr->party == NULL) {
227  "You are not a member of a party");
228  return;
229  }
230 
231  if (strlen(params) > 8) {
233  "The password must not exceed 8 characters");
234  return;
235  }
236 
237  party_set_password(op->contr->party, params);
239  "The password for party %s is %s",
240  op->contr->party->partyname, party_get_password(op->contr->party));
241 
242  snprintf(buf, MAX_BUF, "Password for party %s is now %s, changed by %s",
243  op->contr->party->partyname, party_get_password(op->contr->party), op->name);
245  return;
246  } /* passwd */
247 
248  if (strcmp(params, "list") == 0) {
249  partylist *party;
250 
251  if (party_get_first() == NULL) {
253  "There are no parties active right now");
254  return;
255  }
256 
258  "[fixed]Party name Leader\n---------- ------");
259  for (party = party_get_first(); party != NULL; party = party_get_next(party)) {
261  "[fixed]%-32s %s",
262  party->partyname, party_get_leader(party));
263  }
264 
265  return;
266  } /* list */
267 
268  if (strncmp(params, "join ", 5) == 0) {
269  partylist *party;
270 
271  params += 5;
272 
273  party = party_find(params);
274  if (party == NULL) {
276  "Party %s does not exist. You must form it first.",
277  params);
278  return;
279  }
280 
281  if (get_party_password(op, party)) {
282  return;
283  }
284 
285  party_join(op, party);
286  return;
287  } /* join */
288 
289  command_help(op, "party");
290 }
291 
293 static const char *rejoin_modes[] = {
294  "no",
295  "if_exists",
296  "always",
297  NULL
298 };
299 
307 void command_party_rejoin(object *op, const char *params) {
308  int mode;
309 
310  if (*params == '\0') {
312  "party rejoin: %s", rejoin_modes[op->contr->rejoin_party]);
313  return;
314  }
315  for (mode = 0; rejoin_modes[mode] != NULL; mode++) {
316  if (strcmp(rejoin_modes[mode], params) == 0) {
317  op->contr->rejoin_party = mode;
319  "party rejoin is now: %s", rejoin_modes[op->contr->rejoin_party]);
320  return;
321  }
322  }
324  "invalid mode: %50s", params);
325 }
global.h
party_get_leader
const char * party_get_leader(const partylist *party)
Definition: party.c:292
rejoin_modes
static const char * rejoin_modes[]
Definition: c_party.c:293
MSG_TYPE_COMMAND_SUCCESS
#define MSG_TYPE_COMMAND_SUCCESS
Definition: newclient.h:530
confirm_party_password
static int confirm_party_password(object *op, const char *password)
Definition: c_party.c:38
get_party_password
int get_party_password(object *op, partylist *party)
Definition: player.c:1013
party_find
partylist * party_find(const char *partyname)
Definition: party.c:148
MSG_TYPE_COMMAND_ERROR
#define MSG_TYPE_COMMAND_ERROR
Definition: newclient.h:529
MSG_TYPE_COMMAND
#define MSG_TYPE_COMMAND
Definition: newclient.h:404
party_struct::partyname
char * partyname
Definition: party.h:14
party_join
void party_join(object *op, partylist *party)
Definition: party.c:85
party_get_first
partylist * party_get_first(void)
Definition: party.c:196
party_confirm_password
int party_confirm_password(const partylist *party, const char *password)
Definition: party.c:259
receive_party_password
void receive_party_password(object *op, const char *password)
Definition: c_party.c:53
party_leave
void party_leave(object *op)
Definition: party.c:123
command_help
void command_help(object *op, const char *params)
Definition: c_misc.c:1769
party_set_password
void party_set_password(partylist *party, const char *password)
Definition: party.c:244
say.max
dictionary max
Definition: say.py:148
sproto.h
command_party
void command_party(object *op, const char *params)
Definition: c_party.c:97
list_players
void list_players(object *op, region *reg, partylist *party)
Definition: c_misc.c:550
party_form
partylist * party_form(object *op, const char *partyname)
Definition: party.c:40
party_struct
Definition: party.h:10
MAX_BUF
#define MAX_BUF
Definition: define.h:35
party_get_next
partylist * party_get_next(const partylist *party)
Definition: party.c:208
ST_PLAYING
#define ST_PLAYING
Definition: define.h:541
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
command_gsay
void command_gsay(object *op, const char *params)
Definition: c_party.c:75
spells.h
party_get_password
const char * party_get_password(const partylist *party)
Definition: party.c:232
give.op
op
Definition: give.py:33
party_send_message
void party_send_message(object *op, const char *message)
Definition: party.c:274
roll-o-matic.params
params
Definition: roll-o-matic.py:193
NDI_WHITE
#define NDI_WHITE
Definition: newclient.h:243
buf
StringBuffer * buf
Definition: readable.c:1610
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:309
MSG_TYPE_COMMUNICATION_PARTY
#define MSG_TYPE_COMMUNICATION_PARTY
Definition: newclient.h:627
player_set_state
void player_set_state(player *pl, uint8_t state)
Definition: player.c:4439
MSG_TYPE_COMMUNICATION
#define MSG_TYPE_COMMUNICATION
Definition: newclient.h:410
command_party_rejoin
void command_party_rejoin(object *op, const char *params)
Definition: c_party.c:307
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:319