]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
15 #if defined(HAVE_CRYPT_H)
19 #elif defined(HAVE_UNISTD_H)
25 // this will be hash.cpp start
27 unsigned long sHASH ( const unsigned char * name
);
28 unsigned long iHASH ( const unsigned char * name
);
29 List
< aClient
> players
[ U_TABLE_SIZE
];
30 // this will be hash.cpp end
33 Monster
* monsters
[ LEVELS
][ MONSTERS
]; // Monsters per level. Total = MONSTERS * LEVELS
34 Monster boss
; // The boss monster
36 Monster
* masters
[ LEVELS
]; // A master for each level
44 char * strtok ( char * str
, const char * delim
);
47 int stricmp ( const char * s1
, const char * s2
);
48 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
51 /********** Password functions **********/
53 bool passcmp ( char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
55 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
57 /********** Password functions **********/
60 /********** GameServ Booleans **********/
63 bool timedOut ( Player
* p
);
64 void updateTS ( Player
* p
);
65 void timeOutEvent ( Player
* p
);
67 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
68 bool is_playing ( aClient
* user
);
70 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
71 bool is_fighting ( aClient
* user
);
73 bool player_fight ( char * u
); // True if the player is fighting another player.
74 bool player_fight ( aClient
* user
);
76 bool master_fight ( char * u
); // True if the player is fighting their master.
77 bool master_fight ( aClient
* user
);
79 /********** GameServ Booleans **********/
81 void display_help ( char * u
, char * file
= NULL
);
82 void display_monster ( char * u
);
83 void display_players ( char * u
);
84 void display_players ( aClient
* user
);
85 long int chartoint ( char ch
);
86 int isstringnum ( char * num
);
87 long int pow ( int x
, int y
);
88 long int stringtoint ( char * number
);
90 char * spaces ( int len
, char * seperator
);
91 void refresh ( Player
* p
);
93 void updateTS ( Player
* p
);
94 void reset ( Player
* p
);
98 void delete_monsters ();
99 void delete_masters ();
101 void do_admin ( char * u
);
102 void do_attack ( char * u
);
103 void do_bank ( char * u
);
104 void do_fight ( char * u
);
105 void do_heal ( char * u
);
106 void do_help ( char * u
);
107 void do_identify ( char * u
);
108 void do_inventory ( char * u
);
109 void do_refresh ( char * u
);
110 void do_register ( char * u
);
111 void do_list ( char * u
);
112 void do_logout ( char * u
);
113 void do_master ( char * u
);
114 void do_dragon ( char * u
);
115 void do_play ( char * u
);
116 void do_quitg ( char * u
);
117 void do_reset ( char * u
);
118 void do_run ( char * u
);
119 void do_stats ( char * u
);
120 void do_store ( char * u
);
121 void do_tavern ( char * u
);
122 void do_use ( char * u
);
123 void see_master ( char * u
);
125 void logout ( aClient
* user
);
126 void showstats ( const char * u
, const char * nick
);
127 void showinventory ( aClient
* from
, aClient
* to
);
128 void showBankBalance ( const char * u
);
129 void end_turn ( aClient
* user
);
132 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
133 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
134 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
135 "Light Saber" , "Masamune" , "Mystical Sword" };
137 char * armors
[ WNA
] = { "Birthday Suit" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
138 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
139 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
140 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
142 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
143 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
144 int webonus
[ WNA
] = { 2 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
145 int arbonus
[ WNA
] = { 2 , 3 , 5 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
147 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
148 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
149 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
151 void gameserv ( char * source
, char * buf
)
154 cmd
= strtok ( buf
, " " );
157 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
162 cmd
++; // Get rid of that : at the beginning of the :text (command)
165 log ( "Source: %s Command: %s " , source
, cmd
);
173 int curday
= tm
-> tm_mday
;
179 save_day (); // here i come to save the day!
182 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
185 ts
= strtok ( NULL
, "\1" );
186 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
187 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
188 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
189 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
190 cmd
= strtok ( NULL
, " " );
193 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
197 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
199 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
201 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
203 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
205 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
207 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
208 do_inventory ( source
);
209 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
211 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
213 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
215 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
217 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
219 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
221 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
223 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
225 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
227 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
229 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
231 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
233 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
235 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
237 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
240 if (!( user
= find ( source
)))
242 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
243 log ( "Error: aClient not found: %s " , source
);
245 else if (! isAdmin ( user
))
247 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
253 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
255 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
259 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
262 if (!( user
= find ( source
)))
264 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
265 log ( "Error: aClient not found: %s " , source
);
267 else if (! isAdmin ( user
))
269 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
275 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
278 if (!( user
= find ( source
)))
280 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
281 log ( "Error: aClient not found: %s " , source
);
283 else if (! isAdmin ( user
))
285 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
289 char * cmd2
= strtok ( NULL
, " " );
292 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
295 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
297 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
301 display_help ( source
, cmd
);
304 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
307 if (!( user
= find ( source
)))
309 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
310 log ( "Error: aClient not found: %s " , source
);
312 else if (! isAdmin ( user
))
314 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
318 char * rest
= strtok ( NULL
, "" );
324 if (( user
= find ( source
)))
329 log ( "Ignoring %s ." , user
-> getNick ());
334 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
340 source
--; // Bring the ':' back so we don't leak memory
343 cmd
--; // Same thing :)
346 int stricmp ( const char * s1
, const char * s2
)
350 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
356 if ( c
< tolower (* s2
))
361 void showstats ( const char * u
, const char * nick
)
363 aClient
* ni
, * sender
= find ( u
);
369 if (!( ni
= findplayer ( nick
)))
371 notice ( s_GameServ
, u
, " %s not found" , nick
);
375 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
377 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
378 space
= spaces ( strlen ( buf
), " " );
379 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
383 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
384 space
= spaces ( strlen ( buf
), " " );
385 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
388 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
391 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
392 space
= spaces ( strlen ( buf
), " " );
393 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
394 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
397 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
398 space
= spaces ( strlen ( buf
), " " );
399 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
400 weapons
[ ni
-> stats
-> weapon
]);
403 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
404 space
= spaces ( strlen ( buf
), " " );
405 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
407 Pouch
* inv
= & ni
-> stats
-> inventory
;
409 notice ( s_GameServ
, u
, "Potions" );
410 sprintf ( buf
, "Healing: %d " , inv
-> Healing ());
411 space
= spaces ( strlen ( buf
), " " );
412 notice ( s_GameServ
, sender
-> getNick (), " %s%s HP: %d " , buf
,
416 sprintf ( buf
, "Strength: %d " , inv
-> Strength ());
417 space
= spaces ( strlen ( buf
), " " );
418 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " , buf
,
419 space
, inv
-> Defense ());
424 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
429 char * spaces ( int len
, char * seperator
)
432 final
= new char [ 30 ];
434 strcpy ( final
, seperator
);
435 for ( y
= 0 ; y
< 30 - len
; y
++)
436 strcat ( final
, seperator
);
440 void raw ( const char * fmt
, ...)
445 input
= new char [ 1024 ];
447 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
453 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
454 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
455 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
458 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
463 sprintf ( input
, " %s%c " , input
, * t
);
468 log ( "Input: %s " , input
);
471 sprintf ( input
, " %s%s " , input
, " \r\n " );
472 sock_puts ( sock
, input
);
476 /* Send a NOTICE from the given source to the given nick. */
478 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
484 commanduse
= new char [ 16 ];
488 strcpy ( commanduse
, "P" );
490 strcpy ( commanduse
, "O" );
494 strcpy ( commanduse
, "PRIVMSG" );
496 strcpy ( commanduse
, "NOTICE" );
502 input
= new char [ 1024 ];
509 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
511 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
519 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
521 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
530 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
531 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
532 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
535 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
540 sprintf ( input
, " %s%c " , input
, * t
);
545 log ( "Input: %s " , input
);
547 sprintf ( input
, " %s%s " , input
, " \r\n " );
548 sock_puts ( sock
, input
);
549 delete [] commanduse
;
555 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
561 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
562 if ( c
== 0 || -- len
== 0 )
567 if ( c
< tolower (* s2
))
573 char * strtok ( char * str
, const char * delim
)
575 static char * current
= NULL
;
582 current
+= strspn ( current
, delim
);
583 ret
= * current
? current
: NULL
;
584 current
+= strcspn ( current
, delim
);
593 void do_list ( char * u
)
596 char * cmd
= strtok ( NULL
, " " );
598 if (!( user
= find ( u
)))
600 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
603 else if ( isIgnore ( user
))
606 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
611 ListNode
< aClient
> * temp
;
614 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
616 temp
= players
[ x
]. First ();
617 if (! players
[ x
]. isEmpty ())
621 if (! cmd
|| is_playing ( temp
-> getData ()))
625 notice ( s_GameServ
, u
, "Players:" );
629 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
630 temp
-> getData ()-> stats
-> name
);
632 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
633 temp
-> getData ()-> stats
-> name
);
642 notice ( s_GameServ
, u
, "No one is playing" );
644 notice ( s_GameServ
, u
, "End of List" );
648 void do_logout ( char * u
)
651 char * name
= strtok ( NULL
, " " );
653 if (!( user
= find ( u
)))
655 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
656 "Buf: %s LOGOUT" , u
);
657 log ( "Could not find aClient Buf: %s LOGOUT" ,
661 else if ( isIgnore ( user
))
664 log ( "Ignoring %s ." , user
-> getNick ());
673 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
675 else if (!( user
= findplayer ( name
)))
677 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
681 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
687 if (! is_playing ( user
))
689 notice ( s_GameServ
, u
, "You're not logged in!" );
691 else if ( is_fighting ( user
))
693 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
697 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
703 void logout ( aClient
* user
)
705 if ( is_playing ( user
))
707 ListNode
< aClient
> * it
;
709 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
710 it
= players
[ hv
]. Find ( user
);
714 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
715 " %S Admin. Cannot find you in the players list." );
716 log ( "Error on logout(). Can't find %s in the players list" ,
727 temp
-> stats
= new Player
;
728 temp
-> stats
-> setData ( user
-> stats
);
729 user
-> stats
-> client
= NULL
;
731 if ( player_fight ( user
))
732 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
736 temp
-> stats
-> client
= NULL
;
738 temp
-> setRealNick ( "Not Playing" );
740 temp
-> setNick ( "Not Playing" );
744 log ( "Logged out player %s " ,
756 void do_register ( char * u
)
758 char * password
, * name
;
760 name
= strtok ( NULL
, " " );
761 password
= strtok ( NULL
, " " );
763 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
766 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
767 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
772 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
776 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
778 else if (( user
= findplayer ( name
)))
780 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
781 notice ( s_GameServ
, u
, "Choose another name!" );
783 else if (!( user
= find ( u
)))
785 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
787 else if ( isIgnore ( user
))
790 log ( "Ignoring %s ." , user
-> getNick ());
796 if (! is_playing ( user
))
798 ListNode
< aClient
> * temp
;
799 user
-> stats
= new Player ( user
);
800 user
-> stats
-> client
= user
; // Set the backwards pointer
801 user
-> stats
-> reset (); // set the user up
802 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
803 strncpy ( user
-> stats
-> name
, name
, 255 );
804 unsigned long hv
= iHASH (( unsigned char *) name
);
805 updateTS ( user
-> stats
);
806 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
807 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
809 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
810 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
811 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
812 setPlaying ( user
); // set the playing flag
816 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
821 void do_identify ( char * u
)
823 char * password
, * name
;
825 name
= strtok ( NULL
, " " );
826 password
= strtok ( NULL
, " " );
827 if (! password
|| ! name
)
829 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
831 else if (!( user
= find ( u
)))
833 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
834 log ( "Error: aClient not found: %s " , u
);
836 else if ( isIgnore ( user
))
839 log ( "Ignoring %s ." , user
-> getNick ());
843 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
844 notice ( s_GameServ
, u
, "Player %s not found" , name
);
845 else if ( is_playing ( user
))
847 notice ( s_GameServ
, u
, "You are already playing!" );
849 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
851 notice ( s_GameServ
, u
, "That player has already identified." );
853 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
855 notice ( s_GameServ
, u
, "Password incorrect" );
858 ListNode
< aClient
> * temp
;
859 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
860 temp
= players
[ hv
]. Find ( p
);
863 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
867 user
-> stats
= new Player ( p
-> stats
-> name
);
869 log ( "Setting data for identified" );
871 user
-> stats
-> setData ( p
-> stats
);
872 user
-> stats
-> client
= user
;
873 updateTS ( user
-> stats
);
877 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
881 setPlaying ( user
); // set the playing flag
884 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
888 void do_stats ( char * u
)
893 nick
= strtok ( NULL
, " " );
895 if (!( user
= find ( u
)))
897 log ( "Fatal Error: %s not found in client list" , u
);
900 else if ( isIgnore ( user
))
903 log ( "Ignoring %s ." , user
-> getNick ());
909 if (! is_playing ( user
))
911 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
916 updateTS ( user
-> stats
);
917 showstats ( u
, user
-> stats
-> name
);
927 log ( "Calling delete_masters()" );
933 log ( "Initializing masters" );
936 for ( int x
= 0 ; x
< LEVELS
; x
++)
937 masters
[ x
] = new Monster
;
939 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
940 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
941 masters
[ 0 ]-> strength
= 32 ;
942 masters
[ 0 ]-> gold
= 0 ;
944 masters
[ 0 ]-> maxhp
= 35 ;
946 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!" );
948 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
949 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
950 masters
[ 1 ]-> strength
= 48 ;
951 masters
[ 1 ]-> gold
= 0 ;
953 masters
[ 1 ]-> maxhp
= 51 ;
955 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." );
957 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
958 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
959 masters
[ 2 ]-> strength
= 88 ;
960 masters
[ 2 ]-> gold
= 0 ;
962 masters
[ 2 ]-> maxhp
= 100 ;
963 masters
[ 2 ]-> hp
= 100 ;
964 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!" );
967 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
968 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
969 masters
[ 3 ]-> strength
= 169 ;
970 masters
[ 3 ]-> gold
= 0 ;
972 masters
[ 3 ]-> maxhp
= 165 ;
973 masters
[ 3 ]-> hp
= 165 ;
974 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
976 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
977 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
978 masters
[ 4 ]-> strength
= 275 ;
979 masters
[ 4 ]-> gold
= 0 ;
981 masters
[ 4 ]-> maxhp
= 232 ;
982 masters
[ 4 ]-> hp
= 232 ;
983 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!" );
985 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
986 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
987 masters
[ 5 ]-> strength
= 347 ;
988 masters
[ 5 ]-> gold
= 0 ;
990 masters
[ 5 ]-> maxhp
= 504 ;
991 masters
[ 5 ]-> hp
= 504 ;
992 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
995 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
996 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
997 masters
[ 6 ]-> strength
= 515 ;
998 masters
[ 6 ]-> gold
= 0 ;
1000 masters
[ 6 ]-> maxhp
= 1078 ;
1001 masters
[ 6 ]-> hp
= 1078 ;
1002 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
1004 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
1005 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
1006 masters
[ 7 ]-> strength
= 655 ;
1007 masters
[ 7 ]-> gold
= 0 ;
1008 masters
[ 7 ]-> exp
= 0 ;
1009 masters
[ 7 ]-> maxhp
= 2207 ;
1010 masters
[ 7 ]-> hp
= 2207 ;
1011 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
1014 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
1015 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
1016 masters
[ 8 ]-> strength
= 819 ;
1017 masters
[ 8 ]-> gold
= 0 ;
1018 masters
[ 8 ]-> exp
= 0 ;
1019 masters
[ 8 ]-> maxhp
= 2780 ;
1020 masters
[ 8 ]-> hp
= 2780 ;
1021 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1023 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1024 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1025 masters
[ 9 ]-> strength
= 1014 ;
1026 masters
[ 9 ]-> gold
= 0 ;
1027 masters
[ 9 ]-> exp
= 0 ;
1028 masters
[ 9 ]-> maxhp
= 3046 ;
1029 masters
[ 9 ]-> hp
= 3046 ;
1030 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1032 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1033 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1034 masters
[ 10 ]-> strength
= 1286 ;
1035 masters
[ 10 ]-> gold
= 0 ;
1036 masters
[ 10 ]-> exp
= 0 ;
1037 masters
[ 10 ]-> maxhp
= 3988 ;
1038 masters
[ 10 ]-> hp
= 3988 ;
1039 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." );
1042 void init_monsters ()
1045 log ( "Calling delete_monsters" );
1050 for ( int x
= 0 ; x
< LEVELS
; x
++)
1051 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1052 monsters
[ x
][ y
] = new Monster ();
1055 void delete_monsters ()
1057 for ( int x
= 0 ; x
< LEVELS
; x
++)
1058 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1060 delete monsters
[ x
][ y
];
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 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1363 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1364 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1365 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealing
);
1367 if ( player_fight ( user
))
1369 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1370 " %s has used a healing potion!" );
1373 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1375 if ( p
-> Strength () <= 0 )
1377 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1380 int oldstrength
= user
-> stats
-> strength
;
1381 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1382 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1383 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1384 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1386 if ( player_fight ( user
))
1388 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1389 " %s has used a strength potion!" );
1392 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1394 if ( p
-> Defense () <= 0 )
1396 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1399 int olddefense
= user
-> stats
-> defense
;
1400 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1401 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1402 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1403 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1405 if ( player_fight ( user
))
1407 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1408 " %s has used a defense potion!" );
1411 else if ( stricmp ( item
, "HP" ) == 0 )
1415 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1418 int oldHP
= user
-> stats
-> maxhp
;
1419 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1420 user
-> stats
-> maxhp
+= 2 +
1421 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1423 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1425 if ( player_fight ( user
))
1427 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1428 " %s has used a HP potion!" );
1433 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}" );
1437 end_turn ( user
); // If they're fighting, end their turn
1439 void do_run ( char * u
)
1442 Player
* p
, * p2
= NULL
;
1444 if (!( user
= find ( u
)))
1446 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1449 else if ( isIgnore ( user
))
1452 log ( "Ignoring %s ." , user
-> getNick ());
1456 else if (! is_playing ( user
))
1458 notice ( s_GameServ
, u
, "You must be playing to run!" );
1462 updateTS ( user
-> stats
);
1466 p2
= p
-> battle
-> stats
;
1468 if (! is_fighting ( user
))
1469 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1470 else if (! player_fight ( user
) && ! master_fight ( user
))
1472 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1476 else if ( player_fight ( user
) && isYourTurn ( p
))
1478 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1479 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1482 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1484 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1486 else if ( master_fight ( user
))
1488 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1493 void end_turn ( aClient
* user
)
1495 char * nick
, * u
= user
-> getNick ();
1500 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1502 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1505 if (! player_fight ( user
) && ! master_fight ( user
))
1506 fight
= user
-> stats
-> fight
;
1508 fight
= user
-> stats
-> master
;
1509 battle
= user
-> stats
-> battle
;
1511 if (! player_fight ( user
))
1514 mhit
= ( fight
-> strength
/ 2 ) +
1515 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1516 arbonus
[ user
-> stats
-> armor
]));
1521 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1522 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1523 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1525 if (! player_fight ( user
))
1530 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1531 fight
-> name
, fight
-> weapon
, mhit
);
1534 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1536 if ( mhit
>= user
-> stats
-> hp
)
1538 if (! master_fight ( user
))
1540 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1541 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1542 "of your experience!" );
1543 user
-> stats
-> gold
= 0 ;
1544 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1545 user
-> stats
-> hp
= 0 ;
1546 user
-> stats
-> fight
= NULL
;
1547 clearAlive ( user
-> stats
);
1552 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1553 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1554 user
-> stats
-> fight
= NULL
;
1555 user
-> stats
-> master
= NULL
;
1562 user
-> stats
-> hp
-= mhit
;
1569 clearYourTurn ( user
-> stats
);
1570 setYourTurn ( battle
-> stats
);
1571 display_players ( battle
);
1577 void do_attack ( char * u
)
1580 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1581 Monster
* fight
; // The monster they may be fighting
1583 if (!( ni
= find ( u
)))
1585 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1588 else if ( isIgnore ( ni
))
1591 log ( "Ignoring %s ." , ni
-> getNick ());
1595 else if (! is_playing ( ni
))
1597 notice ( s_GameServ
, u
, "You're not playing!" );
1600 else if (! is_fighting ( ni
))
1602 notice ( s_GameServ
, u
, "You're not in battle!" );
1607 if (! ni
-> stats
-> master
) // This is not a master fight
1608 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1609 else // This IS a master fight
1610 fight
= ni
-> stats
-> master
; // Master Could be NULL
1612 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1614 // One has to be !NULL based on the previous else if
1615 // We wouldn't be here if they were all NULL
1617 updateTS ( ni
-> stats
);
1619 if (! player_fight ( ni
))
1622 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1623 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1626 mhit
= ( fight
-> strength
/ 2 ) +
1627 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1628 arbonus
[ ni
-> stats
-> armor
]));
1633 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1634 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1635 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1638 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1639 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1640 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1643 if (! player_fight ( ni
))
1646 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1648 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1650 if ( hit
>= fight
-> hp
)
1652 if ( master_fight ( ni
))
1653 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1655 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1657 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1658 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1659 fight
-> exp
, fight
-> gold
);
1661 // If your new experience (or gold) will be greater than 2 billion,
1662 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1663 // This could be a problem with overflowing out of the sign bit.
1664 // Unsigned long int maybe? Leave it for now.
1665 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1666 ni
-> stats
-> exp
+ fight
-> exp
);
1668 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1669 ni
-> stats
-> gold
+ fight
-> gold
);
1672 if ( master_fight ( ni
))
1674 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1675 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1676 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1678 // Increase your level
1681 // Increase your maximum hit points
1682 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1684 // Heal the player by setting hp to their max
1685 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1687 // Add to your strength
1688 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1690 // Add to your defensive power
1691 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1693 // Clear the pointer for your master
1694 ni
-> stats
-> master
= NULL
;
1697 // They're dead so remove the pointer
1698 delete ni
-> stats
-> fight
;
1699 ni
-> stats
-> fight
= NULL
;
1700 ni
-> stats
-> master
= NULL
;
1710 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1711 fight
-> name
, fight
-> weapon
, mhit
);
1714 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1716 if ( mhit
>= ni
-> stats
-> hp
)
1718 if (! master_fight ( ni
))
1720 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1721 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1722 "of your experience!" );
1723 ni
-> stats
-> gold
= 0 ;
1724 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1726 ni
-> stats
-> fight
= NULL
;
1727 clearAlive ( ni
-> stats
);
1732 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1733 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1734 ni
-> stats
-> fight
= NULL
;
1735 ni
-> stats
-> master
= NULL
;
1742 ni
-> stats
-> hp
-= mhit
;
1748 else if ( player_fight ( ni
))
1750 /* Offline fighting not available yet
1751 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1754 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1756 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1757 if (hit >= battle->stats->hp)
1759 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1760 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1761 (long int)(battle->stats->exp * .10), battle->stats->gold);
1762 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1764 ni->stats->exp += (long int)(battle->stats->exp * .10);
1765 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1769 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1770 ni->stats->exp = 2000000000;
1773 if (2000000000 - ni->stats->gold > battle->stats->gold)
1775 * ni->stats->gold += battle->stats->gold;
1776 battle->stats->gold = 0;
1780 battle->stats->gold = 2000000000 - ni->stats->gold;
1781 ni->stats->gold = 2000000000;
1783 * ni->stats->battle->stats->alive = 0;
1784 ni->stats->battle->battle = NULL;
1785 ni->stats->battle = NULL;
1791 * battle->stats->hp -= hit;
1794 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1795 battle->nick, weapons[battle->stats->weapon], mhit);
1798 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1800 if (mhit >= ni->stats->hp)
1802 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1803 if (2000000000 - battle->stats->gold > ni->stats->gold)
1805 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1806 battle->stats->gold += ni->stats->gold;
1807 * ni->stats->gold = 0;
1811 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1813 ni->stats->gold -= (2000000000 - battle->stats->gold);
1814 notice(s_GameServ, u, "You were left dead with %d gold.",
1815 * (long int)ni->stats->gold);
1816 battle->stats->gold = 2000000000;
1818 ni->stats->battle->battle = NULL;
1819 ni->stats->battle = NULL;
1820 ni->stats->alive = 0;
1826 ni->stats->hp -= mhit;
1832 * end offline fighting */
1834 if ( is_playing ( battle
))
1836 if (! isYourTurn ( ni
-> stats
))
1838 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1839 battle
-> stats
-> name
);
1844 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1846 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1847 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1848 weapons
[ ni
-> stats
-> weapon
], hit
);
1849 clearYourTurn ( ni
-> stats
);
1850 setYourTurn ( battle
-> stats
);
1851 display_players ( battle
);
1855 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1856 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1857 clearYourTurn ( ni
-> stats
);
1858 setYourTurn ( battle
-> stats
);
1859 display_players ( battle
);
1861 if ( hit
>= battle
-> stats
-> hp
)
1863 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1864 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1865 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1866 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1868 battle
-> stats
-> hp
= 0 ;
1869 clearAlive ( battle
-> stats
);
1871 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1873 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1874 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1878 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1879 ni
-> stats
-> exp
= 2000000000 ;
1882 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1884 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1885 "all gold on hand!" );
1886 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1887 battle
-> stats
-> gold
= 0 ;
1891 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1892 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1894 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1895 "gold." , ni
-> stats
-> name
);
1897 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1898 "left. All is not lost!" , battle
-> stats
-> gold
);
1900 ni
-> stats
-> gold
= 2000000000 ;
1902 battle
-> stats
-> battle
= NULL
;
1903 ni
-> stats
-> battle
= NULL
;
1909 battle
-> stats
-> hp
-= hit
;
1910 clearYourTurn ( ni
-> stats
);
1911 setYourTurn ( battle
-> stats
);
1912 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1913 battle
-> stats
-> name
);
1921 void do_heal ( char * u
)
1924 char * amount
= strtok ( NULL
, " " );
1929 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1932 else if (!( ni
= find ( u
)))
1934 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1937 else if ( isIgnore ( ni
))
1940 log ( "Ignoring %s ." , ni
-> getNick ());
1944 else if (! is_playing ( ni
))
1946 notice ( s_GameServ
, u
, "You aren't playing!" );
1949 else if (! isAlive ( ni
-> stats
))
1951 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1954 else if ( is_fighting ( ni
))
1956 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1959 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1961 notice ( s_GameServ
, u
, "You don't need healing!" );
1965 updateTS ( ni
-> stats
);
1966 if ( stricmp ( amount
, "ALL" ) == 0 )
1968 price
= ni
-> stats
-> level
* 3 ;
1969 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1971 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1972 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1973 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1974 ni
-> stats
-> gold
%= price
;
1978 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1979 "per point." , price
);
1980 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1981 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1982 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1983 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1984 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1987 else if ( isstringnum ( amount
))
1989 num
= stringtoint ( amount
);
1990 price
= ni
-> stats
-> level
* 3 ;
1991 if ( ni
-> stats
-> gold
< price
* num
)
1993 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1994 ( long int ) ni
-> stats
-> gold
/ price
);
1996 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1998 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2000 ni
-> stats
-> hp
+= num
;
2001 ni
-> stats
-> gold
-= num
* price
;
2003 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2005 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2006 "per point." , price
);
2007 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2008 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
2009 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2010 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2013 else if ( amount
[ 0 ] == '-' )
2014 notice ( s_GameServ
, u
, "You trying to cheat?" );
2016 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2019 int isstringnum ( char * num
)
2022 for ( x
= 0 ; x
< strlen ( num
); x
++)
2024 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2030 long int stringtoint ( char * number
)
2032 long int x
, len
= strlen ( number
), sum
= 0 ;
2034 return chartoint ( number
[ 0 ]);
2035 sum
+= chartoint ( number
[ len
- 1 ]);
2036 for ( x
= len
- 2 ; x
>= 0 ; x
--)
2037 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
2041 long int pow ( int x
, int y
)
2047 if ( x
!= 0 && y
!= 0 )
2049 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2057 long int chartoint ( char ch
)
2059 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2060 return int ( ch
) - 48 ;
2067 ListNode
< aClient
> * ptr
;
2071 outfile
. open ( playerdata
);
2075 log ( "Error opening %s " , playerdata
);
2079 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2081 ptr
= players
[ x
]. First ();
2084 it
= ptr
-> getData ()-> stats
;
2086 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2087 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2088 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2089 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2090 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2091 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
2104 char * tempname
, * buf
, * password
;
2105 buf
= new char [ 1023 ];
2107 infile
. open ( playerdata
);
2111 log ( "Error opening %s " , playerdata
);
2115 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2118 tempname
= strtok ( buf
, " " );
2119 temp
-> stats
= new Player ( tempname
);
2122 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2123 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2124 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2125 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2126 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2127 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2128 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2129 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2130 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2131 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2132 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2133 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2134 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2136 password
= strtok ( NULL
, " " );
2137 strcpy ( p
-> password
, password
);
2138 temp
-> setNick ( "Not Playing" );
2140 temp
-> setRealNick ( "Not Playing" );
2143 p
-> inventory
. reset (); // Set inventory to all 0s
2144 // Old player databases didn't have these three extra values
2145 // If they come up null, leave them to 0 as the default.
2146 // On the next gameserv database save, it will save the values.
2147 tempname
= strtok ( NULL
, " " );
2149 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2151 tempname
= strtok ( NULL
, " " );
2153 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2155 tempname
= strtok ( NULL
, " " );
2157 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2159 tempname
= strtok ( NULL
, " " );
2161 p
-> inventory
. setHP ( stringtoint ( tempname
));
2162 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2164 temp
-> stats
-> client
= NULL
;
2165 players
[ hv
]. insertAtBack ( temp
);
2173 bool passcmp ( char * encrypted
, char * plaintext
)
2176 char * plaintext2
, * plainToencrypt
;
2179 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2180 strcpy ( plaintext2
, plaintext
);
2182 salt
[ 0 ] = encrypted
[ 0 ];
2183 salt
[ 1 ] = encrypted
[ 1 ];
2186 plainToencrypt
= crypt ( plaintext2
, salt
);
2188 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2190 delete [] plaintext2
;
2195 bool check_password ( char * name
, char * plaintext
)
2199 if (!( client
= findplayer ( name
)))
2203 return passcmp ( client
-> stats
-> password
, plaintext
);
2207 void do_store ( char * u
)
2209 char * cmd
= strtok ( NULL
, " " );
2210 char * item
= strtok ( NULL
, " " );
2211 char * num
= strtok ( NULL
, " " );
2219 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2220 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2221 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2224 else if (!( user
= find ( u
)))
2226 log ( "Fatal Error: could not find %s in client list" , u
);
2229 else if ( isIgnore ( user
))
2232 log ( "Ignoring %s ." , user
-> getNick ());
2236 else if (! is_playing ( user
))
2238 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2241 else if (! isAlive ( user
-> stats
))
2243 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2246 updateTS ( user
-> stats
);
2248 if ( stricmp ( cmd
, "LIST" ) == 0 )
2250 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2252 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2253 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2254 for ( int x
= 1 ; x
< WNA
; x
++)
2256 space
= spaces ( strlen ( weapons
[ x
]), "." );
2257 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2260 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2261 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2264 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2266 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2267 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2268 for ( int x
= 1 ; x
< WNA
; x
++)
2270 space
= spaces ( strlen ( armors
[ x
]), "." );
2271 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2274 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2275 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2279 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2282 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2285 else if (! isstringnum ( num
))
2287 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2290 if ( stricmp ( item
, "WEAPON" ) == 0 )
2292 wep
= stringtoint ( num
);
2293 if ( wep
>= WNA
|| wep
< 1 )
2295 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2302 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2303 else if ( p
-> gold
< prices
[ wep
- 1 ])
2304 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2307 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2309 p
-> gold
-= prices
[ wep
- 1 ];
2312 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2314 wep
= stringtoint ( num
);
2315 if ( wep
>= WNA
|| wep
< 1 )
2317 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2324 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2325 else if ( p
-> gold
< prices
[ wep
- 1 ])
2326 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2329 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2331 p
-> gold
-= prices
[ wep
- 1 ];
2335 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2339 if ( stricmp ( item
, "WEAPON" ) == 0 )
2343 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2346 else if ( p
-> gold
== 2000000000 )
2348 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2351 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2353 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2354 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2355 p
-> gold
= 2000000000 ;
2360 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2361 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2365 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2371 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2374 if ( p
-> gold
== 2000000000 )
2376 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2379 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2381 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2382 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2383 p
-> gold
= 2000000000 ;
2388 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2389 ( prices
[ p
-> armor
- 1 ] / 2 ));
2391 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2397 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2398 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2399 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2404 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2405 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2406 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2410 void do_inventory ( char * u
)
2414 if (!( user
= find ( u
)))
2416 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2419 else if ( isIgnore ( user
))
2422 log ( "Ignoring %s ." , user
-> getNick ());
2426 else if (! is_playing ( user
))
2428 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2431 updateTS ( user
-> stats
);
2432 showinventory ( user
, user
);
2434 void showinventory ( aClient
* from
, aClient
* to
)
2436 char * nick
= to
-> getNick ();
2440 if ( is_playing ( from
))
2442 Pouch
* p
= & from
-> stats
-> inventory
;
2443 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2444 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2445 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2446 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2447 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2450 void do_tavern ( char * u
)
2452 char * cmd
= strtok ( NULL
, " " );
2458 if (!( user
= find ( u
)))
2460 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2463 else if ( isIgnore ( user
))
2466 log ( "Ignoring %s ." , user
-> getNick ());
2470 else if (! is_playing ( user
))
2472 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2475 else if ( is_fighting ( user
))
2477 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2481 updateTS ( user
-> stats
);
2486 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2487 notice ( s_GameServ
, u
, "Your commands:" );
2488 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2489 notice ( s_GameServ
, u
, "What'll it be?" );
2491 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2493 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2494 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2495 1000 * p
-> level
* 4 );
2496 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2497 2500 * p
-> level
* 4 );
2498 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2499 3000 * p
-> level
* 4 );
2500 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2501 2000 * p
-> level
* 4 );
2502 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2503 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2505 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2507 char * chnum
= strtok ( NULL
, " " );
2508 int num
= stringtoint ( chnum
);
2512 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2513 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2516 if ( num
< 1 || num
> 4 )
2518 notice ( s_GameServ
, u
, "Invalid Choice!" );
2519 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2520 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2521 1000 * p
-> level
* 4 );
2522 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2523 2500 * p
-> level
* 4 );
2524 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2525 3000 * p
-> level
* 4 );
2526 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2527 2000 * p
-> level
* 4 );
2528 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2529 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2535 price
= ( 1000 * p
-> level
* 4 );
2536 if ( p
-> gold
>= price
)
2538 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2539 p
-> inventory
. incHealing ();
2543 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2546 price
= 2500 * p
-> level
* 4 ;
2547 if ( p
-> gold
>= price
)
2549 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2550 p
-> inventory
. incStrength ();
2554 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2557 price
= 3000 * p
-> level
* 4 ;
2558 if ( p
-> gold
>= price
)
2560 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2561 p
-> inventory
. incDefense ();
2565 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2568 price
= 3000 * p
-> level
* 4 ;
2569 if ( p
-> gold
>= price
)
2571 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2572 p
-> inventory
. incHP ();
2576 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2579 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2585 notice ( s_GameServ
, u
, "Improper Syntax." );
2586 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2590 void do_bank ( char * u
)
2592 char * cmd
= strtok ( NULL
, " " );
2593 char * amount
= strtok ( NULL
, " " );
2594 char * nick
= strtok ( NULL
, " " );
2599 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2601 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2602 notice ( s_GameServ
, u
, "BANK BALANCE" );
2605 else if (!( user
= find ( u
)))
2607 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2609 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2612 else if ( isIgnore ( user
))
2615 log ( "Ignoring %s ." , user
-> getNick ());
2619 else if (! is_playing ( user
))
2621 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2624 else if ( is_fighting ( user
))
2626 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2629 updateTS ( user
-> stats
);
2630 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2635 else if (! isAlive ( user
-> stats
))
2637 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2640 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2642 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2648 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2650 if ( p
-> bank
== 2000000000 )
2652 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2655 else if ( stricmp ( amount
, "ALL" ) == 0 )
2657 if ( 2000000000 - p
-> bank
< p
-> gold
)
2659 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2660 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2661 p
-> gold
-= ( 2000000000 - p
-> bank
);
2662 p
-> bank
= 2000000000 ;
2667 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2673 else if ( stringtoint ( amount
) > p
-> gold
)
2675 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2681 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2683 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2684 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2685 p
-> gold
-= ( 2000000000 - p
-> bank
);
2686 p
-> bank
= 2000000000 ;
2691 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2692 p
-> bank
+= stringtoint ( amount
);
2693 p
-> gold
-= stringtoint ( amount
);
2698 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2700 if ( p
-> gold
== 2000000000 )
2702 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2706 else if ( stricmp ( amount
, "ALL" ) == 0 )
2708 if ( 2000000000 - p
-> gold
< p
-> bank
)
2710 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2711 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2712 p
-> bank
-= ( 2000000000 - p
-> gold
);
2713 p
-> gold
= 2000000000 ;
2718 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2724 else if ( stringtoint ( amount
) > p
-> bank
)
2726 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2732 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2734 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2735 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2736 ( 2000000000 - p
-> gold
));
2737 p
-> bank
-= ( 2000000000 - p
-> gold
);
2738 p
-> gold
= 2000000000 ;
2743 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2744 p
-> gold
+= stringtoint ( amount
);
2745 p
-> bank
-= stringtoint ( amount
);
2753 void do_dragon ( char * u
)
2757 if (!( user
= find ( u
)))
2759 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2762 else if ( isIgnore ( user
))
2765 log ( "Ignoring %s ." , user
-> getNick ());
2769 else if (! is_playing ( user
))
2771 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2774 else if ( is_fighting ( user
))
2776 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2779 else if (! isAlive ( user
-> stats
))
2781 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2784 else if ( user
-> stats
-> level
< REALLEVELS
)
2786 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2787 "to vanquish any foe should DARE fight the dragon!" );
2788 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2789 "You are too weak. You must be Level %d !" , REALLEVELS
);
2793 updateTS ( user
-> stats
);
2795 Player
* p
= user
-> stats
;
2796 p
-> fight
= new Monster ( boss
);
2797 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2798 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2799 "deep, red fog rolls in. The air is filled with the " \
2800 "heated mist of deadly fire from beyond the cave " \
2802 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2803 "your %s , and venture into the hot, dark cave. " \
2804 "You are surprised at the angle of descent as you climb " \
2805 "lower and lower, deeper into the dragon's den." );
2806 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2807 "a tooth. It is a large tooth... bigger than your torso." \
2808 " Suddenly the darkness lifts from the gleam of an eye " \
2809 " staring into your soul! The eye is large... HUGE!" );
2810 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2811 "glare orange! The tooth is moving... but it is still too " \
2812 "dark for you to make out.... THE DRAGON! You see it!" );
2816 void do_master ( char * u
)
2821 if (!( user
= find ( u
)))
2823 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2826 else if ( isIgnore ( user
))
2829 log ( "Ignoring %s ." , user
-> getNick ());
2833 else if (! is_playing ( user
))
2835 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2838 else if ( is_fighting ( user
))
2840 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2843 else if (! isAlive ( user
-> stats
))
2845 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2849 updateTS ( user
-> stats
);
2851 char * cmd
= strtok ( NULL
, " " );
2852 Player
* p
= user
-> stats
;
2857 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2901 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
2905 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2911 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2915 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2923 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
));
2926 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2929 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
);
2931 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2937 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2941 void see_master ( char * u
)
2945 if (!( user
= find ( u
)))
2947 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2951 if (! is_fighting ( user
) && is_playing ( user
))
2953 Player
* p
= user
-> stats
;
2954 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2955 p
-> fight
= p
-> master
;
2956 display_monster ( u
); // Since master is the same structure, use this function
2960 void showBankBalance ( const char * u
)
2965 if (!( user
= find ( u
)))
2973 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2979 ListNode
< aClient
> * it
;
2981 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2983 it
= players
[ x
]. First ();
2987 p
= it
-> getData ()-> stats
;
2994 void refresh ( Player
* p
)
2999 if ( p
-> hp
< p
-> maxhp
)
3001 p
-> forest_fights
= forestfights
;
3002 p
-> player_fights
= 3 ;
3007 void do_refresh ( char * u
)
3009 char * nick
= strtok ( NULL
, " " );
3012 if (!( user
= find ( u
)))
3014 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3015 log ( "Error: aClient not found: %s " , u
);
3018 else if ( isIgnore ( user
))
3021 log ( "Ignoring %s ." , user
-> getNick ());
3025 else if (! isAdmin ( user
))
3027 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3032 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3035 else if ( stricmp ( nick
, "ALL" ) == 0 )
3037 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3040 else if (( user
= findplayer ( nick
)))
3042 if ( is_playing ( user
))
3045 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3047 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3049 refresh ( user
-> stats
);
3054 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3056 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3062 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3070 ListNode
< aClient
> * it
;
3073 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3075 it
= players
[ x
]. First ();
3079 p
= it
-> getData ()-> stats
;
3086 void reset ( Player
* p
)
3094 void updateTS ( Player
* p
)
3100 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3102 p
-> lastcommand
= time ( NULL
);
3104 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3109 bool timedOut ( Player
* p
)
3113 else if ( p
-> lastcommand
== 0 )
3117 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3124 void timeOutEvent ( Player
* p
)
3126 aClient
* user
= findplayer ( p
-> name
);
3128 if (! user
|| ! p
-> client
) // then they're not playing
3131 char * nick
= user
-> getNick ();
3133 if ( player_fight ( user
) && isYourTurn ( p
))
3135 // Check to see if they were the idler or if it was the other
3137 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3139 // This person's last command was given earlier,
3140 // so this person is the idler
3141 notice ( s_GameServ
, nick
, "You timed out " \
3142 "during a fight. You lose your turn!" );
3143 notice ( s_GameServ
, p
-> battle
-> getNick (),
3144 " %s hesitated for too long. Your move." , p
-> name
);
3146 setYourTurn ( p
-> battle
-> stats
);
3148 // Update the TS for both players to give them another
3149 // Chance to wake up, but if the other player doesn't
3150 // Attack now, they both get logged out.
3152 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3153 display_players ( p
-> battle
);
3158 notice ( s_GameServ
, p
-> battle
-> getNick (),
3159 "You and %s timed out at the same time." \
3160 " Don't fight if you're just going to " \
3161 "sit there!" , p
-> name
);
3162 notice ( s_GameServ
, user
-> getNick (),
3163 "You and %s timed out at the same time." \
3164 " Don't fight if you're just going to " \
3165 "sit there!" , p
-> battle
-> stats
-> name
);
3171 else if (! player_fight ( user
))
3173 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3175 // Place fun stuff here :)
3176 int randnum
= 1 + rand () % 100 ; // 1-100
3177 #define GSN(s) notice(s_GameServ, nick, s)
3178 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3182 // 35-100% of your gold goes pffft - kain
3183 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3185 GSN ( "You stop for a moment to rest on the " \
3186 "street corner. All of a sudden, you " \
3187 "are ambushed from all sides by a hoarde " \
3188 "of knife wielding thugs." );
3189 GSN2 ( "The thugs beat you into utter submission " \
3190 "and steal %d gold from you!" , stolen
);
3191 user
-> stats
-> gold
-= stolen
;
3193 else if ( randnum
>= 50 && randnum
< 75 )
3195 // 25-65% of your gold goes pffft - kain
3196 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3197 GSN ( "While dilly dallying around, you lose " \
3198 "your sense of time. Little did you know, " \
3199 "but thieves lifted your gold while you " \
3200 "weren't watching." );
3201 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3202 user
-> stats
-> gold
-= stolen
;
3204 else if ( randnum
>= 75 )
3206 // 25-75% of your gold goes pffft - kain
3207 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3208 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3209 "goblins grabbed your gold!" );
3210 GSN2 ( "They stole %d gold from you!" , stolen
);
3211 user
-> stats
-> gold
-= stolen
;
3215 // Always log out the user
3220 void do_reset ( char * u
)
3222 char * nick
= strtok ( NULL
, " " );
3225 if (!( user
= find ( u
)))
3227 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3228 log ( "Error: aClient not found: %s " , u
);
3231 else if (! isAdmin ( user
))
3233 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3239 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3242 else if ( stricmp ( nick
, "ALL" ) == 0 )
3244 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3247 else if (( user
= findbyrealnick ( nick
)))
3249 if ( is_playing ( user
))
3252 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3254 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3261 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3263 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3269 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3274 void do_help ( char * u
)
3276 char * cmd
= strtok ( NULL
, " " );
3278 display_help ( u
, cmd
);
3281 void display_help ( char * u
, char * file
)
3288 infile
. open ( "helpfiles/help" );
3291 log ( "Error opening helpfiles/help" );
3292 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3295 buf
= new char [ 1024 ];
3296 while ( infile
. getline ( buf
, 1024 ))
3298 // Written this way, it will process %S in the helpfiles
3299 // Instead of notice(s_GameServ, u, "%s", buf);
3300 notice ( s_GameServ
, u
, buf
);
3304 aClient
* user
= find ( u
);
3305 if ( user
&& isAdmin ( user
))
3306 display_help ( u
, "admin_commands" );
3311 filename
= new char [ strlen ( file
) + 11 ];
3312 strcpy ( filename
, "helpfiles/" );
3313 strcat ( filename
, file
);
3315 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3316 filename
[ x
] = tolower ( filename
[ x
]);
3318 infile
. open ( filename
);
3322 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3325 buf
= new char [ 1024 ];
3326 while ( infile
. getline ( buf
, 1024 ))
3328 // Written this way, it will process %S in the helpfiles
3329 // Instead of notice(s_GameServ, u, "%s", buf);
3330 notice ( s_GameServ
, u
, buf
);
3337 void do_admin ( char * u
)
3340 char * pass
= strtok ( NULL
, " " );
3342 if (!( user
= find ( u
)))
3344 log ( "Error: aClient not found: %s " , u
);
3345 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3351 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3357 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3360 else if ( strcmp ( pass
, adminpass
) == 0 )
3362 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3365 log ( " %s became an administrator." , user
-> getRealNick ());
3367 log ( " %s became an administrator." , user
-> getNick ());
3372 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3377 bool load_monsters ()
3380 infile
. open ( "monsters.dat" );
3386 log ( "Error opening monsters.dat" );
3390 buf
= new char [ 2048 ];
3393 log ( "Loading monsters from monsters.dat" );
3396 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
3398 for ( int m
= 0 ; m
< MONSTERS
;)
3400 infile
. getline ( buf
, 2048 );
3401 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3405 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
3406 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
3407 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
3408 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
3409 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
3410 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
3411 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
3412 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));
3421 // this will be hash.cpp start
3422 // thank you wcampbel
3423 unsigned long sHASH ( const unsigned char * name
)
3425 unsigned long h
= 0 , g
;
3429 h
= ( h
<< 4 ) + (* name
++); // Case sensitive for numerics
3430 if (( g
= ( h
& 0xF0000000 )))
3434 return h
% U_TABLE_SIZE
;
3437 unsigned long iHASH ( const unsigned char * name
)
3439 unsigned long h
= 0 , g
;
3443 h
= ( h
<< 4 ) + tolower (* name
++);
3444 if (( g
= ( h
& 0xF0000000 )))
3448 return h
% U_TABLE_SIZE
;
3451 // this will be hash.cpp end