]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
21 #if defined(HAVE_CRYPT_H)
25 #elif defined(HAVE_UNISTD_H)
31 Monster dragon
; // The current dragon
32 Level levels
[ LEVELS
]; // The newest way to store monsters
33 list
< item
*> Items
; // The master list of items
34 list
< tavernItem
> tavern
; // The list of items available at the tavern
35 list
< item
*> store
; // The list of items available at the store
46 item
* findItemByID ( int id
);
47 item
* findStoreItemByID ( int id
);
48 tavernItem
* findTavernItemByID ( int id
);
52 char * strtok ( char * str
, const char * delim
);
55 int stricmp ( const char * s1
, const char * s2
);
56 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
59 /********** Password functions **********/
61 bool passcmp ( const char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
63 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
65 /********** Password functions **********/
68 /********** GameServ Booleans **********/
71 bool timedOut ( Player
* p
);
72 void updateTS ( Player
* p
);
73 void timeOutEvent ( Player
* p
);
75 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
76 bool is_playing ( aClient
* user
);
78 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
79 bool is_fighting ( aClient
* user
);
81 bool player_fight ( char * u
); // True if the player is fighting another player.
82 bool player_fight ( aClient
* user
);
84 bool master_fight ( char * u
); // True if the player is fighting their master.
85 bool master_fight ( aClient
* user
);
87 bool dragon_fight ( char * u
); // True if the player is fighting the dragon.
88 bool dragon_fight ( aClient
* user
);
90 bool alphaNumeric ( const char * str
); // Returns true if all of the characters in str are alphanumeric non-special chars
91 /********** GameServ Booleans **********/
93 void display_help ( char * u
, char * file
= NULL
);
94 void display_monster ( char * u
);
95 void display_players ( char * u
);
96 void display_players ( aClient
* user
);
97 long int chartoint ( char ch
);
98 int isstringnum ( char * num
);
99 long int pow ( int x
, int y
);
100 long int stringtoint ( char * number
);
102 char * spaces ( int len
, char * seperator
);
103 void refresh ( Player
* p
);
105 void rollover ( Player
* p
);
108 void updateTS ( Player
* p
);
109 void reset ( Player
* p
);
111 bool load_monsters ();
113 void delete_monsters ();
115 void do_admin ( char * u
);
116 void do_attack ( char * u
);
117 void do_bank ( char * u
);
118 void do_check ( char * u
);
119 void do_equip ( char * u
);
120 void do_fight ( char * u
);
121 void do_heal ( char * u
);
122 void do_help ( char * u
);
123 void do_identify ( char * u
);
124 void do_inventory ( char * u
);
125 void do_refresh ( char * u
);
126 void do_register ( char * u
);
127 void do_list ( char * u
);
128 void do_logout ( char * u
);
129 void do_master ( char * u
);
130 void do_dragon ( char * u
);
131 void do_play ( char * u
);
132 void do_quitg ( char * u
);
133 void do_reset ( char * u
);
134 void do_run ( char * u
);
135 void do_set ( char * u
);
136 void do_stats ( char * u
);
137 void do_store ( char * u
);
138 void do_tavern ( char * u
);
139 void do_use ( char * u
);
140 void see_master ( char * u
);
142 void logout ( aClient
* user
);
143 void showstats ( const char * u
, const char * nick
);
144 void showTavern ( aClient
* user
);
145 void showinventory ( Player
* from
, aClient
* to
);
146 void showBankBalance ( const char * u
);
147 void end_turn ( aClient
* user
);
151 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
152 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
153 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
155 void gameserv ( char * source
, char * buf
)
158 cmd
= strtok ( buf
, " " );
161 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
166 cmd
++; // Get rid of that : at the beginning of the :text (command)
169 log ( "Source: %s Command: %s " , source
, cmd
);
172 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
175 ts
= strtok ( NULL
, "\1" );
176 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
178 else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 )
180 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
182 else if ( stricmp ( cmd
, "SEARCH" ) == 0 )
184 cmd
= strtok ( NULL
, " " );
187 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
192 else if ( stricmp ( cmd
, "ADMIN" ) == 0 )
196 else if ( stricmp ( cmd
, "ATTACK" ) == 0 )
200 else if ( stricmp ( cmd
, "BANK" ) == 0 )
204 else if ( stricmp ( cmd
, "CHECK" ) == 0 )
208 else if ( stricmp ( cmd
, "DRAGON" ) == 0 )
212 else if ( stricmp ( cmd
, "EQUIP" ) == 0 )
216 else if ( stricmp ( cmd
, "FIGHT" ) == 0 )
220 else if ( stricmp ( cmd
, "HEAL" ) == 0 )
224 else if ( stricmp ( cmd
, "HELP" ) == 0 )
228 else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 )
232 else if ( stricmp ( cmd
, "INVENTORY" ) == 0 )
234 do_inventory ( source
);
236 else if ( stricmp ( cmd
, "LIST" ) == 0 )
240 else if ( stricmp ( cmd
, "LOGOUT" ) == 0 )
244 else if ( stricmp ( cmd
, "MASTER" ) == 0 )
248 else if ( stricmp ( cmd
, "NEWS" ) == 0 )
252 else if ( stricmp ( cmd
, "REGISTER" ) == 0 )
256 else if ( stricmp ( cmd
, "REFRESH" ) == 0 )
260 else if ( stricmp ( cmd
, "RESET" ) == 0 )
264 else if ( stricmp ( cmd
, "RUN" ) == 0 )
268 else if ( stricmp ( cmd
, "SET" ) == 0 )
272 else if ( stricmp ( cmd
, "STATS" ) == 0 )
276 else if ( stricmp ( cmd
, "STORE" ) == 0 )
280 else if ( stricmp ( cmd
, "TAVERN" ) == 0 )
284 else if ( stricmp ( cmd
, "USE" ) == 0 )
288 else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 )
292 if (!( user
= find ( source
)))
294 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
295 log ( "Error: aClient not found: %s " , source
);
297 else if (! isAdmin ( user
))
299 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
305 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
307 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
312 else if ( stricmp ( cmd
, "SAVE" ) == 0 )
316 if (!( user
= find ( source
)))
318 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
319 log ( "Error: aClient not found: %s " , source
);
321 else if (! isAdmin ( user
))
323 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
330 else if ( stricmp ( cmd
, "LOAD" ) == 0 )
334 if (!( user
= find ( source
)))
336 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
337 log ( "Error: aClient not found: %s " , source
);
339 else if (! isAdmin ( user
))
341 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
345 char * cmd2
= strtok ( NULL
, " " );
348 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
351 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
353 notice ( s_GameServ
, source
, "Loading monster data" );
356 else if ( stricmp ( cmd2
, "SCRIPTS" ) == 0 )
358 // Testing scripts for now
360 notice ( s_GameServ
, source
, "Loading scripts" );
362 if ( scr
. loadScript ( "test.txt" ))
363 scr
. executeScript ( user
-> stats
);
367 display_help ( source
, cmd
);
372 else if ( stricmp ( cmd
, "RAW" ) == 0 )
376 if (!( user
= find ( source
)))
378 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
379 log ( "Error: aClient not found: %s " , source
);
381 else if (! isAdmin ( user
))
383 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
387 char * rest
= strtok ( NULL
, "" );
391 else if ( stricmp ( cmd
, "RANDOM" ) == 0 )
393 char * rstr
= strtok ( NULL
, "" );
395 trange
. setRange ( rstr
);
396 notice ( s_GameServ
, source
, "Random number in that range: %d " , trange
. random ());
402 if (( user
= find ( source
)))
407 log ( "Ignoring %s ." , user
-> getNick ());
412 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
418 source
--; // Bring the ':' back so we don't leak memory
421 cmd
--; // Same thing :)
424 int stricmp ( const char * s1
, const char * s2
)
428 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
434 if ( c
< tolower (* s2
))
439 void showstats ( const char * u
, const char * nick
)
441 aClient
* sender
= find ( u
);
448 if (!( p
= findplayer ( nick
)))
450 notice ( s_GameServ
, u
, " %s not found" , nick
);
454 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , p
-> getName (). c_str ());
456 sprintf ( buf
, "Experience: %l d" , p
-> getExp ());
457 space
= spaces ( strlen ( buf
), " " );
458 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
462 sprintf ( buf
, "Gold: %l d" , p
-> getGold ());
463 space
= spaces ( strlen ( buf
), " " );
464 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, p
-> getBank ());
467 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , p
-> getHP (),
470 sprintf ( buf
, "Strength: %d " , p
-> getStrength ());
471 space
= spaces ( strlen ( buf
), " " );
472 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
473 buf
, space
, p
-> getDefense ());
476 sprintf ( buf
, "Armor: %s " , ( p
-> getArmor () ? p
-> getArmor ()-> getName (). c_str () : "Nothing" ));
477 space
= spaces ( strlen ( buf
), " " );
479 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
480 ( p
-> getWeapon () ? p
-> getWeapon ()-> getName (). c_str () : "Fists" ));
484 sprintf ( buf
, "Forest Fights: %d " , p
-> getForestFights ());
485 space
= spaces ( strlen ( buf
), " " );
486 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, p
-> getPlayerFights ());
488 if ( p
-> getClient () == sender
|| isAdmin ( sender
))
490 showinventory ( p
, sender
);
497 char * spaces ( int len
, char * seperator
)
500 final
= new char [ 30 ];
502 strcpy ( final
, seperator
);
503 for ( y
= 0 ; y
< 30 - len
; y
++)
504 strcat ( final
, seperator
);
508 void raw ( const char * fmt
, ...)
513 input
= new char [ 1024 ];
515 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
521 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
522 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
523 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
526 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
531 sprintf ( input
, " %s%c " , input
, * t
);
536 log ( "Input: %s " , input
);
539 sprintf ( input
, " %s%s " , input
, " \r\n " );
540 sock_puts ( sock
, input
);
544 /* Send a NOTICE from the given source to the given nick. */
546 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
552 commanduse
= new char [ 16 ];
556 strcpy ( commanduse
, "P" );
558 strcpy ( commanduse
, "O" );
562 strcpy ( commanduse
, "PRIVMSG" );
564 strcpy ( commanduse
, "NOTICE" );
570 input
= new char [ 1024 ];
577 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
579 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
587 sprintf ( input
, ": %s %s %s :" , source
, commanduse
, dest
);
589 sprintf ( input
, " %s %s %s :" , gsnum
, commanduse
, dest
);
598 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
599 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
600 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
601 case 'c' : sprintf ( input
, " %s%c " , input
, va_arg ( args
, int )); break ;
604 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
609 sprintf ( input
, " %s%c " , input
, * t
);
614 log ( "Input: %s " , input
);
616 sprintf ( input
, " %s%s " , input
, " \r\n " );
617 sock_puts ( sock
, input
);
618 delete [] commanduse
;
624 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
630 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
631 if ( c
== 0 || -- len
== 0 )
636 if ( c
< tolower (* s2
))
642 char * strtok ( char * str
, const char * delim
)
644 static char * current
= NULL
;
651 current
+= strspn ( current
, delim
);
652 ret
= * current
? current
: NULL
;
653 current
+= strcspn ( current
, delim
);
662 void do_check ( char * u
)
664 int days
, hours
, minutes
, seconds
;
666 complete
= ( lastrefresh
+ refreshperiod
) - time ( NULL
);
667 days
= complete
/ 86400 ;
668 hours
= ( complete
% 86400 ) / 3600 ;
669 minutes
= ( complete
% 86400 ) % 3600 / 60 ;
670 seconds
= ( complete
% 86400 ) % 3600 % 60 ;
672 notice ( s_GameServ
, u
, "Time left to next refresh: %d d %d h %d m %d s" ,
673 days
, hours
, minutes
, seconds
);
675 if ( isRolloverForestFights ())
677 complete
= ( lastrollover
+ rolloverperiod
) - time ( NULL
);
679 days
= complete
/ 86400 ;
680 hours
= ( complete
% 86400 ) / 3600 ;
681 minutes
= ( complete
% 86400 ) % 3600 / 60 ;
682 seconds
= ( complete
% 86400 ) % 3600 % 60 ;
684 notice ( s_GameServ
, u
, "Time left to next rollover: %d d %d h %d m %d s" ,
685 days
, hours
, minutes
, seconds
);
689 void do_list ( char * u
)
693 char * cmd
= strtok ( NULL
, " " );
695 if (!( user
= find ( u
)))
697 log ( "Fatal Error: Couldn't find %s in the client list" , u
);
700 else if ( isIgnore ( user
))
703 log ( "Ignoring %s . Command LIST" , user
-> getNick ());
708 list
< Player
*>:: iterator iter
;
711 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
713 iter
= players
[ x
]. begin ();
714 if (! players
[ x
]. empty ())
716 while ( iter
!= players
[ x
]. end ())
719 if ( cmd
|| is_playing ( p
-> getClient ()))
723 notice ( s_GameServ
, u
, "Players:" );
727 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , ( p
-> getClient () ? p
-> getClient ()-> getRealNick () : "Not Playing" ),
728 p
-> getName (). c_str ());
730 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , ( p
-> getClient () ? p
-> getClient ()-> getNick () : "Not Playing" ),
731 p
-> getName (). c_str ());
739 notice ( s_GameServ
, u
, "No one is playing" );
741 notice ( s_GameServ
, u
, "End of List" );
748 char * name
= strtok ( NULL
, " " );
749 char * cmd
= strtok ( NULL
, " " );
752 if (!( user
= find ( u
)))
754 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
755 "Buf: %s LOGOUT" , u
);
758 else if ( isIgnore ( user
))
761 log ( "Ignoring %s ." , user
-> getNick ());
765 else if (! name
|| ! cmd
)
767 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}" );
770 else if (!( p
= findplayer ( name
)))
772 // Back the pointers up... they didn't send a name probably
777 if (! is_playing ( user
))
779 notice ( s_GameServ
, u
, "You must be playing to set things for yourself!" );
785 cmd2
= strtok ( NULL
, " " );
789 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}" );
793 // Regardless of the previous if/else, if it got here, we know we have the cmd pointer at the right spot.
794 if ( stricmp ( cmd
, "PASSWORD" ) == 0 )
796 // Person is looking to change their password
797 // If they're an admin, or it's theirself, allow it
798 // cmd2 is pointing to the password now
799 if ( isAdmin ( user
) || user
== p
-> getClient ())
801 p
-> setPassword ( cmd2
);
802 notice ( s_GameServ
, u
, "Password successfully changed" );
804 else if ( user
!= p
-> getClient () && ! isAdmin ( user
))
806 notice ( s_GameServ
, u
, "You must be a %S admin to set other peoples' passwords." );
810 else if ( stricmp ( cmd
, "BANK" ) == 0 || stricmp ( cmd
, "BALANCE" ) == 0 )
814 notice ( s_GameServ
, u
, "Admins Only!" );
817 else if ( stricmp ( cmd
, "BANK" ) == 0 )
819 cmd2
= strtok ( NULL
, " " ); // Need an extra parameter for set bank balance
823 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] [BANK] BALANCE <NUMBER>" );
827 p
-> setBank ( stringtoint ( cmd2
));
829 notice ( s_GameServ
, u
, "Bank balance changed to %l d!" , p
-> getBank ());
831 else if ( stricmp ( cmd
, "PLAYER" ) == 0 )
835 notice ( s_GameServ
, u
, "Admins Only!" );
838 else if ( stricmp ( cmd2
, "FIGHTS" ) != 0 )
840 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>" );
845 cmd2
= strtok ( NULL
, " " );
848 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>" );
851 p
-> setPlayerFights ( stringtoint ( cmd2
));
853 notice ( s_GameServ
, u
, "Player fights changed to %d !" , p
-> getPlayerFights ());
856 else if ( stricmp ( cmd
, "FOREST" ) == 0 )
860 notice ( s_GameServ
, u
, "Admins Only!" );
863 else if ( stricmp ( cmd2
, "FIGHTS" ) != 0 )
865 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <number>" );
870 cmd2
= strtok ( NULL
, " " );
873 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <NUMBER>" );
877 p
-> setForestFights ( stringtoint ( cmd2
));
879 notice ( s_GameServ
, u
, "Forest fights changed to %d !" , p
-> getForestFights ());
882 else if ( stricmp ( cmd
, "GOLD" ) == 0 )
886 notice ( s_GameServ
, u
, "Admins Only!" );
893 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] GOLD <NUMBER>" );
896 p
-> setGold ( stringtoint ( cmd2
));
898 notice ( s_GameServ
, u
, "Gold set to %l d" , p
-> getGold ());
902 else if ( stricmp ( cmd
, "STRENGTH" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
906 notice ( s_GameServ
, u
, "Admins Only!" );
913 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] STRENGTH <NUMBER>" );
917 p
-> setStrength ( stringtoint ( cmd2
));
919 notice ( s_GameServ
, u
, "Strength set to %d " , p
-> getStrength ());
923 else if ( stricmp ( cmd
, "DEFENSE" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
927 notice ( s_GameServ
, u
, "Admins Only!" );
934 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] DEFENSE <NUMBER>" );
938 p
-> setDefense ( stringtoint ( cmd2
));
940 notice ( s_GameServ
, u
, "Defense set to %d " , p
-> getDefense ());
944 else if ( stricmp ( cmd
, "HP" ) == 0 && stricmp ( cmd2
, "POTIONS" ) != 0 )
948 notice ( s_GameServ
, u
, "Admins Only!" );
955 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] HP <NUMBER>" );
959 // Make sure it's easy for an admin to set the hp
960 if ( p
-> getMaxHP () < stringtoint ( cmd2
))
961 p
-> setMaxHP ( stringtoint ( cmd2
));
963 p
-> setHP ( stringtoint ( cmd2
));
965 notice ( s_GameServ
, u
, "HP set to %d " , p
-> getHP ());
969 else if ( stricmp ( cmd
, "MAXHP" ) == 0 )
973 notice ( s_GameServ
, u
, "Admins Only!" );
980 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] MAXHP <NUMBER>" );
983 p
-> setMaxHP ( stringtoint ( cmd2
));
985 notice ( s_GameServ
, u
, "MaxHP set to %d " , p
-> getMaxHP ());
989 else if ( stricmp ( cmd
, "EXPERIENCE" ) == 0 || stricmp ( cmd
, "EXP" ) == 0 )
993 notice ( s_GameServ
, u
, "Admins Only!" );
1000 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] {EXPERIENCE|EXP} <NUMBER>" );
1004 p
-> setExp ( stringtoint ( cmd2
));
1006 notice ( s_GameServ
, u
, "Exp set to %l d" , p
-> getExp ());
1010 else if ( stricmp ( cmd
, "LEVEL" ) == 0 )
1014 notice ( s_GameServ
, u
, "Admins Only!" );
1021 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] LEVEL <NUMBER>" );
1024 p
-> setLevel ( stringtoint ( cmd2
));
1026 notice ( s_GameServ
, u
, "Level set to %d " , p
-> getLevel ());
1030 else if ( stricmp ( cmd
, "ALIVE" ) == 0 )
1034 notice ( s_GameServ
, u
, "Admins Only!" );
1041 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] ALIVE TRUE|FALSE" );
1044 else if ( stricmp ( cmd2
, "TRUE" ) == 0 )
1046 notice ( s_GameServ
, u
, " %s has been Resurrected!" , p
-> getName (). c_str ());
1051 notice ( s_GameServ
, u
, " %s is now dead!" , p
-> getName (). c_str ());
1056 else if ( stricmp ( cmd
, "SEEN" ) == 0 )
1060 notice ( s_GameServ
, u
, "Admins Only!" );
1063 else if ( stricmp ( cmd2
, "MASTER" ) != 0 )
1065 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NAME] SEEN MASTER {TRUE|FALSE}" );
1070 cmd2
= strtok ( NULL
, " " );
1073 notice ( s_GameServ
, u
, "SYNTAX: /msg %S SET [NICK] SEEN MASTER {TRUE|FALSE}" );
1076 else if ( stricmp ( cmd2
, "TRUE" ) == 0 )
1078 notice ( s_GameServ
, u
, " %s has seen their master now." , p
-> getName (). c_str ());
1079 p
-> addFlag ( FLAG_MASTER
);
1083 notice ( s_GameServ
, u
, " %s has not seen their master now." , p
-> getName (). c_str ());
1084 p
-> remFlag ( FLAG_MASTER
);
1090 notice ( s_GameServ
, u
, "Unknown command: SET %s " , cmd
);
1091 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}" );
1096 void do_logout ( char * u
)
1100 char * name
= strtok ( NULL
, " " );
1102 if (!( user
= find ( u
)))
1104 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
1105 "Buf: %s LOGOUT" , u
);
1106 log ( "Could not find aClient Buf: %s LOGOUT" ,
1110 else if ( isIgnore ( user
))
1113 log ( "Ignoring %s ." , user
-> getNick ());
1122 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
1124 else if (!( p
= findplayer ( name
)))
1126 notice ( s_GameServ
, u
, "Couldn't find a player named %s " , name
);
1130 notice ( s_GameServ
, u
, "Logging out %s " , p
-> getName (). c_str ());
1131 logout ( p
-> getClient ());
1136 if (! is_playing ( user
))
1138 notice ( s_GameServ
, u
, "You're not logged in!" );
1140 else if ( is_fighting ( user
))
1142 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
1146 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
1152 void logout ( aClient
* user
)
1156 if ( user
-> stats
!= NULL
)
1159 list
< Player
*>:: iterator iter
;
1160 unsigned long hv
= iHASH (( unsigned char *) user
-> stats
-> getName (). c_str ());
1161 iter
= find ( players
[ hv
]. begin (), players
[ hv
]. end (), user
-> stats
);
1163 if ( iter
== players
[ hv
]. end ())
1165 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
1166 " %S Admin. Cannot find you in the players list. This should NEVER happen" );
1167 log ( "Error on logout(). Can't find %s in the players list" ,
1178 user
-> stats
-> delMonster ();
1179 user
-> stats
-> delMaster ();
1180 user
-> stats
-> delBattle ();
1181 clearDragonFight ( user
-> stats
);
1182 clearYourTurn ( user
-> stats
);
1185 user
-> stats
-> setClient ( NULL
);
1188 if ( player_fight ( user
))
1190 clearYourTurn ( user
-> stats
-> getBattle ()-> stats
);
1191 user
-> stats
-> getBattle ()-> stats
-> delBattle ();
1195 log ( "Logged out player %s " ,
1209 void do_register ( char * u
)
1211 char * password
, * name
;
1214 name
= strtok ( NULL
, " " );
1215 password
= strtok ( NULL
, " " );
1219 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
1221 else if ( stricmp ( name
, s_GameServ
) == 0 )
1223 notice ( s_GameServ
, u
, "You can't use %S as a name!" );
1227 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
1229 else if ( strlen ( name
) > maxnicklen
)
1231 notice ( s_GameServ
, u
, "Name too long. Maximum length: %d " , maxnicklen
);
1233 else if (! alphaNumeric ( name
))
1235 notice ( s_GameServ
, u
, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!" );
1237 else if (( p
= findplayer ( name
)))
1239 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
1240 notice ( s_GameServ
, u
, "Choose another name!" );
1242 else if (!( user
= find ( u
)))
1244 log ( "Fatal Error: Couldn't find %s in the clients list" , u
);
1246 else if ( isIgnore ( user
))
1249 log ( "Ignoring %s ." , user
-> getNick ());
1254 if (! is_playing ( user
))
1257 unsigned long hv
= iHASH (( unsigned char *) name
);
1259 // First create the Player
1260 user
-> stats
= new Player ();
1262 // Set the backwards pointer
1263 user
-> stats
-> setClient ( user
);
1265 // Set the player's password
1266 user
-> stats
-> setPassword ( password
);
1268 // Set the player's name
1269 user
-> stats
-> setName ( name
);
1271 // Make sure they have a proper time stamp
1272 updateTS ( user
-> stats
);
1274 // Update the last login time
1275 user
-> stats
-> lastlogin
= time ( NULL
);
1277 // Send notification of success
1278 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> getName (). c_str (), password
);
1279 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
1281 // Log the new player
1282 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> getName (). c_str ());
1284 // Log the player in
1287 // Start the player at the beginning
1290 // Add the stick and clothes
1291 tempItem
= findItemByID ( 3001 );
1292 user
-> stats
-> inventory
-> addItem ((* Items
. begin ()))-> use ( user
-> stats
); // Add the stick
1293 user
-> stats
-> inventory
-> addItem ( tempItem
)-> use ( user
-> stats
); // Add Clothes
1295 // Add the player to the list
1296 players
[ hv
]. push_back ( user
-> stats
);
1300 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
1305 void do_identify ( char * u
)
1307 char * password
, * name
;
1310 name
= strtok ( NULL
, " " );
1311 password
= strtok ( NULL
, " " );
1312 if (! password
|| ! name
)
1314 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
1316 else if (!( user
= find ( u
)))
1318 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
1319 log ( "Error: aClient not found: %s " , u
);
1321 else if ( isIgnore ( user
))
1324 log ( "Ignoring %s ." , user
-> getNick ());
1328 else if (!( p
= findplayer ( name
)))
1330 notice ( s_GameServ
, u
, "Player %s not found" , name
);
1332 else if ( is_playing ( user
))
1334 notice ( s_GameServ
, u
, "You are already playing!" );
1336 else if ( is_playing ( p
-> getClient ()) && ! isAdmin ( user
))
1338 notice ( s_GameServ
, u
, "That player has already identified." );
1340 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
1342 notice ( s_GameServ
, u
, "Password incorrect" );
1346 list
< Player
*>:: iterator iter
;
1347 unsigned long hv
= iHASH (( unsigned char *) p
-> getName (). c_str ());
1349 iter
= find ( players
[ hv
]. begin (), players
[ hv
]. end (), p
);
1351 if ( iter
== players
[ hv
]. end ())
1353 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
1357 // Make sure the other user is logged out
1358 logout ( p
-> getClient ());
1366 log ( "Player %s IRC: %s Identified" , user
-> stats
-> getName (). c_str (),
1369 //Set the playing flag
1372 // Update the last login time
1373 user
-> stats
-> lastlogin
= time ( NULL
);
1375 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
1376 showNews ( u
, todaysnews
);
1380 void do_stats ( char * u
)
1385 nick
= strtok ( NULL
, " " );
1387 if (!( user
= find ( u
)))
1389 log ( "Fatal Error: %s not found in client list" , u
);
1392 else if ( isIgnore ( user
))
1395 log ( "Ignoring %s ." , user
-> getNick ());
1401 if (! is_playing ( user
))
1403 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
1408 if (! is_fighting ( user
))
1409 updateTS ( user
-> stats
);
1410 showstats ( u
, user
-> stats
-> getName (). c_str ());
1419 ifstream
infile ( masterdata
);
1422 buf
= new char [ 1024 ];
1426 log ( "Error opening %s " , masterdata
);
1431 log ( "Loading masters from %s " , masterdata
);
1434 for ( l
= 0 ; l
< LEVELS
- 1 ; l
++)
1436 infile
. getline ( buf
, 1024 , ' \n ' );
1439 if ( buf
[ 0 ] == '#' || buf
[ 0 ] == ' \n ' || buf
[ 0 ] == ' \r ' )
1444 else if ( buf
[ 0 ] == '^' )
1447 Monster
* master
= & levels
[ l
]. master
;
1449 char * name
, * weapon
, * strength
, * gold
, * exp
, * maxhp
, * death
;
1452 name
= strtok ( buf
, "~" );
1453 weapon
= strtok ( NULL
, "~" );
1454 strength
= strtok ( NULL
, "~" );
1455 gold
= strtok ( NULL
, "~" );
1456 exp
= strtok ( NULL
, "~" );
1457 maxhp
= strtok ( NULL
, "~" );
1458 death
= strtok ( NULL
, "~" );
1460 master
-> name
= name
;
1461 master
-> weapon
= weapon
;
1462 master
-> strength
= stringtoint ( strength
);
1463 master
-> gold
= stringtoint ( gold
);
1464 master
-> exp
= stringtoint ( exp
);
1465 master
-> maxhp
= stringtoint ( maxhp
);
1466 master
-> hp
= master
-> maxhp
;
1467 master
-> death
= death
;
1472 if ( l
< LEVELS
- 1 ) // We didn't load a master for every level - check data/masters.dat
1478 void delete_monsters ()
1480 for ( int x
= 0 ; x
< LEVELS
; x
++)
1481 levels
[ x
]. monsters
. clear ();
1484 void display_monster ( char * u
)
1488 aClient
* user
= find ( u
);
1489 Player
* ni
= user
-> stats
;
1491 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> getHP ());
1492 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> getMonster ()-> name
. c_str (), ni
-> getMonster ()-> hp
);
1493 notice ( s_GameServ
, u
, "Here are your commands:" );
1494 notice ( s_GameServ
, u
, "/msg %S attack" );
1495 notice ( s_GameServ
, u
, "/msg %S run" );
1496 notice ( s_GameServ
, u
, "What will you do?" );
1500 void display_players ( char * u
)
1503 if (!( user
= find ( u
)))
1505 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
1508 display_players ( user
);
1511 void display_players ( aClient
* user
)
1513 char * u
= user
-> getNick ();
1514 if ( is_playing ( user
) && player_fight ( user
))
1516 aClient
* battle
= user
-> stats
-> getBattle ();
1517 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> getHP ());
1518 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> getName (). c_str (), battle
-> stats
-> getHP ());
1519 notice ( s_GameServ
, u
, "Here are your commands:" );
1520 notice ( s_GameServ
, u
, "/msg %S attack" );
1521 notice ( s_GameServ
, u
, "/msg %S run" );
1522 notice ( s_GameServ
, u
, "What will you do?" );
1527 bool is_playing ( char * u
)
1530 if (!( user
= find ( u
)))
1533 return is_playing ( user
);
1536 bool is_playing ( aClient
* user
)
1542 else if (! user
-> stats
)
1546 else if (! FL_is_playing ( user
))
1550 else if ( user
-> stats
-> getClient () != user
)
1558 bool is_fighting ( char * u
)
1562 if (!( user
= find ( u
)))
1565 return is_fighting ( user
);
1568 bool is_fighting ( aClient
* user
)
1570 if (! is_playing ( user
))
1573 return player_fight ( user
) || master_fight ( user
) || user
-> stats
-> getMonster () != NULL
;
1576 bool player_fight ( char * u
)
1580 if (!( user
= find ( u
)))
1583 return player_fight ( user
);
1586 bool player_fight ( aClient
* user
)
1588 if (! is_playing ( user
))
1590 else if ( is_playing ( user
-> stats
-> getBattle ()))
1597 bool master_fight ( char * u
)
1601 if (!( user
= find ( u
)))
1604 return master_fight ( user
);
1607 bool master_fight ( aClient
* user
)
1609 if (! is_playing ( user
))
1612 return user
-> stats
-> getMaster () != NULL
;
1615 bool dragon_fight ( char * u
)
1618 if (!( user
= find ( u
)))
1621 return dragon_fight ( user
);
1624 bool dragon_fight ( aClient
* user
)
1626 if (! is_playing ( user
))
1629 return ( isDragonFight ( user
-> stats
));
1632 bool alphaNumeric ( const char * str
)
1634 int len
= strlen ( str
);
1635 for ( int x
= 0 ; x
< len
; x
++)
1637 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 ))
1643 void do_fight ( char * u
)
1648 char * nick
= strtok ( NULL
, " " );
1652 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1655 else if (!( ni
= find ( u
)))
1657 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1660 else if ( isIgnore ( ni
))
1663 log ( "Ignoring %s ." , ni
-> getNick ());
1667 else if (! is_playing ( ni
))
1669 notice ( s_GameServ
, u
, "You are not playing!" );
1673 updateTS ( ni
-> stats
);
1675 if ( ni
-> stats
-> getPlayerFights () <= 0 )
1677 ni
-> stats
-> setPlayerFights ( 0 ); // just to be safe
1678 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1679 "day. You have to wait until tomorrow!" );
1681 else if (!( battle
= findplayer ( nick
)))
1683 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1685 else if (! isAlive ( ni
-> stats
))
1687 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1689 else if (! is_playing ( battle
-> getClient ()))
1691 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1694 /* offline fighting not available yet
1695 else if (!(fight = finduser(nick)))
1697 ni->stats->battle = battle;
1698 battle->battle = ni;
1699 setYourTurn(ni->stats);
1700 clearYourTurn(battle->stats);
1702 notice(s_GameServ, u, "You decide to fight %s while they're "\
1703 "not in the realm!",
1704 battle->stats->name.c_str());
1708 else if ( stricmp ( ni
-> stats
-> getName (). c_str (), battle
-> getName (). c_str ()) == 0 )
1710 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1712 else if (! isAlive ( battle
))
1714 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1716 else if ( player_fight ( battle
-> getClient ()))
1718 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> getName (). c_str (), battle
-> getBattle ()-> stats
-> getName (). c_str ());
1720 else if ( master_fight ( battle
-> getClient ()))
1722 notice ( s_GameServ
, u
, " %s is fighting their master!" , battle
-> getName (). c_str ());
1724 else if ( is_fighting ( battle
-> getClient ()))
1726 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> getName (). c_str (), battle
-> getMonster ()-> name
. c_str ());
1728 else if (! isAdmin ( ni
) && isFairFights () && ( ni
-> stats
-> getStrength ()/ 2 - battle
-> getDefense ()) > battle
-> getHP ())
1730 notice ( s_GameServ
, u
, "Fair fighting is enabled, and you're too strong for %s !" , battle
-> getName (). c_str ());
1732 else if ( ni
-> stats
-> getLevel () - battle
-> getLevel () > maxbfightdistance
)
1734 // You can't fight someone below you by more than X level(s)
1735 // level 12 can fight level (12 - X) but not < (12 - X)
1736 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1737 battle
-> getName (). c_str ());
1739 else if ( battle
-> getLevel () - ni
-> stats
-> getLevel () > maxafightdistance
)
1741 // You can't fight someone above you by more than X level(S)
1742 // level 1 can fight level (1 + X), but not > (1 + X)
1743 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1744 "weakling!" , ni
-> stats
-> getName (). c_str ());
1748 // Set your battle pointer to the other player
1749 ni
-> stats
-> setBattle ( battle
-> getClient ());
1751 // Set the other player's battle pointer to you
1752 battle
-> setBattle ( ni
);
1754 // The initiator gets the first move (perhaps this should be 50/50)
1755 setYourTurn ( ni
-> stats
);
1756 clearYourTurn ( battle
);
1758 // Initiate Battle sequence!
1759 ni
-> stats
-> subtractPlayerFights ( 1 );
1761 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> getName (). c_str ());
1762 notice ( s_GameServ
, c_Forest
, " %s walks up and hits %s in the face! Let's see who will bite the dust." ,
1763 ni
-> stats
-> getName (). c_str (), battle
-> getName (). c_str ()); /* DrLnet - Modified by Kain*/
1765 notice ( s_GameServ
, battle
-> getClient ()-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> getName (). c_str ());
1766 notice ( s_GameServ
, battle
-> getClient ()-> getNick (), " %s gets to go first " \
1767 "because they initiated!" , ni
-> stats
-> getName (). c_str ());
1768 notice ( s_GameServ
, battle
-> getClient ()-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> getName (). c_str ());
1769 display_players ( ni
);
1773 void do_equip ( char * u
)
1777 itemContainer
* equip
;
1780 char * item
= strtok ( NULL
, " " );
1782 if (! item
|| int ( item
[ 0 ]) < 48 || int ( item
[ 0 ] > 57 ))
1784 notice ( s_GameServ
, u
, "SYNTAX: EQUIP ####" );
1785 notice ( s_GameServ
, u
, "Type /msg %S HELP EQUIP for more information." );
1788 else if (!( user
= find ( u
)))
1790 notice ( s_GameServ
, u
, "Fatal error in do_equip. Contact a(n) %S Admin" );
1793 else if ( isIgnore ( user
))
1796 log ( "Ignoring %s ." , user
-> getNick ());
1800 else if (! is_playing ( user
))
1802 notice ( s_GameServ
, u
, "You must be playing to equip weapons and armor!" );
1805 id
= stringtoint ( item
);
1806 if (! is_fighting ( user
))
1807 updateTS ( user
-> stats
);
1808 p
= user
-> stats
-> inventory
;
1811 if (!( equip
= p
-> Find ( id
)))
1815 notice ( s_GameServ
, u
, "You aren't carrying that item!" );
1817 showinventory ( user
-> stats
, user
);
1819 else if ( equip
-> getItem ()-> getType () != ARMOR
&& equip
-> getItem ()-> getType () != WEAPON
)
1821 notice ( s_GameServ
, u
, "You can't use %s like that. Try /msg %S use" , equip
-> getItem ()-> getName (). c_str ());
1826 notice ( s_GameServ
, u
, "You equip %s ." , equip
-> getItem ()-> getName (). c_str ());
1827 equip
-> use ( user
-> stats
);
1831 void do_use ( char * u
)
1836 char * item
= strtok ( NULL
, " " );
1837 char * numuse
= strtok ( NULL
, " " );
1839 itemContainer
* used
;
1841 if (! item
|| int ( item
[ 0 ]) < 48 || int ( item
[ 0 ]) > 57 || ( numuse
&& ( int ( numuse
[ 0 ]) < 48 || int ( numuse
[ 0 ]) > 57 )))
1843 notice ( s_GameServ
, u
, "SYNTAX: USE ####" );
1844 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1847 else if (!( user
= find ( u
)))
1849 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1852 else if ( isIgnore ( user
))
1855 log ( "Ignoring %s ." , user
-> getNick ());
1859 else if (! is_playing ( user
))
1861 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1864 id
= stringtoint ( item
);
1872 num
= stringtoint ( numuse
);
1875 updateTS ( user
-> stats
);
1876 p
= user
-> stats
-> inventory
;
1879 if (!( used
= p
-> Find ( id
)))
1883 notice ( s_GameServ
, u
, "You aren't carrying that item!" );
1885 showinventory ( user
-> stats
, user
);
1887 else if ( used
-> getItem ()-> getType () != POTION
)
1889 notice ( s_GameServ
, u
, "You can't use %s like that. Try /msg %S equip" , used
-> getItem ()-> getName (). c_str ());
1894 if ( num
<= 1 || is_fighting ( user
))
1896 notice ( s_GameServ
, u
, "You used %s ." , used
-> getItem ()-> getName (). c_str ());
1897 used
-> use ( user
-> stats
);
1898 if ( used
-> getUses () <= 0 )
1900 p
-> deleteItem ( used
-> getItem ());
1907 const char * name
= used
-> getItem ()-> getName (). c_str ();
1908 for ( count
= 0 ; count
< num
; count
++)
1910 if (!( used
= p
-> Find ( id
)))
1916 used
-> use ( user
-> stats
);
1917 if ( used
-> getUses () == 0 )
1919 p
-> deleteItem ( used
-> getItem ());
1923 notice ( s_GameServ
, u
, "You used %d %s 's" , count
, name
);
1927 void do_run ( char * u
)
1930 Player
* p
, * p2
= NULL
;
1932 if (!( user
= find ( u
)))
1934 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1937 else if ( isIgnore ( user
))
1940 log ( "Ignoring %s ." , user
-> getNick ());
1944 else if (! is_playing ( user
))
1946 notice ( s_GameServ
, u
, "You must be playing to run!" );
1950 updateTS ( user
-> stats
);
1954 p2
= p
-> getBattle ()-> stats
;
1956 if (! is_fighting ( user
))
1957 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1958 else if (! player_fight ( user
) && ! master_fight ( user
) && ! dragon_fight ( user
))
1960 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> getMonster ()-> name
. c_str ());
1963 else if ( player_fight ( user
) && isYourTurn ( p
))
1965 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> getName (). c_str ());
1966 notice ( s_GameServ
, p
-> getBattle ()-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> getName (). c_str ());
1967 addNews ( todaysnews
, " %s ran away from %s like a little baby!!" , p
-> getName (). c_str (), p2
-> getName (). c_str ()); /* DrLnet - edited by Kain */
1971 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1973 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> getName (). c_str ());
1975 else if ( master_fight ( user
))
1977 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> getMaster ()-> name
. c_str ());
1979 else if ( dragon_fight ( user
))
1981 notice ( s_GameServ
, u
, "You cannot run from %s ! FIGHT!" , dragon
. name
. c_str ());
1985 void end_turn ( aClient
* user
)
1987 char * nick
, * u
= user
-> getNick ();
1992 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1994 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1997 if (! player_fight ( user
) && ! master_fight ( user
))
1998 fight
= user
-> stats
-> getMonster ();
2000 fight
= user
-> stats
-> getMaster ();
2001 battle
= user
-> stats
-> getBattle ();
2003 if (! player_fight ( user
))
2006 mhit
= ( fight
-> strength
/ 2 ) + ( rand () % ( fight
-> strength
/ 2 )) - ( user
-> stats
-> getDefense ());
2011 mhit
= ( battle
-> stats
-> getStrength () / 2 ) + ( rand () % ( battle
-> stats
-> getStrength () / 2 )) - user
-> stats
-> getDefense ();
2013 if (! player_fight ( user
))
2018 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
2019 fight
-> name
. c_str (), fight
-> weapon
. c_str (), mhit
);
2022 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
. c_str ());
2024 if ( mhit
>= user
-> stats
-> getHP ())
2026 if (! master_fight ( user
))
2028 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
. c_str ());
2029 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
2030 "of your experience!" );
2031 user
-> stats
-> setGold ( 0 );
2032 user
-> stats
-> subtractExp (( long int )( user
-> stats
-> getExp () * .10 ));
2033 user
-> stats
-> setHP ( 0 );
2034 user
-> stats
-> delMonster ();
2035 clearAlive ( user
-> stats
);
2040 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
2041 "until tomorrow to try again" , user
-> stats
-> getMaster ()-> name
. c_str ());
2042 user
-> stats
-> delMonster ();
2043 user
-> stats
-> delMaster ();
2050 user
-> stats
-> subtractHP ( mhit
);
2057 clearYourTurn ( user
-> stats
);
2058 setYourTurn ( battle
-> stats
);
2059 display_players ( battle
);
2065 void do_heal ( char * u
)
2068 char * amount
= strtok ( NULL
, " " );
2073 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2076 else if (!( ni
= find ( u
)))
2078 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2081 else if ( isIgnore ( ni
))
2084 log ( "Ignoring %s ." , ni
-> getNick ());
2088 else if (! is_playing ( ni
))
2090 notice ( s_GameServ
, u
, "You aren't playing!" );
2093 else if (! isAlive ( ni
-> stats
))
2095 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
2098 else if ( is_fighting ( ni
))
2100 notice ( s_GameServ
, u
, "You can't heal in battle!" );
2103 else if ( ni
-> stats
-> getHP () >= ni
-> stats
-> getMaxHP ())
2105 notice ( s_GameServ
, u
, "You don't need healing!" );
2109 updateTS ( ni
-> stats
);
2110 if ( stricmp ( amount
, "ALL" ) == 0 )
2112 price
= ni
-> stats
-> getLevel () * 3 ;
2113 if ( ni
-> stats
-> getGold () < ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()) * price
)
2115 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
2116 ( long int ) ni
-> stats
-> getGold ()/ price
, price
);
2117 ni
-> stats
-> addHP ( ni
-> stats
-> getGold () / price
);
2118 ni
-> stats
-> setGold ( ni
-> stats
-> getGold () % price
);
2122 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2123 "per point." , price
);
2124 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
2125 ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()),
2126 ( price
* ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ())) );
2127 ni
-> stats
-> subtractGold ( price
* ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()));
2128 ni
-> stats
-> healall ();
2131 else if ( isstringnum ( amount
))
2133 num
= stringtoint ( amount
);
2134 price
= ni
-> stats
-> getLevel () * 3 ;
2135 if ( ni
-> stats
-> getGold () < price
* num
)
2137 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
2138 ( long int ) ni
-> stats
-> getGold ()/ price
);
2140 else if ( num
<= ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ())
2142 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
2144 ni
-> stats
-> addHP ( num
);
2145 ni
-> stats
-> subtractGold ( num
* price
);
2147 else if ( num
> ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ())
2149 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
2150 "per point." , price
);
2151 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
2152 ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()));
2153 ni
-> stats
-> subtractGold ( price
* ( ni
-> stats
-> getMaxHP () - ni
-> stats
-> getHP ()));
2154 ni
-> stats
-> healall ();
2157 else if ( amount
[ 0 ] == '-' )
2158 notice ( s_GameServ
, u
, "You trying to cheat?" );
2160 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
2163 int isstringnum ( char * num
)
2166 for ( x
= 0 ; x
< strlen ( num
); x
++)
2168 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
2174 long int stringtoint ( char * number
)
2176 return atol ( number
);
2179 long int pow ( int x
, int y
)
2185 if ( x
!= 0 && y
!= 0 )
2187 for ( count
= 1 ; count
<= y
- 1 ; count
++)
2197 long int chartoint ( char ch
)
2199 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
2200 return int ( ch
) - 48 ;
2207 list
< Player
*>:: iterator iter
;
2211 outfile
. open ( playerdata
);
2215 log ( "Error opening %s " , playerdata
);
2219 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2221 for ( iter
= players
[ x
]. begin (); iter
!= players
[ x
]. end (); iter
++)
2226 w
= it
-> getWeapon ();
2229 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 );
2231 // Traverse the list and write out each item ID and how many uses are left
2232 if (! it
-> inventory
-> isEmpty ())
2234 list
< itemContainer
> * myitems
;
2235 list
< itemContainer
>:: iterator item_iter
;
2236 myitems
= it
-> inventory
-> getItems ();
2238 for ( item_iter
= myitems
-> begin (); item_iter
!= myitems
-> end (); item_iter
++)
2240 outfile
<< ' ' << (* item_iter
). getItem ()-> getID () << ' ' << (* item_iter
). getUses ();
2255 infile
. open ( dragondata
);
2260 log ( "Error opening %s . Trying initialdragon.dat" , dragondata
);
2261 infile
. open ( "data/initialdragon.dat" );
2264 log ( "Error opening data/initialdragon.dat" );
2269 buf
= new char [ 1024 ];
2271 infile
. getline ( buf
, 1024 , ' \n ' );
2272 infile
. close (); // Done with the file... we have what we want
2274 dragon
. name
= strtok ( buf
, "~" );
2275 dragon
. weapon
= strtok ( NULL
, "~" );
2278 dragon
. strength
= stringtoint ( strtok ( NULL
, "~" ));
2279 dragon
. hp
= stringtoint ( strtok ( NULL
, "~" ));
2280 dragon
. defense
= stringtoint ( strtok ( NULL
, "~" ));
2281 dragon
. death
= strtok ( NULL
, "" );
2283 log ( "loaded dragon: %s " , dragon
. name
. c_str ());
2287 return save_dragon (); // Save the dragon file and return the status code :)
2294 outfile
. open ( dragondata
);
2298 log ( "Error opening %s . Exiting." , dragondata
);
2302 outfile
<< dragon
. name
. c_str () << '~' << dragon
. weapon
. c_str () << '~'
2303 << dragon
. strength
<< '~' << dragon
. hp
<< '~'
2304 << dragon
. defense
<< '~' << dragon
. death
. c_str () << " \n ^"
2317 buf
= new char [ 1024 ];
2320 infile
. open ( storeitemdata
);
2324 log ( "Error opening %s " , storeitemdata
);
2328 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2332 if ( buf
[ 0 ] != '#' && buf
[ 0 ] != ' \n ' && buf
[ 0 ] != '\0' )
2335 id
= stringtoint ( strtok ( buf
, "" ));
2336 tempItem2
= findItemByID ( id
);
2337 if ( tempItem2
== NULL
)
2339 log ( "Invalid ID in %s " , storeitemdata
);
2343 tempItem
= tempItem2
;
2344 store
. push_back ( tempItem
);
2349 log ( "Exception loading store: %s " , str
);
2361 tavernItem tempItem
;
2362 buf
= new char [ 1024 ];
2365 infile
. open ( tavernitemdata
);
2368 log ( "Error opening %s " , tavernitemdata
);
2372 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2376 if ( buf
[ 0 ] != '#' && buf
[ 0 ] != ' \n ' && buf
[ 0 ] != '\0' )
2379 id
= stringtoint ( strtok ( buf
, "~" ));
2380 level
= stringtoint ( strtok ( NULL
, "" ));
2381 tempItem2
= findItemByID ( id
);
2382 if ( tempItem2
== NULL
)
2384 log ( "Invalid ID in %s " , tavernitemdata
);
2387 tempItem
. setItem ( tempItem2
);
2388 tempItem
. setLevel ( level
);
2389 tavern
. push_back ( tempItem
);
2394 log ( "Exception loading tavern: %s " , str
);
2408 buf
= new char [ 1024 ];
2410 infile
. open ( itemdata
);
2414 log ( "Error opening %s " , itemdata
);
2418 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
2424 if ( buf
[ 0 ] != '#' && buf
[ 0 ] != ' \n ' && buf
[ 0 ] != '\0' )
2429 tempItem
= new weapon ();
2432 tempItem
= new armor ();
2435 tempItem
= new potion ();
2438 log ( "Invalid Item Type %c in %s " , buf
[ 0 ], itemdata
);
2443 if ( tempItem
-> setData ( buf
))
2445 Items
. push_back ( tempItem
);
2451 log ( "Exception loading items: %s " , str
);
2464 char * tempname
, * buf
, * password
;
2466 buf
= new char [ 100000 ];
2468 infile
. open ( playerdata
);
2472 log ( "Error opening %s " , playerdata
);
2477 for ( int x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2479 list
< Player
*>:: iterator iter
;
2481 for ( iter
= players
[ x
]. begin (); iter
!= players
[ x
]. end (); iter
++)
2483 logout ((* iter
)-> getClient ());
2489 while ( infile
. getline ( buf
, 100000 , ' \n ' ))
2491 tempname
= strtok ( buf
, " " );
2492 p
= new Player ( tempname
);
2494 p
-> setLevel ( stringtoint ( strtok ( NULL
, " " )));
2495 p
-> setExp ( stringtoint ( strtok ( NULL
, " " )));
2496 p
-> setGold ( stringtoint ( strtok ( NULL
, " " )));
2497 p
-> setBank ( stringtoint ( strtok ( NULL
, " " )));
2498 tempnum
= stringtoint ( strtok ( NULL
, " " ));
2499 p
-> setMaxHP ( stringtoint ( strtok ( NULL
, " " )));
2501 p
-> setStrength ( stringtoint ( strtok ( NULL
, " " )));
2502 p
-> setDefense ( stringtoint ( strtok ( NULL
, " " )));
2503 p
-> setForestFights ( stringtoint ( strtok ( NULL
, " " )));
2504 p
-> setPlayerFights ( stringtoint ( strtok ( NULL
, " " )));
2505 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
2509 password
= strtok ( NULL
, " " );
2510 p
-> setRawPassword ( password
);
2511 tempname
= strtok ( NULL
, " " );
2514 p
-> lastlogin
= stringtoint ( tempname
);
2516 p
-> lastlogin
= time ( NULL
);
2518 tempname
= strtok ( NULL
, " " );
2519 tempnum
= stringtoint ( tempname
);
2523 tempitem
= findItemByID ( tempnum
);
2524 p
-> setWeapon (* tempitem
);
2527 tempname
= strtok ( NULL
, " " );
2528 tempnum
= stringtoint ( tempname
);
2532 tempitem
= findItemByID ( tempnum
);
2533 p
-> setArmor (* tempitem
);
2537 unsigned long hv
= iHASH (( unsigned char *) p
-> getName (). c_str ());
2541 for ( tempname
= strtok ( NULL
, " " ); tempname
!= NULL
; tempname
= strtok ( NULL
, " " ))
2544 list
< item
*>:: iterator item_iter
;
2545 id
= stringtoint ( tempname
);
2546 tempname
= strtok ( NULL
, " " );
2547 uses
= stringtoint ( tempname
);
2549 item_iter
= Items
. begin ();
2550 while ( item_iter
!= Items
. end ())
2552 if ((* item_iter
)-> getID () == id
)
2554 // Don't sort every time you add an item or it eats CPU
2555 p
-> inventory
-> addItemNoChecks ((* item_iter
))-> setUses ( uses
);
2560 p
-> inventory
-> sort ();
2561 players
[ hv
]. push_back ( p
);
2569 bool passcmp ( const char * encrypted
, char * plaintext
)
2572 char * plaintext2
, * plainToencrypt
;
2575 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
2576 strcpy ( plaintext2
, plaintext
);
2578 salt
[ 0 ] = encrypted
[ 0 ];
2579 salt
[ 1 ] = encrypted
[ 1 ];
2582 plainToencrypt
= crypt ( plaintext2
, salt
);
2584 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
2586 delete [] plaintext2
;
2591 bool check_password ( char * name
, char * plaintext
)
2595 if (!( p
= findplayer ( name
)))
2599 return passcmp ( p
-> getPassword (). c_str (), plaintext
);
2603 void do_store ( char * u
)
2605 list
< item
*>:: iterator item_iterator
;
2607 char * cmd
= strtok ( NULL
, " " );
2608 char * num
= strtok ( NULL
, " " );
2617 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2618 notice ( s_GameServ
, u
, " \ 2 STORE SELL NUMBER\ 2 " );
2619 notice ( s_GameServ
, u
, " \ 2 STORE BUY \1f NUMBER\1f \ 2 " );
2622 else if (!( user
= find ( u
)))
2624 log ( "Fatal Error: could not find %s in client list" , u
);
2627 else if ( isIgnore ( user
))
2630 log ( "Ignoring %s ." , user
-> getNick ());
2634 else if (! is_playing ( user
))
2636 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
2639 else if ( is_fighting ( user
))
2641 notice ( s_GameServ
, u
, "You can't go to the store while fighting!" );
2644 else if (! isAlive ( user
-> stats
))
2646 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2649 updateTS ( user
-> stats
);
2651 if ( stricmp ( cmd
, "LIST" ) == 0 )
2653 if ( stricmp ( num
, "WEAPONS" ) == 0 )
2655 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2656 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2657 for ( item_iterator
= store
. begin (); item_iterator
!= store
. end (); ++ item_iterator
)
2659 if ((* item_iterator
)-> getType () == WEAPON
)
2661 space
= spaces ( strlen ((* item_iterator
)-> getName (). c_str ()), "." );
2662 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 ());
2666 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 #\ 2 ." );
2667 notice ( s_GameServ
, u
, "Where # is the weapon number from the menu above." );
2670 else if ( stricmp ( num
, "ARMOR" ) == 0 )
2672 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2673 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2674 for ( item_iterator
= store
. begin (); item_iterator
!= store
. end (); ++ item_iterator
)
2676 if ((* item_iterator
)-> getType () == ARMOR
)
2678 space
= spaces ( strlen ((* item_iterator
)-> getName (). c_str ()), "." );
2679 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 ());
2684 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy #" );
2685 notice ( s_GameServ
, u
, "Where # is the armor number from the menu above." );
2689 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2694 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY \1f #\1f \ 2 " );
2699 id
= stringtoint ( num
);
2702 if (! isstringnum ( num
))
2704 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY \1f #\1f \ 2 " );
2707 else if (!( tempItem
= findStoreItemByID ( id
)))
2709 notice ( s_GameServ
, u
, "Sorry, we don't carry that item!" );
2712 else if ( p
-> getGold () < tempItem
-> price ())
2714 notice ( s_GameServ
, u
, "You can't afford to buy %s " , tempItem
-> getName (). c_str ());
2717 else if ( p
-> inventory
-> addItem ( tempItem
))
2719 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , tempItem
-> getName (). c_str ());
2720 p
-> subtractGold ( tempItem
-> price ());
2721 notice ( s_GameServ
, u
, "Don't forget to type /msg %S equip %l d" , tempItem
-> getID ());
2725 notice ( s_GameServ
, u
, "You can't carry any more!" );
2728 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2730 itemContainer
* tempContainer
;
2732 id
= stringtoint ( num
);
2733 if (! isstringnum ( num
))
2735 notice ( s_GameServ
, u
, "SYNTAX: /msg %S store sell #" );
2738 else if (!( tempContainer
= p
-> inventory
-> Find ( id
)))
2740 notice ( s_GameServ
, u
, "You're not carrying that!" );
2743 else if ( p
-> getGold () >= 2000000000 )
2745 notice ( s_GameServ
, u
, "You have enough gold. Just hang on to it for now." );
2749 tempItem
= tempContainer
-> getItem ();
2751 notice ( s_GameServ
, u
, "Thank you for your business! We gave you %l d gold for %s !" , ( tempItem
-> price () / 2 ), tempItem
-> getName (). c_str ());
2752 p
-> addGold (( tempItem
-> price () / 2 ));
2753 p
-> inventory
-> deleteItem ( tempItem
);
2754 if ( tempItem
== p
-> getWeapon ())
2756 notice ( s_GameServ
, u
, "Since you equipped %s , you're going to have to reequip something" , tempItem
-> getName (). c_str ());
2760 else if ( tempItem
== p
-> getArmor ())
2763 notice ( s_GameServ
, u
, "Since you equipped %s , you're going to have to reequip something" , tempItem
-> getName (). c_str ());
2770 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2771 notice ( s_GameServ
, u
, " \ 2 STORE SELL #\ 2 " );
2772 notice ( s_GameServ
, u
, " \ 2 STORE BUY \1f #\1f \ 2 " );
2776 void do_inventory ( char * u
)
2780 if (!( user
= find ( u
)))
2782 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2785 else if ( isIgnore ( user
))
2788 log ( "Ignoring %s ." , user
-> getNick ());
2792 else if (! is_playing ( user
))
2794 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2797 if (! is_fighting ( user
))
2798 updateTS ( user
-> stats
);
2799 showinventory ( user
-> stats
, user
);
2802 void showinventory ( Player
* from
, aClient
* to
)
2810 nick
= to
-> getNick ();
2812 if ( from
-> inventory
-> isEmpty ())
2814 notice ( s_GameServ
, nick
, "You aren't carrying anything" );
2818 list
< itemContainer
> * items
;
2819 items
= from
-> inventory
-> getItems ();
2821 list
< itemContainer
>:: iterator item_iter
, item_iter2
;
2822 item_iter
= items
-> begin ();
2824 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> getName (). c_str ());
2826 while ( item_iter
!= items
-> end ())
2828 // Display a list of counted items so as not to show an extra line for duplicate items
2830 item_iter2
= item_iter
;
2831 while ( item_iter
!= items
-> end () && (* item_iter
) == (* item_iter2
))
2833 if ((* item_iter
) == (* item_iter2
))
2843 notice ( s_GameServ
, nick
, " %l d.) %s ( %l d)" , (* item_iter2
). getItem ()-> getID (), (* item_iter2
). getItem ()-> getName (). c_str (), count
);
2847 void do_tavern ( char * u
)
2849 char * cmd
= strtok ( NULL
, " " );
2854 if (!( user
= find ( u
)))
2856 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2859 else if ( isIgnore ( user
))
2862 log ( "Ignoring %s ." , user
-> getNick ());
2866 else if (! is_playing ( user
))
2868 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2871 else if ( is_fighting ( user
))
2873 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2877 updateTS ( user
-> stats
);
2882 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary and General Store" );
2883 notice ( s_GameServ
, u
, "Your commands:" );
2884 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2885 notice ( s_GameServ
, u
, "What'll it be?" );
2887 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2889 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2891 notice ( s_GameServ
, u
, "To buy an item, type /msg %S TAVERN BUY #" );
2893 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2896 char * chid
= strtok ( NULL
, " " );
2897 char * amount
= strtok ( NULL
, " " );
2900 amt
= stringtoint ( amount
);
2904 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY # [#]" );
2905 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 6001" );
2906 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 6001 10" );
2909 long id
= stringtoint ( chid
);
2910 tavernItem
* tempItem
;
2912 if (!( tempItem
= findTavernItemByID ( id
)) || user
-> stats
-> getLevel () < tempItem
-> getLevel ())
2914 notice ( s_GameServ
, u
, "Invalid Choice!" );
2915 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2917 notice ( s_GameServ
, u
, "To buy an item, type /msg %S TAVERN BUY #" );
2920 else if (! amount
&& user
-> stats
-> getGold () < tempItem
-> getItem ()-> price ())
2922 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2923 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2925 notice ( s_GameServ
, u
, "To buy an item, type /msg %S TAVERN BUY #" );
2927 else if ( user
-> stats
-> getGold () < amt
* tempItem
-> getItem ()-> price ())
2929 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2930 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2932 notice ( s_GameServ
, u
, "To buy an item, type /msg %S TAVERN BUY # [#]" );
2938 int amt
= stringtoint ( amount
);
2939 if ( amt
< 0 || amount
[ 0 ] == '-' )
2941 notice ( s_GameServ
, u
, "You trying to steal from me?" );
2943 else if ( user
-> stats
-> inventory
-> addItem ( tempItem
-> getItem (), amt
) == NULL
)
2945 notice ( s_GameServ
, u
, "You can't carry that many!" );
2949 notice ( s_GameServ
, u
, " %d %s 's coming right up!" , amt
, tempItem
-> getItem ()-> getName (). c_str ());
2950 user
-> stats
-> subtractGold ( tempItem
-> getItem ()-> price () * amt
);
2955 if ( user
-> stats
-> inventory
-> addItem ( tempItem
-> getItem ()) == NULL
)
2957 notice ( s_GameServ
, u
, "You can't carry any more!" );
2961 notice ( s_GameServ
, u
, "One %s coming right up!" , tempItem
-> getItem ()-> getName (). c_str ());
2962 user
-> stats
-> subtractGold ( tempItem
-> getItem ()-> price ());
2969 notice ( s_GameServ
, u
, "Improper Syntax." );
2970 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2975 void do_bank ( char * u
)
2977 char * cmd
= strtok ( NULL
, " " );
2978 char * amount
= strtok ( NULL
, " " );
2979 char * nick
= strtok ( NULL
, " " );
2984 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2986 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2987 notice ( s_GameServ
, u
, "BANK BALANCE" );
2990 else if (!( user
= find ( u
)))
2992 notice ( s_GameServ
, u
, "Fatal Error. Couldn't find your aClient. Contact a(n) %S " \
2994 log ( "Fatal Error. Couldn't find %s while executing do_bank()" , u
);
2997 else if ( isIgnore ( user
))
3000 log ( "Ignoring %s ." , user
-> getNick ());
3004 else if (! is_playing ( user
))
3006 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
3009 else if ( is_fighting ( user
))
3011 notice ( s_GameServ
, u
, "You can't go to the bank during a fight!" );
3014 updateTS ( user
-> stats
);
3015 if ( stricmp ( cmd
, "BALANCE" ) == 0 )
3020 else if (! isAlive ( user
-> stats
))
3022 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
3025 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
3027 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
3030 if ( stringtoint ( amount
) < 0 )
3032 notice ( s_GameServ
, u
, "Sorry. This bank is not licensed " \
3033 "to handle such sums of cash, noble Lord." );
3038 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
3040 if ( p
-> getBank () == 2000000000 )
3042 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
3045 else if ( stricmp ( amount
, "ALL" ) == 0 )
3047 if ( 2000000000 - p
-> getBank () < p
-> getGold ())
3049 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
3050 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> getBank ()));
3051 p
-> subtractGold (( 2000000000 - p
-> getBank ()));
3052 p
-> setBank ( 2000000000 );
3057 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> getGold ());
3058 p
-> addBank ( p
-> getGold ());
3063 else if ( stringtoint ( amount
) > p
-> getGold ())
3065 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> getGold ());
3071 if ( 2000000000 - p
-> getBank () < stringtoint ( amount
))
3073 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
3074 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> getBank ()));
3075 p
-> subtractGold (( 2000000000 - p
-> getBank ()));
3076 p
-> setBank ( 2000000000 );
3081 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
3082 p
-> addBank ( stringtoint ( amount
));
3083 p
-> subtractGold ( stringtoint ( amount
));
3088 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
3090 if ( p
-> getGold () == 2000000000 )
3092 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
3096 else if ( stricmp ( amount
, "ALL" ) == 0 )
3098 if ( 2000000000 - p
-> getGold () < p
-> getBank ())
3100 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
3101 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> getGold ()));
3102 p
-> subtractBank (( 2000000000 - p
-> getGold ()));
3103 p
-> setGold ( 2000000000 );
3108 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> getBank ());
3109 p
-> addGold ( p
-> getBank ());
3114 else if ( stringtoint ( amount
) > p
-> getBank ())
3116 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> getBank ());
3122 if ( 2000000000 - p
-> getGold () < stringtoint ( amount
))
3124 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
3125 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
3126 ( 2000000000 - p
-> getGold ()));
3127 p
-> subtractBank (( 2000000000 - p
-> getGold ()));
3128 p
-> setGold ( 2000000000 );
3133 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
3134 p
-> addGold ( stringtoint ( amount
));
3135 p
-> subtractBank ( stringtoint ( amount
));
3142 void do_dragon ( char * u
)
3146 if (!( user
= find ( u
)))
3148 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
3151 else if ( isIgnore ( user
))
3154 log ( "Ignoring %s ." , user
-> getNick ());
3158 else if (! is_playing ( user
))
3160 notice ( s_GameServ
, u
, "You must be playing to fight the dragon!" );
3163 else if ( is_fighting ( user
))
3165 notice ( s_GameServ
, u
, "You are already in a fight. How will you fight the almighty dragon!?" );
3168 else if (! isAlive ( user
-> stats
))
3170 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
3173 else if ( user
-> stats
-> getLevel () < LEVELS
)
3175 notice ( s_GameServ
, u
, "You fool! Only those strong enough " \
3176 "to vanquish any foe should DARE fight the dragon!" );
3177 notice ( s_GameServ
, u
, "To put it in terms you can understand: " \
3178 "You are too weak. You must be Level %d !" , REALLEVELS
);
3182 updateTS ( user
-> stats
);
3184 Player
* p
= user
-> stats
;
3186 notice ( s_GameServ
, u
, "You approach the dragon's lair cautiously." );
3187 notice ( s_GameServ
, u
, "The stench of sulfer fills the air as a " \
3188 "deep, red fog rolls in. The air is filled with the " \
3189 "heated mist of deadly fire from beyond the cave " \
3191 notice ( s_GameServ
, u
, "You adjust your %s , tighten your grip on " \
3192 "your %s , and venture into the hot, dark cave. " \
3193 "You are surprised at the angle of descent as you climb " \
3194 "lower and lower, deeper into the dragon's den." ,
3195 ( p
-> getArmor () ? p
-> getArmor ()-> getName (). c_str () : "Fists" ), ( p
-> getWeapon () ? p
-> getWeapon ()-> getName (). c_str () : "Birthday Suit" ));
3196 notice ( s_GameServ
, u
, "You come to the end of the cave to find " \
3197 "a tooth. It is a large tooth... bigger than your torso." \
3198 " Suddenly the darkness lifts from the gleam of an eye " \
3199 " staring into your soul! The eye is large... HUGE!" );
3200 notice ( s_GameServ
, u
, "Just then you notice the eye begin to " \
3201 "glare orange! The tooth is moving... but it is still too " \
3202 "dark for you to make out.... THE DRAGON! You see it!" );
3203 p
-> setMonster (& dragon
);
3208 void do_master ( char * u
)
3213 if (!( user
= find ( u
)))
3215 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
3218 else if ( isIgnore ( user
))
3221 log ( "Ignoring %s ." , user
-> getNick ());
3225 else if (! is_playing ( user
))
3227 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
3230 else if ( is_fighting ( user
))
3232 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
3235 else if (! isAlive ( user
-> stats
))
3237 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
3241 updateTS ( user
-> stats
);
3243 char * cmd
= strtok ( NULL
, " " );
3244 Player
* p
= user
-> stats
;
3249 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
3255 switch ( p
-> getLevel ())
3292 need
= p
-> getExp () + 1 ;
3293 notice ( s_GameServ
, u
, "You are at level %d . You are the master. What's left? The DRAGON!" , REALLEVELS
);
3297 need
= p
-> getExp () + 1 ; // Unknown level... don't let them fight a fake master!
3303 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
3307 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
3309 if ( p
-> getExp () >= need
)
3315 notice ( s_GameServ
, u
, "You are not worthy of fighting %s ! You need %l d more experience." ,
3316 levels
[ p
-> getLevel () - 1 ]. master
. name
. c_str (), ( need
- p
-> getExp ()));
3319 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
3321 if ( p
-> getExp () >= need
)
3322 notice ( s_GameServ
, u
, " %s looks you up and down and decides you are more ready than you will ever be." ,
3323 levels
[ p
-> getLevel () - 1 ]. master
. name
. c_str ());
3325 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" ,
3326 levels
[ p
-> getLevel () - 1 ]. master
. name
. c_str (), p
-> getName (). c_str ());
3332 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
3336 void see_master ( char * u
)
3340 if (!( user
= find ( u
)))
3342 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
3346 if (! is_fighting ( user
) && is_playing ( user
))
3348 Player
* p
= user
-> stats
;
3349 p
-> setMyMaster (& levels
[ p
-> getLevel () - 1 ]. master
);
3350 p
-> setMonster (& levels
[ p
-> getLevel () - 1 ]. master
);
3351 display_monster ( u
); // Since master is the same structure, use this function
3355 void showTavern ( aClient
* user
)
3358 list
< tavernItem
>:: iterator item_iterator
;
3366 item_iterator
= tavern
. begin ();
3369 notice ( s_GameServ
, user
-> getNick (), "Tavern is empty" );
3373 while ( item_iterator
!= tavern
. end ())
3375 if ( p
-> getLevel () < (* item_iterator
). getLevel ())
3380 tempItem
= (* item_iterator
). getItem ();
3381 notice ( s_GameServ
, user
-> getNick (), " %d . %s for %l d gold" , tempItem
-> getID (), tempItem
-> getName (). c_str (), tempItem
-> price ());
3386 void showBankBalance ( const char * u
)
3391 if (!( user
= find ( u
)))
3399 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> getBank (), p
-> getGold ());
3404 list
< Player
*>:: iterator iter
;
3405 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3407 for ( iter
= players
[ x
]. begin (); iter
!= players
[ x
]. end (); iter
++)
3415 list
< Player
*>:: iterator iter
;
3416 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3418 for ( iter
= players
[ x
]. begin (); iter
!= players
[ x
]. end (); iter
++)
3425 void rollover ( Player
* p
)
3430 p
-> addForestFights ( numrolloverfights
);
3432 if ( p
-> getForestFights () > maxforestfights
)
3433 p
-> setForestFights ( maxforestfights
);
3436 void refresh ( Player
* p
)
3441 if ( p
-> getHP () < p
-> getMaxHP ())
3443 if ( p
-> getForestFights () < forestfights
)
3445 p
-> setForestFights ( forestfights
);
3448 p
-> setPlayerFights ( 3 );
3453 void do_refresh ( char * u
)
3455 char * name
= strtok ( NULL
, " " );
3459 if (!( user
= find ( u
)))
3461 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3462 log ( "Error: aClient not found: %s " , u
);
3465 else if ( isIgnore ( user
))
3468 log ( "Ignoring %s ." , user
-> getNick ());
3472 else if (! isAdmin ( user
))
3474 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3479 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
3482 else if ( stricmp ( name
, "ALL" ) == 0 )
3484 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
3487 else if (( p
= findplayer ( name
)))
3489 notice ( s_GameServ
, u
, "Refreshing %s ." , p
-> getName (). c_str ());
3494 notice ( s_GameServ
, u
, "Player %s not found." , name
);
3502 list
< Player
*>:: iterator iter
;
3503 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
3505 for ( iter
= players
[ x
]. begin (); iter
!= players
[ x
]. end (); iter
++)
3512 void reset ( Player
* p
)
3520 // Add the stick and clothes
3521 tempItem
= findItemByID ( 3001 );
3522 p
-> inventory
-> addItem ((* Items
. begin ()))-> use ( p
); // Add the stick
3523 p
-> inventory
-> addItem ( tempItem
)-> use ( p
); // Add Clothes
3526 void updateTS ( Player
* p
)
3532 log ( "Old timestamp for %s : %l d" , p
-> getName (). c_str (), p
-> lastcommand
);
3534 p
-> lastcommand
= time ( NULL
);
3536 log ( "New timestamp for %s : %l d" , p
-> getName (). c_str (), p
-> lastcommand
);
3538 PF_cleartimedout ( p
);
3542 bool timedOut ( Player
* p
)
3546 else if ( p
-> lastcommand
== 0 )
3550 if (( time ( NULL
) - p
-> lastcommand
) >= maxidletime
)
3557 void timeOutEvent ( Player
* p
)
3559 if (! p
|| ! is_playing ( p
-> getClient ())) // then they're not playing
3562 char * nick
= p
-> getClient ()-> getNick ();
3564 if ( player_fight ( p
-> getClient ()) && isYourTurn ( p
))
3566 // Check to see if they were the idler or if it was the other
3568 if (! PF_timedout ( p
-> getBattle ()-> stats
))
3570 // This person's last command was given earlier,
3571 // so this person is the idler
3572 notice ( s_GameServ
, nick
, "You timed out " \
3573 "during a fight. You lose your turn!" );
3574 notice ( s_GameServ
, p
-> getBattle ()-> getNick (),
3575 " %s hesitated for too long. Your move." , p
-> getName (). c_str ());
3577 setYourTurn ( p
-> getBattle ()-> stats
);
3579 // Update the TS for both players to give them another
3580 // Chance to wake up, but if the other player doesn't
3581 // Attack now, they both get logged out.
3584 display_players ( p
-> getBattle ());
3589 notice ( s_GameServ
, p
-> getBattle ()-> getNick (),
3590 "You and %s timed out at the same time." \
3591 " Don't fight if you're just going to " \
3592 "sit there!" , p
-> getName (). c_str ());
3593 notice ( s_GameServ
, p
-> getClient ()-> getNick (),
3594 "You and %s timed out at the same time." \
3595 " Don't fight if you're just going to " \
3596 "sit there!" , p
-> getBattle ()-> stats
-> getName (). c_str ());
3597 logout ( p
-> getBattle ());
3598 logout ( p
-> getClient ());
3602 else if (! player_fight ( p
-> getClient ()))
3604 if ( isAlive ( p
) && p
-> getGold () > 0 )
3606 // Place fun stuff here :)
3607 int randnum
= 1 + rand () % 100 ; // 1-100
3608 #define GSN(s) notice(s_GameServ, nick, s)
3609 #define GSN2(s, f) notice(s_GameServ, nick, s, f)
3613 // 35-100% of your gold goes pffft - kain
3614 int stolen
= ( 35 + ( rand () % 66 )) * ( p
-> getGold () / 100 );
3616 GSN ( "You stop for a moment to rest on the " \
3617 "street corner. All of a sudden, you " \
3618 "are ambushed from all sides by a hoarde " \
3619 "of knife wielding thugs." );
3620 GSN2 ( "The thugs beat you into utter submission " \
3621 "and steal %l d gold from you!" , stolen
);
3622 p
-> subtractGold ( stolen
);
3624 else if ( randnum
>= 50 && randnum
< 75 )
3626 // 25-65% of your gold goes pffft - kain
3627 int stolen
= ( 25 + ( rand () % 41 )) * ( p
-> getGold () / 100 );
3628 GSN ( "While dilly dallying around, you lose " \
3629 "your sense of time. Little did you know, " \
3630 "but thieves lifted your gold while you " \
3631 "weren't watching." );
3632 GSN2 ( "Better luck next time... you lose %d gold" , stolen
);
3633 p
-> subtractGold ( stolen
);
3635 else if ( randnum
>= 75 )
3637 // 25-75% of your gold goes pffft - kain
3638 int stolen
= ( 25 + ( rand () % 51 )) * ( p
-> getGold () / 100 );
3639 GSN ( "Good grief! A gaggle of gooey green ghostlike " \
3640 "goblins grabbed your gold!" );
3641 GSN2 ( "They stole %d gold from you!" , stolen
);
3642 p
-> subtractGold ( stolen
);
3646 // Always log out the user
3647 logout ( p
-> getClient ());
3651 void do_reset ( char * u
)
3653 char * nick
= strtok ( NULL
, " " );
3657 if (!( user
= find ( u
)))
3659 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
3660 log ( "Error: aClient not found: %s " , u
);
3663 else if (! isAdmin ( user
))
3665 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
3671 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
3673 else if ( stricmp ( nick
, "ALL" ) == 0 )
3675 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
3678 else if (!( p
= findplayer ( nick
)))
3680 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
3684 notice ( s_GameServ
, u
, "Resetting %s ." , p
-> getName (). c_str ());
3689 void do_help ( char * u
)
3691 char * cmd
= strtok ( NULL
, " " );
3693 display_help ( u
, cmd
);
3696 void display_help ( char * u
, char * file
)
3703 infile
. open ( "helpfiles/help" );
3706 log ( "Error opening helpfiles/help" );
3707 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
3710 buf
= new char [ 1024 ];
3711 while ( infile
. getline ( buf
, 1024 ))
3713 // Written this way, it will process %S in the helpfiles
3714 // Instead of notice(s_GameServ, u, "%s", buf);
3715 notice ( s_GameServ
, u
, buf
);
3719 aClient
* user
= find ( u
);
3720 if ( user
&& isAdmin ( user
))
3721 display_help ( u
, "admin_commands" );
3726 filename
= new char [ strlen ( file
) + 11 ];
3727 strcpy ( filename
, "helpfiles/" );
3728 strcat ( filename
, file
);
3730 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
3731 filename
[ x
] = tolower ( filename
[ x
]);
3733 infile
. open ( filename
);
3737 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
3740 buf
= new char [ 1024 ];
3741 while ( infile
. getline ( buf
, 1024 ))
3743 // Written this way, it will process %S in the helpfiles
3744 // Instead of notice(s_GameServ, u, "%s", buf);
3745 notice ( s_GameServ
, u
, buf
);
3752 void do_admin ( char * u
)
3755 char * pass
= strtok ( NULL
, " " );
3757 if (!( user
= find ( u
)))
3759 log ( "Error: aClient not found: %s " , u
);
3760 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
3766 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
3772 notice ( s_GameServ
, u
, "You already have administrator privledges." );
3775 else if ( strcmp ( pass
, adminpass
) == 0 )
3777 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
3780 log ( " %s became an administrator." , user
-> getRealNick ());
3782 log ( " %s became an administrator." , user
-> getNick ());
3787 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
3795 filename
= new char [ 256 ];
3797 for ( int x
= 1 ; x
<= LEVELS
; x
++)
3799 sprintf ( filename
, "data/levels/level %d .dat" , x
);
3800 if ( levels
[ x
- 1 ]. loadLevel ( filename
) == false )
3811 bool load_monsters ()
3816 buf
= new char [ 2048 ];
3818 for ( int level
= 1 ; level
<= LEVELS
; level
++)
3820 filename
= new char [ 256 ];
3821 sprintf ( filename
, "data/monsters/level %d .dat" , level
);
3822 infile
. open ( filename
);
3826 log ( "Error opening %s " , filename
);
3833 log ( "Loading monsters from %s " , filename
);
3836 while ( infile
. getline ( buf
, 2048 ))
3840 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
3845 temp
-> name
= strtok ( buf
, "~" );
3846 temp
-> weapon
= strtok ( NULL
, "~" );
3847 temp
-> death
= strtok ( NULL
, "~" );
3849 levels
[ level
- 1 ]. monsters
. push_back ( temp
);
3859 item
* findItemByID ( int id
)
3861 list
< item
*>:: iterator item_iterator
;
3863 item_iterator
= Items
. begin ();
3865 while ( item_iterator
!= Items
. end ())
3867 if ((* item_iterator
)-> getID () == id
)
3869 return (* item_iterator
);
3876 item
* findStoreItemByID ( int id
)
3878 list
< item
*>:: iterator item_iterator
;
3880 item_iterator
= store
. begin ();
3882 while ( item_iterator
!= store
. end ())
3884 if ((* item_iterator
)-> getID () == id
)
3886 return (* item_iterator
);
3893 tavernItem
* findTavernItemByID ( int id
)
3895 list
< tavernItem
>:: iterator item_iterator
;
3897 item_iterator
= tavern
. begin ();
3899 while ( item_iterator
!= tavern
. end ())
3901 if ((* item_iterator
). getItem ()-> getID () == id
)
3903 return &(* item_iterator
);