]>
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
);
410 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
415 char * spaces ( int len
, char * seperator
)
418 final
= new char [ 30 ];
420 strcpy ( final
, seperator
);
421 for ( y
= 0 ; y
< 30 - len
; y
++)
422 strcat ( final
, seperator
);
426 void raw ( const char * fmt
, ...)
431 input
= new char [ 1024 ];
433 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
439 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
440 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
441 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
444 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
449 sprintf ( input
, " %s%c " , input
, * t
);
454 log ( "Input: %s " , input
);
457 sprintf ( input
, " %s%s " , input
, " \r\n " );
458 sock_puts ( sock
, input
);
462 /* Send a NOTICE from the given source to the given nick. */
464 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
470 commanduse
= new char [ 16 ];
474 strcpy ( commanduse
, "P" );
476 strcpy ( commanduse
, "O" );
480 strcpy ( commanduse
, "PRIVMSG" );
482 strcpy ( commanduse
, "NOTICE" );
488 input
= new char [ 1024 ];
495 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
497 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
505 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
507 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
516 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
517 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
518 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
521 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
526 sprintf ( input
, " %s%c " , input
, * t
);
531 log ( "Input: %s " , input
);
533 sprintf ( input
, " %s%s " , input
, " \r\n " );
534 sock_puts ( sock
, input
);
535 delete [] commanduse
;
541 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
547 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
548 if ( c
== 0 || -- len
== 0 )
553 if ( c
< tolower (* s2
))
559 char * strtok ( char * str
, const char * delim
)
561 static char * current
= NULL
;
568 current
+= strspn ( current
, delim
);
569 ret
= * current
? current
: NULL
;
570 current
+= strcspn ( current
, delim
);
579 void do_list ( char * u
)
582 char * cmd
= strtok ( NULL
, " " );
584 if (!( user
= find ( u
)))
586 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
589 else if ( isIgnore ( user
))
592 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
597 ListNode
< aClient
> * temp
;
600 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
602 temp
= players
[ x
]. First ();
603 if (! players
[ x
]. isEmpty ())
607 if (! cmd
|| is_playing ( temp
-> getData ()))
611 notice ( s_GameServ
, u
, "Players:" );
615 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
616 temp
-> getData ()-> stats
-> name
);
618 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
619 temp
-> getData ()-> stats
-> name
);
628 notice ( s_GameServ
, u
, "No one is playing" );
630 notice ( s_GameServ
, u
, "End of List" );
634 void do_logout ( char * u
)
637 char * name
= strtok ( NULL
, " " );
639 if (!( user
= find ( u
)))
641 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
642 "Buf: %s LOGOUT" , u
);
643 log ( "Could not find aClient Buf: %s LOGOUT" ,
647 else if ( isIgnore ( user
))
650 log ( "Ignoring %s ." , user
-> getNick ());
659 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
661 else if (!( user
= findplayer ( name
)))
663 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
667 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
673 if (! is_playing ( user
))
675 notice ( s_GameServ
, u
, "You're not logged in!" );
677 else if ( is_fighting ( user
))
679 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
683 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
689 void logout ( aClient
* user
)
691 if ( is_playing ( user
))
693 ListNode
< aClient
> * it
;
695 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
696 it
= players
[ hv
]. Find ( user
);
700 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
701 " %S Admin. Cannot find you in the players list." );
702 log ( "Error on logout(). Can't find %s in the players list" ,
713 temp
-> stats
= new Player
;
714 temp
-> stats
-> setData ( user
-> stats
);
715 user
-> stats
-> client
= NULL
;
717 if ( player_fight ( user
))
718 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
722 temp
-> stats
-> client
= NULL
;
724 temp
-> setRealNick ( "Not Playing" );
726 temp
-> setNick ( "Not Playing" );
730 log ( "Logged out player %s " ,
742 void do_register ( char * u
)
744 char * password
, * name
;
746 name
= strtok ( NULL
, " " );
747 password
= strtok ( NULL
, " " );
749 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
752 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
753 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
758 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
762 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
764 else if (( user
= findplayer ( name
)))
766 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
767 notice ( s_GameServ
, u
, "Choose another name!" );
769 else if (!( user
= find ( u
)))
771 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
773 else if ( isIgnore ( user
))
776 log ( "Ignoring %s ." , user
-> getNick ());
782 if (! is_playing ( user
))
784 ListNode
< aClient
> * temp
;
785 user
-> stats
= new Player ( user
);
786 user
-> stats
-> client
= user
; // Set the backwards pointer
787 user
-> stats
-> reset (); // set the user up
788 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
789 strncpy ( user
-> stats
-> name
, name
, 255 );
790 unsigned long hv
= iHASH (( unsigned char *) name
);
791 updateTS ( user
-> stats
);
792 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
793 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
795 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
796 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
797 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
798 setPlaying ( user
); // set the playing flag
802 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
807 void do_identify ( char * u
)
809 char * password
, * name
;
811 name
= strtok ( NULL
, " " );
812 password
= strtok ( NULL
, " " );
813 if (! password
|| ! name
)
815 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
817 else if (!( user
= find ( u
)))
819 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
820 log ( "Error: aClient not found: %s " , u
);
822 else if ( isIgnore ( user
))
825 log ( "Ignoring %s ." , user
-> getNick ());
829 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
830 notice ( s_GameServ
, u
, "Player %s not found" , name
);
831 else if ( is_playing ( user
))
833 notice ( s_GameServ
, u
, "You are already playing!" );
835 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
837 notice ( s_GameServ
, u
, "That player has already identified." );
839 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
841 notice ( s_GameServ
, u
, "Password incorrect" );
844 ListNode
< aClient
> * temp
;
845 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
846 temp
= players
[ hv
]. Find ( p
);
849 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
853 user
-> stats
= new Player ( p
-> stats
-> name
);
855 log ( "Setting data for identified" );
857 user
-> stats
-> setData ( p
-> stats
);
858 user
-> stats
-> client
= user
;
859 updateTS ( user
-> stats
);
863 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
867 setPlaying ( user
); // set the playing flag
870 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
874 void do_stats ( char * u
)
879 nick
= strtok ( NULL
, " " );
881 if (!( user
= find ( u
)))
883 log ( "Fatal Error: %s not found in client list" , u
);
886 else if ( isIgnore ( user
))
889 log ( "Ignoring %s ." , user
-> getNick ());
895 if (! is_playing ( user
))
897 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
902 updateTS ( user
-> stats
);
903 showstats ( u
, user
-> stats
-> name
);
913 log ( "Calling delete_masters()" );
919 log ( "Initializing masters" );
922 for ( int x
= 0 ; x
< LEVELS
; x
++)
923 masters
[ x
] = new Monster
;
925 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
926 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
927 masters
[ 0 ]-> strength
= 30 ;
928 masters
[ 0 ]-> gold
= 0 ;
930 masters
[ 0 ]-> maxhp
= 35 ;
932 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!" );
934 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
935 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
936 masters
[ 1 ]-> strength
= 45 ;
937 masters
[ 1 ]-> gold
= 0 ;
939 masters
[ 1 ]-> maxhp
= 51 ;
941 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." );
943 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
944 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
945 masters
[ 2 ]-> strength
= 83 ;
946 masters
[ 2 ]-> gold
= 0 ;
948 masters
[ 2 ]-> maxhp
= 100 ;
949 masters
[ 2 ]-> hp
= 100 ;
950 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!" );
953 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
954 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
955 masters
[ 3 ]-> strength
= 159 ;
956 masters
[ 3 ]-> gold
= 0 ;
958 masters
[ 3 ]-> maxhp
= 165 ;
959 masters
[ 3 ]-> hp
= 165 ;
960 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
962 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
963 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
964 masters
[ 4 ]-> strength
= 260 ;
965 masters
[ 4 ]-> gold
= 0 ;
967 masters
[ 4 ]-> maxhp
= 232 ;
968 masters
[ 4 ]-> hp
= 232 ;
969 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!" );
971 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
972 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
973 masters
[ 5 ]-> strength
= 325 ;
974 masters
[ 5 ]-> gold
= 0 ;
976 masters
[ 5 ]-> maxhp
= 504 ;
977 masters
[ 5 ]-> hp
= 504 ;
978 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
981 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
982 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
983 masters
[ 6 ]-> strength
= 380 ;
984 masters
[ 6 ]-> gold
= 0 ;
986 masters
[ 6 ]-> maxhp
= 1078 ;
987 masters
[ 6 ]-> hp
= 1078 ;
988 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
990 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
991 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
992 masters
[ 7 ]-> strength
= 462 ;
993 masters
[ 7 ]-> gold
= 0 ;
995 masters
[ 7 ]-> maxhp
= 2207 ;
996 masters
[ 7 ]-> hp
= 2207 ;
997 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
1000 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
1001 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
1002 masters
[ 8 ]-> strength
= 511 ;
1003 masters
[ 8 ]-> gold
= 0 ;
1004 masters
[ 8 ]-> exp
= 0 ;
1005 masters
[ 8 ]-> maxhp
= 2780 ;
1006 masters
[ 8 ]-> hp
= 2780 ;
1007 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1009 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1010 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1011 masters
[ 9 ]-> strength
= 618 ;
1012 masters
[ 9 ]-> gold
= 0 ;
1013 masters
[ 9 ]-> exp
= 0 ;
1014 masters
[ 9 ]-> maxhp
= 3046 ;
1015 masters
[ 9 ]-> hp
= 3046 ;
1016 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1018 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1019 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1020 masters
[ 10 ]-> strength
= 725 ;
1021 masters
[ 10 ]-> gold
= 0 ;
1022 masters
[ 10 ]-> exp
= 0 ;
1023 masters
[ 10 ]-> maxhp
= 3988 ;
1024 masters
[ 10 ]-> hp
= 3988 ;
1025 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." );
1028 void init_monsters ()
1031 log ( "Calling delete_monsters" );
1036 for ( int x
= 0 ; x
< LEVELS
; x
++)
1037 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1038 monsters
[ x
][ y
] = new Monster ();
1041 void delete_monsters ()
1043 for ( int x
= 0 ; x
< LEVELS
; x
++)
1044 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1046 delete monsters
[ x
][ y
];
1049 void delete_masters ()
1051 for ( int x
= 0 ; x
< LEVELS
; x
++)
1056 void display_monster ( char * u
)
1060 aClient
* user
= find ( u
);
1061 Player
* ni
= user
-> stats
;
1063 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1064 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
1065 notice ( s_GameServ
, u
, "Here are your commands:" );
1066 notice ( s_GameServ
, u
, "/msg %S attack" );
1067 notice ( s_GameServ
, u
, "/msg %S run" );
1068 notice ( s_GameServ
, u
, "What will you do?" );
1072 void display_players ( char * u
)
1075 if (!( user
= find ( u
)))
1077 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1080 display_players ( user
);
1083 void display_players ( aClient
* user
)
1085 char * u
= user
-> getNick ();
1086 if ( is_playing ( user
) && player_fight ( user
))
1088 aClient
* battle
= user
-> stats
-> battle
;
1089 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1090 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
1091 notice ( s_GameServ
, u
, "Here are your commands:" );
1092 notice ( s_GameServ
, u
, "/msg %S attack" );
1093 notice ( s_GameServ
, u
, "/msg %S run" );
1094 notice ( s_GameServ
, u
, "What will you do?" );
1099 bool is_playing ( char * u
)
1102 if (!( user
= find ( u
)))
1105 return is_playing ( user
);
1108 bool is_playing ( aClient
* user
)
1110 if ( user
-> stats
== NULL
)
1114 else if ( user
-> stats
-> client
== NULL
)
1118 else if (! FL_is_playing ( user
))
1126 bool is_fighting ( char * u
)
1130 if (!( user
= find ( u
)))
1133 return is_fighting ( user
);
1136 bool is_fighting ( aClient
* user
)
1138 if (! is_playing ( user
))
1141 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1144 bool player_fight ( char * u
)
1148 if (!( user
= find ( u
)))
1151 return player_fight ( user
);
1154 bool player_fight ( aClient
* user
)
1156 if (! is_playing ( user
))
1158 else if ( user
-> stats
-> battle
!= NULL
)
1160 return user
-> stats
-> battle
-> stats
!= NULL
;
1165 bool master_fight ( char * u
)
1169 if (!( user
= find ( u
)))
1172 return master_fight ( user
);
1175 bool master_fight ( aClient
* user
)
1177 if (! is_playing ( user
))
1180 return user
-> stats
-> master
!= NULL
;
1183 void do_fight ( char * u
)
1185 aClient
* ni
, * battle
;
1187 char * nick
= strtok ( NULL
, " " );
1191 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1194 else if (!( ni
= find ( u
)))
1196 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1199 else if ( isIgnore ( ni
))
1202 log ( "Ignoring %s ." , ni
-> getNick ());
1206 else if (! is_playing ( ni
))
1208 notice ( s_GameServ
, u
, "You are not playing!" );
1212 updateTS ( ni
-> stats
);
1214 if ( ni
-> stats
-> player_fights
<= 0 )
1216 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1217 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1218 "day. You have to wait until tomorrow!" );
1220 else if (!( battle
= findplayer ( nick
)))
1222 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1224 else if (! isAlive ( ni
-> stats
))
1226 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1228 else if (! is_playing ( battle
))
1230 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1233 /* offline fighting not available yet
1234 else if (!(fight = finduser(nick)))
1236 ni->stats->battle = battle;
1237 battle->battle = ni;
1238 setYourTurn(ni->stats);
1239 clearYourTurn(battle->stats);
1241 notice(s_GameServ, u, "You decide to fight %s while they're "\
1242 "not in the realm!",
1243 battle->stats->name);
1247 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1249 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1251 else if (! isAlive ( battle
-> stats
))
1253 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1255 else if ( player_fight ( battle
))
1257 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1259 else if ( master_fight ( battle
))
1261 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
);
1263 else if ( is_fighting ( battle
))
1265 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1267 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1269 // You can't fight someone below you by more than X level(s)
1270 // level 12 can fight level (12 - X) but not < (12 - X)
1271 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1272 battle
-> stats
-> name
);
1274 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1276 // You can't fight someone above you by more than X level(S)
1277 // level 1 can fight level (1 + X), but not > (1 + X)
1278 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1279 "weakling!" , ni
-> stats
-> name
);
1283 // Set your battle pointer to the other player
1284 ni
-> stats
-> battle
= battle
;
1286 // Set the other player's battle pointer to you
1287 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1289 // The initiator gets the first move (perhaps this should be 50/50)
1290 setYourTurn ( ni
-> stats
);
1291 clearYourTurn ( battle
-> stats
);
1293 // Initiate Battle sequence!
1294 ni
-> stats
-> player_fights
-= 1 ;
1296 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1297 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1298 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1299 "because they initiated!" , ni
-> stats
-> name
);
1300 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1301 display_players ( ni
);
1305 void do_use ( char * u
)
1310 char * item
= strtok ( NULL
, " " );
1314 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1315 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1318 else if (!( user
= find ( u
)))
1320 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1323 else if ( isIgnore ( user
))
1326 log ( "Ignoring %s ." , user
-> getNick ());
1330 else if (! is_playing ( user
))
1332 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1336 updateTS ( user
-> stats
);
1338 p
= & user
-> stats
-> inventory
;
1340 if ( stricmp ( item
, "HEALTH" ) == 0 )
1342 if ( p
-> Healing () <= 0 )
1344 notice ( s_GameServ
, u
, "You are out of Health Potions!" );
1347 int oldhealth
= user
-> stats
-> hp
;
1348 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1349 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1350 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1351 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealth
);
1354 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1356 if ( p
-> Strength () <= 0 )
1358 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1361 int oldstrength
= user
-> stats
-> strength
;
1362 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1363 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1364 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1365 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1368 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1370 if ( p
-> Defense () <= 0 )
1372 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1375 int olddefense
= user
-> stats
-> defense
;
1376 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1377 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1378 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1379 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1382 else if ( stricmp ( item
, "HP" ) == 0 )
1386 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1389 int oldHP
= user
-> stats
-> maxhp
;
1390 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1391 user
-> stats
-> maxhp
+= 2 +
1392 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1394 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1399 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALTH | STRENGTH | DEFENSE}" );
1403 end_turn ( user
); // If they're fighting, end their turn
1405 void do_run ( char * u
)
1408 Player
* p
, * p2
= NULL
;
1410 if (!( user
= find ( u
)))
1412 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1415 else if ( isIgnore ( user
))
1418 log ( "Ignoring %s ." , user
-> getNick ());
1422 else if (! is_playing ( user
))
1424 notice ( s_GameServ
, u
, "You must be playing to run!" );
1428 updateTS ( user
-> stats
);
1432 p2
= p
-> battle
-> stats
;
1434 if (! is_fighting ( user
))
1435 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1436 else if (! player_fight ( user
) && ! master_fight ( user
))
1438 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1442 else if ( player_fight ( user
) && isYourTurn ( p
))
1444 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1445 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1448 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1450 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1452 else if ( master_fight ( user
))
1454 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1459 void end_turn ( aClient
* user
)
1461 char * nick
, * u
= user
-> getNick ();
1466 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1468 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1471 if (! player_fight ( user
) && ! master_fight ( user
))
1472 fight
= user
-> stats
-> fight
;
1474 fight
= user
-> stats
-> master
;
1475 battle
= user
-> stats
-> battle
;
1477 if (! player_fight ( user
))
1480 mhit
= ( fight
-> strength
/ 2 ) +
1481 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1482 arbonus
[ user
-> stats
-> armor
]));
1487 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1488 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1489 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1491 if (! player_fight ( user
))
1496 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1497 fight
-> name
, fight
-> weapon
, mhit
);
1500 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1502 if ( mhit
>= user
-> stats
-> hp
)
1504 if (! master_fight ( user
))
1506 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1507 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1508 "of your experience!" );
1509 user
-> stats
-> gold
= 0 ;
1510 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1511 user
-> stats
-> hp
= 0 ;
1512 user
-> stats
-> fight
= NULL
;
1513 clearAlive ( user
-> stats
);
1518 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1519 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1520 user
-> stats
-> fight
= NULL
;
1521 user
-> stats
-> master
= NULL
;
1528 user
-> stats
-> hp
-= mhit
;
1535 clearYourTurn ( user
-> stats
);
1536 setYourTurn ( battle
-> stats
);
1537 display_players ( battle
);
1543 void do_attack ( char * u
)
1546 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1547 Monster
* fight
; // The monster they may be fighting
1549 if (!( ni
= find ( u
)))
1551 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1554 else if ( isIgnore ( ni
))
1557 log ( "Ignoring %s ." , ni
-> getNick ());
1561 else if (! is_playing ( ni
))
1563 notice ( s_GameServ
, u
, "You're not playing!" );
1566 else if (! is_fighting ( ni
))
1568 notice ( s_GameServ
, u
, "You're not in battle!" );
1573 if (! ni
-> stats
-> master
) // This is not a master fight
1574 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1575 else // This IS a master fight
1576 fight
= ni
-> stats
-> master
; // Master Could be NULL
1578 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1580 // One has to be !NULL based on the previous else if
1581 // We wouldn't be here if they were all NULL
1583 updateTS ( ni
-> stats
);
1585 if (! player_fight ( ni
))
1588 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1589 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1592 mhit
= ( fight
-> strength
/ 2 ) +
1593 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1594 arbonus
[ ni
-> stats
-> armor
]));
1599 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1600 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1601 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1604 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1605 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1606 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1609 if (! player_fight ( ni
))
1612 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1614 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1616 if ( hit
>= fight
-> hp
)
1618 if ( master_fight ( ni
))
1619 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1621 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1623 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1624 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1625 fight
-> exp
, fight
-> gold
);
1627 // If your new experience (or gold) will be greater than 2 billion,
1628 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1629 // This could be a problem with overflowing out of the sign bit.
1630 // Unsigned long int maybe? Leave it for now.
1631 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1632 ni
-> stats
-> exp
+ fight
-> exp
);
1634 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1635 ni
-> stats
-> gold
+ fight
-> gold
);
1638 if ( master_fight ( ni
))
1640 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1641 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1642 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1644 // Increase your level
1647 // Increase your maximum hit points
1648 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1650 // Heal the player by setting hp to their max
1651 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1653 // Add to your strength
1654 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1656 // Add to your defensive power
1657 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1659 // Clear the pointer for your master
1660 ni
-> stats
-> master
= NULL
;
1663 // They're dead so remove the pointer
1664 delete ni
-> stats
-> fight
;
1665 ni
-> stats
-> fight
= NULL
;
1666 ni
-> stats
-> master
= NULL
;
1676 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1677 fight
-> name
, fight
-> weapon
, mhit
);
1680 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1682 if ( mhit
>= ni
-> stats
-> hp
)
1684 if (! master_fight ( ni
))
1686 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1687 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1688 "of your experience!" );
1689 ni
-> stats
-> gold
= 0 ;
1690 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1692 ni
-> stats
-> fight
= NULL
;
1693 clearAlive ( ni
-> stats
);
1698 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1699 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1700 ni
-> stats
-> fight
= NULL
;
1701 ni
-> stats
-> master
= NULL
;
1708 ni
-> stats
-> hp
-= mhit
;
1714 else if ( player_fight ( ni
))
1716 /* Offline fighting not available yet
1717 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1720 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1722 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1723 if (hit >= battle->stats->hp)
1725 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1726 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1727 (long int)(battle->stats->exp * .10), battle->stats->gold);
1728 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1730 ni->stats->exp += (long int)(battle->stats->exp * .10);
1731 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1735 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1736 ni->stats->exp = 2000000000;
1739 if (2000000000 - ni->stats->gold > battle->stats->gold)
1741 * ni->stats->gold += battle->stats->gold;
1742 battle->stats->gold = 0;
1746 battle->stats->gold = 2000000000 - ni->stats->gold;
1747 ni->stats->gold = 2000000000;
1749 * ni->stats->battle->stats->alive = 0;
1750 ni->stats->battle->battle = NULL;
1751 ni->stats->battle = NULL;
1757 * battle->stats->hp -= hit;
1760 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1761 battle->nick, weapons[battle->stats->weapon], mhit);
1764 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1766 if (mhit >= ni->stats->hp)
1768 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1769 if (2000000000 - battle->stats->gold > ni->stats->gold)
1771 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1772 battle->stats->gold += ni->stats->gold;
1773 * ni->stats->gold = 0;
1777 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1779 ni->stats->gold -= (2000000000 - battle->stats->gold);
1780 notice(s_GameServ, u, "You were left dead with %d gold.",
1781 * (long int)ni->stats->gold);
1782 battle->stats->gold = 2000000000;
1784 ni->stats->battle->battle = NULL;
1785 ni->stats->battle = NULL;
1786 ni->stats->alive = 0;
1792 ni->stats->hp -= mhit;
1798 * end offline fighting */
1800 if ( is_playing ( battle
))
1802 if (! isYourTurn ( ni
-> stats
))
1804 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1805 battle
-> stats
-> name
);
1810 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1812 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1813 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1814 weapons
[ ni
-> stats
-> weapon
], hit
);
1815 clearYourTurn ( ni
-> stats
);
1816 setYourTurn ( battle
-> stats
);
1817 display_players ( battle
);
1821 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1822 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1823 clearYourTurn ( ni
-> stats
);
1824 setYourTurn ( battle
-> stats
);
1825 display_players ( battle
);
1827 if ( hit
>= battle
-> stats
-> hp
)
1829 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1830 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1831 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1832 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1834 battle
-> stats
-> hp
= 0 ;
1835 clearAlive ( battle
-> stats
);
1837 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1839 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1840 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1844 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1845 ni
-> stats
-> exp
= 2000000000 ;
1848 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1850 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1851 "all gold on hand!" );
1852 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1853 battle
-> stats
-> gold
= 0 ;
1857 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1858 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1860 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1861 "gold." , ni
-> stats
-> name
);
1863 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1864 "left. All is not lost!" , battle
-> stats
-> gold
);
1866 ni
-> stats
-> gold
= 2000000000 ;
1868 battle
-> stats
-> battle
= NULL
;
1869 ni
-> stats
-> battle
= NULL
;
1875 battle
-> stats
-> hp
-= hit
;
1876 clearYourTurn ( ni
-> stats
);
1877 setYourTurn ( battle
-> stats
);
1878 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1879 battle
-> stats
-> name
);
1887 void do_heal ( char * u
)
1890 char * amount
= strtok ( NULL
, " " );
1895 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1898 else if (!( ni
= find ( u
)))
1900 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1903 else if ( isIgnore ( ni
))
1906 log ( "Ignoring %s ." , ni
-> getNick ());
1910 else if (! is_playing ( ni
))
1912 notice ( s_GameServ
, u
, "You aren't playing!" );
1915 else if (! isAlive ( ni
-> stats
))
1917 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1920 else if ( is_fighting ( ni
))
1922 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1925 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1927 notice ( s_GameServ
, u
, "You don't need healing!" );
1931 updateTS ( ni
-> stats
);
1932 if ( stricmp ( amount
, "ALL" ) == 0 )
1934 price
= ni
-> stats
-> level
* 3 ;
1935 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1937 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1938 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1939 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1940 ni
-> stats
-> gold
%= price
;
1944 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1945 "per point." , price
);
1946 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1947 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1948 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1949 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1950 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1953 else if ( isstringnum ( amount
))
1955 num
= stringtoint ( amount
);
1956 price
= ni
-> stats
-> level
* 3 ;
1957 if ( ni
-> stats
-> gold
< price
* num
)
1959 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1960 ( long int ) ni
-> stats
-> gold
/ price
);
1962 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1964 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
1966 ni
-> stats
-> hp
+= num
;
1967 ni
-> stats
-> gold
-= num
* price
;
1969 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1971 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1972 "per point." , price
);
1973 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
1974 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
1975 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1976 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1979 else if ( amount
[ 0 ] == '-' )
1980 notice ( s_GameServ
, u
, "You trying to cheat?" );
1982 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1985 int isstringnum ( char * num
)
1988 for ( x
= 0 ; x
< strlen ( num
); x
++)
1990 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
1996 long int stringtoint ( char * number
)
1998 long int x
, len
= strlen ( number
), sum
= 0 ;
2000 return chartoint ( number
[ 0 ]);
2001 sum
+= chartoint ( number
[ len
- 1 ]);
2002 for ( x
= len
- 2 ; x
>= 0 ; x
--)
2003 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
2007 long int pow ( int x
, int y
)
2013 if ( x
!= 0 && y
!= 0 )
2015 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2023 long int chartoint ( char ch
)
2025 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2026 return int ( ch
) - 48 ;
2033 ListNode
< aClient
> * ptr
;
2037 outfile
. open ( playerdata
);
2041 log ( "Error opening %s " , playerdata
);
2045 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2047 ptr
= players
[ x
]. First ();
2050 it
= ptr
-> getData ()-> stats
;
2052 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2053 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2054 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2055 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2056 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2057 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
2070 char * tempname
, * buf
, * password
;
2071 buf
= new char [ 1023 ];
2073 infile
. open ( playerdata
);
2077 log ( "Error opening %s " , playerdata
);
2081 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2084 tempname
= strtok ( buf
, " " );
2085 temp
-> stats
= new Player ( tempname
);
2088 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2089 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2090 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2091 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2092 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2093 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2094 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2095 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2096 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2097 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2098 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2099 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2100 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2102 password
= strtok ( NULL
, " " );
2103 strcpy ( p
-> password
, password
);
2104 temp
-> setNick ( "Not Playing" );
2106 temp
-> setRealNick ( "Not Playing" );
2109 p
-> inventory
. reset (); // Set inventory to all 0s
2110 // Old player databases didn't have these three extra values
2111 // If they come up null, leave them to 0 as the default.
2112 // On the next gameserv database save, it will save the values.
2113 tempname
= strtok ( NULL
, " " );
2115 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2117 tempname
= strtok ( NULL
, " " );
2119 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2121 tempname
= strtok ( NULL
, " " );
2123 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2125 tempname
= strtok ( NULL
, " " );
2127 p
-> inventory
. setHP ( stringtoint ( tempname
));
2128 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2130 temp
-> stats
-> client
= NULL
;
2131 players
[ hv
]. insertAtBack ( temp
);
2139 bool passcmp ( char * encrypted
, char * plaintext
)
2142 char * plaintext2
, * plainToencrypt
;
2145 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2146 strcpy ( plaintext2
, plaintext
);
2148 salt
[ 0 ] = encrypted
[ 0 ];
2149 salt
[ 1 ] = encrypted
[ 1 ];
2152 plainToencrypt
= crypt ( plaintext2
, salt
);
2154 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2156 delete [] plaintext2
;
2161 bool check_password ( char * name
, char * plaintext
)
2165 if (!( client
= findplayer ( name
)))
2169 return passcmp ( client
-> stats
-> password
, plaintext
);
2173 void do_store ( char * u
)
2175 char * cmd
= strtok ( NULL
, " " );
2176 char * item
= strtok ( NULL
, " " );
2177 char * num
= strtok ( NULL
, " " );
2185 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2186 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2187 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2190 else if (!( user
= find ( u
)))
2192 log ( "Fatal Error: could not find %s in client list" , u
);
2195 else if ( isIgnore ( user
))
2198 log ( "Ignoring %s ." , user
-> getNick ());
2202 else if (! is_playing ( user
))
2204 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2207 else if (! isAlive ( user
-> stats
))
2209 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2212 updateTS ( user
-> stats
);
2214 if ( stricmp ( cmd
, "LIST" ) == 0 )
2216 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2218 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2219 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2220 for ( int x
= 1 ; x
< WNA
; x
++)
2222 space
= spaces ( strlen ( weapons
[ x
]), "." );
2223 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2226 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2227 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2230 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2232 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2233 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2234 for ( int x
= 1 ; x
< WNA
; x
++)
2236 space
= spaces ( strlen ( armors
[ x
]), "." );
2237 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2240 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2241 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2245 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2248 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2251 else if (! isstringnum ( num
))
2253 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2256 if ( stricmp ( item
, "WEAPON" ) == 0 )
2258 wep
= stringtoint ( num
);
2259 if ( wep
>= WNA
|| wep
< 1 )
2261 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2268 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2269 else if ( p
-> gold
< prices
[ wep
- 1 ])
2270 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2273 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2275 p
-> gold
-= prices
[ wep
- 1 ];
2278 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2280 wep
= stringtoint ( num
);
2281 if ( wep
>= WNA
|| wep
< 1 )
2283 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2290 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2291 else if ( p
-> gold
< prices
[ wep
- 1 ])
2292 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2295 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2297 p
-> gold
-= prices
[ wep
- 1 ];
2301 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2305 if ( stricmp ( item
, "WEAPON" ) == 0 )
2309 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2312 else if ( p
-> gold
== 2000000000 )
2314 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2317 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2319 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2320 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2321 p
-> gold
= 2000000000 ;
2326 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2327 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2331 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2337 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2340 if ( p
-> gold
== 2000000000 )
2342 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2345 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2347 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2348 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2349 p
-> gold
= 2000000000 ;
2354 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2355 ( prices
[ p
-> armor
- 1 ] / 2 ));
2357 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2363 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2364 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2365 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2370 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2371 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2372 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2376 void do_inventory ( char * u
)
2380 if (!( user
= find ( u
)))
2382 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2385 else if ( isIgnore ( user
))
2388 log ( "Ignoring %s ." , user
-> getNick ());
2392 else if (! is_playing ( user
))
2394 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2397 updateTS ( user
-> stats
);
2398 showinventory ( user
, user
);
2400 void showinventory ( aClient
* from
, aClient
* to
)
2402 char * nick
= to
-> getNick ();
2406 if ( is_playing ( from
))
2408 Pouch
* p
= & from
-> stats
-> inventory
;
2409 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2410 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2411 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2412 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2413 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2416 void do_tavern ( char * u
)
2418 char * cmd
= strtok ( NULL
, " " );
2423 if (!( user
= find ( u
)))
2425 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2428 else if ( isIgnore ( user
))
2431 log ( "Ignoring %s ." , user
-> getNick ());
2435 else if (! is_playing ( user
))
2437 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2440 else if ( is_fighting ( user
))
2442 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2446 updateTS ( user
-> stats
);
2451 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2452 notice ( s_GameServ
, u
, "Your commands:" );
2453 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2454 notice ( s_GameServ
, u
, "What'll it be?" );
2456 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2458 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2459 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 100 * p
-> level
+ ( p
-> exp
/ 10 ));
2460 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 205 * p
-> level
+ ( p
-> exp
/ 10 ));
2461 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 200 * p
-> level
+ ( p
-> exp
/ 10 ));
2462 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 230 * p
-> level
+ ( p
-> exp
/ 10 ));
2463 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2464 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2465 notice ( s_GameServ
, u
, "By something will ya!" );
2467 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2469 char * chnum
= strtok ( NULL
, " " );
2470 int num
= stringtoint ( chnum
);
2474 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2475 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2478 if ( num
< 1 || num
> 4 )
2480 notice ( s_GameServ
, u
, "Invalid Choice!" );
2481 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2482 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 100 * p
-> level
+ ( p
-> exp
/ 10 ));
2483 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 205 * p
-> level
+ ( p
-> exp
/ 10 ));
2484 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 200 * p
-> level
+ ( p
-> exp
/ 10 ));
2485 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 230 * p
-> level
+ ( p
-> exp
/ 10 ));
2486 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2487 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2493 price
= ( 100 * p
-> level
) + ( p
-> exp
/ 10 );
2494 if ( p
-> gold
>= price
)
2496 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2497 p
-> inventory
. incHealing ();
2501 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2504 price
= ( 205 * p
-> level
) + ( p
-> exp
/ 10 );
2505 if ( p
-> gold
>= price
)
2507 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2508 p
-> inventory
. incStrength ();
2512 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2515 price
= ( 200 * p
-> level
) + ( p
-> exp
/ 10 );
2516 if ( p
-> gold
>= price
)
2518 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2519 p
-> inventory
. incDefense ();
2523 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2526 price
= ( 230 * p
-> level
) + ( p
-> exp
/ 10 );
2527 if ( p
-> gold
>= price
)
2529 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2530 p
-> inventory
. incHP ();
2534 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2537 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2543 notice ( s_GameServ
, u
, "Improper Syntax." );
2544 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2548 void do_bank ( char * u
)
2550 char * cmd
= strtok ( NULL
, " " );
2551 char * amount
= strtok ( NULL
, " " );
2552 char * nick
= strtok ( NULL
, " " );
2557 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2559 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2560 notice ( s_GameServ
, u
, "BANK BALANCE" );
2563 else if (!( user
= find ( u
)))
2565 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2567 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2570 else if ( isIgnore ( user
))
2573 log ( "Ignoring %s ." , user
-> getNick ());
2577 else if (! is_playing ( user
))
2579 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2582 else if ( is_fighting ( user
))
2584 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2587 updateTS ( user
-> stats
);
2588 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2593 else if (! isAlive ( user
-> stats
))
2595 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2598 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2600 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2606 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2608 if ( p
-> bank
== 2000000000 )
2610 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2613 else if ( stricmp ( amount
, "ALL" ) == 0 )
2615 if ( 2000000000 - p
-> bank
< p
-> gold
)
2617 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2618 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2619 p
-> gold
-= ( 2000000000 - p
-> bank
);
2620 p
-> bank
= 2000000000 ;
2625 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2631 else if ( stringtoint ( amount
) > p
-> gold
)
2633 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2639 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2641 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2642 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2643 p
-> gold
-= ( 2000000000 - p
-> bank
);
2644 p
-> bank
= 2000000000 ;
2649 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2650 p
-> bank
+= stringtoint ( amount
);
2651 p
-> gold
-= stringtoint ( amount
);
2656 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2658 if ( p
-> gold
== 2000000000 )
2660 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2664 else if ( stricmp ( amount
, "ALL" ) == 0 )
2666 if ( 2000000000 - p
-> gold
< p
-> bank
)
2668 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2669 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2670 p
-> bank
-= ( 2000000000 - p
-> gold
);
2671 p
-> gold
= 2000000000 ;
2676 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2682 else if ( stringtoint ( amount
) > p
-> bank
)
2684 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2690 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2692 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2693 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2694 ( 2000000000 - p
-> gold
));
2695 p
-> bank
-= ( 2000000000 - p
-> gold
);
2696 p
-> gold
= 2000000000 ;
2701 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2702 p
-> gold
+= stringtoint ( amount
);
2703 p
-> bank
-= stringtoint ( amount
);
2711 void do_dragon ( char * u
)
2715 if (!( user
= find ( u
)))
2717 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2720 else if ( isIgnore ( user
))
2723 log ( "Ignoring %s ." , user
-> getNick ());
2727 else if (! is_playing ( user
))
2729 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2732 else if ( is_fighting ( user
))
2734 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2737 else if (! isAlive ( user
-> stats
))
2739 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2742 else if ( user
-> stats
-> level
< 12 )
2744 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2745 "to vanquish any foe should DARE fight the dragon!" );
2746 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2747 "You are too weak. You must be Level 12!" );
2751 updateTS ( user
-> stats
);
2753 Player
* p
= user
-> stats
;
2754 p
-> fight
= new Monster ( boss
);
2755 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2756 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2757 "deep, red fog rolls in. The air is filled with the " \
2758 "heated mist of deadly fire from beyond the cave " \
2760 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2761 "your %s , and venture into the hot, dark cave. " \
2762 "You are surprised at the angle of descent as you climb " \
2763 "lower and lower, deeper into the dragon's den." );
2764 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2765 "a tooth. It is a large tooth... bigger than your torso." \
2766 " Suddenly the darkness lifts from the gleam of an eye " \
2767 " staring into your soul! The eye is large... HUGE!" );
2768 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2769 "glare orange! The tooth is moving... but it is still too " \
2770 "dark for you to make out.... THE DRAGON! You see it!" );
2774 void do_master ( char * u
)
2779 if (!( user
= find ( u
)))
2781 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2784 else if ( isIgnore ( user
))
2787 log ( "Ignoring %s ." , user
-> getNick ());
2791 else if (! is_playing ( user
))
2793 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2796 else if ( is_fighting ( user
))
2798 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2801 else if (! isAlive ( user
-> stats
))
2803 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2807 updateTS ( user
-> stats
);
2809 char * cmd
= strtok ( NULL
, " " );
2810 Player
* p
= user
-> stats
;
2815 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2858 notice ( s_GameServ
, u
, "You are at level 12. You are the master. What's left? The DRAGON!" );
2862 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2868 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2872 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2880 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
));
2883 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2886 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
);
2888 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2894 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2898 void see_master ( char * u
)
2902 if (!( user
= find ( u
)))
2904 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2908 if (! is_fighting ( user
) && is_playing ( user
))
2910 Player
* p
= user
-> stats
;
2911 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2912 p
-> fight
= p
-> master
;
2913 display_monster ( u
); // Since master is the same structure, use this function
2917 void showBankBalance ( const char * u
)
2922 if (!( user
= find ( u
)))
2930 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2936 ListNode
< aClient
> * it
;
2938 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2940 it
= players
[ x
]. First ();
2944 p
= it
-> getData ()-> stats
;
2951 void refresh ( Player
* p
)
2956 if ( p
-> hp
< p
-> maxhp
)
2958 p
-> forest_fights
= forestfights
;
2959 p
-> player_fights
= 3 ;
2964 void do_refresh ( char * u
)
2966 char * nick
= strtok ( NULL
, " " );
2969 if (!( user
= find ( u
)))
2971 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2972 log ( "Error: aClient not found: %s " , u
);
2975 else if ( isIgnore ( user
))
2978 log ( "Ignoring %s ." , user
-> getNick ());
2982 else if (! isAdmin ( user
))
2984 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2989 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
2992 else if ( stricmp ( nick
, "ALL" ) == 0 )
2994 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
2997 else if (( user
= findplayer ( nick
)))
2999 if ( is_playing ( user
))
3002 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3004 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3006 refresh ( user
-> stats
);
3011 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3013 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3019 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3027 ListNode
< aClient
> * it
;
3030 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3032 it
= players
[ x
]. First ();
3036 p
= it
-> getData ()-> stats
;
3043 void reset ( Player
* p
)
3051 void updateTS ( Player
* p
)
3057 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3059 p
-> lastcommand
= time ( NULL
);
3061 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3066 bool timedOut ( Player
* p
)
3070 else if ( p
-> lastcommand
== 0 )
3074 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3081 void timeOutEvent ( Player
* p
)
3083 aClient
* user
= findplayer ( p
-> name
);
3085 if (! user
|| ! p
-> client
) // then they're not playing
3088 char * nick
= user
-> getNick ();
3090 if ( player_fight ( user
) && isYourTurn ( p
))
3092 // Check to see if they were the idler or if it was the other
3094 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3096 // This person's last command was given earlier,
3097 // so this person is the idler
3098 notice ( s_GameServ
, nick
, "You timed out " \
3099 "during a fight. You lose your turn!" );
3100 notice ( s_GameServ
, p
-> battle
-> getNick (),
3101 " %s hesitated for too long. Your move." , p
-> name
);
3103 setYourTurn ( p
-> battle
-> stats
);
3105 // Update the TS for both players to give them another
3106 // Chance to wake up, but if the other player doesn't
3107 // Attack now, they both get logged out.
3109 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3110 display_players ( p
-> battle
);
3115 notice ( s_GameServ
, p
-> battle
-> getNick (),
3116 "You and %s timed out at the same time." \
3117 " Don't fight if you're just going to " \
3118 "sit there!" , p
-> name
);
3119 notice ( s_GameServ
, user
-> getNick (),
3120 "You and %s timed out at the same time." \
3121 " Don't fight if you're just going to " \
3122 "sit there!" , p
-> battle
-> stats
-> name
);
3128 else if (! player_fight ( user
))
3130 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3132 // Place fun stuff here :)
3133 int randnum
= 1 + rand () % 100 ; // 1-100
3134 #define GSN(s) notice(s_GameServ, nick, s)
3135 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3139 // 35-100% of your gold goes pffft - kain
3140 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3142 GSN ( "You stop for a moment to rest on the " \
3143 "street corner. All of a sudden, you " \
3144 "are ambushed from all sides by a hoarde " \
3145 "of knife wielding thugs." );
3146 GSN2 ( "The thugs beat you into utter submission " \
3147 "and steal %d gold from you!" , stolen
);
3148 user
-> stats
-> gold
-= stolen
;
3150 else if ( randnum
>= 50 && randnum
< 75 )
3152 // 25-65% of your gold goes pffft - kain
3153 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3154 GSN ( "While dilly dallying around, you lose " \
3155 "your sense of time. Little did you know, " \
3156 "but thieves lifted your gold while you " \
3157 "weren't watching." );
3158 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3159 user
-> stats
-> gold
-= stolen
;
3161 else if ( randnum
>= 75 )
3163 // 25-75% of your gold goes pffft - kain
3164 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3165 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3166 "goblins grabbed your gold!" );
3167 GSN2 ( "They stole %d gold from you!" , stolen
);
3168 user
-> stats
-> gold
-= stolen
;
3172 // Always log out the user
3177 void do_reset ( char * u
)
3179 char * nick
= strtok ( NULL
, " " );
3182 if (!( user
= find ( u
)))
3184 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3185 log ( "Error: aClient not found: %s " , u
);
3188 else if (! isAdmin ( user
))
3190 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3196 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3199 else if ( stricmp ( nick
, "ALL" ) == 0 )
3201 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3204 else if (( user
= findbyrealnick ( nick
)))
3206 if ( is_playing ( user
))
3209 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3211 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3218 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3220 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3226 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3231 void do_help ( char * u
)
3233 char * cmd
= strtok ( NULL
, " " );
3235 display_help ( u
, cmd
);
3238 void display_help ( char * u
, char * file
)
3245 infile
. open ( "helpfiles/help" );
3248 log ( "Error opening helpfiles/help" );
3249 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3252 buf
= new char [ 1024 ];
3253 while ( infile
. getline ( buf
, 1024 ))
3255 // Written this way, it will process %S in the helpfiles
3256 // Instead of notice(s_GameServ, u, "%s", buf);
3257 notice ( s_GameServ
, u
, buf
);
3261 aClient
* user
= find ( u
);
3262 if ( user
&& isAdmin ( user
))
3263 display_help ( u
, "admin_commands" );
3268 filename
= new char [ strlen ( file
) + 11 ];
3269 strcpy ( filename
, "helpfiles/" );
3270 strcat ( filename
, file
);
3272 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3273 filename
[ x
] = tolower ( filename
[ x
]);
3275 infile
. open ( filename
);
3279 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3282 buf
= new char [ 1024 ];
3283 while ( infile
. getline ( buf
, 1024 ))
3285 // Written this way, it will process %S in the helpfiles
3286 // Instead of notice(s_GameServ, u, "%s", buf);
3287 notice ( s_GameServ
, u
, buf
);
3294 void do_admin ( char * u
)
3297 char * pass
= strtok ( NULL
, " " );
3299 if (!( user
= find ( u
)))
3301 log ( "Error: aClient not found: %s " , u
);
3302 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3308 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3314 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3317 else if ( strcmp ( pass
, adminpass
) == 0 )
3319 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3322 log ( " %s became an administrator." , user
-> getRealNick ());
3324 log ( " %s became an administrator." , user
-> getNick ());
3329 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3334 bool load_monsters ()
3337 infile
. open ( "monsters.dat" );
3343 log ( "Error opening monsters.dat" );
3347 buf
= new char [ 2048 ];
3350 log ( "Loading monsters from monsters.dat" );
3353 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
3355 for ( int m
= 0 ; m
< MONSTERS
;)
3357 infile
. getline ( buf
, 2048 );
3358 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3362 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
3363 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
3364 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
3365 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
3366 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
3367 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
3368 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
3369 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));
3378 // this will be hash.cpp start
3379 // thank you wcampbel
3380 unsigned long sHASH ( const unsigned char * name
)
3382 unsigned long h
= 0 , g
;
3386 h
= ( h
<< 4 ) + (* name
++); // Case sensitive for numerics
3387 if (( g
= ( h
& 0xF0000000 )))
3391 return h
% U_TABLE_SIZE
;
3394 unsigned long iHASH ( const unsigned char * name
)
3396 unsigned long h
= 0 , g
;
3400 h
= ( h
<< 4 ) + tolower (* name
++);
3401 if (( g
= ( h
& 0xF0000000 )))
3405 return h
% U_TABLE_SIZE
;
3408 // this will be hash.cpp end