Crossfire Server, Trunk
c_party.cpp
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 = static_cast<party_rejoin_mode>(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.cpp:292
MSG_TYPE_COMMAND_SUCCESS
#define MSG_TYPE_COMMAND_SUCCESS
Definition: newclient.h:533
get_party_password
int get_party_password(object *op, partylist *party)
Definition: player.cpp:1021
command_gsay
void command_gsay(object *op, const char *params)
Definition: c_party.cpp:75
party_find
partylist * party_find(const char *partyname)
Definition: party.cpp:148
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,...) PRINTF_ARGS(6
rejoin_modes
static const char * rejoin_modes[]
Definition: c_party.cpp:293
MSG_TYPE_COMMAND_ERROR
#define MSG_TYPE_COMMAND_ERROR
Definition: newclient.h:532
partylist
Definition: party.h:10
buf
StringBuffer * buf
Definition: readable.cpp:1565
MSG_TYPE_COMMAND
#define MSG_TYPE_COMMAND
Definition: newclient.h:407
party_join
void party_join(object *op, partylist *party)
Definition: party.cpp:85
party_get_first
partylist * party_get_first(void)
Definition: party.cpp:196
party_confirm_password
int party_confirm_password(const partylist *party, const char *password)
Definition: party.cpp:259
party_leave
void party_leave(object *op)
Definition: party.cpp:123
confirm_party_password
static int confirm_party_password(object *op, const char *password)
Definition: c_party.cpp:38
command_help
void command_help(object *op, const char *params)
Definition: c_misc.cpp:1772
party_set_password
void party_set_password(partylist *party, const char *password)
Definition: party.cpp:244
say.max
dictionary max
Definition: say.py:148
sproto.h
partylist::partyname
char * partyname
Definition: party.h:14
list_players
void list_players(object *op, region *reg, partylist *party)
Definition: c_misc.cpp:550
party_form
partylist * party_form(object *op, const char *partyname)
Definition: party.cpp:40
MAX_BUF
#define MAX_BUF
Definition: define.h:35
party_get_next
partylist * party_get_next(const partylist *party)
Definition: party.cpp:208
ST_PLAYING
#define ST_PLAYING
Definition: define.h:541
command_party_rejoin
void command_party_rejoin(object *op, const char *params)
Definition: c_party.cpp:307
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:265
spells.h
party_get_password
const char * party_get_password(const partylist *party)
Definition: party.cpp:232
give.op
op
Definition: give.py:33
party_send_message
void party_send_message(object *op, const char *message)
Definition: party.cpp:274
roll-o-matic.params
params
Definition: roll-o-matic.py:193
NDI_WHITE
#define NDI_WHITE
Definition: newclient.h:246
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.cpp:308
MSG_TYPE_COMMUNICATION_PARTY
#define MSG_TYPE_COMMUNICATION_PARTY
Definition: newclient.h:630
player_set_state
void player_set_state(player *pl, uint8_t state)
Definition: player.cpp:4471
command_party
void command_party(object *op, const char *params)
Definition: c_party.cpp:97
MSG_TYPE_COMMUNICATION
#define MSG_TYPE_COMMUNICATION
Definition: newclient.h:413
party_rejoin_mode
party_rejoin_mode
Definition: player.h:98
receive_party_password
void receive_party_password(object *op, const char *password)
Definition: c_party.cpp:53