]>
Commit | Line | Data |
---|---|---|
96f71fee | 1 | #include "aClient.h" |
c1068b6e | 2 | #include "config.h" |
3 | #include "extern.h" | |
96f71fee | 4 | #include "flags.h" |
85ce9d3e | 5 | #include "list.h" |
586cf465 | 6 | #include "level.h" |
96f71fee | 7 | #include "sockhelp.h" |
8 | ||
85ce9d3e | 9 | #include <cctype> |
fb37ecc7 | 10 | #include <fstream> |
11 | ||
12 | using std::ifstream; | |
13 | using std::ofstream; | |
85bcf836 | 14 | using std::ios; |
c1068b6e | 15 | |
16 | #if defined(HAVE_CRYPT_H) | |
17 | ||
e3c5fe46 | 18 | #include <crypt.h> |
85ce9d3e | 19 | |
c1068b6e | 20 | #elif defined(HAVE_UNISTD_H) |
21 | ||
22 | #include <unistd.h> | |
23 | ||
24 | #endif | |
c8ada07e | 25 | |
fc9d2643 | 26 | |
7031d99e | 27 | Monster boss; // The boss monster |
42106907 | 28 | Level levels[LEVELS]; // The newest way to store monsters |
bf3a2ff9 | 29 | |
c8ada07e | 30 | Monster *masters[LEVELS]; // A master for each level |
85ce9d3e | 31 | |
a8fb9757 | 32 | // Database functions |
85ce9d3e | 33 | int save_gs_dbase(); |
34 | int load_gs_dbase(); | |
35 | ||
36 | // String functions | |
653c4f62 | 37 | #ifndef HAVE_STRTOK |
85ce9d3e | 38 | char *strtok(char *str, const char *delim); |
653c4f62 | 39 | #endif |
40 | ||
85ce9d3e | 41 | int stricmp(const char *s1, const char *s2); |
42 | int strnicmp(const char *s1, const char *s2, size_t len); | |
43 | // String Functions | |
44 | ||
e3c5fe46 | 45 | /********** Password functions **********/ |
46 | ||
47 | bool passcmp(char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one | |
48 | ||
49 | bool check_password(char *name, char *plaintext); // Finds a password for the given name, and checks it with passcmp against the plaintext password given. | |
50 | ||
51 | /********** Password functions **********/ | |
52 | ||
53 | ||
54 | /********** GameServ Booleans **********/ | |
55 | ||
05c527e6 | 56 | bool shuttingdown; |
40251952 | 57 | bool timedOut(Player *p); |
14e24ba1 | 58 | void updateTS(Player *p); |
40251952 | 59 | void timeOutEvent(Player *p); |
60 | ||
e3c5fe46 | 61 | bool is_playing(char *u); // True if the given nickname in the clients list is playing. |
1af35752 | 62 | bool is_playing(aClient *user); |
63 | ||
e3c5fe46 | 64 | bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything. |
1af35752 | 65 | bool is_fighting(aClient *user); |
66 | ||
e3c5fe46 | 67 | bool player_fight(char *u); // True if the player is fighting another player. |
1af35752 | 68 | bool player_fight(aClient *user); |
69 | ||
e3c5fe46 | 70 | bool master_fight(char *u); // True if the player is fighting their master. |
1af35752 | 71 | bool master_fight(aClient *user); |
e3c5fe46 | 72 | |
73 | /********** GameServ Booleans **********/ | |
85ce9d3e | 74 | |
c7340cbd | 75 | void display_help(char *u, char *file = NULL); |
85ce9d3e | 76 | void display_monster(char *u); |
77 | void display_players(char *u); | |
83cf716f | 78 | void display_players(aClient *user); |
85ce9d3e | 79 | long int chartoint(char ch); |
80 | int isstringnum(char *num); | |
81 | long int pow (int x, int y); | |
82 | long int stringtoint(char *number); | |
83 | ||
84 | char *spaces(int len, char *seperator); | |
44ea29f7 | 85 | void refresh(Player *p); |
85ce9d3e | 86 | void refreshall(); |
40251952 | 87 | void updateTS(Player *p); |
ee38284f | 88 | void reset(Player *p); |
c8ada07e | 89 | void init_masters(); |
4dde2ed9 | 90 | bool load_monsters(); |
c8ada07e | 91 | void delete_monsters(); |
92 | void delete_masters(); | |
85ce9d3e | 93 | |
96f71fee | 94 | void do_admin(char *u); |
c7340cbd | 95 | void do_attack(char *u); |
96 | void do_bank(char *u); | |
70065ca1 | 97 | void do_check(char *u); |
c7340cbd | 98 | void do_fight(char *u); |
99 | void do_heal(char *u); | |
100 | void do_help(char *u); | |
85ce9d3e | 101 | void do_identify(char *u); |
9cda831c | 102 | void do_inventory(char *u); |
c7340cbd | 103 | void do_refresh(char *u); |
104 | void do_register(char *u); | |
105 | void do_list(char *u); | |
b0359af9 | 106 | void do_logout(char *u); |
c7340cbd | 107 | void do_master(char *u); |
fcca861d | 108 | void do_dragon(char *u); |
85ce9d3e | 109 | void do_play(char *u); |
110 | void do_quitg(char *u); | |
111 | void do_reset(char *u); | |
85ce9d3e | 112 | void do_run(char *u); |
85ce9d3e | 113 | void do_stats(char *u); |
c7340cbd | 114 | void do_store(char *u); |
f5c25639 | 115 | void do_tavern(char *u); |
83cf716f | 116 | void do_use(char *u); |
c7340cbd | 117 | void see_master(char *u); |
85ce9d3e | 118 | |
b0359af9 | 119 | void logout(aClient *user); |
85ce9d3e | 120 | void showstats(const char *u, const char *nick); |
c62d75be | 121 | void showinventory(aClient *from, aClient *to); |
e282e9d2 | 122 | void showBankBalance(const char *u); |
83cf716f | 123 | void end_turn(aClient *user); |
85ce9d3e | 124 | |
125 | #define WNA 16 | |
126 | char *weapons[WNA] = { "Fists", "Stick", "Dagger", "Quarterstaff", "Short Sword", | |
127 | "Long Sword", "Silver Spear", "Battle Axe", "The Ragnarok", | |
128 | "Chain Saw", "Poison Sword", "Flame Sword", "Earth Hammer", | |
129 | "Light Saber", "Masamune", "Mystical Sword"}; | |
130 | ||
b410b364 | 131 | char *armors[WNA] = { "Birthday Suit", "Clothes", "Leather Vest", "Chain Mail", "Plate Armor", |
85ce9d3e | 132 | "Full Body Armor", "Magic Mail", "Graphite Suit", "Steel Suit", |
133 | "Force Field", "Armor of Light", "Mythril Vest", "DemiGod Armor", | |
e7a0d0ab | 134 | "Hades' Cloak", "Dragon Scales", "Adamantium"}; |
85ce9d3e | 135 | |
136 | int prices[WNA - 1] = {200, 1000, 3000, 10000, 30000, 100000, 150000, 200000, 400000, | |
137 | 1000000, 4000000, 10000000, 40000000, 100000000, 400000000}; | |
b410b364 | 138 | int webonus[WNA] = {2, 10, 15, 25, 35, 45, 65, 85, 125, 185, 255, 355, 505, 805, 1205, 1805}; |
139 | int arbonus[WNA] = {2, 3, 5, 10, 15, 25, 35, 50, 75, 100, 150, 225, 300, 400, 600, 1000}; | |
85ce9d3e | 140 | |
141 | int hpbonus[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550}; | |
142 | int strbonus[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200}; | |
143 | int defbonus[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150}; | |
144 | ||
85ce9d3e | 145 | void gameserv(char *source, char *buf) |
146 | { | |
448a1531 | 147 | char *cmd, z; |
85ce9d3e | 148 | cmd = strtok(buf, " "); |
149 | ||
fc9d2643 | 150 | #ifndef P10 |
151 | source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text | |
152 | #endif | |
153 | ||
448a1531 | 154 | z = cmd[0]; |
155 | if (z == ':') | |
fc9d2643 | 156 | cmd++; // Get rid of that : at the beginning of the :text (command) |
85ce9d3e | 157 | |
9f8c2acc | 158 | #ifdef DEBUGMODE |
159 | log("Source: %s Command: %s", source, cmd); | |
160 | #endif | |
161 | ||
0eeaca4c | 162 | if (strnicmp(cmd, "\1PING", 6) == 0) |
85ce9d3e | 163 | { |
44ea29f7 | 164 | char *ts; |
165 | ts = strtok(NULL, "\1"); | |
166 | notice(s_GameServ, source, "\1PING %s\1", ts); | |
0eeaca4c | 167 | } else if (stricmp(cmd, "\1VERSION\1") == 0) { |
a3017ab1 | 168 | notice(s_GameServ, source, "\1VERSION %s %s\1", PACKAGE, VERSION); |
85ce9d3e | 169 | } else if (stricmp(cmd, "SEARCH") == 0) { |
170 | cmd = strtok(NULL, " "); | |
171 | ||
172 | if (!cmd) | |
173 | notice(s_GameServ, source, "SYNTAX: /msg %S SEARCH FOREST"); | |
174 | else | |
175 | do_forest(source); | |
1af35752 | 176 | |
85ce9d3e | 177 | } else if (stricmp(cmd, "FIGHT") == 0) { |
178 | do_fight(source); | |
179 | } else if (stricmp(cmd, "ATTACK") == 0) { | |
180 | do_attack(source); | |
70065ca1 | 181 | } else if (stricmp(cmd, "CHECK") == 0) { |
182 | do_check(source); | |
c8ada07e | 183 | } else if (stricmp(cmd, "RUN") == 0) { |
184 | do_run(source); | |
83cf716f | 185 | } else if (stricmp(cmd, "USE") == 0) { |
186 | do_use(source); | |
85ce9d3e | 187 | } else if (stricmp(cmd, "HEAL") == 0) { |
188 | do_heal(source); | |
9cda831c | 189 | } else if (stricmp(cmd, "INVENTORY") == 0) { |
190 | do_inventory(source); | |
ab4f4ec0 | 191 | } else if (stricmp(cmd, "MASTER") == 0) { |
192 | do_master(source); | |
fcca861d | 193 | } else if (stricmp(cmd, "DRAGON") == 0) { |
194 | do_dragon(source); | |
ad7dfaa0 | 195 | } else if (stricmp(cmd, "STORE") == 0) { |
196 | do_store(source); | |
8c126acc | 197 | } else if (stricmp(cmd, "BANK") == 0) { |
198 | do_bank(source); | |
96f71fee | 199 | } else if (stricmp(cmd, "ADMIN") == 0) { |
200 | do_admin(source); | |
c7340cbd | 201 | } else if (stricmp(cmd, "REFRESH") == 0) { |
96f71fee | 202 | do_refresh(source); |
ee38284f | 203 | } else if (stricmp(cmd, "RESET") == 0) { |
204 | do_reset(source); | |
f5c25639 | 205 | } else if (stricmp(cmd, "TAVERN") == 0) { |
206 | do_tavern(source); | |
85ce9d3e | 207 | } else if (stricmp(cmd, "LIST") == 0) { |
208 | do_list(source); | |
b0359af9 | 209 | } else if (stricmp(cmd, "LOGOUT") == 0) { |
210 | do_logout(source); | |
174e7f8f | 211 | } else if (stricmp(cmd, "NEWS") == 0) { |
5aa1d28d | 212 | do_news(source); |
85ce9d3e | 213 | } else if (stricmp(cmd, "REGISTER") == 0) { |
214 | do_register(source); | |
215 | } else if (stricmp(cmd, "IDENTIFY") == 0) { | |
216 | do_identify(source); | |
217 | } else if (stricmp(cmd, "HELP") == 0) { | |
c7340cbd | 218 | do_help(source); |
85ce9d3e | 219 | } else if (stricmp(cmd, "STATS") == 0) { |
220 | do_stats(source); | |
221 | } else if (stricmp(cmd, "SHUTDOWN") == 0) { | |
96f71fee | 222 | aClient *user; |
223 | ||
224 | if (!(user = find(source))) | |
45a84400 | 225 | { |
96f71fee | 226 | notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin"); |
9f8c2acc | 227 | log("Error: aClient not found: %s", source); |
96f71fee | 228 | } |
229 | else if (!isAdmin(user)) | |
230 | { | |
231 | notice(s_GameServ, source, "You must be a %S admin to use this command!"); | |
45a84400 | 232 | } |
233 | else | |
234 | { | |
96f71fee | 235 | save_gs_dbase(); |
23ec3ff4 | 236 | #ifdef P10 |
ce61cdfa | 237 | raw("[] SQ %s 0 :leaving: %s used the Shutdown command.", servername, user->getRealNick()); |
23ec3ff4 | 238 | #else |
4e5760fd | 239 | raw("SQUIT %s :leaving: %s used the Shutdown command.", servername, source); |
23ec3ff4 | 240 | #endif |
05c527e6 | 241 | shuttingdown = true; |
45a84400 | 242 | } |
85ce9d3e | 243 | } else if (stricmp(cmd, "SAVE") == 0) { |
96f71fee | 244 | aClient *user; |
245 | ||
246 | if (!(user = find(source))) | |
247 | { | |
248 | notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin"); | |
9f8c2acc | 249 | log("Error: aClient not found: %s", source); |
96f71fee | 250 | } |
251 | else if (!isAdmin(user)) | |
252 | { | |
253 | notice(s_GameServ, source, "You must be a %S admin to use this command!"); | |
254 | } | |
255 | else | |
45a84400 | 256 | { |
257 | save_gs_dbase(); | |
258 | } | |
85ce9d3e | 259 | } else if (stricmp(cmd, "LOAD") == 0) { |
96f71fee | 260 | aClient *user; |
261 | ||
262 | if (!(user = find(source))) | |
263 | { | |
264 | notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin"); | |
5d04eb42 | 265 | log("Error: aClient not found: %s", source); |
96f71fee | 266 | } |
267 | else if (!isAdmin(user)) | |
268 | { | |
269 | notice(s_GameServ, source, "You must be a %S admin to use this command!"); | |
270 | } | |
271 | else | |
45a84400 | 272 | { |
4dde2ed9 | 273 | char *cmd2 = strtok(NULL, " "); |
274 | if (!cmd2) | |
275 | { | |
276 | notice(s_GameServ, source, "Loading player data from %s", playerdata); | |
277 | load_gs_dbase(); | |
278 | } | |
279 | else if (stricmp(cmd2, "MONSTERS") == 0) | |
280 | { | |
281 | notice(s_GameServ, source, "Loading monster data from %s", monsterdata); | |
282 | load_monsters(); | |
283 | } | |
284 | else | |
285 | display_help(source, cmd); | |
45a84400 | 286 | } |
8450c018 | 287 | #ifdef DEBUGMODE |
85ce9d3e | 288 | } else if (stricmp(cmd, "RAW") == 0) { |
96f71fee | 289 | aClient *user; |
290 | ||
291 | if (!(user = find(source))) | |
292 | { | |
293 | notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin"); | |
9f8c2acc | 294 | log("Error: aClient not found: %s", source); |
96f71fee | 295 | } |
296 | else if (!isAdmin(user)) | |
297 | { | |
298 | notice(s_GameServ, source, "You must be a %S admin to use this command!"); | |
299 | } | |
300 | else | |
45a84400 | 301 | { |
302 | char *rest = strtok(NULL, ""); | |
303 | raw("%s", rest); | |
304 | } | |
bf3a2ff9 | 305 | } else if (stricmp(cmd, "PRINT") == 0) { |
306 | for (int x = 0; x < LEVELS; x++) | |
42106907 | 307 | levels[x].monsters.print(); |
8450c018 | 308 | #endif |
42ec1800 | 309 | } else { |
448a1531 | 310 | aClient *user; |
311 | if ((user = find(source))) | |
312 | { | |
313 | if (isIgnore(user)) | |
314 | { | |
315 | #ifdef DEBUGMODE | |
316 | log("Ignoring %s.", user->getNick()); | |
317 | #endif | |
318 | } | |
319 | else | |
320 | { | |
321 | notice(s_GameServ, source, "Unknown command \002%s\002. Type /msg %S \002HELP\002 to get a list of commands.", cmd); | |
322 | } | |
323 | } | |
c7340cbd | 324 | } |
85ce9d3e | 325 | |
448a1531 | 326 | #ifndef P10 |
327 | source--; // Bring the ':' back so we don't leak memory | |
328 | #endif | |
329 | if (z == ':') | |
330 | cmd--; // Same thing :) | |
85ce9d3e | 331 | } |
332 | ||
333 | int stricmp(const char *s1, const char *s2) | |
334 | { | |
335 | register int c; | |
336 | ||
337 | while ((c = tolower(*s1)) == tolower(*s2)) { | |
338 | if (c == 0) | |
339 | return 0; | |
340 | s1++; | |
341 | s2++; | |
342 | } | |
343 | if (c < tolower(*s2)) | |
344 | return -1; | |
345 | return 1; | |
346 | } | |
347 | ||
348 | void showstats(const char *u, const char *nick) | |
349 | { | |
350 | aClient *ni, *sender = find(u); | |
351 | char *buf; | |
352 | buf = new char[50]; | |
353 | char *space; | |
354 | ||
355 | ||
73c71976 | 356 | if (!(ni = findplayer(nick))) |
85ce9d3e | 357 | { |
358 | notice(s_GameServ, u, "%s not found", nick); | |
359 | } | |
360 | else if (ni->stats) | |
361 | { | |
85ce9d3e | 362 | notice(s_GameServ, sender->getNick(), "Stats for %s:", ni->stats->name); |
363 | ||
364 | sprintf(buf, "Experience: %ld", ni->stats->exp); | |
365 | space = spaces(strlen(buf), " "); | |
366 | notice(s_GameServ, sender->getNick(), "%s%sLevel: %d", buf, space, | |
367 | ni->stats->level); | |
1cf88153 | 368 | delete [] space; |
85ce9d3e | 369 | |
370 | sprintf(buf, "Gold: %ld", ni->stats->gold); | |
371 | space = spaces(strlen(buf), " "); | |
372 | notice(s_GameServ, sender->getNick(), "%s%sGold in Bank: %ld", buf, space, ni->stats->bank); | |
1cf88153 | 373 | delete [] space; |
85ce9d3e | 374 | |
c7340cbd | 375 | notice(s_GameServ, sender->getNick(), "Hit Points: %d of %d", ni->stats->hp, |
85ce9d3e | 376 | ni->stats->maxhp); |
377 | ||
378 | sprintf(buf, "Strength: %d", ni->stats->strength + webonus[ni->stats->weapon]); | |
379 | space = spaces(strlen(buf), " "); | |
380 | notice(s_GameServ, sender->getNick(), "%s%sDefense: %d", | |
381 | buf, space, ni->stats->defense + arbonus[ni->stats->armor]); | |
1cf88153 | 382 | delete [] space; |
85ce9d3e | 383 | |
384 | sprintf(buf, "Armor: %s", armors[ni->stats->armor]); | |
385 | space = spaces(strlen(buf), " "); | |
386 | notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space, | |
387 | weapons[ni->stats->weapon]); | |
1cf88153 | 388 | delete [] space; |
85ce9d3e | 389 | |
390 | sprintf(buf, "Forest Fights: %d", ni->stats->forest_fights); | |
391 | space = spaces(strlen(buf), " "); | |
392 | notice(s_GameServ, sender->getNick(), "%s%sPlayer Fights: %d", buf, space, ni->stats->player_fights); | |
1cf88153 | 393 | delete [] space; |
35cba3f5 | 394 | Pouch *inv = &ni->stats->inventory; |
395 | ||
396 | notice(s_GameServ, u, "Potions"); | |
397 | sprintf(buf, "Healing: %d", inv->Healing()); | |
398 | space = spaces(strlen(buf), " "); | |
399 | notice(s_GameServ, sender->getNick(), "%s%sHP: %d", buf, | |
400 | space, inv->HP()); | |
401 | delete [] space; | |
402 | ||
403 | sprintf(buf, "Strength: %d", inv->Strength()); | |
404 | space = spaces(strlen(buf), " "); | |
405 | notice(s_GameServ, sender->getNick(), "%s%sDefense: %d", buf, | |
406 | space, inv->Defense()); | |
407 | delete [] space; | |
85ce9d3e | 408 | } |
73c71976 | 409 | else |
410 | { | |
411 | notice(s_GameServ, u, "%s is not playing!", ni->stats->name); | |
412 | } | |
1cf88153 | 413 | delete [] buf; |
85ce9d3e | 414 | } |
415 | ||
416 | char *spaces(int len, char *seperator) | |
417 | { | |
418 | char *final; | |
42ec1800 | 419 | final = new char[30]; |
85ce9d3e | 420 | int y; |
421 | strcpy(final, seperator); | |
42ec1800 | 422 | for (y = 0; y < 30 - len; y++) |
85ce9d3e | 423 | strcat(final, seperator); |
424 | return final; | |
425 | } | |
426 | ||
427 | void raw(const char *fmt, ...) | |
428 | { | |
429 | va_list args; | |
430 | char *input; | |
431 | const char *t = fmt; | |
432 | input = new char[1024]; | |
433 | va_start(args, fmt); | |
434 | memset(input, 0, sizeof(input)); // Initialize to NULL | |
435 | for (; *t; t++) | |
436 | { | |
437 | if (*t == '%') | |
438 | { | |
439 | switch(*++t) { | |
440 | case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break; | |
441 | case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break; | |
442 | case 'S': sprintf(input, "%s%s", input, s_GameServ); break; | |
443 | case 'l': | |
444 | if (*++t == 'd') | |
445 | sprintf(input, "%s%ld", input, va_arg(args, long int)); break; | |
446 | } | |
447 | } | |
448 | else | |
449 | { | |
450 | sprintf(input, "%s%c", input, *t); | |
451 | } | |
452 | ||
453 | } | |
9f8c2acc | 454 | #ifdef DEBUGMODE |
455 | log("Input: %s", input); | |
456 | #endif | |
457 | ||
85ce9d3e | 458 | sprintf(input, "%s%s", input, "\r\n"); |
85ce9d3e | 459 | sock_puts(sock, input); |
1cf88153 | 460 | delete [] input; |
85ce9d3e | 461 | va_end(args); |
462 | } | |
463 | /* Send a NOTICE from the given source to the given nick. */ | |
464 | ||
465 | void notice(const char *source, const char *dest, const char *fmt, ...) | |
466 | { | |
c7340cbd | 467 | if (fmt[0] == '\0') |
468 | return; | |
469 | ||
9bafc40d | 470 | char *commanduse; |
471 | commanduse = new char[16]; | |
472 | ||
473 | #ifdef P10 | |
6f727d4c | 474 | if (isUsePrivmsg()) |
475 | strcpy(commanduse, "P"); | |
9bafc40d | 476 | else |
a51121e0 | 477 | strcpy(commanduse, "O"); |
9bafc40d | 478 | #else |
479 | ||
6f727d4c | 480 | if (isUsePrivmsg()) |
481 | strcpy(commanduse, "PRIVMSG"); | |
9bafc40d | 482 | else |
6f727d4c | 483 | strcpy(commanduse, "NOTICE"); |
9bafc40d | 484 | #endif |
485 | ||
85ce9d3e | 486 | va_list args; |
487 | char *input; | |
488 | const char *t = fmt; | |
489 | input = new char[1024]; | |
490 | va_start(args, fmt); | |
491 | if (dest[0] == ':') | |
492 | { | |
493 | dest++; | |
ba2a880f | 494 | |
495 | #if !defined(P10) | |
9bafc40d | 496 | sprintf(input, ":%s %s %s :", source, commanduse, dest); |
ba2a880f | 497 | #else |
9bafc40d | 498 | sprintf(input, "%s %s %s :", gsnum, commanduse, dest); |
ba2a880f | 499 | #endif |
500 | ||
85ce9d3e | 501 | dest--; |
502 | } | |
503 | else | |
ba2a880f | 504 | { |
505 | #if !defined(P10) | |
9bafc40d | 506 | sprintf(input, ":%s %s %s :", source, commanduse, dest); |
ba2a880f | 507 | #else |
9bafc40d | 508 | sprintf(input, "%s %s %s :", gsnum, commanduse, dest); |
ba2a880f | 509 | #endif |
510 | } | |
85ce9d3e | 511 | |
512 | for (; *t; t++) | |
513 | { | |
514 | if (*t == '%') | |
515 | { | |
516 | switch(*++t) { | |
517 | case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break; | |
518 | case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break; | |
519 | case 'S': sprintf(input, "%s%s", input, s_GameServ); break; | |
520 | case 'l': | |
521 | if (*++t == 'd') | |
522 | sprintf(input, "%s%ld", input, va_arg(args, long int)); break; | |
523 | } | |
524 | } | |
525 | else | |
526 | { | |
527 | sprintf(input, "%s%c", input, *t); | |
528 | } | |
529 | ||
530 | } | |
9f8c2acc | 531 | #ifdef DEBUGMODE |
532 | log("Input: %s", input); | |
533 | #endif | |
85ce9d3e | 534 | sprintf(input, "%s%s", input, "\r\n"); |
85ce9d3e | 535 | sock_puts(sock, input); |
9bafc40d | 536 | delete [] commanduse; |
1cf88153 | 537 | delete [] input; |
85ce9d3e | 538 | va_end(args); |
539 | } | |
540 | ||
541 | ||
542 | int strnicmp(const char *s1, const char *s2, size_t len) | |
543 | { | |
544 | register int c; | |
545 | ||
546 | if (!len) | |
547 | return 0; | |
548 | while ((c = tolower(*s1)) == tolower(*s2) && len > 0) { | |
549 | if (c == 0 || --len == 0) | |
550 | return 0; | |
551 | s1++; | |
552 | s2++; | |
553 | } | |
554 | if (c < tolower(*s2)) | |
555 | return -1; | |
556 | return 1; | |
557 | } | |
558 | ||
653c4f62 | 559 | #ifndef HAVE_STRTOK |
85ce9d3e | 560 | char *strtok(char *str, const char *delim) |
561 | { | |
562 | static char *current = NULL; | |
563 | char *ret; | |
564 | ||
565 | if (str) | |
566 | current = str; | |
567 | if (!current) | |
568 | return NULL; | |
569 | current += strspn(current, delim); | |
570 | ret = *current ? current : NULL; | |
571 | current += strcspn(current, delim); | |
572 | if (!*current) | |
573 | current = NULL; | |
574 | else | |
575 | *current++ = 0; | |
576 | return ret; | |
577 | } | |
653c4f62 | 578 | #endif |
85ce9d3e | 579 | |
70065ca1 | 580 | void do_check(char *u) |
581 | { | |
582 | int days, hours, minutes, seconds; | |
583 | long complete; | |
584 | complete = (lastrefresh + refreshperiod) - time(NULL); | |
585 | days = complete / 86400; | |
586 | hours = (complete % 86400) / 3600; | |
587 | minutes = (complete % 86400) % 3600 / 60; | |
588 | seconds = (complete % 86400) % 3600 % 60; | |
589 | ||
590 | notice(s_GameServ, u, "Time left to next refresh: %dd %dh %dm %ds", | |
591 | days, hours, minutes, seconds); | |
592 | } | |
593 | ||
85ce9d3e | 594 | void do_list(char *u) |
595 | { | |
448a1531 | 596 | aClient *user; |
9cb6f227 | 597 | char *cmd = strtok(NULL, " "); |
598 | ||
448a1531 | 599 | if (!(user = find(u))) |
600 | { | |
601 | log("Fatal Error: Couldn't find %s in the client list", u); | |
602 | return; | |
603 | } | |
604 | else if (isIgnore(user)) | |
605 | { | |
606 | #ifdef DEBUGMODE | |
607 | log("Ignoring %s. Command LIST", user->getNick()); | |
608 | #endif | |
609 | return; | |
610 | } | |
611 | ||
85ce9d3e | 612 | ListNode<aClient> *temp; |
7996e5fd | 613 | bool header = false; |
9cb6f227 | 614 | |
7996e5fd | 615 | for (unsigned long x = 0; x < U_TABLE_SIZE; x++) |
616 | { | |
617 | temp = players[x].First(); | |
618 | if (!players[x].isEmpty()) | |
85ce9d3e | 619 | { |
85ce9d3e | 620 | while(temp) |
621 | { | |
100c5e33 | 622 | if (cmd || is_playing(temp->getData())) |
9cb6f227 | 623 | { |
624 | if (!header) | |
625 | { | |
626 | notice(s_GameServ, u, "Players:"); | |
627 | header = true; | |
628 | } | |
629 | #ifdef P10 | |
630 | notice(s_GameServ, u, "IRC: %s Game: %s", temp->getData()->getRealNick(), | |
631 | temp->getData()->stats->name); | |
632 | #else | |
633 | notice(s_GameServ, u, "IRC: %s Game: %s", temp->getData()->getNick(), | |
634 | temp->getData()->stats->name); | |
635 | #endif | |
636 | } | |
ce61cdfa | 637 | |
85ce9d3e | 638 | temp = temp->Next(); |
639 | } | |
85ce9d3e | 640 | } |
7996e5fd | 641 | } |
642 | if (!header) | |
85ce9d3e | 643 | notice(s_GameServ, u, "No one is playing"); |
7996e5fd | 644 | else |
645 | notice(s_GameServ, u, "End of List"); | |
646 | ||
85ce9d3e | 647 | } |
1af35752 | 648 | |
b0359af9 | 649 | void do_logout(char *u) |
650 | { | |
651 | aClient *user; | |
18b84d11 | 652 | char *name = strtok(NULL, " "); |
653 | ||
b0359af9 | 654 | if (!(user = find(u))) |
655 | { | |
656 | notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\ | |
657 | "Buf: %s LOGOUT", u); | |
658 | log("Could not find aClient Buf: %s LOGOUT", | |
659 | u); | |
18b84d11 | 660 | return; |
b0359af9 | 661 | } |
448a1531 | 662 | else if (isIgnore(user)) |
663 | { | |
664 | #ifdef DEBUGMODE | |
665 | log("Ignoring %s.", user->getNick()); | |
666 | #endif | |
667 | return; | |
668 | } | |
18b84d11 | 669 | |
670 | if (name) | |
6e8ec003 | 671 | { |
18b84d11 | 672 | if (!isAdmin(user)) |
673 | { | |
674 | notice(s_GameServ, u, "You must be a %S admin to use this command!"); | |
675 | } | |
676 | else if (!(user = findplayer(name))) | |
677 | { | |
678 | notice(s_GameServ, u, "Couldn't find a player named %s", name); | |
679 | } | |
680 | else | |
681 | { | |
682 | notice(s_GameServ, u, "Logging out %s", user->stats->name); | |
683 | logout(user); | |
684 | } | |
6e8ec003 | 685 | } |
18b84d11 | 686 | else if (!name) |
b0359af9 | 687 | { |
18b84d11 | 688 | if (!is_playing(user)) |
689 | { | |
690 | notice(s_GameServ, u, "You're not logged in!"); | |
691 | } | |
692 | else if (is_fighting(user)) | |
693 | { | |
694 | notice(s_GameServ, u, "You can't logout while fighting!"); | |
695 | } | |
696 | else | |
697 | { | |
698 | notice(s_GameServ, u, "You have left the fields. You have lived to kill another day!"); | |
699 | logout(user); | |
700 | } | |
b0359af9 | 701 | } |
702 | } | |
3f243b0b | 703 | |
b0359af9 | 704 | void logout(aClient *user) |
705 | { | |
706 | if (is_playing(user)) | |
707 | { | |
708 | ListNode<aClient> *it; | |
709 | aClient *temp; | |
448a1531 | 710 | unsigned long hv = iHASH((unsigned char *) user->stats->name); |
7996e5fd | 711 | it = players[hv].Find(user); |
448a1531 | 712 | |
b0359af9 | 713 | if (!it) |
714 | { | |
715 | notice(s_GameServ, user->getNick(), "Fatal error. Contact "\ | |
716 | "%S Admin. Cannot find you in the players list."); | |
717 | log("Error on logout(). Can't find %s in the players list", | |
718 | #ifdef P10 | |
719 | user->getRealNick() | |
720 | #else | |
721 | user->getNick() | |
722 | #endif | |
723 | ); | |
724 | return; | |
725 | } | |
726 | ||
727 | temp = new aClient; | |
728 | temp->stats = new Player; | |
729 | temp->stats->setData(user->stats); | |
85bcf836 | 730 | user->stats->client = NULL; |
6e8ec003 | 731 | |
732 | if (player_fight(user)) | |
733 | user->stats->battle->stats->battle = NULL; | |
734 | ||
b0359af9 | 735 | delete user->stats; |
736 | user->stats = NULL; | |
85bcf836 | 737 | temp->stats->client = NULL; |
b0359af9 | 738 | #ifdef P10 |
448a1531 | 739 | temp->setRealNick("Not Playing"); |
b0359af9 | 740 | #endif |
448a1531 | 741 | temp->setNick("Not Playing"); |
b0359af9 | 742 | |
743 | it->setNewPtr(temp); | |
744 | #ifdef DEBUGMODE | |
745 | log("Logged out player %s", | |
746 | #ifdef P10 | |
747 | user->getRealNick() | |
748 | #else | |
749 | user->getNick() | |
750 | #endif | |
751 | ); | |
752 | #endif | |
753 | } | |
3f243b0b | 754 | clearPlaying(user); |
b0359af9 | 755 | } |
3f243b0b | 756 | |
85ce9d3e | 757 | void do_register(char *u) |
758 | { | |
e1c41a84 | 759 | char *password, *name; |
40251952 | 760 | aClient *user; |
e1c41a84 | 761 | name = strtok(NULL, " "); |
85ce9d3e | 762 | password = strtok(NULL, " "); |
763 | ||
e3c5fe46 | 764 | static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
765 | static char salt[3]; | |
766 | ||
767 | salt[0] = saltChars[rand() % strlen(saltChars)]; | |
768 | salt[1] = saltChars[rand() % strlen(saltChars)]; | |
f27a378f | 769 | salt[2] = '\0'; |
e3c5fe46 | 770 | |
e1c41a84 | 771 | if (!name) |
772 | { | |
773 | notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD"); | |
774 | } | |
775 | else if (!password) | |
85ce9d3e | 776 | { |
e1c41a84 | 777 | notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD"); |
85ce9d3e | 778 | } |
03e0a9d8 | 779 | else if ((user = findplayer(name))) |
780 | { | |
781 | notice(s_GameServ, u, "%s is already registered!", name); | |
782 | notice(s_GameServ, u, "Choose another name!"); | |
783 | } | |
448a1531 | 784 | else if (!(user = find(u))) |
785 | { | |
786 | log("Fatal Error: Couldn't find %s in the clients list", u); | |
787 | } | |
788 | else if (isIgnore(user)) | |
789 | { | |
790 | #ifdef DEBUGMODE | |
791 | log("Ignoring %s.", user->getNick()); | |
792 | #endif | |
793 | return; | |
794 | } | |
795 | else | |
85ce9d3e | 796 | { |
3f243b0b | 797 | if (!is_playing(user)) |
85ce9d3e | 798 | { |
ae2685f6 | 799 | ListNode<aClient> *temp; |
85ce9d3e | 800 | user->stats = new Player(user); |
85bcf836 | 801 | user->stats->client = user; // Set the backwards pointer |
ae2685f6 | 802 | user->stats->reset(); // set the user up |
803 | strncpy(user->stats->password, crypt(password, salt), 255); | |
804 | strncpy(user->stats->name, name, 255); | |
448a1531 | 805 | unsigned long hv = iHASH((unsigned char *) name); |
40251952 | 806 | updateTS(user->stats); |
ae2685f6 | 807 | temp = players[hv].insertAtBack_RLN(user); |
808 | temp->setPtr(user); // This is an extra step, but necessary for now | |
809 | ||
14e24ba1 | 810 | // Update the last login time |
811 | user->stats->lastlogin = time(NULL); | |
812 | ||
c7340cbd | 813 | notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->name, password); |
814 | notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!"); | |
5d04eb42 | 815 | log("Nickname %s registered player %s.", u, user->stats->name); |
3f243b0b | 816 | setPlaying(user); // set the playing flag |
85ce9d3e | 817 | } |
818 | else | |
819 | { | |
820 | notice(s_GameServ, u, "Already registered. Contact a %S admin for help."); | |
821 | } | |
822 | } | |
823 | } | |
824 | ||
825 | void do_identify(char *u) | |
826 | { | |
0a1518fa | 827 | char *password, *name; |
828 | aClient *user, *p; | |
829 | name = strtok(NULL, " "); | |
85ce9d3e | 830 | password = strtok(NULL, " "); |
0a1518fa | 831 | if (!password || !name) |
85ce9d3e | 832 | { |
0a1518fa | 833 | notice(s_GameServ, u, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD"); |
85ce9d3e | 834 | } |
448a1531 | 835 | else if (!(user = find(u))) |
5d04eb42 | 836 | { |
837 | notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, "")); | |
838 | log("Error: aClient not found: %s", u); | |
839 | } | |
448a1531 | 840 | else if (isIgnore(user)) |
841 | { | |
842 | #ifdef DEBUGMODE | |
843 | log("Ignoring %s.", user->getNick()); | |
844 | #endif | |
845 | return; | |
846 | } | |
0a1518fa | 847 | else if (!(p = findplayer(name)) || !p->stats) |
848 | notice(s_GameServ, u, "Player %s not found", name); | |
b0359af9 | 849 | else if (is_playing(user)) |
850 | { | |
851 | notice(s_GameServ, u, "You are already playing!"); | |
852 | } | |
85bcf836 | 853 | else if (p->stats->client != NULL && !isAdmin(user)) |
1579dfa2 | 854 | { |
855 | notice(s_GameServ, u, "That player has already identified."); | |
1579dfa2 | 856 | } |
20d5d721 | 857 | else if (!check_password(name, password) && !isAdmin(user)) |
85ce9d3e | 858 | { |
0a1518fa | 859 | notice(s_GameServ, u, "Password incorrect"); |
85ce9d3e | 860 | } |
1579dfa2 | 861 | else { |
b0359af9 | 862 | ListNode<aClient> *temp; |
448a1531 | 863 | unsigned long hv = iHASH((unsigned char *) p->stats->name); |
7996e5fd | 864 | temp = players[hv].Find(p); |
b0359af9 | 865 | if (!temp) |
85ce9d3e | 866 | { |
b0359af9 | 867 | notice(s_GameServ, u, "Fatal error. Contact %S Admin. Buf: %s", |
868 | strtok(NULL, "")); | |
869 | return; | |
85ce9d3e | 870 | } |
b0359af9 | 871 | user->stats = new Player(p->stats->name); |
872 | #ifdef DEBUGMODE | |
873 | log("Setting data for identified"); | |
874 | #endif | |
0b6098d5 | 875 | user->stats->setData(p->stats); |
448a1531 | 876 | user->stats->client = user; |
40251952 | 877 | updateTS(user->stats); |
878 | ||
b0359af9 | 879 | |
880 | #ifdef DEBUGMODE | |
448a1531 | 881 | log("Player %s IRC: %s Identified", user->stats->name, |
882 | user->getNick()); | |
b0359af9 | 883 | #endif |
884 | ||
3f243b0b | 885 | setPlaying(user); // set the playing flag |
886 | ||
b0359af9 | 887 | temp->setPtr(user); |
14e24ba1 | 888 | |
889 | // Update the last login time | |
890 | user->stats->lastlogin = time(NULL); | |
891 | ||
c260a8d7 | 892 | notice(s_GameServ, u, "Password Accepted. Identified."); |
893 | showNews(u, todaysnews); | |
85ce9d3e | 894 | } |
895 | } | |
896 | ||
897 | void do_stats(char *u) | |
898 | { | |
899 | char *nick; | |
73c71976 | 900 | aClient *user; |
85ce9d3e | 901 | |
902 | nick = strtok(NULL, " "); | |
85ce9d3e | 903 | |
448a1531 | 904 | if (!(user = find(u))) |
73c71976 | 905 | { |
448a1531 | 906 | log("Fatal Error: %s not found in client list", u); |
907 | return; | |
908 | } | |
909 | else if (isIgnore(user)) | |
910 | { | |
911 | #ifdef DEBUGMODE | |
912 | log("Ignoring %s.", user->getNick()); | |
913 | #endif | |
914 | return; | |
915 | } | |
916 | else if (!nick) | |
917 | { | |
918 | if (!is_playing(user)) | |
73c71976 | 919 | { |
920 | notice(s_GameServ, u, "You're not playing, so you have no stats!"); | |
921 | return; | |
922 | } | |
923 | else | |
40251952 | 924 | { |
925 | updateTS(user->stats); | |
73c71976 | 926 | showstats(u, user->stats->name); |
40251952 | 927 | } |
73c71976 | 928 | } |
85ce9d3e | 929 | else |
930 | showstats(u, nick); | |
931 | } | |
448a1531 | 932 | |
ad7dfaa0 | 933 | void init_masters() |
934 | { | |
5d04eb42 | 935 | #ifdef DEBUGMODE |
936 | log("Calling delete_masters()"); | |
937 | #endif | |
938 | ||
ab4f4ec0 | 939 | delete_masters(); |
c8ada07e | 940 | |
5d04eb42 | 941 | #ifdef DEBUGMODE |
942 | log("Initializing masters"); | |
943 | #endif | |
944 | ||
c8ada07e | 945 | for (int x = 0; x < LEVELS; x++) |
946 | masters[x] = new Monster; | |
947 | ||
948 | strcpy(masters[0]->name, "Old Bones"); | |
949 | strcpy(masters[0]->weapon, "Dull Sword Cane"); | |
f0314ad5 | 950 | masters[0]->strength = 32; |
c8ada07e | 951 | masters[0]->gold = 0; |
952 | masters[0]->exp = 0; | |
6d053d90 | 953 | masters[0]->maxhp = 35; |
954 | masters[0]->hp = 35; | |
c8ada07e | 955 | strcpy(masters[0]->death, "You have done well my student, but the road is long. Use your new strength with humility and honor as you progress in levels!"); |
e282e9d2 | 956 | |
c8ada07e | 957 | strcpy(masters[1]->name, "Master Chang"); |
958 | strcpy(masters[1]->weapon, "Nanchaku"); | |
f0314ad5 | 959 | masters[1]->strength = 48; |
c8ada07e | 960 | masters[1]->gold = 0; |
961 | masters[1]->exp = 0; | |
6d053d90 | 962 | masters[1]->maxhp = 51; |
963 | masters[1]->hp = 51; | |
c8ada07e | 964 | strcpy(masters[1]->death, "You try to make out what Master Chang is saying, but the only thing you catch is something about a grasshopper."); |
965 | ||
966 | strcpy(masters[2]->name, "Chuck Norris"); | |
967 | strcpy(masters[2]->weapon, "Ranger Kick"); | |
f0314ad5 | 968 | masters[2]->strength = 88; |
c8ada07e | 969 | masters[2]->gold = 0; |
970 | masters[2]->exp = 0; | |
6d053d90 | 971 | masters[2]->maxhp = 100; |
972 | masters[2]->hp = 100; | |
c8ada07e | 973 | strcpy(masters[2]->death, "Be strong, and keep your goals in site. Drink milk, and don't do drugs. One day you may be fighting next to me as a Texas Ranger YEEHAW!"); |
974 | ||
975 | ||
976 | strcpy(masters[3]->name, "Mr. Miagi"); | |
977 | strcpy(masters[3]->weapon, "Petrified Bonsai"); | |
f0314ad5 | 978 | masters[3]->strength = 169; |
c8ada07e | 979 | masters[3]->gold = 0; |
980 | masters[3]->exp = 0; | |
6d053d90 | 981 | masters[3]->maxhp = 165; |
982 | masters[3]->hp = 165; | |
c8ada07e | 983 | strcpy(masters[3]->death, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!"); |
984 | ||
985 | strcpy(masters[4]->name, "Jackie Chan"); | |
e282e9d2 | 986 | strcpy(masters[4]->weapon, "Kung Fu Kick"); |
f0314ad5 | 987 | masters[4]->strength = 275; |
c8ada07e | 988 | masters[4]->gold = 0; |
989 | masters[4]->exp = 0; | |
6d053d90 | 990 | masters[4]->maxhp = 232; |
991 | masters[4]->hp = 232; | |
c8ada07e | 992 | strcpy(masters[4]->death, "I like to let people talk who like to talk... it's easier to find out how full of it they really are!"); |
993 | ||
994 | strcpy(masters[5]->name, "Jet Li"); | |
995 | strcpy(masters[5]->weapon, "Motorcycle"); | |
f0314ad5 | 996 | masters[5]->strength = 347; |
c8ada07e | 997 | masters[5]->gold = 0; |
998 | masters[5]->exp = 0; | |
6d053d90 | 999 | masters[5]->maxhp = 504; |
1000 | masters[5]->hp = 504; | |
c8ada07e | 1001 | strcpy(masters[5]->death, "Failure is a fuel for excuses. It's the doing the do, that makes the making."); |
1002 | ||
1003 | ||
1004 | strcpy(masters[6]->name, "Muhammad Ali"); | |
1005 | strcpy(masters[6]->weapon, "Quick Jab"); | |
f0314ad5 | 1006 | masters[6]->strength = 515; |
c8ada07e | 1007 | masters[6]->gold = 0; |
1008 | masters[6]->exp = 0; | |
6d053d90 | 1009 | masters[6]->maxhp = 1078; |
1010 | masters[6]->hp = 1078; | |
c8ada07e | 1011 | strcpy(masters[6]->death, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up."); |
1012 | ||
1013 | strcpy(masters[7]->name, "Li Mu Bai"); | |
1014 | strcpy(masters[7]->weapon, "Green Destiny"); | |
f0314ad5 | 1015 | masters[7]->strength = 655; |
c8ada07e | 1016 | masters[7]->gold = 0; |
1017 | masters[7]->exp = 0; | |
6d053d90 | 1018 | masters[7]->maxhp = 2207; |
1019 | masters[7]->hp = 2207; | |
c8ada07e | 1020 | strcpy(masters[7]->death, "No growth without resistance. No action without reaction. No desire without restraint."); |
1021 | ||
1022 | ||
1023 | strcpy(masters[8]->name, "Jimmy Wang Yu"); | |
1024 | strcpy(masters[8]->weapon, "Flying Guillotine"); | |
f0314ad5 | 1025 | masters[8]->strength = 819; |
c8ada07e | 1026 | masters[8]->gold = 0; |
1027 | masters[8]->exp = 0; | |
6d053d90 | 1028 | masters[8]->maxhp = 2780; |
1029 | masters[8]->hp = 2780; | |
c8ada07e | 1030 | strcpy(masters[8]->death, "You have beaten the one armed boxer. Proceed with caution!"); |
1031 | ||
1032 | strcpy(masters[9]->name, "Wong Fei Hung"); | |
1033 | strcpy(masters[9]->weapon, "Drunken Boxing"); | |
f0314ad5 | 1034 | masters[9]->strength = 1014; |
c8ada07e | 1035 | masters[9]->gold = 0; |
1036 | masters[9]->exp = 0; | |
6d053d90 | 1037 | masters[9]->maxhp = 3046; |
1038 | masters[9]->hp = 3046; | |
e282e9d2 | 1039 | strcpy(masters[9]->death, "Hiccup! Monkey drinks master's wine!"); |
c8ada07e | 1040 | |
1041 | strcpy(masters[10]->name, "Bruce Lee"); | |
1042 | strcpy(masters[10]->weapon, "Fists of fury"); | |
f0314ad5 | 1043 | masters[10]->strength = 1286; |
c8ada07e | 1044 | masters[10]->gold = 0; |
1045 | masters[10]->exp = 0; | |
6d053d90 | 1046 | masters[10]->maxhp = 3988; |
1047 | masters[10]->hp = 3988; | |
c8ada07e | 1048 | strcpy(masters[10]->death, "You must learn to concentrate. It is like a finger pointing away to the moon... DONT concentrate on the finger, or you will miss all the heavenly glory."); |
ad7dfaa0 | 1049 | } |
85ce9d3e | 1050 | |
c8ada07e | 1051 | void delete_monsters() |
1052 | { | |
1053 | for (int x = 0; x < LEVELS; x++) | |
42106907 | 1054 | levels[x].monsters.deleteNodes(); |
c8ada07e | 1055 | } |
1056 | ||
1057 | void delete_masters() | |
1058 | { | |
1059 | for (int x = 0; x < LEVELS; x++) | |
1060 | if (masters[x]) | |
1061 | delete masters[x]; | |
85ce9d3e | 1062 | } |
1063 | ||
1064 | void display_monster(char *u) | |
1065 | { | |
1066 | if (is_playing(u)) | |
1067 | { | |
1068 | aClient *user = find(u); | |
1069 | Player *ni = user->stats; | |
1070 | ||
1071 | notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->hp); | |
1072 | notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", ni->fight->name, ni->fight->hp); | |
1073 | notice(s_GameServ, u, "Here are your commands:"); | |
1074 | notice(s_GameServ, u, "/msg %S attack"); | |
1075 | notice(s_GameServ, u, "/msg %S run"); | |
1076 | notice(s_GameServ, u, "What will you do?"); | |
1077 | } | |
1078 | } | |
1079 | ||
1080 | void display_players(char *u) | |
1081 | { | |
85bcf836 | 1082 | aClient *user; |
1083 | if (!(user = find(u))) | |
85ce9d3e | 1084 | { |
85bcf836 | 1085 | log("Fatal error in display_players(): Couldn't find %s", u); |
83cf716f | 1086 | } |
85bcf836 | 1087 | else |
1088 | display_players(user); | |
83cf716f | 1089 | } |
85bcf836 | 1090 | |
83cf716f | 1091 | void display_players(aClient *user) |
1092 | { | |
1093 | char *u = user->getNick(); | |
1094 | if (is_playing(user) && player_fight(user)) | |
1095 | { | |
1096 | aClient *battle = user->stats->battle; | |
1097 | notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", user->stats->hp); | |
ce61cdfa | 1098 | notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", battle->stats->name, battle->stats->hp); |
83cf716f | 1099 | notice(s_GameServ, u, "Here are your commands:"); |
1100 | notice(s_GameServ, u, "/msg %S attack"); | |
1101 | notice(s_GameServ, u, "/msg %S run"); | |
85ce9d3e | 1102 | notice(s_GameServ, u, "What will you do?"); |
1103 | } | |
1104 | } | |
1105 | ||
1106 | ||
1107 | bool is_playing(char *u) | |
1108 | { | |
1109 | aClient *user; | |
1110 | if (!(user = find(u))) | |
85ce9d3e | 1111 | return false; |
85ce9d3e | 1112 | else |
40251952 | 1113 | return is_playing(user); |
85ce9d3e | 1114 | } |
1115 | ||
1af35752 | 1116 | bool is_playing(aClient *user) |
1117 | { | |
03a4bdbb | 1118 | if (user->stats == NULL) |
f1ab3b7c | 1119 | { |
03a4bdbb | 1120 | return false; |
f1ab3b7c | 1121 | } |
03a4bdbb | 1122 | else if (user->stats->client == NULL) |
f1ab3b7c | 1123 | { |
03a4bdbb | 1124 | return false; |
f1ab3b7c | 1125 | } |
3f243b0b | 1126 | else if (!FL_is_playing(user)) |
1127 | { | |
1128 | return false; | |
1129 | } | |
03a4bdbb | 1130 | else |
1131 | return true; | |
1af35752 | 1132 | } |
1133 | ||
85ce9d3e | 1134 | bool is_fighting(char *u) |
1135 | { | |
1136 | aClient *user; | |
1137 | ||
1138 | if (!(user = find(u))) | |
85ce9d3e | 1139 | return false; |
85ce9d3e | 1140 | else |
40251952 | 1141 | return is_fighting(user); |
85ce9d3e | 1142 | } |
40251952 | 1143 | |
1af35752 | 1144 | bool is_fighting(aClient *user) |
1145 | { | |
1146 | if (!is_playing(user)) | |
1147 | return false; | |
1148 | else | |
448a1531 | 1149 | return player_fight(user) || master_fight(user) || user->stats->fight != NULL; |
1af35752 | 1150 | } |
85ce9d3e | 1151 | |
1152 | bool player_fight(char *u) | |
1153 | { | |
1154 | aClient *user; | |
1155 | ||
1156 | if (!(user = find(u))) | |
1157 | return false; | |
40251952 | 1158 | else |
1159 | return player_fight(user); | |
85ce9d3e | 1160 | } |
448a1531 | 1161 | |
1af35752 | 1162 | bool player_fight(aClient *user) |
1163 | { | |
448a1531 | 1164 | if (!is_playing(user)) |
1af35752 | 1165 | return false; |
a51f0dcd | 1166 | else if (user->stats->battle != NULL) |
1167 | { | |
1168 | return user->stats->battle->stats != NULL; | |
1169 | } | |
1170 | return false; | |
1af35752 | 1171 | } |
85ce9d3e | 1172 | |
1173 | bool master_fight(char *u) | |
1174 | { | |
1175 | aClient *user; | |
1176 | ||
1177 | if (!(user = find(u))) | |
1178 | return false; | |
85ce9d3e | 1179 | else |
40251952 | 1180 | return master_fight(user); |
85ce9d3e | 1181 | } |
40251952 | 1182 | |
1af35752 | 1183 | bool master_fight(aClient *user) |
85ce9d3e | 1184 | { |
1af35752 | 1185 | if (!is_playing(user)) |
1186 | return false; | |
1187 | else | |
1188 | return user->stats->master != NULL; | |
85ce9d3e | 1189 | } |
1190 | ||
1191 | void do_fight(char *u) | |
1192 | { | |
1193 | aClient *ni, *battle; | |
1194 | ||
1195 | char *nick = strtok(NULL, " "); | |
1196 | ||
1197 | if (!nick) | |
1198 | { | |
1199 | notice(s_GameServ, u, "SYNTAX: /msg %S FIGHT PLAYER"); | |
40251952 | 1200 | return; |
85ce9d3e | 1201 | } |
1202 | else if (!(ni = find(u))) | |
1203 | { | |
1af35752 | 1204 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); |
40251952 | 1205 | return; |
85ce9d3e | 1206 | } |
448a1531 | 1207 | else if (isIgnore(ni)) |
1208 | { | |
1209 | #ifdef DEBUGMODE | |
1210 | log("Ignoring %s.", ni->getNick()); | |
1211 | #endif | |
1212 | return; | |
1213 | } | |
71098075 | 1214 | else if (!is_playing(ni)) |
85ce9d3e | 1215 | { |
71098075 | 1216 | notice(s_GameServ, u, "You are not playing!"); |
40251952 | 1217 | return; |
85ce9d3e | 1218 | } |
40251952 | 1219 | |
1220 | updateTS(ni->stats); | |
1221 | ||
1222 | if (ni->stats->player_fights <= 0) | |
3348c24e | 1223 | { |
1224 | ni->stats->player_fights = 0; // just to be safe | |
1225 | notice(s_GameServ, u, "You are out of player fights for the "\ | |
1226 | "day. You have to wait until tomorrow!"); | |
1227 | } | |
71098075 | 1228 | else if (!(battle = findplayer(nick))) |
b0359af9 | 1229 | { |
1230 | notice(s_GameServ, u, "Player %s not found!", nick); | |
1231 | } | |
448a1531 | 1232 | else if (!isAlive(ni->stats)) |
1233 | { | |
1234 | notice(s_GameServ, u, "You are dead. Wait until tomorrow to fight others!"); | |
1235 | } | |
b0359af9 | 1236 | else if (!is_playing(battle)) |
85ce9d3e | 1237 | { |
71098075 | 1238 | notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick); |
85ce9d3e | 1239 | } |
b478c0df | 1240 | |
1241 | /* offline fighting not available yet | |
1242 | else if (!(fight = finduser(nick))) | |
1243 | { | |
1244 | ni->stats->battle = battle; | |
1245 | battle->battle = ni; | |
1246 | setYourTurn(ni->stats); | |
1247 | clearYourTurn(battle->stats); | |
1248 | ||
1249 | notice(s_GameServ, u, "You decide to fight %s while they're "\ | |
1250 | "not in the realm!", | |
1251 | battle->stats->name); | |
1252 | display_players(u); | |
1253 | } | |
1254 | */ | |
b0359af9 | 1255 | else if (stricmp(ni->stats->name, battle->stats->name) == 0) |
1256 | { | |
1257 | notice(s_GameServ, u, "Are you trying to commit suicide!?"); | |
1af35752 | 1258 | } |
da5cf17a | 1259 | else if (!isAlive(battle->stats)) |
1260 | { | |
1261 | notice(s_GameServ, u, "They are dead. Cannot fight dead players!"); | |
da5cf17a | 1262 | } |
1902338e | 1263 | else if (player_fight(battle)) |
1264 | { | |
1265 | notice(s_GameServ, u, "%s is fighting %s already!", battle->stats->name, battle->stats->battle->stats->name); | |
1902338e | 1266 | } |
448a1531 | 1267 | else if (master_fight(battle)) |
1268 | { | |
1269 | notice(s_GameServ, u, "%s is fighting their master!", battle->stats->name); | |
1270 | } | |
1902338e | 1271 | else if (is_fighting(battle)) |
1272 | { | |
1273 | notice(s_GameServ, u, "%s is fighting %s already!", battle->stats->name, battle->stats->fight->name); | |
1902338e | 1274 | } |
8450c018 | 1275 | else if (ni->stats->level - battle->stats->level > maxbfightdistance) |
1276 | { | |
1277 | // You can't fight someone below you by more than X level(s) | |
1278 | // level 12 can fight level (12 - X) but not < (12 - X) | |
1279 | notice(s_GameServ, u, "You may not fight %s. You're too strong!", | |
ae2685f6 | 1280 | battle->stats->name); |
8450c018 | 1281 | } |
1282 | else if (battle->stats->level - ni->stats->level > maxafightdistance) | |
1283 | { | |
1284 | // You can't fight someone above you by more than X level(S) | |
1285 | // level 1 can fight level (1 + X), but not > (1 + X) | |
1286 | notice(s_GameServ, u, "%s, do you really have a death wish? Try the forest you "\ | |
1287 | "weakling!", ni->stats->name); | |
8450c018 | 1288 | } |
b0359af9 | 1289 | else |
85ce9d3e | 1290 | { |
1291 | // Set your battle pointer to the other player | |
1292 | ni->stats->battle = battle; | |
1293 | ||
1294 | // Set the other player's battle pointer to you | |
448a1531 | 1295 | ni->stats->battle->stats->battle = ni; |
85ce9d3e | 1296 | |
1297 | // The initiator gets the first move (perhaps this should be 50/50) | |
ee38284f | 1298 | setYourTurn(ni->stats); |
1299 | clearYourTurn(battle->stats); | |
85ce9d3e | 1300 | |
1301 | // Initiate Battle sequence! | |
b0359af9 | 1302 | ni->stats->player_fights -= 1; |
f2072f1a | 1303 | |
ce61cdfa | 1304 | notice(s_GameServ, u, "You challenge %s to an online duel!", battle->stats->name); |
1305 | notice(s_GameServ, battle->getNick(), "%s has challenged you to an online duel!", ni->stats->name); | |
71098075 | 1306 | notice(s_GameServ, battle->getNick(), "%s gets to go first "\ |
1307 | "because they initiated!", ni->stats->name); | |
ce61cdfa | 1308 | notice(s_GameServ, battle->getNick(), "Please wait while %s decides what to do.", ni->stats->name); |
85bcf836 | 1309 | display_players(ni); |
85ce9d3e | 1310 | } |
1311 | } | |
40251952 | 1312 | |
83cf716f | 1313 | void do_use(char *u) |
1314 | { | |
1315 | aClient *user; | |
1316 | Pouch *p; | |
1317 | ||
1318 | char *item = strtok(NULL, " "); | |
1319 | ||
1320 | if (!item) | |
1321 | { | |
1322 | notice(s_GameServ, u, "SYNTAX: USE ITEM"); | |
1323 | notice(s_GameServ, u, "Type /msg %S HELP USE for more information."); | |
1324 | return; | |
1325 | } | |
1326 | else if (!(user = find(u))) | |
1327 | { | |
1328 | notice(s_GameServ, u, "Fatal Error in do_use. Contact a(n) %S Admin"); | |
1329 | return; | |
1330 | } | |
448a1531 | 1331 | else if (isIgnore(user)) |
1332 | { | |
1333 | #ifdef DEBUGMODE | |
1334 | log("Ignoring %s.", user->getNick()); | |
1335 | #endif | |
1336 | return; | |
1337 | } | |
83cf716f | 1338 | else if (!is_playing(user)) |
1339 | { | |
1340 | notice(s_GameServ, u, "You must be playing to use items!"); | |
1341 | return; | |
1342 | } | |
1343 | ||
40251952 | 1344 | updateTS(user->stats); |
1345 | ||
83cf716f | 1346 | p = &user->stats->inventory; |
1347 | ||
35cba3f5 | 1348 | if (stricmp(item, "HEALING") == 0) |
83cf716f | 1349 | { |
1350 | if (p->Healing() <= 0) | |
1351 | { | |
35cba3f5 | 1352 | notice(s_GameServ, u, "You are out of Healing Potions!"); |
83cf716f | 1353 | return; |
1354 | } | |
35cba3f5 | 1355 | int oldhealing = user->stats->hp; |
36b31e1c | 1356 | user->stats->hp += (10 * user->stats->level) + (rand() % 10) * user->stats->level; |
1357 | if (user->stats->hp - user->stats->maxhp >= 100) | |
1358 | { | |
1359 | user->stats->hp = user->stats->maxhp + 100; | |
1360 | ||
1361 | if (oldhealing >= (user->stats->maxhp + 100)) | |
1362 | { | |
1363 | notice(s_GameServ, u, "You cannot hold anymore HP!"); | |
1364 | return; | |
1365 | } | |
1366 | } | |
1367 | ||
83cf716f | 1368 | notice(s_GameServ, u, "You hastiliy gulp down the flask of cool life-giving waters."); |
1369 | notice(s_GameServ, u, "Rejuvination spreads throughout your body."); | |
35cba3f5 | 1370 | notice(s_GameServ, u, "You gain %d HP!", user->stats->hp - oldhealing); |
83cf716f | 1371 | p->decHealing(); |
35cba3f5 | 1372 | if (player_fight(user)) |
1373 | { | |
1374 | notice(s_GameServ, user->stats->battle->getNick(), | |
1375 | "%s has used a healing potion!"); | |
1376 | } | |
83cf716f | 1377 | } |
1378 | else if (stricmp(item, "STRENGTH") == 0) | |
1379 | { | |
1380 | if (p->Strength() <= 0) | |
1381 | { | |
1382 | notice(s_GameServ, u, "You are out of Strength Potions!"); | |
1383 | return; | |
1384 | } | |
1385 | int oldstrength = user->stats->strength; | |
1386 | notice(s_GameServ, u, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!"); | |
1387 | notice(s_GameServ, u, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!"); | |
ae2685f6 | 1388 | user->stats->strength += 1 + (rand() % 10 >= 8 ? 1 : 0); // 1-2 |
83cf716f | 1389 | notice(s_GameServ, u, "You gain %d Strength points!", user->stats->strength - oldstrength); |
1390 | p->decStrength(); | |
35cba3f5 | 1391 | if (player_fight(user)) |
1392 | { | |
1393 | notice(s_GameServ, user->stats->battle->getNick(), | |
1394 | "%s has used a strength potion!"); | |
1395 | } | |
83cf716f | 1396 | } |
1397 | else if (stricmp(item, "DEFENSE") == 0) | |
1398 | { | |
1399 | if (p->Defense() <= 0) | |
1400 | { | |
1401 | notice(s_GameServ, u, "You are out of Defense Potions!"); | |
1402 | return; | |
1403 | } | |
8c734eb9 | 1404 | int olddefense = user->stats->defense; |
83cf716f | 1405 | notice(s_GameServ, u, "You drink the foul tasting viscous liquid while pinching your nose in disgust."); |
1406 | notice(s_GameServ, u, "It tasted bad, but you feel like you are unbeatable!"); | |
ae2685f6 | 1407 | user->stats->defense += 1 + (rand() % 10 >= 8 ? 1 : 0); // 1-2 |
83cf716f | 1408 | notice(s_GameServ, u, "You gain %d Defense points!", user->stats->defense - olddefense); |
1409 | p->decDefense(); | |
35cba3f5 | 1410 | if (player_fight(user)) |
1411 | { | |
1412 | notice(s_GameServ, user->stats->battle->getNick(), | |
1413 | "%s has used a defense potion!"); | |
1414 | } | |
83cf716f | 1415 | } |
8c734eb9 | 1416 | else if (stricmp(item, "HP") == 0) |
1417 | { | |
1418 | if (p->HP() <= 0) | |
1419 | { | |
1420 | notice(s_GameServ, u, "You are out of HP Potions!"); | |
1421 | return; | |
1422 | } | |
1423 | int oldHP = user->stats->maxhp; | |
1424 | notice(s_GameServ, u, "You feel your life growing longer as you drink the green glowing liquid."); | |
4e64da60 | 1425 | user->stats->maxhp += 2 + |
1426 | (rand() % 100 > 70 ? (rand() % 7) : (rand() % 2) ); | |
ae2685f6 | 1427 | |
8c734eb9 | 1428 | notice(s_GameServ, u, "You gain %d Maximum hit points!", user->stats->maxhp - oldHP); |
1429 | p->decHP(); | |
35cba3f5 | 1430 | if (player_fight(user)) |
1431 | { | |
1432 | notice(s_GameServ, user->stats->battle->getNick(), | |
1433 | "%s has used a HP potion!"); | |
1434 | } | |
8c734eb9 | 1435 | } |
ee38284f | 1436 | else |
1437 | { | |
35cba3f5 | 1438 | notice(s_GameServ, u, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}"); |
ee38284f | 1439 | return; |
1440 | } | |
83cf716f | 1441 | |
1442 | end_turn(user); // If they're fighting, end their turn | |
1443 | } | |
c8ada07e | 1444 | void do_run(char *u) |
1445 | { | |
1446 | aClient *user; | |
28f552b8 | 1447 | Player *p, *p2 = NULL; |
85ce9d3e | 1448 | |
c8ada07e | 1449 | if (!(user = find(u))) |
1450 | { | |
1451 | notice(s_GameServ, u, "Couldn't find you. Error. Contact a %S admin"); | |
1452 | return; | |
1453 | } | |
448a1531 | 1454 | else if (isIgnore(user)) |
1455 | { | |
1456 | #ifdef DEBUGMODE | |
1457 | log("Ignoring %s.", user->getNick()); | |
1458 | #endif | |
1459 | return; | |
1460 | } | |
bb668fcf | 1461 | else if (!is_playing(user)) |
1462 | { | |
adaf4cdb | 1463 | notice(s_GameServ, u, "You must be playing to run!"); |
bb668fcf | 1464 | return; |
1465 | } | |
1466 | ||
40251952 | 1467 | updateTS(user->stats); |
c8ada07e | 1468 | p = user->stats; |
1469 | ||
1470 | if (p->battle) | |
1471 | p2 = p->battle->stats; | |
1472 | ||
1af35752 | 1473 | if (!is_fighting(user)) |
c8ada07e | 1474 | notice(s_GameServ, u, "You run in place... try fighting next time."); |
1af35752 | 1475 | else if (!player_fight(user) && !master_fight(user)) |
c8ada07e | 1476 | { |
1477 | notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p->fight->name); | |
1478 | delete p->fight; | |
1479 | p->fight = NULL; | |
1480 | } | |
ee38284f | 1481 | else if (player_fight(user) && isYourTurn(p)) |
c8ada07e | 1482 | { |
1483 | notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p2->name); | |
1484 | notice(s_GameServ, p->battle->getNick(), "\ 2%s\ 2 ran away from you like a little baby!", p->name); | |
1485 | p2->battle = NULL; | |
1486 | } | |
ee38284f | 1487 | else if (player_fight(user) && !isYourTurn(p)) |
c8ada07e | 1488 | { |
1489 | notice(s_GameServ, u, "It is not your turn. Please wait until \ 2%s\ 2 decides what to do.", p2->name); | |
1490 | } | |
1af35752 | 1491 | else if (master_fight(user)) |
c8ada07e | 1492 | { |
1493 | notice(s_GameServ, u, "You cannot run from \ 2%s\ 2! FIGHT!", p->master->name); | |
1494 | } | |
1495 | p->battle = NULL; | |
1496 | } | |
83cf716f | 1497 | |
1498 | void end_turn(aClient *user) | |
1499 | { | |
1500 | char *nick, *u = user->getNick(); | |
1501 | Monster *fight; | |
1502 | aClient *battle; | |
1503 | int mhit; | |
1504 | ||
1505 | nick = new char[strlen(user->getNick()) + 1]; | |
1506 | ||
1507 | if (!user || !is_playing(user) || !is_fighting(user)) | |
1508 | goto endturn; | |
1509 | ||
1510 | if (!player_fight(user) && !master_fight(user)) | |
1511 | fight = user->stats->fight; | |
1512 | else | |
1513 | fight = user->stats->master; | |
1514 | battle = user->stats->battle; | |
1515 | ||
1516 | if (!player_fight(user)) | |
1517 | { | |
1518 | // Opponent's Hit | |
1519 | mhit = (fight->strength / 2) + | |
1520 | (rand() % (fight->strength / 2) - (user->stats->defense + | |
1521 | arbonus[user->stats->armor])); | |
1522 | } | |
1523 | else | |
1524 | { | |
1525 | // Opponent's Hit | |
1526 | mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) + | |
1527 | (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) - | |
1528 | (user->stats->defense + arbonus[user->stats->armor])); | |
1529 | } | |
1530 | if (!player_fight(user)) | |
1531 | { | |
1532 | ||
1533 | if (mhit > 0) | |
1534 | { | |
1535 | notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!", | |
1536 | fight->name, fight->weapon, mhit); | |
1537 | } | |
1538 | else if (mhit <= 0) | |
1539 | notice(s_GameServ, u, "%s completely misses you!", fight->name); | |
1540 | ||
1541 | if (mhit >= user->stats->hp) | |
1542 | { | |
1543 | if (!master_fight(user)) | |
1544 | { | |
1545 | notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name); | |
1546 | notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\ | |
1547 | "of your experience!"); | |
1548 | user->stats->gold = 0; | |
1549 | user->stats->exp -= (long int)(user->stats->exp * .10); | |
b478c0df | 1550 | user->stats->hp = 0; |
83cf716f | 1551 | user->stats->fight = NULL; |
ee38284f | 1552 | clearAlive(user->stats); |
83cf716f | 1553 | goto endturn; |
1554 | } | |
1555 | else | |
1556 | { | |
1557 | notice(s_GameServ, u, "%s has bested you! You will have to wait "\ | |
1558 | "until tomorrow to try again", user->stats->master->name); | |
1559 | user->stats->fight = NULL; | |
1560 | user->stats->master = NULL; | |
1561 | goto endturn; | |
1562 | } | |
1563 | } | |
1564 | else | |
1565 | { | |
1566 | if (mhit > 0) | |
1567 | user->stats->hp -= mhit; | |
1568 | display_monster(u); | |
1569 | goto endturn; | |
1570 | } | |
1571 | } | |
1572 | else | |
1573 | { | |
ee38284f | 1574 | clearYourTurn(user->stats); |
1575 | setYourTurn(battle->stats); | |
83cf716f | 1576 | display_players(battle); |
1577 | } | |
1578 | endturn: | |
1579 | delete nick; | |
1580 | } | |
1581 | ||
85ce9d3e | 1582 | void do_attack(char *u) |
1583 | { | |
1584 | int hit, mhit; | |
1585 | aClient *ni, *battle; // The player and perhaps the player they're fighting | |
1586 | Monster *fight; // The monster they may be fighting | |
1587 | ||
1588 | if (!(ni = find(u))) | |
83cf716f | 1589 | { |
1590 | notice(s_GameServ, u, "Fatal error in do_attack. Contact a(n) %S admin for help."); | |
1591 | return; | |
1592 | } | |
448a1531 | 1593 | else if (isIgnore(ni)) |
1594 | { | |
1595 | #ifdef DEBUGMODE | |
1596 | log("Ignoring %s.", ni->getNick()); | |
1597 | #endif | |
1598 | return; | |
1599 | } | |
83cf716f | 1600 | else if (!is_playing(ni)) |
85ce9d3e | 1601 | { |
1602 | notice(s_GameServ, u, "You're not playing!"); | |
1603 | return; | |
1604 | } | |
83cf716f | 1605 | else if (!is_fighting(ni)) |
85ce9d3e | 1606 | { |
1607 | notice(s_GameServ, u, "You're not in battle!"); | |
1608 | return; | |
1609 | } | |
1610 | else | |
1611 | { | |
1612 | if (!ni->stats->master) // This is not a master fight | |
1613 | fight = ni->stats->fight; // Monster Could be NULL | |
1614 | else // This IS a master fight | |
1615 | fight = ni->stats->master; // Master Could be NULL | |
1616 | ||
1617 | battle = ni->stats->battle; // Player Could be NULL | |
1618 | ||
1619 | // One has to be !NULL based on the previous else if | |
1620 | // We wouldn't be here if they were all NULL | |
1621 | } | |
40251952 | 1622 | updateTS(ni->stats); |
85ce9d3e | 1623 | |
1af35752 | 1624 | if (!player_fight(ni)) |
85ce9d3e | 1625 | { |
1626 | // Player's Hit | |
1627 | hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) + | |
1628 | (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2)); | |
1629 | ||
1630 | // Opponent's Hit | |
1631 | mhit = (fight->strength / 2) + | |
1632 | (rand() % (fight->strength / 2) - (ni->stats->defense + | |
1633 | arbonus[ni->stats->armor])); | |
1634 | } | |
1635 | else | |
1636 | { | |
1637 | // Opponent's Hit | |
1638 | mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) + | |
1639 | (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) - | |
1640 | (ni->stats->defense + arbonus[ni->stats->armor])); | |
1641 | ||
1642 | // Player's Hit | |
1643 | hit = (((ni->stats->strength + webonus[ni->stats->weapon]) / 2) + | |
1644 | (rand() % ((ni->stats->strength + webonus[ni->stats->weapon])) / 2) - | |
1645 | (battle->stats->defense + arbonus[battle->stats->armor])); | |
1646 | } | |
1647 | ||
1af35752 | 1648 | if (!player_fight(ni)) |
85ce9d3e | 1649 | { |
1650 | if (hit > 0) | |
1651 | notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", fight->name, hit); | |
1652 | else | |
1653 | notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name); | |
1654 | ||
1655 | if (hit >= fight->hp) | |
1656 | { | |
1af35752 | 1657 | if (master_fight(ni)) |
c260a8d7 | 1658 | { |
85ce9d3e | 1659 | notice(s_GameServ, u, "You have bested %s!", fight->name); |
c260a8d7 | 1660 | addNews(todaysnews, "%s has bested %s and moved "\ |
1661 | "to level %d", ni->stats->name, fight->name, | |
1662 | (ni->stats->level + 1)); | |
1663 | } | |
85ce9d3e | 1664 | else |
1665 | notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name); | |
1666 | ||
1667 | notice(s_GameServ, u, "%s", fight->death); | |
1668 | notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!", | |
1669 | fight->exp, fight->gold); | |
1670 | ||
1671 | // If your new experience (or gold) will be greater than 2 billion, | |
1672 | // then set your exp to 2bil. (2 billion max)... otherwise add them. | |
1673 | // This could be a problem with overflowing out of the sign bit. | |
1674 | // Unsigned long int maybe? Leave it for now. | |
082f064d | 1675 | ni->stats->exp += fight->exp; |
1676 | if (ni->stats->exp < 0 || ni->stats->exp > 2000000000) | |
1677 | ni->stats->exp = 2000000000; | |
c8ada07e | 1678 | |
082f064d | 1679 | ni->stats->gold += fight->gold; |
1680 | if (ni->stats->gold < 0 || ni->stats->gold > 2000000000) | |
1681 | ni->stats->gold = 2000000000; | |
85ce9d3e | 1682 | |
1af35752 | 1683 | if (master_fight(ni)) |
85ce9d3e | 1684 | { |
1685 | notice(s_GameServ, u, "You are now level %d!", ni->stats->level + 1); | |
1686 | notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!", | |
1687 | strbonus[ni->stats->level - 1], defbonus[ni->stats->level - 1]); | |
1688 | ||
1689 | // Increase your level | |
85ce9d3e | 1690 | |
1691 | // Increase your maximum hit points | |
1692 | ni->stats->maxhp += hpbonus[ni->stats->level - 1]; | |
1693 | ||
1694 | // Heal the player by setting hp to their max | |
1695 | ni->stats->hp = ni->stats->maxhp; | |
1696 | ||
1697 | // Add to your strength | |
1698 | ni->stats->strength += strbonus[ni->stats->level - 1]; | |
1699 | ||
1700 | // Add to your defensive power | |
1701 | ni->stats->defense += defbonus[ni->stats->level - 1]; | |
1702 | ||
6370e3da | 1703 | ni->stats->level++; |
1704 | ||
85ce9d3e | 1705 | // Clear the pointer for your master |
1706 | ni->stats->master = NULL; | |
1707 | } | |
ab4f4ec0 | 1708 | |
1709 | // They're dead so remove the pointer | |
1710 | delete ni->stats->fight; | |
1711 | ni->stats->fight = NULL; | |
1712 | ni->stats->master = NULL; | |
1713 | ||
85ce9d3e | 1714 | return; |
1715 | } | |
1716 | else | |
1717 | { | |
1718 | if (hit > 0) | |
1719 | fight->hp -= hit; | |
1720 | if (mhit > 0) | |
1721 | { | |
e282e9d2 | 1722 | notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!", |
85ce9d3e | 1723 | fight->name, fight->weapon, mhit); |
1724 | } | |
1725 | else if (mhit <= 0) | |
1726 | notice(s_GameServ, u, "%s completely misses you!", fight->name); | |
1727 | ||
1728 | if (mhit >= ni->stats->hp) | |
1729 | { | |
1af35752 | 1730 | if (!master_fight(ni)) |
85ce9d3e | 1731 | { |
1732 | notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name); | |
1733 | notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\ | |
1734 | "of your experience!"); | |
c260a8d7 | 1735 | addNews(todaysnews, "%s has been killed by %s!", |
1736 | ni->stats->name, fight->name); | |
85ce9d3e | 1737 | ni->stats->gold = 0; |
1738 | ni->stats->exp -= (long int)(ni->stats->exp * .10); | |
b478c0df | 1739 | ni->stats->hp = 0; |
85ce9d3e | 1740 | ni->stats->fight = NULL; |
ee38284f | 1741 | clearAlive(ni->stats); |
85ce9d3e | 1742 | return; |
1743 | } | |
1744 | else | |
1745 | { | |
1746 | notice(s_GameServ, u, "%s has bested you! You will have to wait "\ | |
1747 | "until tomorrow to try again", ni->stats->master->name); | |
c260a8d7 | 1748 | addNews(todaysnews, "%s tried to best %s and failed!", |
1749 | ni->stats->name, fight->name); | |
85ce9d3e | 1750 | ni->stats->fight = NULL; |
1751 | ni->stats->master = NULL; | |
1752 | return; | |
1753 | } | |
1754 | } | |
1755 | else | |
1756 | { | |
1757 | if (mhit > 0) | |
1758 | ni->stats->hp -= mhit; | |
1759 | display_monster(u); | |
1760 | return; | |
1761 | } | |
1762 | } | |
1763 | } | |
1af35752 | 1764 | else if (player_fight(ni)) |
85ce9d3e | 1765 | { |
1766 | /* Offline fighting not available yet | |
1767 | if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online)) | |
1768 | { | |
1769 | if (hit > 0) | |
1770 | notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->nick, hit); | |
1771 | else | |
1772 | notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->nick); | |
1773 | if (hit >= battle->stats->hp) | |
1774 | { | |
1775 | notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->nick); | |
1776 | * notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!", | |
1777 | (long int)(battle->stats->exp * .10), battle->stats->gold); | |
1778 | if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10)) | |
1779 | { | |
1780 | ni->stats->exp += (long int)(battle->stats->exp * .10); | |
1781 | battle->stats->exp -= (long int)(battle->stats->exp * .10); | |
1782 | } | |
1783 | * else | |
1784 | { | |
1785 | battle->stats->exp -= (long int)(battle->stats->exp * .10); | |
1786 | ni->stats->exp = 2000000000; | |
1787 | } | |
1788 | ||
1789 | if (2000000000 - ni->stats->gold > battle->stats->gold) | |
1790 | { | |
1791 | * ni->stats->gold += battle->stats->gold; | |
1792 | battle->stats->gold = 0; | |
1793 | } | |
1794 | else | |
1795 | { | |
1796 | battle->stats->gold = 2000000000 - ni->stats->gold; | |
1797 | ni->stats->gold = 2000000000; | |
1798 | } | |
1799 | * ni->stats->battle->stats->alive = 0; | |
1800 | ni->stats->battle->battle = NULL; | |
1801 | ni->stats->battle = NULL; | |
1802 | return; | |
1803 | } | |
1804 | else | |
1805 | { | |
1806 | if (hit > 0) | |
1807 | * battle->stats->hp -= hit; | |
1808 | if (mhit > 0) | |
1809 | { | |
1810 | notice(s_GameServ, u, "\1f%s\1f hits you with their \1f%s\1f for \ 2%d\ 2 damage!", | |
1811 | battle->nick, weapons[battle->stats->weapon], mhit); | |
1812 | } | |
1813 | else if (mhit <= 0) | |
1814 | notice(s_GameServ, u, "%s completely misses you!", battle->nick); | |
1815 | * | |
1816 | if (mhit >= ni->stats->hp) | |
1817 | { | |
1818 | notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", battle->nick); | |
1819 | if (2000000000 - battle->stats->gold > ni->stats->gold) | |
1820 | { | |
1821 | notice(s_GameServ, u, "%s took all your gold!", battle->nick); | |
1822 | battle->stats->gold += ni->stats->gold; | |
1823 | * ni->stats->gold = 0; | |
1824 | } | |
1825 | else | |
1826 | { | |
1827 | notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.", | |
1828 | battle->nick); | |
1829 | ni->stats->gold -= (2000000000 - battle->stats->gold); | |
1830 | notice(s_GameServ, u, "You were left dead with %d gold.", | |
1831 | * (long int)ni->stats->gold); | |
1832 | battle->stats->gold = 2000000000; | |
1833 | } | |
1834 | ni->stats->battle->battle = NULL; | |
1835 | ni->stats->battle = NULL; | |
1836 | ni->stats->alive = 0; | |
1837 | return; | |
1838 | } | |
1839 | * else | |
1840 | { | |
1841 | if (mhit > 0) | |
1842 | ni->stats->hp -= mhit; | |
1843 | display_players(u); | |
1844 | return; | |
1845 | } | |
1846 | } | |
1847 | } | |
1848 | * end offline fighting */ | |
1849 | ||
ce61cdfa | 1850 | if (is_playing(battle)) |
85ce9d3e | 1851 | { |
ee38284f | 1852 | if (!isYourTurn(ni->stats)) |
85ce9d3e | 1853 | { |
1854 | notice(s_GameServ, u, "Please wait until %s decides what to do!", | |
ce61cdfa | 1855 | battle->stats->name); |
85ce9d3e | 1856 | return; |
1857 | } | |
1858 | if (hit > 0) | |
1859 | { | |
ce61cdfa | 1860 | notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->stats->name, hit); |
85ce9d3e | 1861 | |
1862 | notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\ | |
ce61cdfa | 1863 | "\ 2%d\ 2 damage!", ni->stats->name, |
1864 | weapons[ni->stats->weapon], hit); | |
85ce9d3e | 1865 | } |
1866 | else | |
1867 | { | |
ce61cdfa | 1868 | notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->stats->name); |
1869 | notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->name); | |
85ce9d3e | 1870 | } |
c260a8d7 | 1871 | |
85ce9d3e | 1872 | if (hit >= battle->stats->hp) |
1873 | { | |
ce61cdfa | 1874 | notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->stats->name); |
85ce9d3e | 1875 | notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!", |
1876 | (long int)(battle->stats->exp * .10), battle->stats->gold); | |
ce61cdfa | 1877 | notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", |
1878 | ni->stats->name); | |
85ce9d3e | 1879 | battle->stats->hp = 0; |
ee38284f | 1880 | clearAlive(battle->stats); |
85ce9d3e | 1881 | |
082f064d | 1882 | ni->stats->exp += (long int)(battle->stats->exp * .10); |
1883 | battle->stats->exp -= (long int)(battle->stats->exp * .10); | |
1884 | ||
1885 | if (ni->stats->exp < 0 || ni->stats->exp > 2000000000) | |
85ce9d3e | 1886 | ni->stats->exp = 2000000000; |
85ce9d3e | 1887 | |
1888 | if (2000000000 - ni->stats->gold > battle->stats->gold) | |
1889 | { | |
1890 | notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\ | |
1891 | "all gold on hand!"); | |
1892 | ni->stats->gold += battle->stats->gold; | |
1893 | battle->stats->gold = 0; | |
1894 | } | |
1895 | else | |
1896 | { | |
1897 | battle->stats->gold = 2000000000 - ni->stats->gold; | |
1898 | notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!"); | |
1899 | ||
1900 | notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\ | |
ce61cdfa | 1901 | "gold.", ni->stats->name); |
85ce9d3e | 1902 | |
1903 | notice(s_GameServ, battle->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\ | |
1904 | "left. All is not lost!", battle->stats->gold); | |
1905 | ||
1906 | ni->stats->gold = 2000000000; | |
1907 | } | |
082f064d | 1908 | |
c260a8d7 | 1909 | clearYourTurn(ni->stats); |
1910 | clearYourTurn(battle->stats); | |
85ce9d3e | 1911 | battle->stats->battle = NULL; |
1912 | ni->stats->battle = NULL; | |
1913 | return; | |
1914 | } | |
1915 | else | |
1916 | { | |
1917 | if (hit > 0) | |
1918 | battle->stats->hp -= hit; | |
ee38284f | 1919 | clearYourTurn(ni->stats); |
1920 | setYourTurn(battle->stats); | |
c260a8d7 | 1921 | display_players(battle); |
85ce9d3e | 1922 | notice(s_GameServ, u, "Please wait while %s decides what to do!", |
ce61cdfa | 1923 | battle->stats->name); |
85ce9d3e | 1924 | return; |
1925 | } | |
1926 | } | |
1927 | } | |
1928 | } | |
ce61cdfa | 1929 | |
85ce9d3e | 1930 | void do_heal(char *u) |
1931 | { | |
1932 | aClient *ni; | |
1933 | char *amount = strtok(NULL, " "); | |
1934 | int price, num; | |
1935 | ||
1936 | if (!amount) | |
1937 | { | |
1938 | notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}"); | |
40251952 | 1939 | return; |
85ce9d3e | 1940 | } |
1af35752 | 1941 | else if (!(ni = find(u))) |
1942 | { | |
1943 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); | |
1944 | return; | |
1945 | } | |
448a1531 | 1946 | else if (isIgnore(ni)) |
1947 | { | |
1948 | #ifdef DEBUGMODE | |
1949 | log("Ignoring %s.", ni->getNick()); | |
1950 | #endif | |
1951 | return; | |
1952 | } | |
1af35752 | 1953 | else if (!is_playing(ni)) |
85ce9d3e | 1954 | { |
1955 | notice(s_GameServ, u, "You aren't playing!"); | |
1af35752 | 1956 | return; |
1957 | } | |
ee38284f | 1958 | else if (!isAlive(ni->stats)) |
1af35752 | 1959 | { |
1960 | notice(s_GameServ, u, "You are dead. Wait until tomorrow for healing."); | |
1961 | return; | |
85ce9d3e | 1962 | } |
1af35752 | 1963 | else if (is_fighting(ni)) |
85ce9d3e | 1964 | { |
1965 | notice(s_GameServ, u, "You can't heal in battle!"); | |
40251952 | 1966 | return; |
85ce9d3e | 1967 | } |
1968 | else if (ni->stats->hp >= ni->stats->maxhp) | |
1969 | { | |
1970 | notice(s_GameServ, u, "You don't need healing!"); | |
40251952 | 1971 | return; |
85ce9d3e | 1972 | } |
40251952 | 1973 | |
1974 | updateTS(ni->stats); | |
1975 | if (stricmp(amount, "ALL") == 0) | |
85ce9d3e | 1976 | { |
1977 | price = ni->stats->level * 3; | |
1978 | if (ni->stats->gold < (ni->stats->maxhp - ni->stats->hp) * price) | |
1979 | { | |
1980 | notice(s_GameServ, u, "Healing \ 2%d\ 2 points for \ 2%d\ 2 gold per point.", | |
1981 | (long int)ni->stats->gold/price, price); | |
1982 | ni->stats->hp += ni->stats->gold / price; | |
1983 | ni->stats->gold %= price; | |
1984 | } | |
1985 | else | |
1986 | { | |
1987 | notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\ | |
1988 | "per point.", price); | |
ad7dfaa0 | 1989 | notice(s_GameServ, u, "\ 2%d\ 2 points healed for \ 2%ld\ 2 gold. HP at MAX!", |
1990 | (ni->stats->maxhp - ni->stats->hp), | |
1991 | (price * (ni->stats->maxhp - ni->stats->hp)) ); | |
85ce9d3e | 1992 | ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp); |
1993 | ni->stats->hp = ni->stats->maxhp; | |
1994 | } | |
1995 | } | |
1996 | else if (isstringnum(amount)) | |
1997 | { | |
1998 | num = stringtoint(amount); | |
1999 | price = ni->stats->level * 3; | |
2000 | if (ni->stats->gold < price * num) | |
2001 | { | |
2002 | notice(s_GameServ, u, "You only have enough gold to heal \ 2%d\ 2 points!", | |
2003 | (long int)ni->stats->gold/price); | |
2004 | } | |
2005 | else if (num <= ni->stats->maxhp - ni->stats->hp) | |
2006 | { | |
2007 | notice(s_GameServ, u, "Healing \ 2%d\ 2 points at \ 2%d\ 2 gold per point.", | |
2008 | num, price); | |
2009 | ni->stats->hp += num; | |
2010 | ni->stats->gold -= num * price; | |
2011 | } | |
2012 | else if (num > ni->stats->maxhp - ni->stats->hp) | |
2013 | { | |
2014 | notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\ | |
2015 | "per point.", price); | |
2016 | notice(s_GameServ, u, "\ 2%d\ 2 points healed. HP at MAX!", | |
2017 | (ni->stats->maxhp - ni->stats->hp)); | |
2018 | ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp); | |
2019 | ni->stats->hp = ni->stats->maxhp; | |
2020 | } | |
2021 | } | |
2022 | else if (amount[0] == '-') | |
2023 | notice(s_GameServ, u, "You trying to cheat?"); | |
2024 | else | |
2025 | notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}"); | |
2026 | } | |
2027 | ||
2028 | int isstringnum(char *num) | |
2029 | { | |
28f552b8 | 2030 | unsigned int x; |
85ce9d3e | 2031 | for (x = 0; x < strlen(num); x++) |
2032 | { | |
2033 | if ((int)num[x] < 48 || (int)num[x] > 57) | |
2034 | return 0; | |
2035 | } | |
2036 | return 1; | |
2037 | } | |
2038 | ||
2039 | long int stringtoint(char *number) | |
2040 | { | |
2041 | long int x, len = strlen(number), sum = 0; | |
2042 | if (len == 1) | |
2043 | return chartoint(number[0]); | |
2044 | sum += chartoint(number[len - 1]); | |
2045 | for (x = len - 2; x >= 0; x--) | |
85ce9d3e | 2046 | sum += chartoint(number[x]) * pow(10, abs(x - len + 1)); |
85ce9d3e | 2047 | return sum; |
2048 | } | |
2049 | ||
2050 | long int pow(int x, int y) | |
2051 | { | |
2052 | long int value = 0; | |
2053 | int count = 0; | |
2054 | value += x; | |
2055 | ||
2056 | if (x != 0 && y != 0) | |
2057 | { | |
2058 | for (count = 1; count <= y - 1; count++) | |
2059 | value *= x; | |
2060 | } | |
2061 | else | |
2062 | return 1; | |
2063 | return value; | |
2064 | } | |
2065 | ||
2066 | long int chartoint(char ch) | |
2067 | { | |
8c126acc | 2068 | if (int(ch) >= 48 && int(ch) <= 57) |
2069 | return int(ch) - 48; | |
2070 | else | |
2071 | return 0; | |
85ce9d3e | 2072 | } |
2073 | ||
2074 | int save_gs_dbase() | |
2075 | { | |
7996e5fd | 2076 | ListNode<aClient> *ptr; |
85ce9d3e | 2077 | Player *it; |
2078 | ofstream outfile; | |
2079 | ||
2080 | outfile.open(playerdata); | |
2081 | ||
2082 | if (!outfile) | |
2083 | { | |
fb37ecc7 | 2084 | log("Error opening %s", playerdata); |
85ce9d3e | 2085 | return 0; |
2086 | } | |
2087 | ||
7996e5fd | 2088 | for (unsigned long x = 0; x < U_TABLE_SIZE; x++) |
2089 | { | |
2090 | ptr = players[x].First(); | |
85ce9d3e | 2091 | while(ptr) |
2092 | { | |
2093 | it = ptr->getData()->stats; | |
ae2685f6 | 2094 | clearYourTurn(it); |
85ce9d3e | 2095 | outfile << it->name << ' ' << it->level << ' ' << it->exp << ' ' << it->gold << ' ' << it->bank << ' ' |
2096 | << it->hp << ' ' << it->maxhp << ' ' << it->strength << ' ' << it->defense << ' ' | |
ee38284f | 2097 | << it->armor << ' ' << it->weapon << ' ' |
e3c5fe46 | 2098 | << it->forest_fights << ' ' << it->player_fights << ' ' |
266608f6 | 2099 | << it->getFlags() << ' ' << it->password << ' ' << it->inventory.Healing() |
14e24ba1 | 2100 | << ' ' << it->inventory.Strength() << ' ' << it->inventory.Defense() << ' ' << it->inventory.HP() |
82c01ddf | 2101 | << ' ' << it->lastlogin << endl; |
85ce9d3e | 2102 | ptr = ptr->Next(); |
2103 | } | |
7996e5fd | 2104 | } |
85ce9d3e | 2105 | outfile.close(); |
28f552b8 | 2106 | return 1; |
85ce9d3e | 2107 | } |
2108 | ||
2109 | int load_gs_dbase() | |
2110 | { | |
2111 | ifstream infile; | |
2112 | aClient *temp; | |
2113 | Player *p; | |
ee38284f | 2114 | char *tempname, *buf, *password; |
85ce9d3e | 2115 | buf = new char[1023]; |
2116 | ||
2117 | infile.open(playerdata); | |
2118 | ||
2119 | if (infile.fail()) | |
2120 | { | |
fb37ecc7 | 2121 | log("Error opening %s", playerdata); |
85ce9d3e | 2122 | return 0; |
2123 | } | |
2124 | ||
19795233 | 2125 | for (int x = 0; x < U_TABLE_SIZE; x++) |
2126 | { | |
2127 | ListNode<aClient> *tempNode; | |
2128 | tempNode = players[x].First(); | |
2129 | while (tempNode) | |
2130 | { | |
2131 | if (tempNode->getData()->stats->client) | |
2132 | logout(tempNode->getData()->stats->client); | |
2133 | tempNode = tempNode->Next(); | |
2134 | } | |
2135 | players[x].deleteNodes(); | |
2136 | } | |
2137 | ||
85ce9d3e | 2138 | while (infile.getline(buf, 1024, '\n')) |
2139 | { | |
2140 | temp = new aClient; | |
2141 | tempname = strtok(buf, " "); | |
2142 | temp->stats = new Player(tempname); | |
2143 | p = temp->stats; | |
2144 | ||
85ce9d3e | 2145 | p->level = stringtoint(strtok(NULL, " ")); |
2146 | p->exp = stringtoint(strtok(NULL, " ")); | |
2147 | p->gold = stringtoint(strtok(NULL, " ")); | |
2148 | p->bank = stringtoint(strtok(NULL, " ")); | |
2149 | p->hp = stringtoint(strtok(NULL, " ")); | |
2150 | p->maxhp = stringtoint(strtok(NULL, " ")); | |
2151 | p->strength = stringtoint(strtok(NULL, " ")); | |
2152 | p->defense = stringtoint(strtok(NULL, " ")); | |
2153 | p->armor = stringtoint(strtok(NULL, " ")); | |
2154 | p->weapon = stringtoint(strtok(NULL, " ")); | |
85ce9d3e | 2155 | p->forest_fights = stringtoint(strtok(NULL, " ")); |
2156 | p->player_fights = stringtoint(strtok(NULL, " ")); | |
1af35752 | 2157 | p->setFlags(stringtoint(strtok(NULL, " "))); |
ee38284f | 2158 | |
e3c5fe46 | 2159 | password = strtok(NULL, " "); |
2160 | strcpy(p->password, password); | |
448a1531 | 2161 | temp->setNick("Not Playing"); |
ce61cdfa | 2162 | #ifdef P10 |
448a1531 | 2163 | temp->setRealNick("Not Playing"); |
ce61cdfa | 2164 | #endif |
85ce9d3e | 2165 | |
9d3b1d42 | 2166 | p->inventory.reset(); // Set inventory to all 0s |
ee38284f | 2167 | // Old player databases didn't have these three extra values |
2168 | // If they come up null, leave them to 0 as the default. | |
2169 | // On the next gameserv database save, it will save the values. | |
266608f6 | 2170 | tempname = strtok(NULL, " "); |
9d3b1d42 | 2171 | if (tempname) |
2172 | p->inventory.setHealing(stringtoint(tempname)); | |
2173 | ||
2174 | tempname = strtok(NULL, " "); | |
2175 | if (tempname) | |
2176 | p->inventory.setStrength(stringtoint(tempname)); | |
2177 | ||
2178 | tempname = strtok(NULL, " "); | |
2179 | if (tempname) | |
2180 | p->inventory.setDefense(stringtoint(tempname)); | |
2181 | ||
2182 | tempname = strtok(NULL, " "); | |
2183 | if (tempname) | |
2184 | p->inventory.setHP(stringtoint(tempname)); | |
14e24ba1 | 2185 | |
2186 | tempname = strtok(NULL, " "); | |
2187 | if (tempname) | |
2188 | p->lastlogin = stringtoint(tempname); | |
2189 | else | |
2190 | p->lastlogin = time(NULL); | |
2191 | ||
448a1531 | 2192 | unsigned long hv = iHASH((unsigned char *) temp->stats->name); |
85bcf836 | 2193 | |
2194 | temp->stats->client = NULL; | |
7996e5fd | 2195 | players[hv].insertAtBack(temp); |
85ce9d3e | 2196 | delete temp; |
2197 | } | |
1cf88153 | 2198 | delete [] buf; |
28f552b8 | 2199 | infile.close(); |
2200 | return 1; | |
85ce9d3e | 2201 | } |
2202 | ||
e3c5fe46 | 2203 | bool passcmp(char *encrypted, char *plaintext) |
2204 | { | |
2205 | char salt[3]; | |
cdc9a6db | 2206 | char *plaintext2, *plainToencrypt; |
2207 | bool same = false; | |
2208 | ||
2209 | plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra | |
2210 | strcpy(plaintext2, plaintext); | |
2211 | ||
e3c5fe46 | 2212 | salt[0] = encrypted[0]; |
2213 | salt[1] = encrypted[1]; | |
2214 | salt[3] = '\0'; | |
cdc9a6db | 2215 | |
2216 | plainToencrypt = crypt(plaintext2, salt); | |
2217 | ||
2218 | same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false); | |
2219 | ||
2220 | delete []plaintext2; | |
2221 | ||
2222 | return same; | |
e3c5fe46 | 2223 | } |
2224 | ||
2225 | bool check_password(char *name, char *plaintext) | |
2226 | { | |
0a1518fa | 2227 | aClient *client; |
e3c5fe46 | 2228 | |
0a1518fa | 2229 | if (!(client = findplayer(name))) |
2230 | return false; | |
2231 | else | |
e3c5fe46 | 2232 | { |
0a1518fa | 2233 | return passcmp(client->stats->password, plaintext); |
e3c5fe46 | 2234 | } |
e3c5fe46 | 2235 | } |
1cf88153 | 2236 | |
ad7dfaa0 | 2237 | void do_store(char *u) |
2238 | { | |
2239 | char *cmd = strtok(NULL, " "); | |
2240 | char *item = strtok(NULL, " "); | |
2241 | char *num = strtok(NULL, " "); | |
2242 | char *space; | |
8c126acc | 2243 | int wep; |
2244 | aClient *user; | |
2245 | Player *p; | |
ad7dfaa0 | 2246 | |
1af35752 | 2247 | if (!cmd || !item) |
ad7dfaa0 | 2248 | { |
2249 | notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}"); | |
2250 | notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2"); | |
2251 | notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2"); | |
40251952 | 2252 | return; |
ad7dfaa0 | 2253 | } |
448a1531 | 2254 | else if (!(user = find(u))) |
2255 | { | |
2256 | log("Fatal Error: could not find %s in client list", u); | |
2257 | return; | |
2258 | } | |
2259 | else if (isIgnore(user)) | |
2260 | { | |
2261 | #ifdef DEBUGMODE | |
2262 | log("Ignoring %s.", user->getNick()); | |
2263 | #endif | |
2264 | return; | |
2265 | } | |
2266 | else if (!is_playing(user)) | |
40251952 | 2267 | { |
1af35752 | 2268 | notice(s_GameServ, u, "You must be playing to use the store!"); |
40251952 | 2269 | return; |
2270 | } | |
ee38284f | 2271 | else if (!isAlive(user->stats)) |
1af35752 | 2272 | { |
2273 | notice(s_GameServ, u, "You are dead. Wait until tomorrow to purchase weapons and armor!"); | |
2274 | return; | |
2275 | } | |
40251952 | 2276 | updateTS(user->stats); |
2277 | ||
2278 | if (stricmp(cmd, "LIST") == 0) | |
ad7dfaa0 | 2279 | { |
2280 | if (stricmp(item, "WEAPONS") == 0) | |
2281 | { | |
2282 | notice(s_GameServ, u, "Welcome to Kain's Armory"); | |
2283 | notice(s_GameServ, u, "Here are the weapons we have available for the killing, sire:"); | |
2284 | for (int x = 1; x < WNA; x++) | |
2285 | { | |
2286 | space = spaces(strlen(weapons[x]), "."); | |
2287 | notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, weapons[x], space, prices[x - 1]); | |
2288 | free(space); | |
2289 | } | |
2290 | notice(s_GameServ, u, "To purchase a weapon, type /msg %S STORE BUY \ 2NUM\ 2."); | |
2291 | notice(s_GameServ, u, "Where num. is the weapon number from the menu above."); | |
2292 | ||
2293 | } | |
2294 | else if (stricmp(item, "ARMOR") == 0) | |
2295 | { | |
2296 | notice(s_GameServ, u, "Welcome to Kain's Armory"); | |
2297 | notice(s_GameServ, u, "I hope you enjoy the fine armor we have available for your protection:"); | |
2298 | for (int x = 1; x < WNA; x++) | |
2299 | { | |
2300 | space = spaces(strlen(armors[x]), "."); | |
2301 | notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, armors[x], space, prices[x - 1]); | |
2302 | free(space); | |
2303 | } | |
2304 | notice(s_GameServ, u, "To purchase armor, type /msg %S store buy armor num."); | |
2305 | notice(s_GameServ, u, "Where num. is the armor number from the menu above."); | |
2306 | ||
2307 | ||
2308 | } | |
2309 | } else if (stricmp(cmd, "BUY") == 0) { | |
8c126acc | 2310 | if (!num) |
2311 | { | |
2312 | notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2"); | |
2313 | return; | |
2314 | } | |
2315 | else if (!isstringnum(num)) | |
2316 | { | |
2317 | notice(s_GameServ, u, "You must specify a number between 1 and %d. Not %s!", WNA - 1, num); | |
2318 | return; | |
2319 | } | |
2320 | if (stricmp(item, "WEAPON") == 0) | |
2321 | { | |
2322 | wep = stringtoint(num); | |
2323 | if (wep >= WNA || wep < 1) | |
2324 | { | |
2325 | notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1); | |
2326 | return; | |
2327 | } | |
2328 | ||
2329 | p = user->stats; | |
2330 | ||
2331 | if (p->weapon != 0) | |
2332 | notice(s_GameServ, u, "You have to sell your %s first!", weapons[p->weapon]); | |
2333 | else if (p->gold < prices[wep - 1]) | |
2334 | notice(s_GameServ, u, "You don't have enough gold for %s!", weapons[wep]); | |
2335 | else | |
2336 | { | |
2337 | notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", weapons[wep]); | |
2338 | p->weapon = wep; | |
2339 | p->gold -= prices[wep - 1]; | |
2340 | } | |
2341 | } | |
2342 | else if (stricmp(item, "ARMOR") == 0) | |
2343 | { | |
2344 | wep = stringtoint(num); | |
2345 | if (wep >= WNA || wep < 1) | |
2346 | { | |
2347 | notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1); | |
2348 | return; | |
2349 | } | |
2350 | ||
2351 | p = user->stats; | |
2352 | ||
2353 | if (p->armor != 0) | |
2354 | notice(s_GameServ, u, "You have to sell your %s first!", armors[p->armor]); | |
2355 | else if (p->gold < prices[wep - 1]) | |
2356 | notice(s_GameServ, u, "You don't have enough gold for %s!", armors[wep]); | |
2357 | else | |
2358 | { | |
2359 | notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", armors[wep]); | |
2360 | p->armor = wep; | |
2361 | p->gold -= prices[wep - 1]; | |
2362 | } | |
2363 | } | |
2364 | } | |
2365 | else if (stricmp(cmd, "SELL" ) == 0) | |
2366 | { | |
2367 | p = user->stats; | |
2368 | ||
2369 | if (stricmp(item, "WEAPON") == 0) | |
2370 | { | |
2371 | if (p->weapon == 0) | |
2372 | { | |
2373 | notice(s_GameServ, u, "You want me to chop off your hands?"); | |
2374 | return; | |
2375 | } | |
2376 | else if (p->gold == 2000000000) | |
2377 | { | |
2378 | notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire."); | |
2379 | p->weapon = 0; | |
2380 | } | |
2381 | else if (2000000000 - p->gold < (prices[p->weapon - 1] / 2)) | |
2382 | { | |
2383 | notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry."); | |
2384 | notice(s_GameServ, u, "However, you have no weapon... can I interest you in the %s?", weapons[WNA - 1]); | |
2385 | p->gold = 2000000000; | |
2386 | p->weapon = 0; | |
2387 | } | |
2388 | else | |
2389 | { | |
2390 | notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no weapon!", (prices[p->weapon - 1] / 2)); | |
2391 | p->gold += (prices[p->weapon - 1] / 2); | |
2392 | p->weapon = 0; | |
2393 | } | |
2394 | } | |
2395 | else if (stricmp(item, "ARMOR") == 0) | |
2396 | { | |
2397 | p = user->stats; | |
2398 | ||
2399 | if (p->armor == 0) | |
2400 | { | |
2401 | notice(s_GameServ, u, "I don't think you can be any more naked..."); | |
2402 | return; | |
2403 | } | |
2404 | if (p->gold == 2000000000) | |
2405 | { | |
2406 | notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire."); | |
2407 | p->armor = 0; | |
2408 | } | |
2409 | else if (2000000000 - p->gold < (prices[p->armor - 1] / 2)) | |
2410 | { | |
2411 | notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry."); | |
2412 | notice(s_GameServ, u, "However, you have no armor... can I interest you in %s?", armors[WNA - 1]); | |
2413 | p->gold = 2000000000; | |
2414 | p->armor = 0; | |
2415 | } | |
2416 | else | |
2417 | { | |
2418 | notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no armor!", | |
2419 | (prices[p->armor - 1] / 2)); | |
2420 | ||
2421 | p->gold += (prices[p->armor - 1] / 2); | |
2422 | p->armor = 0; | |
2423 | } | |
2424 | } | |
2425 | else | |
2426 | { | |
2427 | notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}"); | |
2428 | notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2"); | |
2429 | notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2"); | |
2430 | } | |
2431 | } | |
6d053d90 | 2432 | else |
2433 | { | |
2434 | notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}"); | |
2435 | notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2"); | |
2436 | notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2"); | |
2437 | return; | |
2438 | } | |
8c126acc | 2439 | } |
9cda831c | 2440 | void do_inventory(char *u) |
2441 | { | |
2442 | aClient *user; | |
2443 | ||
2444 | if (!(user = find(u))) | |
2445 | { | |
2446 | notice(s_GameServ, u, "Fatal Error. Contact a %S admin!"); | |
2447 | return; | |
2448 | } | |
448a1531 | 2449 | else if (isIgnore(user)) |
2450 | { | |
2451 | #ifdef DEBUGMODE | |
2452 | log("Ignoring %s.", user->getNick()); | |
2453 | #endif | |
2454 | return; | |
2455 | } | |
9cda831c | 2456 | else if (!is_playing(user)) |
2457 | { | |
2458 | notice(s_GameServ, u, "You must be playing to check your inventory!"); | |
2459 | return; | |
2460 | } | |
40251952 | 2461 | updateTS(user->stats); |
9cda831c | 2462 | showinventory(user, user); |
2463 | } | |
2464 | void showinventory(aClient *from, aClient *to) | |
2465 | { | |
2466 | char *nick = to->getNick(); | |
8c126acc | 2467 | |
9cda831c | 2468 | if (!to) |
2469 | to = from; | |
2470 | if (is_playing(from)) | |
2471 | { | |
2472 | Pouch *p = &from->stats->inventory; | |
ce61cdfa | 2473 | notice(s_GameServ, nick, "Inventory for %s:", from->stats->name); |
9cda831c | 2474 | notice(s_GameServ, nick, " Healing Potions: %d", p->Healing()); |
2475 | notice(s_GameServ, nick, "Strength Potions: %d", p->Strength()); | |
2476 | notice(s_GameServ, nick, " Defense Potions: %d", p->Defense()); | |
9d3b1d42 | 2477 | notice(s_GameServ, nick, " HP Potions: %d", p->HP()); |
9cda831c | 2478 | } |
2479 | } | |
f5c25639 | 2480 | void do_tavern(char *u) |
2481 | { | |
2482 | char *cmd = strtok(NULL, " "); | |
2483 | long int price; | |
2484 | ||
2485 | aClient *user; | |
2486 | Player *p; | |
a6352eed | 2487 | |
f5c25639 | 2488 | if (!(user = find(u))) |
2489 | { | |
2490 | notice(s_GameServ, u, "Fatal Error. See a %S admin for help"); | |
2491 | return; | |
2492 | } | |
448a1531 | 2493 | else if (isIgnore(user)) |
2494 | { | |
2495 | #ifdef DEBUGMODE | |
2496 | log("Ignoring %s.", user->getNick()); | |
2497 | #endif | |
2498 | return; | |
2499 | } | |
f5c25639 | 2500 | else if (!is_playing(user)) |
2501 | { | |
2502 | notice(s_GameServ, u, "You must be playing to go to the Tavern"); | |
2503 | return; | |
2504 | } | |
9cda831c | 2505 | else if (is_fighting(user)) |
2506 | { | |
2507 | notice(s_GameServ, u, "You cannot go to the Tavern during a fight!"); | |
2508 | return; | |
2509 | } | |
40251952 | 2510 | |
2511 | updateTS(user->stats); | |
f5c25639 | 2512 | p = user->stats; |
40251952 | 2513 | |
f5c25639 | 2514 | if (!cmd) |
2515 | { | |
2516 | notice(s_GameServ, u, "Welcome to Boot Liquors Mystic Apothecary"); | |
2517 | notice(s_GameServ, u, "Your commands:"); | |
2518 | notice(s_GameServ, u, "/msg %S TAVERN {LIST | BUY} [NUMBER]"); | |
2519 | notice(s_GameServ, u, "What'll it be?"); | |
2520 | } | |
2521 | else if (stricmp(cmd, "LIST") == 0) | |
2522 | { | |
a6352eed | 2523 | notice(s_GameServ, u, "Here is a list of what we have to offer:"); |
2524 | notice(s_GameServ, u, "1. Healing Potions for %ld Gold", | |
2525 | 1000 * p->level * 4); | |
2526 | notice(s_GameServ, u, "2. Strength Potions for %ld Gold", | |
2527 | 2500 * p->level * 4); | |
2528 | notice(s_GameServ, u, "3. Defense Potions for %ld Gold", | |
2529 | 3000 * p->level * 4); | |
2530 | notice(s_GameServ, u, "4. HP Potions for %ld Gold", | |
2531 | 2000 * p->level * 4); | |
2532 | notice(s_GameServ, u, "To buy a potion, type /msg %S TAVERN BUY #"); | |
2533 | notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1 buys a healing potion!"); | |
f5c25639 | 2534 | } |
2535 | else if (stricmp(cmd, "BUY") == 0) | |
2536 | { | |
2537 | char *chnum = strtok(NULL, " "); | |
f5c25639 | 2538 | |
2539 | if (!chnum) | |
2540 | { | |
2541 | notice(s_GameServ, u, "SYNTAX: TAVERN BUY #"); | |
2542 | notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1"); | |
2543 | return; | |
2544 | } | |
19795233 | 2545 | int num = stringtoint(chnum); |
2546 | ||
8c734eb9 | 2547 | if (num < 1 || num > 4) |
f5c25639 | 2548 | { |
2549 | notice(s_GameServ, u, "Invalid Choice!"); | |
2550 | notice(s_GameServ, u, "Here is a list of what we have to offer:"); | |
a6352eed | 2551 | notice(s_GameServ, u, "1. Healing Potions for %ld Gold", |
2552 | 1000 * p->level * 4); | |
2553 | notice(s_GameServ, u, "2. Strength Potions for %ld Gold", | |
2554 | 2500 * p->level * 4); | |
2555 | notice(s_GameServ, u, "3. Defense Potions for %ld Gold", | |
2556 | 3000 * p->level * 4); | |
2557 | notice(s_GameServ, u, "4. HP Potions for %ld Gold", | |
2558 | 2000 * p->level * 4); | |
f5c25639 | 2559 | notice(s_GameServ, u, "To buy a potion, type /msg %S TAVERN BUY #"); |
2560 | notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1 buys a healing potion!"); | |
ee38284f | 2561 | return; |
f5c25639 | 2562 | } |
2563 | switch(num) | |
2564 | { | |
2565 | case 1: | |
a6352eed | 2566 | price = (1000 * p->level * 4); |
f5c25639 | 2567 | if (p->gold >= price) |
2568 | { | |
2569 | notice(s_GameServ, u, "One healing potion coming right up!"); | |
2570 | p->inventory.incHealing(); | |
ee38284f | 2571 | p->gold -= price; |
f5c25639 | 2572 | } |
2573 | else | |
2574 | notice(s_GameServ, u, "You don't have enough gold!"); | |
2575 | break; | |
2576 | case 2: | |
a6352eed | 2577 | price = 2500 * p->level * 4; |
f5c25639 | 2578 | if (p->gold >= price) |
2579 | { | |
2580 | notice(s_GameServ, u, "One strength boost coming right up!"); | |
2581 | p->inventory.incStrength(); | |
ee38284f | 2582 | p->gold -= price; |
f5c25639 | 2583 | } |
2584 | else | |
2585 | notice(s_GameServ, u, "You don't have enough gold!"); | |
2586 | break; | |
2587 | case 3: | |
a6352eed | 2588 | price = 3000 * p->level * 4; |
f5c25639 | 2589 | if (p->gold >= price) |
2590 | { | |
2591 | notice(s_GameServ, u, "One defense boost coming right up!"); | |
2592 | p->inventory.incDefense(); | |
ee38284f | 2593 | p->gold -= price; |
f5c25639 | 2594 | } |
2595 | else | |
2596 | notice(s_GameServ, u, "You don't have enough gold!"); | |
2597 | break; | |
8c734eb9 | 2598 | case 4: |
a6352eed | 2599 | price = 3000 * p->level * 4; |
8c734eb9 | 2600 | if (p->gold >= price) |
2601 | { | |
2602 | notice(s_GameServ, u, "One HP Potion coming right up!"); | |
2603 | p->inventory.incHP(); | |
2604 | p->gold -= price; | |
2605 | } | |
2606 | else | |
2607 | notice(s_GameServ, u, "You don't have enough gold!"); | |
2608 | break; | |
f5c25639 | 2609 | default: |
2610 | notice(s_GameServ, u, "Logical Error. See a %S admin for help!"); | |
2611 | break; | |
2612 | } | |
2613 | } | |
9cda831c | 2614 | else |
2615 | { | |
2616 | notice(s_GameServ, u, "Improper Syntax."); | |
2617 | notice(s_GameServ, u, "Type /msg %S HELP TAVERN for help"); | |
2618 | } | |
f5c25639 | 2619 | } |
2620 | ||
8c126acc | 2621 | void do_bank(char *u) |
2622 | { | |
2623 | char *cmd = strtok(NULL, " "); | |
2624 | char *amount = strtok(NULL, " "); | |
2625 | char *nick = strtok(NULL, " "); | |
2626 | ||
2627 | aClient *user; | |
2628 | Player *p; | |
2629 | ||
8c734eb9 | 2630 | if (!cmd || (!amount && stricmp(cmd, "BALANCE") != 0) || (stricmp(cmd, "TRANSFER") == 0 && !nick)) |
8c126acc | 2631 | { |
2632 | notice(s_GameServ, u, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}"); | |
e282e9d2 | 2633 | notice (s_GameServ, u, "BANK BALANCE"); |
8c126acc | 2634 | return; |
2635 | } | |
40251952 | 2636 | else if (!(user = find(u))) |
2637 | { | |
2638 | notice(s_GameServ, u, "Fatal Error. Couldn't find your aClient. Contact a(n) %S "\ | |
2639 | " admin for help"); | |
2640 | log("Fatal Error. Couldn't find %s while executing do_bank()", u); | |
2641 | return; | |
2642 | } | |
448a1531 | 2643 | else if (isIgnore(user)) |
2644 | { | |
2645 | #ifdef DEBUGMODE | |
2646 | log("Ignoring %s.", user->getNick()); | |
2647 | #endif | |
2648 | return; | |
2649 | } | |
40251952 | 2650 | else if (!is_playing(user)) |
8c126acc | 2651 | { |
2652 | notice(s_GameServ, u, "You must be playing to use the bank!"); | |
2653 | return; | |
ad7dfaa0 | 2654 | } |
2158299e | 2655 | else if (is_fighting(user)) |
2656 | { | |
2657 | notice(s_GameServ, u, "You can't go to the bank during a fight!"); | |
2658 | return; | |
2659 | } | |
40251952 | 2660 | updateTS(user->stats); |
2661 | if (stricmp(cmd, "BALANCE") == 0) | |
fa376453 | 2662 | { |
2663 | showBankBalance(u); | |
2664 | return; | |
2665 | } | |
ee38284f | 2666 | else if (!isAlive(user->stats)) |
1af35752 | 2667 | { |
2668 | notice(s_GameServ, u, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!"); | |
2669 | return; | |
2670 | } | |
8c126acc | 2671 | else if (!isstringnum(amount) && stricmp(amount, "ALL") != 0) |
2672 | { | |
2673 | notice(s_GameServ, u, "I don't know how to convert alphabet letters into currency, sire!"); | |
2674 | return; | |
2675 | } | |
11f32a66 | 2676 | if (stringtoint(amount) < 0) |
2677 | { | |
2678 | notice(s_GameServ, u, "Sorry. This bank is not licensed "\ | |
2679 | "to handle such sums of cash, noble Lord."); | |
2680 | return; | |
2681 | } | |
8c126acc | 2682 | p = user->stats; |
2683 | ||
fa376453 | 2684 | if (stricmp(cmd, "DEPOSIT") == 0) |
8c126acc | 2685 | { |
2686 | if (p->bank == 2000000000) | |
2687 | { | |
2688 | notice(s_GameServ, u, "Your bank account is full, sire!"); | |
2689 | return; | |
2690 | } | |
2691 | else if (stricmp(amount, "ALL") == 0) | |
2692 | { | |
2693 | if (2000000000 - p->bank < p->gold) | |
2694 | { | |
2695 | notice(s_GameServ, u, "You don't have enough room for all of your gold."); | |
2696 | notice(s_GameServ, u, "Depositing %ld gold into your account", (2000000000 - p->bank)); | |
2697 | p->gold -= (2000000000 - p->bank); | |
2698 | p->bank = 2000000000; | |
e282e9d2 | 2699 | showBankBalance(u); |
8c126acc | 2700 | } |
2701 | else | |
2702 | { | |
2703 | notice(s_GameServ, u, "Depositing %ld gold into your account!", p->gold); | |
2704 | p->bank += p->gold; | |
2705 | p->gold = 0; | |
e282e9d2 | 2706 | showBankBalance(u); |
8c126acc | 2707 | } |
2708 | } | |
2709 | else if (stringtoint(amount) > p->gold) | |
2710 | { | |
2711 | notice(s_GameServ, u, "Sire, you only have %ld gold!", p->gold); | |
e282e9d2 | 2712 | showBankBalance(u); |
8c126acc | 2713 | return; |
2714 | } | |
2715 | else | |
2716 | { | |
2717 | if (2000000000 - p->bank < stringtoint(amount)) | |
2718 | { | |
2719 | notice(s_GameServ, u, "You don't have room in your account for that much."); | |
2720 | notice(s_GameServ, u, "Capping off your account with %ld gold!", (2000000000 - p->bank)); | |
2721 | p->gold -= (2000000000 - p->bank); | |
2722 | p->bank = 2000000000; | |
e282e9d2 | 2723 | showBankBalance(u); |
8c126acc | 2724 | } |
2725 | else | |
2726 | { | |
2727 | notice(s_GameServ, u, "Depositing %d gold into your account!", stringtoint(amount)); | |
2728 | p->bank += stringtoint(amount); | |
2729 | p->gold -= stringtoint(amount); | |
e282e9d2 | 2730 | showBankBalance(u); |
8c126acc | 2731 | } |
2732 | } | |
2733 | } | |
2734 | else if (stricmp(cmd, "WITHDRAW") == 0) | |
2735 | { | |
2736 | if (p->gold == 2000000000) | |
2737 | { | |
2738 | notice(s_GameServ, u, "You cannot carry any more gold, sire!"); | |
e282e9d2 | 2739 | showBankBalance(u); |
8c126acc | 2740 | return; |
2741 | } | |
2742 | else if (stricmp(amount, "ALL") == 0) | |
2743 | { | |
2744 | if (2000000000 - p->gold < p->bank) | |
2745 | { | |
2746 | notice(s_GameServ, u, "You don't have enough room to carry all that gold."); | |
2747 | notice(s_GameServ, u, "Withdrawing %ld gold from your account", (2000000000 - p->gold)); | |
2748 | p->bank -= (2000000000 - p->gold); | |
2749 | p->gold = 2000000000; | |
e282e9d2 | 2750 | showBankBalance(u); |
8c126acc | 2751 | } |
2752 | else | |
2753 | { | |
2754 | notice(s_GameServ, u, "Withdrawing %ld gold from your account!", p->bank); | |
2755 | p->gold += p->bank; | |
2756 | p->bank = 0; | |
e282e9d2 | 2757 | showBankBalance(u); |
8c126acc | 2758 | } |
2759 | } | |
2760 | else if (stringtoint(amount) > p->bank) | |
2761 | { | |
2762 | notice(s_GameServ, u, "Sire, you only have %ld gold in the bank!", p->bank); | |
e282e9d2 | 2763 | showBankBalance(u); |
8c126acc | 2764 | return; |
2765 | } | |
2766 | else | |
2767 | { | |
2768 | if (2000000000 - p->gold < stringtoint(amount)) | |
2769 | { | |
2770 | notice(s_GameServ, u, "You don't enough have room to carry that much gold!"); | |
2771 | notice(s_GameServ, u, "You fill your pockets with %ld gold!", | |
2772 | (2000000000 - p->gold)); | |
2773 | p->bank -= (2000000000 - p->gold); | |
2774 | p->gold = 2000000000; | |
e282e9d2 | 2775 | showBankBalance(u); |
8c126acc | 2776 | } |
2777 | else | |
2778 | { | |
2779 | notice(s_GameServ, u, "Withdrawing %d gold from your account!", stringtoint(amount)); | |
2780 | p->gold += stringtoint(amount); | |
2781 | p->bank -= stringtoint(amount); | |
e282e9d2 | 2782 | showBankBalance(u); |
8c126acc | 2783 | } |
2784 | } | |
2785 | } | |
2786 | ||
ad7dfaa0 | 2787 | } |
ab4f4ec0 | 2788 | |
fcca861d | 2789 | void do_dragon(char *u) |
2790 | { | |
2791 | aClient *user; | |
2792 | ||
2793 | if (!(user = find(u))) | |
2794 | { | |
2795 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); | |
2796 | return; | |
2797 | } | |
2798 | else if (isIgnore(user)) | |
2799 | { | |
2800 | #ifdef DEBUGMODE | |
2801 | log("Ignoring %s.", user->getNick()); | |
2802 | #endif | |
2803 | return; | |
2804 | } | |
2805 | else if (!is_playing(user)) | |
2806 | { | |
2807 | notice(s_GameServ, u, "You must be playing to fight the dragon!"); | |
2808 | return; | |
2809 | } | |
2810 | else if (is_fighting(user)) | |
2811 | { | |
2812 | notice(s_GameServ, u, "You are already in a fight. How will you fight the almighty dragon!?"); | |
2813 | return; | |
2814 | } | |
2815 | else if (!isAlive(user->stats)) | |
2816 | { | |
2817 | notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!"); | |
2818 | return; | |
2819 | } | |
016a160f | 2820 | else if (user->stats->level < REALLEVELS) |
fcca861d | 2821 | { |
2822 | notice(s_GameServ, u, "You fool! Only those strong enough "\ | |
2823 | "to vanquish any foe should DARE fight the dragon!"); | |
2824 | notice(s_GameServ, u, "To put it in terms you can understand: "\ | |
016a160f | 2825 | "You are too weak. You must be Level %d!", REALLEVELS); |
68379f96 | 2826 | return; |
fcca861d | 2827 | } |
2828 | ||
2829 | updateTS(user->stats); | |
2830 | ||
fcca861d | 2831 | Player *p = user->stats; |
082f064d | 2832 | p->fight = new Monster(&boss); |
fcca861d | 2833 | notice(s_GameServ, u, "You approach the dragon's lair cautiously."); |
2834 | notice(s_GameServ, u, "The stench of sulfer fills the air as a "\ | |
2835 | "deep, red fog rolls in. The air is filled with the "\ | |
2836 | "heated mist of deadly fire from beyond the cave "\ | |
2837 | "entrance."); | |
9cb6f227 | 2838 | notice(s_GameServ, u, "You adjust your %s, tighten your grip on "\ |
fcca861d | 2839 | "your %s, and venture into the hot, dark cave. "\ |
2840 | "You are surprised at the angle of descent as you climb "\ | |
2841 | "lower and lower, deeper into the dragon's den."); | |
2842 | notice(s_GameServ, u, "You come to the end of the cave to find "\ | |
2843 | "a tooth. It is a large tooth... bigger than your torso."\ | |
2844 | " Suddenly the darkness lifts from the gleam of an eye "\ | |
2845 | " staring into your soul! The eye is large... HUGE!"); | |
2846 | notice(s_GameServ, u, "Just then you notice the eye begin to "\ | |
2847 | "glare orange! The tooth is moving... but it is still too "\ | |
2848 | "dark for you to make out.... THE DRAGON! You see it!"); | |
9cb6f227 | 2849 | display_monster(u); |
fcca861d | 2850 | } |
2851 | ||
ab4f4ec0 | 2852 | void do_master(char *u) |
2853 | { | |
2854 | aClient *user; | |
1af35752 | 2855 | |
448a1531 | 2856 | |
2857 | if (!(user = find(u))) | |
ab4f4ec0 | 2858 | { |
2859 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); | |
2860 | return; | |
2861 | } | |
448a1531 | 2862 | else if (isIgnore(user)) |
2863 | { | |
2864 | #ifdef DEBUGMODE | |
2865 | log("Ignoring %s.", user->getNick()); | |
2866 | #endif | |
2867 | return; | |
2868 | } | |
c047f947 | 2869 | else if (!is_playing(user)) |
2870 | { | |
2871 | notice(s_GameServ, u, "You must be playing to see your master!"); | |
2872 | return; | |
2873 | } | |
1af35752 | 2874 | else if (is_fighting(user)) |
ab4f4ec0 | 2875 | { |
2876 | notice(s_GameServ, u, "You're in the middle of a fight! Pay attention!"); | |
2877 | return; | |
2878 | } | |
ee38284f | 2879 | else if (!isAlive(user->stats)) |
1af35752 | 2880 | { |
2881 | notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!"); | |
2882 | return; | |
2883 | } | |
40251952 | 2884 | |
2885 | updateTS(user->stats); | |
c047f947 | 2886 | |
c7340cbd | 2887 | char *cmd = strtok(NULL, " "); |
2888 | Player *p = user->stats; | |
2889 | long int need = 0; | |
2890 | ||
1af35752 | 2891 | if (seenMaster(p)) |
2892 | { | |
2893 | notice(s_GameServ, u, "You have already seen your master today. Wait until tomorrow to try again"); | |
2894 | return; | |
2895 | } | |
2896 | ||
c7340cbd | 2897 | if (cmd != NULL) |
ab4f4ec0 | 2898 | { |
ab4f4ec0 | 2899 | switch(p->level) |
2900 | { | |
2901 | case 1: | |
fcca861d | 2902 | need = 200; |
ab4f4ec0 | 2903 | break; |
2904 | case 2: | |
fcca861d | 2905 | need = 800; |
ab4f4ec0 | 2906 | break; |
2907 | case 3: | |
fcca861d | 2908 | need = 2000; |
ab4f4ec0 | 2909 | break; |
2910 | case 4: | |
fcca861d | 2911 | need = 8000; |
ab4f4ec0 | 2912 | break; |
2913 | case 5: | |
fcca861d | 2914 | need = 20000; |
ab4f4ec0 | 2915 | break; |
2916 | case 6: | |
fcca861d | 2917 | need = 80000; |
ab4f4ec0 | 2918 | break; |
2919 | case 7: | |
fcca861d | 2920 | need = 200000; |
ab4f4ec0 | 2921 | break; |
2922 | case 8: | |
fcca861d | 2923 | need = 800000; |
ab4f4ec0 | 2924 | break; |
2925 | case 9: | |
fcca861d | 2926 | need = 2000000; |
ab4f4ec0 | 2927 | break; |
2928 | case 10: | |
fcca861d | 2929 | need = 8000000; |
ab4f4ec0 | 2930 | break; |
2931 | case 11: | |
fcca861d | 2932 | need = 20000000; |
ab4f4ec0 | 2933 | break; |
016a160f | 2934 | |
2935 | case REALLEVELS: | |
ab4f4ec0 | 2936 | need = p->exp + 1; |
016a160f | 2937 | notice(s_GameServ, u, "You are at level %d. You are the master. What's left? The DRAGON!", REALLEVELS); |
fcca861d | 2938 | return; |
ab4f4ec0 | 2939 | break; |
2940 | default: | |
2941 | need = p->exp + 1; // Unknown level... don't let them fight a fake master! | |
2942 | break; | |
c7340cbd | 2943 | } |
2944 | } | |
2945 | else | |
2946 | { | |
2947 | notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}"); | |
2948 | return; | |
2949 | } | |
2950 | ||
2951 | if (stricmp(cmd, "FIGHT") == 0) | |
2952 | { | |
ab4f4ec0 | 2953 | if (p->exp >= need) |
1af35752 | 2954 | { |
2955 | setMaster(p); | |
ab4f4ec0 | 2956 | see_master(u); |
1af35752 | 2957 | } |
ab4f4ec0 | 2958 | else |
2959 | notice(s_GameServ, u, "You are not worthy of fighting %s! You need %ld more experience.", masters[p->level - 1]->name, (need - p->exp)); | |
c7340cbd | 2960 | return; |
2961 | } | |
2962 | else if (stricmp(cmd, "QUESTION") == 0) | |
2963 | { | |
2964 | if (p->exp >= need) | |
2965 | notice(s_GameServ, u, "%s looks you up and down and decides you are more ready than you will ever be.", masters[p->level - 1]->name); | |
2966 | else | |
2967 | notice(s_GameServ, u, "You pathetic fool! You are no match for %s, %s!", masters[p->level - 1]->name, p->name); | |
2968 | ||
2969 | return; | |
2970 | } | |
2971 | else | |
2972 | { | |
2973 | notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}"); | |
ab4f4ec0 | 2974 | } |
2975 | } | |
2976 | ||
2977 | void see_master(char *u) | |
2978 | { | |
2979 | aClient *user; | |
1af35752 | 2980 | |
ab4f4ec0 | 2981 | if (!(user = find(u))) |
2982 | { | |
2983 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); | |
2984 | return; | |
2985 | } | |
2986 | ||
1af35752 | 2987 | if (!is_fighting(user) && is_playing(user)) |
ab4f4ec0 | 2988 | { |
2989 | Player *p = user->stats; | |
2990 | p->master = new Monster(masters[p->level - 1]); | |
2991 | p->fight = p->master; | |
2992 | display_monster(u); // Since master is the same structure, use this function | |
2993 | } | |
2994 | } | |
e282e9d2 | 2995 | |
2996 | void showBankBalance(const char *u) | |
2997 | { | |
2998 | aClient *user; | |
2999 | Player *p; | |
1af35752 | 3000 | |
e282e9d2 | 3001 | if (!(user = find(u))) |
3002 | return; | |
3003 | ||
3004 | p = user->stats; | |
3005 | ||
3006 | if (!p) | |
3007 | return; | |
3008 | ||
3009 | notice(s_GameServ, u, "Account Balance: %ld Gold On hand: %ld", p->bank, p->gold); | |
3010 | ||
3011 | } | |
44ea29f7 | 3012 | |
3013 | void refreshall() | |
3014 | { | |
3015 | ListNode <aClient> *it; | |
3016 | Player *p; | |
7996e5fd | 3017 | for (unsigned long x = 0; x < U_TABLE_SIZE; x++) |
3018 | { | |
3019 | it = players[x].First(); | |
44ea29f7 | 3020 | |
3021 | while (it) | |
3022 | { | |
3023 | p = it->getData()->stats; | |
3024 | refresh(p); | |
3025 | it = it->Next(); | |
3026 | } | |
7996e5fd | 3027 | } |
44ea29f7 | 3028 | } |
3029 | ||
3030 | void refresh(Player *p) | |
3031 | { | |
3032 | if (!p) | |
3033 | return; | |
3034 | ||
ee38284f | 3035 | if (p->hp < p->maxhp) |
3036 | p->hp = p->maxhp; | |
20d5d721 | 3037 | p->forest_fights = forestfights; |
44ea29f7 | 3038 | p->player_fights = 3; |
ee38284f | 3039 | setAlive(p); |
1af35752 | 3040 | clearMaster(p); |
44ea29f7 | 3041 | } |
c7340cbd | 3042 | |
3043 | void do_refresh(char *u) | |
3044 | { | |
3045 | char *nick = strtok(NULL, " "); | |
3046 | aClient *user; | |
3047 | ||
96f71fee | 3048 | if (!(user = find(u))) |
3049 | { | |
3050 | notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin"); | |
5d04eb42 | 3051 | log("Error: aClient not found: %s", u); |
96f71fee | 3052 | return; |
3053 | } | |
448a1531 | 3054 | else if (isIgnore(user)) |
3055 | { | |
3056 | #ifdef DEBUGMODE | |
3057 | log("Ignoring %s.", user->getNick()); | |
3058 | #endif | |
3059 | return; | |
3060 | } | |
96f71fee | 3061 | else if (!isAdmin(user)) |
3062 | { | |
3063 | notice(s_GameServ, u, "You must be a %S admin to use this command!"); | |
3064 | return; | |
3065 | } | |
c7340cbd | 3066 | if (!nick) |
3067 | { | |
96f71fee | 3068 | notice(s_GameServ, u, "SYNTAX: REFRESH {ALL | NICK}"); |
c7340cbd | 3069 | return; |
3070 | } | |
3071 | else if (stricmp(nick, "ALL") == 0) | |
3072 | { | |
3073 | notice(s_GameServ, u, "Refreshing everyone's stats!"); | |
3074 | refreshall(); | |
3075 | } | |
ae2685f6 | 3076 | else if ((user = findplayer(nick))) |
c7340cbd | 3077 | { |
1af35752 | 3078 | if (is_playing(user)) |
c7340cbd | 3079 | { |
ce61cdfa | 3080 | #ifdef P10 |
3081 | notice(s_GameServ, u, "Refreshing %s.", user->getRealNick()); | |
3082 | #else | |
c7340cbd | 3083 | notice(s_GameServ, u, "Refreshing %s.", user->getNick()); |
ce61cdfa | 3084 | #endif |
c7340cbd | 3085 | refresh(user->stats); |
3086 | } | |
3087 | else | |
3088 | { | |
ce61cdfa | 3089 | #ifdef P10 |
3090 | notice(s_GameServ, u, "%s is not playing.", user->getRealNick()); | |
3091 | #else | |
c7340cbd | 3092 | notice(s_GameServ, u, "%s is not playing.", user->getNick()); |
ce61cdfa | 3093 | #endif |
c7340cbd | 3094 | } |
3095 | } | |
3096 | else | |
3097 | { | |
3098 | notice(s_GameServ, u, "Nick %s not found.", nick); | |
3099 | return; | |
3100 | } | |
3101 | } | |
3102 | ||
ee38284f | 3103 | |
3104 | void resetall() | |
3105 | { | |
3106 | ListNode <aClient> *it; | |
3107 | Player *p; | |
3108 | ||
7996e5fd | 3109 | for (unsigned long x = 0; x < U_TABLE_SIZE; x++) |
3110 | { | |
3111 | it = players[x].First(); | |
ee38284f | 3112 | |
3113 | while (it) | |
3114 | { | |
3115 | p = it->getData()->stats; | |
3116 | reset(p); | |
3117 | it = it->Next(); | |
3118 | } | |
7996e5fd | 3119 | } |
ee38284f | 3120 | } |
3121 | ||
3122 | void reset(Player *p) | |
3123 | { | |
082f064d | 3124 | char *myname; |
3125 | myname = new char[strlen(p->name)]; | |
3126 | strcpy(myname, p->name); | |
ee38284f | 3127 | if (!p) |
3128 | return; | |
3129 | ||
3130 | p->reset(); | |
082f064d | 3131 | strcpy(p->name, myname); |
3132 | delete [] myname; | |
ee38284f | 3133 | } |
3134 | ||
40251952 | 3135 | void updateTS(Player *p) |
3136 | { | |
3137 | if (!p) | |
3138 | return; | |
0b6098d5 | 3139 | |
3140 | #ifdef DEBUGMODE | |
3141 | log("Old timestamp for %s: %ld", p->name, p->lastcommand); | |
3142 | #endif | |
40251952 | 3143 | p->lastcommand = time(NULL); |
0b6098d5 | 3144 | #ifdef DEBUGMODE |
3145 | log("New timestamp for %s: %ld", p->name, p->lastcommand); | |
3146 | #endif | |
3147 | ||
40251952 | 3148 | } |
3149 | ||
3150 | bool timedOut(Player *p) | |
3151 | { | |
3152 | if (!p) | |
3153 | return false; | |
0b6098d5 | 3154 | else if (p->lastcommand == 0) |
3155 | return false; | |
40251952 | 3156 | else |
0b6098d5 | 3157 | { |
3158 | if ((time(NULL) - p->lastcommand) >= maxidletime) | |
3159 | return true; | |
3160 | ||
3161 | return false; | |
3162 | } | |
40251952 | 3163 | } |
3164 | ||
3165 | void timeOutEvent(Player *p) | |
3166 | { | |
0b6098d5 | 3167 | aClient *user = findplayer(p->name); |
40251952 | 3168 | |
ae2685f6 | 3169 | if (!user || !p->client) // then they're not playing |
40251952 | 3170 | return; |
3171 | ||
3172 | char *nick = user->getNick(); | |
3173 | ||
0b6098d5 | 3174 | if (player_fight(user) && isYourTurn(p)) |
3175 | { | |
3176 | // Check to see if they were the idler or if it was the other | |
3177 | // person | |
3178 | if (p->lastcommand != p->battle->stats->lastcommand) | |
3179 | { | |
3180 | // This person's last command was given earlier, | |
3181 | // so this person is the idler | |
3182 | notice(s_GameServ, nick, "You timed out "\ | |
3183 | "during a fight. You lose your turn!"); | |
3184 | notice(s_GameServ, p->battle->getNick(), | |
3185 | "%s hesitated for too long. Your move.", p->name); | |
3186 | clearYourTurn(p); | |
3187 | setYourTurn(p->battle->stats); | |
3188 | ||
3189 | // Update the TS for both players to give them another | |
3190 | // Chance to wake up, but if the other player doesn't | |
3191 | // Attack now, they both get logged out. | |
3192 | updateTS(p); | |
3193 | p->battle->stats->lastcommand = p->lastcommand; | |
3194 | display_players(p->battle); | |
3195 | return; | |
3196 | } | |
3197 | else | |
3198 | { | |
3199 | notice(s_GameServ, p->battle->getNick(), | |
3200 | "You and %s timed out at the same time."\ | |
3201 | " Don't fight if you're just going to "\ | |
3202 | "sit there!", p->name); | |
3203 | notice(s_GameServ, user->getNick(), | |
3204 | "You and %s timed out at the same time."\ | |
3205 | " Don't fight if you're just going to "\ | |
3206 | "sit there!", p->battle->stats->name); | |
3207 | logout(p->battle); | |
3208 | logout(user); | |
3209 | return; | |
3210 | } | |
3211 | } | |
3212 | else if (!player_fight(user)) | |
eb7608de | 3213 | { |
c047f947 | 3214 | if (isAlive(user->stats) && user->stats->gold > 0) |
903cd861 | 3215 | { |
eb7608de | 3216 | // Place fun stuff here :) |
3217 | int randnum = 1 + rand() % 100; // 1-100 | |
0b259dff | 3218 | #define GSN(s) notice(s_GameServ, nick, s) |
3219 | #define GSN2(s, f) notice(s_GameServ, nick, s, f) | |
eb7608de | 3220 | |
3221 | if (randnum < 50) | |
3222 | { | |
0b259dff | 3223 | // 35-100% of your gold goes pffft - kain |
3224 | int stolen = (35 + (rand() % 66)) * user->stats->gold / 100; | |
3225 | ||
eb7608de | 3226 | GSN("You stop for a moment to rest on the "\ |
3227 | "street corner. All of a sudden, you "\ | |
3228 | "are ambushed from all sides by a hoarde "\ | |
3229 | "of knife wielding thugs."); | |
3230 | GSN2("The thugs beat you into utter submission "\ | |
3231 | "and steal %d gold from you!", stolen); | |
3232 | user->stats->gold -= stolen; | |
3233 | } | |
0b259dff | 3234 | else if (randnum >= 50 && randnum < 75) |
3235 | { | |
3236 | // 25-65% of your gold goes pffft - kain | |
3237 | int stolen = (25 + (rand() % 41)) * user->stats->gold / 100; | |
3238 | GSN("While dilly dallying around, you lose "\ | |
3239 | "your sense of time. Little did you know, "\ | |
3240 | "but thieves lifted your gold while you "\ | |
3241 | "weren't watching."); | |
3242 | GSN2("Better luck next time... you lose %d gold", stolen); | |
3243 | user->stats->gold -= stolen; | |
3244 | } | |
3245 | else if (randnum >= 75) | |
3246 | { | |
3247 | // 25-75% of your gold goes pffft - kain | |
3248 | int stolen = (25 + (rand() % 51)) * user->stats->gold / 100; | |
3249 | GSN("Good grief! A gaggle of gooey green ghostlike "\ | |
3250 | "goblins grabbed your gold!"); | |
3251 | GSN2("They stole %d gold from you!", stolen); | |
3252 | user->stats->gold -= stolen; | |
3253 | } | |
903cd861 | 3254 | } |
eb7608de | 3255 | |
3256 | // Always log out the user | |
0b6098d5 | 3257 | logout(user); |
eb7608de | 3258 | } |
40251952 | 3259 | } |
3260 | ||
ee38284f | 3261 | void do_reset(char *u) |
3262 | { | |
3263 | char *nick = strtok(NULL, " "); | |
3264 | aClient *user; | |
3265 | ||
3266 | if (!(user = find(u))) | |
3267 | { | |
3268 | notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin"); | |
5d04eb42 | 3269 | log("Error: aClient not found: %s", u); |
ee38284f | 3270 | return; |
3271 | } | |
3272 | else if (!isAdmin(user)) | |
3273 | { | |
3274 | notice(s_GameServ, u, "You must be a %S admin to use this command!"); | |
3275 | return; | |
3276 | } | |
448a1531 | 3277 | |
ee38284f | 3278 | if (!nick) |
3279 | { | |
3280 | notice(s_GameServ, u, "SYNTAX: RESET {ALL | NICK}"); | |
3281 | return; | |
3282 | } | |
3283 | else if (stricmp(nick, "ALL") == 0) | |
3284 | { | |
3285 | notice(s_GameServ, u, "Resetting everyone's stats!"); | |
3286 | resetall(); | |
3287 | } | |
082f064d | 3288 | else if ((user = findplayer(nick))) |
ee38284f | 3289 | { |
3290 | if (is_playing(user)) | |
3291 | { | |
ce61cdfa | 3292 | #ifdef P10 |
3293 | notice(s_GameServ, u, "Resetting %s.", user->getRealNick()); | |
3294 | #else | |
ee38284f | 3295 | notice(s_GameServ, u, "Resetting %s.", user->getNick()); |
ce61cdfa | 3296 | #endif |
ee38284f | 3297 | reset(user->stats); |
3298 | } | |
3299 | else | |
3300 | { | |
082f064d | 3301 | notice(s_GameServ, u, "Resetting %s", user->stats->name); |
3302 | reset(user->stats); | |
ee38284f | 3303 | } |
3304 | } | |
3305 | else | |
3306 | { | |
3307 | notice(s_GameServ, u, "Nick %s not found.", nick); | |
3308 | return; | |
3309 | } | |
3310 | } | |
3311 | ||
c7340cbd | 3312 | void do_help(char *u) |
3313 | { | |
3314 | char *cmd = strtok(NULL, " "); | |
3315 | ||
c7340cbd | 3316 | display_help(u, cmd); |
3317 | } | |
3318 | ||
3319 | void display_help(char *u, char *file) | |
3320 | { | |
3321 | ifstream infile; | |
3322 | char *buf; | |
3323 | ||
3324 | if (!file) | |
3325 | { | |
3326 | infile.open("helpfiles/help"); | |
3327 | if (infile.fail()) | |
3328 | { | |
fb37ecc7 | 3329 | log("Error opening helpfiles/help"); |
c7340cbd | 3330 | notice(s_GameServ, u, "Error opening helpfiles/help"); |
3331 | return; | |
3332 | } | |
3333 | buf = new char[1024]; | |
3334 | while(infile.getline(buf, 1024)) | |
3335 | { | |
3336 | // Written this way, it will process %S in the helpfiles | |
3337 | // Instead of notice(s_GameServ, u, "%s", buf); | |
3338 | notice(s_GameServ, u, buf); | |
3339 | } | |
3340 | ||
3341 | // Minor recursion | |
96f71fee | 3342 | aClient *user = find(u); |
3343 | if (user && isAdmin(user)) | |
3344 | display_help(u, "admin_commands"); | |
c7340cbd | 3345 | } |
3346 | else | |
3347 | { | |
3348 | char *filename; | |
f27a378f | 3349 | filename = new char[strlen(file) + 11]; |
3350 | strcpy(filename, "helpfiles/"); | |
3351 | strcat(filename, file); | |
4dde2ed9 | 3352 | |
f27a378f | 3353 | for (unsigned int x = 10; x < strlen(filename); x++) |
3354 | filename[x] = tolower(filename[x]); | |
4dde2ed9 | 3355 | |
c7340cbd | 3356 | infile.open(filename); |
3357 | delete [] filename; | |
3358 | if (infile.fail()) | |
3359 | { | |
3360 | notice(s_GameServ, u, "No help for \ 2%s\ 2", file); | |
3361 | return; | |
3362 | } | |
3363 | buf = new char[1024]; | |
3364 | while(infile.getline(buf, 1024)) | |
3365 | { | |
3366 | // Written this way, it will process %S in the helpfiles | |
3367 | // Instead of notice(s_GameServ, u, "%s", buf); | |
3368 | notice(s_GameServ, u, buf); | |
3369 | } | |
3370 | } | |
3371 | infile.close(); | |
3372 | delete [] buf; | |
3373 | } | |
96f71fee | 3374 | |
3375 | void do_admin(char *u) | |
3376 | { | |
3377 | aClient *user; | |
3378 | char *pass = strtok(NULL, " "); | |
3379 | ||
3380 | if (!(user = find(u))) | |
3381 | { | |
5d04eb42 | 3382 | log("Error: aClient not found: %s", u); |
96f71fee | 3383 | notice(s_GameServ, u, "Error: aClient not found. Contact %S admin."); |
3384 | return; | |
3385 | } | |
448a1531 | 3386 | |
96f71fee | 3387 | if (!pass) |
3388 | { | |
3389 | notice(s_GameServ, u, "SYNTAX: \ 2ADMIN\ 2 \ 2\1fpassword\1f\ 2"); | |
3390 | return; | |
3391 | } | |
3392 | ||
1af35752 | 3393 | if (isAdmin(user)) |
3394 | { | |
3395 | notice(s_GameServ, u, "You already have administrator privledges."); | |
3396 | return; | |
3397 | } | |
3398 | else if (strcmp(pass, adminpass) == 0) | |
96f71fee | 3399 | { |
3400 | notice(s_GameServ, u, "Password accepted. You now have administrator privledges."); | |
3401 | setAdmin(user); | |
ce61cdfa | 3402 | #ifdef P10 |
3403 | log("%s became an administrator.", user->getRealNick()); | |
3404 | #else | |
5d04eb42 | 3405 | log("%s became an administrator.", user->getNick()); |
ce61cdfa | 3406 | #endif |
96f71fee | 3407 | } |
3408 | else | |
3409 | { | |
3410 | notice(s_GameServ, u, "Invalid password. Remember: case sensitive"); | |
3411 | return; | |
3412 | } | |
3413 | } | |
1af35752 | 3414 | |
4dde2ed9 | 3415 | bool load_monsters() |
3416 | { | |
bf3a2ff9 | 3417 | char *filename; |
4dde2ed9 | 3418 | ifstream infile; |
4dde2ed9 | 3419 | char *buf; |
bf3a2ff9 | 3420 | buf = new char[2048]; |
4dde2ed9 | 3421 | |
bf3a2ff9 | 3422 | for (int level = 1; level <= LEVELS; level++) |
3423 | { | |
3424 | filename = new char[256]; | |
b5cea1ad | 3425 | sprintf(filename, "data/monsters/level%d.dat", level); |
bf3a2ff9 | 3426 | infile.open(filename); |
3427 | ||
3428 | if (!infile) | |
4dde2ed9 | 3429 | { |
bf3a2ff9 | 3430 | log("Error opening %s", filename); |
4dde2ed9 | 3431 | return false; |
3432 | } | |
4dde2ed9 | 3433 | |
5d04eb42 | 3434 | #ifdef DEBUGMODE |
bf3a2ff9 | 3435 | log("Loading monsters from %s", filename); |
5d04eb42 | 3436 | #endif |
3437 | ||
bf3a2ff9 | 3438 | while (infile.getline(buf, 2048)) |
4dde2ed9 | 3439 | { |
bf3a2ff9 | 3440 | if (buf[0] == '^') |
3441 | break; | |
4dde2ed9 | 3442 | if (buf[0] == '\n' || buf[0] == '\0' || buf[0] == '#') |
3443 | continue; | |
bf3a2ff9 | 3444 | Monster *temp; |
3445 | temp = new Monster; | |
3446 | ||
3447 | strcpy(temp->name, strtok(buf, "~")); | |
3448 | strcpy(temp->weapon, strtok(NULL, "~")); | |
3449 | temp->strength = stringtoint(strtok(NULL, "~")); | |
3450 | temp->gold = stringtoint(strtok(NULL, "~")); | |
3451 | temp->exp = stringtoint(strtok(NULL, "~")); | |
3452 | temp->maxhp = stringtoint(strtok(NULL, "~")); | |
3453 | temp->hp = temp->maxhp; | |
3454 | strcpy(temp->death, strtok(NULL, "~")); | |
3455 | ||
42106907 | 3456 | levels[level - 1].monsters.insertAtBack_RLN(temp); |
bf3a2ff9 | 3457 | delete temp; |
4dde2ed9 | 3458 | } |
bf3a2ff9 | 3459 | delete [] filename; |
3460 | infile.close(); | |
4dde2ed9 | 3461 | } |
3462 | delete [] buf; | |
3463 | return true; | |
3464 | } |