]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
b797ac631e74b3b221d2eda51182f026efcb9691
16 #if defined(HAVE_CRYPT_H)
20 #elif defined(HAVE_UNISTD_H)
27 Monster boss
; // The boss monster
28 Level levels
[ LEVELS
]; // The newest way to store monsters
30 Monster
* masters
[ LEVELS
]; // A master for each level
38 char * strtok ( char * str
, const char * delim
);
41 int stricmp ( const char * s1
, const char * s2
);
42 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 **********/
57 bool timedOut ( Player
* p
);
58 void updateTS ( Player
* p
);
59 void timeOutEvent ( Player
* p
);
61 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
62 bool is_playing ( aClient
* user
);
64 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
65 bool is_fighting ( aClient
* user
);
67 bool player_fight ( char * u
); // True if the player is fighting another player.
68 bool player_fight ( aClient
* user
);
70 bool master_fight ( char * u
); // True if the player is fighting their master.
71 bool master_fight ( aClient
* user
);
73 /********** GameServ Booleans **********/
75 void display_help ( char * u
, char * file
= NULL
);
76 void display_monster ( char * u
);
77 void display_players ( char * u
);
78 void display_players ( aClient
* user
);
79 long int chartoint ( char ch
);
80 int isstringnum ( char * num
);
81 long int pow ( int x
, int y
);
82 long int stringtoint ( char * number
);
84 char * spaces ( int len
, char * seperator
);
85 void refresh ( Player
* p
);
87 void updateTS ( Player
* p
);
88 void reset ( Player
* p
);
92 void delete_monsters ();
93 void delete_masters ();
95 void do_admin ( char * u
);
96 void do_attack ( char * u
);
97 void do_bank ( char * u
);
98 void do_check ( char * u
);
99 void do_fight ( char * u
);
100 void do_heal ( char * u
);
101 void do_help ( char * u
);
102 void do_identify ( char * u
);
103 void do_inventory ( char * u
);
104 void do_refresh ( char * u
);
105 void do_register ( char * u
);
106 void do_list ( char * u
);
107 void do_logout ( char * u
);
108 void do_master ( char * u
);
109 void do_dragon ( char * u
);
110 void do_play ( char * u
);
111 void do_quitg ( char * u
);
112 void do_reset ( char * u
);
113 void do_run ( char * u
);
114 void do_stats ( char * u
);
115 void do_store ( char * u
);
116 void do_tavern ( char * u
);
117 void do_use ( char * u
);
118 void see_master ( char * u
);
120 void logout ( aClient
* user
);
121 void showstats ( const char * u
, const char * nick
);
122 void showinventory ( aClient
* from
, aClient
* to
);
123 void showBankBalance ( const char * u
);
124 void end_turn ( aClient
* user
);
127 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
128 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
129 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
130 "Light Saber" , "Masamune" , "Mystical Sword" };
132 char * armors
[ WNA
] = { "Birthday Suit" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
133 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
134 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
135 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
137 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
138 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
139 int webonus
[ WNA
] = { 2 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
140 int arbonus
[ WNA
] = { 2 , 3 , 5 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
142 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
143 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
144 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
146 void gameserv ( char * source
, char * buf
)
149 cmd
= strtok ( buf
, " " );
152 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
157 cmd
++; // Get rid of that : at the beginning of the :text (command)
160 log ( "Source: %s Command: %s " , source
, cmd
);
163 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
166 ts
= strtok ( NULL
, "\1" );
167 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
168 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
169 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
170 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
171 cmd
= strtok ( NULL
, " " );
174 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
178 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
180 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
182 } else if ( stricmp ( cmd
, "CHECK" ) == 0 ) {
184 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
186 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
188 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
190 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
191 do_inventory ( source
);
192 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
194 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
196 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
198 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
200 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
202 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
204 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
206 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
208 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
210 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
212 } else if ( stricmp ( cmd
, "NEWS" ) == 0 ) {
214 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
216 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
218 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
220 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
222 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
225 if (!( user
= find ( source
)))
227 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
228 log ( "Error: aClient not found: %s " , source
);
230 else if (! isAdmin ( user
))
232 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
238 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
240 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
244 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
247 if (!( user
= find ( source
)))
249 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
250 log ( "Error: aClient not found: %s " , source
);
252 else if (! isAdmin ( user
))
254 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
260 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
263 if (!( user
= find ( source
)))
265 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
266 log ( "Error: aClient not found: %s " , source
);
268 else if (! isAdmin ( user
))
270 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
274 char * cmd2
= strtok ( NULL
, " " );
277 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
280 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
282 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
286 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
, "" );
306 } else if ( stricmp ( cmd
, "PRINT" ) == 0 ) {
307 for ( int x
= 0 ; x
< LEVELS
; x
++)
308 levels
[ x
]. monsters
. print ();
309 } else if ( stricmp ( cmd
, "RANDOM" ) == 0 ) {
310 char * rstr
= strtok ( NULL
, "" );
312 trange
. setRange ( rstr
);
313 notice ( s_GameServ
, source
, "Random number in that range: %d " , trange
. random ());
317 if (( user
= find ( source
)))
322 log ( "Ignoring %s ." , user
-> getNick ());
327 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
333 source
--; // Bring the ':' back so we don't leak memory
336 cmd
--; // Same thing :)
339 int stricmp ( const char * s1
, const char * s2
)
343 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
349 if ( c
< tolower (* s2
))
354 void showstats ( const char * u
, const char * nick
)
356 aClient
* ni
, * sender
= find ( u
);
362 if (!( ni
= findplayer ( nick
)))
364 notice ( s_GameServ
, u
, " %s not found" , nick
);
368 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
370 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
371 space
= spaces ( strlen ( buf
), " " );
372 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
376 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
377 space
= spaces ( strlen ( buf
), " " );
378 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
381 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
384 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
385 space
= spaces ( strlen ( buf
), " " );
386 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
387 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
390 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
391 space
= spaces ( strlen ( buf
), " " );
392 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
393 weapons
[ ni
-> stats
-> weapon
]);
396 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
397 space
= spaces ( strlen ( buf
), " " );
398 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
400 Pouch
* inv
= & ni
-> stats
-> inventory
;
402 notice ( s_GameServ
, u
, "Potions" );
403 sprintf ( buf
, "Healing: %d " , inv
-> Healing ());
404 space
= spaces ( strlen ( buf
), " " );
405 notice ( s_GameServ
, sender
-> getNick (), " %s%s HP: %d " , buf
,
409 sprintf ( buf
, "Strength: %d " , inv
-> Strength ());
410 space
= spaces ( strlen ( buf
), " " );
411 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " , buf
,
412 space
, inv
-> Defense ());
417 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
422 char * spaces ( int len
, char * seperator
)
425 final
= new char [ 30 ];
427 strcpy ( final
, seperator
);
428 for ( y
= 0 ; y
< 30 - len
; y
++)
429 strcat ( final
, seperator
);
433 void raw ( const char * fmt
, ...)
438 input
= new char [ 1024 ];
440 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
446 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
447 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
448 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
451 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
456 sprintf ( input
, " %s%c " , input
, * t
);
461 log ( "Input: %s " , input
);
464 sprintf ( input
, " %s%s " , input
, " \r\n " );
465 sock_puts ( sock
, input
);
469 /* Send a NOTICE from the given source to the given nick. */
471 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
477 commanduse
= new char [ 16 ];
481 strcpy ( commanduse
, "P" );
483 strcpy ( commanduse
, "O" );
487 strcpy ( commanduse
, "PRIVMSG" );
489 strcpy ( commanduse
, "NOTICE" );
495 input
= new char [ 1024 ];
502 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
504 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
512 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
514 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
523 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
524 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
525 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
528 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
533 sprintf ( input
, " %s%c " , input
, * t
);
538 log ( "Input: %s " , input
);
540 sprintf ( input
, " %s%s " , input
, " \r\n " );
541 sock_puts ( sock
, input
);
542 delete [] commanduse
;
548 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
554 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
555 if ( c
== 0 || -- len
== 0 )
560 if ( c
< tolower (* s2
))
566 char * strtok ( char * str
, const char * delim
)
568 static char * current
= NULL
;
575 current
+= strspn ( current
, delim
);
576 ret
= * current
? current
: NULL
;
577 current
+= strcspn ( current
, delim
);
586 void do_check ( char * u
)
588 int days
, hours
, minutes
, seconds
;
590 complete
= ( lastrefresh
+ refreshperiod
) - time ( NULL
);
591 days
= complete
/ 86400 ;
592 hours
= ( complete
% 86400 ) / 3600 ;
593 minutes
= ( complete
% 86400 ) % 3600 / 60 ;
594 seconds
= ( complete
% 86400 ) % 3600 % 60 ;
596 notice ( s_GameServ
, u
, "Time left to next refresh: %d d %d h %d m %d s" ,
597 days
, hours
, minutes
, seconds
);
600 void do_list ( char * u
)
603 char * cmd
= strtok ( NULL
, " " );
605 if (!( user
= find ( u
)))
607 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
610 else if ( isIgnore ( user
))
613 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
618 ListNode
< aClient
> * temp
;
621 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
623 temp
= players
[ x
]. First ();
624 if (! players
[ x
]. isEmpty ())
628 if ( cmd
|| is_playing ( temp
-> getData ()))
632 notice ( s_GameServ
, u
, "Players:" );
636 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
637 temp
-> getData ()-> stats
-> name
);
639 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
640 temp
-> getData ()-> stats
-> name
);
649 notice ( s_GameServ
, u
, "No one is playing" );
651 notice ( s_GameServ
, u
, "End of List" );
655 void do_logout ( char * u
)
658 char * name
= strtok ( NULL
, " " );
660 if (!( user
= find ( u
)))
662 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
663 "Buf: %s LOGOUT" , u
);
664 log ( "Could not find aClient Buf: %s LOGOUT" ,
668 else if ( isIgnore ( user
))
671 log ( "Ignoring %s ." , user
-> getNick ());
680 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
682 else if (!( user
= findplayer ( name
)))
684 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
688 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
694 if (! is_playing ( user
))
696 notice ( s_GameServ
, u
, "You're not logged in!" );
698 else if ( is_fighting ( user
))
700 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
704 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
710 void logout ( aClient
* user
)
712 if ( is_playing ( user
))
714 ListNode
< aClient
> * it
;
716 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
717 it
= players
[ hv
]. Find ( user
);
721 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
722 " %S Admin. Cannot find you in the players list." );
723 log ( "Error on logout(). Can't find %s in the players list" ,
734 temp
-> stats
= new Player
;
735 temp
-> stats
-> setData ( user
-> stats
);
736 user
-> stats
-> client
= NULL
;
738 if ( player_fight ( user
))
739 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
743 temp
-> stats
-> client
= NULL
;
745 temp
-> setRealNick ( "Not Playing" );
747 temp
-> setNick ( "Not Playing" );
751 log ( "Logged out player %s " ,
763 void do_register ( char * u
)
765 char * password
, * name
;
767 name
= strtok ( NULL
, " " );
768 password
= strtok ( NULL
, " " );
770 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
773 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
774 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
779 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
783 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
785 else if (( user
= findplayer ( name
)))
787 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
788 notice ( s_GameServ
, u
, "Choose another name!" );
790 else if (!( user
= find ( u
)))
792 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
794 else if ( isIgnore ( user
))
797 log ( "Ignoring %s ." , user
-> getNick ());
803 if (! is_playing ( user
))
805 ListNode
< aClient
> * temp
;
806 user
-> stats
= new Player ( user
);
807 user
-> stats
-> client
= user
; // Set the backwards pointer
808 user
-> stats
-> reset (); // set the user up
809 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
810 strncpy ( user
-> stats
-> name
, name
, 255 );
811 unsigned long hv
= iHASH (( unsigned char *) name
);
812 updateTS ( user
-> stats
);
813 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
814 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
816 // Update the last login time
817 user
-> stats
-> lastlogin
= time ( NULL
);
819 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
820 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
821 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
822 setPlaying ( user
); // set the playing flag
826 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
831 void do_identify ( char * u
)
833 char * password
, * name
;
835 name
= strtok ( NULL
, " " );
836 password
= strtok ( NULL
, " " );
837 if (! password
|| ! name
)
839 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
841 else if (!( user
= find ( u
)))
843 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
844 log ( "Error: aClient not found: %s " , u
);
846 else if ( isIgnore ( user
))
849 log ( "Ignoring %s ." , user
-> getNick ());
853 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
854 notice ( s_GameServ
, u
, "Player %s not found" , name
);
855 else if ( is_playing ( user
))
857 notice ( s_GameServ
, u
, "You are already playing!" );
859 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
861 notice ( s_GameServ
, u
, "That player has already identified." );
863 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
865 notice ( s_GameServ
, u
, "Password incorrect" );
868 ListNode
< aClient
> * temp
;
869 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
870 temp
= players
[ hv
]. Find ( p
);
873 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
877 user
-> stats
= new Player ( p
-> stats
-> name
);
879 log ( "Setting data for identified" );
881 user
-> stats
-> setData ( p
-> stats
);
882 user
-> stats
-> client
= user
;
883 updateTS ( user
-> stats
);
887 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
891 setPlaying ( user
); // set the playing flag
895 // Update the last login time
896 user
-> stats
-> lastlogin
= time ( NULL
);
898 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
899 showNews ( u
, todaysnews
);
903 void do_stats ( char * u
)
908 nick
= strtok ( NULL
, " " );
910 if (!( user
= find ( u
)))
912 log ( "Fatal Error: %s not found in client list" , u
);
915 else if ( isIgnore ( user
))
918 log ( "Ignoring %s ." , user
-> getNick ());
924 if (! is_playing ( user
))
926 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
931 updateTS ( user
-> stats
);
932 showstats ( u
, user
-> stats
-> name
);
942 log ( "Calling delete_masters()" );
948 log ( "Initializing masters" );
951 for ( int x
= 0 ; x
< LEVELS
; x
++)
952 masters
[ x
] = new Monster
;
954 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
955 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
956 masters
[ 0 ]-> strength
= 32 ;
957 masters
[ 0 ]-> gold
= 0 ;
959 masters
[ 0 ]-> maxhp
= 35 ;
961 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!" );
963 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
964 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
965 masters
[ 1 ]-> strength
= 48 ;
966 masters
[ 1 ]-> gold
= 0 ;
968 masters
[ 1 ]-> maxhp
= 51 ;
970 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." );
972 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
973 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
974 masters
[ 2 ]-> strength
= 88 ;
975 masters
[ 2 ]-> gold
= 0 ;
977 masters
[ 2 ]-> maxhp
= 100 ;
978 masters
[ 2 ]-> hp
= 100 ;
979 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!" );
982 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
983 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
984 masters
[ 3 ]-> strength
= 169 ;
985 masters
[ 3 ]-> gold
= 0 ;
987 masters
[ 3 ]-> maxhp
= 165 ;
988 masters
[ 3 ]-> hp
= 165 ;
989 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
991 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
992 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
993 masters
[ 4 ]-> strength
= 275 ;
994 masters
[ 4 ]-> gold
= 0 ;
996 masters
[ 4 ]-> maxhp
= 232 ;
997 masters
[ 4 ]-> hp
= 232 ;
998 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!" );
1000 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
1001 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
1002 masters
[ 5 ]-> strength
= 347 ;
1003 masters
[ 5 ]-> gold
= 0 ;
1004 masters
[ 5 ]-> exp
= 0 ;
1005 masters
[ 5 ]-> maxhp
= 504 ;
1006 masters
[ 5 ]-> hp
= 504 ;
1007 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
1010 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
1011 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
1012 masters
[ 6 ]-> strength
= 515 ;
1013 masters
[ 6 ]-> gold
= 0 ;
1014 masters
[ 6 ]-> exp
= 0 ;
1015 masters
[ 6 ]-> maxhp
= 1078 ;
1016 masters
[ 6 ]-> hp
= 1078 ;
1017 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
1019 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
1020 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
1021 masters
[ 7 ]-> strength
= 655 ;
1022 masters
[ 7 ]-> gold
= 0 ;
1023 masters
[ 7 ]-> exp
= 0 ;
1024 masters
[ 7 ]-> maxhp
= 2207 ;
1025 masters
[ 7 ]-> hp
= 2207 ;
1026 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
1029 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
1030 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
1031 masters
[ 8 ]-> strength
= 819 ;
1032 masters
[ 8 ]-> gold
= 0 ;
1033 masters
[ 8 ]-> exp
= 0 ;
1034 masters
[ 8 ]-> maxhp
= 2780 ;
1035 masters
[ 8 ]-> hp
= 2780 ;
1036 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1038 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1039 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1040 masters
[ 9 ]-> strength
= 1014 ;
1041 masters
[ 9 ]-> gold
= 0 ;
1042 masters
[ 9 ]-> exp
= 0 ;
1043 masters
[ 9 ]-> maxhp
= 3046 ;
1044 masters
[ 9 ]-> hp
= 3046 ;
1045 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1047 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1048 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1049 masters
[ 10 ]-> strength
= 1286 ;
1050 masters
[ 10 ]-> gold
= 0 ;
1051 masters
[ 10 ]-> exp
= 0 ;
1052 masters
[ 10 ]-> maxhp
= 3988 ;
1053 masters
[ 10 ]-> hp
= 3988 ;
1054 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." );
1057 void delete_monsters ()
1059 for ( int x
= 0 ; x
< LEVELS
; x
++)
1060 levels
[ x
]. monsters
. deleteNodes ();
1063 void delete_masters ()
1065 for ( int x
= 0 ; x
< LEVELS
; x
++)
1070 void display_monster ( char * u
)
1074 aClient
* user
= find ( u
);
1075 Player
* ni
= user
-> stats
;
1077 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1078 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
1079 notice ( s_GameServ
, u
, "Here are your commands:" );
1080 notice ( s_GameServ
, u
, "/msg %S attack" );
1081 notice ( s_GameServ
, u
, "/msg %S run" );
1082 notice ( s_GameServ
, u
, "What will you do?" );
1086 void display_players ( char * u
)
1089 if (!( user
= find ( u
)))
1091 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1094 display_players ( user
);
1097 void display_players ( aClient
* user
)
1099 char * u
= user
-> getNick ();
1100 if ( is_playing ( user
) && player_fight ( user
))
1102 aClient
* battle
= user
-> stats
-> battle
;
1103 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1104 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
1105 notice ( s_GameServ
, u
, "Here are your commands:" );
1106 notice ( s_GameServ
, u
, "/msg %S attack" );
1107 notice ( s_GameServ
, u
, "/msg %S run" );
1108 notice ( s_GameServ
, u
, "What will you do?" );
1113 bool is_playing ( char * u
)
1116 if (!( user
= find ( u
)))
1119 return is_playing ( user
);
1122 bool is_playing ( aClient
* user
)
1124 if ( user
-> stats
== NULL
)
1128 else if ( user
-> stats
-> client
== NULL
)
1132 else if (! FL_is_playing ( user
))
1140 bool is_fighting ( char * u
)
1144 if (!( user
= find ( u
)))
1147 return is_fighting ( user
);
1150 bool is_fighting ( aClient
* user
)
1152 if (! is_playing ( user
))
1155 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1158 bool player_fight ( char * u
)
1162 if (!( user
= find ( u
)))
1165 return player_fight ( user
);
1168 bool player_fight ( aClient
* user
)
1170 if (! is_playing ( user
))
1172 else if ( user
-> stats
-> battle
!= NULL
)
1174 return user
-> stats
-> battle
-> stats
!= NULL
;
1179 bool master_fight ( char * u
)
1183 if (!( user
= find ( u
)))
1186 return master_fight ( user
);
1189 bool master_fight ( aClient
* user
)
1191 if (! is_playing ( user
))
1194 return user
-> stats
-> master
!= NULL
;
1197 void do_fight ( char * u
)
1199 aClient
* ni
, * battle
;
1201 char * nick
= strtok ( NULL
, " " );
1205 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1208 else if (!( ni
= find ( u
)))
1210 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1213 else if ( isIgnore ( ni
))
1216 log ( "Ignoring %s ." , ni
-> getNick ());
1220 else if (! is_playing ( ni
))
1222 notice ( s_GameServ
, u
, "You are not playing!" );
1226 updateTS ( ni
-> stats
);
1228 if ( ni
-> stats
-> player_fights
<= 0 )
1230 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1231 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1232 "day. You have to wait until tomorrow!" );
1234 else if (!( battle
= findplayer ( nick
)))
1236 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1238 else if (! isAlive ( ni
-> stats
))
1240 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1242 else if (! is_playing ( battle
))
1244 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1247 /* offline fighting not available yet
1248 else if (!(fight = finduser(nick)))
1250 ni->stats->battle = battle;
1251 battle->battle = ni;
1252 setYourTurn(ni->stats);
1253 clearYourTurn(battle->stats);
1255 notice(s_GameServ, u, "You decide to fight %s while they're "\
1256 "not in the realm!",
1257 battle->stats->name);
1261 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1263 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1265 else if (! isAlive ( battle
-> stats
))
1267 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1269 else if ( player_fight ( battle
))
1271 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1273 else if ( master_fight ( battle
))
1275 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
);
1277 else if ( is_fighting ( battle
))
1279 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1281 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1283 // You can't fight someone below you by more than X level(s)
1284 // level 12 can fight level (12 - X) but not < (12 - X)
1285 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1286 battle
-> stats
-> name
);
1288 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1290 // You can't fight someone above you by more than X level(S)
1291 // level 1 can fight level (1 + X), but not > (1 + X)
1292 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1293 "weakling!" , ni
-> stats
-> name
);
1297 // Set your battle pointer to the other player
1298 ni
-> stats
-> battle
= battle
;
1300 // Set the other player's battle pointer to you
1301 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1303 // The initiator gets the first move (perhaps this should be 50/50)
1304 setYourTurn ( ni
-> stats
);
1305 clearYourTurn ( battle
-> stats
);
1307 // Initiate Battle sequence!
1308 ni
-> stats
-> player_fights
-= 1 ;
1310 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1311 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1312 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1313 "because they initiated!" , ni
-> stats
-> name
);
1314 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1315 display_players ( ni
);
1319 void do_use ( char * u
)
1324 char * item
= strtok ( NULL
, " " );
1328 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1329 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1332 else if (!( user
= find ( u
)))
1334 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1337 else if ( isIgnore ( user
))
1340 log ( "Ignoring %s ." , user
-> getNick ());
1344 else if (! is_playing ( user
))
1346 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1350 updateTS ( user
-> stats
);
1352 p
= & user
-> stats
-> inventory
;
1354 if ( stricmp ( item
, "HEALING" ) == 0 )
1356 if ( p
-> Healing () <= 0 )
1358 notice ( s_GameServ
, u
, "You are out of Healing Potions!" );
1361 int oldhealing
= user
-> stats
-> hp
;
1362 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1363 if ( user
-> stats
-> hp
- user
-> stats
-> maxhp
>= 100 )
1365 user
-> stats
-> hp
= user
-> stats
-> maxhp
+ 100 ;
1367 if ( oldhealing
>= ( user
-> stats
-> maxhp
+ 100 ))
1369 notice ( s_GameServ
, u
, "You cannot hold anymore HP!" );
1374 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1375 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1376 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealing
);
1378 if ( player_fight ( user
))
1380 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1381 " %s has used a healing potion!" );
1384 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1386 if ( p
-> Strength () <= 0 )
1388 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1391 int oldstrength
= user
-> stats
-> strength
;
1392 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1393 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1394 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1395 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1397 if ( player_fight ( user
))
1399 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1400 " %s has used a strength potion!" );
1403 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1405 if ( p
-> Defense () <= 0 )
1407 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1410 int olddefense
= user
-> stats
-> defense
;
1411 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1412 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1413 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1414 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1416 if ( player_fight ( user
))
1418 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1419 " %s has used a defense potion!" );
1422 else if ( stricmp ( item
, "HP" ) == 0 )
1426 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1429 int oldHP
= user
-> stats
-> maxhp
;
1430 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1431 user
-> stats
-> maxhp
+= 2 +
1432 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1434 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1436 if ( player_fight ( user
))
1438 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1439 " %s has used a HP potion!" );
1444 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}" );
1448 end_turn ( user
); // If they're fighting, end their turn
1450 void do_run ( char * u
)
1453 Player
* p
, * p2
= NULL
;
1455 if (!( user
= find ( u
)))
1457 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1460 else if ( isIgnore ( user
))
1463 log ( "Ignoring %s ." , user
-> getNick ());
1467 else if (! is_playing ( user
))
1469 notice ( s_GameServ
, u
, "You must be playing to run!" );
1473 updateTS ( user
-> stats
);
1477 p2
= p
-> battle
-> stats
;
1479 if (! is_fighting ( user
))
1480 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1481 else if (! player_fight ( user
) && ! master_fight ( user
))
1483 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1487 else if ( player_fight ( user
) && isYourTurn ( p
))
1489 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1490 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1493 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1495 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1497 else if ( master_fight ( user
))
1499 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1504 void end_turn ( aClient
* user
)
1506 char * nick
, * u
= user
-> getNick ();
1511 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1513 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1516 if (! player_fight ( user
) && ! master_fight ( user
))
1517 fight
= user
-> stats
-> fight
;
1519 fight
= user
-> stats
-> master
;
1520 battle
= user
-> stats
-> battle
;
1522 if (! player_fight ( user
))
1525 mhit
= ( fight
-> strength
/ 2 ) +
1526 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1527 arbonus
[ user
-> stats
-> armor
]));
1532 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1533 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1534 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1536 if (! player_fight ( user
))
1541 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1542 fight
-> name
, fight
-> weapon
, mhit
);
1545 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1547 if ( mhit
>= user
-> stats
-> hp
)
1549 if (! master_fight ( user
))
1551 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1552 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1553 "of your experience!" );
1554 user
-> stats
-> gold
= 0 ;
1555 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1556 user
-> stats
-> hp
= 0 ;
1557 user
-> stats
-> fight
= NULL
;
1558 clearAlive ( user
-> stats
);
1563 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1564 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1565 user
-> stats
-> fight
= NULL
;
1566 user
-> stats
-> master
= NULL
;
1573 user
-> stats
-> hp
-= mhit
;
1580 clearYourTurn ( user
-> stats
);
1581 setYourTurn ( battle
-> stats
);
1582 display_players ( battle
);
1588 void do_attack ( char * u
)
1591 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1592 Monster
* fight
; // The monster they may be fighting
1594 if (!( ni
= find ( u
)))
1596 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1599 else if ( isIgnore ( ni
))
1602 log ( "Ignoring %s ." , ni
-> getNick ());
1606 else if (! is_playing ( ni
))
1608 notice ( s_GameServ
, u
, "You're not playing!" );
1611 else if (! is_fighting ( ni
))
1613 notice ( s_GameServ
, u
, "You're not in battle!" );
1618 if (! ni
-> stats
-> master
) // This is not a master fight
1619 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1620 else // This IS a master fight
1621 fight
= ni
-> stats
-> master
; // Master Could be NULL
1623 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1625 // One has to be !NULL based on the previous else if
1626 // We wouldn't be here if they were all NULL
1628 updateTS ( ni
-> stats
);
1630 if (! player_fight ( ni
))
1633 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1634 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1637 mhit
= ( fight
-> strength
/ 2 ) +
1638 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1639 arbonus
[ ni
-> stats
-> armor
]));
1644 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1645 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1646 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1649 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1650 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1651 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1654 if (! player_fight ( ni
))
1657 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1659 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1661 if ( hit
>= fight
-> hp
)
1663 if ( master_fight ( ni
))
1665 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1666 addNews ( todaysnews
, " %s has bested %s and moved " \
1667 "to level %d " , ni
-> stats
-> name
, fight
-> name
,
1668 ( ni
-> stats
-> level
+ 1 ));
1671 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1673 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1674 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1675 fight
-> exp
, fight
-> gold
);
1677 // If your new experience (or gold) will be greater than 2 billion,
1678 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1679 // This could be a problem with overflowing out of the sign bit.
1680 // Unsigned long int maybe? Leave it for now.
1681 ni
-> stats
-> exp
+= fight
-> exp
;
1682 if ( ni
-> stats
-> exp
< 0 || ni
-> stats
-> exp
> 2000000000 )
1683 ni
-> stats
-> exp
= 2000000000 ;
1685 ni
-> stats
-> gold
+= fight
-> gold
;
1686 if ( ni
-> stats
-> gold
< 0 || ni
-> stats
-> gold
> 2000000000 )
1687 ni
-> stats
-> gold
= 2000000000 ;
1689 if ( master_fight ( ni
))
1691 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1692 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1693 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1695 // Increase your level
1697 // Increase your maximum hit points
1698 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1700 // Heal the player by setting hp to their max
1701 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1703 // Add to your strength
1704 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1706 // Add to your defensive power
1707 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1711 // Clear the pointer for your master
1712 ni
-> stats
-> master
= NULL
;
1715 // They're dead so remove the pointer
1716 delete ni
-> stats
-> fight
;
1717 ni
-> stats
-> fight
= NULL
;
1718 ni
-> stats
-> master
= NULL
;
1728 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1729 fight
-> name
, fight
-> weapon
, mhit
);
1732 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1734 if ( mhit
>= ni
-> stats
-> hp
)
1736 if (! master_fight ( ni
))
1738 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1739 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1740 "of your experience!" );
1741 addNews ( todaysnews
, " %s has been killed by %s !" ,
1742 ni
-> stats
-> name
, fight
-> name
);
1743 ni
-> stats
-> gold
= 0 ;
1744 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1746 ni
-> stats
-> fight
= NULL
;
1747 clearAlive ( ni
-> stats
);
1752 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1753 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1754 addNews ( todaysnews
, " %s tried to best %s and failed!" ,
1755 ni
-> stats
-> name
, fight
-> name
);
1756 ni
-> stats
-> fight
= NULL
;
1757 ni
-> stats
-> master
= NULL
;
1764 ni
-> stats
-> hp
-= mhit
;
1770 else if ( player_fight ( ni
))
1772 /* Offline fighting not available yet
1773 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1776 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1778 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1779 if (hit >= battle->stats->hp)
1781 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1782 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1783 (long int)(battle->stats->exp * .10), battle->stats->gold);
1784 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1786 ni->stats->exp += (long int)(battle->stats->exp * .10);
1787 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1791 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1792 ni->stats->exp = 2000000000;
1795 if (2000000000 - ni->stats->gold > battle->stats->gold)
1797 * ni->stats->gold += battle->stats->gold;
1798 battle->stats->gold = 0;
1802 battle->stats->gold = 2000000000 - ni->stats->gold;
1803 ni->stats->gold = 2000000000;
1805 * ni->stats->battle->stats->alive = 0;
1806 ni->stats->battle->battle = NULL;
1807 ni->stats->battle = NULL;
1813 * battle->stats->hp -= hit;
1816 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1817 battle->nick, weapons[battle->stats->weapon], mhit);
1820 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1822 if (mhit >= ni->stats->hp)
1824 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1825 if (2000000000 - battle->stats->gold > ni->stats->gold)
1827 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1828 battle->stats->gold += ni->stats->gold;
1829 * ni->stats->gold = 0;
1833 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1835 ni->stats->gold -= (2000000000 - battle->stats->gold);
1836 notice(s_GameServ, u, "You were left dead with %d gold.",
1837 * (long int)ni->stats->gold);
1838 battle->stats->gold = 2000000000;
1840 ni->stats->battle->battle = NULL;
1841 ni->stats->battle = NULL;
1842 ni->stats->alive = 0;
1848 ni->stats->hp -= mhit;
1854 * end offline fighting */
1856 if ( is_playing ( battle
))
1858 if (! isYourTurn ( ni
-> stats
))
1860 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1861 battle
-> stats
-> name
);
1866 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1868 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1869 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1870 weapons
[ ni
-> stats
-> weapon
], hit
);
1874 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1875 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1878 if ( hit
>= battle
-> stats
-> hp
)
1880 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1881 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1882 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1883 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1885 battle
-> stats
-> hp
= 0 ;
1886 clearAlive ( battle
-> stats
);
1888 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1889 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1891 if ( ni
-> stats
-> exp
< 0 || ni
-> stats
-> exp
> 2000000000 )
1892 ni
-> stats
-> exp
= 2000000000 ;
1894 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1896 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1897 "all gold on hand!" );
1898 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1899 battle
-> stats
-> gold
= 0 ;
1903 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1904 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1906 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1907 "gold." , ni
-> stats
-> name
);
1909 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1910 "left. All is not lost!" , battle
-> stats
-> gold
);
1912 ni
-> stats
-> gold
= 2000000000 ;
1915 clearYourTurn ( ni
-> stats
);
1916 clearYourTurn ( battle
-> stats
);
1917 battle
-> stats
-> battle
= NULL
;
1918 ni
-> stats
-> battle
= NULL
;
1924 battle
-> stats
-> hp
-= hit
;
1925 clearYourTurn ( ni
-> stats
);
1926 setYourTurn ( battle
-> stats
);
1927 display_players ( battle
);
1928 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1929 battle
-> stats
-> name
);
1936 void do_heal ( char * u
)
1939 char * amount
= strtok ( NULL
, " " );
1944 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1947 else if (!( ni
= find ( u
)))
1949 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1952 else if ( isIgnore ( ni
))
1955 log ( "Ignoring %s ." , ni
-> getNick ());
1959 else if (! is_playing ( ni
))
1961 notice ( s_GameServ
, u
, "You aren't playing!" );
1964 else if (! isAlive ( ni
-> stats
))
1966 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1969 else if ( is_fighting ( ni
))
1971 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1974 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1976 notice ( s_GameServ
, u
, "You don't need healing!" );
1980 updateTS ( ni
-> stats
);
1981 if ( stricmp ( amount
, "ALL" ) == 0 )
1983 price
= ni
-> stats
-> level
* 3 ;
1984 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1986 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1987 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1988 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1989 ni
-> stats
-> gold
%= price
;
1993 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1994 "per point." , price
);
1995 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1996 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1997 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1998 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1999 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2002 else if ( isstringnum ( amount
))
2004 num
= stringtoint ( amount
);
2005 price
= ni
-> stats
-> level
* 3 ;
2006 if ( ni
-> stats
-> gold
< price
* num
)
2008 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
2009 ( long int ) ni
-> stats
-> gold
/ price
);
2011 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2013 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2015 ni
-> stats
-> hp
+= num
;
2016 ni
-> stats
-> gold
-= num
* price
;
2018 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2020 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2021 "per point." , price
);
2022 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2023 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
2024 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2025 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2028 else if ( amount
[ 0 ] == '-' )
2029 notice ( s_GameServ
, u
, "You trying to cheat?" );
2031 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2034 int isstringnum ( char * num
)
2037 for ( x
= 0 ; x
< strlen ( num
); x
++)
2039 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2045 long int stringtoint ( char * number
)
2047 long int x
, len
= strlen ( number
), sum
= 0 ;
2049 return chartoint ( number
[ 0 ]);
2050 sum
+= chartoint ( number
[ len
- 1 ]);
2051 for ( x
= len
- 2 ; x
>= 0 ; x
--)
2052 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
2056 long int pow ( int x
, int y
)
2062 if ( x
!= 0 && y
!= 0 )
2064 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2072 long int chartoint ( char ch
)
2074 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2075 return int ( ch
) - 48 ;
2082 ListNode
< aClient
> * ptr
;
2086 outfile
. open ( playerdata
);
2090 log ( "Error opening %s " , playerdata
);
2094 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2096 ptr
= players
[ x
]. First ();
2099 it
= ptr
-> getData ()-> stats
;
2101 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2102 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2103 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2104 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2105 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2106 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP ()
2107 << ' ' << it
-> lastlogin
<< endl
;
2120 char * tempname
, * buf
, * password
;
2121 buf
= new char [ 1023 ];
2123 infile
. open ( playerdata
);
2127 log ( "Error opening %s " , playerdata
);
2131 for ( int x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2133 ListNode
< aClient
> * tempNode
;
2134 tempNode
= players
[ x
]. First ();
2137 if ( tempNode
-> getData ()-> stats
-> client
)
2138 logout ( tempNode
-> getData ()-> stats
-> client
);
2139 tempNode
= tempNode
-> Next ();
2141 players
[ x
]. deleteNodes ();
2144 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2147 tempname
= strtok ( buf
, " " );
2148 temp
-> stats
= new Player ( tempname
);
2151 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2152 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2153 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2154 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2155 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2156 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2157 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2158 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2159 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2160 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2161 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2162 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2163 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2165 password
= strtok ( NULL
, " " );
2166 strcpy ( p
-> password
, password
);
2167 temp
-> setNick ( "Not Playing" );
2169 temp
-> setRealNick ( "Not Playing" );
2172 p
-> inventory
. reset (); // Set inventory to all 0s
2173 // Old player databases didn't have these three extra values
2174 // If they come up null, leave them to 0 as the default.
2175 // On the next gameserv database save, it will save the values.
2176 tempname
= strtok ( NULL
, " " );
2178 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2180 tempname
= strtok ( NULL
, " " );
2182 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2184 tempname
= strtok ( NULL
, " " );
2186 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2188 tempname
= strtok ( NULL
, " " );
2190 p
-> inventory
. setHP ( stringtoint ( tempname
));
2192 tempname
= strtok ( NULL
, " " );
2194 p
-> lastlogin
= stringtoint ( tempname
);
2196 p
-> lastlogin
= time ( NULL
);
2198 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2200 temp
-> stats
-> client
= NULL
;
2201 players
[ hv
]. insertAtBack ( temp
);
2209 bool passcmp ( char * encrypted
, char * plaintext
)
2212 char * plaintext2
, * plainToencrypt
;
2215 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2216 strcpy ( plaintext2
, plaintext
);
2218 salt
[ 0 ] = encrypted
[ 0 ];
2219 salt
[ 1 ] = encrypted
[ 1 ];
2222 plainToencrypt
= crypt ( plaintext2
, salt
);
2224 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2226 delete [] plaintext2
;
2231 bool check_password ( char * name
, char * plaintext
)
2235 if (!( client
= findplayer ( name
)))
2239 return passcmp ( client
-> stats
-> password
, plaintext
);
2243 void do_store ( char * u
)
2245 char * cmd
= strtok ( NULL
, " " );
2246 char * item
= strtok ( NULL
, " " );
2247 char * num
= strtok ( NULL
, " " );
2255 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2256 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2257 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2260 else if (!( user
= find ( u
)))
2262 log ( "Fatal Error: could not find %s in client list" , u
);
2265 else if ( isIgnore ( user
))
2268 log ( "Ignoring %s ." , user
-> getNick ());
2272 else if (! is_playing ( user
))
2274 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2277 else if (! isAlive ( user
-> stats
))
2279 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2282 updateTS ( user
-> stats
);
2284 if ( stricmp ( cmd
, "LIST" ) == 0 )
2286 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2288 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2289 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2290 for ( int x
= 1 ; x
< WNA
; x
++)
2292 space
= spaces ( strlen ( weapons
[ x
]), "." );
2293 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2296 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2297 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2300 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2302 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2303 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2304 for ( int x
= 1 ; x
< WNA
; x
++)
2306 space
= spaces ( strlen ( armors
[ x
]), "." );
2307 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2310 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2311 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2315 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2318 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2321 else if (! isstringnum ( num
))
2323 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2326 if ( stricmp ( item
, "WEAPON" ) == 0 )
2328 wep
= stringtoint ( num
);
2329 if ( wep
>= WNA
|| wep
< 1 )
2331 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2338 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2339 else if ( p
-> gold
< prices
[ wep
- 1 ])
2340 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2343 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2345 p
-> gold
-= prices
[ wep
- 1 ];
2348 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2350 wep
= stringtoint ( num
);
2351 if ( wep
>= WNA
|| wep
< 1 )
2353 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2360 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2361 else if ( p
-> gold
< prices
[ wep
- 1 ])
2362 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2365 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2367 p
-> gold
-= prices
[ wep
- 1 ];
2371 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2375 if ( stricmp ( item
, "WEAPON" ) == 0 )
2379 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2382 else if ( p
-> gold
== 2000000000 )
2384 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2387 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2389 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2390 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2391 p
-> gold
= 2000000000 ;
2396 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2397 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2401 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2407 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2410 if ( p
-> gold
== 2000000000 )
2412 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2415 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2417 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2418 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2419 p
-> gold
= 2000000000 ;
2424 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2425 ( prices
[ p
-> armor
- 1 ] / 2 ));
2427 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2433 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2434 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2435 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2440 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2441 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2442 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2446 void do_inventory ( char * u
)
2450 if (!( user
= find ( u
)))
2452 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2455 else if ( isIgnore ( user
))
2458 log ( "Ignoring %s ." , user
-> getNick ());
2462 else if (! is_playing ( user
))
2464 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2467 updateTS ( user
-> stats
);
2468 showinventory ( user
, user
);
2470 void showinventory ( aClient
* from
, aClient
* to
)
2472 char * nick
= to
-> getNick ();
2476 if ( is_playing ( from
))
2478 Pouch
* p
= & from
-> stats
-> inventory
;
2479 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2480 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2481 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2482 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2483 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2486 void do_tavern ( char * u
)
2488 char * cmd
= strtok ( NULL
, " " );
2494 if (!( user
= find ( u
)))
2496 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2499 else if ( isIgnore ( user
))
2502 log ( "Ignoring %s ." , user
-> getNick ());
2506 else if (! is_playing ( user
))
2508 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2511 else if ( is_fighting ( user
))
2513 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2517 updateTS ( user
-> stats
);
2522 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2523 notice ( s_GameServ
, u
, "Your commands:" );
2524 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2525 notice ( s_GameServ
, u
, "What'll it be?" );
2527 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2529 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2530 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2531 1000 * p
-> level
* 4 );
2532 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2533 2500 * p
-> level
* 4 );
2534 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2535 3000 * p
-> level
* 4 );
2536 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2537 2000 * p
-> level
* 4 );
2538 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2539 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2541 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2543 char * chnum
= strtok ( NULL
, " " );
2547 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2548 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2551 int num
= stringtoint ( chnum
);
2553 if ( num
< 1 || num
> 4 )
2555 notice ( s_GameServ
, u
, "Invalid Choice!" );
2556 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2557 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2558 1000 * p
-> level
* 4 );
2559 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2560 2500 * p
-> level
* 4 );
2561 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2562 3000 * p
-> level
* 4 );
2563 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2564 2000 * p
-> level
* 4 );
2565 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2566 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2572 price
= ( 1000 * p
-> level
* 4 );
2573 if ( p
-> gold
>= price
)
2575 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2576 p
-> inventory
. incHealing ();
2580 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2583 price
= 2500 * p
-> level
* 4 ;
2584 if ( p
-> gold
>= price
)
2586 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2587 p
-> inventory
. incStrength ();
2591 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2594 price
= 3000 * p
-> level
* 4 ;
2595 if ( p
-> gold
>= price
)
2597 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2598 p
-> inventory
. incDefense ();
2602 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2605 price
= 2000 * p
-> level
* 4 ;
2606 if ( p
-> gold
>= price
)
2608 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2609 p
-> inventory
. incHP ();
2613 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2616 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2622 notice ( s_GameServ
, u
, "Improper Syntax." );
2623 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2627 void do_bank ( char * u
)
2629 char * cmd
= strtok ( NULL
, " " );
2630 char * amount
= strtok ( NULL
, " " );
2631 char * nick
= strtok ( NULL
, " " );
2636 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2638 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2639 notice ( s_GameServ
, u
, "BANK BALANCE" );
2642 else if (!( user
= find ( u
)))
2644 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2646 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2649 else if ( isIgnore ( user
))
2652 log ( "Ignoring %s ." , user
-> getNick ());
2656 else if (! is_playing ( user
))
2658 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2661 else if ( is_fighting ( user
))
2663 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2666 updateTS ( user
-> stats
);
2667 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2672 else if (! isAlive ( user
-> stats
))
2674 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2677 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2679 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2682 if ( stringtoint ( amount
) < 0 )
2684 notice ( s_GameServ
, u
, "Sorry. This bank is not licensed " \
2685 "to handle such sums of cash, noble Lord." );
2690 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2692 if ( p
-> bank
== 2000000000 )
2694 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2697 else if ( stricmp ( amount
, "ALL" ) == 0 )
2699 if ( 2000000000 - p
-> bank
< p
-> gold
)
2701 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2702 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2703 p
-> gold
-= ( 2000000000 - p
-> bank
);
2704 p
-> bank
= 2000000000 ;
2709 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2715 else if ( stringtoint ( amount
) > p
-> gold
)
2717 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2723 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2725 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2726 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2727 p
-> gold
-= ( 2000000000 - p
-> bank
);
2728 p
-> bank
= 2000000000 ;
2733 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2734 p
-> bank
+= stringtoint ( amount
);
2735 p
-> gold
-= stringtoint ( amount
);
2740 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2742 if ( p
-> gold
== 2000000000 )
2744 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2748 else if ( stricmp ( amount
, "ALL" ) == 0 )
2750 if ( 2000000000 - p
-> gold
< p
-> bank
)
2752 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2753 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2754 p
-> bank
-= ( 2000000000 - p
-> gold
);
2755 p
-> gold
= 2000000000 ;
2760 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2766 else if ( stringtoint ( amount
) > p
-> bank
)
2768 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2774 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2776 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2777 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2778 ( 2000000000 - p
-> gold
));
2779 p
-> bank
-= ( 2000000000 - p
-> gold
);
2780 p
-> gold
= 2000000000 ;
2785 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2786 p
-> gold
+= stringtoint ( amount
);
2787 p
-> bank
-= stringtoint ( amount
);
2795 void do_dragon ( char * u
)
2799 if (!( user
= find ( u
)))
2801 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2804 else if ( isIgnore ( user
))
2807 log ( "Ignoring %s ." , user
-> getNick ());
2811 else if (! is_playing ( user
))
2813 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2816 else if ( is_fighting ( user
))
2818 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2821 else if (! isAlive ( user
-> stats
))
2823 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2826 else if ( user
-> stats
-> level
< REALLEVELS
)
2828 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2829 "to vanquish any foe should DARE fight the dragon!" );
2830 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2831 "You are too weak. You must be Level %d !" , REALLEVELS
);
2835 updateTS ( user
-> stats
);
2837 Player
* p
= user
-> stats
;
2838 p
-> fight
= new Monster (& boss
);
2839 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2840 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2841 "deep, red fog rolls in. The air is filled with the " \
2842 "heated mist of deadly fire from beyond the cave " \
2844 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2845 "your %s , and venture into the hot, dark cave. " \
2846 "You are surprised at the angle of descent as you climb " \
2847 "lower and lower, deeper into the dragon's den." );
2848 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2849 "a tooth. It is a large tooth... bigger than your torso." \
2850 " Suddenly the darkness lifts from the gleam of an eye " \
2851 " staring into your soul! The eye is large... HUGE!" );
2852 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2853 "glare orange! The tooth is moving... but it is still too " \
2854 "dark for you to make out.... THE DRAGON! You see it!" );
2858 void do_master ( char * u
)
2863 if (!( user
= find ( u
)))
2865 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2868 else if ( isIgnore ( user
))
2871 log ( "Ignoring %s ." , user
-> getNick ());
2875 else if (! is_playing ( user
))
2877 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2880 else if ( is_fighting ( user
))
2882 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2885 else if (! isAlive ( user
-> stats
))
2887 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2891 updateTS ( user
-> stats
);
2893 char * cmd
= strtok ( NULL
, " " );
2894 Player
* p
= user
-> stats
;
2899 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2943 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
2947 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2953 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2957 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2965 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
));
2968 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2971 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
);
2973 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2979 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2983 void see_master ( char * u
)
2987 if (!( user
= find ( u
)))
2989 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2993 if (! is_fighting ( user
) && is_playing ( user
))
2995 Player
* p
= user
-> stats
;
2996 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2997 p
-> fight
= p
-> master
;
2998 display_monster ( u
); // Since master is the same structure, use this function
3002 void showBankBalance ( const char * u
)
3007 if (!( user
= find ( u
)))
3015 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
3021 ListNode
< aClient
> * it
;
3023 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3025 it
= players
[ x
]. First ();
3029 p
= it
-> getData ()-> stats
;
3036 void refresh ( Player
* p
)
3041 if ( p
-> hp
< p
-> maxhp
)
3043 p
-> forest_fights
= forestfights
;
3044 p
-> player_fights
= 3 ;
3049 void do_refresh ( char * u
)
3051 char * nick
= strtok ( NULL
, " " );
3054 if (!( user
= find ( u
)))
3056 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3057 log ( "Error: aClient not found: %s " , u
);
3060 else if ( isIgnore ( user
))
3063 log ( "Ignoring %s ." , user
-> getNick ());
3067 else if (! isAdmin ( user
))
3069 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3074 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3077 else if ( stricmp ( nick
, "ALL" ) == 0 )
3079 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3082 else if (( user
= findplayer ( nick
)))
3084 if ( is_playing ( user
))
3087 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3089 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3091 refresh ( user
-> stats
);
3096 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3098 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3104 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3112 ListNode
< aClient
> * it
;
3115 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3117 it
= players
[ x
]. First ();
3121 p
= it
-> getData ()-> stats
;
3128 void reset ( Player
* p
)
3131 myname
= new char [ strlen ( p
-> name
)];
3132 strcpy ( myname
, p
-> name
);
3137 strcpy ( p
-> name
, myname
);
3141 void updateTS ( Player
* p
)
3147 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3149 p
-> lastcommand
= time ( NULL
);
3151 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3156 bool timedOut ( Player
* p
)
3160 else if ( p
-> lastcommand
== 0 )
3164 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3171 void timeOutEvent ( Player
* p
)
3173 aClient
* user
= findplayer ( p
-> name
);
3175 if (! user
|| ! p
-> client
) // then they're not playing
3178 char * nick
= user
-> getNick ();
3180 if ( player_fight ( user
) && isYourTurn ( p
))
3182 // Check to see if they were the idler or if it was the other
3184 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3186 // This person's last command was given earlier,
3187 // so this person is the idler
3188 notice ( s_GameServ
, nick
, "You timed out " \
3189 "during a fight. You lose your turn!" );
3190 notice ( s_GameServ
, p
-> battle
-> getNick (),
3191 " %s hesitated for too long. Your move." , p
-> name
);
3193 setYourTurn ( p
-> battle
-> stats
);
3195 // Update the TS for both players to give them another
3196 // Chance to wake up, but if the other player doesn't
3197 // Attack now, they both get logged out.
3199 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3200 display_players ( p
-> battle
);
3205 notice ( s_GameServ
, p
-> battle
-> getNick (),
3206 "You and %s timed out at the same time." \
3207 " Don't fight if you're just going to " \
3208 "sit there!" , p
-> name
);
3209 notice ( s_GameServ
, user
-> getNick (),
3210 "You and %s timed out at the same time." \
3211 " Don't fight if you're just going to " \
3212 "sit there!" , p
-> battle
-> stats
-> name
);
3218 else if (! player_fight ( user
))
3220 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3222 // Place fun stuff here :)
3223 int randnum
= 1 + rand () % 100 ; // 1-100
3224 #define GSN(s) notice(s_GameServ, nick, s)
3225 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3229 // 35-100% of your gold goes pffft - kain
3230 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3232 GSN ( "You stop for a moment to rest on the " \
3233 "street corner. All of a sudden, you " \
3234 "are ambushed from all sides by a hoarde " \
3235 "of knife wielding thugs." );
3236 GSN2 ( "The thugs beat you into utter submission " \
3237 "and steal %d gold from you!" , stolen
);
3238 user
-> stats
-> gold
-= stolen
;
3240 else if ( randnum
>= 50 && randnum
< 75 )
3242 // 25-65% of your gold goes pffft - kain
3243 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3244 GSN ( "While dilly dallying around, you lose " \
3245 "your sense of time. Little did you know, " \
3246 "but thieves lifted your gold while you " \
3247 "weren't watching." );
3248 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3249 user
-> stats
-> gold
-= stolen
;
3251 else if ( randnum
>= 75 )
3253 // 25-75% of your gold goes pffft - kain
3254 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3255 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3256 "goblins grabbed your gold!" );
3257 GSN2 ( "They stole %d gold from you!" , stolen
);
3258 user
-> stats
-> gold
-= stolen
;
3262 // Always log out the user
3267 void do_reset ( char * u
)
3269 char * nick
= strtok ( NULL
, " " );
3272 if (!( user
= find ( u
)))
3274 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3275 log ( "Error: aClient not found: %s " , u
);
3278 else if (! isAdmin ( user
))
3280 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3286 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3289 else if ( stricmp ( nick
, "ALL" ) == 0 )
3291 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3294 else if (( user
= findplayer ( nick
)))
3296 if ( is_playing ( user
))
3299 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3301 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3307 notice ( s_GameServ
, u
, "Resetting %s " , user
-> stats
-> name
);
3313 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3318 void do_help ( char * u
)
3320 char * cmd
= strtok ( NULL
, " " );
3322 display_help ( u
, cmd
);
3325 void display_help ( char * u
, char * file
)
3332 infile
. open ( "helpfiles/help" );
3335 log ( "Error opening helpfiles/help" );
3336 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3339 buf
= new char [ 1024 ];
3340 while ( infile
. getline ( buf
, 1024 ))
3342 // Written this way, it will process %S in the helpfiles
3343 // Instead of notice(s_GameServ, u, "%s", buf);
3344 notice ( s_GameServ
, u
, buf
);
3348 aClient
* user
= find ( u
);
3349 if ( user
&& isAdmin ( user
))
3350 display_help ( u
, "admin_commands" );
3355 filename
= new char [ strlen ( file
) + 11 ];
3356 strcpy ( filename
, "helpfiles/" );
3357 strcat ( filename
, file
);
3359 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3360 filename
[ x
] = tolower ( filename
[ x
]);
3362 infile
. open ( filename
);
3366 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3369 buf
= new char [ 1024 ];
3370 while ( infile
. getline ( buf
, 1024 ))
3372 // Written this way, it will process %S in the helpfiles
3373 // Instead of notice(s_GameServ, u, "%s", buf);
3374 notice ( s_GameServ
, u
, buf
);
3381 void do_admin ( char * u
)
3384 char * pass
= strtok ( NULL
, " " );
3386 if (!( user
= find ( u
)))
3388 log ( "Error: aClient not found: %s " , u
);
3389 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3395 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3401 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3404 else if ( strcmp ( pass
, adminpass
) == 0 )
3406 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3409 log ( " %s became an administrator." , user
-> getRealNick ());
3411 log ( " %s became an administrator." , user
-> getNick ());
3416 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3424 filename
= new char [ 256 ];
3426 for ( int x
= 1 ; x
<= LEVELS
; x
++)
3428 sprintf ( filename
, "data/levels/level %d .dat" , x
);
3429 if ( levels
[ x
- 1 ]. loadLevel ( filename
) == false )
3436 bool load_monsters ()
3441 buf
= new char [ 2048 ];
3443 for ( int level
= 1 ; level
<= LEVELS
; level
++)
3445 filename
= new char [ 256 ];
3446 sprintf ( filename
, "data/monsters/level %d .dat" , level
);
3447 infile
. open ( filename
);
3451 log ( "Error opening %s " , filename
);
3456 log ( "Loading monsters from %s " , filename
);
3459 while ( infile
. getline ( buf
, 2048 ))
3463 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3468 strcpy ( temp
-> name
, strtok ( buf
, "~" ));
3469 strcpy ( temp
-> weapon
, strtok ( NULL
, "~" ));
3471 temp->strength = stringtoint(strtok(NULL, "~"));
3472 temp->gold = stringtoint(strtok(NULL, "~"));
3473 temp->exp = stringtoint(strtok(NULL, "~"));
3474 temp->maxhp = stringtoint(strtok(NULL, "~"));
3475 temp->hp = temp->maxhp;
3477 strcpy ( temp
-> death
, strtok ( NULL
, "~" ));
3479 levels
[ level
- 1 ]. monsters
. insertAtBack_RLN ( temp
);