]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
15 #if defined(HAVE_CRYPT_H)
19 #elif defined(HAVE_UNISTD_H)
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
);
44 /********** Password functions **********/
46 bool passcmp ( char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
48 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
50 /********** Password functions **********/
53 /********** GameServ Booleans **********/
56 bool timedOut ( Player
* p
);
57 void updateTS ( Player
* p
);
58 void timeOutEvent ( Player
* p
);
60 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
61 bool is_playing ( aClient
* user
);
63 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
64 bool is_fighting ( aClient
* user
);
66 bool player_fight ( char * u
); // True if the player is fighting another player.
67 bool player_fight ( aClient
* user
);
69 bool master_fight ( char * u
); // True if the player is fighting their master.
70 bool master_fight ( aClient
* user
);
72 /********** GameServ Booleans **********/
74 void display_help ( char * u
, char * file
= NULL
);
75 void display_monster ( char * u
);
76 void display_players ( char * u
);
77 void display_players ( aClient
* user
);
78 long int chartoint ( char ch
);
79 int isstringnum ( char * num
);
80 long int pow ( int x
, int y
);
81 long int stringtoint ( char * number
);
83 char * spaces ( int len
, char * seperator
);
84 void refresh ( Player
* p
);
86 void updateTS ( Player
* p
);
87 void reset ( Player
* p
);
91 void delete_monsters ();
92 void delete_masters ();
94 void do_admin ( char * u
);
95 void do_attack ( char * u
);
96 void do_bank ( char * u
);
97 void do_fight ( char * u
);
98 void do_heal ( char * u
);
99 void do_help ( char * u
);
100 void do_identify ( char * u
);
101 void do_inventory ( char * u
);
102 void do_refresh ( char * u
);
103 void do_register ( char * u
);
104 void do_list ( char * u
);
105 void do_logout ( char * u
);
106 void do_master ( char * u
);
107 void do_dragon ( char * u
);
108 void do_play ( char * u
);
109 void do_quitg ( char * u
);
110 void do_reset ( char * u
);
111 void do_run ( char * u
);
112 void do_stats ( char * u
);
113 void do_store ( char * u
);
114 void do_tavern ( char * u
);
115 void do_use ( char * u
);
116 void see_master ( char * u
);
118 void logout ( aClient
* user
);
119 void showstats ( const char * u
, const char * nick
);
120 void showinventory ( aClient
* from
, aClient
* to
);
121 void showBankBalance ( const char * u
);
122 void end_turn ( aClient
* user
);
125 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
126 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
127 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
128 "Light Saber" , "Masamune" , "Mystical Sword" };
130 char * armors
[ WNA
] = { "Birthday Suit" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
131 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
132 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
133 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
135 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
136 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
137 int webonus
[ WNA
] = { 2 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
138 int arbonus
[ WNA
] = { 2 , 3 , 5 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
140 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
141 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
142 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
144 void gameserv ( char * source
, char * buf
)
147 cmd
= strtok ( buf
, " " );
150 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
155 cmd
++; // Get rid of that : at the beginning of the :text (command)
158 log ( "Source: %s Command: %s " , source
, cmd
);
166 int curday
= tm
-> tm_mday
;
171 clearNews ( todaysnews
);
172 saveNews ( newsdata
, todaysnews
);
174 save_day (); // here i come to save the day!
177 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
180 ts
= strtok ( NULL
, "\1" );
181 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
182 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
183 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
184 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
185 cmd
= strtok ( NULL
, " " );
188 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
192 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
194 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
196 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
198 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
200 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
202 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
203 do_inventory ( source
);
204 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
206 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
208 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
210 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
212 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
214 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
216 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
218 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
220 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
222 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
224 } else if ( stricmp ( cmd
, "NEWS" ) == 0 ) {
226 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
228 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
230 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
232 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
234 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
237 if (!( user
= find ( source
)))
239 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
240 log ( "Error: aClient not found: %s " , source
);
242 else if (! isAdmin ( user
))
244 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
250 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
252 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
256 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
259 if (!( user
= find ( source
)))
261 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
262 log ( "Error: aClient not found: %s " , source
);
264 else if (! isAdmin ( user
))
266 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
272 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
275 if (!( user
= find ( source
)))
277 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
278 log ( "Error: aClient not found: %s " , source
);
280 else if (! isAdmin ( user
))
282 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
286 char * cmd2
= strtok ( NULL
, " " );
289 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
292 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
294 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
298 display_help ( source
, cmd
);
301 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
304 if (!( user
= find ( source
)))
306 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
307 log ( "Error: aClient not found: %s " , source
);
309 else if (! isAdmin ( user
))
311 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
315 char * rest
= strtok ( NULL
, "" );
321 if (( user
= find ( source
)))
326 log ( "Ignoring %s ." , user
-> getNick ());
331 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
337 source
--; // Bring the ':' back so we don't leak memory
340 cmd
--; // Same thing :)
343 int stricmp ( const char * s1
, const char * s2
)
347 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
353 if ( c
< tolower (* s2
))
358 void showstats ( const char * u
, const char * nick
)
360 aClient
* ni
, * sender
= find ( u
);
366 if (!( ni
= findplayer ( nick
)))
368 notice ( s_GameServ
, u
, " %s not found" , nick
);
372 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
374 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
375 space
= spaces ( strlen ( buf
), " " );
376 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
380 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
381 space
= spaces ( strlen ( buf
), " " );
382 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
385 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
388 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
389 space
= spaces ( strlen ( buf
), " " );
390 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
391 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
394 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
395 space
= spaces ( strlen ( buf
), " " );
396 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
397 weapons
[ ni
-> stats
-> weapon
]);
400 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
401 space
= spaces ( strlen ( buf
), " " );
402 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
404 Pouch
* inv
= & ni
-> stats
-> inventory
;
406 notice ( s_GameServ
, u
, "Potions" );
407 sprintf ( buf
, "Healing: %d " , inv
-> Healing ());
408 space
= spaces ( strlen ( buf
), " " );
409 notice ( s_GameServ
, sender
-> getNick (), " %s%s HP: %d " , buf
,
413 sprintf ( buf
, "Strength: %d " , inv
-> Strength ());
414 space
= spaces ( strlen ( buf
), " " );
415 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " , buf
,
416 space
, inv
-> Defense ());
421 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
426 char * spaces ( int len
, char * seperator
)
429 final
= new char [ 30 ];
431 strcpy ( final
, seperator
);
432 for ( y
= 0 ; y
< 30 - len
; y
++)
433 strcat ( final
, seperator
);
437 void raw ( const char * fmt
, ...)
442 input
= new char [ 1024 ];
444 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
450 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
451 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
452 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
455 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
460 sprintf ( input
, " %s%c " , input
, * t
);
465 log ( "Input: %s " , input
);
468 sprintf ( input
, " %s%s " , input
, " \r\n " );
469 sock_puts ( sock
, input
);
473 /* Send a NOTICE from the given source to the given nick. */
475 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
481 commanduse
= new char [ 16 ];
485 strcpy ( commanduse
, "P" );
487 strcpy ( commanduse
, "O" );
491 strcpy ( commanduse
, "PRIVMSG" );
493 strcpy ( commanduse
, "NOTICE" );
499 input
= new char [ 1024 ];
506 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
508 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
516 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
518 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
527 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
528 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
529 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
532 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
537 sprintf ( input
, " %s%c " , input
, * t
);
542 log ( "Input: %s " , input
);
544 sprintf ( input
, " %s%s " , input
, " \r\n " );
545 sock_puts ( sock
, input
);
546 delete [] commanduse
;
552 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
558 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
559 if ( c
== 0 || -- len
== 0 )
564 if ( c
< tolower (* s2
))
570 char * strtok ( char * str
, const char * delim
)
572 static char * current
= NULL
;
579 current
+= strspn ( current
, delim
);
580 ret
= * current
? current
: NULL
;
581 current
+= strcspn ( current
, delim
);
590 void do_list ( char * u
)
593 char * cmd
= strtok ( NULL
, " " );
595 if (!( user
= find ( u
)))
597 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
600 else if ( isIgnore ( user
))
603 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
608 ListNode
< aClient
> * temp
;
611 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
613 temp
= players
[ x
]. First ();
614 if (! players
[ x
]. isEmpty ())
618 if (! cmd
|| is_playing ( temp
-> getData ()))
622 notice ( s_GameServ
, u
, "Players:" );
626 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
627 temp
-> getData ()-> stats
-> name
);
629 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
630 temp
-> getData ()-> stats
-> name
);
639 notice ( s_GameServ
, u
, "No one is playing" );
641 notice ( s_GameServ
, u
, "End of List" );
645 void do_logout ( char * u
)
648 char * name
= strtok ( NULL
, " " );
650 if (!( user
= find ( u
)))
652 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
653 "Buf: %s LOGOUT" , u
);
654 log ( "Could not find aClient Buf: %s LOGOUT" ,
658 else if ( isIgnore ( user
))
661 log ( "Ignoring %s ." , user
-> getNick ());
670 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
672 else if (!( user
= findplayer ( name
)))
674 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
678 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
684 if (! is_playing ( user
))
686 notice ( s_GameServ
, u
, "You're not logged in!" );
688 else if ( is_fighting ( user
))
690 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
694 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
700 void logout ( aClient
* user
)
702 if ( is_playing ( user
))
704 ListNode
< aClient
> * it
;
706 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
707 it
= players
[ hv
]. Find ( user
);
711 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
712 " %S Admin. Cannot find you in the players list." );
713 log ( "Error on logout(). Can't find %s in the players list" ,
724 temp
-> stats
= new Player
;
725 temp
-> stats
-> setData ( user
-> stats
);
726 user
-> stats
-> client
= NULL
;
728 if ( player_fight ( user
))
729 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
733 temp
-> stats
-> client
= NULL
;
735 temp
-> setRealNick ( "Not Playing" );
737 temp
-> setNick ( "Not Playing" );
741 log ( "Logged out player %s " ,
753 void do_register ( char * u
)
755 char * password
, * name
;
757 name
= strtok ( NULL
, " " );
758 password
= strtok ( NULL
, " " );
760 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
763 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
764 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
769 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
773 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
775 else if (( user
= findplayer ( name
)))
777 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
778 notice ( s_GameServ
, u
, "Choose another name!" );
780 else if (!( user
= find ( u
)))
782 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
784 else if ( isIgnore ( user
))
787 log ( "Ignoring %s ." , user
-> getNick ());
793 if (! is_playing ( user
))
795 ListNode
< aClient
> * temp
;
796 user
-> stats
= new Player ( user
);
797 user
-> stats
-> client
= user
; // Set the backwards pointer
798 user
-> stats
-> reset (); // set the user up
799 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
800 strncpy ( user
-> stats
-> name
, name
, 255 );
801 unsigned long hv
= iHASH (( unsigned char *) name
);
802 updateTS ( user
-> stats
);
803 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
804 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
806 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
807 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
808 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
809 setPlaying ( user
); // set the playing flag
813 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
818 void do_identify ( char * u
)
820 char * password
, * name
;
822 name
= strtok ( NULL
, " " );
823 password
= strtok ( NULL
, " " );
824 if (! password
|| ! name
)
826 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
828 else if (!( user
= find ( u
)))
830 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
831 log ( "Error: aClient not found: %s " , u
);
833 else if ( isIgnore ( user
))
836 log ( "Ignoring %s ." , user
-> getNick ());
840 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
841 notice ( s_GameServ
, u
, "Player %s not found" , name
);
842 else if ( is_playing ( user
))
844 notice ( s_GameServ
, u
, "You are already playing!" );
846 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
848 notice ( s_GameServ
, u
, "That player has already identified." );
850 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
852 notice ( s_GameServ
, u
, "Password incorrect" );
855 ListNode
< aClient
> * temp
;
856 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
857 temp
= players
[ hv
]. Find ( p
);
860 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
864 user
-> stats
= new Player ( p
-> stats
-> name
);
866 log ( "Setting data for identified" );
868 user
-> stats
-> setData ( p
-> stats
);
869 user
-> stats
-> client
= user
;
870 updateTS ( user
-> stats
);
874 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
878 setPlaying ( user
); // set the playing flag
881 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
882 showNews ( u
, todaysnews
);
886 void do_stats ( char * u
)
891 nick
= strtok ( NULL
, " " );
893 if (!( user
= find ( u
)))
895 log ( "Fatal Error: %s not found in client list" , u
);
898 else if ( isIgnore ( user
))
901 log ( "Ignoring %s ." , user
-> getNick ());
907 if (! is_playing ( user
))
909 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
914 updateTS ( user
-> stats
);
915 showstats ( u
, user
-> stats
-> name
);
925 log ( "Calling delete_masters()" );
931 log ( "Initializing masters" );
934 for ( int x
= 0 ; x
< LEVELS
; x
++)
935 masters
[ x
] = new Monster
;
937 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
938 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
939 masters
[ 0 ]-> strength
= 32 ;
940 masters
[ 0 ]-> gold
= 0 ;
942 masters
[ 0 ]-> maxhp
= 35 ;
944 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!" );
946 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
947 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
948 masters
[ 1 ]-> strength
= 48 ;
949 masters
[ 1 ]-> gold
= 0 ;
951 masters
[ 1 ]-> maxhp
= 51 ;
953 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." );
955 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
956 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
957 masters
[ 2 ]-> strength
= 88 ;
958 masters
[ 2 ]-> gold
= 0 ;
960 masters
[ 2 ]-> maxhp
= 100 ;
961 masters
[ 2 ]-> hp
= 100 ;
962 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!" );
965 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
966 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
967 masters
[ 3 ]-> strength
= 169 ;
968 masters
[ 3 ]-> gold
= 0 ;
970 masters
[ 3 ]-> maxhp
= 165 ;
971 masters
[ 3 ]-> hp
= 165 ;
972 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
974 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
975 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
976 masters
[ 4 ]-> strength
= 275 ;
977 masters
[ 4 ]-> gold
= 0 ;
979 masters
[ 4 ]-> maxhp
= 232 ;
980 masters
[ 4 ]-> hp
= 232 ;
981 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!" );
983 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
984 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
985 masters
[ 5 ]-> strength
= 347 ;
986 masters
[ 5 ]-> gold
= 0 ;
988 masters
[ 5 ]-> maxhp
= 504 ;
989 masters
[ 5 ]-> hp
= 504 ;
990 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
993 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
994 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
995 masters
[ 6 ]-> strength
= 515 ;
996 masters
[ 6 ]-> gold
= 0 ;
998 masters
[ 6 ]-> maxhp
= 1078 ;
999 masters
[ 6 ]-> hp
= 1078 ;
1000 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
1002 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
1003 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
1004 masters
[ 7 ]-> strength
= 655 ;
1005 masters
[ 7 ]-> gold
= 0 ;
1006 masters
[ 7 ]-> exp
= 0 ;
1007 masters
[ 7 ]-> maxhp
= 2207 ;
1008 masters
[ 7 ]-> hp
= 2207 ;
1009 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
1012 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
1013 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
1014 masters
[ 8 ]-> strength
= 819 ;
1015 masters
[ 8 ]-> gold
= 0 ;
1016 masters
[ 8 ]-> exp
= 0 ;
1017 masters
[ 8 ]-> maxhp
= 2780 ;
1018 masters
[ 8 ]-> hp
= 2780 ;
1019 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1021 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1022 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1023 masters
[ 9 ]-> strength
= 1014 ;
1024 masters
[ 9 ]-> gold
= 0 ;
1025 masters
[ 9 ]-> exp
= 0 ;
1026 masters
[ 9 ]-> maxhp
= 3046 ;
1027 masters
[ 9 ]-> hp
= 3046 ;
1028 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1030 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1031 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1032 masters
[ 10 ]-> strength
= 1286 ;
1033 masters
[ 10 ]-> gold
= 0 ;
1034 masters
[ 10 ]-> exp
= 0 ;
1035 masters
[ 10 ]-> maxhp
= 3988 ;
1036 masters
[ 10 ]-> hp
= 3988 ;
1037 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." );
1040 void init_monsters ()
1043 log ( "Calling delete_monsters" );
1048 for ( int x
= 0 ; x
< LEVELS
; x
++)
1049 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1050 monsters
[ x
][ y
] = new Monster ();
1053 void delete_monsters ()
1055 for ( int x
= 0 ; x
< LEVELS
; x
++)
1056 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1058 delete monsters
[ x
][ y
];
1061 void delete_masters ()
1063 for ( int x
= 0 ; x
< LEVELS
; x
++)
1068 void display_monster ( char * u
)
1072 aClient
* user
= find ( u
);
1073 Player
* ni
= user
-> stats
;
1075 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1076 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
1077 notice ( s_GameServ
, u
, "Here are your commands:" );
1078 notice ( s_GameServ
, u
, "/msg %S attack" );
1079 notice ( s_GameServ
, u
, "/msg %S run" );
1080 notice ( s_GameServ
, u
, "What will you do?" );
1084 void display_players ( char * u
)
1087 if (!( user
= find ( u
)))
1089 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1092 display_players ( user
);
1095 void display_players ( aClient
* user
)
1097 char * u
= user
-> getNick ();
1098 if ( is_playing ( user
) && player_fight ( user
))
1100 aClient
* battle
= user
-> stats
-> battle
;
1101 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1102 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
1103 notice ( s_GameServ
, u
, "Here are your commands:" );
1104 notice ( s_GameServ
, u
, "/msg %S attack" );
1105 notice ( s_GameServ
, u
, "/msg %S run" );
1106 notice ( s_GameServ
, u
, "What will you do?" );
1111 bool is_playing ( char * u
)
1114 if (!( user
= find ( u
)))
1117 return is_playing ( user
);
1120 bool is_playing ( aClient
* user
)
1122 if ( user
-> stats
== NULL
)
1126 else if ( user
-> stats
-> client
== NULL
)
1130 else if (! FL_is_playing ( user
))
1138 bool is_fighting ( char * u
)
1142 if (!( user
= find ( u
)))
1145 return is_fighting ( user
);
1148 bool is_fighting ( aClient
* user
)
1150 if (! is_playing ( user
))
1153 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1156 bool player_fight ( char * u
)
1160 if (!( user
= find ( u
)))
1163 return player_fight ( user
);
1166 bool player_fight ( aClient
* user
)
1168 if (! is_playing ( user
))
1170 else if ( user
-> stats
-> battle
!= NULL
)
1172 return user
-> stats
-> battle
-> stats
!= NULL
;
1177 bool master_fight ( char * u
)
1181 if (!( user
= find ( u
)))
1184 return master_fight ( user
);
1187 bool master_fight ( aClient
* user
)
1189 if (! is_playing ( user
))
1192 return user
-> stats
-> master
!= NULL
;
1195 void do_fight ( char * u
)
1197 aClient
* ni
, * battle
;
1199 char * nick
= strtok ( NULL
, " " );
1203 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1206 else if (!( ni
= find ( u
)))
1208 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1211 else if ( isIgnore ( ni
))
1214 log ( "Ignoring %s ." , ni
-> getNick ());
1218 else if (! is_playing ( ni
))
1220 notice ( s_GameServ
, u
, "You are not playing!" );
1224 updateTS ( ni
-> stats
);
1226 if ( ni
-> stats
-> player_fights
<= 0 )
1228 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1229 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1230 "day. You have to wait until tomorrow!" );
1232 else if (!( battle
= findplayer ( nick
)))
1234 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1236 else if (! isAlive ( ni
-> stats
))
1238 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1240 else if (! is_playing ( battle
))
1242 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1245 /* offline fighting not available yet
1246 else if (!(fight = finduser(nick)))
1248 ni->stats->battle = battle;
1249 battle->battle = ni;
1250 setYourTurn(ni->stats);
1251 clearYourTurn(battle->stats);
1253 notice(s_GameServ, u, "You decide to fight %s while they're "\
1254 "not in the realm!",
1255 battle->stats->name);
1259 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1261 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1263 else if (! isAlive ( battle
-> stats
))
1265 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1267 else if ( player_fight ( battle
))
1269 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1271 else if ( master_fight ( battle
))
1273 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
);
1275 else if ( is_fighting ( battle
))
1277 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1279 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1281 // You can't fight someone below you by more than X level(s)
1282 // level 12 can fight level (12 - X) but not < (12 - X)
1283 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1284 battle
-> stats
-> name
);
1286 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1288 // You can't fight someone above you by more than X level(S)
1289 // level 1 can fight level (1 + X), but not > (1 + X)
1290 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1291 "weakling!" , ni
-> stats
-> name
);
1295 // Set your battle pointer to the other player
1296 ni
-> stats
-> battle
= battle
;
1298 // Set the other player's battle pointer to you
1299 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1301 // The initiator gets the first move (perhaps this should be 50/50)
1302 setYourTurn ( ni
-> stats
);
1303 clearYourTurn ( battle
-> stats
);
1305 // Initiate Battle sequence!
1306 ni
-> stats
-> player_fights
-= 1 ;
1308 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1309 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1310 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1311 "because they initiated!" , ni
-> stats
-> name
);
1312 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1313 display_players ( ni
);
1317 void do_use ( char * u
)
1322 char * item
= strtok ( NULL
, " " );
1326 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1327 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1330 else if (!( user
= find ( u
)))
1332 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1335 else if ( isIgnore ( user
))
1338 log ( "Ignoring %s ." , user
-> getNick ());
1342 else if (! is_playing ( user
))
1344 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1348 updateTS ( user
-> stats
);
1350 p
= & user
-> stats
-> inventory
;
1352 if ( stricmp ( item
, "HEALING" ) == 0 )
1354 if ( p
-> Healing () <= 0 )
1356 notice ( s_GameServ
, u
, "You are out of Healing Potions!" );
1359 int oldhealing
= user
-> stats
-> hp
;
1360 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1361 if ( user
-> stats
-> hp
- user
-> stats
-> maxhp
>= 100 )
1363 user
-> stats
-> hp
= user
-> stats
-> maxhp
+ 100 ;
1365 if ( oldhealing
>= ( user
-> stats
-> maxhp
+ 100 ))
1367 notice ( s_GameServ
, u
, "You cannot hold anymore HP!" );
1372 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1373 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1374 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealing
);
1376 if ( player_fight ( user
))
1378 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1379 " %s has used a healing potion!" );
1382 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1384 if ( p
-> Strength () <= 0 )
1386 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1389 int oldstrength
= user
-> stats
-> strength
;
1390 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1391 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1392 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1393 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1395 if ( player_fight ( user
))
1397 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1398 " %s has used a strength potion!" );
1401 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1403 if ( p
-> Defense () <= 0 )
1405 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1408 int olddefense
= user
-> stats
-> defense
;
1409 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1410 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1411 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1412 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1414 if ( player_fight ( user
))
1416 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1417 " %s has used a defense potion!" );
1420 else if ( stricmp ( item
, "HP" ) == 0 )
1424 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1427 int oldHP
= user
-> stats
-> maxhp
;
1428 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1429 user
-> stats
-> maxhp
+= 2 +
1430 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1432 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1434 if ( player_fight ( user
))
1436 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1437 " %s has used a HP potion!" );
1442 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}" );
1446 end_turn ( user
); // If they're fighting, end their turn
1448 void do_run ( char * u
)
1451 Player
* p
, * p2
= NULL
;
1453 if (!( user
= find ( u
)))
1455 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1458 else if ( isIgnore ( user
))
1461 log ( "Ignoring %s ." , user
-> getNick ());
1465 else if (! is_playing ( user
))
1467 notice ( s_GameServ
, u
, "You must be playing to run!" );
1471 updateTS ( user
-> stats
);
1475 p2
= p
-> battle
-> stats
;
1477 if (! is_fighting ( user
))
1478 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1479 else if (! player_fight ( user
) && ! master_fight ( user
))
1481 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1485 else if ( player_fight ( user
) && isYourTurn ( p
))
1487 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1488 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1491 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1493 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1495 else if ( master_fight ( user
))
1497 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1502 void end_turn ( aClient
* user
)
1504 char * nick
, * u
= user
-> getNick ();
1509 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1511 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1514 if (! player_fight ( user
) && ! master_fight ( user
))
1515 fight
= user
-> stats
-> fight
;
1517 fight
= user
-> stats
-> master
;
1518 battle
= user
-> stats
-> battle
;
1520 if (! player_fight ( user
))
1523 mhit
= ( fight
-> strength
/ 2 ) +
1524 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1525 arbonus
[ user
-> stats
-> armor
]));
1530 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1531 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1532 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1534 if (! player_fight ( user
))
1539 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1540 fight
-> name
, fight
-> weapon
, mhit
);
1543 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1545 if ( mhit
>= user
-> stats
-> hp
)
1547 if (! master_fight ( user
))
1549 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1550 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1551 "of your experience!" );
1552 user
-> stats
-> gold
= 0 ;
1553 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1554 user
-> stats
-> hp
= 0 ;
1555 user
-> stats
-> fight
= NULL
;
1556 clearAlive ( user
-> stats
);
1561 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1562 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1563 user
-> stats
-> fight
= NULL
;
1564 user
-> stats
-> master
= NULL
;
1571 user
-> stats
-> hp
-= mhit
;
1578 clearYourTurn ( user
-> stats
);
1579 setYourTurn ( battle
-> stats
);
1580 display_players ( battle
);
1586 void do_attack ( char * u
)
1589 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1590 Monster
* fight
; // The monster they may be fighting
1592 if (!( ni
= find ( u
)))
1594 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1597 else if ( isIgnore ( ni
))
1600 log ( "Ignoring %s ." , ni
-> getNick ());
1604 else if (! is_playing ( ni
))
1606 notice ( s_GameServ
, u
, "You're not playing!" );
1609 else if (! is_fighting ( ni
))
1611 notice ( s_GameServ
, u
, "You're not in battle!" );
1616 if (! ni
-> stats
-> master
) // This is not a master fight
1617 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1618 else // This IS a master fight
1619 fight
= ni
-> stats
-> master
; // Master Could be NULL
1621 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1623 // One has to be !NULL based on the previous else if
1624 // We wouldn't be here if they were all NULL
1626 updateTS ( ni
-> stats
);
1628 if (! player_fight ( ni
))
1631 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1632 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1635 mhit
= ( fight
-> strength
/ 2 ) +
1636 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1637 arbonus
[ ni
-> stats
-> armor
]));
1642 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1643 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1644 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1647 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1648 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1649 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1652 if (! player_fight ( ni
))
1655 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1657 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1659 if ( hit
>= fight
-> hp
)
1661 if ( master_fight ( ni
))
1663 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1664 addNews ( todaysnews
, " %s has bested %s and moved " \
1665 "to level %d " , ni
-> stats
-> name
, fight
-> name
,
1666 ( ni
-> stats
-> level
+ 1 ));
1669 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1671 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1672 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1673 fight
-> exp
, fight
-> gold
);
1675 // If your new experience (or gold) will be greater than 2 billion,
1676 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1677 // This could be a problem with overflowing out of the sign bit.
1678 // Unsigned long int maybe? Leave it for now.
1679 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1680 ni
-> stats
-> exp
+ fight
-> exp
);
1682 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1683 ni
-> stats
-> gold
+ fight
-> gold
);
1686 if ( master_fight ( ni
))
1688 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1689 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1690 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1692 // Increase your level
1694 // Increase your maximum hit points
1695 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1697 // Heal the player by setting hp to their max
1698 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1700 // Add to your strength
1701 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1703 // Add to your defensive power
1704 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1708 // Clear the pointer for your master
1709 ni
-> stats
-> master
= NULL
;
1712 // They're dead so remove the pointer
1713 delete ni
-> stats
-> fight
;
1714 ni
-> stats
-> fight
= NULL
;
1715 ni
-> stats
-> master
= NULL
;
1725 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1726 fight
-> name
, fight
-> weapon
, mhit
);
1729 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1731 if ( mhit
>= ni
-> stats
-> hp
)
1733 if (! master_fight ( ni
))
1735 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1736 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1737 "of your experience!" );
1738 addNews ( todaysnews
, " %s has been killed by %s !" ,
1739 ni
-> stats
-> name
, fight
-> name
);
1740 ni
-> stats
-> gold
= 0 ;
1741 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1743 ni
-> stats
-> fight
= NULL
;
1744 clearAlive ( ni
-> stats
);
1749 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1750 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1751 addNews ( todaysnews
, " %s tried to best %s and failed!" ,
1752 ni
-> stats
-> name
, fight
-> name
);
1753 ni
-> stats
-> fight
= NULL
;
1754 ni
-> stats
-> master
= NULL
;
1761 ni
-> stats
-> hp
-= mhit
;
1767 else if ( player_fight ( ni
))
1769 /* Offline fighting not available yet
1770 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1773 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1775 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1776 if (hit >= battle->stats->hp)
1778 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1779 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1780 (long int)(battle->stats->exp * .10), battle->stats->gold);
1781 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1783 ni->stats->exp += (long int)(battle->stats->exp * .10);
1784 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1788 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1789 ni->stats->exp = 2000000000;
1792 if (2000000000 - ni->stats->gold > battle->stats->gold)
1794 * ni->stats->gold += battle->stats->gold;
1795 battle->stats->gold = 0;
1799 battle->stats->gold = 2000000000 - ni->stats->gold;
1800 ni->stats->gold = 2000000000;
1802 * ni->stats->battle->stats->alive = 0;
1803 ni->stats->battle->battle = NULL;
1804 ni->stats->battle = NULL;
1810 * battle->stats->hp -= hit;
1813 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1814 battle->nick, weapons[battle->stats->weapon], mhit);
1817 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1819 if (mhit >= ni->stats->hp)
1821 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1822 if (2000000000 - battle->stats->gold > ni->stats->gold)
1824 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1825 battle->stats->gold += ni->stats->gold;
1826 * ni->stats->gold = 0;
1830 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1832 ni->stats->gold -= (2000000000 - battle->stats->gold);
1833 notice(s_GameServ, u, "You were left dead with %d gold.",
1834 * (long int)ni->stats->gold);
1835 battle->stats->gold = 2000000000;
1837 ni->stats->battle->battle = NULL;
1838 ni->stats->battle = NULL;
1839 ni->stats->alive = 0;
1845 ni->stats->hp -= mhit;
1851 * end offline fighting */
1853 if ( is_playing ( battle
))
1855 if (! isYourTurn ( ni
-> stats
))
1857 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1858 battle
-> stats
-> name
);
1863 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1865 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1866 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1867 weapons
[ ni
-> stats
-> weapon
], hit
);
1871 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1872 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1875 if ( hit
>= battle
-> stats
-> hp
)
1877 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1878 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1879 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1880 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1882 battle
-> stats
-> hp
= 0 ;
1883 clearAlive ( battle
-> stats
);
1885 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1887 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1888 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1892 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1893 ni
-> stats
-> exp
= 2000000000 ;
1896 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1898 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1899 "all gold on hand!" );
1900 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1901 battle
-> stats
-> gold
= 0 ;
1905 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1906 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1908 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1909 "gold." , ni
-> stats
-> name
);
1911 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1912 "left. All is not lost!" , battle
-> stats
-> gold
);
1914 ni
-> stats
-> gold
= 2000000000 ;
1916 clearYourTurn ( ni
-> stats
);
1917 clearYourTurn ( battle
-> stats
);
1918 battle
-> stats
-> battle
= NULL
;
1919 ni
-> stats
-> battle
= NULL
;
1925 battle
-> stats
-> hp
-= hit
;
1926 clearYourTurn ( ni
-> stats
);
1927 setYourTurn ( battle
-> stats
);
1928 display_players ( battle
);
1929 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1930 battle
-> stats
-> name
);
1937 void do_heal ( char * u
)
1940 char * amount
= strtok ( NULL
, " " );
1945 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1948 else if (!( ni
= find ( u
)))
1950 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1953 else if ( isIgnore ( ni
))
1956 log ( "Ignoring %s ." , ni
-> getNick ());
1960 else if (! is_playing ( ni
))
1962 notice ( s_GameServ
, u
, "You aren't playing!" );
1965 else if (! isAlive ( ni
-> stats
))
1967 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1970 else if ( is_fighting ( ni
))
1972 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1975 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1977 notice ( s_GameServ
, u
, "You don't need healing!" );
1981 updateTS ( ni
-> stats
);
1982 if ( stricmp ( amount
, "ALL" ) == 0 )
1984 price
= ni
-> stats
-> level
* 3 ;
1985 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1987 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1988 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1989 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1990 ni
-> stats
-> gold
%= price
;
1994 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1995 "per point." , price
);
1996 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1997 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1998 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1999 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2000 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2003 else if ( isstringnum ( amount
))
2005 num
= stringtoint ( amount
);
2006 price
= ni
-> stats
-> level
* 3 ;
2007 if ( ni
-> stats
-> gold
< price
* num
)
2009 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
2010 ( long int ) ni
-> stats
-> gold
/ price
);
2012 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2014 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2016 ni
-> stats
-> hp
+= num
;
2017 ni
-> stats
-> gold
-= num
* price
;
2019 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2021 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2022 "per point." , price
);
2023 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2024 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
2025 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2026 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2029 else if ( amount
[ 0 ] == '-' )
2030 notice ( s_GameServ
, u
, "You trying to cheat?" );
2032 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2035 int isstringnum ( char * num
)
2038 for ( x
= 0 ; x
< strlen ( num
); x
++)
2040 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2046 long int stringtoint ( char * number
)
2048 long int x
, len
= strlen ( number
), sum
= 0 ;
2050 return chartoint ( number
[ 0 ]);
2051 sum
+= chartoint ( number
[ len
- 1 ]);
2052 for ( x
= len
- 2 ; x
>= 0 ; x
--)
2053 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
2057 long int pow ( int x
, int y
)
2063 if ( x
!= 0 && y
!= 0 )
2065 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2073 long int chartoint ( char ch
)
2075 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2076 return int ( ch
) - 48 ;
2083 ListNode
< aClient
> * ptr
;
2087 outfile
. open ( playerdata
);
2091 log ( "Error opening %s " , playerdata
);
2095 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2097 ptr
= players
[ x
]. First ();
2100 it
= ptr
-> getData ()-> stats
;
2102 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2103 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2104 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2105 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2106 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2107 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
2120 char * tempname
, * buf
, * password
;
2121 buf
= new char [ 1023 ];
2123 infile
. open ( playerdata
);
2127 log ( "Error opening %s " , playerdata
);
2131 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2134 tempname
= strtok ( buf
, " " );
2135 temp
-> stats
= new Player ( tempname
);
2138 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2139 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2140 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2141 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2142 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2143 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2144 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2145 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2146 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2147 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2148 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2149 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2150 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2152 password
= strtok ( NULL
, " " );
2153 strcpy ( p
-> password
, password
);
2154 temp
-> setNick ( "Not Playing" );
2156 temp
-> setRealNick ( "Not Playing" );
2159 p
-> inventory
. reset (); // Set inventory to all 0s
2160 // Old player databases didn't have these three extra values
2161 // If they come up null, leave them to 0 as the default.
2162 // On the next gameserv database save, it will save the values.
2163 tempname
= strtok ( NULL
, " " );
2165 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2167 tempname
= strtok ( NULL
, " " );
2169 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2171 tempname
= strtok ( NULL
, " " );
2173 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2175 tempname
= strtok ( NULL
, " " );
2177 p
-> inventory
. setHP ( stringtoint ( tempname
));
2178 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2180 temp
-> stats
-> client
= NULL
;
2181 players
[ hv
]. insertAtBack ( temp
);
2189 bool passcmp ( char * encrypted
, char * plaintext
)
2192 char * plaintext2
, * plainToencrypt
;
2195 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2196 strcpy ( plaintext2
, plaintext
);
2198 salt
[ 0 ] = encrypted
[ 0 ];
2199 salt
[ 1 ] = encrypted
[ 1 ];
2202 plainToencrypt
= crypt ( plaintext2
, salt
);
2204 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2206 delete [] plaintext2
;
2211 bool check_password ( char * name
, char * plaintext
)
2215 if (!( client
= findplayer ( name
)))
2219 return passcmp ( client
-> stats
-> password
, plaintext
);
2223 void do_store ( char * u
)
2225 char * cmd
= strtok ( NULL
, " " );
2226 char * item
= strtok ( NULL
, " " );
2227 char * num
= strtok ( NULL
, " " );
2235 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2236 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2237 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2240 else if (!( user
= find ( u
)))
2242 log ( "Fatal Error: could not find %s in client list" , u
);
2245 else if ( isIgnore ( user
))
2248 log ( "Ignoring %s ." , user
-> getNick ());
2252 else if (! is_playing ( user
))
2254 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2257 else if (! isAlive ( user
-> stats
))
2259 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2262 updateTS ( user
-> stats
);
2264 if ( stricmp ( cmd
, "LIST" ) == 0 )
2266 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2268 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2269 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2270 for ( int x
= 1 ; x
< WNA
; x
++)
2272 space
= spaces ( strlen ( weapons
[ x
]), "." );
2273 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2276 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2277 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2280 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2282 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2283 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2284 for ( int x
= 1 ; x
< WNA
; x
++)
2286 space
= spaces ( strlen ( armors
[ x
]), "." );
2287 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2290 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2291 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2295 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2298 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2301 else if (! isstringnum ( num
))
2303 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2306 if ( stricmp ( item
, "WEAPON" ) == 0 )
2308 wep
= stringtoint ( num
);
2309 if ( wep
>= WNA
|| wep
< 1 )
2311 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2318 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2319 else if ( p
-> gold
< prices
[ wep
- 1 ])
2320 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2323 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2325 p
-> gold
-= prices
[ wep
- 1 ];
2328 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2330 wep
= stringtoint ( num
);
2331 if ( wep
>= WNA
|| wep
< 1 )
2333 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2340 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2341 else if ( p
-> gold
< prices
[ wep
- 1 ])
2342 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2345 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2347 p
-> gold
-= prices
[ wep
- 1 ];
2351 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2355 if ( stricmp ( item
, "WEAPON" ) == 0 )
2359 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2362 else if ( p
-> gold
== 2000000000 )
2364 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2367 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2369 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2370 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2371 p
-> gold
= 2000000000 ;
2376 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2377 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2381 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2387 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2390 if ( p
-> gold
== 2000000000 )
2392 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2395 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2397 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2398 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2399 p
-> gold
= 2000000000 ;
2404 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2405 ( prices
[ p
-> armor
- 1 ] / 2 ));
2407 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2413 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2414 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2415 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2420 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2421 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2422 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2426 void do_inventory ( char * u
)
2430 if (!( user
= find ( u
)))
2432 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2435 else if ( isIgnore ( user
))
2438 log ( "Ignoring %s ." , user
-> getNick ());
2442 else if (! is_playing ( user
))
2444 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2447 updateTS ( user
-> stats
);
2448 showinventory ( user
, user
);
2450 void showinventory ( aClient
* from
, aClient
* to
)
2452 char * nick
= to
-> getNick ();
2456 if ( is_playing ( from
))
2458 Pouch
* p
= & from
-> stats
-> inventory
;
2459 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2460 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2461 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2462 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2463 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2466 void do_tavern ( char * u
)
2468 char * cmd
= strtok ( NULL
, " " );
2474 if (!( user
= find ( u
)))
2476 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2479 else if ( isIgnore ( user
))
2482 log ( "Ignoring %s ." , user
-> getNick ());
2486 else if (! is_playing ( user
))
2488 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2491 else if ( is_fighting ( user
))
2493 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2497 updateTS ( user
-> stats
);
2502 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2503 notice ( s_GameServ
, u
, "Your commands:" );
2504 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2505 notice ( s_GameServ
, u
, "What'll it be?" );
2507 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2509 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2510 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2511 1000 * p
-> level
* 4 );
2512 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2513 2500 * p
-> level
* 4 );
2514 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2515 3000 * p
-> level
* 4 );
2516 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2517 2000 * p
-> level
* 4 );
2518 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2519 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2521 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2523 char * chnum
= strtok ( NULL
, " " );
2524 int num
= stringtoint ( chnum
);
2528 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2529 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2532 if ( num
< 1 || num
> 4 )
2534 notice ( s_GameServ
, u
, "Invalid Choice!" );
2535 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2536 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2537 1000 * p
-> level
* 4 );
2538 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2539 2500 * p
-> level
* 4 );
2540 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2541 3000 * p
-> level
* 4 );
2542 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2543 2000 * p
-> level
* 4 );
2544 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2545 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2551 price
= ( 1000 * p
-> level
* 4 );
2552 if ( p
-> gold
>= price
)
2554 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2555 p
-> inventory
. incHealing ();
2559 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2562 price
= 2500 * p
-> level
* 4 ;
2563 if ( p
-> gold
>= price
)
2565 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2566 p
-> inventory
. incStrength ();
2570 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2573 price
= 3000 * p
-> level
* 4 ;
2574 if ( p
-> gold
>= price
)
2576 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2577 p
-> inventory
. incDefense ();
2581 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2584 price
= 3000 * p
-> level
* 4 ;
2585 if ( p
-> gold
>= price
)
2587 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2588 p
-> inventory
. incHP ();
2592 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2595 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2601 notice ( s_GameServ
, u
, "Improper Syntax." );
2602 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2606 void do_bank ( char * u
)
2608 char * cmd
= strtok ( NULL
, " " );
2609 char * amount
= strtok ( NULL
, " " );
2610 char * nick
= strtok ( NULL
, " " );
2615 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2617 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2618 notice ( s_GameServ
, u
, "BANK BALANCE" );
2621 else if (!( user
= find ( u
)))
2623 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2625 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2628 else if ( isIgnore ( user
))
2631 log ( "Ignoring %s ." , user
-> getNick ());
2635 else if (! is_playing ( user
))
2637 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2640 else if ( is_fighting ( user
))
2642 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2645 updateTS ( user
-> stats
);
2646 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2651 else if (! isAlive ( user
-> stats
))
2653 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2656 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2658 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2664 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2666 if ( p
-> bank
== 2000000000 )
2668 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2671 else if ( stricmp ( amount
, "ALL" ) == 0 )
2673 if ( 2000000000 - p
-> bank
< p
-> gold
)
2675 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2676 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2677 p
-> gold
-= ( 2000000000 - p
-> bank
);
2678 p
-> bank
= 2000000000 ;
2683 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2689 else if ( stringtoint ( amount
) > p
-> gold
)
2691 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2697 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2699 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2700 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2701 p
-> gold
-= ( 2000000000 - p
-> bank
);
2702 p
-> bank
= 2000000000 ;
2707 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2708 p
-> bank
+= stringtoint ( amount
);
2709 p
-> gold
-= stringtoint ( amount
);
2714 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2716 if ( p
-> gold
== 2000000000 )
2718 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2722 else if ( stricmp ( amount
, "ALL" ) == 0 )
2724 if ( 2000000000 - p
-> gold
< p
-> bank
)
2726 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2727 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2728 p
-> bank
-= ( 2000000000 - p
-> gold
);
2729 p
-> gold
= 2000000000 ;
2734 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2740 else if ( stringtoint ( amount
) > p
-> bank
)
2742 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2748 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2750 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2751 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2752 ( 2000000000 - p
-> gold
));
2753 p
-> bank
-= ( 2000000000 - p
-> gold
);
2754 p
-> gold
= 2000000000 ;
2759 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2760 p
-> gold
+= stringtoint ( amount
);
2761 p
-> bank
-= stringtoint ( amount
);
2769 void do_dragon ( char * u
)
2773 if (!( user
= find ( u
)))
2775 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2778 else if ( isIgnore ( user
))
2781 log ( "Ignoring %s ." , user
-> getNick ());
2785 else if (! is_playing ( user
))
2787 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2790 else if ( is_fighting ( user
))
2792 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2795 else if (! isAlive ( user
-> stats
))
2797 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2800 else if ( user
-> stats
-> level
< REALLEVELS
)
2802 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2803 "to vanquish any foe should DARE fight the dragon!" );
2804 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2805 "You are too weak. You must be Level %d !" , REALLEVELS
);
2809 updateTS ( user
-> stats
);
2811 Player
* p
= user
-> stats
;
2812 p
-> fight
= new Monster ( boss
);
2813 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2814 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2815 "deep, red fog rolls in. The air is filled with the " \
2816 "heated mist of deadly fire from beyond the cave " \
2818 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2819 "your %s , and venture into the hot, dark cave. " \
2820 "You are surprised at the angle of descent as you climb " \
2821 "lower and lower, deeper into the dragon's den." );
2822 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2823 "a tooth. It is a large tooth... bigger than your torso." \
2824 " Suddenly the darkness lifts from the gleam of an eye " \
2825 " staring into your soul! The eye is large... HUGE!" );
2826 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2827 "glare orange! The tooth is moving... but it is still too " \
2828 "dark for you to make out.... THE DRAGON! You see it!" );
2832 void do_master ( char * u
)
2837 if (!( user
= find ( u
)))
2839 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2842 else if ( isIgnore ( user
))
2845 log ( "Ignoring %s ." , user
-> getNick ());
2849 else if (! is_playing ( user
))
2851 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2854 else if ( is_fighting ( user
))
2856 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2859 else if (! isAlive ( user
-> stats
))
2861 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2865 updateTS ( user
-> stats
);
2867 char * cmd
= strtok ( NULL
, " " );
2868 Player
* p
= user
-> stats
;
2873 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2917 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
2921 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2927 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2931 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2939 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
));
2942 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2945 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
);
2947 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2953 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2957 void see_master ( char * u
)
2961 if (!( user
= find ( u
)))
2963 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2967 if (! is_fighting ( user
) && is_playing ( user
))
2969 Player
* p
= user
-> stats
;
2970 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2971 p
-> fight
= p
-> master
;
2972 display_monster ( u
); // Since master is the same structure, use this function
2976 void showBankBalance ( const char * u
)
2981 if (!( user
= find ( u
)))
2989 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2995 ListNode
< aClient
> * it
;
2997 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2999 it
= players
[ x
]. First ();
3003 p
= it
-> getData ()-> stats
;
3010 void refresh ( Player
* p
)
3015 if ( p
-> hp
< p
-> maxhp
)
3017 p
-> forest_fights
= forestfights
;
3018 p
-> player_fights
= 3 ;
3023 void do_refresh ( char * u
)
3025 char * nick
= strtok ( NULL
, " " );
3028 if (!( user
= find ( u
)))
3030 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3031 log ( "Error: aClient not found: %s " , u
);
3034 else if ( isIgnore ( user
))
3037 log ( "Ignoring %s ." , user
-> getNick ());
3041 else if (! isAdmin ( user
))
3043 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3048 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3051 else if ( stricmp ( nick
, "ALL" ) == 0 )
3053 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3056 else if (( user
= findplayer ( nick
)))
3058 if ( is_playing ( user
))
3061 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3063 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3065 refresh ( user
-> stats
);
3070 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3072 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3078 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3086 ListNode
< aClient
> * it
;
3089 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3091 it
= players
[ x
]. First ();
3095 p
= it
-> getData ()-> stats
;
3102 void reset ( Player
* p
)
3110 void updateTS ( Player
* p
)
3116 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3118 p
-> lastcommand
= time ( NULL
);
3120 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3125 bool timedOut ( Player
* p
)
3129 else if ( p
-> lastcommand
== 0 )
3133 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3140 void timeOutEvent ( Player
* p
)
3142 aClient
* user
= findplayer ( p
-> name
);
3144 if (! user
|| ! p
-> client
) // then they're not playing
3147 char * nick
= user
-> getNick ();
3149 if ( player_fight ( user
) && isYourTurn ( p
))
3151 // Check to see if they were the idler or if it was the other
3153 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3155 // This person's last command was given earlier,
3156 // so this person is the idler
3157 notice ( s_GameServ
, nick
, "You timed out " \
3158 "during a fight. You lose your turn!" );
3159 notice ( s_GameServ
, p
-> battle
-> getNick (),
3160 " %s hesitated for too long. Your move." , p
-> name
);
3162 setYourTurn ( p
-> battle
-> stats
);
3164 // Update the TS for both players to give them another
3165 // Chance to wake up, but if the other player doesn't
3166 // Attack now, they both get logged out.
3168 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3169 display_players ( p
-> battle
);
3174 notice ( s_GameServ
, p
-> battle
-> getNick (),
3175 "You and %s timed out at the same time." \
3176 " Don't fight if you're just going to " \
3177 "sit there!" , p
-> name
);
3178 notice ( s_GameServ
, user
-> getNick (),
3179 "You and %s timed out at the same time." \
3180 " Don't fight if you're just going to " \
3181 "sit there!" , p
-> battle
-> stats
-> name
);
3187 else if (! player_fight ( user
))
3189 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3191 // Place fun stuff here :)
3192 int randnum
= 1 + rand () % 100 ; // 1-100
3193 #define GSN(s) notice(s_GameServ, nick, s)
3194 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3198 // 35-100% of your gold goes pffft - kain
3199 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3201 GSN ( "You stop for a moment to rest on the " \
3202 "street corner. All of a sudden, you " \
3203 "are ambushed from all sides by a hoarde " \
3204 "of knife wielding thugs." );
3205 GSN2 ( "The thugs beat you into utter submission " \
3206 "and steal %d gold from you!" , stolen
);
3207 user
-> stats
-> gold
-= stolen
;
3209 else if ( randnum
>= 50 && randnum
< 75 )
3211 // 25-65% of your gold goes pffft - kain
3212 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3213 GSN ( "While dilly dallying around, you lose " \
3214 "your sense of time. Little did you know, " \
3215 "but thieves lifted your gold while you " \
3216 "weren't watching." );
3217 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3218 user
-> stats
-> gold
-= stolen
;
3220 else if ( randnum
>= 75 )
3222 // 25-75% of your gold goes pffft - kain
3223 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3224 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3225 "goblins grabbed your gold!" );
3226 GSN2 ( "They stole %d gold from you!" , stolen
);
3227 user
-> stats
-> gold
-= stolen
;
3231 // Always log out the user
3236 void do_reset ( char * u
)
3238 char * nick
= strtok ( NULL
, " " );
3241 if (!( user
= find ( u
)))
3243 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3244 log ( "Error: aClient not found: %s " , u
);
3247 else if (! isAdmin ( user
))
3249 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3255 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3258 else if ( stricmp ( nick
, "ALL" ) == 0 )
3260 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3263 else if (( user
= findbyrealnick ( nick
)))
3265 if ( is_playing ( user
))
3268 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3270 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3277 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3279 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3285 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3290 void do_help ( char * u
)
3292 char * cmd
= strtok ( NULL
, " " );
3294 display_help ( u
, cmd
);
3297 void display_help ( char * u
, char * file
)
3304 infile
. open ( "helpfiles/help" );
3307 log ( "Error opening helpfiles/help" );
3308 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3311 buf
= new char [ 1024 ];
3312 while ( infile
. getline ( buf
, 1024 ))
3314 // Written this way, it will process %S in the helpfiles
3315 // Instead of notice(s_GameServ, u, "%s", buf);
3316 notice ( s_GameServ
, u
, buf
);
3320 aClient
* user
= find ( u
);
3321 if ( user
&& isAdmin ( user
))
3322 display_help ( u
, "admin_commands" );
3327 filename
= new char [ strlen ( file
) + 11 ];
3328 strcpy ( filename
, "helpfiles/" );
3329 strcat ( filename
, file
);
3331 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3332 filename
[ x
] = tolower ( filename
[ x
]);
3334 infile
. open ( filename
);
3338 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3341 buf
= new char [ 1024 ];
3342 while ( infile
. getline ( buf
, 1024 ))
3344 // Written this way, it will process %S in the helpfiles
3345 // Instead of notice(s_GameServ, u, "%s", buf);
3346 notice ( s_GameServ
, u
, buf
);
3353 void do_admin ( char * u
)
3356 char * pass
= strtok ( NULL
, " " );
3358 if (!( user
= find ( u
)))
3360 log ( "Error: aClient not found: %s " , u
);
3361 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3367 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3373 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3376 else if ( strcmp ( pass
, adminpass
) == 0 )
3378 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3381 log ( " %s became an administrator." , user
-> getRealNick ());
3383 log ( " %s became an administrator." , user
-> getNick ());
3388 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3393 bool load_monsters ()
3396 infile
. open ( "monsters.dat" );
3402 log ( "Error opening monsters.dat" );
3406 buf
= new char [ 2048 ];
3409 log ( "Loading monsters from monsters.dat" );
3412 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
3414 for ( int m
= 0 ; m
< MONSTERS
;)
3416 infile
. getline ( buf
, 2048 );
3417 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3421 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
3422 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
3423 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
3424 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
3425 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
3426 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
3427 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
3428 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));