Crossfire Server, Trunk  1.75.0
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);
184  party_send_message(op, buf);
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",
241 
242  snprintf(buf, MAX_BUF, "Password for party %s is now %s, changed by %s",
244  party_send_message(op, buf);
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)
Returns the name of the party's leader.
Definition: party.cpp:292
MSG_TYPE_COMMAND_SUCCESS
#define MSG_TYPE_COMMAND_SUCCESS
Successful result from command.
Definition: newclient.h:534
get_party_password
int get_party_password(object *op, partylist *party)
Ask the player for the password of the party she wants to join.
Definition: player.cpp:1026
command_gsay
void command_gsay(object *op, const char *params)
'gsay' command, talks to party.
Definition: c_party.cpp:75
party_find
partylist * party_find(const char *partyname)
Find a party by name.
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[]
Valid modes for 'party_rejoin', indexed by party_rejoin_mode.
Definition: c_party.cpp:293
MSG_TYPE_COMMAND_ERROR
#define MSG_TYPE_COMMAND_ERROR
Bad syntax/can't use command.
Definition: newclient.h:533
partylist
One party.
Definition: party.h:10
buf
StringBuffer * buf
Definition: readable.cpp:1565
MSG_TYPE_COMMAND
#define MSG_TYPE_COMMAND
Responses to commands, eg, who.
Definition: newclient.h:408
draw_ext_info
vs only yadda is in because all tags get reset on the next draw_ext_info In the second since it is all in one draw_ext_info
Definition: media-tags.txt:61
party_join
void party_join(object *op, partylist *party)
Makes a player join a party.
Definition: party.cpp:85
party_get_first
partylist * party_get_first(void)
Returns the first party from the list of all parties.
Definition: party.cpp:196
object::contr
struct player * contr
Pointer to the player which control this object.
Definition: object.h:284
party_confirm_password
int party_confirm_password(const partylist *party, const char *password)
Checks whether a given password matches the party's password.
Definition: party.cpp:259
party_leave
void party_leave(object *op)
Makes a player leave his party.
Definition: party.cpp:123
confirm_party_password
static int confirm_party_password(object *op, const char *password)
Is the password the player entered to join a party the right one?
Definition: c_party.cpp:38
command_help
void command_help(object *op, const char *params)
Player is asking for some help.
Definition: c_misc.cpp:1772
party_set_password
void party_set_password(partylist *party, const char *password)
Sets a party's password.
Definition: party.cpp:244
sproto.h
partylist::partyname
char * partyname
Party name.
Definition: party.h:14
list_players
void list_players(object *op, region *reg, partylist *party)
Displays the players in a region or party.
Definition: c_misc.cpp:550
party_form
partylist * party_form(object *op, const char *partyname)
Forms the party struct for a party called 'partyname'.
Definition: party.cpp:40
MAX_BUF
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
party_get_next
partylist * party_get_next(const partylist *party)
Returns the next party from the list of all parties.
Definition: party.cpp:208
ST_PLAYING
#define ST_PLAYING
Usual state.
Definition: define.h:535
command_party_rejoin
void command_party_rejoin(object *op, const char *params)
Handles the 'party_rejoin' command.
Definition: c_party.cpp:307
NDI_UNIQUE
#define NDI_UNIQUE
Print immediately, don't buffer.
Definition: newclient.h:266
spells.h
object::name
sstring name
The name of the object, obviously...
Definition: object.h:319
party_get_password
const char * party_get_password(const partylist *party)
Returns the party's password.
Definition: party.cpp:232
player::party_to_join
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:204
party_send_message
void party_send_message(object *op, const char *message)
Send a message to all party members except the speaker.
Definition: party.cpp:274
NDI_WHITE
#define NDI_WHITE
Definition: newclient.h:247
player::party
partylist * party
Party this player is part of.
Definition: player.h:203
MSG_TYPE_COMMUNICATION_PARTY
#define MSG_TYPE_COMMUNICATION_PARTY
Party message.
Definition: newclient.h:631
player_set_state
void player_set_state(player *pl, uint8_t state)
Set the player's state to the specified one.
Definition: player.cpp:4485
command_party
void command_party(object *op, const char *params)
'party' command, subdivided in different sub commands.
Definition: c_party.cpp:97
MSG_TYPE_COMMUNICATION
#define MSG_TYPE_COMMUNICATION
Communication between players.
Definition: newclient.h:414
party_rejoin_mode
party_rejoin_mode
Whether to rejoin party at login or not.
Definition: player.h:98
receive_party_password
void receive_party_password(object *op, const char *password)
Player entered a party password.
Definition: c_party.cpp:53
player::rejoin_party
party_rejoin_mode rejoin_party
Whether to rejoin or not party at login.
Definition: player.h:210