Crossfire Server, Trunk  R20513
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 
36 int confirm_party_password(object *op) {
37  const partylist *party;
38 
39  party = party_find(op->contr->party_to_join->partyname);
40  return party == NULL || !party_confirm_password(party, op->contr->write_buf+1);
41 }
42 
49 void receive_party_password(object *op) {
50  if (confirm_party_password(op) == 0) {
51  party_join(op, op->contr->party_to_join);
52  op->contr->party_to_join = NULL;
54  return;
55  }
56 
58  "You entered the wrong password");
59  op->contr->party_to_join = NULL;
61 }
62 
71 void command_gsay(object *op, const char *params) {
72  char party_params[MAX_BUF];
73 
74  if (*params == '\0') {
76  return;
77  }
78  strcpy(party_params, "say ");
79  strcat(party_params, params);
80  command_party(op, party_params);
81 }
82 
89 static void party_help(object *op) {
91  "To form a party type: party form <partyname>. "
92  "To join a party type: party join <partyname> "
93  "If the party has a passwd, it will you prompt you for it. "
94  "For a list of current parties type: party list. "
95  "To leave a party type: party leave "
96  "To change a passwd for a party type: party passwd <password> "
97  "There is an 8 character maximum password length. "
98  "To talk to party members type: party say <msg> "
99  "To see who is in your party: party who "
100 #ifdef PARTY_KILL_LOG
101  "To see what you've killed, type: party kills"
102 #endif
103  );
104 }
105 
116 void command_party(object *op, const char *params) {
117  char buf[MAX_BUF];
118 
119  if (*params == '\0') {
120  if (op->contr->party == NULL) {
122  "You are not a member of any party. "
123  "For help try: party help");
124  } else {
126  "You are a member of party %s.",
127  op->contr->party->partyname);
128  }
129  return;
130  }
131  if (strcmp(params, "help") == 0) {
132  party_help(op);
133  return;
134  }
135 #ifdef PARTY_KILL_LOG
136  if (!strncmp(params, "kills", 5)) {
137  int i, max;
138  char chr;
139  float exp;
140  partylist *tmpparty;
141 
142  if (op->contr->party == NULL) {
144  "You are not a member of any party.");
145  return;
146  }
147  tmpparty = op->contr->party;
148  if (!tmpparty->kills) {
150  "You haven't killed anything yet.");
151  return;
152  }
153  max = tmpparty->kills-1;
154  if (max > PARTY_KILL_LOG-1)
155  max = PARTY_KILL_LOG-1;
157  "[fixed]Killed | Killer| Exp\n----------------+----------------+--------"
158  "Killed | Killer| Exp\n----------------+----------------+--------");
159 
160 
161  for (i = 0; i <= max; i++) {
162  exp = tmpparty->party_kills[i].exp;
163  chr = ' ';
164  if (exp > 1000000) {
165  exp /= 1000000;
166  chr = 'M';
167  } else if (exp > 1000) {
168  exp /= 1000;
169  chr = 'k';
170  }
171 
173  "[fixed]%16s|%16s|%6.1f%c",
174  tmpparty->party_kills[i].dead,
175  tmpparty->party_kills[i].killer, exp, chr);
176  }
177  exp = tmpparty->total_exp;
178  chr = ' ';
179  if (exp > 1000000) {
180  exp /= 1000000;
181  chr = 'M';
182  } else if (exp > 1000) {
183  exp /= 1000;
184  chr = 'k';
185  }
186 
188  "[fixed]----------------+----------------+--------");
190  "Totals: %d kills, %.1f%c exp", tmpparty->kills,
191  exp, chr);
192  return;
193  }
194 #endif /* PARTY_KILL_LOG */
195  if (strncmp(params, "say ", 4) == 0) {
196  if (op->contr->party == NULL) {
198  "You are not a member of any party.");
199  return;
200  }
201  params += 4;
202  snprintf(buf, MAX_BUF-1, "<%s> %s says: %s", op->contr->party->partyname, op->name, params);
203  party_send_message(op, buf);
205  "<%s> You say: %s",
206  op->contr->party->partyname, params);
207  return;
208  }
209 
210  if (strncmp(params, "form ", 5) == 0) {
211  params += 5;
212 
213  if (party_form(op, params) == NULL) {
215  "The party %s already exists, pick another name",
216  params);
217  return;
218  }
219  return;
220  } /* form */
221 
222  if (strcmp(params, "leave") == 0) {
223  if (op->contr->party == NULL) {
225  "You are not a member of any party.");
226  return;
227  }
228  party_leave(op);
229  return;
230  }
231  if (strcmp(params, "who") == 0) {
232  if (op->contr->party == NULL) {
234  "You are not a member of any party.");
235  return;
236  }
237  list_players(op, NULL, op->contr->party);
238  return;
239  } /* leave */
240 
241  if (strncmp(params, "passwd ", 7) == 0) {
242  params += 7;
243 
244  if (op->contr->party == NULL) {
246  "You are not a member of a party");
247  return;
248  }
249 
250  if (strlen(params) > 8) {
252  "The password must not exceed 8 characters");
253  return;
254  }
255 
256  party_set_password(op->contr->party, params);
258  "The password for party %s is %s",
260 
261  snprintf(buf, MAX_BUF, "Password for party %s is now %s, changed by %s",
263  party_send_message(op, buf);
264  return;
265  } /* passwd */
266 
267  if (strcmp(params, "list") == 0) {
268  partylist *party;
269 
270  if (party_get_first() == NULL) {
272  "There are no parties active right now");
273  return;
274  }
275 
277  "[fixed]Party name Leader\n---------- ------");
278  for (party = party_get_first(); party != NULL; party = party_get_next(party)) {
280  "[fixed]%-32s %s",
281  party->partyname, party_get_leader(party));
282  }
283 
284  return;
285  } /* list */
286 
287  if (strncmp(params, "join ", 5) == 0) {
288  partylist *party;
289 
290  params += 5;
291 
292  party = party_find(params);
293  if (party == NULL) {
295  "Party %s does not exist. You must form it first.",
296  params);
297  return;
298  }
299 
300  if (op->contr->party == party) {
302  "You are already a member of party: %s",
303  party->partyname);
304  return;
305  }
306 
307  if (get_party_password(op, party)) {
308  return;
309  }
310 
311  party_join(op, party);
312  return;
313  } /* join */
314 
315  party_help(op);
316 }
317 
319 static const char *rejoin_modes[] = {
320  "no",
321  "if_exists",
322  "always",
323  NULL
324 };
325 
333 void command_party_rejoin(object *op, const char *params) {
334  int mode;
335 
336  if (*params == '\0') {
338  "party rejoin: %s", rejoin_modes[op->contr->rejoin_party]);
339  return;
340  }
341  for (mode = 0; rejoin_modes[mode] != NULL; mode++) {
342  if (strcmp(rejoin_modes[mode], params) == 0) {
343  op->contr->rejoin_party = mode;
345  "party rejoin is now: %s", rejoin_modes[op->contr->rejoin_party]);
346  return;
347  }
348  }
350  "invalid mode: %50s", params);
351 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Sends message to player(s).
Definition: main.c:315
Spell-related defines: spellpath, subtypes, ...
#define NDI_WHITE
Definition: newclient.h:222
One party.
Definition: party.h:10
void receive_party_password(object *op)
Player entered a party password.
Definition: c_party.c:49
void party_set_password(partylist *party, const char *password)
Sets a party&#39;s password.
Definition: party.c:275
partylist * party_get_next(const partylist *party)
Returns the next party from the list of all parties.
Definition: party.c:229
static const char * rejoin_modes[]
Valid modes for &#39;party_rejoin&#39;, indexed by party_rejoin_mode.
Definition: c_party.c:319
const char * party_get_leader(const partylist *party)
Returns the name of the party&#39;s leader.
Definition: party.c:322
const char * party_get_password(const partylist *party)
Returns the party&#39;s password.
Definition: party.c:263
void command_gsay(object *op, const char *params)
&#39;gsay&#39; command, talks to party.
Definition: c_party.c:71
void party_leave(object *op)
Makes a player leave his party.
Definition: party.c:104
Global type definitions and header inclusions.
char * partyname
Party name.
Definition: party.h:14
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.c:310
#define ST_PLAYING
Usual state.
Definition: define.h:577
partylist * party
Party this player is part of.
Definition: player.h:186
void command_party_rejoin(object *op, const char *params)
Handles the &#39;party_rejoin&#39; command.
Definition: c_party.c:333
static void party_help(object *op)
Give help for party commands.
Definition: c_party.c:89
#define MSG_TYPE_COMMAND
Responses to commands, eg, who.
Definition: newclient.h:379
#define MSG_TYPE_COMMAND_HELP
Help related information.
Definition: newclient.h:514
#define MSG_TYPE_COMMAND_SUCCESS
Successful result from command.
Definition: newclient.h:510
#define MSG_TYPE_COMMAND_ERROR
Bad syntax/can&#39;t use command.
Definition: newclient.h:509
#define snprintf
Definition: win32.h:46
void player_set_state(player *pl, uint8_t state)
Set the player&#39;s state to the specified one.
Definition: player.c:4457
void party_send_message(object *op, const char *message)
Send a message to all party members except the speaker.
Definition: party.c:305
const char * name
The name of the object, obviously...
Definition: object.h:311
#define MSG_TYPE_COMMUNICATION
Communication between players.
Definition: newclient.h:386
struct pl * contr
Pointer to the player which control this object.
Definition: object.h:276
partylist * party_find(const char *partyname)
Find a party by name.
Definition: party.c:147
party_rejoin_mode rejoin_party
Whether to rejoin or not party at login.
Definition: player.h:191
partylist * party_get_first(void)
Returns the first party from the list of all parties.
Definition: party.c:217
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
int confirm_party_password(object *op)
Is the password the player entered to join a party the right one?
Definition: c_party.c:36
void command_party(object *op, const char *params)
&#39;party&#39; command, subdivided in different sub commands.
Definition: c_party.c:116
void party_join(object *op, partylist *party)
Makes a player join a party.
Definition: party.c:84
void list_players(object *op, region *reg, partylist *party)
Displays the players in a region or party.
Definition: c_misc.c:484
int party_confirm_password(const partylist *party, const char *password)
Checks whether a given password matches the party&#39;s password.
Definition: party.c:290
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
partylist * party_form(object *op, const char *partyname)
Forms the party struct for a party called &#39;partyname&#39;.
Definition: party.c:40
char write_buf[MAX_BUF]
Holds arbitrary input from client.
Definition: player.h:174
partylist * party_to_join
Used when player wants to join a party but we will have to get password first so we have to remember ...
Definition: player.h:187
int get_party_password(object *op, partylist *party)
Ask the player for the password of the party she wants to join.
Definition: player.c:996
#define MSG_TYPE_COMMUNICATION_PARTY
Party message.
Definition: newclient.h:622