]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
20 #if defined(HAVE_CRYPT_H)
24 #elif defined(HAVE_UNISTD_H)
30 Monster dragon
; // The current dragon
31 Level levels
[ LEVELS
]; // The newest way to store monsters
32 list
< item
*> Items
; // The master list of items
33 list
< tavernItem
> tavern
; // The list of items available at the tavern
34 list
< item
*> store
; // The list of items available at the store
45 item
* findItemByID ( int id
);
46 item
* findStoreItemByID ( int id
);
47 tavernItem
* findTavernItemByID ( int id
);
51 char * strtok ( char * str
, const char * delim
);
54 int stricmp ( const char * s1
, const char * s2
);
55 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
58 /********** Password functions **********/
60 bool passcmp ( const char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
62 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
64 /********** Password functions **********/
67 /********** GameServ Booleans **********/
70 bool timedOut ( Player
* p
);
71 void updateTS ( Player
* p
);
72 void timeOutEvent ( Player
* p
);
74 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
75 bool is_playing ( aClient
* user
);
77 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
78 bool is_fighting ( aClient
* user
);
80 bool player_fight ( char * u
); // True if the player is fighting another player.
81 bool player_fight ( aClient
* user
);
83 bool master_fight ( char * u
); // True if the player is fighting their master.
84 bool master_fight ( aClient
* user
);
86 bool dragon_fight ( char * u
); // True if the player is fighting the dragon.
87 bool dragon_fight ( aClient
* user
);
89 bool alphaNumeric ( const char * str
); // Returns true if all of the characters in str are alphanumeric non-special chars
90 /********** GameServ Booleans **********/
92 void display_help ( char * u
, char * file
= NULL
);
93 void display_monster ( char * u
);
94 void display_players ( char * u
);
95 void display_players ( aClient
* user
);
96 long int chartoint ( char ch
);
97 int isstringnum ( char * num
);
98 long int pow ( int x
, int y
);
99 long int stringtoint ( char * number
);
101 char * spaces ( int len
, char * seperator
);
102 void refresh ( Player
* p
);
104 void rollover ( Player
* p
);
107 void updateTS ( Player
* p
);
108 void reset ( Player
* p
);
110 bool load_monsters ();
112 void delete_monsters ();
114 void do_admin ( char * u
);
115 void do_attack ( char * u
);
116 void do_bank ( char * u
);
117 void do_check ( char * u
);
118 void do_equip ( char * u
);
119 void do_fight ( char * u
);
120 void do_heal ( char * u
);
121 void do_help ( char * u
);
122 void do_identify ( char * u
);
123 void do_inventory ( char * u
);
124 void do_refresh ( char * u
);
125 void do_register ( char * u
);
126 void do_list ( char * u
);
127 void do_logout ( char * u
);
128 void do_master ( char * u
);
129 void do_dragon ( char * u
);
130 void do_play ( char * u
);
131 void do_quitg ( char * u
);
132 void do_reset ( char * u
);
133 void do_run ( char * u
);
134 void do_set ( char * u
);
135 void do_stats ( char * u
);
136 void do_store ( char * u
);
137 void do_tavern ( char * u
);
138 void do_use ( char * u
);
139 void see_master ( char * u
);
141 void logout ( aClient
* user
);
142 void showstats ( const char * u
, const char * nick
);
143 void showTavern ( aClient
* user
);
144 void showinventory ( Player
* from
, aClient
* to
);
145 void showBankBalance ( const char * u
);
146 void end_turn ( aClient
* user
);
150 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
151 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
152 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
154 void gameserv ( char * source
, char * buf
)
157 cmd
= strtok ( buf
, " " );
160 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
165 cmd
++; // Get rid of that : at the beginning of the :text (command)
168 log ( "Source: %s Command: %s " , source
, cmd
);
171 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
174 ts
= strtok ( NULL
, "\1" );
175 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
176 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
177 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
178 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
179 cmd
= strtok ( NULL
, " " );
182 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
186 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
188 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
190 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
192 } else if ( stricmp ( cmd
, "CHECK" ) == 0 ) {
194 } else if ( stricmp ( cmd
, "DRAGON" ) == 0 ) {
196 } else if ( stricmp ( cmd
, "EQUIP" ) == 0 ) {
198 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
200 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
202 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
204 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
206 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
207 do_inventory ( source
);
208 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
210 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
212 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
214 } else if ( stricmp ( cmd
, "NEWS" ) == 0 ) {
216 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
218 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
220 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
222 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
224 } else if ( stricmp ( cmd
, "SET" ) == 0 ) {
226 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
228 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
230 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
232 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
234 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
237 if (!( user
= find ( source
)))
239 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
240 log ( "Error: aClient not found: %s " , source
);
242 else if (! isAdmin ( user
))
244 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
250 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
252 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
256 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
259 if (!( user
= find ( source
)))
261 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
262 log ( "Error: aClient not found: %s " , source
);
264 else if (! isAdmin ( user
))
266 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
272 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
275 if (!( user
= find ( source
)))
277 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
278 log ( "Error: aClient not found: %s " , source
);
280 else if (! isAdmin ( user
))
282 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
286 char * cmd2
= strtok ( NULL
, " " );
289 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
292 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
294 notice ( s_GameServ
, source
, "Loading monster data" );
298 display_help ( source
, cmd
);
301 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
304 if (!( user
= find ( source
)))
306 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
307 log ( "Error: aClient not found: %s " , source
);
309 else if (! isAdmin ( user
))
311 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
315 char * rest
= strtok ( NULL
, "" );
318 } else if ( stricmp ( cmd
, "PRINT" ) == 0 ) {
319 for ( int x
= 0 ; x
< LEVELS
; x
++)
320 levels
[ x
]. monsters
. print ();
321 } else if ( stricmp ( cmd
, "RANDOM" ) == 0 ) {
322 char * rstr
= strtok ( NULL
, "" );
324 trange
. setRange ( rstr
);
325 notice ( s_GameServ
, source
, "Random number in that range: %d " , trange
. random ());
329 if (( user
= find ( source
)))
334 log ( "Ignoring %s ." , user
-> getNick ());
339 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
345 source
--; // Bring the ':' back so we don't leak memory
348 cmd
--; // Same thing :)
351 int stricmp ( const char * s1
, const char * s2
)
355 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
361 if ( c
< tolower (* s2
))
366 void showstats ( const char * u
, const char * nick
)
368 aClient
* ni
, * sender
= find ( u
);
374 if (!( ni
= findplayer ( nick
)))
376 notice ( s_GameServ
, u
, " %s not found" , nick
);
380 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> getName (). c_str ());
382 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> getExp ());
383 space
= spaces ( strlen ( buf
), " " );
384 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
385 ni
-> stats
-> getLevel ());
388 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> getGold ());
389 space
= spaces ( strlen ( buf
), " " );
390 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> getBank ());
393 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> getHP (),
394 ni
-> stats
-> getMaxHP ());
396 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> getStrength ());
397 space
= spaces ( strlen ( buf
), " " );
398 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
399 buf
, space
, ni
-> stats
-> getDefense ());
402 sprintf ( buf
, "Armor: %s " , ( ni
-> stats
-> getArmor () ? ni
-> stats
-> getArmor ()-> getName (). c_str () : "Nothing" ));
403 space
= spaces ( strlen ( buf
), " " );
405 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
406 ( ni
-> stats
-> getWeapon () ? ni
-> stats
-> getWeapon ()-> getName (). c_str () : "Fists" ));
410 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> getForestFights ());
411 space
= spaces ( strlen ( buf
), " " );
412 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> getPlayerFights ());
414 if ( ni
== sender
|| isAdmin ( sender
))
416 showinventory ( ni
-> stats
, sender
);
421 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> getName (). c_str ());
426 char * spaces ( int len
, char * seperator
)
429 final
= new char [ 30 ];
431 strcpy ( final
, seperator
);
432 for ( y
= 0 ; y
< 30 - len
; y
++)
433 strcat ( final
, seperator
);
437 void raw ( const char * fmt
, ...)
442 input
= new char [ 1024 ];
444 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
450 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
451 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
452 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
455 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
460 sprintf ( input
, " %s%c " , input
, * t
);
465 log ( "Input: %s " , input
);
468 sprintf ( input
, " %s%s " , input
, " \r\n " );
469 sock_puts ( sock
, input
);
473 /* Send a NOTICE from the given source to the given nick. */
475 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
481 commanduse
= new char [ 16 ];
485 strcpy ( commanduse
, "P" );
487 strcpy ( commanduse
, "O" );
491 strcpy ( commanduse
, "PRIVMSG" );
493 strcpy ( commanduse
, "NOTICE" );
499 input
= new char [ 1024 ];
506 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
508 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
516 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
518 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
527 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
528 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
529 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
530 case 'c' : sprintf ( input
, " %s%c " , input
, va_arg ( args
, int )); break ;
533 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
538 sprintf ( input
, " %s%c " , input
, * t
);
543 log ( "Input: %s " , input
);
545 sprintf ( input
, " %s%s " , input
, " \r\n " );
546 sock_puts ( sock
, input
);
547 delete [] commanduse
;
553 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
559 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
560 if ( c
== 0 || -- len
== 0 )
565 if ( c
< tolower (* s2
))
571 char * strtok ( char * str
, const char * delim
)
573 static char * current
= NULL
;
580 current
+= strspn ( current
, delim
);
581 ret
= * current
? current
: NULL
;
582 current
+= strcspn ( current
, delim
);
591 void do_check ( char * u
)
593 int days
, hours
, minutes
, seconds
;
595 complete
= ( lastrefresh
+ refreshperiod
) - time ( NULL
);
596 days
= complete
/ 86400 ;
597 hours
= ( complete
% 86400 ) / 3600 ;
598 minutes
= ( complete
% 86400 ) % 3600 / 60 ;
599 seconds
= ( complete
% 86400 ) % 3600 % 60 ;
601 notice ( s_GameServ
, u
, "Time left to next refresh: %d d %d h %d m %d s" ,
602 days
, hours
, minutes
, seconds
);
604 if ( isRolloverForestFights ())
606 complete
= ( lastrollover
+ rolloverperiod
) - time ( NULL
);
608 days
= complete
/ 86400 ;
609 hours
= ( complete
% 86400 ) / 3600 ;
610 minutes
= ( complete
% 86400 ) % 3600 / 60 ;
611 seconds
= ( complete
% 86400 ) % 3600 % 60 ;
613 notice ( s_GameServ
, u
, "Time left to next rollover: %d d %d h %d m %d s" ,
614 days
, hours
, minutes
, seconds
);
618 void do_list ( char * u
)
621 char * cmd
= strtok ( NULL
, " " );
623 if (!( user
= find ( u
)))
625 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
628 else if ( isIgnore ( user
))
631 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
636 ListNode
< aClient
> * temp
;
639 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
641 temp
= players
[ x
]. First ();
642 if (! players
[ x
]. isEmpty ())
646 if ( cmd
|| is_playing ( temp
-> getData ()))
650 notice ( s_GameServ
, u
, "Players:" );
654 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
655 temp
-> getData ()-> stats
-> getName (). c_str ());
657 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
658 temp
-> getData ()-> stats
-> getName (). c_str ());
667 notice ( s_GameServ
, u
, "No one is playing" );
669 notice ( s_GameServ
, u
, "End of List" );
674 aClient
* user
, * target
;
675 char * name
= strtok ( NULL
, " " );
676 char * cmd
= strtok ( NULL
, " " );
679 if (!( user
= find ( u
)))
681 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
682 "Buf: %s LOGOUT" , u
);
685 else if ( isIgnore ( user
))
688 log ( "Ignoring %s ." , user
-> getNick ());
692 else if (! name
|| ! cmd
)
694 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}" );
697 else if (!( target
= findplayer ( name
)))
699 // Back the pointers up... they didn't send a name probably
704 if (! is_playing ( user
))
706 notice ( s_GameServ
, u
, "You must be playing to set things for yourself!" );
712 cmd2
= strtok ( NULL
, " " );
716 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}" );
720 // Regardless of the previous if/else, if it got here, we know we have the cmd pointer at the right spot.
721 if ( stricmp ( cmd
, "PASSWORD" ) == 0 )
723 // Person is looking to change their password
724 // If they're an admin, or it's theirself, allow it
725 // cmd2 is pointing to the password now
726 if ( isAdmin ( user
) || user
== target
)
728 target
-> stats
-> setPassword ( cmd2
);
729 notice ( s_GameServ
, u
, "Password successfully changed" );
731 else if ( user
!= target
&& ! isAdmin ( user
))
733 notice ( s_GameServ
, u
, "You must be a %S admin to set other peoples' passwords." );
737 else if ( stricmp ( cmd
, "BANK" ) == 0 || stricmp ( cmd
, "BALANCE" ) == 0 )
741 notice ( s_GameServ
, u
, "Admins Only!" );
744 else if ( stricmp ( cmd
, "BANK" ) == 0 )
746 cmd2
= strtok ( NULL
, " " ); // Need an extra parameter for set bank balance
750 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] [BANK] BALANCE <NUMBER>" );
754 target
-> stats
-> setBank ( stringtoint ( cmd2
));
756 notice ( s_GameServ
, u
, "Bank balance changed to %l d!" , target
-> stats
-> getBank ());
758 else if ( stricmp ( cmd
, "PLAYER" ) == 0 )
762 notice ( s_GameServ
, u
, "Admins Only!" );
765 else if ( stricmp ( cmd2
, "FIGHTS" ) != 0 )
767 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>" );
772 cmd2
= strtok ( NULL
, " " );
775 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>" );
778 target
-> stats
-> setPlayerFights ( stringtoint ( cmd2
));
780 notice ( s_GameServ
, u
, "Player fights changed to %d !" , target
-> stats
-> getPlayerFights ());
783 else if ( stricmp ( cmd
, "FOREST" ) == 0 )
787 notice ( s_GameServ
, u
, "Admins Only!" );
790 else if ( stricmp ( cmd2
, "FIGHTS" ) != 0 )
792 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <number>" );
797 cmd2
= strtok ( NULL
, " " );
800 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <NUMBER>" );
804 target
-> stats
-> setForestFights ( stringtoint ( cmd2
));
806 notice ( s_GameServ
, u
, "Forest fights changed to %d !" , target
-> stats
-> getForestFights ());
809 else if ( stricmp ( cmd
, "GOLD" ) == 0 )
813 notice ( s_GameServ
, u
, "Admins Only!" );
820 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] GOLD <NUMBER>" );
823 target
-> stats
-> setGold ( stringtoint ( cmd2
));
825 notice ( s_GameServ
, u
, "Gold set to %l d" , target
-> stats
-> getGold ());
829 else if ( stricmp ( cmd
, "STRENGTH" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
833 notice ( s_GameServ
, u
, "Admins Only!" );
840 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] STRENGTH <NUMBER>" );
844 target
-> stats
-> setStrength ( stringtoint ( cmd2
));
846 notice ( s_GameServ
, u
, "Strength set to %d " , target
-> stats
-> getStrength ());
850 else if ( stricmp ( cmd
, "DEFENSE" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
854 notice ( s_GameServ
, u
, "Admins Only!" );
861 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] DEFENSE <NUMBER>" );
865 target
-> stats
-> setDefense ( stringtoint ( cmd2
));
867 notice ( s_GameServ
, u
, "Defense set to %d " , target
-> stats
-> getDefense ());
871 else if ( stricmp ( cmd
, "HP" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
875 notice ( s_GameServ
, u
, "Admins Only!" );
882 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] HP <NUMBER>" );
885 target
-> stats
-> setHP ( stringtoint ( cmd2
));
887 notice ( s_GameServ
, u
, "HP set to %d " , target
-> stats
-> getHP ());
891 else if ( stricmp ( cmd
, "MAXHP" ) == 0 )
895 notice ( s_GameServ
, u
, "Admins Only!" );
902 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] MAXHP <NUMBER>" );
905 target
-> stats
-> setMaxHP ( stringtoint ( cmd2
));
907 notice ( s_GameServ
, u
, "MaxHP set to %d " , target
-> stats
-> getMaxHP ());
911 else if ( stricmp ( cmd
, "EXPERIENCE" ) == 0 || stricmp ( cmd
, "EXP" ) == 0 )
915 notice ( s_GameServ
, u
, "Admins Only!" );
922 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] {EXPERIENCE|EXP} <NUMBER>" );
926 target
-> stats
-> setExp ( stringtoint ( cmd2
));
928 notice ( s_GameServ
, u
, "Exp set to %l d" , target
-> stats
-> getExp ());
932 else if ( stricmp ( cmd
, "LEVEL" ) == 0 )
936 notice ( s_GameServ
, u
, "Admins Only!" );
943 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] LEVEL <NUMBER>" );
946 target
-> stats
-> setLevel ( stringtoint ( cmd2
));
948 notice ( s_GameServ
, u
, "Level set to %d " , target
-> stats
-> getLevel ());
952 else if ( stricmp ( cmd
, "ALIVE" ) == 0 )
956 notice ( s_GameServ
, u
, "Admins Only!" );
963 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] ALIVE TRUE|FALSE" );
966 else if ( stricmp ( cmd2
, "TRUE" ) == 0 )
968 notice ( s_GameServ
, u
, " %s has been Resurrected!" , target
-> stats
-> getName (). c_str ());
969 setAlive ( target
-> stats
);
973 notice ( s_GameServ
, u
, " %s is now dead!" , target
-> stats
-> getName (). c_str ());
974 clearAlive ( target
-> stats
);
978 else if ( stricmp ( cmd
, "SEEN" ) == 0 )
982 notice ( s_GameServ
, u
, "Admins Only!" );
985 else if ( stricmp ( cmd2
, "MASTER" ) != 0 )
987 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] SEEN MASTER {TRUE|FALSE}" );
992 cmd2
= strtok ( NULL
, " " );
995 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NICK] SEEN MASTER {TRUE|FALSE}" );
998 else if ( stricmp ( cmd2
, "TRUE" ) == 0 )
1000 notice ( s_GameServ
, u
, " %s has seen their master now." , target
-> stats
-> getName (). c_str ());
1001 target
-> stats
-> addFlag ( FLAG_MASTER
);
1005 notice ( s_GameServ
, u
, " %s has not seen their master now." , target
-> stats
-> getName (). c_str ());
1006 target
-> stats
-> remFlag ( FLAG_MASTER
);
1012 notice ( s_GameServ
, u
, "Unknown command: SET %s " , cmd
);
1013 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}" );
1018 void do_logout ( char * u
)
1021 char * name
= strtok ( NULL
, " " );
1023 if (!( user
= find ( u
)))
1025 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
1026 "Buf: %s LOGOUT" , u
);
1027 log ( "Could not find aClient Buf: %s LOGOUT" ,
1031 else if ( isIgnore ( user
))
1034 log ( "Ignoring %s ." , user
-> getNick ());
1043 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
1045 else if (!( user
= findplayer ( name
)))
1047 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
1051 notice ( s_GameServ
, u
, "Logging out %s " , user
-> stats
-> getName (). c_str ());
1057 if (! is_playing ( user
))
1059 notice ( s_GameServ
, u
, "You're not logged in!" );
1061 else if ( is_fighting ( user
))
1063 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
1067 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
1073 void logout ( aClient
* user
)
1075 if ( is_playing ( user
))
1077 ListNode
< aClient
> * it
;
1079 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> getName (). c_str ());
1080 it
= players
[ hv
]. Find ( user
);
1084 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
1085 " %S Admin. Cannot find you in the players list." );
1086 log ( "Error on logout(). Can't find %s in the players list" ,
1095 user
-> stats
-> delMonster ();
1096 user
-> stats
-> delMaster ();
1097 clearDragonFight ( user
-> stats
);
1099 if ( player_fight ( user
))
1100 user
-> stats
-> getBattle ()-> stats
-> delBattle ();
1102 user
-> stats
-> delBattle ();
1105 temp
-> stats
= new Player
;
1106 temp
-> stats
-> setData ( user
-> stats
);
1107 user
-> stats
-> setClient ( NULL
);
1112 temp
-> stats
-> setClient ( temp
);
1114 temp
-> setRealNick ( "Not Playing" );
1116 temp
-> setNick ( "Not Playing" );
1118 it
-> setNewPtr ( temp
);
1120 log ( "Logged out player %s " ,
1132 void do_register ( char * u
)
1134 char * password
, * name
;
1136 name
= strtok ( NULL
, " " );
1137 password
= strtok ( NULL
, " " );
1141 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
1143 else if ( stricmp ( name
, s_GameServ
) == 0 )
1145 notice ( s_GameServ
, u
, "You can't use %S as a name!" );
1149 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
1151 else if (( user
= findplayer ( name
)))
1153 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
1154 notice ( s_GameServ
, u
, "Choose another name!" );
1156 else if (!( user
= find ( u
)))
1158 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
1160 else if (! alphaNumeric ( name
))
1162 notice ( s_GameServ
, u
, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!" );
1164 else if ( isIgnore ( user
))
1167 log ( "Ignoring %s ." , user
-> getNick ());
1172 if (! is_playing ( user
))
1174 ListNode
< aClient
> * temp
;
1176 user
-> stats
= new Player ();
1177 user
-> stats
-> setClient ( user
); // Set the backwards pointer
1178 user
-> stats
-> reset (); // set the user up
1179 user
-> stats
-> setPassword ( password
);
1180 user
-> stats
-> setName ( name
);
1181 unsigned long hv
= iHASH (( unsigned char *) name
);
1182 updateTS ( user
-> stats
);
1183 temp
= players
[ hv
]. insertAtBack_RLN ( user
);
1184 temp
-> setPtr ( user
); // This is an extra step, but necessary for now
1186 // Update the last login time
1187 user
-> stats
-> lastlogin
= time ( NULL
);
1189 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> getName (). c_str (), password
);
1190 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
1191 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> getName (). c_str ());
1192 setPlaying ( user
); // set the playing flag
1193 tempItem
= findItemByID ( 3001 );
1194 user
-> stats
-> inventory
-> addItem ((* Items
. begin ()))-> use ( user
-> stats
); // Add the stick
1195 user
-> stats
-> inventory
-> addItem ( tempItem
)-> use ( user
-> stats
); // Add Clothes
1199 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
1204 void do_identify ( char * u
)
1206 char * password
, * name
;
1208 name
= strtok ( NULL
, " " );
1209 password
= strtok ( NULL
, " " );
1210 if (! password
|| ! name
)
1212 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
1214 else if (!( user
= find ( u
)))
1216 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
1217 log ( "Error: aClient not found: %s " , u
);
1219 else if ( isIgnore ( user
))
1222 log ( "Ignoring %s ." , user
-> getNick ());
1226 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
1227 notice ( s_GameServ
, u
, "Player %s not found" , name
);
1228 else if ( is_playing ( user
))
1230 notice ( s_GameServ
, u
, "You are already playing!" );
1232 else if ( p
-> stats
-> getClient () != NULL
&& ! isAdmin ( user
))
1234 notice ( s_GameServ
, u
, "That player has already identified." );
1236 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
1238 notice ( s_GameServ
, u
, "Password incorrect" );
1242 ListNode
< aClient
> * temp
;
1243 unsigned long hv
= iHASH (( unsigned char *) p
-> stats
-> getName (). c_str ());
1244 temp
= players
[ hv
]. Find ( p
);
1247 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
1251 user
-> stats
= new Player ( p
-> stats
-> getName ());
1253 log ( "Setting data for identified" );
1255 user
-> stats
-> setData ( p
-> stats
);
1256 user
-> stats
-> setClient ( user
);
1257 updateTS ( user
-> stats
);
1261 log ( "Player %s IRC: %s Identified" , user
-> stats
-> getName (). c_str (),
1265 setPlaying ( user
); // set the playing flag
1269 // Update the last login time
1270 user
-> stats
-> lastlogin
= time ( NULL
);
1272 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
1273 showNews ( u
, todaysnews
);
1277 void do_stats ( char * u
)
1282 nick
= strtok ( NULL
, " " );
1284 if (!( user
= find ( u
)))
1286 log ( "Fatal Error: %s not found in client list" , u
);
1289 else if ( isIgnore ( user
))
1292 log ( "Ignoring %s ." , user
-> getNick ());
1298 if (! is_playing ( user
))
1300 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
1305 updateTS ( user
-> stats
);
1306 showstats ( u
, user
-> stats
-> getName (). c_str ());
1315 ifstream
infile ( masterdata
);
1318 buf
= new char [ 1024 ];
1322 log ( "Error opening %s " , masterdata
);
1327 log ( "Loading masters from %s " , masterdata
);
1330 for ( l
= 0 ; l
< LEVELS
- 1 ; l
++)
1332 infile
. getline ( buf
, 1024 , ' \n ' );
1335 if ( buf
[ 0 ] == '#' || buf
[ 0 ] == ' \n ' || buf
[ 0 ] == ' \r ' )
1340 else if ( buf
[ 0 ] == '^' )
1343 Monster
* master
= & levels
[ l
]. master
;
1345 char * name
, * weapon
, * strength
, * gold
, * exp
, * maxhp
, * death
;
1348 name
= strtok ( buf
, "~" );
1349 weapon
= strtok ( NULL
, "~" );
1350 strength
= strtok ( NULL
, "~" );
1351 gold
= strtok ( NULL
, "~" );
1352 exp
= strtok ( NULL
, "~" );
1353 maxhp
= strtok ( NULL
, "~" );
1354 death
= strtok ( NULL
, "~" );
1356 master
-> name
= name
;
1357 master
-> weapon
= weapon
;
1358 master
-> strength
= stringtoint ( strength
);
1359 master
-> gold
= stringtoint ( gold
);
1360 master
-> exp
= stringtoint ( exp
);
1361 master
-> maxhp
= stringtoint ( maxhp
);
1362 master
-> hp
= master
-> maxhp
;
1363 master
-> death
= death
;
1368 if ( l
< LEVELS
- 1 ) // We didn't load a master for every level - check data/masters.dat
1374 void delete_monsters ()
1376 for ( int x
= 0 ; x
< LEVELS
; x
++)
1377 levels
[ x
]. monsters
. deleteNodes ();
1380 void display_monster ( char * u
)
1384 aClient
* user
= find ( u
);
1385 Player
* ni
= user
-> stats
;
1387 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> getHP ());
1388 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> getMonster ()-> name
. c_str (), ni
-> getMonster ()-> hp
);
1389 notice ( s_GameServ
, u
, "Here are your commands:" );
1390 notice ( s_GameServ
, u
, "/msg %S attack" );
1391 notice ( s_GameServ
, u
, "/msg %S run" );
1392 notice ( s_GameServ
, u
, "What will you do?" );
1396 void display_players ( char * u
)
1399 if (!( user
= find ( u
)))
1401 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1404 display_players ( user
);
1407 void display_players ( aClient
* user
)
1409 char * u
= user
-> getNick ();
1410 if ( is_playing ( user
) && player_fight ( user
))
1412 aClient
* battle
= user
-> stats
-> getBattle ();
1413 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> getHP ());
1414 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> getName (). c_str (), battle
-> stats
-> getHP ());
1415 notice ( s_GameServ
, u
, "Here are your commands:" );
1416 notice ( s_GameServ
, u
, "/msg %S attack" );
1417 notice ( s_GameServ
, u
, "/msg %S run" );
1418 notice ( s_GameServ
, u
, "What will you do?" );
1423 bool is_playing ( char * u
)
1426 if (!( user
= find ( u
)))
1429 return is_playing ( user
);
1432 bool is_playing ( aClient
* user
)
1434 if ( user
-> stats
== NULL
)
1438 else if ( user
-> stats
-> getClient () == NULL
)
1442 else if (! FL_is_playing ( user
))
1450 bool is_fighting ( char * u
)
1454 if (!( user
= find ( u
)))
1457 return is_fighting ( user
);
1460 bool is_fighting ( aClient
* user
)
1462 if (! is_playing ( user
))
1465 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> getMonster () != NULL
;
1468 bool player_fight ( char * u
)
1472 if (!( user
= find ( u
)))
1475 return player_fight ( user
);
1478 bool player_fight ( aClient
* user
)
1480 if (! is_playing ( user
))
1482 else if ( user
-> stats
-> getBattle () != NULL
&& is_playing ( user
-> stats
-> getBattle ()))
1484 return user
-> stats
-> getBattle ()-> stats
!= NULL
;
1489 bool master_fight ( char * u
)
1493 if (!( user
= find ( u
)))
1496 return master_fight ( user
);
1499 bool master_fight ( aClient
* user
)
1501 if (! is_playing ( user
))
1504 return user
-> stats
-> getMaster () != NULL
;
1507 bool dragon_fight ( char * u
)
1510 if (!( user
= find ( u
)))
1513 return dragon_fight ( user
);
1516 bool dragon_fight ( aClient
* user
)
1518 if (! is_playing ( user
))
1521 return ( isDragonFight ( user
-> stats
));
1524 bool alphaNumeric ( const char * str
)
1526 int len
= strlen ( str
);
1527 for ( int x
= 0 ; x
< len
; x
++)
1529 if (!(( int ( str
[ x
]) >= 65 && int ( str
[ x
]) <= 90 ) || ( int ( str
[ x
]) >= 97 && int ( str
[ x
]) <= 122 ) || ( int ( str
[ x
]) >= 48 && int ( str
[ x
]) <= 57 ) || int ( str
[ x
]) == 95 ))
1535 void do_fight ( char * u
)
1537 aClient
* ni
, * battle
;
1539 char * nick
= strtok ( NULL
, " " );
1543 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1546 else if (!( ni
= find ( u
)))
1548 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1551 else if ( isIgnore ( ni
))
1554 log ( "Ignoring %s ." , ni
-> getNick ());
1558 else if (! is_playing ( ni
))
1560 notice ( s_GameServ
, u
, "You are not playing!" );
1564 updateTS ( ni
-> stats
);
1566 if ( ni
-> stats
-> getPlayerFights () <= 0 )
1568 ni
-> stats
-> setPlayerFights ( 0 ); // just to be safe
1569 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1570 "day. You have to wait until tomorrow!" );
1572 else if (!( battle
= findplayer ( nick
)))
1574 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1576 else if (! isAlive ( ni
-> stats
))
1578 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1580 else if (! is_playing ( battle
))
1582 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1585 /* offline fighting not available yet
1586 else if (!(fight = finduser(nick)))
1588 ni->stats->battle = battle;
1589 battle->battle = ni;
1590 setYourTurn(ni->stats);
1591 clearYourTurn(battle->stats);
1593 notice(s_GameServ, u, "You decide to fight %s while they're "\
1594 "not in the realm!",
1595 battle->stats->name.c_str());
1599 else if ( stricmp ( ni
-> stats
-> getName (). c_str (), battle
-> stats
-> getName (). c_str ()) == 0 )
1601 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1603 else if (! isAlive ( battle
-> stats
))
1605 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1607 else if ( player_fight ( battle
))
1609 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> getName (). c_str (), battle
-> stats
-> getBattle ()-> stats
-> getName (). c_str ());
1611 else if ( master_fight ( battle
))
1613 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> stats
-> getName (). c_str ());
1615 else if ( is_fighting ( battle
))
1617 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> getName (). c_str (), battle
-> stats
-> getMonster ()-> name
. c_str ());
1619 else if (! isAdmin ( ni
) && isFairFights () && ( ni
-> stats
-> getStrength ()/ 2 - battle
-> stats
-> getDefense ()) > battle
-> stats
-> getHP ())
1621 notice ( s_GameServ
, u
, "Fair fighting is enabled, and you're too strong for %s !" , battle
-> stats
-> getName (). c_str ());
1623 else if ( ni
-> stats
-> getLevel () - battle
-> stats
-> getLevel () > maxbfightdistance
)
1625 // You can't fight someone below you by more than X level(s)
1626 // level 12 can fight level (12 - X) but not < (12 - X)
1627 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1628 battle
-> stats
-> getName (). c_str ());
1630 else if ( battle
-> stats
-> getLevel () - ni
-> stats
-> getLevel () > maxafightdistance
)
1632 // You can't fight someone above you by more than X level(S)
1633 // level 1 can fight level (1 + X), but not > (1 + X)
1634 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1635 "weakling!" , ni
-> stats
-> getName (). c_str ());
1639 // Set your battle pointer to the other player
1640 ni
-> stats
-> setBattle ( battle
);
1642 // Set the other player's battle pointer to you
1643 battle
-> stats
-> setBattle ( ni
);
1645 // The initiator gets the first move (perhaps this should be 50/50)
1646 setYourTurn ( ni
-> stats
);
1647 clearYourTurn ( battle
-> stats
);
1649 // Initiate Battle sequence!
1650 ni
-> stats
-> subtractPlayerFights ( 1 );
1652 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> getName (). c_str ());
1653 notice ( s_GameServ
, c_Forest
, " %s walks up and hits %s in the face! Let's see who will bite the dust." ,
1654 ni
-> stats
-> getName (). c_str (), battle
-> stats
-> getName (). c_str ()); /* DrLnet - Modified by Kain*/
1656 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> getName (). c_str ());
1657 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1658 "because they initiated!" , ni
-> stats
-> getName (). c_str ());
1659 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> getName (). c_str ());
1660 display_players ( ni
);
1664 void do_equip ( char * u
)
1668 itemContainer
* equip
;
1671 char * item
= strtok ( NULL
, " " );
1673 if (! item
|| int ( item
[ 0 ]) < 48 || int ( item
[ 0 ] > 57 ))
1675 notice ( s_GameServ
, u
, "SYNTAX: EQUIP ####" );
1676 notice ( s_GameServ
, u
, "Type /msg %S HELP EQUIP for more information." );
1679 else if (!( user
= find ( u
)))
1681 notice ( s_GameServ
, u
, "Fatal error in do_equip. Contact a(n) %S Admin" );
1684 else if ( isIgnore ( user
))
1687 log ( "Ignoring %s ." , user
-> getNick ());
1691 else if (! is_playing ( user
))
1693 notice ( s_GameServ
, u
, "You must be playing to equip weapons and armor!" );
1696 id
= stringtoint ( item
);
1697 updateTS ( user
-> stats
);
1698 p
= user
-> stats
-> inventory
;
1701 if (!( equip
= p
-> Find ( id
)))
1705 notice ( s_GameServ
, u
, "You aren't carrying that item!" );
1707 showinventory ( user
-> stats
, user
);
1709 else if ( equip
-> getItem ()-> getType () != ARMOR
&& equip
-> getItem ()-> getType () != WEAPON
)
1711 notice ( s_GameServ
, u
, "You can't use %s like that. Try /msg %S use" , equip
-> getItem ()-> getName (). c_str ());
1716 notice ( s_GameServ
, u
, "You equip %s ." , equip
-> getItem ()-> getName (). c_str ());
1717 equip
-> use ( user
-> stats
);
1720 void do_use ( char * u
)
1725 char * item
= strtok ( NULL
, " " );
1727 itemContainer
* used
;
1729 if (! item
|| int ( item
[ 0 ]) < 48 || int ( item
[ 0 ]) > 57 )
1731 notice ( s_GameServ
, u
, "SYNTAX: USE ####" );
1732 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1735 else if (!( user
= find ( u
)))
1737 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1740 else if ( isIgnore ( user
))
1743 log ( "Ignoring %s ." , user
-> getNick ());
1747 else if (! is_playing ( user
))
1749 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1752 id
= stringtoint ( item
);
1753 updateTS ( user
-> stats
);
1754 p
= user
-> stats
-> inventory
;
1757 if (!( used
= p
-> Find ( id
)))
1761 notice ( s_GameServ
, u
, "You aren't carrying that item!" );
1763 showinventory ( user
-> stats
, user
);
1765 else if ( used
-> getItem ()-> getType () != POTION
)
1767 notice ( s_GameServ
, u
, "You can't use %s like that. Try /msg %S equip" , used
-> getItem ()-> getName (). c_str ());
1772 notice ( s_GameServ
, u
, "You used %s ." , used
-> getItem ()-> getName (). c_str ());
1773 used
-> use ( user
-> stats
);
1774 if ( used
-> getUses () <= 0 )
1776 p
-> deleteItem ( used
-> getItem ());
1781 void do_run ( char * u
)
1784 Player
* p
, * p2
= NULL
;
1786 if (!( user
= find ( u
)))
1788 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1791 else if ( isIgnore ( user
))
1794 log ( "Ignoring %s ." , user
-> getNick ());
1798 else if (! is_playing ( user
))
1800 notice ( s_GameServ
, u
, "You must be playing to run!" );
1804 updateTS ( user
-> stats
);
1808 p2
= p
-> getBattle ()-> stats
;
1810 if (! is_fighting ( user
))
1811 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1812 else if (! player_fight ( user
) && ! master_fight ( user
) && ! dragon_fight ( user
))
1814 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> getMonster ()-> name
. c_str ());
1817 else if ( player_fight ( user
) && isYourTurn ( p
))
1819 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> getName (). c_str ());
1820 notice ( s_GameServ
, p
-> getBattle ()-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> getName (). c_str ());
1821 addNews ( todaysnews
, " %s ran away from %s like a little baby!!" , p
-> getName (). c_str (), p2
-> getName (). c_str ()); /* DrLnet - edited by Kain */
1824 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1826 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> getName (). c_str ());
1828 else if ( master_fight ( user
))
1830 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> getMaster ()-> name
. c_str ());
1832 else if ( dragon_fight ( user
))
1834 notice ( s_GameServ
, u
, "You cannot run from %s ! FIGHT!" , dragon
. name
. c_str ());
1838 void end_turn ( aClient
* user
)
1840 char * nick
, * u
= user
-> getNick ();
1845 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1847 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1850 if (! player_fight ( user
) && ! master_fight ( user
))
1851 fight
= user
-> stats
-> getMonster ();
1853 fight
= user
-> stats
-> getMaster ();
1854 battle
= user
-> stats
-> getBattle ();
1856 if (! player_fight ( user
))
1859 mhit
= ( fight
-> strength
/ 2 ) + ( rand () % ( fight
-> strength
/ 2 )) - ( user
-> stats
-> getDefense ());
1864 mhit
= ( battle
-> stats
-> getStrength () / 2 ) + ( rand () % ( battle
-> stats
-> getStrength () / 2 )) - user
-> stats
-> getDefense ();
1866 if (! player_fight ( user
))
1871 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1872 fight
-> name
. c_str (), fight
-> weapon
. c_str (), mhit
);
1875 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
. c_str ());
1877 if ( mhit
>= user
-> stats
-> getHP ())
1879 if (! master_fight ( user
))
1881 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
. c_str ());
1882 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1883 "of your experience!" );
1884 user
-> stats
-> setGold ( 0 );
1885 user
-> stats
-> subtractExp (( long int )( user
-> stats
-> getExp () * .10 ));
1886 user
-> stats
-> setHP ( 0 );
1887 user
-> stats
-> delMonster ();
1888 clearAlive ( user
-> stats
);
1893 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1894 "until tomorrow to try again" , user
-> stats
-> getMaster ()-> name
. c_str ());
1895 user
-> stats
-> delMonster ();
1896 user
-> stats
-> delMaster ();
1903 user
-> stats
-> subtractHP ( mhit
);
1910 clearYourTurn ( user
-> stats
);
1911 setYourTurn ( battle
-> stats
);
1912 display_players ( battle
);
1918 void do_heal ( char * u
)
1921 char * amount
= strtok ( NULL
, " " );
1926 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1929 else if (!( ni
= find ( u
)))
1931 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1934 else if ( isIgnore ( ni
))
1937 log ( "Ignoring %s ." , ni
-> getNick ());
1941 else if (! is_playing ( ni
))
1943 notice ( s_GameServ
, u
, "You aren't playing!" );
1946 else if (! isAlive ( ni
-> stats
))
1948 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1951 else if ( is_fighting ( ni
))
1953 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1956 else if ( ni
-> stats
-> getHP () >= ni
-> stats
-> getMaxHP ())
1958 notice ( s_GameServ
, u
, "You don't need healing!" );
1962 updateTS ( ni
-> stats
);
1963 if ( stricmp ( amount
, "ALL" ) == 0 )
1965 price
= ni
-> stats
-> getLevel () * 3 ;
1966 if ( ni
-> stats
-> getGold () < ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()) * price
)
1968 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1969 ( long int ) ni
-> stats
-> getGold ()/ price
, price
);
1970 ni
-> stats
-> addHP ( ni
-> stats
-> getGold () / price
);
1971 ni
-> stats
-> setGold ( ni
-> stats
-> getGold () % price
);
1975 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1976 "per point." , price
);
1977 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1978 ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()),
1979 ( price
* ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ())) );
1980 ni
-> stats
-> subtractGold ( price
* ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()));
1981 ni
-> stats
-> healall ();
1984 else if ( isstringnum ( amount
))
1986 num
= stringtoint ( amount
);
1987 price
= ni
-> stats
-> getLevel () * 3 ;
1988 if ( ni
-> stats
-> getGold () < price
* num
)
1990 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1991 ( long int ) ni
-> stats
-> getGold ()/ price
);
1993 else if ( num
<= ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ())
1995 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
1997 ni
-> stats
-> addHP ( num
);
1998 ni
-> stats
-> subtractGold ( num
* price
);
2000 else if ( num
> ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ())
2002 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2003 "per point." , price
);
2004 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2005 ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()));
2006 ni
-> stats
-> subtractGold ( price
* ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()));
2007 ni
-> stats
-> healall ();
2010 else if ( amount
[ 0 ] == '-' )
2011 notice ( s_GameServ
, u
, "You trying to cheat?" );
2013 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2016 int isstringnum ( char * num
)
2019 for ( x
= 0 ; x
< strlen ( num
); x
++)
2021 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2027 long int stringtoint ( char * number
)
2029 return atol ( number
);
2032 long int pow ( int x
, int y
)
2038 if ( x
!= 0 && y
!= 0 )
2040 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2048 long int chartoint ( char ch
)
2050 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2051 return int ( ch
) - 48 ;
2058 ListNode
< aClient
> * ptr
;
2062 outfile
. open ( playerdata
);
2066 log ( "Error opening %s " , playerdata
);
2070 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2072 ptr
= players
[ x
]. First ();
2075 it
= ptr
-> getData ()-> stats
;
2078 w
= it
-> getWeapon ();
2081 outfile
<< it
-> getName (). c_str () << ' ' << it
-> getLevel () << ' ' << it
-> getExp () << ' ' << it
-> getGold () << ' ' << it
-> getBank () << ' ' << it
-> getHP () << ' ' << it
-> getMaxHP () << ' ' << it
-> getStrength () << ' ' << it
-> getDefense () << ' ' << it
-> getForestFights () << ' ' << it
-> getPlayerFights () << ' ' << it
-> getFlags () << ' ' << it
-> getPassword (). c_str () << ' ' << it
-> lastlogin
<< ' ' << ( w
? w
-> getID () : 0 ) << ' ' << ( a
? a
-> getID () : 0 );
2083 // Traverse the list and write out each item ID and how many uses are left
2084 if (! it
-> inventory
-> isEmpty ())
2086 list
< itemContainer
> * myitems
;
2087 list
< itemContainer
>:: iterator item_iter
;
2088 myitems
= it
-> inventory
-> getItems ();
2090 for ( item_iter
= myitems
-> begin (); item_iter
!= myitems
-> end (); item_iter
++)
2092 outfile
<< ' ' << (* item_iter
). getItem ()-> getID () << ' ' << (* item_iter
). getUses ();
2108 infile
. open ( dragondata
);
2113 log ( "Error opening %s . Trying initialdragon.dat" , dragondata
);
2114 infile
. open ( "data/initialdragon.dat" );
2117 log ( "Error opening data/initialdragon.dat" );
2122 buf
= new char [ 1024 ];
2124 infile
. getline ( buf
, 1024 , ' \n ' );
2125 infile
. close (); // Done with the file... we have what we want
2127 dragon
. name
= strtok ( buf
, "~" );
2128 dragon
. weapon
= strtok ( NULL
, "~" );
2131 dragon
. strength
= stringtoint ( strtok ( NULL
, "~" ));
2132 dragon
. hp
= stringtoint ( strtok ( NULL
, "~" ));
2133 dragon
. defense
= stringtoint ( strtok ( NULL
, "~" ));
2134 dragon
. death
= strtok ( NULL
, "" );
2136 log ( "loaded dragon: %s " , dragon
. name
. c_str ());
2140 return save_dragon (); // Save the dragon file and return the status code :)
2147 outfile
. open ( dragondata
);
2151 log ( "Error opening %s . Exiting." , dragondata
);
2155 outfile
<< dragon
. name
. c_str () << '~' << dragon
. weapon
. c_str () << '~'
2156 << dragon
. strength
<< '~' << dragon
. hp
<< '~'
2157 << dragon
. defense
<< '~' << dragon
. death
. c_str () << " \n ^"
2170 buf
= new char [ 1024 ];
2173 infile
. open ( storeitemdata
);
2177 log ( "Error opening %s " , storeitemdata
);
2181 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2185 if ( buf
[ 0 ] != '#' && buf
[ 0 ] != ' \n ' && buf
[ 0 ] != '\0' )
2188 id
= stringtoint ( strtok ( buf
, "" ));
2189 tempItem2
= findItemByID ( id
);
2190 if ( tempItem2
== NULL
)
2192 log ( "Invalid ID in %s " , storeitemdata
);
2196 tempItem
= tempItem2
;
2197 store
. push_back ( tempItem
);
2202 log ( "Exception loading store: %s " , str
);
2214 tavernItem tempItem
;
2215 buf
= new char [ 1024 ];
2218 infile
. open ( tavernitemdata
);
2221 log ( "Error opening %s " , tavernitemdata
);
2225 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2229 if ( buf
[ 0 ] != '#' && buf
[ 0 ] != ' \n ' && buf
[ 0 ] != '\0' )
2232 id
= stringtoint ( strtok ( buf
, "~" ));
2233 level
= stringtoint ( strtok ( NULL
, "" ));
2234 tempItem2
= findItemByID ( id
);
2235 if ( tempItem2
== NULL
)
2237 log ( "Invalid ID in %s " , tavernitemdata
);
2240 tempItem
. setItem ( tempItem2
);
2241 tempItem
. setLevel ( level
);
2242 tavern
. push_back ( tempItem
);
2247 log ( "Exception loading tavern: %s " , str
);
2262 buf
= new char [ 1024 ];
2264 infile
. open ( itemdata
);
2268 log ( "Error opening %s " , itemdata
);
2272 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2278 if ( buf
[ 0 ] != '#' && buf
[ 0 ] != ' \n ' && buf
[ 0 ] != '\0' )
2283 tempItem
= new weapon ();
2286 tempItem
= new armor ();
2289 tempItem
= new potion ();
2292 log ( "Invalid Item Type %c in %s " , buf
[ 0 ], itemdata
);
2297 if ( tempItem
-> setData ( buf
))
2299 Items
. push_back ( tempItem
);
2305 log ( "Exception loading items: %s " , str
);
2319 char * tempname
, * buf
, * password
;
2321 buf
= new char [ 100000 ];
2323 infile
. open ( playerdata
);
2327 log ( "Error opening %s " , playerdata
);
2331 for ( int x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2333 ListNode
< aClient
> * tempNode
;
2334 tempNode
= players
[ x
]. First ();
2337 if ( tempNode
-> getData ()-> stats
-> getClient ())
2339 logout ( tempNode
-> getData ()-> stats
-> getClient ());
2341 tempNode
= tempNode
-> Next ();
2343 players
[ x
]. deleteNodes ();
2346 while ( infile
. getline ( buf
, 100000 , ' \n ' ))
2349 tempname
= strtok ( buf
, " " );
2350 temp
-> stats
= new Player ( tempname
);
2353 p
-> setLevel ( stringtoint ( strtok ( NULL
, " " )));
2354 p
-> setExp ( stringtoint ( strtok ( NULL
, " " )));
2355 p
-> setGold ( stringtoint ( strtok ( NULL
, " " )));
2356 p
-> setBank ( stringtoint ( strtok ( NULL
, " " )));
2357 p
-> setHP ( stringtoint ( strtok ( NULL
, " " )));
2358 p
-> setMaxHP ( stringtoint ( strtok ( NULL
, " " )));
2359 p
-> setStrength ( stringtoint ( strtok ( NULL
, " " )));
2360 p
-> setDefense ( stringtoint ( strtok ( NULL
, " " )));
2361 p
-> setForestFights ( stringtoint ( strtok ( NULL
, " " )));
2362 p
-> setPlayerFights ( stringtoint ( strtok ( NULL
, " " )));
2363 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2367 password
= strtok ( NULL
, " " );
2368 p
-> setRawPassword ( password
);
2369 temp
-> setNick ( "Not Playing" );
2371 temp
-> setRealNick ( "Not Playing" );
2373 tempname
= strtok ( NULL
, " " );
2375 p
-> lastlogin
= stringtoint ( tempname
);
2377 p
-> lastlogin
= time ( NULL
);
2379 tempname
= strtok ( NULL
, " " );
2380 tempnum
= stringtoint ( tempname
);
2384 tempitem
= findItemByID ( tempnum
);
2385 p
-> setWeapon (* tempitem
);
2388 tempname
= strtok ( NULL
, " " );
2389 tempnum
= stringtoint ( tempname
);
2393 tempitem
= findItemByID ( tempnum
);
2394 p
-> setArmor (* tempitem
);
2398 unsigned long hv
= iHASH (( unsigned char *) temp
-> stats
-> getName (). c_str ());
2400 temp
-> stats
-> setClient ( NULL
);
2401 p
= players
[ hv
]. insertAtBack ( temp
)-> stats
;
2403 for ( tempname
= strtok ( NULL
, " " ); tempname
!= NULL
; tempname
= strtok ( NULL
, " " ))
2406 list
< item
*>:: iterator item_iter
;
2407 id
= stringtoint ( tempname
);
2408 tempname
= strtok ( NULL
, " " );
2409 uses
= stringtoint ( tempname
);
2411 item_iter
= Items
. begin ();
2412 while ( item_iter
!= Items
. end ())
2414 if ((* item_iter
)-> getID () == id
)
2416 // Don't sort every time you add an item or it eats CPU
2417 p
-> inventory
-> addItemNoChecks ((* item_iter
))-> setUses ( uses
);
2418 log ( "Inventory Count: %d " , p
-> inventory
-> getCount ());
2423 p
-> inventory
-> sort ();
2424 log ( "Inventory Count: %d " , p
-> inventory
-> getCount ());
2432 bool passcmp ( const char * encrypted
, char * plaintext
)
2435 char * plaintext2
, * plainToencrypt
;
2438 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2439 strcpy ( plaintext2
, plaintext
);
2441 salt
[ 0 ] = encrypted
[ 0 ];
2442 salt
[ 1 ] = encrypted
[ 1 ];
2445 plainToencrypt
= crypt ( plaintext2
, salt
);
2447 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2449 delete [] plaintext2
;
2454 bool check_password ( char * name
, char * plaintext
)
2458 if (!( client
= findplayer ( name
)))
2462 return passcmp ( client
-> stats
-> getPassword (). c_str (), plaintext
);
2466 void do_store ( char * u
)
2468 list
< item
*>:: iterator item_iterator
;
2470 char * cmd
= strtok ( NULL
, " " );
2471 char * num
= strtok ( NULL
, " " );
2480 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2481 notice ( s_GameServ
, u
, " \ 2 STORE SELL NUMBER\ 2 " );
2482 notice ( s_GameServ
, u
, " \ 2 STORE BUY \1f NUMBER\1f \ 2 " );
2485 else if (!( user
= find ( u
)))
2487 log ( "Fatal Error: could not find %s in client list" , u
);
2490 else if ( isIgnore ( user
))
2493 log ( "Ignoring %s ." , user
-> getNick ());
2497 else if (! is_playing ( user
))
2499 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2502 else if ( is_fighting ( user
))
2504 notice ( s_GameServ
, u
, "You can't go to the store while fighting!" );
2507 else if (! isAlive ( user
-> stats
))
2509 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2512 updateTS ( user
-> stats
);
2514 if ( stricmp ( cmd
, "LIST" ) == 0 )
2516 if ( stricmp ( num
, "WEAPONS" ) == 0 )
2518 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2519 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2520 for ( item_iterator
= store
. begin (); item_iterator
!= store
. end (); ++ item_iterator
)
2522 if ((* item_iterator
)-> getType () == WEAPON
)
2524 space
= spaces ( strlen ((* item_iterator
)-> getName (). c_str ()), "." );
2525 notice ( s_GameServ
, u
, " %s%l d. %s%s%l d" , ((* item_iterator
)-> getID () < 10 ? " " : "" ), (* item_iterator
)-> getID (), (* item_iterator
)-> getName (). c_str (), space
, (* item_iterator
)-> price ());
2529 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 #\ 2 ." );
2530 notice ( s_GameServ
, u
, "Where # is the weapon number from the menu above." );
2533 else if ( stricmp ( num
, "ARMOR" ) == 0 )
2535 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2536 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2537 for ( item_iterator
= store
. begin (); item_iterator
!= store
. end (); ++ item_iterator
)
2539 if ((* item_iterator
)-> getType () == ARMOR
)
2541 space
= spaces ( strlen ((* item_iterator
)-> getName (). c_str ()), "." );
2542 notice ( s_GameServ
, u
, " %s%l d. %s%s%d " ,((* item_iterator
)-> getID () < 10 ? " " : "" ), (* item_iterator
)-> getID (), (* item_iterator
)-> getName (). c_str (), space
, (* item_iterator
)-> price ());
2547 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy #" );
2548 notice ( s_GameServ
, u
, "Where # is the armor number from the menu above." );
2552 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2557 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY \1f #\1f \ 2 " );
2562 id
= stringtoint ( num
);
2565 if (! isstringnum ( num
))
2567 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY \1f #\1f \ 2 " );
2570 else if (!( tempItem
= findStoreItemByID ( id
)))
2572 notice ( s_GameServ
, u
, "Sorry, we don't carry that item!" );
2575 else if ( p
-> getGold () < tempItem
-> price ())
2577 notice ( s_GameServ
, u
, "You can't afford to buy %s " , tempItem
-> getName (). c_str ());
2580 else if ( p
-> inventory
-> addItem ( tempItem
))
2582 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , tempItem
-> getName (). c_str ());
2583 p
-> subtractGold ( tempItem
-> price ());
2584 notice ( s_GameServ
, u
, "Don't forget to type /msg %S equip %l d" , tempItem
-> getID ());
2588 notice ( s_GameServ
, u
, "You can't carry any more!" );
2591 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2593 itemContainer
* tempContainer
;
2595 id
= stringtoint ( num
);
2596 if (! isstringnum ( num
))
2598 notice ( s_GameServ
, u
, "SYNTAX: /msg %S store sell #" );
2601 else if (!( tempContainer
= p
-> inventory
-> Find ( id
)))
2603 notice ( s_GameServ
, u
, "You're not carrying that!" );
2606 else if ( p
-> getGold () >= 2000000000 )
2608 notice ( s_GameServ
, u
, "You have enough gold. Just hang on to it for now." );
2612 tempItem
= tempContainer
-> getItem ();
2614 notice ( s_GameServ
, u
, "Thank you for your business! We gave you %l d gold for %s !" , ( tempItem
-> price () / 2 ), tempItem
-> getName (). c_str ());
2615 p
-> addGold (( tempItem
-> price () / 2 ));
2616 p
-> inventory
-> deleteItem ( tempItem
);
2617 if ( tempItem
== p
-> getWeapon ())
2619 notice ( s_GameServ
, u
, "Since you equipped %s , you're going to have to reequip something" , tempItem
-> getName (). c_str ());
2623 else if ( tempItem
== p
-> getArmor ())
2626 notice ( s_GameServ
, u
, "Since you equipped %s , you're going to have to reequip something" , tempItem
-> getName (). c_str ());
2633 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2634 notice ( s_GameServ
, u
, " \ 2 STORE SELL #\ 2 " );
2635 notice ( s_GameServ
, u
, " \ 2 STORE BUY \1f #\1f \ 2 " );
2639 void do_inventory ( char * u
)
2643 if (!( user
= find ( u
)))
2645 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2648 else if ( isIgnore ( user
))
2651 log ( "Ignoring %s ." , user
-> getNick ());
2655 else if (! is_playing ( user
))
2657 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2660 updateTS ( user
-> stats
);
2661 showinventory ( user
-> stats
, user
);
2664 void showinventory ( Player
* from
, aClient
* to
)
2672 nick
= to
-> getNick ();
2674 if ( from
-> inventory
-> isEmpty ())
2676 notice ( s_GameServ
, nick
, "You aren't carrying anything" );
2680 list
< itemContainer
> * items
;
2681 items
= from
-> inventory
-> getItems ();
2683 list
< itemContainer
>:: iterator item_iter
, item_iter2
;
2684 item_iter
= items
-> begin ();
2686 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> getName (). c_str ());
2688 while ( item_iter
!= items
-> end ())
2690 // Display a list of counted items so as not to show an extra line for duplicate items
2692 item_iter2
= item_iter
;
2693 while ( item_iter
!= items
-> end () && (* item_iter
) == (* item_iter2
))
2695 if ((* item_iter
) == (* item_iter2
))
2705 notice ( s_GameServ
, nick
, " %l d.) %s ( %l d)" , (* item_iter2
). getItem ()-> getID (), (* item_iter2
). getItem ()-> getName (). c_str (), count
);
2709 void do_tavern ( char * u
)
2711 char * cmd
= strtok ( NULL
, " " );
2716 if (!( user
= find ( u
)))
2718 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2721 else if ( isIgnore ( user
))
2724 log ( "Ignoring %s ." , user
-> getNick ());
2728 else if (! is_playing ( user
))
2730 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2733 else if ( is_fighting ( user
))
2735 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2739 updateTS ( user
-> stats
);
2744 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary and General Store" );
2745 notice ( s_GameServ
, u
, "Your commands:" );
2746 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2747 notice ( s_GameServ
, u
, "What'll it be?" );
2749 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2751 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2753 notice ( s_GameServ
, u
, "To buy an item, type /msg %S TAVERN BUY #" );
2755 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2758 char * chid
= strtok ( NULL
, " " );
2759 char * amount
= strtok ( NULL
, " " );
2762 amt
= stringtoint ( amount
);
2766 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY # [#]" );
2767 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 6001" );
2768 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 6001 10" );
2771 long id
= stringtoint ( chid
);
2772 tavernItem
* tempItem
;
2774 if (!( tempItem
= findTavernItemByID ( id
)) || user
-> stats
-> getLevel () < tempItem
-> getLevel ())
2776 notice ( s_GameServ
, u
, "Invalid Choice!" );
2777 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2779 notice ( s_GameServ
, u
, "To buy an item, type /msg %S TAVERN BUY #" );
2782 else if (! amount
&& user
-> stats
-> getGold () < tempItem
-> getItem ()-> price ())
2784 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2785 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2787 notice ( s_GameServ
, u
, "To buy an item, type /msg %S TAVERN BUY #" );
2789 else if ( user
-> stats
-> getGold () < amt
* tempItem
-> getItem ()-> price ())
2791 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2792 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2794 notice ( s_GameServ
, u
, "To buy an item, type /msg %S TAVERN BUY # [#]" );
2800 int amt
= stringtoint ( amount
);
2801 if ( amt
< 0 || amount
[ 0 ] == '-' )
2803 notice ( s_GameServ
, u
, "You trying to steal from me?" );
2805 else if ( user
-> stats
-> inventory
-> addItem ( tempItem
-> getItem (), amt
) == NULL
)
2807 notice ( s_GameServ
, u
, "You can't carry that many!" );
2811 notice ( s_GameServ
, u
, " %d %s 's coming right up!" , amt
, tempItem
-> getItem ()-> getName (). c_str ());
2812 user
-> stats
-> subtractGold ( tempItem
-> getItem ()-> price () * amt
);
2817 if ( user
-> stats
-> inventory
-> addItem ( tempItem
-> getItem ()) == NULL
)
2819 notice ( s_GameServ
, u
, "You can't carry any more!" );
2823 notice ( s_GameServ
, u
, "One %s coming right up!" , tempItem
-> getItem ()-> getName (). c_str ());
2824 user
-> stats
-> subtractGold ( tempItem
-> getItem ()-> price ());
2825 notice ( s_GameServ
, u
, " %d " , user
-> stats
-> inventory
-> getCount ());
2832 notice ( s_GameServ
, u
, "Improper Syntax." );
2833 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2838 void do_bank ( char * u
)
2840 char * cmd
= strtok ( NULL
, " " );
2841 char * amount
= strtok ( NULL
, " " );
2842 char * nick
= strtok ( NULL
, " " );
2847 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2849 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2850 notice ( s_GameServ
, u
, "BANK BALANCE" );
2853 else if (!( user
= find ( u
)))
2855 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2857 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2860 else if ( isIgnore ( user
))
2863 log ( "Ignoring %s ." , user
-> getNick ());
2867 else if (! is_playing ( user
))
2869 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2872 else if ( is_fighting ( user
))
2874 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
2877 updateTS ( user
-> stats
);
2878 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2883 else if (! isAlive ( user
-> stats
))
2885 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2888 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2890 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2893 if ( stringtoint ( amount
) < 0 )
2895 notice ( s_GameServ
, u
, "Sorry. This bank is not licensed " \
2896 "to handle such sums of cash, noble Lord." );
2901 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2903 if ( p
-> getBank () == 2000000000 )
2905 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2908 else if ( stricmp ( amount
, "ALL" ) == 0 )
2910 if ( 2000000000 - p
-> getBank () < p
-> getGold ())
2912 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2913 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> getBank ()));
2914 p
-> subtractGold (( 2000000000 - p
-> getBank ()));
2915 p
-> setBank ( 2000000000 );
2920 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> getGold ());
2921 p
-> addBank ( p
-> getGold ());
2926 else if ( stringtoint ( amount
) > p
-> getGold ())
2928 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> getGold ());
2934 if ( 2000000000 - p
-> getBank () < stringtoint ( amount
))
2936 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2937 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> getBank ()));
2938 p
-> subtractGold (( 2000000000 - p
-> getBank ()));
2939 p
-> setBank ( 2000000000 );
2944 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2945 p
-> addBank ( stringtoint ( amount
));
2946 p
-> subtractGold ( stringtoint ( amount
));
2951 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2953 if ( p
-> getGold () == 2000000000 )
2955 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2959 else if ( stricmp ( amount
, "ALL" ) == 0 )
2961 if ( 2000000000 - p
-> getGold () < p
-> getBank ())
2963 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2964 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> getGold ()));
2965 p
-> subtractBank (( 2000000000 - p
-> getGold ()));
2966 p
-> setGold ( 2000000000 );
2971 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> getBank ());
2972 p
-> addGold ( p
-> getBank ());
2977 else if ( stringtoint ( amount
) > p
-> getBank ())
2979 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> getBank ());
2985 if ( 2000000000 - p
-> getGold () < stringtoint ( amount
))
2987 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2988 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2989 ( 2000000000 - p
-> getGold ()));
2990 p
-> subtractBank (( 2000000000 - p
-> getGold ()));
2991 p
-> setGold ( 2000000000 );
2996 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2997 p
-> addGold ( stringtoint ( amount
));
2998 p
-> subtractBank ( stringtoint ( amount
));
3005 void do_dragon ( char * u
)
3009 if (!( user
= find ( u
)))
3011 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
3014 else if ( isIgnore ( user
))
3017 log ( "Ignoring %s ." , user
-> getNick ());
3021 else if (! is_playing ( user
))
3023 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
3026 else if ( is_fighting ( user
))
3028 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
3031 else if (! isAlive ( user
-> stats
))
3033 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
3036 else if ( user
-> stats
-> getLevel () < LEVELS
)
3038 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
3039 "to vanquish any foe should DARE fight the dragon!" );
3040 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
3041 "You are too weak. You must be Level %d !" , REALLEVELS
);
3045 updateTS ( user
-> stats
);
3047 Player
* p
= user
-> stats
;
3049 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
3050 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
3051 "deep, red fog rolls in. The air is filled with the " \
3052 "heated mist of deadly fire from beyond the cave " \
3054 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
3055 "your %s , and venture into the hot, dark cave. " \
3056 "You are surprised at the angle of descent as you climb " \
3057 "lower and lower, deeper into the dragon's den." ,
3058 ( p
-> getArmor () ? p
-> getArmor ()-> getName (). c_str () : "Fists" ), ( p
-> getWeapon () ? p
-> getWeapon ()-> getName (). c_str () : "Birthday Suit" ));
3059 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
3060 "a tooth. It is a large tooth... bigger than your torso." \
3061 " Suddenly the darkness lifts from the gleam of an eye " \
3062 " staring into your soul! The eye is large... HUGE!" );
3063 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
3064 "glare orange! The tooth is moving... but it is still too " \
3065 "dark for you to make out.... THE DRAGON! You see it!" );
3066 p
-> setMonster ( new Monster ( dragon
));
3071 void do_master ( char * u
)
3076 if (!( user
= find ( u
)))
3078 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
3081 else if ( isIgnore ( user
))
3084 log ( "Ignoring %s ." , user
-> getNick ());
3088 else if (! is_playing ( user
))
3090 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
3093 else if ( is_fighting ( user
))
3095 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
3098 else if (! isAlive ( user
-> stats
))
3100 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
3104 updateTS ( user
-> stats
);
3106 char * cmd
= strtok ( NULL
, " " );
3107 Player
* p
= user
-> stats
;
3112 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
3118 switch ( p
-> getLevel ())
3155 need
= p
-> getExp () + 1 ;
3156 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
3160 need
= p
-> getExp () + 1 ; // Unknown level... don't let them fight a fake master!
3166 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
3170 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
3172 if ( p
-> getExp () >= need
)
3178 notice ( s_GameServ
, u
, "You are not worthy of fighting %s ! You need %l d more experience." ,
3179 levels
[ p
-> getLevel () - 1 ]. master
. name
. c_str (), ( need
- p
-> getExp ()));
3182 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
3184 if ( p
-> getExp () >= need
)
3185 notice ( s_GameServ
, u
, " %s looks you up and down and decides you are more ready than you will ever be." ,
3186 levels
[ p
-> getLevel () - 1 ]. master
. name
. c_str ());
3188 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" ,
3189 levels
[ p
-> getLevel () - 1 ]. master
. name
. c_str (), p
-> getName (). c_str ());
3195 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
3199 void see_master ( char * u
)
3203 if (!( user
= find ( u
)))
3205 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
3209 if (! is_fighting ( user
) && is_playing ( user
))
3212 Player
* p
= user
-> stats
;
3213 temp
= new Monster ( levels
[ p
-> getLevel () - 1 ]. master
);
3214 p
-> setMyMaster ( temp
);
3215 p
-> setMonster ( temp
);
3216 display_monster ( u
); // Since master is the same structure, use this function
3220 void showTavern ( aClient
* user
)
3223 list
< tavernItem
>:: iterator item_iterator
;
3231 item_iterator
= tavern
. begin ();
3234 notice ( s_GameServ
, user
-> getNick (), "Tavern is empty" );
3238 while ( item_iterator
!= tavern
. end ())
3240 if ( p
-> getLevel () < (* item_iterator
). getLevel ())
3245 tempItem
= (* item_iterator
). getItem ();
3246 notice ( s_GameServ
, user
-> getNick (), " %d . %s for %l d gold" , tempItem
-> getID (), tempItem
-> getName (). c_str (), tempItem
-> price ());
3251 void showBankBalance ( const char * u
)
3256 if (!( user
= find ( u
)))
3264 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> getBank (), p
-> getGold ());
3269 ListNode
< aClient
> * it
;
3271 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3273 it
= players
[ x
]. First ();
3276 p
= it
-> getData ()-> stats
;
3284 ListNode
< aClient
> * it
;
3286 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3288 it
= players
[ x
]. First ();
3292 p
= it
-> getData ()-> stats
;
3299 void rollover ( Player
* p
)
3304 p
-> addForestFights ( numrolloverfights
);
3306 if ( p
-> getForestFights () > maxforestfights
)
3307 p
-> setForestFights ( maxforestfights
);
3310 void refresh ( Player
* p
)
3315 if ( p
-> getHP () < p
-> getMaxHP ())
3317 if ( p
-> getForestFights () < forestfights
)
3319 p
-> setForestFights ( forestfights
);
3322 p
-> setPlayerFights ( 3 );
3327 void do_refresh ( char * u
)
3329 char * nick
= strtok ( NULL
, " " );
3332 if (!( user
= find ( u
)))
3334 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3335 log ( "Error: aClient not found: %s " , u
);
3338 else if ( isIgnore ( user
))
3341 log ( "Ignoring %s ." , user
-> getNick ());
3345 else if (! isAdmin ( user
))
3347 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3352 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3355 else if ( stricmp ( nick
, "ALL" ) == 0 )
3357 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3360 else if (( user
= findplayer ( nick
)))
3362 if ( is_playing ( user
))
3365 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
3367 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
3369 refresh ( user
-> stats
);
3374 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
3376 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
3382 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3390 ListNode
< aClient
> * it
;
3393 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3395 it
= players
[ x
]. First ();
3399 p
= it
-> getData ()-> stats
;
3406 void reset ( Player
* p
)
3413 tempItem
= findItemByID ( 3001 );
3414 p
-> inventory
-> addItem ((* Items
. begin ()))-> use ( p
); // Add the stick
3415 p
-> inventory
-> addItem ( tempItem
)-> use ( p
); // Add Clothes
3419 void updateTS ( Player
* p
)
3425 log ( "Old timestamp for %s : %l d" , p
-> getName (). c_str (), p
-> lastcommand
);
3427 p
-> lastcommand
= time ( NULL
);
3429 log ( "New timestamp for %s : %l d" , p
-> getName (). c_str (), p
-> lastcommand
);
3434 bool timedOut ( Player
* p
)
3438 else if ( p
-> lastcommand
== 0 )
3442 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3449 void timeOutEvent ( Player
* p
)
3451 aClient
* user
= findplayer ( p
-> getName (). c_str ());
3453 if (! user
|| ! p
-> getClient ()) // then they're not playing
3456 char * nick
= user
-> getNick ();
3458 if ( player_fight ( user
) && isYourTurn ( p
))
3460 // Check to see if they were the idler or if it was the other
3462 if ( p
-> lastcommand
!= p
-> getBattle ()-> stats
-> lastcommand
)
3464 // This person's last command was given earlier,
3465 // so this person is the idler
3466 notice ( s_GameServ
, nick
, "You timed out " \
3467 "during a fight. You lose your turn!" );
3468 notice ( s_GameServ
, p
-> getBattle ()-> getNick (),
3469 " %s hesitated for too long. Your move." , p
-> getName (). c_str ());
3471 setYourTurn ( p
-> getBattle ()-> stats
);
3473 // Update the TS for both players to give them another
3474 // Chance to wake up, but if the other player doesn't
3475 // Attack now, they both get logged out.
3477 p
-> getBattle ()-> stats
-> lastcommand
= p
-> lastcommand
;
3478 display_players ( p
-> getBattle ());
3483 notice ( s_GameServ
, p
-> getBattle ()-> getNick (),
3484 "You and %s timed out at the same time." \
3485 " Don't fight if you're just going to " \
3486 "sit there!" , p
-> getName (). c_str ());
3487 notice ( s_GameServ
, user
-> getNick (),
3488 "You and %s timed out at the same time." \
3489 " Don't fight if you're just going to " \
3490 "sit there!" , p
-> getBattle ()-> stats
-> getName (). c_str ());
3491 logout ( p
-> getBattle ());
3496 else if (! player_fight ( user
))
3498 if ( isAlive ( user
-> stats
) && user
-> stats
-> getGold () > 0 )
3500 // Place fun stuff here :)
3501 int randnum
= 1 + rand () % 100 ; // 1-100
3502 #define GSN(s) notice(s_GameServ, nick, s)
3503 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3507 // 35-100% of your gold goes pffft - kain
3508 int stolen
= ( 35 + ( rand () % 66 )) * ( user
-> stats
-> getGold () / 100 );
3510 GSN ( "You stop for a moment to rest on the " \
3511 "street corner. All of a sudden, you " \
3512 "are ambushed from all sides by a hoarde " \
3513 "of knife wielding thugs." );
3514 GSN2 ( "The thugs beat you into utter submission " \
3515 "and steal %l d gold from you!" , stolen
);
3516 user
-> stats
-> subtractGold ( stolen
);
3518 else if ( randnum
>= 50 && randnum
< 75 )
3520 // 25-65% of your gold goes pffft - kain
3521 int stolen
= ( 25 + ( rand () % 41 )) * ( user
-> stats
-> getGold () / 100 );
3522 GSN ( "While dilly dallying around, you lose " \
3523 "your sense of time. Little did you know, " \
3524 "but thieves lifted your gold while you " \
3525 "weren't watching." );
3526 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3527 user
-> stats
-> subtractGold ( stolen
);
3529 else if ( randnum
>= 75 )
3531 // 25-75% of your gold goes pffft - kain
3532 int stolen
= ( 25 + ( rand () % 51 )) * ( user
-> stats
-> getGold () / 100 );
3533 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3534 "goblins grabbed your gold!" );
3535 GSN2 ( "They stole %d gold from you!" , stolen
);
3536 user
-> stats
-> subtractGold ( stolen
);
3540 // Always log out the user
3545 void do_reset ( char * u
)
3547 char * nick
= strtok ( NULL
, " " );
3550 if (!( user
= find ( u
)))
3552 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3553 log ( "Error: aClient not found: %s " , u
);
3556 else if (! isAdmin ( user
))
3558 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3564 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3567 else if ( stricmp ( nick
, "ALL" ) == 0 )
3569 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3572 else if (( user
= findplayer ( nick
)))
3574 if ( is_playing ( user
))
3577 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
3579 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
3585 notice ( s_GameServ
, u
, "Resetting %s " , user
-> stats
-> getName (). c_str ());
3591 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3596 void do_help ( char * u
)
3598 char * cmd
= strtok ( NULL
, " " );
3600 display_help ( u
, cmd
);
3603 void display_help ( char * u
, char * file
)
3610 infile
. open ( "helpfiles/help" );
3613 log ( "Error opening helpfiles/help" );
3614 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3617 buf
= new char [ 1024 ];
3618 while ( infile
. getline ( buf
, 1024 ))
3620 // Written this way, it will process %S in the helpfiles
3621 // Instead of notice(s_GameServ, u, "%s", buf);
3622 notice ( s_GameServ
, u
, buf
);
3626 aClient
* user
= find ( u
);
3627 if ( user
&& isAdmin ( user
))
3628 display_help ( u
, "admin_commands" );
3633 filename
= new char [ strlen ( file
) + 11 ];
3634 strcpy ( filename
, "helpfiles/" );
3635 strcat ( filename
, file
);
3637 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3638 filename
[ x
] = tolower ( filename
[ x
]);
3640 infile
. open ( filename
);
3644 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3647 buf
= new char [ 1024 ];
3648 while ( infile
. getline ( buf
, 1024 ))
3650 // Written this way, it will process %S in the helpfiles
3651 // Instead of notice(s_GameServ, u, "%s", buf);
3652 notice ( s_GameServ
, u
, buf
);
3659 void do_admin ( char * u
)
3662 char * pass
= strtok ( NULL
, " " );
3664 if (!( user
= find ( u
)))
3666 log ( "Error: aClient not found: %s " , u
);
3667 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3673 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3679 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3682 else if ( strcmp ( pass
, adminpass
) == 0 )
3684 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3687 log ( " %s became an administrator." , user
-> getRealNick ());
3689 log ( " %s became an administrator." , user
-> getNick ());
3694 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3702 filename
= new char [ 256 ];
3704 for ( int x
= 1 ; x
<= LEVELS
; x
++)
3706 sprintf ( filename
, "data/levels/level %d .dat" , x
);
3707 if ( levels
[ x
- 1 ]. loadLevel ( filename
) == false )
3714 bool load_monsters ()
3719 buf
= new char [ 2048 ];
3721 for ( int level
= 1 ; level
<= LEVELS
; level
++)
3723 filename
= new char [ 256 ];
3724 sprintf ( filename
, "data/monsters/level %d .dat" , level
);
3725 infile
. open ( filename
);
3729 log ( "Error opening %s " , filename
);
3734 log ( "Loading monsters from %s " , filename
);
3737 while ( infile
. getline ( buf
, 2048 ))
3741 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3746 temp
-> name
= strtok ( buf
, "~" );
3747 temp
-> weapon
= strtok ( NULL
, "~" );
3748 temp
-> death
= strtok ( NULL
, "~" );
3750 levels
[ level
- 1 ]. monsters
. insertAtBack_RLN ( temp
);
3760 item
* findItemByID ( int id
)
3762 list
< item
*>:: iterator item_iterator
;
3764 item_iterator
= Items
. begin ();
3766 while ( item_iterator
!= Items
. end ())
3768 if ((* item_iterator
)-> getID () == id
)
3770 return (* item_iterator
);
3777 item
* findStoreItemByID ( int id
)
3779 list
< item
*>:: iterator item_iterator
;
3781 item_iterator
= store
. begin ();
3783 while ( item_iterator
!= store
. end ())
3785 if ((* item_iterator
)-> getID () == id
)
3787 return (* item_iterator
);
3794 tavernItem
* findTavernItemByID ( int id
)
3796 list
< tavernItem
>:: iterator item_iterator
;
3798 item_iterator
= tavern
. begin ();
3800 while ( item_iterator
!= tavern
. end ())
3802 if ((* item_iterator
). getItem ()-> getID () == id
)
3804 return &(* item_iterator
);