]>
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_play ( char * u
);
115 void do_quitg ( char * u
);
116 void do_reset ( char * u
);
117 void do_run ( char * u
);
118 void do_stats ( char * u
);
119 void do_store ( char * u
);
120 void do_tavern ( char * u
);
121 void do_use ( char * u
);
122 void see_master ( char * u
);
124 void logout ( aClient
* user
);
125 void showstats ( const char * u
, const char * nick
);
126 void showinventory ( aClient
* from
, aClient
* to
);
127 void showBankBalance ( const char * u
);
128 void end_turn ( aClient
* user
);
131 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
132 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
133 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
134 "Light Saber" , "Masamune" , "Mystical Sword" };
136 char * armors
[ WNA
] = { "Birthday Suit" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
137 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
138 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
139 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
141 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
142 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
143 int webonus
[ WNA
] = { 2 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
144 int arbonus
[ WNA
] = { 2 , 3 , 5 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
146 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
147 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
148 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
150 void gameserv ( char * source
, char * buf
)
153 cmd
= strtok ( buf
, " " );
156 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
161 cmd
++; // Get rid of that : at the beginning of the :text (command)
164 log ( "Source: %s Command: %s " , source
, cmd
);
172 int curday
= tm
-> tm_mday
;
178 save_day (); // here i come to save the day!
181 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
184 ts
= strtok ( NULL
, "\1" );
185 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
186 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
187 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
188 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
189 cmd
= strtok ( NULL
, " " );
192 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
196 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
198 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
200 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
202 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
204 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
206 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
207 do_inventory ( source
);
208 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
210 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
212 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
214 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
216 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
218 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
220 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
222 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
224 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
226 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
228 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
230 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
232 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
234 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
237 if (!( user
= find ( source
)))
239 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
240 log ( "Error: aClient not found: %s " , source
);
242 else if (! isAdmin ( user
))
244 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
250 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
252 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
256 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
259 if (!( user
= find ( source
)))
261 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
262 log ( "Error: aClient not found: %s " , source
);
264 else if (! isAdmin ( user
))
266 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
272 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
275 if (!( user
= find ( source
)))
277 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
278 log ( "Error: aClient not found: %s " , source
);
280 else if (! isAdmin ( user
))
282 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
286 char * cmd2
= strtok ( NULL
, " " );
289 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
292 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
294 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
298 display_help ( source
, cmd
);
301 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
304 if (!( user
= find ( source
)))
306 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
307 log ( "Error: aClient not found: %s " , source
);
309 else if (! isAdmin ( user
))
311 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
315 char * rest
= strtok ( NULL
, "" );
321 if (( user
= find ( source
)))
326 log ( "Ignoring %s ." , user
-> getNick ());
331 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
337 source
--; // Bring the ':' back so we don't leak memory
340 cmd
--; // Same thing :)
343 int stricmp ( const char * s1
, const char * s2
)
347 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
353 if ( c
< tolower (* s2
))
358 void showstats ( const char * u
, const char * nick
)
360 aClient
* ni
, * sender
= find ( u
);
366 if (!( ni
= findplayer ( nick
)))
368 notice ( s_GameServ
, u
, " %s not found" , nick
);
372 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
374 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
375 space
= spaces ( strlen ( buf
), " " );
376 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
380 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
381 space
= spaces ( strlen ( buf
), " " );
382 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
385 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
388 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
389 space
= spaces ( strlen ( buf
), " " );
390 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
391 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
394 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
395 space
= spaces ( strlen ( buf
), " " );
396 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
397 weapons
[ ni
-> stats
-> weapon
]);
400 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
401 space
= spaces ( strlen ( buf
), " " );
402 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
407 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
412 char * spaces ( int len
, char * seperator
)
415 final
= new char [ 30 ];
417 strcpy ( final
, seperator
);
418 for ( y
= 0 ; y
< 30 - len
; y
++)
419 strcat ( final
, seperator
);
423 void raw ( const char * fmt
, ...)
428 input
= new char [ 1024 ];
430 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
436 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
437 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
438 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
441 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
446 sprintf ( input
, " %s%c " , input
, * t
);
451 log ( "Input: %s " , input
);
454 sprintf ( input
, " %s%s " , input
, " \r\n " );
455 sock_puts ( sock
, input
);
459 /* Send a NOTICE from the given source to the given nick. */
461 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
467 commanduse
= new char [ 16 ];
471 strcpy ( commanduse
, "P" );
473 strcpy ( commanduse
, "O" );
477 strcpy ( commanduse
, "PRIVMSG" );
479 strcpy ( commanduse
, "NOTICE" );
485 input
= new char [ 1024 ];
492 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
494 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
502 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
504 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
513 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
514 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
515 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
518 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
523 sprintf ( input
, " %s%c " , input
, * t
);
528 log ( "Input: %s " , input
);
530 sprintf ( input
, " %s%s " , input
, " \r\n " );
531 sock_puts ( sock
, input
);
532 delete [] commanduse
;
538 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
544 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
545 if ( c
== 0 || -- len
== 0 )
550 if ( c
< tolower (* s2
))
556 char * strtok ( char * str
, const char * delim
)
558 static char * current
= NULL
;
565 current
+= strspn ( current
, delim
);
566 ret
= * current
? current
: NULL
;
567 current
+= strcspn ( current
, delim
);
576 void do_list ( char * u
)
579 if (!( user
= find ( u
)))
581 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
584 else if ( isIgnore ( user
))
587 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
592 ListNode
< aClient
> * temp
;
594 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
596 temp
= players
[ x
]. First ();
597 if (! players
[ x
]. isEmpty ())
601 notice ( s_GameServ
, u
, "People Playing:" );
607 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
608 temp
-> getData ()-> stats
-> name
);
610 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
611 temp
-> getData ()-> stats
-> name
);
619 notice ( s_GameServ
, u
, "No one is playing" );
621 notice ( s_GameServ
, u
, "End of List" );
625 void do_logout ( char * u
)
628 char * name
= strtok ( NULL
, " " );
630 if (!( user
= find ( u
)))
632 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
633 "Buf: %s LOGOUT" , u
);
634 log ( "Could not find aClient Buf: %s LOGOUT" ,
638 else if ( isIgnore ( user
))
641 log ( "Ignoring %s ." , user
-> getNick ());
650 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
652 else if (!( user
= findplayer ( name
)))
654 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
658 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
664 if (! is_playing ( user
))
666 notice ( s_GameServ
, u
, "You're not logged in!" );
668 else if ( is_fighting ( user
))
670 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
674 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
680 void logout ( aClient
* user
)
682 if ( is_playing ( user
))
684 ListNode
< aClient
> * it
;
686 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
687 it
= players
[ hv
]. Find ( user
);
691 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
692 " %S Admin. Cannot find you in the players list." );
693 log ( "Error on logout(). Can't find %s in the players list" ,
704 temp
-> stats
= new Player
;
705 temp
-> stats
-> setData ( user
-> stats
);
706 user
-> stats
-> client
= NULL
;
708 if ( player_fight ( user
))
709 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
713 temp
-> stats
-> client
= NULL
;
715 temp
-> setRealNick ( "Not Playing" );
717 temp
-> setNick ( "Not Playing" );
721 log ( "Logged out player %s " ,
733 void do_register ( char * u
)
735 char * password
, * name
;
737 name
= strtok ( NULL
, " " );
738 password
= strtok ( NULL
, " " );
740 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
743 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
744 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
749 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
753 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
755 else if (( user
= findplayer ( name
)))
757 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
758 notice ( s_GameServ
, u
, "Choose another name!" );
760 else if (!( user
= find ( u
)))
762 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
764 else if ( isIgnore ( user
))
767 log ( "Ignoring %s ." , user
-> getNick ());
773 if (! is_playing ( user
))
775 ListNode
< aClient
> * temp
;
776 user
-> stats
= new Player ( user
);
777 user
-> stats
-> client
= user
; // Set the backwards pointer
778 user
-> stats
-> reset (); // set the user up
779 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
780 strncpy ( user
-> stats
-> name
, name
, 255 );
781 unsigned long hv
= iHASH (( unsigned char *) name
);
782 updateTS ( user
-> stats
);
783 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
784 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
786 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
787 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
788 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
789 setPlaying ( user
); // set the playing flag
793 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
798 void do_identify ( char * u
)
800 char * password
, * name
;
802 name
= strtok ( NULL
, " " );
803 password
= strtok ( NULL
, " " );
804 if (! password
|| ! name
)
806 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
808 else if (!( user
= find ( u
)))
810 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
811 log ( "Error: aClient not found: %s " , u
);
813 else if ( isIgnore ( user
))
816 log ( "Ignoring %s ." , user
-> getNick ());
820 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
821 notice ( s_GameServ
, u
, "Player %s not found" , name
);
822 else if ( is_playing ( user
))
824 notice ( s_GameServ
, u
, "You are already playing!" );
826 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
828 notice ( s_GameServ
, u
, "That player has already identified." );
830 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
832 notice ( s_GameServ
, u
, "Password incorrect" );
835 ListNode
< aClient
> * temp
;
836 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
837 temp
= players
[ hv
]. Find ( p
);
840 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
844 user
-> stats
= new Player ( p
-> stats
-> name
);
846 log ( "Setting data for identified" );
848 user
-> stats
-> setData ( p
-> stats
);
849 user
-> stats
-> client
= user
;
850 updateTS ( user
-> stats
);
854 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
858 setPlaying ( user
); // set the playing flag
861 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
865 void do_stats ( char * u
)
870 nick
= strtok ( NULL
, " " );
872 if (!( user
= find ( u
)))
874 log ( "Fatal Error: %s not found in client list" , u
);
877 else if ( isIgnore ( user
))
880 log ( "Ignoring %s ." , user
-> getNick ());
886 if (! is_playing ( user
))
888 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
893 updateTS ( user
-> stats
);
894 showstats ( u
, user
-> stats
-> name
);
904 log ( "Calling delete_masters()" );
910 log ( "Initializing masters" );
913 for ( int x
= 0 ; x
< LEVELS
; x
++)
914 masters
[ x
] = new Monster
;
916 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
917 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
918 masters
[ 0 ]-> strength
= 30 ;
919 masters
[ 0 ]-> gold
= 0 ;
921 masters
[ 0 ]-> maxhp
= 35 ;
923 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!" );
925 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
926 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
927 masters
[ 1 ]-> strength
= 45 ;
928 masters
[ 1 ]-> gold
= 0 ;
930 masters
[ 1 ]-> maxhp
= 51 ;
932 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." );
934 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
935 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
936 masters
[ 2 ]-> strength
= 83 ;
937 masters
[ 2 ]-> gold
= 0 ;
939 masters
[ 2 ]-> maxhp
= 100 ;
940 masters
[ 2 ]-> hp
= 100 ;
941 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!" );
944 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
945 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
946 masters
[ 3 ]-> strength
= 159 ;
947 masters
[ 3 ]-> gold
= 0 ;
949 masters
[ 3 ]-> maxhp
= 165 ;
950 masters
[ 3 ]-> hp
= 165 ;
951 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
953 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
954 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
955 masters
[ 4 ]-> strength
= 260 ;
956 masters
[ 4 ]-> gold
= 0 ;
958 masters
[ 4 ]-> maxhp
= 232 ;
959 masters
[ 4 ]-> hp
= 232 ;
960 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!" );
962 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
963 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
964 masters
[ 5 ]-> strength
= 325 ;
965 masters
[ 5 ]-> gold
= 0 ;
967 masters
[ 5 ]-> maxhp
= 504 ;
968 masters
[ 5 ]-> hp
= 504 ;
969 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
972 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
973 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
974 masters
[ 6 ]-> strength
= 380 ;
975 masters
[ 6 ]-> gold
= 0 ;
977 masters
[ 6 ]-> maxhp
= 1078 ;
978 masters
[ 6 ]-> hp
= 1078 ;
979 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
981 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
982 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
983 masters
[ 7 ]-> strength
= 462 ;
984 masters
[ 7 ]-> gold
= 0 ;
986 masters
[ 7 ]-> maxhp
= 2207 ;
987 masters
[ 7 ]-> hp
= 2207 ;
988 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
991 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
992 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
993 masters
[ 8 ]-> strength
= 511 ;
994 masters
[ 8 ]-> gold
= 0 ;
996 masters
[ 8 ]-> maxhp
= 2780 ;
997 masters
[ 8 ]-> hp
= 2780 ;
998 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1000 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1001 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1002 masters
[ 9 ]-> strength
= 618 ;
1003 masters
[ 9 ]-> gold
= 0 ;
1004 masters
[ 9 ]-> exp
= 0 ;
1005 masters
[ 9 ]-> maxhp
= 3046 ;
1006 masters
[ 9 ]-> hp
= 3046 ;
1007 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1009 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1010 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1011 masters
[ 10 ]-> strength
= 725 ;
1012 masters
[ 10 ]-> gold
= 0 ;
1013 masters
[ 10 ]-> exp
= 0 ;
1014 masters
[ 10 ]-> maxhp
= 3988 ;
1015 masters
[ 10 ]-> hp
= 3988 ;
1016 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." );
1019 void init_monsters ()
1022 log ( "Calling delete_monsters" );
1027 for ( int x
= 0 ; x
< LEVELS
; x
++)
1028 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1029 monsters
[ x
][ y
] = new Monster ();
1032 void delete_monsters ()
1034 for ( int x
= 0 ; x
< LEVELS
; x
++)
1035 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1037 delete monsters
[ x
][ y
];
1040 void delete_masters ()
1042 for ( int x
= 0 ; x
< LEVELS
; x
++)
1047 void display_monster ( char * u
)
1051 aClient
* user
= find ( u
);
1052 Player
* ni
= user
-> stats
;
1054 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1055 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
1056 notice ( s_GameServ
, u
, "Here are your commands:" );
1057 notice ( s_GameServ
, u
, "/msg %S attack" );
1058 notice ( s_GameServ
, u
, "/msg %S run" );
1059 notice ( s_GameServ
, u
, "What will you do?" );
1063 void display_players ( char * u
)
1066 if (!( user
= find ( u
)))
1068 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1071 display_players ( user
);
1074 void display_players ( aClient
* user
)
1076 char * u
= user
-> getNick ();
1077 if ( is_playing ( user
) && player_fight ( user
))
1079 aClient
* battle
= user
-> stats
-> battle
;
1080 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1081 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
1082 notice ( s_GameServ
, u
, "Here are your commands:" );
1083 notice ( s_GameServ
, u
, "/msg %S attack" );
1084 notice ( s_GameServ
, u
, "/msg %S run" );
1085 notice ( s_GameServ
, u
, "What will you do?" );
1090 bool is_playing ( char * u
)
1093 if (!( user
= find ( u
)))
1096 return is_playing ( user
);
1099 bool is_playing ( aClient
* user
)
1101 if ( user
-> stats
== NULL
)
1105 else if ( user
-> stats
-> client
== NULL
)
1109 else if (! FL_is_playing ( user
))
1117 bool is_fighting ( char * u
)
1121 if (!( user
= find ( u
)))
1124 return is_fighting ( user
);
1127 bool is_fighting ( aClient
* user
)
1129 if (! is_playing ( user
))
1132 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1135 bool player_fight ( char * u
)
1139 if (!( user
= find ( u
)))
1142 return player_fight ( user
);
1145 bool player_fight ( aClient
* user
)
1147 if (! is_playing ( user
))
1149 else if ( user
-> stats
-> battle
!= NULL
)
1151 return user
-> stats
-> battle
-> stats
!= NULL
;
1156 bool master_fight ( char * u
)
1160 if (!( user
= find ( u
)))
1163 return master_fight ( user
);
1166 bool master_fight ( aClient
* user
)
1168 if (! is_playing ( user
))
1171 return user
-> stats
-> master
!= NULL
;
1174 void do_fight ( char * u
)
1176 aClient
* ni
, * battle
;
1178 char * nick
= strtok ( NULL
, " " );
1182 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1185 else if (!( ni
= find ( u
)))
1187 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1190 else if ( isIgnore ( ni
))
1193 log ( "Ignoring %s ." , ni
-> getNick ());
1197 else if (! is_playing ( ni
))
1199 notice ( s_GameServ
, u
, "You are not playing!" );
1203 updateTS ( ni
-> stats
);
1205 if ( ni
-> stats
-> player_fights
<= 0 )
1207 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1208 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1209 "day. You have to wait until tomorrow!" );
1211 else if (!( battle
= findplayer ( nick
)))
1213 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1215 else if (! isAlive ( ni
-> stats
))
1217 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1219 else if (! is_playing ( battle
))
1221 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1224 * Offline fighting not implemented yet.
1225 * else if (!(fight = finduser(nick)))
1227 * ni->stats->battle = battle;
1228 * battle->battle = ni;
1230 * battle->yourturn = 0;
1231 * notice(s_GameServ, u, "You decide to fight %s while they're not online!",
1232 * battle->stats->name);
1233 * display_players(u);
1236 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1238 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1240 else if (! isAlive ( battle
-> stats
))
1242 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1244 else if ( player_fight ( battle
))
1246 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1248 else if ( master_fight ( battle
))
1250 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
);
1252 else if ( is_fighting ( battle
))
1254 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1256 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1258 // You can't fight someone below you by more than X level(s)
1259 // level 12 can fight level (12 - X) but not < (12 - X)
1260 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1261 battle
-> stats
-> name
);
1263 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1265 // You can't fight someone above you by more than X level(S)
1266 // level 1 can fight level (1 + X), but not > (1 + X)
1267 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1268 "weakling!" , ni
-> stats
-> name
);
1272 // Set your battle pointer to the other player
1273 ni
-> stats
-> battle
= battle
;
1275 // Set the other player's battle pointer to you
1276 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1278 // The initiator gets the first move (perhaps this should be 50/50)
1279 setYourTurn ( ni
-> stats
);
1280 clearYourTurn ( battle
-> stats
);
1282 // Initiate Battle sequence!
1283 ni
-> stats
-> player_fights
-= 1 ;
1285 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1286 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1287 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1288 "because they initiated!" , ni
-> stats
-> name
);
1289 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1290 display_players ( ni
);
1294 void do_use ( char * u
)
1299 char * item
= strtok ( NULL
, " " );
1303 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1304 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1307 else if (!( user
= find ( u
)))
1309 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1312 else if ( isIgnore ( user
))
1315 log ( "Ignoring %s ." , user
-> getNick ());
1319 else if (! is_playing ( user
))
1321 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1325 updateTS ( user
-> stats
);
1327 p
= & user
-> stats
-> inventory
;
1329 if ( stricmp ( item
, "HEALTH" ) == 0 )
1331 if ( p
-> Healing () <= 0 )
1333 notice ( s_GameServ
, u
, "You are out of Health Potions!" );
1336 int oldhealth
= user
-> stats
-> hp
;
1337 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1338 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1339 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1340 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealth
);
1343 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1345 if ( p
-> Strength () <= 0 )
1347 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1350 int oldstrength
= user
-> stats
-> strength
;
1351 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1352 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1353 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1354 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1357 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1359 if ( p
-> Defense () <= 0 )
1361 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1364 int olddefense
= user
-> stats
-> defense
;
1365 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1366 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1367 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1368 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1371 else if ( stricmp ( item
, "HP" ) == 0 )
1375 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1378 int oldHP
= user
-> stats
-> maxhp
;
1379 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1380 user
-> stats
-> maxhp
+= 2 +
1381 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1383 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1388 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALTH | STRENGTH | DEFENSE}" );
1392 end_turn ( user
); // If they're fighting, end their turn
1394 void do_run ( char * u
)
1397 Player
* p
, * p2
= NULL
;
1399 if (!( user
= find ( u
)))
1401 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1404 else if ( isIgnore ( user
))
1407 log ( "Ignoring %s ." , user
-> getNick ());
1411 else if (! is_playing ( user
))
1413 notice ( s_GameServ
, u
, "You must be playing to run!" );
1417 updateTS ( user
-> stats
);
1421 p2
= p
-> battle
-> stats
;
1423 if (! is_fighting ( user
))
1424 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1425 else if (! player_fight ( user
) && ! master_fight ( user
))
1427 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1431 else if ( player_fight ( user
) && isYourTurn ( p
))
1433 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1434 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1437 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1439 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1441 else if ( master_fight ( user
))
1443 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1448 void end_turn ( aClient
* user
)
1450 char * nick
, * u
= user
-> getNick ();
1455 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1457 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1460 if (! player_fight ( user
) && ! master_fight ( user
))
1461 fight
= user
-> stats
-> fight
;
1463 fight
= user
-> stats
-> master
;
1464 battle
= user
-> stats
-> battle
;
1466 if (! player_fight ( user
))
1469 mhit
= ( fight
-> strength
/ 2 ) +
1470 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1471 arbonus
[ user
-> stats
-> armor
]));
1476 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1477 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1478 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1480 if (! player_fight ( user
))
1485 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1486 fight
-> name
, fight
-> weapon
, mhit
);
1489 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1491 if ( mhit
>= user
-> stats
-> hp
)
1493 if (! master_fight ( user
))
1495 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1496 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1497 "of your experience!" );
1498 user
-> stats
-> gold
= 0 ;
1499 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1500 user
-> stats
-> fight
= NULL
;
1501 clearAlive ( user
-> stats
);
1506 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1507 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1508 user
-> stats
-> fight
= NULL
;
1509 user
-> stats
-> master
= NULL
;
1516 user
-> stats
-> hp
-= mhit
;
1523 clearYourTurn ( user
-> stats
);
1524 setYourTurn ( battle
-> stats
);
1525 display_players ( battle
);
1531 void do_attack ( char * u
)
1534 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1535 Monster
* fight
; // The monster they may be fighting
1537 if (!( ni
= find ( u
)))
1539 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1542 else if ( isIgnore ( ni
))
1545 log ( "Ignoring %s ." , ni
-> getNick ());
1549 else if (! is_playing ( ni
))
1551 notice ( s_GameServ
, u
, "You're not playing!" );
1554 else if (! is_fighting ( ni
))
1556 notice ( s_GameServ
, u
, "You're not in battle!" );
1561 if (! ni
-> stats
-> master
) // This is not a master fight
1562 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1563 else // This IS a master fight
1564 fight
= ni
-> stats
-> master
; // Master Could be NULL
1566 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1568 // One has to be !NULL based on the previous else if
1569 // We wouldn't be here if they were all NULL
1571 updateTS ( ni
-> stats
);
1573 if (! player_fight ( ni
))
1576 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1577 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1580 mhit
= ( fight
-> strength
/ 2 ) +
1581 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1582 arbonus
[ ni
-> stats
-> armor
]));
1587 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1588 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1589 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1592 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1593 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1594 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1597 if (! player_fight ( ni
))
1600 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1602 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1604 if ( hit
>= fight
-> hp
)
1606 if ( master_fight ( ni
))
1607 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1609 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1611 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1612 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1613 fight
-> exp
, fight
-> gold
);
1615 // If your new experience (or gold) will be greater than 2 billion,
1616 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1617 // This could be a problem with overflowing out of the sign bit.
1618 // Unsigned long int maybe? Leave it for now.
1619 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1620 ni
-> stats
-> exp
+ fight
-> exp
);
1622 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1623 ni
-> stats
-> gold
+ fight
-> gold
);
1626 if ( master_fight ( ni
))
1628 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1629 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1630 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1632 // Increase your level
1635 // Increase your maximum hit points
1636 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1638 // Heal the player by setting hp to their max
1639 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1641 // Add to your strength
1642 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1644 // Add to your defensive power
1645 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1647 // Clear the pointer for your master
1648 ni
-> stats
-> master
= NULL
;
1651 // They're dead so remove the pointer
1652 delete ni
-> stats
-> fight
;
1653 ni
-> stats
-> fight
= NULL
;
1654 ni
-> stats
-> master
= NULL
;
1664 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1665 fight
-> name
, fight
-> weapon
, mhit
);
1668 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1670 if ( mhit
>= ni
-> stats
-> hp
)
1672 if (! master_fight ( ni
))
1674 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1675 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1676 "of your experience!" );
1677 ni
-> stats
-> gold
= 0 ;
1678 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1679 ni
-> stats
-> fight
= NULL
;
1680 clearAlive ( ni
-> stats
);
1685 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1686 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1687 ni
-> stats
-> fight
= NULL
;
1688 ni
-> stats
-> master
= NULL
;
1695 ni
-> stats
-> hp
-= mhit
;
1701 else if ( player_fight ( ni
))
1703 /* Offline fighting not available yet
1704 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1707 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1709 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1710 if (hit >= battle->stats->hp)
1712 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1713 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1714 (long int)(battle->stats->exp * .10), battle->stats->gold);
1715 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1717 ni->stats->exp += (long int)(battle->stats->exp * .10);
1718 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1722 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1723 ni->stats->exp = 2000000000;
1726 if (2000000000 - ni->stats->gold > battle->stats->gold)
1728 * ni->stats->gold += battle->stats->gold;
1729 battle->stats->gold = 0;
1733 battle->stats->gold = 2000000000 - ni->stats->gold;
1734 ni->stats->gold = 2000000000;
1736 * ni->stats->battle->stats->alive = 0;
1737 ni->stats->battle->battle = NULL;
1738 ni->stats->battle = NULL;
1744 * battle->stats->hp -= hit;
1747 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1748 battle->nick, weapons[battle->stats->weapon], mhit);
1751 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1753 if (mhit >= ni->stats->hp)
1755 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1756 if (2000000000 - battle->stats->gold > ni->stats->gold)
1758 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1759 battle->stats->gold += ni->stats->gold;
1760 * ni->stats->gold = 0;
1764 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1766 ni->stats->gold -= (2000000000 - battle->stats->gold);
1767 notice(s_GameServ, u, "You were left dead with %d gold.",
1768 * (long int)ni->stats->gold);
1769 battle->stats->gold = 2000000000;
1771 ni->stats->battle->battle = NULL;
1772 ni->stats->battle = NULL;
1773 ni->stats->alive = 0;
1779 ni->stats->hp -= mhit;
1785 * end offline fighting */
1787 if ( is_playing ( battle
))
1789 if (! isYourTurn ( ni
-> stats
))
1791 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1792 battle
-> stats
-> name
);
1797 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1799 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1800 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1801 weapons
[ ni
-> stats
-> weapon
], hit
);
1802 clearYourTurn ( ni
-> stats
);
1803 setYourTurn ( battle
-> stats
);
1804 display_players ( battle
);
1808 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1809 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1810 clearYourTurn ( ni
-> stats
);
1811 setYourTurn ( battle
-> stats
);
1812 display_players ( battle
);
1814 if ( hit
>= battle
-> stats
-> hp
)
1816 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1817 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1818 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1819 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1821 battle
-> stats
-> hp
= 0 ;
1822 clearAlive ( battle
-> stats
);
1824 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1826 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1827 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1831 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1832 ni
-> stats
-> exp
= 2000000000 ;
1835 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1837 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1838 "all gold on hand!" );
1839 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1840 battle
-> stats
-> gold
= 0 ;
1844 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1845 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1847 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1848 "gold." , ni
-> stats
-> name
);
1850 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1851 "left. All is not lost!" , battle
-> stats
-> gold
);
1853 ni
-> stats
-> gold
= 2000000000 ;
1855 battle
-> stats
-> battle
= NULL
;
1856 ni
-> stats
-> battle
= NULL
;
1862 battle
-> stats
-> hp
-= hit
;
1863 clearYourTurn ( ni
-> stats
);
1864 setYourTurn ( battle
-> stats
);
1865 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1866 battle
-> stats
-> name
);
1874 void do_heal ( char * u
)
1877 char * amount
= strtok ( NULL
, " " );
1882 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1885 else if (!( ni
= find ( u
)))
1887 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1890 else if ( isIgnore ( ni
))
1893 log ( "Ignoring %s ." , ni
-> getNick ());
1897 else if (! is_playing ( ni
))
1899 notice ( s_GameServ
, u
, "You aren't playing!" );
1902 else if (! isAlive ( ni
-> stats
))
1904 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1907 else if ( is_fighting ( ni
))
1909 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1912 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1914 notice ( s_GameServ
, u
, "You don't need healing!" );
1918 updateTS ( ni
-> stats
);
1919 if ( stricmp ( amount
, "ALL" ) == 0 )
1921 price
= ni
-> stats
-> level
* 3 ;
1922 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1924 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1925 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1926 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1927 ni
-> stats
-> gold
%= price
;
1931 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1932 "per point." , price
);
1933 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1934 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1935 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1936 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1937 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1940 else if ( isstringnum ( amount
))
1942 num
= stringtoint ( amount
);
1943 price
= ni
-> stats
-> level
* 3 ;
1944 if ( ni
-> stats
-> gold
< price
* num
)
1946 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1947 ( long int ) ni
-> stats
-> gold
/ price
);
1949 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1951 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
1953 ni
-> stats
-> hp
+= num
;
1954 ni
-> stats
-> gold
-= num
* price
;
1956 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1958 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1959 "per point." , price
);
1960 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
1961 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
1962 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1963 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1966 else if ( amount
[ 0 ] == '-' )
1967 notice ( s_GameServ
, u
, "You trying to cheat?" );
1969 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1972 int isstringnum ( char * num
)
1975 for ( x
= 0 ; x
< strlen ( num
); x
++)
1977 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
1983 long int stringtoint ( char * number
)
1985 long int x
, len
= strlen ( number
), sum
= 0 ;
1987 return chartoint ( number
[ 0 ]);
1988 sum
+= chartoint ( number
[ len
- 1 ]);
1989 for ( x
= len
- 2 ; x
>= 0 ; x
--)
1990 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
1994 long int pow ( int x
, int y
)
2000 if ( x
!= 0 && y
!= 0 )
2002 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2010 long int chartoint ( char ch
)
2012 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2013 return int ( ch
) - 48 ;
2020 ListNode
< aClient
> * ptr
;
2024 outfile
. open ( playerdata
);
2028 log ( "Error opening %s " , playerdata
);
2032 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2034 ptr
= players
[ x
]. First ();
2037 it
= ptr
-> getData ()-> stats
;
2039 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2040 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2041 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2042 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2043 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2044 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
2057 char * tempname
, * buf
, * password
;
2058 buf
= new char [ 1023 ];
2060 infile
. open ( playerdata
);
2064 log ( "Error opening %s " , playerdata
);
2068 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2071 tempname
= strtok ( buf
, " " );
2072 temp
-> stats
= new Player ( tempname
);
2075 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2076 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2077 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2078 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2079 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2080 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2081 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2082 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2083 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2084 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2085 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2086 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2087 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2089 password
= strtok ( NULL
, " " );
2090 strcpy ( p
-> password
, password
);
2091 temp
-> setNick ( "Not Playing" );
2093 temp
-> setRealNick ( "Not Playing" );
2096 p
-> inventory
. reset (); // Set inventory to all 0s
2097 // Old player databases didn't have these three extra values
2098 // If they come up null, leave them to 0 as the default.
2099 // On the next gameserv database save, it will save the values.
2100 tempname
= strtok ( NULL
, " " );
2102 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2104 tempname
= strtok ( NULL
, " " );
2106 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2108 tempname
= strtok ( NULL
, " " );
2110 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2112 tempname
= strtok ( NULL
, " " );
2114 p
-> inventory
. setHP ( stringtoint ( tempname
));
2115 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2117 temp
-> stats
-> client
= NULL
;
2118 players
[ hv
]. insertAtBack ( temp
);
2126 bool passcmp ( char * encrypted
, char * plaintext
)
2129 char * plaintext2
, * plainToencrypt
;
2132 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2133 strcpy ( plaintext2
, plaintext
);
2135 salt
[ 0 ] = encrypted
[ 0 ];
2136 salt
[ 1 ] = encrypted
[ 1 ];
2139 plainToencrypt
= crypt ( plaintext2
, salt
);
2141 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2143 delete [] plaintext2
;
2148 bool check_password ( char * name
, char * plaintext
)
2152 if (!( client
= findplayer ( name
)))
2156 return passcmp ( client
-> stats
-> password
, plaintext
);
2160 void do_store ( char * u
)
2162 char * cmd
= strtok ( NULL
, " " );
2163 char * item
= strtok ( NULL
, " " );
2164 char * num
= strtok ( NULL
, " " );
2172 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2173 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2174 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2177 else if (!( user
= find ( u
)))
2179 log ( "Fatal Error: could not find %s in client list" , u
);
2182 else if ( isIgnore ( user
))
2185 log ( "Ignoring %s ." , user
-> getNick ());
2189 else if (! is_playing ( user
))
2191 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2194 else if (! isAlive ( user
-> stats
))
2196 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2199 updateTS ( user
-> stats
);
2201 if ( stricmp ( cmd
, "LIST" ) == 0 )
2203 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2205 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2206 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2207 for ( int x
= 1 ; x
< WNA
; x
++)
2209 space
= spaces ( strlen ( weapons
[ x
]), "." );
2210 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2213 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2214 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2217 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2219 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2220 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2221 for ( int x
= 1 ; x
< WNA
; x
++)
2223 space
= spaces ( strlen ( armors
[ x
]), "." );
2224 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2227 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2228 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2232 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2235 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2238 else if (! isstringnum ( num
))
2240 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2243 if ( stricmp ( item
, "WEAPON" ) == 0 )
2245 wep
= stringtoint ( num
);
2246 if ( wep
>= WNA
|| wep
< 1 )
2248 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2255 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2256 else if ( p
-> gold
< prices
[ wep
- 1 ])
2257 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2260 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2262 p
-> gold
-= prices
[ wep
- 1 ];
2265 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2267 wep
= stringtoint ( num
);
2268 if ( wep
>= WNA
|| wep
< 1 )
2270 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2277 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2278 else if ( p
-> gold
< prices
[ wep
- 1 ])
2279 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2282 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2284 p
-> gold
-= prices
[ wep
- 1 ];
2288 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2292 if ( stricmp ( item
, "WEAPON" ) == 0 )
2296 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2299 else if ( p
-> gold
== 2000000000 )
2301 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2304 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2306 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2307 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2308 p
-> gold
= 2000000000 ;
2313 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2314 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2318 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2324 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2327 if ( p
-> gold
== 2000000000 )
2329 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2332 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2334 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2335 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2336 p
-> gold
= 2000000000 ;
2341 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2342 ( prices
[ p
-> armor
- 1 ] / 2 ));
2344 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2350 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2351 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2352 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2357 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2358 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2359 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2363 void do_inventory ( char * u
)
2367 if (!( user
= find ( u
)))
2369 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2372 else if ( isIgnore ( user
))
2375 log ( "Ignoring %s ." , user
-> getNick ());
2379 else if (! is_playing ( user
))
2381 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2384 updateTS ( user
-> stats
);
2385 showinventory ( user
, user
);
2387 void showinventory ( aClient
* from
, aClient
* to
)
2389 char * nick
= to
-> getNick ();
2393 if ( is_playing ( from
))
2395 Pouch
* p
= & from
-> stats
-> inventory
;
2396 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2397 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2398 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2399 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2400 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2403 void do_tavern ( char * u
)
2405 char * cmd
= strtok ( NULL
, " " );
2410 if (!( user
= find ( u
)))
2412 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2415 else if ( isIgnore ( user
))
2418 log ( "Ignoring %s ." , user
-> getNick ());
2422 else if (! is_playing ( user
))
2424 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2427 else if ( is_fighting ( user
))
2429 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2433 updateTS ( user
-> stats
);
2438 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2439 notice ( s_GameServ
, u
, "Your commands:" );
2440 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2441 notice ( s_GameServ
, u
, "What'll it be?" );
2443 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2445 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2446 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 100 * p
-> level
+ ( p
-> exp
/ 10 ));
2447 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 205 * p
-> level
+ ( p
-> exp
/ 10 ));
2448 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 200 * p
-> level
+ ( p
-> exp
/ 10 ));
2449 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 230 * p
-> level
+ ( p
-> exp
/ 10 ));
2450 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2451 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2452 notice ( s_GameServ
, u
, "By something will ya!" );
2454 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2456 char * chnum
= strtok ( NULL
, " " );
2457 int num
= stringtoint ( chnum
);
2461 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2462 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2465 if ( num
< 1 || num
> 4 )
2467 notice ( s_GameServ
, u
, "Invalid Choice!" );
2468 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2469 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 100 * p
-> level
+ ( p
-> exp
/ 10 ));
2470 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 205 * p
-> level
+ ( p
-> exp
/ 10 ));
2471 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 200 * p
-> level
+ ( p
-> exp
/ 10 ));
2472 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 230 * p
-> level
+ ( p
-> exp
/ 10 ));
2473 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2474 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2480 price
= ( 100 * p
-> level
) + ( p
-> exp
/ 10 );
2481 if ( p
-> gold
>= price
)
2483 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2484 p
-> inventory
. incHealing ();
2488 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2491 price
= ( 205 * p
-> level
) + ( p
-> exp
/ 10 );
2492 if ( p
-> gold
>= price
)
2494 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2495 p
-> inventory
. incStrength ();
2499 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2502 price
= ( 200 * p
-> level
) + ( p
-> exp
/ 10 );
2503 if ( p
-> gold
>= price
)
2505 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2506 p
-> inventory
. incDefense ();
2510 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2513 price
= ( 230 * p
-> level
) + ( p
-> exp
/ 10 );
2514 if ( p
-> gold
>= price
)
2516 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2517 p
-> inventory
. incHP ();
2521 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2524 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2530 notice ( s_GameServ
, u
, "Improper Syntax." );
2531 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2535 void do_bank ( char * u
)
2537 char * cmd
= strtok ( NULL
, " " );
2538 char * amount
= strtok ( NULL
, " " );
2539 char * nick
= strtok ( NULL
, " " );
2544 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2546 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2547 notice ( s_GameServ
, u
, "BANK BALANCE" );
2550 else if (!( user
= find ( u
)))
2552 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2554 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2557 else if ( isIgnore ( user
))
2560 log ( "Ignoring %s ." , user
-> getNick ());
2564 else if (! is_playing ( user
))
2566 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2569 else if ( is_fighting ( user
))
2571 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2574 updateTS ( user
-> stats
);
2575 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2580 else if (! isAlive ( user
-> stats
))
2582 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2585 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2587 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2593 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2595 if ( p
-> bank
== 2000000000 )
2597 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2600 else if ( stricmp ( amount
, "ALL" ) == 0 )
2602 if ( 2000000000 - p
-> bank
< p
-> gold
)
2604 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2605 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2606 p
-> gold
-= ( 2000000000 - p
-> bank
);
2607 p
-> bank
= 2000000000 ;
2612 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2618 else if ( stringtoint ( amount
) > p
-> gold
)
2620 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2626 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2628 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2629 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2630 p
-> gold
-= ( 2000000000 - p
-> bank
);
2631 p
-> bank
= 2000000000 ;
2636 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2637 p
-> bank
+= stringtoint ( amount
);
2638 p
-> gold
-= stringtoint ( amount
);
2643 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2645 if ( p
-> gold
== 2000000000 )
2647 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2651 else if ( stricmp ( amount
, "ALL" ) == 0 )
2653 if ( 2000000000 - p
-> gold
< p
-> bank
)
2655 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2656 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2657 p
-> bank
-= ( 2000000000 - p
-> gold
);
2658 p
-> gold
= 2000000000 ;
2663 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2669 else if ( stringtoint ( amount
) > p
-> bank
)
2671 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2677 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2679 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2680 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2681 ( 2000000000 - p
-> gold
));
2682 p
-> bank
-= ( 2000000000 - p
-> gold
);
2683 p
-> gold
= 2000000000 ;
2688 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2689 p
-> gold
+= stringtoint ( amount
);
2690 p
-> bank
-= stringtoint ( amount
);
2698 void do_master ( char * u
)
2703 if (!( user
= find ( u
)))
2705 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2708 else if ( isIgnore ( user
))
2711 log ( "Ignoring %s ." , user
-> getNick ());
2715 else if (! is_playing ( user
))
2717 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2720 else if ( is_fighting ( user
))
2722 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2725 else if (! isAlive ( user
-> stats
))
2727 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2731 updateTS ( user
-> stats
);
2733 char * cmd
= strtok ( NULL
, " " );
2734 Player
* p
= user
-> stats
;
2739 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2782 notice ( s_GameServ
, u
, "You are at level 12. You are the master. What's left? The DRAGON!" );
2785 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2791 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2795 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2803 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
));
2806 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2809 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
);
2811 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2817 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2821 void see_master ( char * u
)
2825 if (!( user
= find ( u
)))
2827 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2831 if (! is_fighting ( user
) && is_playing ( user
))
2833 Player
* p
= user
-> stats
;
2834 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2835 p
-> fight
= p
-> master
;
2836 display_monster ( u
); // Since master is the same structure, use this function
2840 void showBankBalance ( const char * u
)
2845 if (!( user
= find ( u
)))
2853 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2859 ListNode
< aClient
> * it
;
2861 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2863 it
= players
[ x
]. First ();
2867 p
= it
-> getData ()-> stats
;
2874 void refresh ( Player
* p
)
2879 if ( p
-> hp
< p
-> maxhp
)
2881 p
-> forest_fights
= forestfights
;
2882 p
-> player_fights
= 3 ;
2887 void do_refresh ( char * u
)
2889 char * nick
= strtok ( NULL
, " " );
2892 if (!( user
= find ( u
)))
2894 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2895 log ( "Error: aClient not found: %s " , u
);
2898 else if ( isIgnore ( user
))
2901 log ( "Ignoring %s ." , user
-> getNick ());
2905 else if (! isAdmin ( user
))
2907 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2912 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
2915 else if ( stricmp ( nick
, "ALL" ) == 0 )
2917 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
2920 else if (( user
= findplayer ( nick
)))
2922 if ( is_playing ( user
))
2925 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
2927 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
2929 refresh ( user
-> stats
);
2934 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2936 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2942 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2950 ListNode
< aClient
> * it
;
2953 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2955 it
= players
[ x
]. First ();
2959 p
= it
-> getData ()-> stats
;
2966 void reset ( Player
* p
)
2974 void updateTS ( Player
* p
)
2980 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
2982 p
-> lastcommand
= time ( NULL
);
2984 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
2989 bool timedOut ( Player
* p
)
2993 else if ( p
-> lastcommand
== 0 )
2997 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3004 void timeOutEvent ( Player
* p
)
3006 aClient
* user
= findplayer ( p
-> name
);
3008 if (! user
|| ! p
-> client
) // then they're not playing
3011 char * nick
= user
-> getNick ();
3013 if ( player_fight ( user
) && isYourTurn ( p
))
3015 // Check to see if they were the idler or if it was the other
3017 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3019 // This person's last command was given earlier,
3020 // so this person is the idler
3021 notice ( s_GameServ
, nick
, "You timed out " \
3022 "during a fight. You lose your turn!" );
3023 notice ( s_GameServ
, p
-> battle
-> getNick (),
3024 " %s hesitated for too long. Your move." , p
-> name
);
3026 setYourTurn ( p
-> battle
-> stats
);
3028 // Update the TS for both players to give them another
3029 // Chance to wake up, but if the other player doesn't
3030 // Attack now, they both get logged out.
3032 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3033 display_players ( p
-> battle
);
3038 notice ( s_GameServ
, p
-> battle
-> getNick (),
3039 "You and %s timed out at the same time." \
3040 " Don't fight if you're just going to " \
3041 "sit there!" , p
-> name
);
3042 notice ( s_GameServ
, user
-> getNick (),
3043 "You and %s timed out at the same time." \
3044 " Don't fight if you're just going to " \
3045 "sit there!" , p
-> battle
-> stats
-> name
);
3051 else if (! player_fight ( user
))
3053 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3055 // Place fun stuff here :)
3056 int randnum
= 1 + rand () % 100 ; // 1-100
3057 #define GSN(s) notice(s_GameServ, nick, s)
3058 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3062 // 35-100% of your gold goes pffft - kain
3063 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3065 GSN ( "You stop for a moment to rest on the " \
3066 "street corner. All of a sudden, you " \
3067 "are ambushed from all sides by a hoarde " \
3068 "of knife wielding thugs." );
3069 GSN2 ( "The thugs beat you into utter submission " \
3070 "and steal %d gold from you!" , stolen
);
3071 user
-> stats
-> gold
-= stolen
;
3073 else if ( randnum
>= 50 && randnum
< 75 )
3075 // 25-65% of your gold goes pffft - kain
3076 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3077 GSN ( "While dilly dallying around, you lose " \
3078 "your sense of time. Little did you know, " \
3079 "but thieves lifted your gold while you " \
3080 "weren't watching." );
3081 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3082 user
-> stats
-> gold
-= stolen
;
3084 else if ( randnum
>= 75 )
3086 // 25-75% of your gold goes pffft - kain
3087 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3088 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3089 "goblins grabbed your gold!" );
3090 GSN2 ( "They stole %d gold from you!" , stolen
);
3091 user
-> stats
-> gold
-= stolen
;
3095 // Always log out the user
3100 void do_reset ( char * u
)
3102 char * nick
= strtok ( NULL
, " " );
3105 if (!( user
= find ( u
)))
3107 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3108 log ( "Error: aClient not found: %s " , u
);
3111 else if (! isAdmin ( user
))
3113 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3119 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3122 else if ( stricmp ( nick
, "ALL" ) == 0 )
3124 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3127 else if (( user
= findbyrealnick ( nick
)))
3129 if ( is_playing ( user
))
3132 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3134 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3141 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3143 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3149 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3154 void do_help ( char * u
)
3156 char * cmd
= strtok ( NULL
, " " );
3158 display_help ( u
, cmd
);
3161 void display_help ( char * u
, char * file
)
3168 infile
. open ( "helpfiles/help" );
3171 log ( "Error opening helpfiles/help" );
3172 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3175 buf
= new char [ 1024 ];
3176 while ( infile
. getline ( buf
, 1024 ))
3178 // Written this way, it will process %S in the helpfiles
3179 // Instead of notice(s_GameServ, u, "%s", buf);
3180 notice ( s_GameServ
, u
, buf
);
3184 aClient
* user
= find ( u
);
3185 if ( user
&& isAdmin ( user
))
3186 display_help ( u
, "admin_commands" );
3191 filename
= new char [ strlen ( file
) + 11 ];
3192 strcpy ( filename
, "helpfiles/" );
3193 strcat ( filename
, file
);
3195 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3196 filename
[ x
] = tolower ( filename
[ x
]);
3198 infile
. open ( filename
);
3202 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3205 buf
= new char [ 1024 ];
3206 while ( infile
. getline ( buf
, 1024 ))
3208 // Written this way, it will process %S in the helpfiles
3209 // Instead of notice(s_GameServ, u, "%s", buf);
3210 notice ( s_GameServ
, u
, buf
);
3217 void do_admin ( char * u
)
3220 char * pass
= strtok ( NULL
, " " );
3222 if (!( user
= find ( u
)))
3224 log ( "Error: aClient not found: %s " , u
);
3225 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3231 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3237 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3240 else if ( strcmp ( pass
, adminpass
) == 0 )
3242 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3245 log ( " %s became an administrator." , user
-> getRealNick ());
3247 log ( " %s became an administrator." , user
-> getNick ());
3252 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3257 bool load_monsters ()
3260 infile
. open ( "monsters.dat" );
3266 log ( "Error opening monsters.dat" );
3270 buf
= new char [ 2048 ];
3273 log ( "Loading monsters from monsters.dat" );
3276 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
3278 for ( int m
= 0 ; m
< MONSTERS
;)
3280 infile
. getline ( buf
, 2048 );
3281 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3285 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
3286 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
3287 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
3288 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
3289 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
3290 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
3291 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
3292 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));
3301 // this will be hash.cpp start
3302 // thank you wcampbel
3303 unsigned long sHASH ( const unsigned char * name
)
3305 unsigned long h
= 0 , g
;
3309 h
= ( h
<< 4 ) + (* name
++); // Case sensitive for numerics
3310 if (( g
= ( h
& 0xF0000000 )))
3314 return h
% U_TABLE_SIZE
;
3317 unsigned long iHASH ( const unsigned char * name
)
3319 unsigned long h
= 0 , g
;
3323 h
= ( h
<< 4 ) + tolower (* name
++);
3324 if (( g
= ( h
& 0xF0000000 )))
3328 return h
% U_TABLE_SIZE
;
3331 // this will be hash.cpp end