]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
ce27a5014329915685db4f3b3584a2ca8013d340
22 #if defined(HAVE_CRYPT_H)
26 #elif defined(HAVE_UNISTD_H)
32 Monster dragon
; // The current dragon
33 Level levels
[LEVELS
]; // The newest way to store monsters
34 list
<item
*> Items
; // The master list of items
35 list
<tavernItem
> tavern
; // The list of items available at the tavern
36 list
<item
*> store
; // List of items available at the store
38 toplist myToplist
; // List of the top 10 players
45 void do_heal(char *u
);
46 void do_help(char *u
);
47 void do_identify(char *u
);
48 void do_inventory(char *u
);
49 void do_refresh(char *u
);
50 void do_register(char *u
);
51 void do_list(char *u
);
52 void do_logout(char *u
);
53 void do_master(char *u
);
54 void do_dragon(char *u
);
55 void do_play(char *u
);
56 void do_quitg(char *u
);
57 void do_reset(char *u
);
60 void do_stats(char *u
);
61 void do_store(char *u
);
62 void do_tavern(char *u
);
67 int hpbonus
[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550};
68 int strbonus
[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200};
69 int defbonus
[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150};
71 void gameserv(char *source
, char *buf
)
74 cmd
= strtok(buf
, " ");
77 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
82 cmd
++; // Get rid of that : at the beginning of the :text (command)
85 log("Source: %s Command: %s", source
, cmd
);
88 if (strnicmp(cmd
, "\1PING", 6) == 0)
91 ts
= strtok(NULL
, "\1");
92 notice(s_GameServ
, source
, "\1PING %s\1", ts
);
94 else if (stricmp(cmd
, "\1VERSION\1") == 0)
96 notice(s_GameServ
, source
, "\1VERSION %s %s\1", PACKAGE
, VERSION
);
98 else if (stricmp(cmd
, "SEARCH") == 0)
100 cmd
= strtok(NULL
, " ");
103 notice(s_GameServ
, source
, "SYNTAX: /msg <S SEARCH FOREST");
108 else if (stricmp(cmd
, "ADMIN") == 0)
112 else if (stricmp(cmd
, "ATTACK") == 0)
116 else if (stricmp(cmd
, "BANK") == 0)
120 else if (stricmp(cmd
, "CHECK") == 0)
124 else if (stricmp(cmd
, "DRAGON") == 0)
128 else if (stricmp(cmd
, "EQUIP") == 0)
132 else if (stricmp(cmd
, "FIGHT") == 0)
136 else if (stricmp(cmd
, "HEAL") == 0)
140 else if (stricmp(cmd
, "HELP") == 0)
144 else if (stricmp(cmd
, "IDENTIFY") == 0)
148 else if (stricmp(cmd
, "INVENTORY") == 0)
150 do_inventory(source
);
152 else if (stricmp(cmd
, "LIST") == 0)
156 else if (stricmp(cmd
, "LOGOUT") == 0)
160 else if (stricmp(cmd
, "MASTER") == 0)
164 else if (stricmp(cmd
, "NEWS") == 0)
168 else if (stricmp(cmd
, "REGISTER") == 0)
172 else if (stricmp(cmd
, "REFRESH") == 0)
176 else if (stricmp(cmd
, "RESET") == 0)
180 else if (stricmp(cmd
, "RUN") == 0)
184 else if (stricmp(cmd
, "SET") == 0)
188 else if (stricmp(cmd
, "STATS") == 0)
192 else if (stricmp(cmd
, "STORE") == 0)
196 else if (stricmp(cmd
, "TAVERN") == 0)
200 else if (stricmp(cmd
, "USE") == 0)
204 else if (stricmp(cmd
, "SHUTDOWN") == 0)
208 if (!(user
= find(source
)))
210 notice(s_GameServ
, source
, "Error: aClient not found. Contact a <S admin");
211 log("Error: aClient not found: %s", source
);
213 else if (!isAdmin(user
))
215 notice(s_GameServ
, source
, "You must be a <S admin to use this command!");
221 raw("[] SQ %s 0 :leaving: %s used the Shutdown command.", servername
, user
->getRealNick());
223 raw("SQUIT %s :leaving: %s used the Shutdown command.", servername
, source
);
228 else if (stricmp(cmd
, "SAVE") == 0)
232 if (!(user
= find(source
)))
234 notice(s_GameServ
, source
, "Error: aClient not found. Contact a <S admin");
235 log("Error: aClient not found: %s", source
);
237 else if (!isAdmin(user
))
239 notice(s_GameServ
, source
, "You must be a <S admin to use this command!");
246 else if (stricmp(cmd
, "LOAD") == 0)
250 if (!(user
= find(source
)))
252 notice(s_GameServ
, source
, "Error: aClient not found. Contact a <S admin");
253 log("Error: aClient not found: %s", source
);
255 else if (!isAdmin(user
))
257 notice(s_GameServ
, source
, "You must be a <S admin to use this command!");
261 char *cmd2
= strtok(NULL
, " ");
264 notice(s_GameServ
, source
, "Loading player data from %s", playerdata
);
267 else if (stricmp(cmd2
, "MONSTERS") == 0)
269 notice(s_GameServ
, source
, "Loading monster data");
272 else if (stricmp(cmd2
, "SCRIPTS") == 0)
274 // Testing scripts for now
276 notice(s_GameServ
, source
, "Loading scripts");
278 if (scr
.loadScript("test.txt"))
279 scr
.executeScript(user
->stats
);
283 display_help(source
, cmd
);
288 else if (stricmp(cmd
, "RAW") == 0)
292 if (!(user
= find(source
)))
294 notice(s_GameServ
, source
, "Error: aClient not found. Contact a <S admin");
295 log("Error: aClient not found: %s", source
);
297 else if (!isAdmin(user
))
299 notice(s_GameServ
, source
, "You must be a <S admin to use this command!");
303 char *rest
= strtok(NULL
, "");
307 else if (stricmp(cmd
, "RANDOM") == 0)
309 char *rstr
= strtok(NULL
, "");
311 trange
.setRange(rstr
);
312 notice(s_GameServ
, source
, "Random number in that range: %d", trange
.random());
318 if ((user
= find(source
)))
323 log("Ignoring %s.", user
->getNick());
328 notice(s_GameServ
, source
, "Unknown command \002%s\002. Type /msg <S \002HELP\002 to get a list of commands.", cmd
);
334 source
--; // Bring the ':' back so we don't leak memory
337 cmd
--; // Same thing :)
342 void do_list(char *u
)
346 char *cmd
= strtok(NULL
, " ");
348 if (!(user
= find(u
)))
350 log("Fatal Error: Couldn't find %s in the client list", u
);
353 else if (isIgnore(user
))
356 log("Ignoring %s. Command LIST", user
->getNick());
361 if (cmd
== NULL
|| stricmp(cmd
, "TOP") == 0)
363 list
<PlayerWrapper
>::iterator iter
;
366 if (myToplist
.empty())
368 notice(s_GameServ
, u
, "There are no players");
374 iter
= myToplist
.begin();
376 while (iter
!= myToplist
.end())
380 notice(s_GameServ
, u
, "Top Players");
384 notice(s_GameServ
, u
, "Level: %2d Exp: %10d Name: %s",
385 (*iter
).getLevel(), (*iter
).getExp(), (*iter
).getName().c_str());
392 list
<Player
*>::iterator iter
;
395 for (unsigned long x
= 0; x
< U_TABLE_SIZE
; x
++)
397 iter
= players
[x
].begin();
398 if (!players
[x
].empty())
400 while(iter
!= players
[x
].end())
403 if (cmd
|| is_playing(p
->getClient()))
407 notice(s_GameServ
, u
, "Players:");
411 notice(s_GameServ
, u
, "IRC: %s Game: %s", (p
->getClient() ? p
->getClient()->getRealNick() : "Not Playing"),
412 p
->getName().c_str());
414 notice(s_GameServ
, u
, "IRC: %s Game: %s", (p
->getClient() ? p
->getClient()->getNick() : "Not Playing"),
415 p
->getName().c_str());
423 notice(s_GameServ
, u
, "No one is playing");
425 notice(s_GameServ
, u
, "End of List");
433 char *name
= strtok(NULL
, " ");
434 char *cmd
= strtok(NULL
, " ");
437 if (!(user
= find(u
)))
439 notice(s_GameServ
, u
, "Fatal error. Cannot find aClient. "\
440 "Buf: %s LOGOUT", u
);
443 else if (isIgnore(user
))
446 log("Ignoring %s.", user
->getNick());
450 else if (!name
|| !cmd
)
452 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
455 else if (!(p
= findplayer(name
)))
457 // Back the pointers up... they didn't send a name probably
462 if (!is_playing(user
))
464 notice(s_GameServ
, u
, "You must be playing to set things for yourself!");
470 cmd2
= strtok(NULL
, " ");
474 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
478 // Regardless of the previous if/else, if it got here, we know we have the cmd pointer at the right spot.
479 if (stricmp(cmd
, "PASSWORD") == 0)
481 // Person is looking to change their password
482 // If they're an admin, or it's theirself, allow it
483 // cmd2 is pointing to the password now
484 if (isAdmin(user
) || user
== p
->getClient())
486 p
->setPassword(cmd2
);
487 notice(s_GameServ
, u
, "Password successfully changed");
489 else if (user
!= p
->getClient() && !isAdmin(user
))
491 notice(s_GameServ
, u
, "You must be a <S admin to set other peoples' passwords.");
495 else if (stricmp(cmd
, "BANK") == 0 || stricmp(cmd
, "BALANCE") == 0)
499 notice(s_GameServ
, u
, "Admins Only!");
502 else if (stricmp(cmd
, "BANK") == 0)
504 cmd2
= strtok(NULL
, " "); // Need an extra parameter for set bank balance
508 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] [BANK] BALANCE <NUMBER>");
512 p
->setBank(stringtoint(cmd2
));
514 notice(s_GameServ
, u
, "Bank balance changed to %ld!", p
->getBank());
516 else if (stricmp(cmd
, "PLAYER") == 0)
520 notice(s_GameServ
, u
, "Admins Only!");
523 else if (stricmp(cmd2
, "FIGHTS") != 0)
525 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] PLAYER FIGHTS <NUMBER>");
530 cmd2
= strtok(NULL
, " ");
533 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] PLAYER FIGHTS <NUMBER>");
536 p
->setPlayerFights(stringtoint(cmd2
));
538 notice(s_GameServ
, u
, "Player fights changed to %d!", p
->getPlayerFights());
541 else if (stricmp(cmd
, "FOREST") == 0)
545 notice(s_GameServ
, u
, "Admins Only!");
548 else if (stricmp(cmd2
, "FIGHTS") != 0)
550 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] FOREST FIGHTS <number>");
555 cmd2
= strtok(NULL
, " ");
558 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] FOREST FIGHTS <NUMBER>");
562 p
->setForestFights(stringtoint(cmd2
));
564 notice(s_GameServ
, u
, "Forest fights changed to %d!", p
->getForestFights());
567 else if (stricmp(cmd
, "GOLD") == 0)
571 notice(s_GameServ
, u
, "Admins Only!");
578 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] GOLD <NUMBER>");
581 p
->setGold(stringtoint(cmd2
));
583 notice(s_GameServ
, u
, "Gold set to %ld", p
->getGold());
587 else if (stricmp(cmd
, "STRENGTH") == 0 && stricmp(cmd2
, "POTIONS") != 0)
591 notice(s_GameServ
, u
, "Admins Only!");
598 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] STRENGTH <NUMBER>");
602 p
->setStrength(stringtoint(cmd2
));
604 notice(s_GameServ
, u
, "Strength set to %d", p
->getStrength());
608 else if (stricmp(cmd
, "DEFENSE") == 0 && stricmp(cmd2
, "POTIONS") != 0)
612 notice(s_GameServ
, u
, "Admins Only!");
619 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] DEFENSE <NUMBER>");
623 p
->setDefense(stringtoint(cmd2
));
625 notice(s_GameServ
, u
, "Defense set to %d", p
->getDefense());
629 else if (stricmp(cmd
, "HP") == 0 && stricmp(cmd2
, "POTIONS") != 0)
633 notice(s_GameServ
, u
, "Admins Only!");
640 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] HP <NUMBER>");
644 // Make sure it's easy for an admin to set the hp
645 if (p
->getMaxHP() < stringtoint(cmd2
))
646 p
->setMaxHP(stringtoint(cmd2
));
648 p
->setHP(stringtoint(cmd2
));
650 notice(s_GameServ
, u
, "HP set to %d", p
->getHP());
654 else if (stricmp(cmd
, "MAXHP") == 0)
658 notice(s_GameServ
, u
, "Admins Only!");
665 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] MAXHP <NUMBER>");
668 p
->setMaxHP(stringtoint(cmd2
));
670 notice(s_GameServ
, u
, "MaxHP set to %d", p
->getMaxHP());
674 else if (stricmp(cmd
, "EXPERIENCE") == 0 || stricmp(cmd
, "EXP") == 0)
678 notice(s_GameServ
, u
, "Admins Only!");
685 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] {EXPERIENCE|EXP} <NUMBER>");
689 p
->setExp(stringtoint(cmd2
));
691 notice(s_GameServ
, u
, "Exp set to %ld", p
->getExp());
695 else if (stricmp(cmd
, "LEVEL") == 0)
699 notice(s_GameServ
, u
, "Admins Only!");
706 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] LEVEL <NUMBER>");
709 p
->setLevel(stringtoint(cmd2
));
711 notice(s_GameServ
, u
, "Level set to %d", p
->getLevel());
715 else if (stricmp(cmd
, "ALIVE") == 0)
719 notice(s_GameServ
, u
, "Admins Only!");
726 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] ALIVE TRUE|FALSE");
729 else if (stricmp(cmd2
, "TRUE") == 0)
731 notice(s_GameServ
, u
, "%s has been Resurrected!", p
->getName().c_str());
736 notice(s_GameServ
, u
, "%s is now dead!", p
->getName().c_str());
741 else if (stricmp(cmd
, "SEEN") == 0)
745 notice(s_GameServ
, u
, "Admins Only!");
748 else if (stricmp(cmd2
, "MASTER") != 0)
750 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] SEEN MASTER {TRUE|FALSE}");
755 cmd2
= strtok(NULL
, " ");
758 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NICK] SEEN MASTER {TRUE|FALSE}");
761 else if (stricmp(cmd2
, "TRUE") == 0)
763 notice(s_GameServ
, u
, "%s has seen their master now.", p
->getName().c_str());
764 p
->addFlag(FLAG_MASTER
);
768 notice(s_GameServ
, u
, "%s has not seen their master now.", p
->getName().c_str());
769 p
->remFlag(FLAG_MASTER
);
775 notice(s_GameServ
, u
, "Unknown command: SET %s", cmd
);
776 notice(s_GameServ
, u
, "SYNTAX: /msg <S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
781 void do_logout(char *u
)
785 char *name
= strtok(NULL
, " ");
787 if (!(user
= find(u
)))
789 notice(s_GameServ
, u
, "Fatal error. Cannot find aClient. "\
790 "Buf: %s LOGOUT", u
);
791 log("Could not find aClient Buf: %s LOGOUT",
795 else if (isIgnore(user
))
798 log("Ignoring %s.", user
->getNick());
807 notice(s_GameServ
, u
, "You must be a <S admin to use this command!");
809 else if (!(p
= findplayer(name
)))
811 notice(s_GameServ
, u
, "Couldn't find a player named %s", name
);
815 notice(s_GameServ
, u
, "Logging out %s", p
->getName().c_str());
816 logout(p
->getClient());
821 if (!is_playing(user
))
823 notice(s_GameServ
, u
, "You're not logged in!");
825 else if (is_fighting(user
))
827 notice(s_GameServ
, u
, "You can't logout while fighting!");
831 notice(s_GameServ
, u
, "You have left the fields. You have lived to kill another day!");
837 void do_register(char *u
)
839 char *password
, *name
;
842 name
= strtok(NULL
, " ");
843 password
= strtok(NULL
, " ");
847 notice(s_GameServ
, u
, "SYNTAX: /msg <S REGISTER NAME PASSWORD");
849 else if (stricmp(name
, s_GameServ
) == 0)
851 notice(s_GameServ
, u
, "You can't use <S as a name!");
855 notice(s_GameServ
, u
, "SYNTAX: /msg <S REGISTER NAME PASSWORD");
857 else if (strlen(name
) > maxnicklen
)
859 notice(s_GameServ
, u
, "Name too long. Maximum length: %d", maxnicklen
);
861 else if (!alphaNumeric(name
))
863 notice(s_GameServ
, u
, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!");
865 else if ((p
= findplayer(name
)))
867 notice(s_GameServ
, u
, "%s is already registered!", name
);
868 notice(s_GameServ
, u
, "Choose another name!");
870 else if (!(user
= find(u
)))
872 log("Fatal Error: Couldn't find %s in the clients list", u
);
874 else if (isIgnore(user
))
877 log("Ignoring %s.", user
->getNick());
882 if (!is_playing(user
))
885 unsigned long hv
= iHASH((unsigned char *) name
);
887 // First create the Player
888 user
->stats
= new Player();
890 // Set the backwards pointer
891 user
->stats
->setClient(user
);
893 // Set the player's password
894 user
->stats
->setPassword(password
);
896 // Set the player's name
897 user
->stats
->setName(name
);
899 // Make sure they have a proper time stamp
900 updateTS(user
->stats
);
902 // Update the last login time
903 user
->stats
->lastlogin
= time(NULL
);
905 // Send notification of success
906 notice(s_GameServ
, u
, "Player %s registered with password %s.", user
->stats
->getName().c_str(), password
);
907 notice(s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!");
909 // Log the new player
910 log("Nickname %s registered player %s.", u
, user
->stats
->getName().c_str());
915 // Start the player at the beginning
918 // Add the stick and clothes
919 tempItem
= findItemByID(3001);
920 user
->stats
->inventory
->addItem((*Items
.begin()))->use(user
->stats
); // Add the stick
921 user
->stats
->inventory
->addItem(tempItem
)->use(user
->stats
); // Add Clothes
923 // Add the player to the list
924 players
[hv
].push_back(user
->stats
);
926 // Attempt to add the player to the top list
927 // The class takes care of pruning the user out if they don't deserve to be in the list
928 myToplist
.insertPlayer(user
->stats
);
932 notice(s_GameServ
, u
, "Already registered. Contact a <S admin for help.");
937 void do_identify(char *u
)
939 char *password
, *name
;
942 name
= strtok(NULL
, " ");
943 password
= strtok(NULL
, " ");
944 if (!password
|| !name
)
946 notice(s_GameServ
, u
, "SYNTAX: /msg <S IDENTIFY NAME PASSWORD");
948 else if (!(user
= find(u
)))
950 notice(s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL
, ""));
951 log("Error: aClient not found: %s", u
);
953 else if (isIgnore(user
))
956 log("Ignoring %s.", user
->getNick());
960 else if (!(p
= findplayer(name
)))
962 notice(s_GameServ
, u
, "Player %s not found", name
);
964 else if (is_playing(user
))
966 notice(s_GameServ
, u
, "You are already playing!");
968 else if (is_playing(p
->getClient()) && !isAdmin(user
))
970 notice(s_GameServ
, u
, "That player has already identified.");
972 else if (!check_password(name
, password
) && !isAdmin(user
))
974 notice(s_GameServ
, u
, "Password incorrect");
978 list
<Player
*>::iterator iter
;
979 unsigned long hv
= iHASH((unsigned char *) p
->getName().c_str());
981 iter
= find(players
[hv
].begin(), players
[hv
].end(), p
);
983 if (iter
== players
[hv
].end())
985 notice(s_GameServ
, u
, "Fatal error. Contact <S Admin. Buf: %s",
989 // Make sure the other user is logged out
990 logout(p
->getClient());
998 log("Player %s IRC: %s Identified", user
->stats
->getName().c_str(),
1001 //Set the playing flag
1004 // Update the last login time
1005 user
->stats
->lastlogin
= time(NULL
);
1007 notice(s_GameServ
, u
, "Password Accepted. Identified.");
1008 showNews(u
, todaysnews
);
1012 void do_stats(char *u
)
1017 nick
= strtok(NULL
, " ");
1019 if (!(user
= find(u
)))
1021 log("Fatal Error: %s not found in client list", u
);
1024 else if (isIgnore(user
))
1027 log("Ignoring %s.", user
->getNick());
1033 if (!is_playing(user
))
1035 notice(s_GameServ
, u
, "You're not playing, so you have no stats!");
1040 if (!is_fighting(user
))
1041 updateTS(user
->stats
);
1042 showstats(u
, user
->stats
->getName().c_str());
1049 void do_use(char *u
)
1054 char *item
= strtok(NULL
, " ");
1055 char *numuse
= strtok(NULL
, " ");
1057 itemContainer
*used
;
1059 if (!item
|| int(item
[0]) < 48 || int(item
[0]) > 57 || (numuse
&& (int(numuse
[0]) < 48 || int(numuse
[0]) > 57)))
1061 notice(s_GameServ
, u
, "SYNTAX: USE ####");
1062 notice(s_GameServ
, u
, "Type /msg <S HELP USE for more information.");
1065 else if (!(user
= find(u
)))
1067 notice(s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) <S Admin");
1070 else if (isIgnore(user
))
1073 log("Ignoring %s.", user
->getNick());
1077 else if (!is_playing(user
))
1079 notice(s_GameServ
, u
, "You must be playing to use items!");
1082 id
= stringtoint(item
);
1090 num
= stringtoint(numuse
);
1093 updateTS(user
->stats
);
1094 p
= user
->stats
->inventory
;
1097 if (!(used
= p
->Find(id
)))
1101 notice(s_GameServ
, u
, "You aren't carrying that item!");
1103 showinventory(user
->stats
, user
);
1105 else if (used
->getItem()->getType() != POTION
)
1107 notice(s_GameServ
, u
, "You can't use %s like that. Try /msg <S equip", used
->getItem()->getName().c_str());
1112 if (num
<= 1 || is_fighting(user
))
1114 notice(s_GameServ
, u
, "You used %s.", used
->getItem()->getName().c_str());
1115 used
->use(user
->stats
);
1116 if (used
->getUses() <= 0)
1118 p
->deleteItem(used
->getItem());
1125 const char *name
= used
->getItem()->getName().c_str();
1126 for (count
= 0; count
< num
; count
++)
1128 if (!(used
= p
->Find(id
)))
1134 used
->use(user
->stats
);
1135 if (used
->getUses() == 0)
1137 p
->deleteItem(used
->getItem());
1141 notice(s_GameServ
, u
, "You used %d %s's", count
, name
);
1145 void do_run(char *u
)
1148 Player
*p
, *p2
= NULL
;
1150 if (!(user
= find(u
)))
1152 notice(s_GameServ
, u
, "Couldn't find you. Error. Contact a <S admin");
1155 else if (isIgnore(user
))
1158 log("Ignoring %s.", user
->getNick());
1162 else if (!is_playing(user
))
1164 notice(s_GameServ
, u
, "You must be playing to run!");
1168 updateTS(user
->stats
);
1172 p2
= p
->getBattle()->stats
;
1174 if (!is_fighting(user
))
1175 notice(s_GameServ
, u
, "You run in place... try fighting next time.");
1176 else if (!player_fight(user
) && !master_fight(user
) && !dragon_fight(user
))
1178 notice(s_GameServ
, u
, "You run away from \ 2%s\ 2 like a little baby!", p
->getMonster()->name
.c_str());
1181 else if (player_fight(user
) && isYourTurn(p
))
1183 notice(s_GameServ
, u
, "You run away from \ 2%s\ 2 like a little baby!", p2
->getName().c_str());
1184 notice(s_GameServ
, p
->getBattle()->getNick(), "\ 2%s\ 2 ran away from you like a little baby!", p
->getName().c_str());
1185 addNews(todaysnews
, "%s ran away from %s like a little baby!!", p
->getName().c_str(), p2
->getName().c_str()); /* DrLnet - edited by Kain */
1189 else if (player_fight(user
) && !isYourTurn(p
))
1191 notice(s_GameServ
, u
, "It is not your turn. Please wait until \ 2%s\ 2 decides what to do.", p2
->getName().c_str());
1193 else if (master_fight(user
))
1195 notice(s_GameServ
, u
, "You cannot run from \ 2%s\ 2! FIGHT!", p
->getMaster()->name
.c_str());
1197 else if (dragon_fight(user
))
1199 notice(s_GameServ
, u
, "You cannot run from %s! FIGHT!", dragon
.name
.c_str());
1204 void do_heal(char *u
)
1207 char *amount
= strtok(NULL
, " ");
1212 notice(s_GameServ
, u
, "SYNTAX: /msg <S HEAL {ALL | #}");
1215 else if (!(ni
= find(u
)))
1217 notice(s_GameServ
, u
, "Fatal error. Contact a(n) <S admin. buf: %s", strtok(NULL
, ""));
1220 else if (isIgnore(ni
))
1223 log("Ignoring %s.", ni
->getNick());
1227 else if (!is_playing(ni
))
1229 notice(s_GameServ
, u
, "You aren't playing!");
1232 else if (!isAlive(ni
->stats
))
1234 notice(s_GameServ
, u
, "You are dead. Wait until tomorrow for healing.");
1237 else if (is_fighting(ni
))
1239 notice(s_GameServ
, u
, "You can't heal in battle!");
1242 else if (ni
->stats
->getHP() >= ni
->stats
->getMaxHP())
1244 notice(s_GameServ
, u
, "You don't need healing!");
1248 updateTS(ni
->stats
);
1249 if (stricmp(amount
, "ALL") == 0)
1251 price
= ni
->stats
->getLevel() * 3;
1252 if (ni
->stats
->getGold() < (ni
->stats
->getMaxHP() - ni
->stats
->getHP()) * price
)
1254 notice(s_GameServ
, u
, "Healing \ 2%d\ 2 points for \ 2%d\ 2 gold per point.",
1255 (long int)ni
->stats
->getGold()/price
, price
);
1256 ni
->stats
->addHP(ni
->stats
->getGold() / price
);
1257 ni
->stats
->setGold(ni
->stats
->getGold() % price
);
1261 notice(s_GameServ
, u
, "Healing all possible points at \ 2%d\ 2 gold "\
1262 "per point.", price
);
1263 notice(s_GameServ
, u
, "\ 2%d\ 2 points healed for \ 2%ld\ 2 gold. HP at MAX!",
1264 (ni
->stats
->getMaxHP() - ni
->stats
->getHP()),
1265 (price
* (ni
->stats
->getMaxHP() - ni
->stats
->getHP())) );
1266 ni
->stats
->subtractGold(price
* (ni
->stats
->getMaxHP() - ni
->stats
->getHP()));
1267 ni
->stats
->healall();
1270 else if (isstringnum(amount
))
1272 num
= stringtoint(amount
);
1273 price
= ni
->stats
->getLevel() * 3;
1274 if (ni
->stats
->getGold() < price
* num
)
1276 notice(s_GameServ
, u
, "You only have enough gold to heal \ 2%d\ 2 points!",
1277 (long int)ni
->stats
->getGold()/price
);
1279 else if (num
<= ni
->stats
->getMaxHP() - ni
->stats
->getHP())
1281 notice(s_GameServ
, u
, "Healing \ 2%d\ 2 points at \ 2%d\ 2 gold per point.",
1283 ni
->stats
->addHP(num
);
1284 ni
->stats
->subtractGold(num
* price
);
1286 else if (num
> ni
->stats
->getMaxHP() - ni
->stats
->getHP())
1288 notice(s_GameServ
, u
, "Healing all possible points at \ 2%d\ 2 gold "\
1289 "per point.", price
);
1290 notice(s_GameServ
, u
, "\ 2%d\ 2 points healed. HP at MAX!",
1291 (ni
->stats
->getMaxHP() - ni
->stats
->getHP()));
1292 ni
->stats
->subtractGold(price
* (ni
->stats
->getMaxHP() - ni
->stats
->getHP()));
1293 ni
->stats
->healall();
1296 else if (amount
[0] == '-')
1297 notice(s_GameServ
, u
, "You trying to cheat?");
1299 notice(s_GameServ
, u
, "SYNTAX: /msg <S HEAL {ALL | #}");
1305 void do_store(char *u
)
1307 list
<item
*>::iterator item_iterator
;
1309 char *cmd
= strtok(NULL
, " ");
1310 char *num
= strtok(NULL
, " ");
1319 notice(s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
1320 notice(s_GameServ
, u
, " \ 2STORE SELL NUMBER\ 2");
1321 notice(s_GameServ
, u
, " \ 2STORE BUY \1fNUMBER\1f\ 2");
1324 else if (!(user
= find(u
)))
1326 log("Fatal Error: could not find %s in client list", u
);
1329 else if (isIgnore(user
))
1332 log("Ignoring %s.", user
->getNick());
1336 else if (!is_playing(user
))
1338 notice(s_GameServ
, u
, "You must be playing to use the store!");
1341 else if (is_fighting(user
))
1343 notice(s_GameServ
, u
, "You can't go to the store while fighting!");
1346 else if (!isAlive(user
->stats
))
1348 notice(s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!");
1351 updateTS(user
->stats
);
1353 if (stricmp(cmd
, "LIST") == 0)
1355 if (stricmp(num
, "WEAPONS") == 0)
1357 notice(s_GameServ
, u
, "Welcome to Kain's Armory");
1358 notice(s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:");
1359 for (item_iterator
= store
.begin(); item_iterator
!= store
.end(); ++item_iterator
)
1361 if ((*item_iterator
)->getType() == WEAPON
)
1363 space
= spaces(strlen((*item_iterator
)->getName().c_str()), ".");
1364 notice(s_GameServ
, u
, "%s%ld. %20s..........%ld",
1365 ((*item_iterator
)->getID() < 10 ? " " : ""),
1366 (*item_iterator
)->getID(), (*item_iterator
)->getName().c_str(), (*item_iterator
)->price());
1369 notice(s_GameServ
, u
, "To purchase a weapon, type /msg <S STORE BUY \ 2#\ 2.");
1370 notice(s_GameServ
, u
, "Where # is the weapon number from the menu above.");
1373 else if (stricmp(num
, "ARMOR") == 0)
1375 notice(s_GameServ
, u
, "Welcome to Kain's Armory");
1376 notice(s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:");
1377 for (item_iterator
= store
.begin(); item_iterator
!= store
.end(); ++item_iterator
)
1379 if ((*item_iterator
)->getType() == ARMOR
)
1381 notice(s_GameServ
, u
, "%s%ld. %20s..........%d",
1382 ((*item_iterator
)->getID() < 10 ? " " : ""),
1383 (*item_iterator
)->getID(), (*item_iterator
)->getName().c_str(),
1384 (*item_iterator
)->price());
1388 notice(s_GameServ
, u
, "To purchase armor, type /msg <S store buy #");
1389 notice(s_GameServ
, u
, "Where # is the armor number from the menu above.");
1393 else if (stricmp(cmd
, "BUY") == 0)
1398 notice(s_GameServ
, u
, "SYNTAX: \ 2STORE BUY \1f#\1f\ 2");
1403 id
= stringtoint(num
);
1406 if (!isstringnum(num
))
1408 notice(s_GameServ
, u
, "SYNTAX: \ 2STORE BUY \1f#\1f\ 2");
1411 else if (!(tempItem
= findStoreItemByID(id
)))
1413 notice(s_GameServ
, u
, "Sorry, we don't carry that item!");
1416 else if (p
->getGold() < tempItem
->price())
1418 notice(s_GameServ
, u
, "You can't afford to buy %s", tempItem
->getName().c_str());
1421 else if (p
->inventory
->addItem(tempItem
))
1423 notice(s_GameServ
, u
, "You have purchased %s! Thanks for the gold!", tempItem
->getName().c_str());
1424 p
->subtractGold(tempItem
->price());
1425 notice(s_GameServ
, u
, "Don't forget to type /msg <S equip %ld", tempItem
->getID());
1429 notice(s_GameServ
, u
, "You can't carry any more!");
1432 else if (stricmp(cmd
, "SELL" ) == 0)
1434 itemContainer
*tempContainer
;
1436 id
= stringtoint(num
);
1437 if (!isstringnum(num
))
1439 notice(s_GameServ
, u
, "SYNTAX: /msg <S store sell #");
1442 else if (!(tempContainer
= p
->inventory
->Find(id
)))
1444 notice(s_GameServ
, u
, "You're not carrying that!");
1447 else if (p
->getGold() >= 2000000000)
1449 notice(s_GameServ
, u
, "You have enough gold. Just hang on to it for now.");
1453 tempItem
= tempContainer
->getItem();
1455 notice(s_GameServ
, u
, "Thank you for your business! We gave you %ld gold for %s!", (tempItem
->price() / 2), tempItem
->getName().c_str());
1456 p
->addGold((tempItem
->price() / 2));
1457 p
->inventory
->deleteItem(tempItem
);
1458 if (tempItem
== p
->getWeapon())
1460 notice(s_GameServ
, u
, "Since you equipped %s, you're going to have to reequip something", tempItem
->getName().c_str());
1464 else if (tempItem
== p
->getArmor())
1467 notice(s_GameServ
, u
, "Since you equipped %s, you're going to have to reequip something", tempItem
->getName().c_str());
1474 notice(s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
1475 notice(s_GameServ
, u
, " \ 2STORE SELL #\ 2");
1476 notice(s_GameServ
, u
, " \ 2STORE BUY \1f#\1f\ 2");
1480 void do_inventory(char *u
)
1484 if (!(user
= find(u
)))
1486 notice(s_GameServ
, u
, "Fatal Error. Contact a <S admin!");
1489 else if (isIgnore(user
))
1492 log("Ignoring %s.", user
->getNick());
1496 else if (!is_playing(user
))
1498 notice(s_GameServ
, u
, "You must be playing to check your inventory!");
1501 if (!is_fighting(user
))
1502 updateTS(user
->stats
);
1503 showinventory(user
->stats
, user
);
1507 void do_tavern(char *u
)
1509 char *cmd
= strtok(NULL
, " ");
1514 if (!(user
= find(u
)))
1516 notice(s_GameServ
, u
, "Fatal Error. See a <S admin for help");
1519 else if (isIgnore(user
))
1522 log("Ignoring %s.", user
->getNick());
1526 else if (!is_playing(user
))
1528 notice(s_GameServ
, u
, "You must be playing to go to the Tavern");
1531 else if (is_fighting(user
))
1533 notice(s_GameServ
, u
, "You cannot go to the Tavern during a fight!");
1537 updateTS(user
->stats
);
1542 notice(s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary and General Store");
1543 notice(s_GameServ
, u
, "Your commands:");
1544 notice(s_GameServ
, u
, "/msg <S TAVERN {LIST | BUY} [NUMBER]");
1545 notice(s_GameServ
, u
, "What'll it be?");
1547 else if (stricmp(cmd
, "LIST") == 0)
1549 notice(s_GameServ
, u
, "Here is a list of what we have to offer:");
1551 notice(s_GameServ
, u
, "To buy an item, type /msg <S TAVERN BUY #");
1553 else if (stricmp(cmd
, "BUY") == 0)
1556 char *chid
= strtok(NULL
, " ");
1557 char *amount
= strtok(NULL
, " ");
1560 amt
= stringtoint(amount
);
1564 notice(s_GameServ
, u
, "SYNTAX: TAVERN BUY # [#]");
1565 notice(s_GameServ
, u
, "Example: /msg <S TAVERN BUY 6001");
1566 notice(s_GameServ
, u
, "Example: /msg <S TAVERN BUY 6001 10");
1569 long id
= stringtoint(chid
);
1570 tavernItem
*tempItem
;
1572 if (!(tempItem
= findTavernItemByID(id
)) || user
->stats
->getLevel() < tempItem
->getLevel())
1574 notice(s_GameServ
, u
, "Invalid Choice!");
1575 notice(s_GameServ
, u
, "Here is a list of what we have to offer:");
1577 notice(s_GameServ
, u
, "To buy an item, type /msg <S TAVERN BUY #");
1580 else if (!amount
&& user
->stats
->getGold() < tempItem
->getItem()->price())
1582 notice(s_GameServ
, u
, "You don't have enough gold!");
1583 notice(s_GameServ
, u
, "Here is a list of what we have to offer:");
1585 notice(s_GameServ
, u
, "To buy an item, type /msg <S TAVERN BUY #");
1587 else if (user
->stats
->getGold() < amt
* tempItem
->getItem()->price())
1589 notice(s_GameServ
, u
, "You don't have enough gold!");
1590 notice(s_GameServ
, u
, "Here is a list of what we have to offer:");
1592 notice(s_GameServ
, u
, "To buy an item, type /msg <S TAVERN BUY # [#]");
1598 int amt
= stringtoint(amount
);
1599 if (amt
< 0 || amount
[0] == '-')
1601 notice(s_GameServ
, u
, "You trying to steal from me?");
1603 else if (user
->stats
->inventory
->addItem(tempItem
->getItem(), amt
) == NULL
)
1605 notice(s_GameServ
, u
, "You can't carry that many!");
1609 notice(s_GameServ
, u
, "%d %s's coming right up!", amt
, tempItem
->getItem()->getName().c_str());
1610 user
->stats
->subtractGold(tempItem
->getItem()->price() * amt
);
1615 if (user
->stats
->inventory
->addItem(tempItem
->getItem()) == NULL
)
1617 notice(s_GameServ
, u
, "You can't carry any more!");
1621 notice(s_GameServ
, u
, "One %s coming right up!", tempItem
->getItem()->getName().c_str());
1622 user
->stats
->subtractGold(tempItem
->getItem()->price());
1629 notice(s_GameServ
, u
, "Improper Syntax.");
1630 notice(s_GameServ
, u
, "Type /msg <S HELP TAVERN for help");
1637 void do_dragon(char *u
)
1641 if (!(user
= find(u
)))
1643 notice(s_GameServ
, u
, "Fatal error. Contact a(n) <S admin. buf: %s", strtok(NULL
, ""));
1646 else if (isIgnore(user
))
1649 log("Ignoring %s.", user
->getNick());
1653 else if (!is_playing(user
))
1655 notice(s_GameServ
, u
, "You must be playing to fight the dragon!");
1658 else if (is_fighting(user
))
1660 notice(s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?");
1663 else if (!isAlive(user
->stats
))
1665 notice(s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!");
1668 else if (user
->stats
->getLevel() < LEVELS
)
1670 notice(s_GameServ
, u
, "You fool! Only those strong enough "\
1671 "to vanquish any foe should DARE fight the dragon!");
1672 notice(s_GameServ
, u
, "To put it in terms you can understand: "\
1673 "You are too weak. You must be Level %d!", REALLEVELS
);
1677 updateTS(user
->stats
);
1679 Player
*p
= user
->stats
;
1681 notice(s_GameServ
, u
, "You approach the dragon's lair cautiously.");
1682 notice(s_GameServ
, u
, "The stench of sulfer fills the air as a "\
1683 "deep, red fog rolls in. The air is filled with the "\
1684 "heated mist of deadly fire from beyond the cave "\
1686 notice(s_GameServ
, u
, "You adjust your %s, tighten your grip on "\
1687 "your %s, and venture into the hot, dark cave. "\
1688 "You are surprised at the angle of descent as you climb "\
1689 "lower and lower, deeper into the dragon's den.",
1690 (p
->getArmor() ? p
->getArmor()->getName().c_str() : "Fists"), (p
->getWeapon() ? p
->getWeapon()->getName().c_str() : "Birthday Suit"));
1691 notice(s_GameServ
, u
, "You come to the end of the cave to find "\
1692 "a tooth. It is a large tooth... bigger than your torso."\
1693 " Suddenly the darkness lifts from the gleam of an eye "\
1694 " staring into your soul! The eye is large... HUGE!");
1695 notice(s_GameServ
, u
, "Just then you notice the eye begin to "\
1696 "glare orange! The tooth is moving... but it is still too "\
1697 "dark for you to make out.... THE DRAGON! You see it!");
1698 p
->setMonster(&dragon
);
1703 void do_master(char *u
)
1708 if (!(user
= find(u
)))
1710 notice(s_GameServ
, u
, "Fatal error. Contact a(n) <S admin. buf: %s", strtok(NULL
, ""));
1713 else if (isIgnore(user
))
1716 log("Ignoring %s.", user
->getNick());
1720 else if (!is_playing(user
))
1722 notice(s_GameServ
, u
, "You must be playing to see your master!");
1725 else if (is_fighting(user
))
1727 notice(s_GameServ
, u
, "You're in the middle of a fight! Pay attention!");
1730 else if (!isAlive(user
->stats
))
1732 notice(s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!");
1736 updateTS(user
->stats
);
1738 char *cmd
= strtok(NULL
, " ");
1739 Player
*p
= user
->stats
;
1744 notice(s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again");
1750 switch(p
->getLevel())
1787 need
= p
->getExp() + 1;
1788 notice(s_GameServ
, u
, "You are at level %d. You are the master. What's left? The DRAGON!", REALLEVELS
);
1792 need
= p
->getExp() + 1; // Unknown level... don't let them fight a fake master!
1798 notice(s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}");
1802 if (stricmp(cmd
, "FIGHT") == 0)
1804 if (p
->getExp() >= need
)
1810 notice(s_GameServ
, u
, "You are not worthy of fighting %s! You need %ld more experience.",
1811 levels
[p
->getLevel() - 1].master
.name
.c_str(), (need
- p
->getExp()));
1814 else if (stricmp(cmd
, "QUESTION") == 0)
1816 if (p
->getExp() >= need
)
1817 notice(s_GameServ
, u
, "%s looks you up and down and decides you are more ready than you will ever be.",
1818 levels
[p
->getLevel() - 1].master
.name
.c_str());
1820 notice(s_GameServ
, u
, "You pathetic fool! You are no match for %s, %s!",
1821 levels
[p
->getLevel() - 1].master
.name
.c_str(), p
->getName().c_str());
1827 notice(s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}");
1833 void do_reset(char *u
)
1835 char *nick
= strtok(NULL
, " ");
1839 if (!(user
= find(u
)))
1841 notice(s_GameServ
, u
, "Error: aClient not found. Contact a <S admin");
1842 log("Error: aClient not found: %s", u
);
1845 else if (!isAdmin(user
))
1847 notice(s_GameServ
, u
, "You must be a <S admin to use this command!");
1853 notice(s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}");
1855 else if (stricmp(nick
, "ALL") == 0)
1857 notice(s_GameServ
, u
, "Resetting everyone's stats!");
1860 else if (!(p
= findplayer(nick
)))
1862 notice(s_GameServ
, u
, "Nick %s not found.", nick
);
1866 notice(s_GameServ
, u
, "Resetting %s.", p
->getName().c_str());
1871 void do_help(char *u
)
1873 char *cmd
= strtok(NULL
, " ");
1875 display_help(u
, cmd
);