ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_party.C
Revision: 1.22
Committed: Thu Apr 24 04:40:31 2008 UTC (16 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.21: +177 -380 lines
Log Message:
rewrote party commands

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra 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 <support@deliantra.net>
22 */
23
24 #include <global.h>
25 #include <sproto.h>
26 #include <spells.h>
27
28 static partylist *firstparty;
29
30 partylist *
31 get_firstparty (void)
32 {
33 return firstparty;
34 }
35
36 void
37 remove_party (partylist *target_party)
38 {
39 if (firstparty == NULL)
40 {
41 LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname);
42 return;
43 }
44
45 for_all_players (pl)
46 if (pl->party == target_party)
47 pl->party = NULL;
48
49 partylist **prevlink = &firstparty;
50
51 for (partylist *p = firstparty; p; p = p->next)
52 if (p->next == target_party)
53 {
54 prevlink = &p->next;
55 break;
56 }
57
58 *prevlink = target_party->next;
59
60 free (target_party->partyleader);
61 free (target_party->partyname);
62 sfree (target_party);
63 }
64
65 /* Remove unused parties, this could be made to scale a lot better. */
66 void
67 obsolete_parties (void)
68 {
69 int player_count;
70 partylist *party;
71 partylist *next = NULL;
72
73 if (!firstparty)
74 return; /* we can't obsolete parties if there aren't any */
75
76 for (party = firstparty; party != NULL; party = next)
77 {
78 next = party->next;
79 player_count = 0;
80 for_all_players (pl)
81 if (pl->party == party)
82 player_count++;
83 if (player_count == 0)
84 remove_party (party);
85 }
86 }
87
88 void
89 add_kill_to_party (partylist *party, const char *killer, const char *dead, long exp)
90 {
91 int i, pos;
92
93 if (party == NULL)
94 return;
95
96 if (party->kills >= PARTY_KILL_LOG)
97 {
98 pos = PARTY_KILL_LOG - 1;
99 for (i = 0; i < PARTY_KILL_LOG - 1; i++)
100 party->party_kills[i] = party->party_kills[i + 1];
101 }
102 else
103 pos = party->kills;
104
105 party->kills++;
106 party->total_exp += exp;
107 party->party_kills[pos].exp = exp;
108 assign (party->party_kills[pos].killer, killer);
109 assign (party->party_kills[pos].dead, dead);
110 party->party_kills[pos].killer[MAX_NAME] = 0;
111 party->party_kills[pos].dead[MAX_NAME] = 0;
112 }
113
114 int
115 confirm_party_password (object *op)
116 {
117 partylist *tmppartylist;
118
119 for (tmppartylist = firstparty; tmppartylist != NULL; tmppartylist = tmppartylist->next)
120 {
121 if (!strcmp (op->contr->party_to_join->partyname, tmppartylist->partyname))
122 {
123 if (strcmp (op->contr->write_buf + 1, tmppartylist->passwd) == 0)
124 return 0;
125 else
126 return 1;
127 }
128 }
129 return 1;
130 }
131
132 void
133 send_party_message (object *op, const char *msg)
134 {
135 for_all_players (pl)
136 if (pl->ob->contr->party == op->contr->party && pl->ob != op)
137 new_draw_info (NDI_WHITE, 0, pl->ob, msg);
138 }
139
140 void
141 receive_party_password (object *op, char k)
142 {
143
144 if (confirm_party_password (op) == 0)
145 {
146 partylist *joined_party = op->contr->party_to_join;
147 char buf[MAX_BUF];
148
149 op->contr->party = op->contr->party_to_join;
150 op->contr->party_to_join = NULL;
151 new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s\n", joined_party->partyname);
152 snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, joined_party->partyname);
153 send_party_message (op, buf);
154 op->contr->ns->state = ST_PLAYING;
155 return;
156 }
157 else
158 {
159 new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password");
160 op->contr->party_to_join = NULL;
161 op->contr->ns->state = ST_PLAYING;
162 return;
163 }
164 }
165
166 int
167 command_gsay (object *op, char *params)
168 {
169 char party_params[MAX_BUF];
170
171 if (!params)
172 return 0;
173
174 strcpy (party_params, "say ");
175 strcat (party_params, params);
176 command_party (op, party_params);
177 return 0;
178 }
179
180 int
181 command_party (object *op, char *params)
182 {
183 dynbuf_text buf;
184 partylist *party = op->contr->party;
185
186 if (!params)
187 params = (char *)"";
188
189 if (!strcmp (params, "help"))
190 buf << "To form a party type: C<party form> <partyname>\n\n"
191 "To join a party type: C<party join> <partyname>\n\n"
192 "If the party has a passwd, it will you prompt you for it.\n\n"
193 "For a list of current parties type: C<party list>\n\n"
194 "To leave a party type: C<party leave>\n\n"
195 "To change a passwd for a party type: C<party passwd> <password>\n\n"
196 "There is an 8 character max\n\n"
197 "To talk to party members type: C<party say> <msg>\n\n"
198 "To see who is in your party: C<party who>\n\n"
199 "To see what you've killed, type: C<party kills>";
200 else if (strncmp (params, "form ", 5) == 0)
201 {
202 params += 5;
203
204 if (party)
205 buf << "You are already a member of party " << party->partyname << ". You must leave it first.";
206 else
207 {
208 for (partylist *tmpparty = firstparty; tmpparty; tmpparty = tmpparty->next)
209 {
210 if (!strcmp (tmpparty->partyname, params))
211 {
212 buf << "The party " << tmpparty->partyname << " already exists, pick another name";
213 goto reply;
214 }
215 }
216
217 /* Forms the party struct for a party called 'params'. it is the responsibility
218 * of the caller to ensure that the name is unique, and that it is placed in the
219 * main party list correctly */
220
221 party = salloc0<partylist> ();
222 party->partyname = strdup (params);
223 party->total_exp = 0;
224 party->kills = 0;
225 party->passwd[0] = '\0';
226 party->next = NULL;
227 party->partyleader = strdup (op->name);
228
229 buf << "You have formed party: " << party->partyname << ".";
230
231 party->next = firstparty;
232 op->contr->party = firstparty = party;
233 }
234 }
235 else if (strcmp (params, "list") == 0)
236 {
237 if (!firstparty)
238 buf << "There are no parties active right now";
239 else
240 {
241 buf << "Party name Leader\n\n"
242 "---------- ------\n\n";
243
244 for (partylist *p = firstparty; p; p = p->next)
245 buf.printf ("%-32s %s\n\n", p->partyname, p->partyleader);
246 }
247 }
248 else if (strncmp (params, "join ", 5) == 0)
249 {
250 params += 5;
251
252 /* Can't join a party cause non exist */
253 if (!firstparty)
254 buf << "Party: " << params << " does not exist. You must form it first.";
255 else if (party)
256 buf << "You are already a member of party " << party->partyname << ". You must leave it first.";
257 else
258 for (partylist *p = firstparty; p; p = p->next)
259 if (!strcmp (p->partyname, params))
260 {
261 if (!*p->passwd)
262 {
263 op->contr->party = p;
264
265 buf << op->name << " joins party " << p->partyname << ".";
266 send_party_message (op, buf);
267 buf.clear ();
268
269 buf << "You have joined party: " << p->partyname << ".";
270 }
271 else
272 get_party_password (op, p);
273
274 goto reply;
275 }
276 else
277 buf << "Party " << params << " does not exist. You must form it first.";
278 }
279 else if (!party)
280 buf << "You are not a member of any party.\n\n"
281 "For help try: C<party help>";
282 else if (!*params)
283 buf << "You are a member of party " << party->partyname << ".";
284 else if (!strncmp (params, "kills", 5))
285 {
286 if (!party->kills)
287 buf << "You haven't killed anything yet.";
288 else
289 {
290 int max = min (party->kills - 1, PARTY_KILL_LOG - 1);
291
292 buf << "Killed | Killer| Exp\n\n"
293 << "----------------+----------------+--------\n\n";
294
295 for (int i = 0; i <= max; i++)
296 {
297 sint64 exp = party->party_kills[i].exp;
298 char suffix = ' ';
299 if (exp > 1000000)
300 {
301 exp /= 1000000;
302 suffix = 'M';
303 }
304 else if (exp > 1000)
305 {
306 exp /= 1000;
307 suffix = 'k';
308 }
309
310 buf.printf ("%16s|%16s|%6.1f%c\n\n", party->party_kills[i].dead, party->party_kills[i].killer, (double)exp, suffix);
311 }
312
313 buf << "----------------+----------------+--------\n\n";
314
315 {
316 sint64 exp = party->total_exp;
317 char suffix = ' ';
318
319 if (exp > 1000000)
320 {
321 exp /= 1000000;
322 suffix = 'M';
323 }
324 else if (exp > 1000)
325 {
326 exp /= 1000;
327 suffix = 'k';
328 }
329
330 buf.printf ("Totals: %d kills, %.1f%c exp", party->kills, (double)exp, suffix);
331 }
332 }
333 }
334 else if (strncmp (params, "say ", 4) == 0)
335 {
336 params += 4;
337
338 buf << "[" << party->partyname << "] " << op->name << " says: " << params;
339 send_party_message (op, buf);
340 buf.clear ();
341
342 buf << "[" << party->partyname << "] You say: " << params;
343 }
344 else if (strcmp (params, "leave") == 0)
345 {
346 buf << op->name << " leaves party " << party->partyname << ".";
347 send_party_message (op, buf);
348 buf.clear ();
349
350 buf << "You leave party " << party->partyname << ".";
351
352 op->contr->party = 0;
353 obsolete_parties ();
354 }
355 else if (strcmp (params, "who") == 0)
356 {
357 buf << "Members of party " << party->partyname << ".\n\n";
358
359 for_all_players (pl)
360 if (pl->ob->contr->party == party)
361 buf.printf ("%s/%d %s", &pl->ob->name, pl->ob->level,
362 *pl->ob->contr->own_title ? pl->ob->contr->own_title : pl->ob->contr->title);
363 }
364 else if (strncmp (params, "passwd ", 7) == 0)
365 {
366 params += 7;
367
368 if (strlen (params) > 8)
369 buf << "The password must not exceed 8 characters";
370 else
371 {
372 strcpy (party->passwd, params);
373 buf << "The password for party " << party->partyname << " is set to B<" << params << "> by " << &op->name;
374 }
375 }
376 else
377 buf << "I did not understand your command. For help try: C<party help>";
378
379 reply:
380 op->contr->send_msg (NDI_UNIQUE | NDI_REPLY, MSG_CHANNEL("party"), buf);
381
382 return 1;
383 }