]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
14 #if defined(HAVE_CRYPT_H)
18 #elif defined(HAVE_UNISTD_H)
24 List
< aClient
> players
;
26 Monster
* monsters
[ LEVELS
][ MONSTERS
]; // Monsters per level. Total = MONSTERS * LEVELS
27 Monster boss
; // The boss monster
29 Monster
* masters
[ LEVELS
]; // A master for each level
37 char * strtok ( char * str
, const char * delim
);
40 int stricmp ( const char * s1
, const char * s2
);
41 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
45 /********** Password functions **********/
47 bool passcmp ( char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
49 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
51 /********** Password functions **********/
54 /********** GameServ Booleans **********/
56 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
57 bool is_playing ( aClient
* user
);
59 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
60 bool is_fighting ( aClient
* user
);
62 bool player_fight ( char * u
); // True if the player is fighting another player.
63 bool player_fight ( aClient
* user
);
65 bool master_fight ( char * u
); // True if the player is fighting their master.
66 bool master_fight ( aClient
* user
);
68 /********** GameServ Booleans **********/
70 void display_help ( char * u
, char * file
= NULL
);
71 void display_monster ( char * u
);
72 void display_players ( char * u
);
73 void display_players ( aClient
* user
);
74 long int chartoint ( char ch
);
75 int isstringnum ( char * num
);
76 long int pow ( int x
, int y
);
77 long int stringtoint ( char * number
);
79 char * spaces ( int len
, char * seperator
);
80 void refresh ( Player
* p
);
82 void reset ( Player
* p
);
86 void delete_monsters ();
87 void delete_masters ();
89 void do_admin ( char * u
);
90 void do_attack ( char * u
);
91 void do_bank ( char * u
);
92 void do_fight ( char * u
);
93 void do_heal ( char * u
);
94 void do_help ( char * u
);
95 void do_identify ( char * u
);
96 void do_inventory ( char * u
);
97 void do_refresh ( char * u
);
98 void do_register ( char * u
);
99 void do_list ( char * u
);
100 void do_master ( char * u
);
101 void do_play ( char * u
);
102 void do_quitg ( char * u
);
103 void do_reset ( char * u
);
104 void do_run ( char * u
);
105 void do_stats ( char * u
);
106 void do_store ( char * u
);
107 void do_tavern ( char * u
);
108 void do_use ( char * u
);
109 void see_master ( char * u
);
111 void showstats ( const char * u
, const char * nick
);
112 void showinventory ( aClient
* from
, aClient
* to
);
113 void showBankBalance ( const char * u
);
114 void end_turn ( aClient
* user
);
117 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
118 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
119 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
120 "Light Saber" , "Masamune" , "Mystical Sword" };
122 char * armors
[ WNA
] = { "Nothing" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
123 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
124 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
125 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
127 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
128 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
129 int webonus
[ WNA
] = { 0 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
130 int arbonus
[ WNA
] = { 0 , 1 , 3 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
132 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
133 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
134 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
136 void gameserv ( char * source
, char * buf
)
139 cmd
= strtok ( buf
, " " );
142 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
146 cmd
++; // Get rid of that : at the beginning of the :text (command)
149 log ( "Source: %s Command: %s " , source
, cmd
);
157 int curday
= tm
-> tm_mday
;
166 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
169 ts
= strtok ( NULL
, "\1" );
170 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
171 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
172 notice ( s_GameServ
, source
, "\1VERSION %s %s +devel\1" , PACKAGE
, VERSION
);
173 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
174 cmd
= strtok ( NULL
, " " );
177 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
181 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
183 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
185 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
187 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
189 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
191 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
192 do_inventory ( source
);
193 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
195 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
197 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
199 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
201 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
203 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
205 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
207 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
210 } else if ( stricmp ( cmd
, "PRINT" ) == 0 ) {
211 cout
<< "Printing the clients list:" << endl
;
213 cout
<< " \n Printing the players list:" << endl
;
216 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
218 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
220 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
222 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
224 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
227 if (!( user
= find ( source
)))
229 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
230 log ( "Error: aClient not found: %s " , source
);
232 else if (! isAdmin ( user
))
234 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
240 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
242 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
245 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
248 if (!( user
= find ( source
)))
250 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
251 log ( "Error: aClient not found: %s " , source
);
253 else if (! isAdmin ( user
))
255 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
261 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
264 if (!( user
= find ( source
)))
266 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
267 log ( "Error: aClient not found: %s " , source
);
269 else if (! isAdmin ( user
))
271 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
275 char * cmd2
= strtok ( NULL
, " " );
278 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
281 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
283 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
287 display_help ( source
, cmd
);
289 } 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 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
310 source
--; // Bring the ':' back so we don't leak memory
311 cmd
--; // Same thing :)
314 int stricmp ( const char * s1
, const char * s2
)
318 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
324 if ( c
< tolower (* s2
))
329 void showstats ( const char * u
, const char * nick
)
331 aClient
* ni
, * sender
= find ( u
);
337 if (!( ni
= findplayer ( nick
)))
339 notice ( s_GameServ
, u
, " %s not found" , nick
);
343 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
345 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
346 space
= spaces ( strlen ( buf
), " " );
347 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
351 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
352 space
= spaces ( strlen ( buf
), " " );
353 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
356 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
359 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
360 space
= spaces ( strlen ( buf
), " " );
361 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
362 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
365 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
366 space
= spaces ( strlen ( buf
), " " );
367 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
368 weapons
[ ni
-> stats
-> weapon
]);
371 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
372 space
= spaces ( strlen ( buf
), " " );
373 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
378 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
383 char * spaces ( int len
, char * seperator
)
386 final
= new char [ 30 ];
388 strcpy ( final
, seperator
);
389 for ( y
= 0 ; y
< 30 - len
; y
++)
390 strcat ( final
, seperator
);
394 void raw ( const char * fmt
, ...)
399 input
= new char [ 1024 ];
401 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
407 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
408 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
409 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
412 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
417 sprintf ( input
, " %s%c " , input
, * t
);
422 log ( "Input: %s " , input
);
425 sprintf ( input
, " %s%s " , input
, " \r\n " );
426 sock_puts ( sock
, input
);
430 /* Send a NOTICE from the given source to the given nick. */
432 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
440 input
= new char [ 1024 ];
447 sprintf ( input
, ": %s NOTICE %s :" , source
, dest
);
449 sprintf ( input
, " %s O %s :" , gsnum
, dest
);
457 sprintf ( input
, ": %s NOTICE %s :" , source
, dest
);
459 sprintf ( input
, " %s O %s :" , gsnum
, dest
);
468 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
469 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
470 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
473 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
478 sprintf ( input
, " %s%c " , input
, * t
);
483 log ( "Input: %s " , input
);
485 sprintf ( input
, " %s%s " , input
, " \r\n " );
486 sock_puts ( sock
, input
);
492 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
498 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
499 if ( c
== 0 || -- len
== 0 )
504 if ( c
< tolower (* s2
))
510 char * strtok ( char * str
, const char * delim
)
512 static char * current
= NULL
;
519 current
+= strspn ( current
, delim
);
520 ret
= * current
? current
: NULL
;
521 current
+= strcspn ( current
, delim
);
530 void do_list ( char * u
)
532 ListNode
< aClient
> * temp
;
533 temp
= players
. First ();
534 if (! players
. isEmpty ())
536 notice ( s_GameServ
, u
, "People Playing:" );
541 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
542 temp
-> getData ()-> stats
-> name
);
544 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
545 temp
-> getData ()-> stats
-> name
);
550 notice ( s_GameServ
, u
, "End of List" );
553 notice ( s_GameServ
, u
, "No one is playing" );
556 void do_register ( char * u
)
558 char * password
, * name
;
560 name
= strtok ( NULL
, " " );
561 password
= strtok ( NULL
, " " );
563 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
566 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
567 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
572 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
576 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
578 else if (( user
= find ( u
)))
581 if (! user
-> stats
&& ! p
)
583 user
-> stats
= new Player ( user
);
584 user
-> stats
-> user
= user
; // Set the backwards pointer
585 strcpy ( user
-> stats
-> password
, crypt ( password
, salt
));
586 strcpy ( user
-> stats
-> name
, name
);
587 players
. insertAtBack ( user
);
588 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
589 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
590 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
594 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
599 void do_identify ( char * u
)
601 char * password
, * name
;
603 name
= strtok ( NULL
, " " );
604 password
= strtok ( NULL
, " " );
606 if (! password
|| ! name
)
608 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
612 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
613 log ( "Error: aClient not found: %s " , u
);
615 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
616 notice ( s_GameServ
, u
, "Player %s not found" , name
);
617 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
619 notice ( s_GameServ
, u
, "Password incorrect" );
623 if ( p
-> stats
-> user
&& ! isAdmin ( user
))
625 notice ( s_GameServ
, u
, "That player has already identified." );
630 ListNode
< aClient
> * temp
;
631 temp
= players
. Find ( p
);
634 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
638 user
-> stats
= new Player ( p
-> stats
-> name
);
640 log ( "Setting data for identified" );
642 user
-> stats
-> setData ( p
-> stats
);
645 log ( "Player Identified" );
650 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
655 notice ( s_GameServ
, u
, "Already identified. Contact a %S admin for help." );
660 void do_stats ( char * u
)
665 nick
= strtok ( NULL
, " " );
669 if (!( user
= find ( u
)))
671 notice ( s_GameServ
, u
, "Fatal Error in do_stats(). Contact a %S admin for help!" );
672 log ( "Error: aClient not found: %s " , u
);
675 else if (! is_playing ( user
))
677 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
681 showstats ( u
, user
-> stats
-> name
);
689 log ( "Calling delete_masters()" );
695 log ( "Initializing masters" );
698 for ( int x
= 0 ; x
< LEVELS
; x
++)
699 masters
[ x
] = new Monster
;
701 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
702 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
703 masters
[ 0 ]-> strength
= 15 ;
704 masters
[ 0 ]-> gold
= 0 ;
706 masters
[ 0 ]-> maxhp
= 30 ;
708 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!" );
710 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
711 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
712 masters
[ 1 ]-> strength
= 30 ;
713 masters
[ 1 ]-> gold
= 0 ;
715 masters
[ 1 ]-> maxhp
= 40 ;
717 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." );
719 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
720 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
721 masters
[ 2 ]-> strength
= 85 ;
722 masters
[ 2 ]-> gold
= 0 ;
724 masters
[ 2 ]-> maxhp
= 70 ;
726 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!" );
729 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
730 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
731 masters
[ 3 ]-> strength
= 120 ;
732 masters
[ 3 ]-> gold
= 0 ;
734 masters
[ 3 ]-> maxhp
= 120 ;
735 masters
[ 3 ]-> hp
= 120 ;
736 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
738 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
739 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
740 masters
[ 4 ]-> strength
= 135 ;
741 masters
[ 4 ]-> gold
= 0 ;
743 masters
[ 4 ]-> maxhp
= 200 ;
744 masters
[ 4 ]-> hp
= 200 ;
745 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!" );
747 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
748 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
749 masters
[ 5 ]-> strength
= 160 ;
750 masters
[ 5 ]-> gold
= 0 ;
752 masters
[ 5 ]-> maxhp
= 400 ;
753 masters
[ 5 ]-> hp
= 400 ;
754 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
757 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
758 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
759 masters
[ 6 ]-> strength
= 185 ;
760 masters
[ 6 ]-> gold
= 0 ;
762 masters
[ 6 ]-> maxhp
= 600 ;
763 masters
[ 6 ]-> hp
= 600 ;
764 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
766 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
767 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
768 masters
[ 7 ]-> strength
= 210 ;
769 masters
[ 7 ]-> gold
= 0 ;
771 masters
[ 7 ]-> maxhp
= 800 ;
772 masters
[ 7 ]-> hp
= 800 ;
773 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
776 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
777 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
778 masters
[ 8 ]-> strength
= 275 ;
779 masters
[ 8 ]-> gold
= 0 ;
781 masters
[ 8 ]-> maxhp
= 1200 ;
782 masters
[ 8 ]-> hp
= 1200 ;
783 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
785 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
786 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
787 masters
[ 9 ]-> strength
= 360 ;
788 masters
[ 9 ]-> gold
= 0 ;
790 masters
[ 9 ]-> maxhp
= 1800 ;
791 masters
[ 9 ]-> hp
= 1800 ;
792 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
794 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
795 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
796 masters
[ 10 ]-> strength
= 575 ;
797 masters
[ 10 ]-> gold
= 0 ;
798 masters
[ 10 ]-> exp
= 0 ;
799 masters
[ 10 ]-> maxhp
= 2500 ;
800 masters
[ 10 ]-> hp
= 2500 ;
801 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." );
807 log ( "Calling delete_monsters" );
812 for ( int x
= 0 ; x
< LEVELS
; x
++)
813 for ( int y
= 0 ; y
< MONSTERS
; y
++)
814 monsters
[ x
][ y
] = new Monster ();
817 void delete_monsters ()
819 for ( int x
= 0 ; x
< LEVELS
; x
++)
820 for ( int y
= 0 ; y
< MONSTERS
; y
++)
822 delete monsters
[ x
][ y
];
825 void delete_masters ()
827 for ( int x
= 0 ; x
< LEVELS
; x
++)
832 void display_monster ( char * u
)
836 aClient
* user
= find ( u
);
837 Player
* ni
= user
-> stats
;
839 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
840 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
841 notice ( s_GameServ
, u
, "Here are your commands:" );
842 notice ( s_GameServ
, u
, "/msg %S attack" );
843 notice ( s_GameServ
, u
, "/msg %S run" );
844 notice ( s_GameServ
, u
, "What will you do?" );
848 void display_players ( char * u
)
852 aClient
* ni
= find ( u
);
854 aClient
* battle
= ni
-> stats
-> battle
;
856 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> stats
-> hp
);
857 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
,
859 notice ( s_GameServ
, u
, "Here are your commands:" );
860 notice ( s_GameServ
, u
, "/msg %S attack" );
861 notice ( s_GameServ
, u
, "/msg %S run" );
862 notice ( s_GameServ
, u
, "What will you do?" );
865 void display_players ( aClient
* user
)
867 char * u
= user
-> getNick ();
868 if ( is_playing ( user
) && player_fight ( user
))
870 aClient
* battle
= user
-> stats
-> battle
;
871 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
872 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
873 notice ( s_GameServ
, u
, "Here are your commands:" );
874 notice ( s_GameServ
, u
, "/msg %S attack" );
875 notice ( s_GameServ
, u
, "/msg %S run" );
876 notice ( s_GameServ
, u
, "What will you do?" );
881 bool is_playing ( char * u
)
884 if (!( user
= find ( u
)))
890 return user
-> stats
!= NULL
;
894 bool is_playing ( aClient
* user
)
896 return user
-> stats
!= NULL
&& ( stricmp ( user
-> getNick (), "!NULL!" ) != 0 );
899 bool is_fighting ( char * u
)
903 if (!( user
= find ( u
)))
907 else if ( user
-> stats
)
909 return user
-> stats
-> fight
!= NULL
|| user
-> stats
-> battle
!= NULL
910 || user
-> stats
-> master
!= NULL
;
915 bool is_fighting ( aClient
* user
)
917 if (! is_playing ( user
))
920 return ( user
-> stats
-> fight
!= NULL
|| user
-> stats
-> battle
!= NULL
|| user
-> stats
-> master
!= NULL
);
923 bool player_fight ( char * u
)
927 if (!( user
= find ( u
)))
929 else if ( user
-> stats
)
930 return user
-> stats
-> battle
!= NULL
;
934 bool player_fight ( aClient
* user
)
936 if (! is_fighting ( user
))
939 return user
-> stats
-> battle
!= NULL
;
942 bool master_fight ( char * u
)
946 if (!( user
= find ( u
)))
948 else if ( user
-> stats
)
949 return user
-> stats
-> master
!= NULL
;
953 bool master_fight ( aClient
* user
)
955 if (! is_playing ( user
))
958 return user
-> stats
-> master
!= NULL
;
961 void do_fight ( char * u
)
963 aClient
* ni
, * battle
;
965 char * nick
= strtok ( NULL
, " " );
969 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
971 else if (!( ni
= find ( u
)))
973 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
976 else if (!( battle
= findbyrealnick ( nick
)))
978 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
981 else if (! is_playing ( ni
))
983 notice ( s_GameServ
, u
, "You are not playing!" );
987 * Offline fighting not implemented yet.
988 * else if (!(fight = finduser(nick)))
990 * ni->stats->battle = battle;
991 * battle->battle = ni;
993 * battle->yourturn = 0;
994 * notice(s_GameServ, u, "You decide to fight %s while they're not online!",
995 * battle->stats->name);
996 * display_players(u);
999 else if (! isAlive ( ni
-> stats
))
1001 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1004 else if ( player_fight ( battle
))
1006 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1009 else if ( is_fighting ( battle
))
1011 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1014 else if ( is_playing ( ni
) && is_playing ( battle
) && stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) != 0 )
1016 // Set your battle pointer to the other player
1017 ni
-> stats
-> battle
= battle
;
1019 // Set the other player's battle pointer to you
1020 battle
-> stats
-> battle
= ni
;
1022 // The initiator gets the first move (perhaps this should be 50/50)
1023 setYourTurn ( ni
-> stats
);
1024 clearYourTurn ( battle
-> stats
);
1026 // Initiate Battle sequence!
1027 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1028 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1029 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first because he initiated!" , ni
-> stats
-> name
);
1030 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1034 void do_use ( char * u
)
1039 char * item
= strtok ( NULL
, " " );
1043 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1044 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1047 else if (!( user
= find ( u
)))
1049 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1052 else if (! is_playing ( user
))
1054 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1058 p
= & user
-> stats
-> inventory
;
1060 if ( stricmp ( item
, "HEALTH" ) == 0 )
1062 if ( p
-> Healing () <= 0 )
1064 notice ( s_GameServ
, u
, "You are out of Health Potions!" );
1067 int oldhealth
= user
-> stats
-> hp
;
1068 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1069 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1070 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1071 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealth
);
1074 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1076 if ( p
-> Strength () <= 0 )
1078 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1081 int oldstrength
= user
-> stats
-> strength
;
1082 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1083 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1084 user
-> stats
-> strength
+= 1 + rand () % 2 ; // 1 - 2 Strength Added
1085 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1088 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1090 if ( p
-> Defense () <= 0 )
1092 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1095 int olddefense
= user
-> stats
-> defense
;
1096 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1097 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1098 user
-> stats
-> defense
+= 1 + rand () % 2 ; // 1 - 2 Defense Added
1099 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1102 else if ( stricmp ( item
, "HP" ) == 0 )
1106 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1109 int oldHP
= user
-> stats
-> maxhp
;
1110 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1111 user
-> stats
-> maxhp
+= 1 + rand () % 5 ; // 1 - 5 Maxhp
1112 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1117 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALTH | STRENGTH | DEFENSE}" );
1121 end_turn ( user
); // If they're fighting, end their turn
1123 void do_run ( char * u
)
1126 Player
* p
, * p2
= NULL
;
1128 if (!( user
= find ( u
)))
1130 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1134 else if (! is_playing ( user
))
1136 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1143 p2
= p
-> battle
-> stats
;
1145 if (! is_fighting ( user
))
1146 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1147 else if (! player_fight ( user
) && ! master_fight ( user
))
1149 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1153 else if ( player_fight ( user
) && isYourTurn ( p
))
1155 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1156 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1159 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1161 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1163 else if ( master_fight ( user
))
1165 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1170 void end_turn ( aClient
* user
)
1172 char * nick
, * u
= user
-> getNick ();
1177 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1179 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1182 if (! player_fight ( user
) && ! master_fight ( user
))
1183 fight
= user
-> stats
-> fight
;
1185 fight
= user
-> stats
-> master
;
1186 battle
= user
-> stats
-> battle
;
1188 if (! player_fight ( user
))
1191 mhit
= ( fight
-> strength
/ 2 ) +
1192 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1193 arbonus
[ user
-> stats
-> armor
]));
1198 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1199 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1200 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1202 if (! player_fight ( user
))
1207 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1208 fight
-> name
, fight
-> weapon
, mhit
);
1211 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1213 if ( mhit
>= user
-> stats
-> hp
)
1215 if (! master_fight ( user
))
1217 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1218 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1219 "of your experience!" );
1220 user
-> stats
-> gold
= 0 ;
1221 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1222 user
-> stats
-> fight
= NULL
;
1223 clearAlive ( user
-> stats
);
1228 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1229 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1230 user
-> stats
-> fight
= NULL
;
1231 user
-> stats
-> master
= NULL
;
1238 user
-> stats
-> hp
-= mhit
;
1245 clearYourTurn ( user
-> stats
);
1246 setYourTurn ( battle
-> stats
);
1247 display_players ( battle
);
1253 void do_attack ( char * u
)
1256 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1257 Monster
* fight
; // The monster they may be fighting
1259 if (!( ni
= find ( u
)))
1261 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1264 else if (! is_playing ( ni
))
1266 notice ( s_GameServ
, u
, "You're not playing!" );
1269 else if (! is_fighting ( ni
))
1271 notice ( s_GameServ
, u
, "You're not in battle!" );
1276 if (! ni
-> stats
-> master
) // This is not a master fight
1277 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1278 else // This IS a master fight
1279 fight
= ni
-> stats
-> master
; // Master Could be NULL
1281 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1283 // One has to be !NULL based on the previous else if
1284 // We wouldn't be here if they were all NULL
1287 if (! player_fight ( ni
))
1290 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1291 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1294 mhit
= ( fight
-> strength
/ 2 ) +
1295 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1296 arbonus
[ ni
-> stats
-> armor
]));
1301 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1302 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1303 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1306 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1307 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1308 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1311 if (! player_fight ( ni
))
1314 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1316 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1318 if ( hit
>= fight
-> hp
)
1320 if ( master_fight ( ni
))
1321 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1323 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1325 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1326 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1327 fight
-> exp
, fight
-> gold
);
1329 // If your new experience (or gold) will be greater than 2 billion,
1330 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1331 // This could be a problem with overflowing out of the sign bit.
1332 // Unsigned long int maybe? Leave it for now.
1333 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1334 ni
-> stats
-> exp
+ fight
-> exp
);
1336 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1337 ni
-> stats
-> gold
+ fight
-> gold
);
1340 if ( master_fight ( ni
))
1342 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1343 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1344 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1346 // Increase your level
1349 // Increase your maximum hit points
1350 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1352 // Heal the player by setting hp to their max
1353 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1355 // Add to your strength
1356 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1358 // Add to your defensive power
1359 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1361 // Clear the pointer for your master
1362 ni
-> stats
-> master
= NULL
;
1365 // They're dead so remove the pointer
1366 delete ni
-> stats
-> fight
;
1367 ni
-> stats
-> fight
= NULL
;
1368 ni
-> stats
-> master
= NULL
;
1378 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1379 fight
-> name
, fight
-> weapon
, mhit
);
1382 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1384 if ( mhit
>= ni
-> stats
-> hp
)
1386 if (! master_fight ( ni
))
1388 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1389 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1390 "of your experience!" );
1391 ni
-> stats
-> gold
= 0 ;
1392 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1393 ni
-> stats
-> fight
= NULL
;
1394 clearAlive ( ni
-> stats
);
1399 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1400 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1401 ni
-> stats
-> fight
= NULL
;
1402 ni
-> stats
-> master
= NULL
;
1409 ni
-> stats
-> hp
-= mhit
;
1415 else if ( player_fight ( ni
))
1417 /* Offline fighting not available yet
1418 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1421 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1423 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1424 if (hit >= battle->stats->hp)
1426 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1427 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1428 (long int)(battle->stats->exp * .10), battle->stats->gold);
1429 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1431 ni->stats->exp += (long int)(battle->stats->exp * .10);
1432 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1436 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1437 ni->stats->exp = 2000000000;
1440 if (2000000000 - ni->stats->gold > battle->stats->gold)
1442 * ni->stats->gold += battle->stats->gold;
1443 battle->stats->gold = 0;
1447 battle->stats->gold = 2000000000 - ni->stats->gold;
1448 ni->stats->gold = 2000000000;
1450 * ni->stats->battle->stats->alive = 0;
1451 ni->stats->battle->battle = NULL;
1452 ni->stats->battle = NULL;
1458 * battle->stats->hp -= hit;
1461 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1462 battle->nick, weapons[battle->stats->weapon], mhit);
1465 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1467 if (mhit >= ni->stats->hp)
1469 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1470 if (2000000000 - battle->stats->gold > ni->stats->gold)
1472 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1473 battle->stats->gold += ni->stats->gold;
1474 * ni->stats->gold = 0;
1478 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1480 ni->stats->gold -= (2000000000 - battle->stats->gold);
1481 notice(s_GameServ, u, "You were left dead with %d gold.",
1482 * (long int)ni->stats->gold);
1483 battle->stats->gold = 2000000000;
1485 ni->stats->battle->battle = NULL;
1486 ni->stats->battle = NULL;
1487 ni->stats->alive = 0;
1493 ni->stats->hp -= mhit;
1499 * end offline fighting */
1501 if ( is_playing ( battle
))
1503 if (! isYourTurn ( ni
-> stats
))
1505 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1506 battle
-> stats
-> name
);
1511 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1513 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1514 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1515 weapons
[ ni
-> stats
-> weapon
], hit
);
1516 clearYourTurn ( ni
-> stats
);
1517 setYourTurn ( battle
-> stats
);
1518 display_players ( battle
-> getNick ());
1522 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1523 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1524 clearYourTurn ( ni
-> stats
);
1525 setYourTurn ( battle
-> stats
);
1526 display_players ( battle
-> getNick ());
1528 if ( hit
>= battle
-> stats
-> hp
)
1530 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1531 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1532 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1533 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1535 battle
-> stats
-> hp
= 0 ;
1536 clearAlive ( battle
-> stats
);
1538 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1540 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1541 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1545 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1546 ni
-> stats
-> exp
= 2000000000 ;
1549 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1551 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1552 "all gold on hand!" );
1553 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1554 battle
-> stats
-> gold
= 0 ;
1558 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1559 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1561 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1562 "gold." , ni
-> stats
-> name
);
1564 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1565 "left. All is not lost!" , battle
-> stats
-> gold
);
1567 ni
-> stats
-> gold
= 2000000000 ;
1569 battle
-> stats
-> battle
= NULL
;
1570 ni
-> stats
-> battle
= NULL
;
1576 battle
-> stats
-> hp
-= hit
;
1577 clearYourTurn ( ni
-> stats
);
1578 setYourTurn ( battle
-> stats
);
1579 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1580 battle
-> stats
-> name
);
1588 void do_heal ( char * u
)
1591 char * amount
= strtok ( NULL
, " " );
1596 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1598 else if (!( ni
= find ( u
)))
1600 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1603 else if (! is_playing ( ni
))
1605 notice ( s_GameServ
, u
, "You aren't playing!" );
1608 else if (! isAlive ( ni
-> stats
))
1610 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1613 else if ( is_fighting ( ni
))
1615 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1617 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1619 notice ( s_GameServ
, u
, "You don't need healing!" );
1621 else if ( stricmp ( amount
, "ALL" ) == 0 )
1623 price
= ni
-> stats
-> level
* 3 ;
1624 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1626 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1627 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1628 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1629 ni
-> stats
-> gold
%= price
;
1633 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1634 "per point." , price
);
1635 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1636 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1637 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1638 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1639 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1642 else if ( isstringnum ( amount
))
1644 num
= stringtoint ( amount
);
1645 price
= ni
-> stats
-> level
* 3 ;
1646 if ( ni
-> stats
-> gold
< price
* num
)
1648 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1649 ( long int ) ni
-> stats
-> gold
/ price
);
1651 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1653 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
1655 ni
-> stats
-> hp
+= num
;
1656 ni
-> stats
-> gold
-= num
* price
;
1658 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1660 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1661 "per point." , price
);
1662 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
1663 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
1664 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1665 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1668 else if ( amount
[ 0 ] == '-' )
1669 notice ( s_GameServ
, u
, "You trying to cheat?" );
1671 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1674 int isstringnum ( char * num
)
1677 for ( x
= 0 ; x
< strlen ( num
); x
++)
1679 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
1685 long int stringtoint ( char * number
)
1687 long int x
, len
= strlen ( number
), sum
= 0 ;
1689 return chartoint ( number
[ 0 ]);
1690 sum
+= chartoint ( number
[ len
- 1 ]);
1691 for ( x
= len
- 2 ; x
>= 0 ; x
--)
1692 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
1696 long int pow ( int x
, int y
)
1702 if ( x
!= 0 && y
!= 0 )
1704 for ( count
= 1 ; count
<= y
- 1 ; count
++)
1712 long int chartoint ( char ch
)
1714 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
1715 return int ( ch
) - 48 ;
1722 ListNode
< aClient
> * ptr
= players
. First ();
1726 outfile
. open ( playerdata
);
1730 log ( "Error opening %s " , playerdata
);
1736 it
= ptr
-> getData ()-> stats
;
1737 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
1738 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
1739 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
1740 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
1741 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
1742 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
1754 char * tempname
, * buf
, * password
;
1755 buf
= new char [ 1023 ];
1757 infile
. open ( playerdata
);
1761 log ( "Error opening %s " , playerdata
);
1765 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
1768 tempname
= strtok ( buf
, " " );
1769 temp
-> stats
= new Player ( tempname
);
1772 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
1773 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
1774 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
1775 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
1776 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
1777 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
1778 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
1779 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
1780 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
1781 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
1782 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
1783 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
1784 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
1786 password
= strtok ( NULL
, " " );
1787 strcpy ( p
-> password
, password
);
1788 temp
-> setNick ( "!NULL!" );
1790 temp
-> setRealNick ( "!NULL!" );
1793 p
-> inventory
. reset (); // Set inventory to all 0s
1794 // Old player databases didn't have these three extra values
1795 // If they come up null, leave them to 0 as the default.
1796 // On the next gameserv database save, it will save the values.
1797 tempname
= strtok ( NULL
, " " );
1799 p
-> inventory
. setHealing ( stringtoint ( tempname
));
1801 tempname
= strtok ( NULL
, " " );
1803 p
-> inventory
. setStrength ( stringtoint ( tempname
));
1805 tempname
= strtok ( NULL
, " " );
1807 p
-> inventory
. setDefense ( stringtoint ( tempname
));
1809 tempname
= strtok ( NULL
, " " );
1811 p
-> inventory
. setHP ( stringtoint ( tempname
));
1813 players
. insertAtBack ( temp
);
1821 bool passcmp ( char * encrypted
, char * plaintext
)
1824 char * plaintext2
, * plainToencrypt
;
1827 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
1828 strcpy ( plaintext2
, plaintext
);
1830 salt
[ 0 ] = encrypted
[ 0 ];
1831 salt
[ 1 ] = encrypted
[ 1 ];
1834 plainToencrypt
= crypt ( plaintext2
, salt
);
1836 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
1838 delete [] plaintext2
;
1843 bool check_password ( char * name
, char * plaintext
)
1847 if (!( client
= findplayer ( name
)))
1851 return passcmp ( client
-> stats
-> password
, plaintext
);
1855 void do_store ( char * u
)
1857 char * cmd
= strtok ( NULL
, " " );
1858 char * item
= strtok ( NULL
, " " );
1859 char * num
= strtok ( NULL
, " " );
1867 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
1868 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
1869 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
1871 else if (!( user
= find ( u
)) || ! is_playing ( user
))
1872 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
1873 else if (! isAlive ( user
-> stats
))
1875 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
1878 else if ( stricmp ( cmd
, "LIST" ) == 0 )
1880 if ( stricmp ( item
, "WEAPONS" ) == 0 )
1882 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
1883 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
1884 for ( int x
= 1 ; x
< WNA
; x
++)
1886 space
= spaces ( strlen ( weapons
[ x
]), "." );
1887 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
1890 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
1891 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
1894 else if ( stricmp ( item
, "ARMOR" ) == 0 )
1896 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
1897 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
1898 for ( int x
= 1 ; x
< WNA
; x
++)
1900 space
= spaces ( strlen ( armors
[ x
]), "." );
1901 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
1904 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
1905 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
1909 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
1912 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
1915 else if (! isstringnum ( num
))
1917 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
1920 if ( stricmp ( item
, "WEAPON" ) == 0 )
1922 wep
= stringtoint ( num
);
1923 if ( wep
>= WNA
|| wep
< 1 )
1925 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
1932 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
1933 else if ( p
-> gold
< prices
[ wep
- 1 ])
1934 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
1937 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
1939 p
-> gold
-= prices
[ wep
- 1 ];
1942 else if ( stricmp ( item
, "ARMOR" ) == 0 )
1944 wep
= stringtoint ( num
);
1945 if ( wep
>= WNA
|| wep
< 1 )
1947 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
1954 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
1955 else if ( p
-> gold
< prices
[ wep
- 1 ])
1956 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
1959 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
1961 p
-> gold
-= prices
[ wep
- 1 ];
1965 else if ( stricmp ( cmd
, "SELL" ) == 0 )
1969 if ( stricmp ( item
, "WEAPON" ) == 0 )
1973 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
1976 else if ( p
-> gold
== 2000000000 )
1978 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
1981 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
1983 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
1984 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
1985 p
-> gold
= 2000000000 ;
1990 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
1991 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
1995 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2001 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2004 if ( p
-> gold
== 2000000000 )
2006 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2009 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2011 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2012 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2013 p
-> gold
= 2000000000 ;
2018 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2019 ( prices
[ p
-> armor
- 1 ] / 2 ));
2021 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2027 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2028 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2029 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2033 void do_inventory ( char * u
)
2037 if (!( user
= find ( u
)))
2039 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2042 else if (! is_playing ( user
))
2044 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2047 showinventory ( user
, user
);
2049 void showinventory ( aClient
* from
, aClient
* to
)
2051 char * nick
= to
-> getNick ();
2055 if ( is_playing ( from
))
2057 Pouch
* p
= & from
-> stats
-> inventory
;
2058 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2059 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2060 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2061 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2062 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2065 void do_tavern ( char * u
)
2067 char * cmd
= strtok ( NULL
, " " );
2072 if (!( user
= find ( u
)))
2074 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2077 else if (! is_playing ( user
))
2079 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2082 else if ( is_fighting ( user
))
2084 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2090 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2091 notice ( s_GameServ
, u
, "Your commands:" );
2092 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2093 notice ( s_GameServ
, u
, "What'll it be?" );
2095 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2097 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2098 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 1000 * p
-> level
+ ( p
-> exp
/ 10 ));
2099 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 2050 * p
-> level
+ ( p
-> exp
/ 10 ));
2100 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 2000 * p
-> level
+ ( p
-> exp
/ 10 ));
2101 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 2300 * p
-> level
+ ( p
-> exp
/ 10 ));
2102 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2103 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2104 notice ( s_GameServ
, u
, "By something will ya!" );
2106 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2108 char * chnum
= strtok ( NULL
, " " );
2109 int num
= stringtoint ( chnum
);
2113 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2114 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2117 if ( num
< 1 || num
> 4 )
2119 notice ( s_GameServ
, u
, "Invalid Choice!" );
2120 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2121 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 1000 * p
-> level
+ ( p
-> exp
/ 10 ));
2122 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 2050 * p
-> level
+ ( p
-> exp
/ 10 ));
2123 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 2000 * p
-> level
+ ( p
-> exp
/ 10 ));
2124 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 2300 * p
-> level
+ ( p
-> exp
/ 10 ));
2125 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2126 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2132 price
= ( 1000 * p
-> level
) + ( p
-> exp
/ 10 );
2133 if ( p
-> gold
>= price
)
2135 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2136 p
-> inventory
. incHealing ();
2140 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2143 price
= ( 2050 * p
-> level
) + ( p
-> exp
/ 10 );
2144 if ( p
-> gold
>= price
)
2146 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2147 p
-> inventory
. incStrength ();
2151 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2154 price
= ( 2000 * p
-> level
) + ( p
-> exp
/ 10 );
2155 if ( p
-> gold
>= price
)
2157 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2158 p
-> inventory
. incDefense ();
2162 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2165 price
= ( 2300 * p
-> level
) + ( p
-> exp
/ 10 );
2166 if ( p
-> gold
>= price
)
2168 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2169 p
-> inventory
. incHP ();
2173 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2176 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2182 notice ( s_GameServ
, u
, "Improper Syntax." );
2183 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2187 void do_bank ( char * u
)
2189 char * cmd
= strtok ( NULL
, " " );
2190 char * amount
= strtok ( NULL
, " " );
2191 char * nick
= strtok ( NULL
, " " );
2196 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2198 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2199 notice ( s_GameServ
, u
, "BANK BALANCE" );
2204 if (! is_playing ( user
))
2206 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2209 else if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2214 else if (! isAlive ( user
-> stats
))
2216 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2219 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2221 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2227 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2229 if ( p
-> bank
== 2000000000 )
2231 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2234 else if ( stricmp ( amount
, "ALL" ) == 0 )
2236 if ( 2000000000 - p
-> bank
< p
-> gold
)
2238 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2239 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2240 p
-> gold
-= ( 2000000000 - p
-> bank
);
2241 p
-> bank
= 2000000000 ;
2246 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2252 else if ( stringtoint ( amount
) > p
-> gold
)
2254 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2260 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2262 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2263 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2264 p
-> gold
-= ( 2000000000 - p
-> bank
);
2265 p
-> bank
= 2000000000 ;
2270 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2271 p
-> bank
+= stringtoint ( amount
);
2272 p
-> gold
-= stringtoint ( amount
);
2277 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2279 if ( p
-> gold
== 2000000000 )
2281 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2285 else if ( stricmp ( amount
, "ALL" ) == 0 )
2287 if ( 2000000000 - p
-> gold
< p
-> bank
)
2289 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2290 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2291 p
-> bank
-= ( 2000000000 - p
-> gold
);
2292 p
-> gold
= 2000000000 ;
2297 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2303 else if ( stringtoint ( amount
) > p
-> bank
)
2305 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2311 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2313 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2314 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2315 ( 2000000000 - p
-> gold
));
2316 p
-> bank
-= ( 2000000000 - p
-> gold
);
2317 p
-> gold
= 2000000000 ;
2322 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2323 p
-> gold
+= stringtoint ( amount
);
2324 p
-> bank
-= stringtoint ( amount
);
2332 void do_master ( char * u
)
2339 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2342 else if ( is_fighting ( user
))
2344 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2347 else if (! isAlive ( user
-> stats
))
2349 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2352 else if (! is_playing ( user
))
2354 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2358 char * cmd
= strtok ( NULL
, " " );
2359 Player
* p
= user
-> stats
;
2364 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2407 notice ( s_GameServ
, u
, "You are at level 12. You are the master. What's left? The DRAGON!" );
2410 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2416 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2420 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2428 notice ( s_GameServ
, u
, "You are not worthy of fighting %s ! You need %l d more experience." , masters
[ p
-> level
- 1 ]-> name
, ( need
- p
-> exp
));
2431 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2434 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
);
2436 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2442 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2446 void see_master ( char * u
)
2450 if (!( user
= find ( u
)))
2452 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2456 if (! is_fighting ( user
) && is_playing ( user
))
2458 Player
* p
= user
-> stats
;
2459 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2460 p
-> fight
= p
-> master
;
2461 display_monster ( u
); // Since master is the same structure, use this function
2465 void showBankBalance ( const char * u
)
2470 if (!( user
= find ( u
)))
2478 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2484 ListNode
< aClient
> * it
;
2487 it
= players
. First ();
2491 p
= it
-> getData ()-> stats
;
2497 void refresh ( Player
* p
)
2502 if ( p
-> hp
< p
-> maxhp
)
2504 p
-> forest_fights
= forestfights
;
2505 p
-> player_fights
= 3 ;
2510 void do_refresh ( char * u
)
2512 char * nick
= strtok ( NULL
, " " );
2515 if (!( user
= find ( u
)))
2517 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2518 log ( "Error: aClient not found: %s " , u
);
2521 else if (! isAdmin ( user
))
2523 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2528 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
2531 else if ( stricmp ( nick
, "ALL" ) == 0 )
2533 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
2536 else if (( user
= findbyrealnick ( nick
)))
2538 if ( is_playing ( user
))
2541 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
2543 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
2545 refresh ( user
-> stats
);
2550 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2552 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2558 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2566 ListNode
< aClient
> * it
;
2569 it
= players
. First ();
2573 p
= it
-> getData ()-> stats
;
2579 void reset ( Player
* p
)
2587 void do_reset ( char * u
)
2589 char * nick
= strtok ( NULL
, " " );
2592 if (!( user
= find ( u
)))
2594 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2595 log ( "Error: aClient not found: %s " , u
);
2598 else if (! isAdmin ( user
))
2600 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2605 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
2608 else if ( stricmp ( nick
, "ALL" ) == 0 )
2610 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
2613 else if (( user
= findbyrealnick ( nick
)))
2615 if ( is_playing ( user
))
2618 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
2620 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
2627 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2629 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2635 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2640 void do_help ( char * u
)
2642 char * cmd
= strtok ( NULL
, " " );
2644 display_help ( u
, cmd
);
2647 void display_help ( char * u
, char * file
)
2654 infile
. open ( "helpfiles/help" );
2657 log ( "Error opening helpfiles/help" );
2658 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
2661 buf
= new char [ 1024 ];
2662 while ( infile
. getline ( buf
, 1024 ))
2664 // Written this way, it will process %S in the helpfiles
2665 // Instead of notice(s_GameServ, u, "%s", buf);
2666 notice ( s_GameServ
, u
, buf
);
2670 aClient
* user
= find ( u
);
2671 if ( user
&& isAdmin ( user
))
2672 display_help ( u
, "admin_commands" );
2677 filename
= new char [ strlen ( file
) + 11 ];
2678 strcpy ( filename
, "helpfiles/" );
2679 strcat ( filename
, file
);
2681 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
2682 filename
[ x
] = tolower ( filename
[ x
]);
2684 infile
. open ( filename
);
2688 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
2691 buf
= new char [ 1024 ];
2692 while ( infile
. getline ( buf
, 1024 ))
2694 // Written this way, it will process %S in the helpfiles
2695 // Instead of notice(s_GameServ, u, "%s", buf);
2696 notice ( s_GameServ
, u
, buf
);
2703 void do_admin ( char * u
)
2706 char * pass
= strtok ( NULL
, " " );
2708 if (!( user
= find ( u
)))
2710 log ( "Error: aClient not found: %s " , u
);
2711 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
2716 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
2722 notice ( s_GameServ
, u
, "You already have administrator privledges." );
2725 else if ( strcmp ( pass
, adminpass
) == 0 )
2727 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
2730 log ( " %s became an administrator." , user
-> getRealNick ());
2732 log ( " %s became an administrator." , user
-> getNick ());
2737 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
2742 bool load_monsters ()
2745 infile
. open ( "monsters.dat" );
2751 log ( "Error opening monsters.dat" );
2755 buf
= new char [ 2048 ];
2758 log ( "Loading monsters from monsters.dat" );
2761 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
2763 for ( int m
= 0 ; m
< MONSTERS
;)
2765 infile
. getline ( buf
, 2048 );
2766 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
2770 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
2771 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
2772 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
2773 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
2774 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
2775 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
2776 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
2777 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));