1 |
elmex |
1.1 |
/* |
2 |
root |
1.21 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
pippijn |
1.15 |
* |
4 |
root |
1.24 |
* Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.19 |
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (©) 1992,2007 Frank Tore Johansen |
7 |
pippijn |
1.15 |
* |
8 |
root |
1.29 |
* Deliantra is free software: you can redistribute it and/or modify it under |
9 |
|
|
* the terms of the Affero GNU General Public License as published by the |
10 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
11 |
|
|
* option) any later version. |
12 |
pippijn |
1.15 |
* |
13 |
root |
1.20 |
* 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 |
pippijn |
1.15 |
* |
18 |
root |
1.29 |
* You should have received a copy of the Affero GNU General Public License |
19 |
|
|
* and the GNU General Public License along with this program. If not, see |
20 |
|
|
* <http://www.gnu.org/licenses/>. |
21 |
root |
1.19 |
* |
22 |
root |
1.21 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
pippijn |
1.15 |
*/ |
24 |
elmex |
1.1 |
|
25 |
|
|
#include <global.h> |
26 |
root |
1.11 |
#include <sproto.h> |
27 |
elmex |
1.1 |
#include <spells.h> |
28 |
|
|
|
29 |
root |
1.22 |
static partylist *firstparty; |
30 |
elmex |
1.1 |
|
31 |
root |
1.4 |
partylist * |
32 |
|
|
get_firstparty (void) |
33 |
elmex |
1.1 |
{ |
34 |
root |
1.4 |
return firstparty; |
35 |
elmex |
1.1 |
} |
36 |
|
|
|
37 |
root |
1.4 |
void |
38 |
|
|
remove_party (partylist *target_party) |
39 |
|
|
{ |
40 |
|
|
if (firstparty == NULL) |
41 |
|
|
{ |
42 |
|
|
LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); |
43 |
|
|
return; |
44 |
|
|
} |
45 |
elmex |
1.1 |
|
46 |
root |
1.10 |
for_all_players (pl) |
47 |
root |
1.4 |
if (pl->party == target_party) |
48 |
|
|
pl->party = NULL; |
49 |
elmex |
1.1 |
|
50 |
root |
1.22 |
partylist **prevlink = &firstparty; |
51 |
root |
1.4 |
|
52 |
root |
1.22 |
for (partylist *p = firstparty; p; p = p->next) |
53 |
|
|
if (p->next == target_party) |
54 |
|
|
{ |
55 |
|
|
prevlink = &p->next; |
56 |
|
|
break; |
57 |
|
|
} |
58 |
root |
1.4 |
|
59 |
root |
1.22 |
*prevlink = target_party->next; |
60 |
root |
1.4 |
|
61 |
root |
1.22 |
free (target_party->partyleader); |
62 |
|
|
free (target_party->partyname); |
63 |
|
|
sfree (target_party); |
64 |
elmex |
1.1 |
} |
65 |
|
|
|
66 |
|
|
/* Remove unused parties, this could be made to scale a lot better. */ |
67 |
root |
1.4 |
void |
68 |
|
|
obsolete_parties (void) |
69 |
|
|
{ |
70 |
|
|
int player_count; |
71 |
|
|
partylist *party; |
72 |
|
|
partylist *next = NULL; |
73 |
|
|
|
74 |
|
|
if (!firstparty) |
75 |
|
|
return; /* we can't obsolete parties if there aren't any */ |
76 |
root |
1.22 |
|
77 |
root |
1.4 |
for (party = firstparty; party != NULL; party = next) |
78 |
|
|
{ |
79 |
|
|
next = party->next; |
80 |
|
|
player_count = 0; |
81 |
root |
1.10 |
for_all_players (pl) |
82 |
root |
1.4 |
if (pl->party == party) |
83 |
|
|
player_count++; |
84 |
|
|
if (player_count == 0) |
85 |
|
|
remove_party (party); |
86 |
elmex |
1.1 |
} |
87 |
|
|
} |
88 |
|
|
|
89 |
root |
1.4 |
void |
90 |
root |
1.17 |
add_kill_to_party (partylist *party, const char *killer, const char *dead, long exp) |
91 |
elmex |
1.1 |
{ |
92 |
root |
1.4 |
int i, pos; |
93 |
elmex |
1.1 |
|
94 |
root |
1.4 |
if (party == NULL) |
95 |
|
|
return; |
96 |
root |
1.12 |
|
97 |
root |
1.4 |
if (party->kills >= PARTY_KILL_LOG) |
98 |
elmex |
1.1 |
{ |
99 |
root |
1.4 |
pos = PARTY_KILL_LOG - 1; |
100 |
|
|
for (i = 0; i < PARTY_KILL_LOG - 1; i++) |
101 |
|
|
party->party_kills[i] = party->party_kills[i + 1]; |
102 |
elmex |
1.1 |
} |
103 |
|
|
else |
104 |
root |
1.4 |
pos = party->kills; |
105 |
root |
1.12 |
|
106 |
elmex |
1.1 |
party->kills++; |
107 |
root |
1.4 |
party->total_exp += exp; |
108 |
|
|
party->party_kills[pos].exp = exp; |
109 |
root |
1.5 |
assign (party->party_kills[pos].killer, killer); |
110 |
|
|
assign (party->party_kills[pos].dead, dead); |
111 |
root |
1.4 |
party->party_kills[pos].killer[MAX_NAME] = 0; |
112 |
|
|
party->party_kills[pos].dead[MAX_NAME] = 0; |
113 |
elmex |
1.1 |
} |
114 |
|
|
|
115 |
root |
1.4 |
int |
116 |
|
|
confirm_party_password (object *op) |
117 |
|
|
{ |
118 |
|
|
partylist *tmppartylist; |
119 |
|
|
|
120 |
|
|
for (tmppartylist = firstparty; tmppartylist != NULL; tmppartylist = tmppartylist->next) |
121 |
|
|
{ |
122 |
|
|
if (!strcmp (op->contr->party_to_join->partyname, tmppartylist->partyname)) |
123 |
|
|
{ |
124 |
|
|
if (strcmp (op->contr->write_buf + 1, tmppartylist->passwd) == 0) |
125 |
|
|
return 0; |
126 |
|
|
else |
127 |
|
|
return 1; |
128 |
root |
1.2 |
} |
129 |
elmex |
1.1 |
} |
130 |
root |
1.4 |
return 1; |
131 |
elmex |
1.1 |
} |
132 |
|
|
|
133 |
root |
1.4 |
void |
134 |
root |
1.22 |
send_party_message (object *op, const char *msg) |
135 |
|
|
{ |
136 |
|
|
for_all_players (pl) |
137 |
|
|
if (pl->ob->contr->party == op->contr->party && pl->ob != op) |
138 |
root |
1.25 |
pl->send_msg (NDI_UNIQUE, MSG_CHANNEL ("party"), msg); |
139 |
root |
1.22 |
} |
140 |
|
|
|
141 |
|
|
void |
142 |
root |
1.4 |
receive_party_password (object *op, char k) |
143 |
|
|
{ |
144 |
|
|
|
145 |
|
|
if (confirm_party_password (op) == 0) |
146 |
|
|
{ |
147 |
|
|
partylist *joined_party = op->contr->party_to_join; |
148 |
|
|
char buf[MAX_BUF]; |
149 |
|
|
|
150 |
|
|
op->contr->party = op->contr->party_to_join; |
151 |
|
|
op->contr->party_to_join = NULL; |
152 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s\n", joined_party->partyname); |
153 |
|
|
snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, joined_party->partyname); |
154 |
|
|
send_party_message (op, buf); |
155 |
root |
1.9 |
op->contr->ns->state = ST_PLAYING; |
156 |
root |
1.4 |
return; |
157 |
|
|
} |
158 |
|
|
else |
159 |
|
|
{ |
160 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "You entered the wrong password"); |
161 |
|
|
op->contr->party_to_join = NULL; |
162 |
root |
1.9 |
op->contr->ns->state = ST_PLAYING; |
163 |
root |
1.4 |
return; |
164 |
|
|
} |
165 |
elmex |
1.1 |
} |
166 |
|
|
|
167 |
root |
1.4 |
int |
168 |
|
|
command_gsay (object *op, char *params) |
169 |
elmex |
1.1 |
{ |
170 |
root |
1.4 |
if (!params) |
171 |
|
|
return 0; |
172 |
root |
1.12 |
|
173 |
root |
1.30 |
command_party (op, (char *)format ("say %s", params)); |
174 |
|
|
|
175 |
elmex |
1.1 |
return 0; |
176 |
|
|
} |
177 |
|
|
|
178 |
root |
1.4 |
int |
179 |
|
|
command_party (object *op, char *params) |
180 |
elmex |
1.1 |
{ |
181 |
root |
1.28 |
dynbuf_text &buf = msg_dynbuf; buf.clear (); |
182 |
|
|
|
183 |
root |
1.22 |
partylist *party = op->contr->party; |
184 |
|
|
|
185 |
|
|
if (!params) |
186 |
|
|
params = (char *)""; |
187 |
elmex |
1.1 |
|
188 |
root |
1.22 |
if (!strcmp (params, "help")) |
189 |
root |
1.27 |
buf << "\n" |
190 |
|
|
" - To form a party type: C<party form> <partyname>\n" |
191 |
root |
1.26 |
" - To join a party type: C<party join> <partyname>\n" |
192 |
|
|
" - If the party has a passwd, it will you prompt you for it.\n" |
193 |
|
|
" - For a list of current parties type: C<party list>\n" |
194 |
|
|
" - To leave a party type: C<party leave>\n" |
195 |
|
|
" - To change a passwd for a party type: C<party passwd> <password>\n" |
196 |
|
|
" - There is an 8 character max\n" |
197 |
|
|
" - To talk to party members type: C<party say> <msg>\n" |
198 |
|
|
" - To see who is in your party: C<party who>\n" |
199 |
|
|
" - To see what you've killed, type: C<party kills>\n"; |
200 |
root |
1.22 |
else if (strncmp (params, "form ", 5) == 0) |
201 |
root |
1.4 |
{ |
202 |
root |
1.22 |
params += 5; |
203 |
|
|
|
204 |
|
|
if (party) |
205 |
|
|
buf << "You are already a member of party " << party->partyname << ". You must leave it first."; |
206 |
root |
1.4 |
else |
207 |
|
|
{ |
208 |
root |
1.22 |
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 |
root |
1.7 |
|
221 |
root |
1.22 |
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 |
root |
1.7 |
|
229 |
root |
1.22 |
buf << "You have formed party: " << party->partyname << "."; |
230 |
elmex |
1.1 |
|
231 |
root |
1.22 |
party->next = firstparty; |
232 |
|
|
op->contr->party = firstparty = party; |
233 |
root |
1.4 |
} |
234 |
elmex |
1.1 |
} |
235 |
root |
1.22 |
else if (strcmp (params, "list") == 0) |
236 |
elmex |
1.1 |
{ |
237 |
root |
1.22 |
if (!firstparty) |
238 |
|
|
buf << "There are no parties active right now"; |
239 |
|
|
else |
240 |
root |
1.4 |
{ |
241 |
root |
1.22 |
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 |
root |
1.4 |
} |
247 |
|
|
} |
248 |
root |
1.22 |
else if (strncmp (params, "join ", 5) == 0) |
249 |
root |
1.4 |
{ |
250 |
root |
1.22 |
params += 5; |
251 |
root |
1.4 |
|
252 |
root |
1.22 |
/* 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 |
root |
1.4 |
else |
258 |
root |
1.22 |
for (partylist *p = firstparty; p; p = p->next) |
259 |
|
|
if (!strcmp (p->partyname, params)) |
260 |
elmex |
1.1 |
{ |
261 |
root |
1.22 |
if (!*p->passwd) |
262 |
root |
1.4 |
{ |
263 |
root |
1.22 |
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 |
root |
1.4 |
} |
271 |
root |
1.22 |
else |
272 |
|
|
get_party_password (op, p); |
273 |
|
|
|
274 |
|
|
goto reply; |
275 |
elmex |
1.1 |
} |
276 |
root |
1.22 |
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 |
root |
1.4 |
else |
289 |
|
|
{ |
290 |
root |
1.22 |
int max = min (party->kills - 1, PARTY_KILL_LOG - 1); |
291 |
|
|
|
292 |
root |
1.26 |
buf << " Killed | Killer| Exp\n" |
293 |
|
|
<< " ----------------+----------------+--------\n"; |
294 |
root |
1.14 |
|
295 |
root |
1.22 |
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 |
root |
1.14 |
|
310 |
root |
1.26 |
buf.printf (" %16s|%16s|%6.1f%c\n", party->party_kills[i].dead, party->party_kills[i].killer, (double)exp, suffix); |
311 |
root |
1.22 |
} |
312 |
root |
1.4 |
|
313 |
root |
1.26 |
buf << " ----------------+----------------+--------\n"; |
314 |
root |
1.7 |
|
315 |
root |
1.4 |
{ |
316 |
root |
1.22 |
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 |
root |
1.4 |
{ |
326 |
root |
1.22 |
exp /= 1000; |
327 |
|
|
suffix = 'k'; |
328 |
root |
1.4 |
} |
329 |
root |
1.22 |
|
330 |
root |
1.26 |
buf.printf (" Totals: %d kills, %.1f%c exp", party->kills, (double)exp, suffix); |
331 |
root |
1.4 |
} |
332 |
root |
1.22 |
} |
333 |
|
|
} |
334 |
|
|
else if (strncmp (params, "say ", 4) == 0) |
335 |
root |
1.4 |
{ |
336 |
root |
1.22 |
params += 4; |
337 |
elmex |
1.1 |
|
338 |
root |
1.22 |
buf << "[" << party->partyname << "] " << op->name << " says: " << params; |
339 |
|
|
send_party_message (op, buf); |
340 |
|
|
buf.clear (); |
341 |
elmex |
1.1 |
|
342 |
root |
1.22 |
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 |
elmex |
1.1 |
|
350 |
root |
1.22 |
buf << "You leave party " << party->partyname << "."; |
351 |
elmex |
1.1 |
|
352 |
root |
1.22 |
op->contr->party = 0; |
353 |
|
|
obsolete_parties (); |
354 |
|
|
} |
355 |
|
|
else if (strcmp (params, "who") == 0) |
356 |
root |
1.4 |
{ |
357 |
root |
1.26 |
buf << "Members of party " << party->partyname << ".\n"; |
358 |
elmex |
1.1 |
|
359 |
root |
1.22 |
for_all_players (pl) |
360 |
|
|
if (pl->ob->contr->party == party) |
361 |
root |
1.26 |
buf.printf (" - %s/%d %s\n\n", &pl->ob->name, pl->ob->level, |
362 |
root |
1.22 |
*pl->ob->contr->own_title ? pl->ob->contr->own_title : pl->ob->contr->title); |
363 |
|
|
} |
364 |
|
|
else if (strncmp (params, "passwd ", 7) == 0) |
365 |
root |
1.4 |
{ |
366 |
root |
1.22 |
params += 7; |
367 |
elmex |
1.1 |
|
368 |
root |
1.22 |
if (strlen (params) > 8) |
369 |
|
|
buf << "The password must not exceed 8 characters"; |
370 |
|
|
else |
371 |
root |
1.4 |
{ |
372 |
root |
1.22 |
strcpy (party->passwd, params); |
373 |
|
|
buf << "The password for party " << party->partyname << " is set to B<" << params << "> by " << &op->name; |
374 |
elmex |
1.1 |
} |
375 |
root |
1.22 |
} |
376 |
|
|
else |
377 |
|
|
buf << "I did not understand your command. For help try: C<party help>"; |
378 |
elmex |
1.1 |
|
379 |
root |
1.22 |
reply: |
380 |
root |
1.25 |
op->contr->send_msg (NDI_UNIQUE | NDI_REPLY, MSG_CHANNEL ("party"), buf); |
381 |
elmex |
1.1 |
|
382 |
|
|
return 1; |
383 |
|
|
} |