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