]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
17 #if defined(HAVE_CRYPT_H)
21 #elif defined(HAVE_UNISTD_H)
28 Level levels
[ LEVELS
]; // The newest way to store monsters
36 char * strtok ( char * str
, const char * delim
);
39 int stricmp ( const char * s1
, const char * s2
);
40 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
43 /********** Password functions **********/
45 bool passcmp ( const char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
47 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
49 /********** Password functions **********/
52 /********** GameServ Booleans **********/
55 bool timedOut ( Player
* p
);
56 void updateTS ( Player
* p
);
57 void timeOutEvent ( Player
* p
);
59 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
60 bool is_playing ( aClient
* user
);
62 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
63 bool is_fighting ( aClient
* user
);
65 bool player_fight ( char * u
); // True if the player is fighting another player.
66 bool player_fight ( aClient
* user
);
68 bool master_fight ( char * u
); // True if the player is fighting their master.
69 bool master_fight ( aClient
* user
);
71 bool dragon_fight ( char * u
); // True if the player is fighting the dragon.
72 bool dragon_fight ( aClient
* user
);
74 /********** GameServ Booleans **********/
76 void display_help ( char * u
, char * file
= NULL
);
77 void display_monster ( char * u
);
78 void display_players ( char * u
);
79 void display_players ( aClient
* user
);
80 long int chartoint ( char ch
);
81 int isstringnum ( char * num
);
82 long int pow ( int x
, int y
);
83 long int stringtoint ( char * number
);
85 char * spaces ( int len
, char * seperator
);
86 void refresh ( Player
* p
);
88 void updateTS ( Player
* p
);
89 void reset ( Player
* p
);
93 void delete_monsters ();
95 void do_admin ( char * u
);
96 void do_attack ( char * u
);
97 void do_bank ( char * u
);
98 void do_check ( char * u
);
99 void do_fight ( char * u
);
100 void do_heal ( char * u
);
101 void do_help ( char * u
);
102 void do_identify ( char * u
);
103 void do_inventory ( char * u
);
104 void do_refresh ( char * u
);
105 void do_register ( char * u
);
106 void do_list ( char * u
);
107 void do_logout ( char * u
);
108 void do_master ( char * u
);
109 void do_dragon ( char * u
);
110 void do_play ( char * u
);
111 void do_quitg ( char * u
);
112 void do_reset ( char * u
);
113 void do_run ( char * u
);
114 void do_set ( char * u
);
115 void do_stats ( char * u
);
116 void do_store ( char * u
);
117 void do_tavern ( char * u
);
118 void do_use ( char * u
);
119 void see_master ( char * u
);
121 void logout ( aClient
* user
);
122 void showstats ( const char * u
, const char * nick
);
123 void showinventory ( aClient
* from
, aClient
* to
);
124 void showBankBalance ( const char * u
);
125 void end_turn ( aClient
* user
);
128 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
129 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
130 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
131 "Light Saber" , "Masamune" , "Mystical Sword" };
133 char * armors
[ WNA
] = { "Birthday Suit" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
134 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
135 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
136 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
138 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
139 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
140 int webonus
[ WNA
] = { 2 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
141 int arbonus
[ WNA
] = { 2 , 3 , 5 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
143 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
144 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
145 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
147 void gameserv ( char * source
, char * buf
)
150 cmd
= strtok ( buf
, " " );
153 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
158 cmd
++; // Get rid of that : at the beginning of the :text (command)
161 log ( "Source: %s Command: %s " , source
, cmd
);
164 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
167 ts
= strtok ( NULL
, "\1" );
168 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
169 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
170 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
171 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
172 cmd
= strtok ( NULL
, " " );
175 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
179 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
181 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
183 } else if ( stricmp ( cmd
, "CHECK" ) == 0 ) {
185 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
187 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
189 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
191 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
192 do_inventory ( source
);
193 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
195 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
197 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
199 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
201 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
203 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
205 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
207 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
209 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
211 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
213 } else if ( stricmp ( cmd
, "NEWS" ) == 0 ) {
215 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
217 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
219 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
221 } else if ( stricmp ( cmd
, "SET" ) == 0 ) {
223 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
225 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
228 if (!( user
= find ( source
)))
230 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
231 log ( "Error: aClient not found: %s " , source
);
233 else if (! isAdmin ( user
))
235 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
241 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
243 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
247 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
250 if (!( user
= find ( source
)))
252 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
253 log ( "Error: aClient not found: %s " , source
);
255 else if (! isAdmin ( user
))
257 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
263 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
266 if (!( user
= find ( source
)))
268 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
269 log ( "Error: aClient not found: %s " , source
);
271 else if (! isAdmin ( user
))
273 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
277 char * cmd2
= strtok ( NULL
, " " );
280 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
283 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
285 notice ( s_GameServ
, source
, "Loading monster data" );
289 display_help ( source
, cmd
);
292 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
295 if (!( user
= find ( source
)))
297 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
298 log ( "Error: aClient not found: %s " , source
);
300 else if (! isAdmin ( user
))
302 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
306 char * rest
= strtok ( NULL
, "" );
309 } else if ( stricmp ( cmd
, "PRINT" ) == 0 ) {
310 for ( int x
= 0 ; x
< LEVELS
; x
++)
311 levels
[ x
]. monsters
. print ();
312 } else if ( stricmp ( cmd
, "RANDOM" ) == 0 ) {
313 char * rstr
= strtok ( NULL
, "" );
315 trange
. setRange ( rstr
);
316 notice ( s_GameServ
, source
, "Random number in that range: %d " , trange
. random ());
320 if (( user
= find ( source
)))
325 log ( "Ignoring %s ." , user
-> getNick ());
330 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
336 source
--; // Bring the ':' back so we don't leak memory
339 cmd
--; // Same thing :)
342 int stricmp ( const char * s1
, const char * s2
)
346 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
352 if ( c
< tolower (* s2
))
357 void showstats ( const char * u
, const char * nick
)
359 aClient
* ni
, * sender
= find ( u
);
365 if (!( ni
= findplayer ( nick
)))
367 notice ( s_GameServ
, u
, " %s not found" , nick
);
371 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
. c_str ());
373 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
374 space
= spaces ( strlen ( buf
), " " );
375 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
379 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
380 space
= spaces ( strlen ( buf
), " " );
381 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
384 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
387 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
388 space
= spaces ( strlen ( buf
), " " );
389 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
390 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
393 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
394 space
= spaces ( strlen ( buf
), " " );
395 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
396 weapons
[ ni
-> stats
-> weapon
]);
399 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
400 space
= spaces ( strlen ( buf
), " " );
401 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
403 Pouch
* inv
= & ni
-> stats
-> inventory
;
405 notice ( s_GameServ
, u
, "Potions" );
406 sprintf ( buf
, "Healing: %d " , inv
-> Healing ());
407 space
= spaces ( strlen ( buf
), " " );
408 notice ( s_GameServ
, sender
-> getNick (), " %s%s HP: %d " , buf
,
412 sprintf ( buf
, "Strength: %d " , inv
-> Strength ());
413 space
= spaces ( strlen ( buf
), " " );
414 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " , buf
,
415 space
, inv
-> Defense ());
420 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
. c_str ());
425 char * spaces ( int len
, char * seperator
)
428 final
= new char [ 30 ];
430 strcpy ( final
, seperator
);
431 for ( y
= 0 ; y
< 30 - len
; y
++)
432 strcat ( final
, seperator
);
436 void raw ( const char * fmt
, ...)
441 input
= new char [ 1024 ];
443 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
449 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
450 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
451 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
454 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
459 sprintf ( input
, " %s%c " , input
, * t
);
464 log ( "Input: %s " , input
);
467 sprintf ( input
, " %s%s " , input
, " \r\n " );
468 sock_puts ( sock
, input
);
472 /* Send a NOTICE from the given source to the given nick. */
474 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
480 commanduse
= new char [ 16 ];
484 strcpy ( commanduse
, "P" );
486 strcpy ( commanduse
, "O" );
490 strcpy ( commanduse
, "PRIVMSG" );
492 strcpy ( commanduse
, "NOTICE" );
498 input
= new char [ 1024 ];
505 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
507 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
515 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
517 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
526 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
527 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
528 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
531 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
536 sprintf ( input
, " %s%c " , input
, * t
);
541 log ( "Input: %s " , input
);
543 sprintf ( input
, " %s%s " , input
, " \r\n " );
544 sock_puts ( sock
, input
);
545 delete [] commanduse
;
551 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
557 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
558 if ( c
== 0 || -- len
== 0 )
563 if ( c
< tolower (* s2
))
569 char * strtok ( char * str
, const char * delim
)
571 static char * current
= NULL
;
578 current
+= strspn ( current
, delim
);
579 ret
= * current
? current
: NULL
;
580 current
+= strcspn ( current
, delim
);
589 void do_check ( char * u
)
591 int days
, hours
, minutes
, seconds
;
593 complete
= ( lastrefresh
+ refreshperiod
) - time ( NULL
);
594 days
= complete
/ 86400 ;
595 hours
= ( complete
% 86400 ) / 3600 ;
596 minutes
= ( complete
% 86400 ) % 3600 / 60 ;
597 seconds
= ( complete
% 86400 ) % 3600 % 60 ;
599 notice ( s_GameServ
, u
, "Time left to next refresh: %d d %d h %d m %d s" ,
600 days
, hours
, minutes
, seconds
);
603 void do_list ( char * u
)
606 char * cmd
= strtok ( NULL
, " " );
608 if (!( user
= find ( u
)))
610 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
613 else if ( isIgnore ( user
))
616 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
621 ListNode
< aClient
> * temp
;
624 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
626 temp
= players
[ x
]. First ();
627 if (! players
[ x
]. isEmpty ())
631 if ( cmd
|| is_playing ( temp
-> getData ()))
635 notice ( s_GameServ
, u
, "Players:" );
639 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
640 temp
-> getData ()-> stats
-> name
. c_str ());
642 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
643 temp
-> getData ()-> stats
-> name
. c_str ());
652 notice ( s_GameServ
, u
, "No one is playing" );
654 notice ( s_GameServ
, u
, "End of List" );
659 aClient
* user
, * target
;
660 char * name
= strtok ( NULL
, " " );
661 char * cmd
= strtok ( NULL
, " " );
664 if (!( user
= find ( u
)))
666 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
667 "Buf: %s LOGOUT" , u
);
670 else if ( isIgnore ( user
))
673 log ( "Ignoring %s ." , user
-> getNick ());
679 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|WEAPON|ARMOR|HP POTIONS|STRENGTH POTIONS|DEFENSE POTIONS|HEALING POTIONS|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}" );
682 else if (!( target
= findplayer ( name
)))
684 // Back the pointers up... they didn't send a name probably
689 if (! is_playing ( user
))
691 notice ( s_GameServ
, u
, "You must be playing to set things for yourself!" );
697 cmd2
= strtok ( NULL
, " " );
700 // Regardless of the previous if/else, if it got here, we know we have the cmd pointer at the right spot.
701 if ( stricmp ( cmd
, "PASSWORD" ) == 0 )
703 // Person is looking to change their password
704 // If they're an admin, or it's theirself, allow it
705 // cmd2 is pointing to the password now
706 if ( isAdmin ( user
) || user
== target
)
708 target
-> stats
-> setPassword ( cmd2
);
709 notice ( s_GameServ
, u
, "Password successfully changed" );
711 else if ( user
!= target
&& ! isAdmin ( user
))
713 notice ( s_GameServ
, u
, "You must be a %S admin to set other peoples' passwords." );
717 else if ( stricmp ( cmd
, "BANK" ) == 0 || stricmp ( cmd
, "BALANCE" ) == 0 )
721 notice ( s_GameServ
, u
, "Admins Only!" );
724 else if ( stricmp ( cmd
, "BANK" ) == 0 )
726 cmd2
= strtok ( NULL
, " " ); // Need an extra parameter for set bank balance
730 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] [BANK] BALANCE <NUMBER>" );
734 target
-> stats
-> bank
= stringtoint ( cmd2
);
735 notice ( s_GameServ
, u
, "Bank balance changed to %s !" , cmd2
);
737 else if ( stricmp ( cmd
, "PLAYER" ) == 0 )
741 notice ( s_GameServ
, u
, "Admins Only!" );
744 else if ( stricmp ( cmd2
, "FIGHTS" ) != 0 )
746 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>" );
751 cmd2
= strtok ( NULL
, " " );
754 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>" );
757 target
-> stats
-> player_fights
= stringtoint ( cmd2
);
758 notice ( s_GameServ
, u
, "Player fights changed to %s !" , cmd2
);
761 else if ( stricmp ( cmd
, "FOREST" ) == 0 )
765 notice ( s_GameServ
, u
, "Admins Only!" );
768 else if ( stricmp ( cmd2
, "FIGHTS" ) != 0 )
770 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <number>" );
775 cmd2
= strtok ( NULL
, " " );
778 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <NUMBER>" );
781 target
-> stats
-> forest_fights
= stringtoint ( cmd2
);
782 notice ( s_GameServ
, u
, "Forest fights changed to %s !" , cmd2
);
785 else if ( stricmp ( cmd
, "GOLD" ) == 0 )
789 notice ( s_GameServ
, u
, "Admins Only!" );
796 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] GOLD <NUMBER>" );
799 target
-> stats
-> gold
= stringtoint ( cmd2
);
800 notice ( s_GameServ
, u
, "Gold set to %s " , cmd2
);
804 else if ( stricmp ( cmd
, "STRENGTH" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
808 notice ( s_GameServ
, u
, "Admins Only!" );
815 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] STRENGTH <NUMBER>" );
819 target
-> stats
-> strength
= stringtoint ( cmd2
);
820 notice ( s_GameServ
, u
, "Strength set to %s " , cmd2
);
824 else if ( stricmp ( cmd
, "DEFENSE" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
828 notice ( s_GameServ
, u
, "Admins Only!" );
835 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] DEFENSE <NUMBER>" );
839 target
-> stats
-> defense
= stringtoint ( cmd2
);
840 notice ( s_GameServ
, u
, "Defense set to %s " , cmd2
);
844 else if ( stricmp ( cmd
, "HP" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
848 notice ( s_GameServ
, u
, "Admins Only!" );
855 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] HP <NUMBER>" );
858 target
-> stats
-> hp
= stringtoint ( cmd2
);
859 notice ( s_GameServ
, u
, "HP set to %s " , cmd2
);
863 else if ( stricmp ( cmd
, "MAXHP" ) == 0 )
867 notice ( s_GameServ
, u
, "Admins Only!" );
874 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] MAXHP <NUMBER>" );
877 target
-> stats
-> maxhp
= stringtoint ( cmd2
);
878 notice ( s_GameServ
, u
, "MaxHP set to %s " , cmd2
);
882 else if ( stricmp ( cmd
, "EXPERIENCE" ) == 0 || stricmp ( cmd
, "EXP" ) == 0 )
886 notice ( s_GameServ
, u
, "Admins Only!" );
893 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] {EXPERIENCE|EXP} <NUMBER>" );
897 target
-> stats
-> exp
= stringtoint ( cmd2
);
898 notice ( s_GameServ
, u
, "Exp set to %s " , cmd2
);
902 else if ( stricmp ( cmd
, "LEVEL" ) == 0 )
906 notice ( s_GameServ
, u
, "Admins Only!" );
913 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] LEVEL <NUMBER>" );
916 target
-> stats
-> level
= stringtoint ( cmd2
);
917 notice ( s_GameServ
, u
, "Level set to %s " , cmd2
);
921 else if ( stricmp ( cmd
, "WEAPON" ) == 0 )
925 notice ( s_GameServ
, u
, "Admins Only!" );
932 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] WEAPON <NUMBER>" );
936 target
-> stats
-> weapon
= stringtoint ( cmd2
);
937 notice ( s_GameServ
, u
, "Weapon set to %s " , weapons
[ target
-> stats
-> weapon
]);
941 else if ( stricmp ( cmd
, "ARMOR" ) == 0 )
945 notice ( s_GameServ
, u
, "Admins Only!" );
952 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] ARMOR <NUMBER>" );
955 target
-> stats
-> armor
= stringtoint ( cmd2
);
956 notice ( s_GameServ
, u
, "Armor set to %s " , armors
[ target
-> stats
-> armor
]);
960 else if ( stricmp ( cmd
, "HP" ) == 0 && stricmp ( cmd2
, "POTIONS" ) == 0 )
964 notice ( s_GameServ
, u
, "Admins Only!" );
969 cmd2
= strtok ( NULL
, " " );
972 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] HP POTIONS <NUMBER>" );
975 target
-> stats
-> inventory
. setHP ( stringtoint ( cmd2
));
976 notice ( s_GameServ
, u
, "HP Potions set to %s " , cmd2
);
980 else if ( stricmp ( cmd
, "HEALING" ) == 0 && stricmp ( cmd2
, "POTIONS" ) == 0 )
984 notice ( s_GameServ
, u
, "Admins Only!" );
989 cmd2
= strtok ( NULL
, " " );
992 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] HEALING POTIONS <NUMBER>" );
995 target
-> stats
-> inventory
. setHealing ( stringtoint ( cmd2
));
996 notice ( s_GameServ
, u
, "Healing Potions set to %s " , cmd2
);
1000 else if ( stricmp ( cmd
, "STRENGTH" ) == 0 && stricmp ( cmd2
, "POTIONS" ) == 0 )
1004 notice ( s_GameServ
, u
, "Admins Only!" );
1009 cmd2
= strtok ( NULL
, " " );
1012 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] STRENGTH POTIONS <NUMBER>" );
1015 target
-> stats
-> inventory
. setStrength ( stringtoint ( cmd2
));
1016 notice ( s_GameServ
, u
, "Strength Potions set to %s " , cmd2
);
1020 else if ( stricmp ( cmd
, "DEFENSE" ) == 0 && stricmp ( cmd2
, "POTIONS" ) == 0 )
1024 notice ( s_GameServ
, u
, "Admins Only!" );
1029 cmd2
= strtok ( NULL
, " " );
1032 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] DEFENSE POTIONS <NUMBER>" );
1035 target
-> stats
-> inventory
. setDefense ( stringtoint ( cmd2
));
1036 notice ( s_GameServ
, u
, "Defense Potions set to %s " , cmd2
);
1040 else if ( stricmp ( cmd
, "ALIVE" ) == 0 )
1044 notice ( s_GameServ
, u
, "Admins Only!" );
1049 cmd2
= strtok ( NULL
, " " );
1050 if (! cmd2
|| ( stricmp ( cmd2
, "TRUE" ) != 0 && stricmp ( cmd2
, "FALSE" ) != 0 ))
1052 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET ALIVE TRUE|FALSE" );
1055 else if ( stricmp ( cmd2
, "TRUE" ) == 0 )
1057 notice ( s_GameServ
, u
, "Target has been Resurrected!" );
1058 setAlive ( target
-> stats
);
1062 notice ( s_GameServ
, u
, "Target is now dead!" );
1063 clearAlive ( target
-> stats
);
1067 else if ( stricmp ( cmd
, "SEEN" ) == 0 )
1071 notice ( s_GameServ
, u
, "Admins Only!" );
1074 else if ( stricmp ( cmd2
, "MASTER" ) != 0 )
1076 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] SEEN MASTER {TRUE|FALSE}" );
1081 cmd2
= strtok ( NULL
, " " );
1082 if (! cmd2
|| ( stricmp ( cmd2
, "TRUE" ) != 0 && stricmp ( cmd2
, "FALSE" ) != 0 ))
1084 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NICK] SEEN MASTER {TRUE|FALSE}" );
1087 else if ( stricmp ( cmd2
, "TRUE" ) == 0 )
1089 notice ( s_GameServ
, u
, "Target has seen their master now." );
1090 target
-> addFlag ( FLAG_MASTER
);
1094 notice ( s_GameServ
, u
, "Target has not seen their master now." );
1095 target
-> remFlag ( FLAG_MASTER
);
1101 notice ( s_GameServ
, u
, "Unknown command: SET %s " , cmd
);
1102 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|WEAPON|ARMOR|HP POTIONS|STRENGTH POTIONS|DEFENSE POTIONS|HEALING POTIONS|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}" );
1107 void do_logout ( char * u
)
1110 char * name
= strtok ( NULL
, " " );
1112 if (!( user
= find ( u
)))
1114 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
1115 "Buf: %s LOGOUT" , u
);
1116 log ( "Could not find aClient Buf: %s LOGOUT" ,
1120 else if ( isIgnore ( user
))
1123 log ( "Ignoring %s ." , user
-> getNick ());
1132 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
1134 else if (!( user
= findplayer ( name
)))
1136 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
1140 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> name
. c_str ());
1146 if (! is_playing ( user
))
1148 notice ( s_GameServ
, u
, "You're not logged in!" );
1150 else if ( is_fighting ( user
))
1152 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
1156 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
1162 void logout ( aClient
* user
)
1164 if ( is_playing ( user
))
1166 ListNode
< aClient
> * it
;
1168 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> name
. c_str ());
1169 it
= players
[ hv
]. Find ( user
);
1173 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
1174 " %S Admin. Cannot find you in the players list." );
1175 log ( "Error on logout(). Can't find %s in the players list" ,
1186 temp
-> stats
= new Player
;
1187 temp
-> stats
-> setData ( user
-> stats
);
1188 user
-> stats
-> client
= NULL
;
1190 if ( player_fight ( user
))
1191 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
1195 temp
-> stats
-> client
= NULL
;
1197 temp
-> setRealNick ( "Not Playing" );
1199 temp
-> setNick ( "Not Playing" );
1201 it
-> setNewPtr ( temp
);
1203 log ( "Logged out player %s " ,
1215 void do_register ( char * u
)
1217 char * password
, * name
;
1219 name
= strtok ( NULL
, " " );
1220 password
= strtok ( NULL
, " " );
1224 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
1228 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
1230 else if (( user
= findplayer ( name
)))
1232 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
1233 notice ( s_GameServ
, u
, "Choose another name!" );
1235 else if (!( user
= find ( u
)))
1237 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
1239 else if ( isIgnore ( user
))
1242 log ( "Ignoring %s ." , user
-> getNick ());
1248 if (! is_playing ( user
))
1250 ListNode
< aClient
> * temp
;
1251 user
-> stats
= new Player ( user
);
1252 user
-> stats
-> client
= user
; // Set the backwards pointer
1253 user
-> stats
-> reset (); // set the user up
1254 user
-> stats
-> setPassword ( password
);
1255 user
-> stats
-> name
= name
;
1256 unsigned long hv
= iHASH (( unsigned char *) name
);
1257 updateTS ( user
-> stats
);
1258 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
1259 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
1261 // Update the last login time
1262 user
-> stats
-> lastlogin
= time ( NULL
);
1264 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
. c_str (), password
);
1265 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
1266 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
. c_str ());
1267 setPlaying ( user
); // set the playing flag
1271 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
1276 void do_identify ( char * u
)
1278 char * password
, * name
;
1280 name
= strtok ( NULL
, " " );
1281 password
= strtok ( NULL
, " " );
1282 if (! password
|| ! name
)
1284 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
1286 else if (!( user
= find ( u
)))
1288 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
1289 log ( "Error: aClient not found: %s " , u
);
1291 else if ( isIgnore ( user
))
1294 log ( "Ignoring %s ." , user
-> getNick ());
1298 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
1299 notice ( s_GameServ
, u
, "Player %s not found" , name
);
1300 else if ( is_playing ( user
))
1302 notice ( s_GameServ
, u
, "You are already playing!" );
1304 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
1306 notice ( s_GameServ
, u
, "That player has already identified." );
1308 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
1310 notice ( s_GameServ
, u
, "Password incorrect" );
1313 ListNode
< aClient
> * temp
;
1314 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> name
. c_str ());
1315 temp
= players
[ hv
]. Find ( p
);
1318 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
1322 user
-> stats
= new Player ( p
-> stats
-> name
);
1324 log ( "Setting data for identified" );
1326 user
-> stats
-> setData ( p
-> stats
);
1327 user
-> stats
-> client
= user
;
1328 updateTS ( user
-> stats
);
1332 log ( "Player %s IRC: %s Identified" , user
-> stats
-> name
. c_str (),
1336 setPlaying ( user
); // set the playing flag
1340 // Update the last login time
1341 user
-> stats
-> lastlogin
= time ( NULL
);
1343 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
1344 showNews ( u
, todaysnews
);
1348 void do_stats ( char * u
)
1353 nick
= strtok ( NULL
, " " );
1355 if (!( user
= find ( u
)))
1357 log ( "Fatal Error: %s not found in client list" , u
);
1360 else if ( isIgnore ( user
))
1363 log ( "Ignoring %s ." , user
-> getNick ());
1369 if (! is_playing ( user
))
1371 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
1376 updateTS ( user
-> stats
);
1377 showstats ( u
, user
-> stats
-> name
. c_str ());
1386 ifstream
infile ( "data/masters.dat" );
1389 buf
= new char [ 1024 ];
1393 log ( "Error opening data/masters.dat" );
1398 log ( "Loading masters from data/masters.dat" );
1401 for ( l
= 0 ; l
< LEVELS
; l
++)
1403 infile
. getline ( buf
, 1024 , ' \n ' );
1406 if ( buf
[ 0 ] == '#' || buf
[ 0 ] == ' \n ' || buf
[ 0 ] == ' \r ' )
1411 else if ( buf
[ 0 ] == '^' )
1414 Monster
* master
= & levels
[ l
]. master
;
1416 char * name
, * weapon
, * strength
, * gold
, * exp
, * maxhp
, * death
;
1419 name
= strtok ( buf
, "~" );
1420 weapon
= strtok ( NULL
, "~" );
1421 strength
= strtok ( NULL
, "~" );
1422 gold
= strtok ( NULL
, "~" );
1423 exp
= strtok ( NULL
, "~" );
1424 maxhp
= strtok ( NULL
, "~" );
1425 death
= strtok ( NULL
, "~" );
1427 master
-> name
= name
;
1428 master
-> weapon
= weapon
;
1429 master
-> strength
= stringtoint ( strength
);
1430 master
-> gold
= stringtoint ( gold
);
1431 master
-> exp
= stringtoint ( exp
);
1432 master
-> maxhp
= stringtoint ( maxhp
);
1433 master
-> hp
= master
-> maxhp
;
1434 master
-> death
= death
;
1439 if ( l
< LEVELS
) // We didn't load a master for every level - check data/masters.dat
1445 void delete_monsters ()
1447 for ( int x
= 0 ; x
< LEVELS
; x
++)
1448 levels
[ x
]. monsters
. deleteNodes ();
1451 void display_monster ( char * u
)
1455 aClient
* user
= find ( u
);
1456 Player
* ni
= user
-> stats
;
1458 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
1459 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
. c_str (), ni
-> fight
-> hp
);
1460 notice ( s_GameServ
, u
, "Here are your commands:" );
1461 notice ( s_GameServ
, u
, "/msg %S attack" );
1462 notice ( s_GameServ
, u
, "/msg %S run" );
1463 notice ( s_GameServ
, u
, "What will you do?" );
1467 void display_players ( char * u
)
1470 if (!( user
= find ( u
)))
1472 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1475 display_players ( user
);
1478 void display_players ( aClient
* user
)
1480 char * u
= user
-> getNick ();
1481 if ( is_playing ( user
) && player_fight ( user
))
1483 aClient
* battle
= user
-> stats
-> battle
;
1484 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
1485 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
. c_str (), battle
-> stats
-> hp
);
1486 notice ( s_GameServ
, u
, "Here are your commands:" );
1487 notice ( s_GameServ
, u
, "/msg %S attack" );
1488 notice ( s_GameServ
, u
, "/msg %S run" );
1489 notice ( s_GameServ
, u
, "What will you do?" );
1494 bool is_playing ( char * u
)
1497 if (!( user
= find ( u
)))
1500 return is_playing ( user
);
1503 bool is_playing ( aClient
* user
)
1505 if ( user
-> stats
== NULL
)
1509 else if ( user
-> stats
-> client
== NULL
)
1513 else if (! FL_is_playing ( user
))
1521 bool is_fighting ( char * u
)
1525 if (!( user
= find ( u
)))
1528 return is_fighting ( user
);
1531 bool is_fighting ( aClient
* user
)
1533 if (! is_playing ( user
))
1536 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> fight
!= NULL
;
1539 bool player_fight ( char * u
)
1543 if (!( user
= find ( u
)))
1546 return player_fight ( user
);
1549 bool player_fight ( aClient
* user
)
1551 if (! is_playing ( user
))
1553 else if ( user
-> stats
-> battle
!= NULL
&& is_playing ( user
-> stats
-> battle
))
1555 return user
-> stats
-> battle
-> stats
!= NULL
;
1560 bool master_fight ( char * u
)
1564 if (!( user
= find ( u
)))
1567 return master_fight ( user
);
1570 bool master_fight ( aClient
* user
)
1572 if (! is_playing ( user
))
1575 return user
-> stats
-> master
!= NULL
;
1578 bool dragon_fight ( char * u
)
1581 if (!( user
= find ( u
)))
1584 return dragon_fight ( user
);
1587 bool dragon_fight ( aClient
* user
)
1589 if (! is_playing ( user
))
1592 return ( user
-> stats
-> level
== LEVELS
&& master_fight ( user
));
1594 void do_fight ( char * u
)
1596 aClient
* ni
, * battle
;
1598 char * nick
= strtok ( NULL
, " " );
1602 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1605 else if (!( ni
= find ( u
)))
1607 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1610 else if ( isIgnore ( ni
))
1613 log ( "Ignoring %s ." , ni
-> getNick ());
1617 else if (! is_playing ( ni
))
1619 notice ( s_GameServ
, u
, "You are not playing!" );
1623 updateTS ( ni
-> stats
);
1625 if ( ni
-> stats
-> player_fights
<= 0 )
1627 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1628 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1629 "day. You have to wait until tomorrow!" );
1631 else if (!( battle
= findplayer ( nick
)))
1633 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1635 else if (! isAlive ( ni
-> stats
))
1637 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1639 else if (! is_playing ( battle
))
1641 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1644 /* offline fighting not available yet
1645 else if (!(fight = finduser(nick)))
1647 ni->stats->battle = battle;
1648 battle->battle = ni;
1649 setYourTurn(ni->stats);
1650 clearYourTurn(battle->stats);
1652 notice(s_GameServ, u, "You decide to fight %s while they're "\
1653 "not in the realm!",
1654 battle->stats->name.c_str());
1658 else if ( stricmp ( ni
-> stats
-> name
. c_str (), battle
-> stats
-> name
. c_str ()) == 0 )
1660 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1662 else if (! isAlive ( battle
-> stats
))
1664 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1666 else if ( player_fight ( battle
))
1668 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
. c_str (), battle
-> stats
-> battle
-> stats
-> name
. c_str ());
1670 else if ( master_fight ( battle
))
1672 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> name
. c_str ());
1674 else if ( is_fighting ( battle
))
1676 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
. c_str (), battle
-> stats
-> fight
-> name
. c_str ());
1678 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1680 // You can't fight someone below you by more than X level(s)
1681 // level 12 can fight level (12 - X) but not < (12 - X)
1682 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1683 battle
-> stats
-> name
. c_str ());
1685 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1687 // You can't fight someone above you by more than X level(S)
1688 // level 1 can fight level (1 + X), but not > (1 + X)
1689 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1690 "weakling!" , ni
-> stats
-> name
. c_str ());
1694 // Set your battle pointer to the other player
1695 ni
-> stats
-> battle
= battle
;
1697 // Set the other player's battle pointer to you
1698 ni
-> stats
-> battle
-> stats
-> battle
= ni
;
1700 // The initiator gets the first move (perhaps this should be 50/50)
1701 setYourTurn ( ni
-> stats
);
1702 clearYourTurn ( battle
-> stats
);
1704 // Initiate Battle sequence!
1705 ni
-> stats
-> player_fights
-= 1 ;
1707 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
. c_str ());
1708 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
. c_str ());
1709 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1710 "because they initiated!" , ni
-> stats
-> name
. c_str ());
1711 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
. c_str ());
1712 display_players ( ni
);
1716 void do_use ( char * u
)
1721 char * item
= strtok ( NULL
, " " );
1725 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1726 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1729 else if (!( user
= find ( u
)))
1731 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1734 else if ( isIgnore ( user
))
1737 log ( "Ignoring %s ." , user
-> getNick ());
1741 else if (! is_playing ( user
))
1743 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1747 updateTS ( user
-> stats
);
1749 p
= & user
-> stats
-> inventory
;
1751 if ( stricmp ( item
, "HEALING" ) == 0 )
1753 if ( p
-> Healing () <= 0 )
1755 notice ( s_GameServ
, u
, "You are out of Healing Potions!" );
1758 int oldhealing
= user
-> stats
-> hp
;
1759 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1760 if ( user
-> stats
-> hp
- user
-> stats
-> maxhp
>= 100 )
1762 user
-> stats
-> hp
= user
-> stats
-> maxhp
+ 100 ;
1764 if ( oldhealing
>= ( user
-> stats
-> maxhp
+ 100 ))
1766 notice ( s_GameServ
, u
, "You cannot hold anymore HP!" );
1771 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1772 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1773 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealing
);
1775 if ( player_fight ( user
))
1777 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1778 " %s has used a healing potion!" );
1781 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1783 if ( p
-> Strength () <= 0 )
1785 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1788 int oldstrength
= user
-> stats
-> strength
;
1789 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1790 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1791 user
-> stats
-> strength
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1792 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1794 if ( player_fight ( user
))
1796 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1797 " %s has used a strength potion!" );
1800 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1802 if ( p
-> Defense () <= 0 )
1804 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1807 int olddefense
= user
-> stats
-> defense
;
1808 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1809 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1810 user
-> stats
-> defense
+= 1 + ( rand () % 10 >= 8 ? 1 : 0 ); // 1-2
1811 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1813 if ( player_fight ( user
))
1815 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1816 " %s has used a defense potion!" );
1819 else if ( stricmp ( item
, "HP" ) == 0 )
1823 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1826 int oldHP
= user
-> stats
-> maxhp
;
1827 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1828 user
-> stats
-> maxhp
+= 2 +
1829 ( rand () % 100 > 70 ? ( rand () % 7 ) : ( rand () % 2 ) );
1831 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1833 if ( player_fight ( user
))
1835 notice ( s_GameServ
, user
-> stats
-> battle
-> getNick (),
1836 " %s has used a HP potion!" );
1841 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}" );
1845 end_turn ( user
); // If they're fighting, end their turn
1847 void do_run ( char * u
)
1850 Player
* p
, * p2
= NULL
;
1852 if (!( user
= find ( u
)))
1854 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1857 else if ( isIgnore ( user
))
1860 log ( "Ignoring %s ." , user
-> getNick ());
1864 else if (! is_playing ( user
))
1866 notice ( s_GameServ
, u
, "You must be playing to run!" );
1870 updateTS ( user
-> stats
);
1874 p2
= p
-> battle
-> stats
;
1876 if (! is_fighting ( user
))
1877 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1878 else if (! player_fight ( user
) && ! master_fight ( user
))
1880 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
. c_str ());
1884 else if ( player_fight ( user
) && isYourTurn ( p
))
1886 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
. c_str ());
1887 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
. c_str ());
1890 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1892 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
. c_str ());
1894 else if ( master_fight ( user
))
1896 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
. c_str ());
1901 void end_turn ( aClient
* user
)
1903 char * nick
, * u
= user
-> getNick ();
1908 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1910 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1913 if (! player_fight ( user
) && ! master_fight ( user
))
1914 fight
= user
-> stats
-> fight
;
1916 fight
= user
-> stats
-> master
;
1917 battle
= user
-> stats
-> battle
;
1919 if (! player_fight ( user
))
1922 mhit
= ( fight
-> strength
/ 2 ) +
1923 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1924 arbonus
[ user
-> stats
-> armor
]));
1929 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1930 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1931 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1933 if (! player_fight ( user
))
1938 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1939 fight
-> name
. c_str (), fight
-> weapon
. c_str (), mhit
);
1942 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
. c_str ());
1944 if ( mhit
>= user
-> stats
-> hp
)
1946 if (! master_fight ( user
))
1948 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
. c_str ());
1949 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1950 "of your experience!" );
1951 user
-> stats
-> gold
= 0 ;
1952 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1953 user
-> stats
-> hp
= 0 ;
1954 user
-> stats
-> fight
= NULL
;
1955 clearAlive ( user
-> stats
);
1960 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1961 "until tomorrow to try again" , user
-> stats
-> master
-> name
. c_str ());
1962 user
-> stats
-> fight
= NULL
;
1963 user
-> stats
-> master
= NULL
;
1970 user
-> stats
-> hp
-= mhit
;
1977 clearYourTurn ( user
-> stats
);
1978 setYourTurn ( battle
-> stats
);
1979 display_players ( battle
);
1985 void do_heal ( char * u
)
1988 char * amount
= strtok ( NULL
, " " );
1993 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1996 else if (!( ni
= find ( u
)))
1998 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2001 else if ( isIgnore ( ni
))
2004 log ( "Ignoring %s ." , ni
-> getNick ());
2008 else if (! is_playing ( ni
))
2010 notice ( s_GameServ
, u
, "You aren't playing!" );
2013 else if (! isAlive ( ni
-> stats
))
2015 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
2018 else if ( is_fighting ( ni
))
2020 notice ( s_GameServ
, u
, "You can't heal in battle!" );
2023 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
2025 notice ( s_GameServ
, u
, "You don't need healing!" );
2029 updateTS ( ni
-> stats
);
2030 if ( stricmp ( amount
, "ALL" ) == 0 )
2032 price
= ni
-> stats
-> level
* 3 ;
2033 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
2035 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
2036 ( long int ) ni
-> stats
-> gold
/ price
, price
);
2037 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
2038 ni
-> stats
-> gold
%= price
;
2042 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2043 "per point." , price
);
2044 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
2045 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
2046 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
2047 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2048 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2051 else if ( isstringnum ( amount
))
2053 num
= stringtoint ( amount
);
2054 price
= ni
-> stats
-> level
* 3 ;
2055 if ( ni
-> stats
-> gold
< price
* num
)
2057 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
2058 ( long int ) ni
-> stats
-> gold
/ price
);
2060 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2062 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2064 ni
-> stats
-> hp
+= num
;
2065 ni
-> stats
-> gold
-= num
* price
;
2067 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
2069 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2070 "per point." , price
);
2071 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2072 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
2073 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
2074 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
2077 else if ( amount
[ 0 ] == '-' )
2078 notice ( s_GameServ
, u
, "You trying to cheat?" );
2080 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2083 int isstringnum ( char * num
)
2086 for ( x
= 0 ; x
< strlen ( num
); x
++)
2088 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2094 long int stringtoint ( char * number
)
2096 return atol ( number
);
2098 long int x, len = strlen(number), sum = 0;
2100 return chartoint(number[0]);
2101 sum += chartoint(number[len - 1]);
2102 for (x = len - 2; x >= 0; x--)
2103 sum += chartoint(number[x]) * pow(10, abs(x - len + 1));
2108 long int pow ( int x
, int y
)
2114 if ( x
!= 0 && y
!= 0 )
2116 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2124 long int chartoint ( char ch
)
2126 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2127 return int ( ch
) - 48 ;
2134 ListNode
< aClient
> * ptr
;
2138 outfile
. open ( playerdata
);
2142 log ( "Error opening %s " , playerdata
);
2146 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2148 ptr
= players
[ x
]. First ();
2151 it
= ptr
-> getData ()-> stats
;
2153 outfile
<< it
-> name
. c_str () << ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
2154 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
2155 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
2156 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
2157 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
2158 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP ()
2159 << ' ' << it
-> lastlogin
<< endl
;
2172 char * tempname
, * buf
, * password
;
2173 buf
= new char [ 1023 ];
2175 infile
. open ( playerdata
);
2179 log ( "Error opening %s " , playerdata
);
2183 for ( int x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2185 ListNode
< aClient
> * tempNode
;
2186 tempNode
= players
[ x
]. First ();
2189 if ( tempNode
-> getData ()-> stats
-> client
)
2190 logout ( tempNode
-> getData ()-> stats
-> client
);
2191 tempNode
= tempNode
-> Next ();
2193 players
[ x
]. deleteNodes ();
2196 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2199 tempname
= strtok ( buf
, " " );
2200 temp
-> stats
= new Player ( tempname
);
2203 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
2204 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
2205 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
2206 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
2207 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
2208 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
2209 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
2210 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
2211 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
2212 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
2213 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
2214 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
2215 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2217 password
= strtok ( NULL
, " " );
2218 p
-> password
= password
;
2219 temp
-> setNick ( "Not Playing" );
2221 temp
-> setRealNick ( "Not Playing" );
2224 p
-> inventory
. reset (); // Set inventory to all 0s
2225 // Old player databases didn't have these three extra values
2226 // If they come up null, leave them to 0 as the default.
2227 // On the next gameserv database save, it will save the values.
2228 tempname
= strtok ( NULL
, " " );
2230 p
-> inventory
. setHealing ( stringtoint ( tempname
));
2232 tempname
= strtok ( NULL
, " " );
2234 p
-> inventory
. setStrength ( stringtoint ( tempname
));
2236 tempname
= strtok ( NULL
, " " );
2238 p
-> inventory
. setDefense ( stringtoint ( tempname
));
2240 tempname
= strtok ( NULL
, " " );
2242 p
-> inventory
. setHP ( stringtoint ( tempname
));
2244 tempname
= strtok ( NULL
, " " );
2246 p
-> lastlogin
= stringtoint ( tempname
);
2248 p
-> lastlogin
= time ( NULL
);
2250 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> name
. c_str ());
2252 temp
-> stats
-> client
= NULL
;
2253 players
[ hv
]. insertAtBack ( temp
);
2261 bool passcmp ( const char * encrypted
, char * plaintext
)
2264 char * plaintext2
, * plainToencrypt
;
2267 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2268 strcpy ( plaintext2
, plaintext
);
2270 salt
[ 0 ] = encrypted
[ 0 ];
2271 salt
[ 1 ] = encrypted
[ 1 ];
2274 plainToencrypt
= crypt ( plaintext2
, salt
);
2276 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2278 delete [] plaintext2
;
2283 bool check_password ( char * name
, char * plaintext
)
2287 if (!( client
= findplayer ( name
)))
2291 return passcmp ( client
-> stats
-> password
. c_str (), plaintext
);
2295 void do_store ( char * u
)
2297 char * cmd
= strtok ( NULL
, " " );
2298 char * item
= strtok ( NULL
, " " );
2299 char * num
= strtok ( NULL
, " " );
2307 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2308 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2309 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2312 else if (!( user
= find ( u
)))
2314 log ( "Fatal Error: could not find %s in client list" , u
);
2317 else if ( isIgnore ( user
))
2320 log ( "Ignoring %s ." , user
-> getNick ());
2324 else if (! is_playing ( user
))
2326 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2329 else if (! isAlive ( user
-> stats
))
2331 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2334 updateTS ( user
-> stats
);
2336 if ( stricmp ( cmd
, "LIST" ) == 0 )
2338 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2340 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2341 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2342 for ( int x
= 1 ; x
< WNA
; x
++)
2344 space
= spaces ( strlen ( weapons
[ x
]), "." );
2345 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2348 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2349 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2352 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2354 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2355 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2356 for ( int x
= 1 ; x
< WNA
; x
++)
2358 space
= spaces ( strlen ( armors
[ x
]), "." );
2359 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2362 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2363 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2367 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2370 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2373 else if (! isstringnum ( num
))
2375 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2378 if ( stricmp ( item
, "WEAPON" ) == 0 )
2380 wep
= stringtoint ( num
);
2381 if ( wep
>= WNA
|| wep
< 1 )
2383 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2390 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2391 else if ( p
-> gold
< prices
[ wep
- 1 ])
2392 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2395 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2397 p
-> gold
-= prices
[ wep
- 1 ];
2400 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2402 wep
= stringtoint ( num
);
2403 if ( wep
>= WNA
|| wep
< 1 )
2405 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2412 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2413 else if ( p
-> gold
< prices
[ wep
- 1 ])
2414 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2417 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2419 p
-> gold
-= prices
[ wep
- 1 ];
2424 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2428 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2432 if ( stricmp ( item
, "WEAPON" ) == 0 )
2436 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2439 else if ( p
-> gold
== 2000000000 )
2441 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2444 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2446 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2447 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2448 p
-> gold
= 2000000000 ;
2453 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2454 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2458 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2464 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2467 if ( p
-> gold
== 2000000000 )
2469 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2472 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2474 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2475 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2476 p
-> gold
= 2000000000 ;
2481 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2482 ( prices
[ p
-> armor
- 1 ] / 2 ));
2484 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2490 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2491 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2492 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2497 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2498 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2499 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2503 void do_inventory ( char * u
)
2507 if (!( user
= find ( u
)))
2509 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2512 else if ( isIgnore ( user
))
2515 log ( "Ignoring %s ." , user
-> getNick ());
2519 else if (! is_playing ( user
))
2521 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2524 updateTS ( user
-> stats
);
2525 showinventory ( user
, user
);
2527 void showinventory ( aClient
* from
, aClient
* to
)
2529 char * nick
= to
-> getNick ();
2533 if ( is_playing ( from
))
2535 Pouch
* p
= & from
-> stats
-> inventory
;
2536 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
. c_str ());
2537 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2538 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2539 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2540 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2543 void do_tavern ( char * u
)
2545 char * cmd
= strtok ( NULL
, " " );
2551 if (!( user
= find ( u
)))
2553 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2556 else if ( isIgnore ( user
))
2559 log ( "Ignoring %s ." , user
-> getNick ());
2563 else if (! is_playing ( user
))
2565 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2568 else if ( is_fighting ( user
))
2570 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2574 updateTS ( user
-> stats
);
2579 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2580 notice ( s_GameServ
, u
, "Your commands:" );
2581 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2582 notice ( s_GameServ
, u
, "What'll it be?" );
2584 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2586 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2587 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2588 1000 * p
-> level
* 4 );
2589 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2590 2500 * p
-> level
* 4 );
2591 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2592 3000 * p
-> level
* 4 );
2593 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2594 2000 * p
-> level
* 4 );
2595 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2596 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2598 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2600 char * chnum
= strtok ( NULL
, " " );
2604 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2605 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2608 int num
= stringtoint ( chnum
);
2610 if ( num
< 1 || num
> 4 )
2612 notice ( s_GameServ
, u
, "Invalid Choice!" );
2613 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2614 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" ,
2615 1000 * p
-> level
* 4 );
2616 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" ,
2617 2500 * p
-> level
* 4 );
2618 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" ,
2619 3000 * p
-> level
* 4 );
2620 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" ,
2621 2000 * p
-> level
* 4 );
2622 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2623 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2629 price
= ( 1000 * p
-> level
* 4 );
2630 if ( p
-> gold
>= price
)
2632 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2633 p
-> inventory
. incHealing ();
2637 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2640 price
= 2500 * p
-> level
* 4 ;
2641 if ( p
-> gold
>= price
)
2643 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2644 p
-> inventory
. incStrength ();
2648 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2651 price
= 3000 * p
-> level
* 4 ;
2652 if ( p
-> gold
>= price
)
2654 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2655 p
-> inventory
. incDefense ();
2659 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2662 price
= 3000 * p
-> level
* 4 ;
2663 if ( p
-> gold
>= price
)
2665 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2666 p
-> inventory
. incHP ();
2670 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2673 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2679 notice ( s_GameServ
, u
, "Improper Syntax." );
2680 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2684 void do_bank ( char * u
)
2686 char * cmd
= strtok ( NULL
, " " );
2687 char * amount
= strtok ( NULL
, " " );
2688 char * nick
= strtok ( NULL
, " " );
2693 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2695 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2696 notice ( s_GameServ
, u
, "BANK BALANCE" );
2699 else if (!( user
= find ( u
)))
2701 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2703 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2706 else if ( isIgnore ( user
))
2709 log ( "Ignoring %s ." , user
-> getNick ());
2713 else if (! is_playing ( user
))
2715 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2718 else if ( is_fighting ( user
))
2720 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2723 updateTS ( user
-> stats
);
2724 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2729 else if (! isAlive ( user
-> stats
))
2731 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2734 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2736 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2739 if ( stringtoint ( amount
) < 0 )
2741 notice ( s_GameServ
, u
, "Sorry. This bank is not licensed " \
2742 "to handle such sums of cash, noble Lord." );
2747 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2749 if ( p
-> bank
== 2000000000 )
2751 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2754 else if ( stricmp ( amount
, "ALL" ) == 0 )
2756 if ( 2000000000 - p
-> bank
< p
-> gold
)
2758 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2759 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2760 p
-> gold
-= ( 2000000000 - p
-> bank
);
2761 p
-> bank
= 2000000000 ;
2766 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2772 else if ( stringtoint ( amount
) > p
-> gold
)
2774 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2780 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2782 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2783 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2784 p
-> gold
-= ( 2000000000 - p
-> bank
);
2785 p
-> bank
= 2000000000 ;
2790 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2791 p
-> bank
+= stringtoint ( amount
);
2792 p
-> gold
-= stringtoint ( amount
);
2797 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2799 if ( p
-> gold
== 2000000000 )
2801 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2805 else if ( stricmp ( amount
, "ALL" ) == 0 )
2807 if ( 2000000000 - p
-> gold
< p
-> bank
)
2809 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2810 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2811 p
-> bank
-= ( 2000000000 - p
-> gold
);
2812 p
-> gold
= 2000000000 ;
2817 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2823 else if ( stringtoint ( amount
) > p
-> bank
)
2825 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2831 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2833 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2834 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2835 ( 2000000000 - p
-> gold
));
2836 p
-> bank
-= ( 2000000000 - p
-> gold
);
2837 p
-> gold
= 2000000000 ;
2842 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2843 p
-> gold
+= stringtoint ( amount
);
2844 p
-> bank
-= stringtoint ( amount
);
2852 void do_dragon ( char * u
)
2856 if (!( user
= find ( u
)))
2858 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2861 else if ( isIgnore ( user
))
2864 log ( "Ignoring %s ." , user
-> getNick ());
2868 else if (! is_playing ( user
))
2870 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
2873 else if ( is_fighting ( user
))
2875 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
2878 else if (! isAlive ( user
-> stats
))
2880 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2883 else if ( user
-> stats
-> level
< LEVELS
)
2885 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
2886 "to vanquish any foe should DARE fight the dragon!" );
2887 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
2888 "You are too weak. You must be Level %d !" , REALLEVELS
);
2892 updateTS ( user
-> stats
);
2894 Player
* p
= user
-> stats
;
2896 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
2897 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
2898 "deep, red fog rolls in. The air is filled with the " \
2899 "heated mist of deadly fire from beyond the cave " \
2901 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
2902 "your %s , and venture into the hot, dark cave. " \
2903 "You are surprised at the angle of descent as you climb " \
2904 "lower and lower, deeper into the dragon's den." ,
2905 armors
[ p
-> armor
], weapons
[ p
-> weapon
]);
2906 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
2907 "a tooth. It is a large tooth... bigger than your torso." \
2908 " Suddenly the darkness lifts from the gleam of an eye " \
2909 " staring into your soul! The eye is large... HUGE!" );
2910 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
2911 "glare orange! The tooth is moving... but it is still too " \
2912 "dark for you to make out.... THE DRAGON! You see it!" );
2916 void do_master ( char * u
)
2921 if (!( user
= find ( u
)))
2923 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2926 else if ( isIgnore ( user
))
2929 log ( "Ignoring %s ." , user
-> getNick ());
2933 else if (! is_playing ( user
))
2935 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2938 else if ( is_fighting ( user
))
2940 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2943 else if (! isAlive ( user
-> stats
))
2945 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2949 updateTS ( user
-> stats
);
2951 char * cmd
= strtok ( NULL
, " " );
2952 Player
* p
= user
-> stats
;
2957 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
3001 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
3005 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
3011 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
3015 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
3023 notice ( s_GameServ
, u
, "You are not worthy of fighting %s ! You need %l d more experience." ,
3024 levels
[ p
-> level
- 1 ]. master
. name
. c_str (), ( need
- p
-> exp
));
3027 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
3030 notice ( s_GameServ
, u
, " %s looks you up and down and decides you are more ready than you will ever be." ,
3031 levels
[ p
-> level
- 1 ]. master
. name
. c_str ());
3033 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" ,
3034 levels
[ p
-> level
- 1 ]. master
. name
. c_str (), p
-> name
. c_str ());
3040 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
3044 void see_master ( char * u
)
3048 if (!( user
= find ( u
)))
3050 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
3054 if (! is_fighting ( user
) && is_playing ( user
))
3056 Player
* p
= user
-> stats
;
3057 p
-> master
= new Monster (& levels
[ p
-> level
- 1 ]. master
);
3058 p
-> fight
= p
-> master
;
3059 display_monster ( u
); // Since master is the same structure, use this function
3063 void showBankBalance ( const char * u
)
3068 if (!( user
= find ( u
)))
3076 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
3082 ListNode
< aClient
> * it
;
3084 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3086 it
= players
[ x
]. First ();
3090 p
= it
-> getData ()-> stats
;
3097 void refresh ( Player
* p
)
3102 if ( p
-> hp
< p
-> maxhp
)
3104 p
-> forest_fights
= forestfights
;
3105 p
-> player_fights
= 3 ;
3110 void do_refresh ( char * u
)
3112 char * nick
= strtok ( NULL
, " " );
3115 if (!( user
= find ( u
)))
3117 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3118 log ( "Error: aClient not found: %s " , u
);
3121 else if ( isIgnore ( user
))
3124 log ( "Ignoring %s ." , user
-> getNick ());
3128 else if (! isAdmin ( user
))
3130 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3135 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3138 else if ( stricmp ( nick
, "ALL" ) == 0 )
3140 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3143 else if (( user
= findplayer ( nick
)))
3145 if ( is_playing ( user
))
3148 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3150 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3152 refresh ( user
-> stats
);
3157 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3159 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3165 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3173 ListNode
< aClient
> * it
;
3176 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3178 it
= players
[ x
]. First ();
3182 p
= it
-> getData ()-> stats
;
3189 void reset ( Player
* p
)
3196 myname
= new string ( p
-> name
);
3203 void updateTS ( Player
* p
)
3209 log ( "Old timestamp for %s : %l d" , p
-> name
. c_str (), p
-> lastcommand
);
3211 p
-> lastcommand
= time ( NULL
);
3213 log ( "New timestamp for %s : %l d" , p
-> name
. c_str (), p
-> lastcommand
);
3218 bool timedOut ( Player
* p
)
3222 else if ( p
-> lastcommand
== 0 )
3226 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3233 void timeOutEvent ( Player
* p
)
3235 aClient
* user
= findplayer ( p
-> name
. c_str ());
3237 if (! user
|| ! p
-> client
) // then they're not playing
3240 char * nick
= user
-> getNick ();
3242 if ( player_fight ( user
) && isYourTurn ( p
))
3244 // Check to see if they were the idler or if it was the other
3246 if ( p
-> lastcommand
!= p
-> battle
-> stats
-> lastcommand
)
3248 // This person's last command was given earlier,
3249 // so this person is the idler
3250 notice ( s_GameServ
, nick
, "You timed out " \
3251 "during a fight. You lose your turn!" );
3252 notice ( s_GameServ
, p
-> battle
-> getNick (),
3253 " %s hesitated for too long. Your move." , p
-> name
. c_str ());
3255 setYourTurn ( p
-> battle
-> stats
);
3257 // Update the TS for both players to give them another
3258 // Chance to wake up, but if the other player doesn't
3259 // Attack now, they both get logged out.
3261 p
-> battle
-> stats
-> lastcommand
= p
-> lastcommand
;
3262 display_players ( p
-> battle
);
3267 notice ( s_GameServ
, p
-> battle
-> getNick (),
3268 "You and %s timed out at the same time." \
3269 " Don't fight if you're just going to " \
3270 "sit there!" , p
-> name
. c_str ());
3271 notice ( s_GameServ
, user
-> getNick (),
3272 "You and %s timed out at the same time." \
3273 " Don't fight if you're just going to " \
3274 "sit there!" , p
-> battle
-> stats
-> name
. c_str ());
3280 else if (! player_fight ( user
))
3282 if ( isAlive ( user
-> stats
) && user
-> stats
-> gold
> 0 )
3284 // Place fun stuff here :)
3285 int randnum
= 1 + rand () % 100 ; // 1-100
3286 #define GSN(s) notice(s_GameServ, nick, s)
3287 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3291 // 35-100% of your gold goes pffft - kain
3292 int stolen
= ( 35 + ( rand () % 66 )) * user
-> stats
-> gold
/ 100 ;
3294 GSN ( "You stop for a moment to rest on the " \
3295 "street corner. All of a sudden, you " \
3296 "are ambushed from all sides by a hoarde " \
3297 "of knife wielding thugs." );
3298 GSN2 ( "The thugs beat you into utter submission " \
3299 "and steal %d gold from you!" , stolen
);
3300 user
-> stats
-> gold
-= stolen
;
3302 else if ( randnum
>= 50 && randnum
< 75 )
3304 // 25-65% of your gold goes pffft - kain
3305 int stolen
= ( 25 + ( rand () % 41 )) * user
-> stats
-> gold
/ 100 ;
3306 GSN ( "While dilly dallying around, you lose " \
3307 "your sense of time. Little did you know, " \
3308 "but thieves lifted your gold while you " \
3309 "weren't watching." );
3310 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3311 user
-> stats
-> gold
-= stolen
;
3313 else if ( randnum
>= 75 )
3315 // 25-75% of your gold goes pffft - kain
3316 int stolen
= ( 25 + ( rand () % 51 )) * user
-> stats
-> gold
/ 100 ;
3317 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3318 "goblins grabbed your gold!" );
3319 GSN2 ( "They stole %d gold from you!" , stolen
);
3320 user
-> stats
-> gold
-= stolen
;
3324 // Always log out the user
3329 void do_reset ( char * u
)
3331 char * nick
= strtok ( NULL
, " " );
3334 if (!( user
= find ( u
)))
3336 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3337 log ( "Error: aClient not found: %s " , u
);
3340 else if (! isAdmin ( user
))
3342 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3348 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3351 else if ( stricmp ( nick
, "ALL" ) == 0 )
3353 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3356 else if (( user
= findplayer ( nick
)))
3358 if ( is_playing ( user
))
3361 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3363 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3369 notice ( s_GameServ
, u
, "Resetting %s " , user
-> stats
-> name
. c_str ());
3375 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3380 void do_help ( char * u
)
3382 char * cmd
= strtok ( NULL
, " " );
3384 display_help ( u
, cmd
);
3387 void display_help ( char * u
, char * file
)
3394 infile
. open ( "helpfiles/help" );
3397 log ( "Error opening helpfiles/help" );
3398 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3401 buf
= new char [ 1024 ];
3402 while ( infile
. getline ( buf
, 1024 ))
3404 // Written this way, it will process %S in the helpfiles
3405 // Instead of notice(s_GameServ, u, "%s", buf);
3406 notice ( s_GameServ
, u
, buf
);
3410 aClient
* user
= find ( u
);
3411 if ( user
&& isAdmin ( user
))
3412 display_help ( u
, "admin_commands" );
3417 filename
= new char [ strlen ( file
) + 11 ];
3418 strcpy ( filename
, "helpfiles/" );
3419 strcat ( filename
, file
);
3421 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3422 filename
[ x
] = tolower ( filename
[ x
]);
3424 infile
. open ( filename
);
3428 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3431 buf
= new char [ 1024 ];
3432 while ( infile
. getline ( buf
, 1024 ))
3434 // Written this way, it will process %S in the helpfiles
3435 // Instead of notice(s_GameServ, u, "%s", buf);
3436 notice ( s_GameServ
, u
, buf
);
3443 void do_admin ( char * u
)
3446 char * pass
= strtok ( NULL
, " " );
3448 if (!( user
= find ( u
)))
3450 log ( "Error: aClient not found: %s " , u
);
3451 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3457 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3463 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3466 else if ( strcmp ( pass
, adminpass
) == 0 )
3468 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3471 log ( " %s became an administrator." , user
-> getRealNick ());
3473 log ( " %s became an administrator." , user
-> getNick ());
3478 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3486 filename
= new char [ 256 ];
3488 for ( int x
= 1 ; x
<= LEVELS
; x
++)
3490 sprintf ( filename
, "data/levels/level %d .dat" , x
);
3491 if ( levels
[ x
- 1 ]. loadLevel ( filename
) == false )
3498 bool load_monsters ()
3503 buf
= new char [ 2048 ];
3505 for ( int level
= 1 ; level
<= LEVELS
; level
++)
3507 filename
= new char [ 256 ];
3508 sprintf ( filename
, "data/monsters/level %d .dat" , level
);
3509 infile
. open ( filename
);
3513 log ( "Error opening %s " , filename
);
3518 log ( "Loading monsters from %s " , filename
);
3521 while ( infile
. getline ( buf
, 2048 ))
3525 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3530 temp
-> name
= strtok ( buf
, "~" );
3531 temp
-> weapon
= strtok ( NULL
, "~" );
3532 temp
-> death
= strtok ( NULL
, "~" );
3534 levels
[ level
- 1 ]. monsters
. insertAtBack_RLN ( temp
);