]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
15 #if defined(HAVE_CRYPT_H)
19 #elif defined(HAVE_UNISTD_H)
26 Monster
* monsters
[ LEVELS
][ MONSTERS
]; // Monsters per level. Total = MONSTERS * LEVELS
27 Monster boss
; // The boss monster
29 Monster
* masters
[ LEVELS
]; // A master for each level
37 char * strtok ( char * str
, const char * delim
);
40 int stricmp ( const char * s1
, const char * s2
);
41 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
44 /********** Password functions **********/
46 bool passcmp ( char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
48 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
50 /********** Password functions **********/
53 /********** GameServ Booleans **********/
56 bool timedOut ( Player
* p
);
57 void updateTS ( Player
* p
);
58 void timeOutEvent ( Player
* p
);
60 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
61 bool is_playing ( aClient
* user
);
63 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
64 bool is_fighting ( aClient
* user
);
66 bool player_fight ( char * u
); // True if the player is fighting another player.
67 bool player_fight ( aClient
* user
);
69 bool master_fight ( char * u
); // True if the player is fighting their master.
70 bool master_fight ( aClient
* user
);
72 /********** GameServ Booleans **********/
74 void display_help ( char * u
, char * file
= NULL
);
75 void display_monster ( char * u
);
76 void display_players ( char * u
);
77 void display_players ( aClient
* user
);
78 long int chartoint ( char ch
);
79 int isstringnum ( char * num
);
80 long int pow ( int x
, int y
);
81 long int stringtoint ( char * number
);
83 char * spaces ( int len
, char * seperator
);
84 void refresh ( Player
* p
);
86 void updateTS ( Player
* p
);
87 void reset ( Player
* p
);
91 void delete_monsters ();
92 void delete_masters ();
94 void do_admin ( char * u
);
95 void do_attack ( char * u
);
96 void do_bank ( char * u
);
97 void do_check ( char * u
);
98 void do_fight ( char * u
);
99 void do_heal ( char * u
);
100 void do_help ( char * u
);
101 void do_identify ( char * u
);
102 void do_inventory ( char * u
);
103 void do_refresh ( char * u
);
104 void do_register ( char * u
);
105 void do_list ( char * u
);
106 void do_logout ( char * u
);
107 void do_master ( char * u
);
108 void do_dragon ( char * u
);
109 void do_play ( char * u
);
110 void do_quitg ( char * u
);
111 void do_reset ( char * u
);
112 void do_run ( char * u
);
113 void do_stats ( char * u
);
114 void do_store ( char * u
);
115 void do_tavern ( char * u
);
116 void do_use ( char * u
);
117 void see_master ( char * u
);
119 void logout ( aClient
* user
);
120 void showstats ( const char * u
, const char * nick
);
121 void showinventory ( aClient
* from
, aClient
* to
);
122 void showBankBalance ( const char * u
);
123 void end_turn ( aClient
* user
);
126 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
127 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
128 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
129 "Light Saber" , "Masamune" , "Mystical Sword" };
131 char * armors
[ WNA
] = { "Birthday Suit" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
132 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
133 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
134 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
136 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
137 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
138 int webonus
[ WNA
] = { 2 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
139 int arbonus
[ WNA
] = { 2 , 3 , 5 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
141 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
142 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
143 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
145 void gameserv ( char * source
, char * buf
)
148 cmd
= strtok ( buf
, " " );
151 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
156 cmd
++; // Get rid of that : at the beginning of the :text (command)
159 log ( "Source: %s Command: %s " , source
, cmd
);
162 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
165 ts
= strtok ( NULL
, "\1" );
166 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
167 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
168 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
169 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
170 cmd
= strtok ( NULL
, " " );
173 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
177 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
179 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
181 } else if ( stricmp ( cmd
, "CHECK" ) == 0 ) {
183 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
185 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
187 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
189 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
190 do_inventory ( source
);
191 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
193 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
195 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
197 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
199 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
201 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
203 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
205 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
207 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
209 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
211 } else if ( stricmp ( cmd
, "NEWS" ) == 0 ) {
213 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
215 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
217 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
219 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
221 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
224 if (!( user
= find ( source
)))
226 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
227 log ( "Error: aClient not found: %s " , source
);
229 else if (! isAdmin ( user
))
231 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
237 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
239 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
243 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
246 if (!( user
= find ( source
)))
248 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
249 log ( "Error: aClient not found: %s " , source
);
251 else if (! isAdmin ( user
))
253 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
259 } else if ( stricmp ( cmd
, "LOAD" ) == 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!" );
273 char * cmd2
= strtok ( NULL
, " " );
276 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
279 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
281 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
285 display_help ( source
, cmd
);
288 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
291 if (!( user
= find ( source
)))
293 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
294 log ( "Error: aClient not found: %s " , source
);
296 else if (! isAdmin ( user
))
298 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
302 char * rest
= strtok ( NULL
, "" );
308 if (( user
= find ( source
)))
313 log ( "Ignoring %s ." , user
-> getNick ());
318 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
324 source
--; // Bring the ':' back so we don't leak memory
327 cmd
--; // Same thing :)
330 int stricmp ( const char * s1
, const char * s2
)
334 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
340 if ( c
< tolower (* s2
))
345 void showstats ( const char * u
, const char * nick
)
347 aClient
* ni
, * sender
= find ( u
);
353 if (!( ni
= findplayer ( nick
)))
355 notice ( s_GameServ
, u
, " %s not found" , nick
);
359 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
361 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
362 space
= spaces ( strlen ( buf
), " " );
363 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
367 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
368 space
= spaces ( strlen ( buf
), " " );
369 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
372 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
375 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
376 space
= spaces ( strlen ( buf
), " " );
377 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
378 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
381 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
382 space
= spaces ( strlen ( buf
), " " );
383 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
384 weapons
[ ni
-> stats
-> weapon
]);
387 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
388 space
= spaces ( strlen ( buf
), " " );
389 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
391 Pouch
* inv
= & ni
-> stats
-> inventory
;
393 notice ( s_GameServ
, u
, "Potions" );
394 sprintf ( buf
, "Healing: %d " , inv
-> Healing ());
395 space
= spaces ( strlen ( buf
), " " );
396 notice ( s_GameServ
, sender
-> getNick (), " %s%s HP: %d " , buf
,
400 sprintf ( buf
, "Strength: %d " , inv
-> Strength ());
401 space
= spaces ( strlen ( buf
), " " );
402 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " , buf
,
403 space
, inv
-> Defense ());
408 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
413 char * spaces ( int len
, char * seperator
)
416 final
= new char [ 30 ];
418 strcpy ( final
, seperator
);
419 for ( y
= 0 ; y
< 30 - len
; y
++)
420 strcat ( final
, seperator
);
424 void raw ( const char * fmt
, ...)
429 input
= new char [ 1024 ];
431 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
437 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
438 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
439 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
442 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
447 sprintf ( input
, " %s%c " , input
, * t
);
452 log ( "Input: %s " , input
);
455 sprintf ( input
, " %s%s " , input
, " \r\n " );
456 sock_puts ( sock
, input
);
460 /* Send a NOTICE from the given source to the given nick. */
462 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
468 commanduse
= new char [ 16 ];
472 strcpy ( commanduse
, "P" );
474 strcpy ( commanduse
, "O" );
478 strcpy ( commanduse
, "PRIVMSG" );
480 strcpy ( commanduse
, "NOTICE" );
486 input
= new char [ 1024 ];
493 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
495 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
503 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
505 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
514 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
515 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
516 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
519 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
524 sprintf ( input
, " %s%c " , input
, * t
);
529 log ( "Input: %s " , input
);
531 sprintf ( input
, " %s%s " , input
, " \r\n " );
532 sock_puts ( sock
, input
);
533 delete [] commanduse
;
539 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
545 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
546 if ( c
== 0 || -- len
== 0 )
551 if ( c
< tolower (* s2
))
557 char * strtok ( char * str
, const char * delim
)
559 static char * current
= NULL
;
566 current
+= strspn ( current
, delim
);
567 ret
= * current
? current
: NULL
;
568 current
+= strcspn ( current
, delim
);
577 void do_check ( char * u
)
579 int days
, hours
, minutes
, seconds
;
581 complete
= ( lastrefresh
+ refreshperiod
) - time ( NULL
);
582 days
= complete
/ 86400 ;
583 hours
= ( complete
% 86400 ) / 3600 ;
584 minutes
= ( complete
% 86400 ) % 3600 / 60 ;
585 seconds
= ( complete
% 86400 ) % 3600 % 60 ;
587 notice ( s_GameServ
, u
, "Time left to next refresh: %d d %d h %d m %d s" ,
588 days
, hours
, minutes
, seconds
);
591 void do_list ( char * u
)
594 char * cmd
= strtok ( NULL
, " " );
596 if (!( user
= find ( u
)))
598 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
601 else if ( isIgnore ( user
))
604 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
609 ListNode
< aClient
> * temp
;
612 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
614 temp
= players
[ x
]. First ();
615 if (! players
[ x
]. isEmpty ())
619 if ( cmd
|| is_playing ( temp
-> getData ()))
623 notice ( s_GameServ
, u
, "Players:" );
627 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
628 temp
-> getData ()-> stats
-> name
);
630 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
631 temp
-> getData ()-> stats
-> name
);
640 notice ( s_GameServ
, u
, "No one is playing" );
642 notice ( s_GameServ
, u
, "End of List" );
646 void do_logout ( char * u
)
649 char * name
= strtok ( NULL
, " " );
651 if (!( user
= find ( u
)))
653 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
654 "Buf: %s LOGOUT" , u
);
655 log ( "Could not find aClient Buf: %s LOGOUT" ,
659 else if ( isIgnore ( user
))
662 log ( "Ignoring %s ." , user
-> getNick ());
671 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
673 else if (!( user
= findplayer ( name
)))
675 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
679 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
);
685 if (! is_playing ( user
))
687 notice ( s_GameServ
, u
, "You're not logged in!" );
689 else if ( is_fighting ( user
))
691 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
695 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
701 void logout ( aClient
* user
)
703 if ( is_playing ( user
))
705 ListNode
< aClient
> * it
;
707 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
);
708 it
= players
[ hv
]. Find ( user
);
712 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
713 " %S Admin. Cannot find you in the players list." );
714 log ( "Error on logout(). Can't find %s in the players list" ,
725 temp
-> stats
= new Player
;
726 temp
-> stats
-> setData ( user
-> stats
);
727 user
-> stats
-> client
= NULL
;
729 if ( player_fight ( user
))
730 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
734 temp
-> stats
-> client
= NULL
;
736 temp
-> setRealNick ( "Not Playing" );
738 temp
-> setNick ( "Not Playing" );
742 log ( "Logged out player %s " ,
754 void do_register ( char * u
)
756 char * password
, * name
;
758 name
= strtok ( NULL
, " " );
759 password
= strtok ( NULL
, " " );
761 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
764 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
765 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
770 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
774 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
776 else if (( user
= findplayer ( name
)))
778 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
779 notice ( s_GameServ
, u
, "Choose another name!" );
781 else if (!( user
= find ( u
)))
783 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
785 else if ( isIgnore ( user
))
788 log ( "Ignoring %s ." , user
-> getNick ());
794 if (! is_playing ( user
))
796 ListNode
< aClient
> * temp
;
797 user
-> stats
= new Player ( user
);
798 user
-> stats
-> client
= user
; // Set the backwards pointer
799 user
-> stats
-> reset (); // set the user up
800 strncpy ( user
-> stats
-> password
, crypt ( password
, salt
), 255 );
801 strncpy ( user
-> stats
-> name
, name
, 255 );
802 unsigned long hv
= iHASH (( unsigned char *) name
);
803 updateTS ( user
-> stats
);
804 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
805 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
807 // Update the last login time
808 user
-> stats
-> lastlogin
= time ( NULL
);
810 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
811 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
812 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
813 setPlaying ( user
); // set the playing flag
817 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
822 void do_identify ( char * u
)
824 char * password
, * name
;
826 name
= strtok ( NULL
, " " );
827 password
= strtok ( NULL
, " " );
828 if (! password
|| ! name
)
830 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
832 else if (!( user
= find ( u
)))
834 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
835 log ( "Error: aClient not found: %s " , u
);
837 else if ( isIgnore ( user
))
840 log ( "Ignoring %s ." , user
-> getNick ());
844 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
845 notice ( s_GameServ
, u
, "Player %s not found" , name
);
846 else if ( is_playing ( user
))
848 notice ( s_GameServ
, u
, "You are already playing!" );
850 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
852 notice ( s_GameServ
, u
, "That player has already identified." );
854 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
856 notice ( s_GameServ
, u
, "Password incorrect" );
859 ListNode
< aClient
> * temp
;
860 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
);
861 temp
= players
[ hv
]. Find ( p
);
864 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
868 user
-> stats
= new Player ( p
-> stats
-> name
);
870 log ( "Setting data for identified" );
872 user
-> stats
-> setData ( p
-> stats
);
873 user
-> stats
-> client
= user
;
874 updateTS ( user
-> stats
);
878 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
,
882 setPlaying ( user
); // set the playing flag
886 // Update the last login time
887 user
-> stats
-> lastlogin
= time ( NULL
);
889 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
890 showNews ( u
, todaysnews
);
894 void do_stats ( char * u
)
899 nick
= strtok ( NULL
, " " );
901 if (!( user
= find ( u
)))
903 log ( "Fatal Error: %s not found in client list" , u
);
906 else if ( isIgnore ( user
))
909 log ( "Ignoring %s ." , user
-> getNick ());
915 if (! is_playing ( user
))
917 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
922 updateTS ( user
-> stats
);
923 showstats ( u
, user
-> stats
-> name
);
933 log ( "Calling delete_masters()" );
939 log ( "Initializing masters" );
942 for ( int x
= 0 ; x
< LEVELS
; x
++)
943 masters
[ x
] = new Monster
;
945 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
946 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
947 masters
[ 0 ]-> strength
= 32 ;
948 masters
[ 0 ]-> gold
= 0 ;
950 masters
[ 0 ]-> maxhp
= 35 ;
952 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!" );
954 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
955 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
956 masters
[ 1 ]-> strength
= 48 ;
957 masters
[ 1 ]-> gold
= 0 ;
959 masters
[ 1 ]-> maxhp
= 51 ;
961 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." );
963 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
964 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
965 masters
[ 2 ]-> strength
= 88 ;
966 masters
[ 2 ]-> gold
= 0 ;
968 masters
[ 2 ]-> maxhp
= 100 ;
969 masters
[ 2 ]-> hp
= 100 ;
970 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!" );
973 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
974 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
975 masters
[ 3 ]-> strength
= 169 ;
976 masters
[ 3 ]-> gold
= 0 ;
978 masters
[ 3 ]-> maxhp
= 165 ;
979 masters
[ 3 ]-> hp
= 165 ;
980 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
982 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
983 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
984 masters
[ 4 ]-> strength
= 275 ;
985 masters
[ 4 ]-> gold
= 0 ;
987 masters
[ 4 ]-> maxhp
= 232 ;
988 masters
[ 4 ]-> hp
= 232 ;
989 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!" );
991 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
992 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
993 masters
[ 5 ]-> strength
= 347 ;
994 masters
[ 5 ]-> gold
= 0 ;
996 masters
[ 5 ]-> maxhp
= 504 ;
997 masters
[ 5 ]-> hp
= 504 ;
998 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
1001 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
1002 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
1003 masters
[ 6 ]-> strength
= 515 ;
1004 masters
[ 6 ]-> gold
= 0 ;
1005 masters
[ 6 ]-> exp
= 0 ;
1006 masters
[ 6 ]-> maxhp
= 1078 ;
1007 masters
[ 6 ]-> hp
= 1078 ;
1008 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
1010 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
1011 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
1012 masters
[ 7 ]-> strength
= 655 ;
1013 masters
[ 7 ]-> gold
= 0 ;
1014 masters
[ 7 ]-> exp
= 0 ;
1015 masters
[ 7 ]-> maxhp
= 2207 ;
1016 masters
[ 7 ]-> hp
= 2207 ;
1017 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
1020 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
1021 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
1022 masters
[ 8 ]-> strength
= 819 ;
1023 masters
[ 8 ]-> gold
= 0 ;
1024 masters
[ 8 ]-> exp
= 0 ;
1025 masters
[ 8 ]-> maxhp
= 2780 ;
1026 masters
[ 8 ]-> hp
= 2780 ;
1027 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
1029 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
1030 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
1031 masters
[ 9 ]-> strength
= 1014 ;
1032 masters
[ 9 ]-> gold
= 0 ;
1033 masters
[ 9 ]-> exp
= 0 ;
1034 masters
[ 9 ]-> maxhp
= 3046 ;
1035 masters
[ 9 ]-> hp
= 3046 ;
1036 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
1038 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
1039 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
1040 masters
[ 10 ]-> strength
= 1286 ;
1041 masters
[ 10 ]-> gold
= 0 ;
1042 masters
[ 10 ]-> exp
= 0 ;
1043 masters
[ 10 ]-> maxhp
= 3988 ;
1044 masters
[ 10 ]-> hp
= 3988 ;
1045 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." );
1048 void init_monsters ()
1051 log ( "Calling delete_monsters" );
1056 for ( int x
= 0 ; x
< LEVELS
; x
++)
1057 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1058 monsters
[ x
][ y
] = new Monster ();
1061 void delete_monsters ()
1063 for ( int x
= 0 ; x
< LEVELS
; x
++)
1064 for ( int y
= 0 ; y
< MONSTERS
; y
++)
1066 delete monsters
[ x
][ y
];
1069 void delete_masters ()
1071 for ( int x
= 0 ; x
< LEVELS
; x
++)
1076 void display_monster ( char * u
)
1080 aClient
* user
= find ( u
);
1081 Player
* ni
= user
-> stats
;
1083 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1084 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
1085 notice ( s_GameServ
, u
, "Here are your commands:" );
1086 notice ( s_GameServ
, u
, "/msg %S attack" );
1087 notice ( s_GameServ
, u
, "/msg %S run" );
1088 notice ( s_GameServ
, u
, "What will you do?" );
1092 void display_players ( char * u
)
1095 if (!( user
= find ( u
)))
1097 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1100 display_players ( user
);
1103 void display_players ( aClient
* user
)
1105 char * u
= user
-> getNick ();
1106 if ( is_playing ( user
) && player_fight ( user
))
1108 aClient
* battle
= user
-> stats
-> battle
;
1109 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1110 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
1111 notice ( s_GameServ
, u
, "Here are your commands:" );
1112 notice ( s_GameServ
, u
, "/msg %S attack" );
1113 notice ( s_GameServ
, u
, "/msg %S run" );
1114 notice ( s_GameServ
, u
, "What will you do?" );
1119 bool is_playing ( char * u
)
1122 if (!( user
= find ( u
)))
1125 return is_playing ( user
);
1128 bool is_playing ( aClient
* user
)
1130 if ( user
-> stats
== NULL
)
1134 else if ( user
-> stats
-> client
== NULL
)
1138 else if (! FL_is_playing ( user
))
1146 bool is_fighting ( char * u
)
1150 if (!( user
= find ( u
)))
1153 return is_fighting ( user
);
1156 bool is_fighting ( aClient
* user
)
1158 if (! is_playing ( user
))
1161 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1164 bool player_fight ( char * u
)
1168 if (!( user
= find ( u
)))
1171 return player_fight ( user
);
1174 bool player_fight ( aClient
* user
)
1176 if (! is_playing ( user
))
1178 else if ( user
-> stats
-> battle
!= NULL
)
1180 return user
-> stats
-> battle
-> stats
!= NULL
;
1185 bool master_fight ( char * u
)
1189 if (!( user
= find ( u
)))
1192 return master_fight ( user
);
1195 bool master_fight ( aClient
* user
)
1197 if (! is_playing ( user
))
1200 return user
-> stats
-> master
!= NULL
;
1203 void do_fight ( char * u
)
1205 aClient
* ni
, * battle
;
1207 char * nick
= strtok ( NULL
, " " );
1211 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1214 else if (!( ni
= find ( u
)))
1216 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1219 else if ( isIgnore ( ni
))
1222 log ( "Ignoring %s ." , ni
-> getNick ());
1226 else if (! is_playing ( ni
))
1228 notice ( s_GameServ
, u
, "You are not playing!" );
1232 updateTS ( ni
-> stats
);
1234 if ( ni
-> stats
-> player_fights
<= 0 )
1236 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1237 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1238 "day. You have to wait until tomorrow!" );
1240 else if (!( battle
= findplayer ( nick
)))
1242 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1244 else if (! isAlive ( ni
-> stats
))
1246 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1248 else if (! is_playing ( battle
))
1250 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1253 /* offline fighting not available yet
1254 else if (!(fight = finduser(nick)))
1256 ni->stats->battle = battle;
1257 battle->battle = ni;
1258 setYourTurn(ni->stats);
1259 clearYourTurn(battle->stats);
1261 notice(s_GameServ, u, "You decide to fight %s while they're "\
1262 "not in the realm!",
1263 battle->stats->name);
1267 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1269 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1271 else if (! isAlive ( battle
-> stats
))
1273 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1275 else if ( player_fight ( battle
))
1277 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1279 else if ( master_fight ( battle
))
1281 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
);
1283 else if ( is_fighting ( battle
))
1285 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1287 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1289 // You can't fight someone below you by more than X level(s)
1290 // level 12 can fight level (12 - X) but not < (12 - X)
1291 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1292 battle
-> stats
-> name
);
1294 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1296 // You can't fight someone above you by more than X level(S)
1297 // level 1 can fight level (1 + X), but not > (1 + X)
1298 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1299 "weakling!" , ni
-> stats
-> name
);
1303 // Set your battle pointer to the other player
1304 ni
-> stats
-> battle
= battle
;
1306 // Set the other player's battle pointer to you
1307 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1309 // The initiator gets the first move (perhaps this should be 50/50)
1310 setYourTurn ( ni
-> stats
);
1311 clearYourTurn ( battle
-> stats
);
1313 // Initiate Battle sequence!
1314 ni
-> stats
-> player_fights
-= 1 ;
1316 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1317 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1318 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1319 "because they initiated!" , ni
-> stats
-> name
);
1320 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1321 display_players ( ni
);
1325 void do_use ( char * u
)
1330 char * item
= strtok ( NULL
, " " );
1334 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1335 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1338 else if (!( user
= find ( u
)))
1340 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1343 else if ( isIgnore ( user
))
1346 log ( "Ignoring %s ." , user
-> getNick ());
1350 else if (! is_playing ( user
))
1352 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1356 updateTS ( user
-> stats
);
1358 p
= & user
-> stats
-> inventory
;
1360 if ( stricmp ( item
, "HEALING" ) == 0 )
1362 if ( p
-> Healing () <= 0 )
1364 notice ( s_GameServ
, u
, "You are out of Healing Potions!" );
1367 int oldhealing
= user
-> stats
-> hp
;
1368 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1369 if ( user
-> stats
-> hp
- user
-> stats
-> maxhp
>= 100 )
1371 user
-> stats
-> hp
= user
-> stats
-> maxhp
+ 100 ;
1373 if ( oldhealing
>= ( user
-> stats
-> maxhp
+ 100 ))
1375 notice ( s_GameServ
, u
, "You cannot hold anymore HP!" );
1380 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1381 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1382 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealing
);
1384 if ( player_fight ( user
))
1386 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1387 " %s has used a healing potion!" );
1390 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1392 if ( p
-> Strength () <= 0 )
1394 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1397 int oldstrength
= user
-> stats
-> strength
;
1398 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1399 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1400 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1401 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1403 if ( player_fight ( user
))
1405 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1406 " %s has used a strength potion!" );
1409 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1411 if ( p
-> Defense () <= 0 )
1413 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1416 int olddefense
= user
-> stats
-> defense
;
1417 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1418 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1419 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1420 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1422 if ( player_fight ( user
))
1424 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1425 " %s has used a defense potion!" );
1428 else if ( stricmp ( item
, "HP" ) == 0 )
1432 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1435 int oldHP
= user
-> stats
-> maxhp
;
1436 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1437 user
-> stats
-> maxhp
+= 2 +
1438 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1440 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1442 if ( player_fight ( user
))
1444 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1445 " %s has used a HP potion!" );
1450 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}" );
1454 end_turn ( user
); // If they're fighting, end their turn
1456 void do_run ( char * u
)
1459 Player
* p
, * p2
= NULL
;
1461 if (!( user
= find ( u
)))
1463 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1466 else if ( isIgnore ( user
))
1469 log ( "Ignoring %s ." , user
-> getNick ());
1473 else if (! is_playing ( user
))
1475 notice ( s_GameServ
, u
, "You must be playing to run!" );
1479 updateTS ( user
-> stats
);
1483 p2
= p
-> battle
-> stats
;
1485 if (! is_fighting ( user
))
1486 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1487 else if (! player_fight ( user
) && ! master_fight ( user
))
1489 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1493 else if ( player_fight ( user
) && isYourTurn ( p
))
1495 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1496 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1499 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1501 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1503 else if ( master_fight ( user
))
1505 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1510 void end_turn ( aClient
* user
)
1512 char * nick
, * u
= user
-> getNick ();
1517 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1519 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1522 if (! player_fight ( user
) && ! master_fight ( user
))
1523 fight
= user
-> stats
-> fight
;
1525 fight
= user
-> stats
-> master
;
1526 battle
= user
-> stats
-> battle
;
1528 if (! player_fight ( user
))
1531 mhit
= ( fight
-> strength
/ 2 ) +
1532 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1533 arbonus
[ user
-> stats
-> armor
]));
1538 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1539 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1540 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1542 if (! player_fight ( user
))
1547 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1548 fight
-> name
, fight
-> weapon
, mhit
);
1551 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1553 if ( mhit
>= user
-> stats
-> hp
)
1555 if (! master_fight ( user
))
1557 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1558 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1559 "of your experience!" );
1560 user
-> stats
-> gold
= 0 ;
1561 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1562 user
-> stats
-> hp
= 0 ;
1563 user
-> stats
-> fight
= NULL
;
1564 clearAlive ( user
-> stats
);
1569 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1570 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1571 user
-> stats
-> fight
= NULL
;
1572 user
-> stats
-> master
= NULL
;
1579 user
-> stats
-> hp
-= mhit
;
1586 clearYourTurn ( user
-> stats
);
1587 setYourTurn ( battle
-> stats
);
1588 display_players ( battle
);
1594 void do_attack ( char * u
)
1597 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1598 Monster
* fight
; // The monster they may be fighting
1600 if (!( ni
= find ( u
)))
1602 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1605 else if ( isIgnore ( ni
))
1608 log ( "Ignoring %s ." , ni
-> getNick ());
1612 else if (! is_playing ( ni
))
1614 notice ( s_GameServ
, u
, "You're not playing!" );
1617 else if (! is_fighting ( ni
))
1619 notice ( s_GameServ
, u
, "You're not in battle!" );
1624 if (! ni
-> stats
-> master
) // This is not a master fight
1625 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1626 else // This IS a master fight
1627 fight
= ni
-> stats
-> master
; // Master Could be NULL
1629 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1631 // One has to be !NULL based on the previous else if
1632 // We wouldn't be here if they were all NULL
1634 updateTS ( ni
-> stats
);
1636 if (! player_fight ( ni
))
1639 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1640 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1643 mhit
= ( fight
-> strength
/ 2 ) +
1644 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1645 arbonus
[ ni
-> stats
-> armor
]));
1650 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1651 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1652 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1655 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1656 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1657 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1660 if (! player_fight ( ni
))
1663 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1665 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1667 if ( hit
>= fight
-> hp
)
1669 if ( master_fight ( ni
))
1671 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1672 addNews ( todaysnews
, " %s has bested %s and moved " \
1673 "to level %d " , ni
-> stats
-> name
, fight
-> name
,
1674 ( ni
-> stats
-> level
+ 1 ));
1677 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1679 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1680 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1681 fight
-> exp
, fight
-> gold
);
1683 // If your new experience (or gold) will be greater than 2 billion,
1684 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1685 // This could be a problem with overflowing out of the sign bit.
1686 // Unsigned long int maybe? Leave it for now.
1687 ni
-> stats
-> exp
+= fight
-> exp
;
1688 if ( ni
-> stats
-> exp
< 0 || ni
-> stats
-> exp
> 2000000000 )
1689 ni
-> stats
-> exp
= 2000000000 ;
1691 ni
-> stats
-> gold
+= fight
-> gold
;
1692 if ( ni
-> stats
-> gold
< 0 || ni
-> stats
-> gold
> 2000000000 )
1693 ni
-> stats
-> gold
= 2000000000 ;
1695 if ( master_fight ( ni
))
1697 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1698 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1699 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1701 // Increase your level
1703 // Increase your maximum hit points
1704 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1706 // Heal the player by setting hp to their max
1707 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1709 // Add to your strength
1710 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1712 // Add to your defensive power
1713 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1717 // Clear the pointer for your master
1718 ni
-> stats
-> master
= NULL
;
1721 // They're dead so remove the pointer
1722 delete ni
-> stats
-> fight
;
1723 ni
-> stats
-> fight
= NULL
;
1724 ni
-> stats
-> master
= NULL
;
1734 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1735 fight
-> name
, fight
-> weapon
, mhit
);
1738 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1740 if ( mhit
>= ni
-> stats
-> hp
)
1742 if (! master_fight ( ni
))
1744 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1745 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1746 "of your experience!" );
1747 addNews ( todaysnews
, " %s has been killed by %s !" ,
1748 ni
-> stats
-> name
, fight
-> name
);
1749 ni
-> stats
-> gold
= 0 ;
1750 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1752 ni
-> stats
-> fight
= NULL
;
1753 clearAlive ( ni
-> stats
);
1758 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1759 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1760 addNews ( todaysnews
, " %s tried to best %s and failed!" ,
1761 ni
-> stats
-> name
, fight
-> name
);
1762 ni
-> stats
-> fight
= NULL
;
1763 ni
-> stats
-> master
= NULL
;
1770 ni
-> stats
-> hp
-= mhit
;
1776 else if ( player_fight ( ni
))
1778 /* Offline fighting not available yet
1779 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1782 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1784 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1785 if (hit >= battle->stats->hp)
1787 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1788 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1789 (long int)(battle->stats->exp * .10), battle->stats->gold);
1790 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1792 ni->stats->exp += (long int)(battle->stats->exp * .10);
1793 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1797 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1798 ni->stats->exp = 2000000000;
1801 if (2000000000 - ni->stats->gold > battle->stats->gold)
1803 * ni->stats->gold += battle->stats->gold;
1804 battle->stats->gold = 0;
1808 battle->stats->gold = 2000000000 - ni->stats->gold;
1809 ni->stats->gold = 2000000000;
1811 * ni->stats->battle->stats->alive = 0;
1812 ni->stats->battle->battle = NULL;
1813 ni->stats->battle = NULL;
1819 * battle->stats->hp -= hit;
1822 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1823 battle->nick, weapons[battle->stats->weapon], mhit);
1826 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1828 if (mhit >= ni->stats->hp)
1830 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1831 if (2000000000 - battle->stats->gold > ni->stats->gold)
1833 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1834 battle->stats->gold += ni->stats->gold;
1835 * ni->stats->gold = 0;
1839 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1841 ni->stats->gold -= (2000000000 - battle->stats->gold);
1842 notice(s_GameServ, u, "You were left dead with %d gold.",
1843 * (long int)ni->stats->gold);
1844 battle->stats->gold = 2000000000;
1846 ni->stats->battle->battle = NULL;
1847 ni->stats->battle = NULL;
1848 ni->stats->alive = 0;
1854 ni->stats->hp -= mhit;
1860 * end offline fighting */
1862 if ( is_playing ( battle
))
1864 if (! isYourTurn ( ni
-> stats
))
1866 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1867 battle
-> stats
-> name
);
1872 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1874 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1875 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1876 weapons
[ ni
-> stats
-> weapon
], hit
);
1880 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1881 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1884 if ( hit
>= battle
-> stats
-> hp
)
1886 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1887 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1888 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1889 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1891 battle
-> stats
-> hp
= 0 ;
1892 clearAlive ( battle
-> stats
);
1894 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1895 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1897 if ( ni
-> stats
-> exp
< 0 || ni
-> stats
-> exp
> 2000000000 )
1898 ni
-> stats
-> exp
= 2000000000 ;
1900 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1902 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1903 "all gold on hand!" );
1904 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1905 battle
-> stats
-> gold
= 0 ;
1909 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1910 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1912 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1913 "gold." , ni
-> stats
-> name
);
1915 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1916 "left. All is not lost!" , battle
-> stats
-> gold
);
1918 ni
-> stats
-> gold
= 2000000000 ;
1921 clearYourTurn ( ni
-> stats
);
1922 clearYourTurn ( battle
-> stats
);
1923 battle
-> stats
-> battle
= NULL
;
1924 ni
-> stats
-> battle
= NULL
;
1930 battle
-> stats
-> hp
-= hit
;
1931 clearYourTurn ( ni
-> stats
);
1932 setYourTurn ( battle
-> stats
);
1933 display_players ( battle
);
1934 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1935 battle
-> stats
-> name
);
1942 void do_heal ( char * u
)
1945 char * amount
= strtok ( NULL
, " " );
1950 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1953 else if (!( ni
= find ( u
)))
1955 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1958 else if ( isIgnore ( ni
))
1961 log ( "Ignoring %s ." , ni
-> getNick ());
1965 else if (! is_playing ( ni
))
1967 notice ( s_GameServ
, u
, "You aren't playing!" );
1970 else if (! isAlive ( ni
-> stats
))
1972 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1975 else if ( is_fighting ( ni
))
1977 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1980 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1982 notice ( s_GameServ
, u
, "You don't need healing!" );
1986 updateTS ( ni
-> stats
);
1987 if ( stricmp ( amount
, "ALL" ) == 0 )
1989 price
= ni
-> stats
-> level
* 3 ;
1990 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1992 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1993 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1994 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1995 ni
-> stats
-> gold
%= price
;
1999 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2000 "per point." , price
);
2001 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
2002 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
2003 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
2004 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2005 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2008 else if ( isstringnum ( amount
))
2010 num
= stringtoint ( amount
);
2011 price
= ni
-> stats
-> level
* 3 ;
2012 if ( ni
-> stats
-> gold
< price
* num
)
2014 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
2015 ( long int ) ni
-> stats
-> gold
/ price
);
2017 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2019 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2021 ni
-> stats
-> hp
+= num
;
2022 ni
-> stats
-> gold
-= num
* price
;
2024 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2026 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2027 "per point." , price
);
2028 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2029 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
2030 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2031 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2034 else if ( amount
[ 0 ] == '-' )
2035 notice ( s_GameServ
, u
, "You trying to cheat?" );
2037 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2040 int isstringnum ( char * num
)
2043 for ( x
= 0 ; x
< strlen ( num
); x
++)
2045 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2051 long int stringtoint ( char * number
)
2053 long int x
, len
= strlen ( number
), sum
= 0 ;
2055 return chartoint ( number
[ 0 ]);
2056 sum
+= chartoint ( number
[ len
- 1 ]);
2057 for ( x
= len
- 2 ; x
>= 0 ; x
--)
2058 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
2062 long int pow ( int x
, int y
)
2068 if ( x
!= 0 && y
!= 0 )
2070 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2078 long int chartoint ( char ch
)
2080 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2081 return int ( ch
) - 48 ;
2088 ListNode
< aClient
> * ptr
;
2092 outfile
. open ( playerdata
);
2096 log ( "Error opening %s " , playerdata
);
2100 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2102 ptr
= players
[ x
]. First ();
2105 it
= ptr
-> getData ()-> stats
;
2107 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2108 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2109 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2110 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2111 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2112 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP ()
2113 << ' ' << it
-> lastlogin
<< endl
;
2126 char * tempname
, * buf
, * password
;
2127 buf
= new char [ 1023 ];
2129 infile
. open ( playerdata
);
2133 log ( "Error opening %s " , playerdata
);
2137 for ( int x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2139 ListNode
< aClient
> * tempNode
;
2140 tempNode
= players
[ x
]. First ();
2143 if ( tempNode
-> getData ()-> stats
-> client
)
2144 logout ( tempNode
-> getData ()-> stats
-> client
);
2145 tempNode
= tempNode
-> Next ();
2147 players
[ x
]. deleteNodes ();
2150 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2153 tempname
= strtok ( buf
, " " );
2154 temp
-> stats
= new Player ( tempname
);
2157 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2158 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2159 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2160 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2161 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2162 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2163 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2164 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2165 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2166 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2167 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2168 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2169 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2171 password
= strtok ( NULL
, " " );
2172 strcpy ( p
-> password
, password
);
2173 temp
-> setNick ( "Not Playing" );
2175 temp
-> setRealNick ( "Not Playing" );
2178 p
-> inventory
. reset (); // Set inventory to all 0s
2179 // Old player databases didn't have these three extra values
2180 // If they come up null, leave them to 0 as the default.
2181 // On the next gameserv database save, it will save the values.
2182 tempname
= strtok ( NULL
, " " );
2184 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2186 tempname
= strtok ( NULL
, " " );
2188 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2190 tempname
= strtok ( NULL
, " " );
2192 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2194 tempname
= strtok ( NULL
, " " );
2196 p
-> inventory
. setHP ( stringtoint ( tempname
));
2198 tempname
= strtok ( NULL
, " " );
2200 p
-> lastlogin
= stringtoint ( tempname
);
2202 p
-> lastlogin
= time ( NULL
);
2204 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
);
2206 temp
-> stats
-> client
= NULL
;
2207 players
[ hv
]. insertAtBack ( temp
);
2215 bool passcmp ( char * encrypted
, char * plaintext
)
2218 char * plaintext2
, * plainToencrypt
;
2221 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2222 strcpy ( plaintext2
, plaintext
);
2224 salt
[ 0 ] = encrypted
[ 0 ];
2225 salt
[ 1 ] = encrypted
[ 1 ];
2228 plainToencrypt
= crypt ( plaintext2
, salt
);
2230 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2232 delete [] plaintext2
;
2237 bool check_password ( char * name
, char * plaintext
)
2241 if (!( client
= findplayer ( name
)))
2245 return passcmp ( client
-> stats
-> password
, plaintext
);
2249 void do_store ( char * u
)
2251 char * cmd
= strtok ( NULL
, " " );
2252 char * item
= strtok ( NULL
, " " );
2253 char * num
= strtok ( NULL
, " " );
2261 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2262 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2263 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2266 else if (!( user
= find ( u
)))
2268 log ( "Fatal Error: could not find %s in client list" , u
);
2271 else if ( isIgnore ( user
))
2274 log ( "Ignoring %s ." , user
-> getNick ());
2278 else if (! is_playing ( user
))
2280 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2283 else if (! isAlive ( user
-> stats
))
2285 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2288 updateTS ( user
-> stats
);
2290 if ( stricmp ( cmd
, "LIST" ) == 0 )
2292 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2294 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2295 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2296 for ( int x
= 1 ; x
< WNA
; x
++)
2298 space
= spaces ( strlen ( weapons
[ x
]), "." );
2299 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2302 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2303 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2306 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2308 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2309 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2310 for ( int x
= 1 ; x
< WNA
; x
++)
2312 space
= spaces ( strlen ( armors
[ x
]), "." );
2313 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2316 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2317 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2321 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2324 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2327 else if (! isstringnum ( num
))
2329 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2332 if ( stricmp ( item
, "WEAPON" ) == 0 )
2334 wep
= stringtoint ( num
);
2335 if ( wep
>= WNA
|| wep
< 1 )
2337 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2344 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2345 else if ( p
-> gold
< prices
[ wep
- 1 ])
2346 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2349 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2351 p
-> gold
-= prices
[ wep
- 1 ];
2354 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2356 wep
= stringtoint ( num
);
2357 if ( wep
>= WNA
|| wep
< 1 )
2359 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2366 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2367 else if ( p
-> gold
< prices
[ wep
- 1 ])
2368 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2371 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2373 p
-> gold
-= prices
[ wep
- 1 ];
2377 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2381 if ( stricmp ( item
, "WEAPON" ) == 0 )
2385 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2388 else if ( p
-> gold
== 2000000000 )
2390 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2393 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2395 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2396 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2397 p
-> gold
= 2000000000 ;
2402 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2403 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2407 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2413 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2416 if ( p
-> gold
== 2000000000 )
2418 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2421 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2423 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2424 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2425 p
-> gold
= 2000000000 ;
2430 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2431 ( prices
[ p
-> armor
- 1 ] / 2 ));
2433 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2439 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2440 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2441 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2446 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2447 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2448 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2452 void do_inventory ( char * u
)
2456 if (!( user
= find ( u
)))
2458 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2461 else if ( isIgnore ( user
))
2464 log ( "Ignoring %s ." , user
-> getNick ());
2468 else if (! is_playing ( user
))
2470 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2473 updateTS ( user
-> stats
);
2474 showinventory ( user
, user
);
2476 void showinventory ( aClient
* from
, aClient
* to
)
2478 char * nick
= to
-> getNick ();
2482 if ( is_playing ( from
))
2484 Pouch
* p
= & from
-> stats
-> inventory
;
2485 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2486 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2487 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2488 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2489 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2492 void do_tavern ( char * u
)
2494 char * cmd
= strtok ( NULL
, " " );
2500 if (!( user
= find ( u
)))
2502 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2505 else if ( isIgnore ( user
))
2508 log ( "Ignoring %s ." , user
-> getNick ());
2512 else if (! is_playing ( user
))
2514 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2517 else if ( is_fighting ( user
))
2519 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2523 updateTS ( user
-> stats
);
2528 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2529 notice ( s_GameServ
, u
, "Your commands:" );
2530 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2531 notice ( s_GameServ
, u
, "What'll it be?" );
2533 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2535 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2536 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2537 1000 * p
-> level
* 4 );
2538 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2539 2500 * p
-> level
* 4 );
2540 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2541 3000 * p
-> level
* 4 );
2542 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2543 2000 * p
-> level
* 4 );
2544 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2545 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2547 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2549 char * chnum
= strtok ( NULL
, " " );
2553 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2554 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2557 int num
= stringtoint ( chnum
);
2559 if ( num
< 1 || num
> 4 )
2561 notice ( s_GameServ
, u
, "Invalid Choice!" );
2562 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2563 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2564 1000 * p
-> level
* 4 );
2565 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2566 2500 * p
-> level
* 4 );
2567 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2568 3000 * p
-> level
* 4 );
2569 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2570 2000 * p
-> level
* 4 );
2571 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2572 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2578 price
= ( 1000 * p
-> level
* 4 );
2579 if ( p
-> gold
>= price
)
2581 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2582 p
-> inventory
. incHealing ();
2586 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2589 price
= 2500 * p
-> level
* 4 ;
2590 if ( p
-> gold
>= price
)
2592 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2593 p
-> inventory
. incStrength ();
2597 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2600 price
= 3000 * p
-> level
* 4 ;
2601 if ( p
-> gold
>= price
)
2603 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2604 p
-> inventory
. incDefense ();
2608 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2611 price
= 3000 * p
-> level
* 4 ;
2612 if ( p
-> gold
>= price
)
2614 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2615 p
-> inventory
. incHP ();
2619 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2622 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2628 notice ( s_GameServ
, u
, "Improper Syntax." );
2629 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2633 void do_bank ( char * u
)
2635 char * cmd
= strtok ( NULL
, " " );
2636 char * amount
= strtok ( NULL
, " " );
2637 char * nick
= strtok ( NULL
, " " );
2642 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2644 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2645 notice ( s_GameServ
, u
, "BANK BALANCE" );
2648 else if (!( user
= find ( u
)))
2650 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2652 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2655 else if ( isIgnore ( user
))
2658 log ( "Ignoring %s ." , user
-> getNick ());
2662 else if (! is_playing ( user
))
2664 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2667 else if ( is_fighting ( user
))
2669 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2672 updateTS ( user
-> stats
);
2673 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2678 else if (! isAlive ( user
-> stats
))
2680 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2683 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2685 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2688 if ( stringtoint ( amount
) < 0 )
2690 notice ( s_GameServ
, u
, "Sorry. This bank is not licensed " \
2691 "to handle such sums of cash, noble Lord." );
2696 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2698 if ( p
-> bank
== 2000000000 )
2700 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2703 else if ( stricmp ( amount
, "ALL" ) == 0 )
2705 if ( 2000000000 - p
-> bank
< p
-> gold
)
2707 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2708 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2709 p
-> gold
-= ( 2000000000 - p
-> bank
);
2710 p
-> bank
= 2000000000 ;
2715 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2721 else if ( stringtoint ( amount
) > p
-> gold
)
2723 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2729 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2731 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2732 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2733 p
-> gold
-= ( 2000000000 - p
-> bank
);
2734 p
-> bank
= 2000000000 ;
2739 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2740 p
-> bank
+= stringtoint ( amount
);
2741 p
-> gold
-= stringtoint ( amount
);
2746 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2748 if ( p
-> gold
== 2000000000 )
2750 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2754 else if ( stricmp ( amount
, "ALL" ) == 0 )
2756 if ( 2000000000 - p
-> gold
< p
-> bank
)
2758 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2759 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2760 p
-> bank
-= ( 2000000000 - p
-> gold
);
2761 p
-> gold
= 2000000000 ;
2766 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2772 else if ( stringtoint ( amount
) > p
-> bank
)
2774 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2780 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2782 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2783 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2784 ( 2000000000 - p
-> gold
));
2785 p
-> bank
-= ( 2000000000 - p
-> gold
);
2786 p
-> gold
= 2000000000 ;
2791 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2792 p
-> gold
+= stringtoint ( amount
);
2793 p
-> bank
-= stringtoint ( amount
);
2801 void do_dragon ( char * u
)
2805 if (!( user
= find ( u
)))
2807 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2810 else if ( isIgnore ( user
))
2813 log ( "Ignoring %s ." , user
-> getNick ());
2817 else if (! is_playing ( user
))
2819 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2822 else if ( is_fighting ( user
))
2824 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2827 else if (! isAlive ( user
-> stats
))
2829 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2832 else if ( user
-> stats
-> level
< REALLEVELS
)
2834 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2835 "to vanquish any foe should DARE fight the dragon!" );
2836 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2837 "You are too weak. You must be Level %d !" , REALLEVELS
);
2841 updateTS ( user
-> stats
);
2843 Player
* p
= user
-> stats
;
2844 p
-> fight
= new Monster (& boss
);
2845 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2846 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2847 "deep, red fog rolls in. The air is filled with the " \
2848 "heated mist of deadly fire from beyond the cave " \
2850 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2851 "your %s , and venture into the hot, dark cave. " \
2852 "You are surprised at the angle of descent as you climb " \
2853 "lower and lower, deeper into the dragon's den." );
2854 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2855 "a tooth. It is a large tooth... bigger than your torso." \
2856 " Suddenly the darkness lifts from the gleam of an eye " \
2857 " staring into your soul! The eye is large... HUGE!" );
2858 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2859 "glare orange! The tooth is moving... but it is still too " \
2860 "dark for you to make out.... THE DRAGON! You see it!" );
2864 void do_master ( char * u
)
2869 if (!( user
= find ( u
)))
2871 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2874 else if ( isIgnore ( user
))
2877 log ( "Ignoring %s ." , user
-> getNick ());
2881 else if (! is_playing ( user
))
2883 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2886 else if ( is_fighting ( user
))
2888 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2891 else if (! isAlive ( user
-> stats
))
2893 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2897 updateTS ( user
-> stats
);
2899 char * cmd
= strtok ( NULL
, " " );
2900 Player
* p
= user
-> stats
;
2905 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2949 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
2953 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2959 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2963 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2971 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
));
2974 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2977 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
);
2979 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2985 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2989 void see_master ( char * u
)
2993 if (!( user
= find ( u
)))
2995 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2999 if (! is_fighting ( user
) && is_playing ( user
))
3001 Player
* p
= user
-> stats
;
3002 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
3003 p
-> fight
= p
-> master
;
3004 display_monster ( u
); // Since master is the same structure, use this function
3008 void showBankBalance ( const char * u
)
3013 if (!( user
= find ( u
)))
3021 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
3027 ListNode
< aClient
> * it
;
3029 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3031 it
= players
[ x
]. First ();
3035 p
= it
-> getData ()-> stats
;
3042 void refresh ( Player
* p
)
3047 if ( p
-> hp
< p
-> maxhp
)
3049 p
-> forest_fights
= forestfights
;
3050 p
-> player_fights
= 3 ;
3055 void do_refresh ( char * u
)
3057 char * nick
= strtok ( NULL
, " " );
3060 if (!( user
= find ( u
)))
3062 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3063 log ( "Error: aClient not found: %s " , u
);
3066 else if ( isIgnore ( user
))
3069 log ( "Ignoring %s ." , user
-> getNick ());
3073 else if (! isAdmin ( user
))
3075 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3080 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3083 else if ( stricmp ( nick
, "ALL" ) == 0 )
3085 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3088 else if (( user
= findplayer ( nick
)))
3090 if ( is_playing ( user
))
3093 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3095 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3097 refresh ( user
-> stats
);
3102 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3104 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3110 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3118 ListNode
< aClient
> * it
;
3121 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3123 it
= players
[ x
]. First ();
3127 p
= it
-> getData ()-> stats
;
3134 void reset ( Player
* p
)
3137 myname
= new char [ strlen ( p
-> name
)];
3138 strcpy ( myname
, p
-> name
);
3143 strcpy ( p
-> name
, myname
);
3147 void updateTS ( Player
* p
)
3153 log ( "Old timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3155 p
-> lastcommand
= time ( NULL
);
3157 log ( "New timestamp for %s : %l d" , p
-> name
, p
-> lastcommand
);
3162 bool timedOut ( Player
* p
)
3166 else if ( p
-> lastcommand
== 0 )
3170 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3177 void timeOutEvent ( Player
* p
)
3179 aClient
* user
= findplayer ( p
-> name
);
3181 if (! user
|| ! p
-> client
) // then they're not playing
3184 char * nick
= user
-> getNick ();
3186 if ( player_fight ( user
) && isYourTurn ( p
))
3188 // Check to see if they were the idler or if it was the other
3190 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3192 // This person's last command was given earlier,
3193 // so this person is the idler
3194 notice ( s_GameServ
, nick
, "You timed out " \
3195 "during a fight. You lose your turn!" );
3196 notice ( s_GameServ
, p
-> battle
-> getNick (),
3197 " %s hesitated for too long. Your move." , p
-> name
);
3199 setYourTurn ( p
-> battle
-> stats
);
3201 // Update the TS for both players to give them another
3202 // Chance to wake up, but if the other player doesn't
3203 // Attack now, they both get logged out.
3205 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3206 display_players ( p
-> battle
);
3211 notice ( s_GameServ
, p
-> battle
-> getNick (),
3212 "You and %s timed out at the same time." \
3213 " Don't fight if you're just going to " \
3214 "sit there!" , p
-> name
);
3215 notice ( s_GameServ
, user
-> getNick (),
3216 "You and %s timed out at the same time." \
3217 " Don't fight if you're just going to " \
3218 "sit there!" , p
-> battle
-> stats
-> name
);
3224 else if (! player_fight ( user
))
3226 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3228 // Place fun stuff here :)
3229 int randnum
= 1 + rand () % 100 ; // 1-100
3230 #define GSN(s) notice(s_GameServ, nick, s)
3231 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3235 // 35-100% of your gold goes pffft - kain
3236 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3238 GSN ( "You stop for a moment to rest on the " \
3239 "street corner. All of a sudden, you " \
3240 "are ambushed from all sides by a hoarde " \
3241 "of knife wielding thugs." );
3242 GSN2 ( "The thugs beat you into utter submission " \
3243 "and steal %d gold from you!" , stolen
);
3244 user
-> stats
-> gold
-= stolen
;
3246 else if ( randnum
>= 50 && randnum
< 75 )
3248 // 25-65% of your gold goes pffft - kain
3249 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3250 GSN ( "While dilly dallying around, you lose " \
3251 "your sense of time. Little did you know, " \
3252 "but thieves lifted your gold while you " \
3253 "weren't watching." );
3254 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3255 user
-> stats
-> gold
-= stolen
;
3257 else if ( randnum
>= 75 )
3259 // 25-75% of your gold goes pffft - kain
3260 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3261 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3262 "goblins grabbed your gold!" );
3263 GSN2 ( "They stole %d gold from you!" , stolen
);
3264 user
-> stats
-> gold
-= stolen
;
3268 // Always log out the user
3273 void do_reset ( char * u
)
3275 char * nick
= strtok ( NULL
, " " );
3278 if (!( user
= find ( u
)))
3280 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3281 log ( "Error: aClient not found: %s " , u
);
3284 else if (! isAdmin ( user
))
3286 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3292 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3295 else if ( stricmp ( nick
, "ALL" ) == 0 )
3297 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3300 else if (( user
= findplayer ( nick
)))
3302 if ( is_playing ( user
))
3305 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3307 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3313 notice ( s_GameServ
, u
, "Resetting %s " , user
-> stats
-> name
);
3319 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3324 void do_help ( char * u
)
3326 char * cmd
= strtok ( NULL
, " " );
3328 display_help ( u
, cmd
);
3331 void display_help ( char * u
, char * file
)
3338 infile
. open ( "helpfiles/help" );
3341 log ( "Error opening helpfiles/help" );
3342 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3345 buf
= new char [ 1024 ];
3346 while ( infile
. getline ( buf
, 1024 ))
3348 // Written this way, it will process %S in the helpfiles
3349 // Instead of notice(s_GameServ, u, "%s", buf);
3350 notice ( s_GameServ
, u
, buf
);
3354 aClient
* user
= find ( u
);
3355 if ( user
&& isAdmin ( user
))
3356 display_help ( u
, "admin_commands" );
3361 filename
= new char [ strlen ( file
) + 11 ];
3362 strcpy ( filename
, "helpfiles/" );
3363 strcat ( filename
, file
);
3365 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3366 filename
[ x
] = tolower ( filename
[ x
]);
3368 infile
. open ( filename
);
3372 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3375 buf
= new char [ 1024 ];
3376 while ( infile
. getline ( buf
, 1024 ))
3378 // Written this way, it will process %S in the helpfiles
3379 // Instead of notice(s_GameServ, u, "%s", buf);
3380 notice ( s_GameServ
, u
, buf
);
3387 void do_admin ( char * u
)
3390 char * pass
= strtok ( NULL
, " " );
3392 if (!( user
= find ( u
)))
3394 log ( "Error: aClient not found: %s " , u
);
3395 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3401 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3407 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3410 else if ( strcmp ( pass
, adminpass
) == 0 )
3412 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3415 log ( " %s became an administrator." , user
-> getRealNick ());
3417 log ( " %s became an administrator." , user
-> getNick ());
3422 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3427 bool load_monsters ()
3430 infile
. open ( "monsters.dat" );
3436 log ( "Error opening monsters.dat" );
3440 buf
= new char [ 2048 ];
3443 log ( "Loading monsters from monsters.dat" );
3446 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
3448 for ( int m
= 0 ; m
< MONSTERS
;)
3450 infile
. getline ( buf
, 2048 );
3451 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3455 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
3456 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
3457 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
3458 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
3459 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
3460 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
3461 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
3462 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));