]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
15 #if defined(HAVE_CRYPT_H)
19 #elif defined(HAVE_UNISTD_H)
25 // this will be hash.cpp start
27 unsigned long HASH ( const unsigned char * name
, int size_of_table
);
28 List
< aClient
> players
[ U_TABLE_SIZE
];
29 // this will be hash.cpp end
32 Monster
* monsters
[ LEVELS
][ MONSTERS
]; // Monsters per level. Total = MONSTERS * LEVELS
33 Monster boss
; // The boss monster
35 Monster
* masters
[ LEVELS
]; // A master for each level
43 char * strtok ( char * str
, const char * delim
);
46 int stricmp ( const char * s1
, const char * s2
);
47 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
50 /********** Password functions **********/
52 bool passcmp ( char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
54 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
56 /********** Password functions **********/
59 /********** GameServ Booleans **********/
62 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
63 bool is_playing ( aClient
* user
);
65 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
66 bool is_fighting ( aClient
* user
);
68 bool player_fight ( char * u
); // True if the player is fighting another player.
69 bool player_fight ( aClient
* user
);
71 bool master_fight ( char * u
); // True if the player is fighting their master.
72 bool master_fight ( aClient
* user
);
74 /********** GameServ Booleans **********/
76 void display_help ( char * u
, char * file
= NULL
);
77 void display_monster ( char * u
);
78 void display_players ( char * u
);
79 void display_players ( aClient
* user
);
80 long int chartoint ( char ch
);
81 int isstringnum ( char * num
);
82 long int pow ( int x
, int y
);
83 long int stringtoint ( char * number
);
85 char * spaces ( int len
, char * seperator
);
86 void refresh ( Player
* p
);
88 void reset ( Player
* p
);
92 void delete_monsters ();
93 void delete_masters ();
95 void do_admin ( char * u
);
96 void do_attack ( char * u
);
97 void do_bank ( char * u
);
98 void do_fight ( char * u
);
99 void do_heal ( char * u
);
100 void do_help ( char * u
);
101 void do_identify ( char * u
);
102 void do_inventory ( char * u
);
103 void do_refresh ( char * u
);
104 void do_register ( char * u
);
105 void do_list ( char * u
);
106 void do_logout ( char * u
);
107 void do_master ( char * u
);
108 void do_play ( char * u
);
109 void do_quitg ( char * u
);
110 void do_reset ( char * u
);
111 void do_run ( char * u
);
112 void do_stats ( char * u
);
113 void do_store ( char * u
);
114 void do_tavern ( char * u
);
115 void do_use ( char * u
);
116 void see_master ( char * u
);
118 void logout ( aClient
* user
);
119 void showstats ( const char * u
, const char * nick
);
120 void showinventory ( aClient
* from
, aClient
* to
);
121 void showBankBalance ( const char * u
);
122 void end_turn ( aClient
* user
);
125 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
126 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
127 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
128 "Light Saber" , "Masamune" , "Mystical Sword" };
130 char * armors
[ WNA
] = { "Nothing" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
131 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
132 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
133 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
135 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
136 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
137 int webonus
[ WNA
] = { 1 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
138 int arbonus
[ WNA
] = { 1 , 2 , 4 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
140 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
141 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
142 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
144 void gameserv ( char * source
, char * buf
)
147 cmd
= strtok ( buf
, " " );
150 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
154 cmd
++; // Get rid of that : at the beginning of the :text (command)
157 log ( "Source: %s Command: %s " , source
, cmd
);
165 int curday
= tm
-> tm_mday
;
171 save_day (); // here i come to save the day!
174 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
177 ts
= strtok ( NULL
, "\1" );
178 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
179 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
180 notice ( s_GameServ
, source
, "\1VERSION %s %s \1" , PACKAGE
, VERSION
);
181 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
182 cmd
= strtok ( NULL
, " " );
185 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
189 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
191 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
193 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
195 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
197 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
199 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
200 do_inventory ( source
);
201 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
203 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
205 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
207 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
209 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
211 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
213 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
215 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
217 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
219 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
221 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
223 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
225 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
227 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
230 if (!( user
= find ( source
)))
232 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
233 log ( "Error: aClient not found: %s " , source
);
235 else if (! isAdmin ( user
))
237 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
243 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
245 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
249 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
252 if (!( user
= find ( source
)))
254 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
255 log ( "Error: aClient not found: %s " , source
);
257 else if (! isAdmin ( user
))
259 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
265 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
268 if (!( user
= find ( source
)))
270 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
271 log ( "Error: aClient not found: %s " , source
);
273 else if (! isAdmin ( user
))
275 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
279 char * cmd2
= strtok ( NULL
, " " );
282 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
285 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
287 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
291 display_help ( source
, cmd
);
294 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
297 if (!( user
= find ( source
)))
299 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
300 log ( "Error: aClient not found: %s " , source
);
302 else if (! isAdmin ( user
))
304 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
308 char * rest
= strtok ( NULL
, "" );
313 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
316 source
--; // Bring the ':' back so we don't leak memory
317 cmd
--; // Same thing :)
320 int stricmp ( const char * s1
, const char * s2
)
324 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
330 if ( c
< tolower (* s2
))
335 void showstats ( const char * u
, const char * nick
)
337 aClient
* ni
, * sender
= find ( u
);
343 if (!( ni
= findplayer ( nick
)))
345 notice ( s_GameServ
, u
, " %s not found" , nick
);
349 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
351 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
352 space
= spaces ( strlen ( buf
), " " );
353 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
357 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
358 space
= spaces ( strlen ( buf
), " " );
359 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
362 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
365 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
366 space
= spaces ( strlen ( buf
), " " );
367 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
368 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
371 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
372 space
= spaces ( strlen ( buf
), " " );
373 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
374 weapons
[ ni
-> stats
-> weapon
]);
377 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
378 space
= spaces ( strlen ( buf
), " " );
379 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
384 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
389 char * spaces ( int len
, char * seperator
)
392 final
= new char [ 30 ];
394 strcpy ( final
, seperator
);
395 for ( y
= 0 ; y
< 30 - len
; y
++)
396 strcat ( final
, seperator
);
400 void raw ( const char * fmt
, ...)
405 input
= new char [ 1024 ];
407 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
413 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
414 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
415 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
418 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
423 sprintf ( input
, " %s%c " , input
, * t
);
428 log ( "Input: %s " , input
);
431 sprintf ( input
, " %s%s " , input
, " \r\n " );
432 sock_puts ( sock
, input
);
436 /* Send a NOTICE from the given source to the given nick. */
438 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
446 input
= new char [ 1024 ];
453 sprintf ( input
, ": %s NOTICE %s :" , source
, dest
);
455 sprintf ( input
, " %s O %s :" , gsnum
, dest
);
463 sprintf ( input
, ": %s NOTICE %s :" , source
, dest
);
465 sprintf ( input
, " %s O %s :" , gsnum
, dest
);
474 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
475 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
476 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
479 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
484 sprintf ( input
, " %s%c " , input
, * t
);
489 log ( "Input: %s " , input
);
491 sprintf ( input
, " %s%s " , input
, " \r\n " );
492 sock_puts ( sock
, input
);
498 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
504 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
505 if ( c
== 0 || -- len
== 0 )
510 if ( c
< tolower (* s2
))
516 char * strtok ( char * str
, const char * delim
)
518 static char * current
= NULL
;
525 current
+= strspn ( current
, delim
);
526 ret
= * current
? current
: NULL
;
527 current
+= strcspn ( current
, delim
);
536 void do_list ( char * u
)
538 ListNode
< aClient
> * temp
;
540 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
542 temp
= players
[ x
]. First ();
543 if (! players
[ x
]. isEmpty ())
547 notice ( s_GameServ
, u
, "People Playing:" );
553 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
554 temp
-> getData ()-> stats
-> name
);
556 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
557 temp
-> getData ()-> stats
-> name
);
565 notice ( s_GameServ
, u
, "No one is playing" );
567 notice ( s_GameServ
, u
, "End of List" );
571 void do_logout ( char * u
)
574 if (!( user
= find ( u
)))
576 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
577 "Buf: %s LOGOUT" , u
);
578 log ( "Could not find aClient Buf: %s LOGOUT" ,
581 else if (! is_playing ( user
))
583 notice ( s_GameServ
, u
, "You're not logged in!" );
585 else if ( is_fighting ( user
))
587 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
591 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
595 void logout ( aClient
* user
)
597 if ( is_playing ( user
))
599 ListNode
< aClient
> * it
;
601 unsigned long hv
= HASH (( unsigned char *) user
-> stats
-> name
,
603 it
= players
[ hv
]. Find ( user
);
606 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
607 " %S Admin. Cannot find you in the players list." );
608 log ( "Error on logout(). Can't find %s in the players list" ,
619 temp
-> stats
= new Player
;
620 temp
-> stats
-> setData ( user
-> stats
);
621 user
-> stats
-> client
= NULL
;
623 if ( player_fight ( user
))
624 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
628 temp
-> stats
-> client
= NULL
;
630 temp
-> setRealNick ( "!NULL!" );
632 temp
-> setNick ( "!NULL!" );
636 log ( "Logged out player %s " ,
646 void do_register ( char * u
)
648 char * password
, * name
;
650 name
= strtok ( NULL
, " " );
651 password
= strtok ( NULL
, " " );
653 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
656 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
657 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
662 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
666 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
668 else if (( user
= findplayer ( name
)))
670 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
671 notice ( s_GameServ
, u
, "Choose another name!" );
673 else if (( user
= find ( u
)))
676 if (! user
-> stats
&& ! p
)
678 user
-> stats
= new Player ( user
);
679 user
-> stats
-> client
= user
; // Set the backwards pointer
680 strcpy ( user
-> stats
-> password
, crypt ( password
, salt
));
681 strcpy ( user
-> stats
-> name
, name
);
682 unsigned long hv
= HASH (( unsigned char *) name
, U_TABLE_SIZE
);
683 players
[ hv
]. insertAtBack ( user
);
684 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
685 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
686 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
690 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
695 void do_identify ( char * u
)
697 char * password
, * name
;
699 name
= strtok ( NULL
, " " );
700 password
= strtok ( NULL
, " " );
702 if (! password
|| ! name
)
704 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
708 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
709 log ( "Error: aClient not found: %s " , u
);
711 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
712 notice ( s_GameServ
, u
, "Player %s not found" , name
);
713 else if ( is_playing ( user
))
715 notice ( s_GameServ
, u
, "You are already playing!" );
717 else if ( p
-> stats
-> client
!= NULL
&& ! isAdmin ( user
))
719 notice ( s_GameServ
, u
, "That player has already identified." );
721 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
723 notice ( s_GameServ
, u
, "Password incorrect" );
726 ListNode
< aClient
> * temp
;
727 unsigned long hv
= HASH (( unsigned char *) p
-> stats
-> name
,
729 temp
= players
[ hv
]. Find ( p
);
732 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
736 user
-> stats
= new Player ( p
-> stats
-> name
);
738 log ( "Setting data for identified" );
740 user
-> stats
-> setData ( p
-> stats
);
743 log ( "Player Identified" );
747 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
751 void do_stats ( char * u
)
756 nick
= strtok ( NULL
, " " );
760 if (!( user
= find ( u
)))
762 notice ( s_GameServ
, u
, "Fatal Error in do_stats(). Contact a %S admin for help!" );
763 log ( "Error: aClient not found: %s " , u
);
766 else if (! is_playing ( user
))
768 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
772 showstats ( u
, user
-> stats
-> name
);
780 log ( "Calling delete_masters()" );
786 log ( "Initializing masters" );
789 for ( int x
= 0 ; x
< LEVELS
; x
++)
790 masters
[ x
] = new Monster
;
792 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
793 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
794 masters
[ 0 ]-> strength
= 15 ;
795 masters
[ 0 ]-> gold
= 0 ;
797 masters
[ 0 ]-> maxhp
= 30 ;
799 strcpy ( masters
[ 0 ]-> death
, "You have done well my student, but the road is long. Use your new strength with humility and honor as you progress in levels!" );
801 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
802 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
803 masters
[ 1 ]-> strength
= 30 ;
804 masters
[ 1 ]-> gold
= 0 ;
806 masters
[ 1 ]-> maxhp
= 40 ;
808 strcpy ( masters
[ 1 ]-> death
, "You try to make out what Master Chang is saying, but the only thing you catch is something about a grasshopper." );
810 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
811 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
812 masters
[ 2 ]-> strength
= 85 ;
813 masters
[ 2 ]-> gold
= 0 ;
815 masters
[ 2 ]-> maxhp
= 70 ;
817 strcpy ( masters
[ 2 ]-> death
, "Be strong, and keep your goals in site. Drink milk, and don't do drugs. One day you may be fighting next to me as a Texas Ranger YEEHAW!" );
820 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
821 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
822 masters
[ 3 ]-> strength
= 120 ;
823 masters
[ 3 ]-> gold
= 0 ;
825 masters
[ 3 ]-> maxhp
= 120 ;
826 masters
[ 3 ]-> hp
= 120 ;
827 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
829 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
830 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
831 masters
[ 4 ]-> strength
= 135 ;
832 masters
[ 4 ]-> gold
= 0 ;
834 masters
[ 4 ]-> maxhp
= 200 ;
835 masters
[ 4 ]-> hp
= 200 ;
836 strcpy ( masters
[ 4 ]-> death
, "I like to let people talk who like to talk... it's easier to find out how full of it they really are!" );
838 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
839 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
840 masters
[ 5 ]-> strength
= 160 ;
841 masters
[ 5 ]-> gold
= 0 ;
843 masters
[ 5 ]-> maxhp
= 400 ;
844 masters
[ 5 ]-> hp
= 400 ;
845 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
848 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
849 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
850 masters
[ 6 ]-> strength
= 185 ;
851 masters
[ 6 ]-> gold
= 0 ;
853 masters
[ 6 ]-> maxhp
= 600 ;
854 masters
[ 6 ]-> hp
= 600 ;
855 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
857 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
858 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
859 masters
[ 7 ]-> strength
= 210 ;
860 masters
[ 7 ]-> gold
= 0 ;
862 masters
[ 7 ]-> maxhp
= 800 ;
863 masters
[ 7 ]-> hp
= 800 ;
864 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
867 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
868 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
869 masters
[ 8 ]-> strength
= 275 ;
870 masters
[ 8 ]-> gold
= 0 ;
872 masters
[ 8 ]-> maxhp
= 1200 ;
873 masters
[ 8 ]-> hp
= 1200 ;
874 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
876 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
877 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
878 masters
[ 9 ]-> strength
= 360 ;
879 masters
[ 9 ]-> gold
= 0 ;
881 masters
[ 9 ]-> maxhp
= 1800 ;
882 masters
[ 9 ]-> hp
= 1800 ;
883 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
885 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
886 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
887 masters
[ 10 ]-> strength
= 575 ;
888 masters
[ 10 ]-> gold
= 0 ;
889 masters
[ 10 ]-> exp
= 0 ;
890 masters
[ 10 ]-> maxhp
= 2500 ;
891 masters
[ 10 ]-> hp
= 2500 ;
892 strcpy ( masters
[ 10 ]-> death
, "You must learn to concentrate. It is like a finger pointing away to the moon... DONT concentrate on the finger, or you will miss all the heavenly glory." );
898 log ( "Calling delete_monsters" );
903 for ( int x
= 0 ; x
< LEVELS
; x
++)
904 for ( int y
= 0 ; y
< MONSTERS
; y
++)
905 monsters
[ x
][ y
] = new Monster ();
908 void delete_monsters ()
910 for ( int x
= 0 ; x
< LEVELS
; x
++)
911 for ( int y
= 0 ; y
< MONSTERS
; y
++)
913 delete monsters
[ x
][ y
];
916 void delete_masters ()
918 for ( int x
= 0 ; x
< LEVELS
; x
++)
923 void display_monster ( char * u
)
927 aClient
* user
= find ( u
);
928 Player
* ni
= user
-> stats
;
930 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
931 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
932 notice ( s_GameServ
, u
, "Here are your commands:" );
933 notice ( s_GameServ
, u
, "/msg %S attack" );
934 notice ( s_GameServ
, u
, "/msg %S run" );
935 notice ( s_GameServ
, u
, "What will you do?" );
939 void display_players ( char * u
)
942 if (!( user
= find ( u
)))
944 log ( "Fatal error in display_players(): Couldn't find %s " , u
);
947 display_players ( user
);
950 void display_players ( aClient
* user
)
952 char * u
= user
-> getNick ();
953 if ( is_playing ( user
) && player_fight ( user
))
955 aClient
* battle
= user
-> stats
-> battle
;
956 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
957 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
958 notice ( s_GameServ
, u
, "Here are your commands:" );
959 notice ( s_GameServ
, u
, "/msg %S attack" );
960 notice ( s_GameServ
, u
, "/msg %S run" );
961 notice ( s_GameServ
, u
, "What will you do?" );
966 bool is_playing ( char * u
)
969 if (!( user
= find ( u
)))
975 return user
-> stats
!= NULL
;
979 bool is_playing ( aClient
* user
)
981 return user
-> stats
!= NULL
&& ( stricmp ( user
-> getNick (), "!NULL!" ) != 0 );
984 bool is_fighting ( char * u
)
988 if (!( user
= find ( u
)))
992 else if ( user
-> stats
)
994 return user
-> stats
-> fight
!= NULL
|| user
-> stats
-> battle
!= NULL
995 || user
-> stats
-> master
!= NULL
;
1000 bool is_fighting ( aClient
* user
)
1002 if (! is_playing ( user
))
1005 return ( user
-> stats
-> fight
!= NULL
|| user
-> stats
-> battle
!= NULL
|| user
-> stats
-> master
!= NULL
);
1008 bool player_fight ( char * u
)
1012 if (!( user
= find ( u
)))
1014 else if ( user
-> stats
)
1015 return user
-> stats
-> battle
!= NULL
;
1019 bool player_fight ( aClient
* user
)
1021 if (! is_fighting ( user
))
1024 return user
-> stats
-> battle
!= NULL
;
1027 bool master_fight ( char * u
)
1031 if (!( user
= find ( u
)))
1033 else if ( user
-> stats
)
1034 return user
-> stats
-> master
!= NULL
;
1038 bool master_fight ( aClient
* user
)
1040 if (! is_playing ( user
))
1043 return user
-> stats
-> master
!= NULL
;
1046 void do_fight ( char * u
)
1048 aClient
* ni
, * battle
;
1050 char * nick
= strtok ( NULL
, " " );
1054 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1056 else if (!( ni
= find ( u
)))
1058 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1060 else if (! is_playing ( ni
))
1062 notice ( s_GameServ
, u
, "You are not playing!" );
1064 else if ( ni
-> stats
-> player_fights
<= 0 )
1066 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1067 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1068 "day. You have to wait until tomorrow!" );
1070 else if (!( battle
= findplayer ( nick
)))
1072 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1074 else if (! is_playing ( battle
))
1076 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1079 * Offline fighting not implemented yet.
1080 * else if (!(fight = finduser(nick)))
1082 * ni->stats->battle = battle;
1083 * battle->battle = ni;
1085 * battle->yourturn = 0;
1086 * notice(s_GameServ, u, "You decide to fight %s while they're not online!",
1087 * battle->stats->name);
1088 * display_players(u);
1091 else if (! isAlive ( ni
-> stats
))
1093 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1095 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1097 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1099 else if (! isAlive ( battle
-> stats
))
1101 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1103 else if ( player_fight ( battle
))
1105 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1107 else if ( is_fighting ( battle
))
1109 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1111 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1113 // You can't fight someone below you by more than X level(s)
1114 // level 12 can fight level (12 - X) but not < (12 - X)
1115 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1116 battle
-> stats
-> level
);
1118 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1120 // You can't fight someone above you by more than X level(S)
1121 // level 1 can fight level (1 + X), but not > (1 + X)
1122 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1123 "weakling!" , ni
-> stats
-> name
);
1127 // Set your battle pointer to the other player
1128 ni
-> stats
-> battle
= battle
;
1130 // Set the other player's battle pointer to you
1131 battle
-> stats
-> battle
= ni
;
1133 // The initiator gets the first move (perhaps this should be 50/50)
1134 setYourTurn ( ni
-> stats
);
1135 clearYourTurn ( battle
-> stats
);
1137 // Initiate Battle sequence!
1138 ni
-> stats
-> player_fights
-= 1 ;
1140 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1141 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1142 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1143 "because they initiated!" , ni
-> stats
-> name
);
1144 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1145 display_players ( ni
);
1148 void do_use ( char * u
)
1153 char * item
= strtok ( NULL
, " " );
1157 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1158 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1161 else if (!( user
= find ( u
)))
1163 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1166 else if (! is_playing ( user
))
1168 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1172 p
= & user
-> stats
-> inventory
;
1174 if ( stricmp ( item
, "HEALTH" ) == 0 )
1176 if ( p
-> Healing () <= 0 )
1178 notice ( s_GameServ
, u
, "You are out of Health Potions!" );
1181 int oldhealth
= user
-> stats
-> hp
;
1182 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1183 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1184 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1185 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealth
);
1188 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1190 if ( p
-> Strength () <= 0 )
1192 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1195 int oldstrength
= user
-> stats
-> strength
;
1196 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1197 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1198 user
-> stats
-> strength
+= 1 + rand () % 2 ; // 1 - 2 Strength Added
1199 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1202 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1204 if ( p
-> Defense () <= 0 )
1206 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1209 int olddefense
= user
-> stats
-> defense
;
1210 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1211 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1212 user
-> stats
-> defense
+= 1 + rand () % 2 ; // 1 - 2 Defense Added
1213 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1216 else if ( stricmp ( item
, "HP" ) == 0 )
1220 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1223 int oldHP
= user
-> stats
-> maxhp
;
1224 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1225 user
-> stats
-> maxhp
+= 1 + rand () % 5 ; // 1 - 5 Maxhp
1226 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1231 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALTH | STRENGTH | DEFENSE}" );
1235 end_turn ( user
); // If they're fighting, end their turn
1237 void do_run ( char * u
)
1240 Player
* p
, * p2
= NULL
;
1242 if (!( user
= find ( u
)))
1244 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1248 else if (! is_playing ( user
))
1250 notice ( s_GameServ
, u
, "You must be playing to run!" );
1257 p2
= p
-> battle
-> stats
;
1259 if (! is_fighting ( user
))
1260 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1261 else if (! player_fight ( user
) && ! master_fight ( user
))
1263 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1267 else if ( player_fight ( user
) && isYourTurn ( p
))
1269 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1270 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1273 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1275 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1277 else if ( master_fight ( user
))
1279 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1284 void end_turn ( aClient
* user
)
1286 char * nick
, * u
= user
-> getNick ();
1291 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1293 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1296 if (! player_fight ( user
) && ! master_fight ( user
))
1297 fight
= user
-> stats
-> fight
;
1299 fight
= user
-> stats
-> master
;
1300 battle
= user
-> stats
-> battle
;
1302 if (! player_fight ( user
))
1305 mhit
= ( fight
-> strength
/ 2 ) +
1306 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1307 arbonus
[ user
-> stats
-> armor
]));
1312 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1313 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1314 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1316 if (! player_fight ( user
))
1321 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1322 fight
-> name
, fight
-> weapon
, mhit
);
1325 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1327 if ( mhit
>= user
-> stats
-> hp
)
1329 if (! master_fight ( user
))
1331 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1332 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1333 "of your experience!" );
1334 user
-> stats
-> gold
= 0 ;
1335 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1336 user
-> stats
-> fight
= NULL
;
1337 clearAlive ( user
-> stats
);
1342 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1343 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1344 user
-> stats
-> fight
= NULL
;
1345 user
-> stats
-> master
= NULL
;
1352 user
-> stats
-> hp
-= mhit
;
1359 clearYourTurn ( user
-> stats
);
1360 setYourTurn ( battle
-> stats
);
1361 display_players ( battle
);
1367 void do_attack ( char * u
)
1370 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1371 Monster
* fight
; // The monster they may be fighting
1373 if (!( ni
= find ( u
)))
1375 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1378 else if (! is_playing ( ni
))
1380 notice ( s_GameServ
, u
, "You're not playing!" );
1383 else if (! is_fighting ( ni
))
1385 notice ( s_GameServ
, u
, "You're not in battle!" );
1390 if (! ni
-> stats
-> master
) // This is not a master fight
1391 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1392 else // This IS a master fight
1393 fight
= ni
-> stats
-> master
; // Master Could be NULL
1395 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1397 // One has to be !NULL based on the previous else if
1398 // We wouldn't be here if they were all NULL
1401 if (! player_fight ( ni
))
1404 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1405 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1408 mhit
= ( fight
-> strength
/ 2 ) +
1409 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1410 arbonus
[ ni
-> stats
-> armor
]));
1415 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1416 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1417 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1420 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1421 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1422 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1425 if (! player_fight ( ni
))
1428 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1430 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1432 if ( hit
>= fight
-> hp
)
1434 if ( master_fight ( ni
))
1435 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1437 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1439 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1440 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1441 fight
-> exp
, fight
-> gold
);
1443 // If your new experience (or gold) will be greater than 2 billion,
1444 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1445 // This could be a problem with overflowing out of the sign bit.
1446 // Unsigned long int maybe? Leave it for now.
1447 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1448 ni
-> stats
-> exp
+ fight
-> exp
);
1450 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1451 ni
-> stats
-> gold
+ fight
-> gold
);
1454 if ( master_fight ( ni
))
1456 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1457 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1458 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1460 // Increase your level
1463 // Increase your maximum hit points
1464 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1466 // Heal the player by setting hp to their max
1467 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1469 // Add to your strength
1470 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1472 // Add to your defensive power
1473 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1475 // Clear the pointer for your master
1476 ni
-> stats
-> master
= NULL
;
1479 // They're dead so remove the pointer
1480 delete ni
-> stats
-> fight
;
1481 ni
-> stats
-> fight
= NULL
;
1482 ni
-> stats
-> master
= NULL
;
1492 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1493 fight
-> name
, fight
-> weapon
, mhit
);
1496 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1498 if ( mhit
>= ni
-> stats
-> hp
)
1500 if (! master_fight ( ni
))
1502 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1503 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1504 "of your experience!" );
1505 ni
-> stats
-> gold
= 0 ;
1506 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1507 ni
-> stats
-> fight
= NULL
;
1508 clearAlive ( ni
-> stats
);
1513 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1514 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1515 ni
-> stats
-> fight
= NULL
;
1516 ni
-> stats
-> master
= NULL
;
1523 ni
-> stats
-> hp
-= mhit
;
1529 else if ( player_fight ( ni
))
1531 /* Offline fighting not available yet
1532 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1535 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1537 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1538 if (hit >= battle->stats->hp)
1540 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1541 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1542 (long int)(battle->stats->exp * .10), battle->stats->gold);
1543 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1545 ni->stats->exp += (long int)(battle->stats->exp * .10);
1546 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1550 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1551 ni->stats->exp = 2000000000;
1554 if (2000000000 - ni->stats->gold > battle->stats->gold)
1556 * ni->stats->gold += battle->stats->gold;
1557 battle->stats->gold = 0;
1561 battle->stats->gold = 2000000000 - ni->stats->gold;
1562 ni->stats->gold = 2000000000;
1564 * ni->stats->battle->stats->alive = 0;
1565 ni->stats->battle->battle = NULL;
1566 ni->stats->battle = NULL;
1572 * battle->stats->hp -= hit;
1575 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1576 battle->nick, weapons[battle->stats->weapon], mhit);
1579 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1581 if (mhit >= ni->stats->hp)
1583 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1584 if (2000000000 - battle->stats->gold > ni->stats->gold)
1586 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1587 battle->stats->gold += ni->stats->gold;
1588 * ni->stats->gold = 0;
1592 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1594 ni->stats->gold -= (2000000000 - battle->stats->gold);
1595 notice(s_GameServ, u, "You were left dead with %d gold.",
1596 * (long int)ni->stats->gold);
1597 battle->stats->gold = 2000000000;
1599 ni->stats->battle->battle = NULL;
1600 ni->stats->battle = NULL;
1601 ni->stats->alive = 0;
1607 ni->stats->hp -= mhit;
1613 * end offline fighting */
1615 if ( is_playing ( battle
))
1617 if (! isYourTurn ( ni
-> stats
))
1619 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1620 battle
-> stats
-> name
);
1625 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1627 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1628 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1629 weapons
[ ni
-> stats
-> weapon
], hit
);
1630 clearYourTurn ( ni
-> stats
);
1631 setYourTurn ( battle
-> stats
);
1632 display_players ( battle
);
1636 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1637 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1638 clearYourTurn ( ni
-> stats
);
1639 setYourTurn ( battle
-> stats
);
1640 display_players ( battle
);
1642 if ( hit
>= battle
-> stats
-> hp
)
1644 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1645 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1646 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1647 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1649 battle
-> stats
-> hp
= 0 ;
1650 clearAlive ( battle
-> stats
);
1652 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1654 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1655 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1659 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1660 ni
-> stats
-> exp
= 2000000000 ;
1663 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1665 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1666 "all gold on hand!" );
1667 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1668 battle
-> stats
-> gold
= 0 ;
1672 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1673 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1675 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1676 "gold." , ni
-> stats
-> name
);
1678 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1679 "left. All is not lost!" , battle
-> stats
-> gold
);
1681 ni
-> stats
-> gold
= 2000000000 ;
1683 battle
-> stats
-> battle
= NULL
;
1684 ni
-> stats
-> battle
= NULL
;
1690 battle
-> stats
-> hp
-= hit
;
1691 clearYourTurn ( ni
-> stats
);
1692 setYourTurn ( battle
-> stats
);
1693 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1694 battle
-> stats
-> name
);
1702 void do_heal ( char * u
)
1705 char * amount
= strtok ( NULL
, " " );
1710 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1712 else if (!( ni
= find ( u
)))
1714 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1717 else if (! is_playing ( ni
))
1719 notice ( s_GameServ
, u
, "You aren't playing!" );
1722 else if (! isAlive ( ni
-> stats
))
1724 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1727 else if ( is_fighting ( ni
))
1729 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1731 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1733 notice ( s_GameServ
, u
, "You don't need healing!" );
1735 else if ( stricmp ( amount
, "ALL" ) == 0 )
1737 price
= ni
-> stats
-> level
* 3 ;
1738 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1740 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1741 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1742 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1743 ni
-> stats
-> gold
%= price
;
1747 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1748 "per point." , price
);
1749 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1750 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1751 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1752 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1753 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1756 else if ( isstringnum ( amount
))
1758 num
= stringtoint ( amount
);
1759 price
= ni
-> stats
-> level
* 3 ;
1760 if ( ni
-> stats
-> gold
< price
* num
)
1762 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1763 ( long int ) ni
-> stats
-> gold
/ price
);
1765 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1767 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
1769 ni
-> stats
-> hp
+= num
;
1770 ni
-> stats
-> gold
-= num
* price
;
1772 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1774 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1775 "per point." , price
);
1776 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
1777 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
1778 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1779 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1782 else if ( amount
[ 0 ] == '-' )
1783 notice ( s_GameServ
, u
, "You trying to cheat?" );
1785 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1788 int isstringnum ( char * num
)
1791 for ( x
= 0 ; x
< strlen ( num
); x
++)
1793 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
1799 long int stringtoint ( char * number
)
1801 long int x
, len
= strlen ( number
), sum
= 0 ;
1803 return chartoint ( number
[ 0 ]);
1804 sum
+= chartoint ( number
[ len
- 1 ]);
1805 for ( x
= len
- 2 ; x
>= 0 ; x
--)
1806 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
1810 long int pow ( int x
, int y
)
1816 if ( x
!= 0 && y
!= 0 )
1818 for ( count
= 1 ; count
<= y
- 1 ; count
++)
1826 long int chartoint ( char ch
)
1828 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
1829 return int ( ch
) - 48 ;
1836 ListNode
< aClient
> * ptr
;
1840 outfile
. open ( playerdata
);
1844 log ( "Error opening %s " , playerdata
);
1848 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
1850 ptr
= players
[ x
]. First ();
1853 it
= ptr
-> getData ()-> stats
;
1854 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
1855 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
1856 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
1857 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
1858 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
1859 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
1872 char * tempname
, * buf
, * password
;
1873 buf
= new char [ 1023 ];
1875 infile
. open ( playerdata
);
1879 log ( "Error opening %s " , playerdata
);
1883 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
1886 tempname
= strtok ( buf
, " " );
1887 temp
-> stats
= new Player ( tempname
);
1890 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
1891 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
1892 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
1893 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
1894 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
1895 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
1896 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
1897 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
1898 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
1899 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
1900 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
1901 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
1902 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
1904 password
= strtok ( NULL
, " " );
1905 strcpy ( p
-> password
, password
);
1906 temp
-> setNick ( "!NULL!" );
1908 temp
-> setRealNick ( "!NULL!" );
1911 p
-> inventory
. reset (); // Set inventory to all 0s
1912 // Old player databases didn't have these three extra values
1913 // If they come up null, leave them to 0 as the default.
1914 // On the next gameserv database save, it will save the values.
1915 tempname
= strtok ( NULL
, " " );
1917 p
-> inventory
. setHealing ( stringtoint ( tempname
));
1919 tempname
= strtok ( NULL
, " " );
1921 p
-> inventory
. setStrength ( stringtoint ( tempname
));
1923 tempname
= strtok ( NULL
, " " );
1925 p
-> inventory
. setDefense ( stringtoint ( tempname
));
1927 tempname
= strtok ( NULL
, " " );
1929 p
-> inventory
. setHP ( stringtoint ( tempname
));
1930 unsigned long hv
= HASH (( unsigned char *) temp
-> stats
-> name
, U_TABLE_SIZE
);
1932 temp
-> stats
-> client
= NULL
;
1933 players
[ hv
]. insertAtBack ( temp
);
1941 bool passcmp ( char * encrypted
, char * plaintext
)
1944 char * plaintext2
, * plainToencrypt
;
1947 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
1948 strcpy ( plaintext2
, plaintext
);
1950 salt
[ 0 ] = encrypted
[ 0 ];
1951 salt
[ 1 ] = encrypted
[ 1 ];
1954 plainToencrypt
= crypt ( plaintext2
, salt
);
1956 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
1958 delete [] plaintext2
;
1963 bool check_password ( char * name
, char * plaintext
)
1967 if (!( client
= findplayer ( name
)))
1971 return passcmp ( client
-> stats
-> password
, plaintext
);
1975 void do_store ( char * u
)
1977 char * cmd
= strtok ( NULL
, " " );
1978 char * item
= strtok ( NULL
, " " );
1979 char * num
= strtok ( NULL
, " " );
1987 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
1988 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
1989 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
1991 else if (!( user
= find ( u
)) || ! is_playing ( user
))
1992 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
1993 else if (! isAlive ( user
-> stats
))
1995 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
1998 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2000 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2002 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2003 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2004 for ( int x
= 1 ; x
< WNA
; x
++)
2006 space
= spaces ( strlen ( weapons
[ x
]), "." );
2007 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2010 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2011 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2014 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2016 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2017 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2018 for ( int x
= 1 ; x
< WNA
; x
++)
2020 space
= spaces ( strlen ( armors
[ x
]), "." );
2021 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2024 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2025 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2029 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2032 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2035 else if (! isstringnum ( num
))
2037 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2040 if ( stricmp ( item
, "WEAPON" ) == 0 )
2042 wep
= stringtoint ( num
);
2043 if ( wep
>= WNA
|| wep
< 1 )
2045 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2052 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2053 else if ( p
-> gold
< prices
[ wep
- 1 ])
2054 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2057 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2059 p
-> gold
-= prices
[ wep
- 1 ];
2062 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2064 wep
= stringtoint ( num
);
2065 if ( wep
>= WNA
|| wep
< 1 )
2067 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2074 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2075 else if ( p
-> gold
< prices
[ wep
- 1 ])
2076 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2079 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2081 p
-> gold
-= prices
[ wep
- 1 ];
2085 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2089 if ( stricmp ( item
, "WEAPON" ) == 0 )
2093 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2096 else if ( p
-> gold
== 2000000000 )
2098 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2101 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2103 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2104 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2105 p
-> gold
= 2000000000 ;
2110 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2111 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2115 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2121 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2124 if ( p
-> gold
== 2000000000 )
2126 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2129 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2131 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2132 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2133 p
-> gold
= 2000000000 ;
2138 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2139 ( prices
[ p
-> armor
- 1 ] / 2 ));
2141 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2147 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2148 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2149 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2153 void do_inventory ( char * u
)
2157 if (!( user
= find ( u
)))
2159 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2162 else if (! is_playing ( user
))
2164 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2167 showinventory ( user
, user
);
2169 void showinventory ( aClient
* from
, aClient
* to
)
2171 char * nick
= to
-> getNick ();
2175 if ( is_playing ( from
))
2177 Pouch
* p
= & from
-> stats
-> inventory
;
2178 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2179 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2180 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2181 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2182 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2185 void do_tavern ( char * u
)
2187 char * cmd
= strtok ( NULL
, " " );
2192 if (!( user
= find ( u
)))
2194 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2197 else if (! is_playing ( user
))
2199 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2202 else if ( is_fighting ( user
))
2204 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2210 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2211 notice ( s_GameServ
, u
, "Your commands:" );
2212 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2213 notice ( s_GameServ
, u
, "What'll it be?" );
2215 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2217 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2218 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 1000 * p
-> level
+ ( p
-> exp
/ 10 ));
2219 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 2050 * p
-> level
+ ( p
-> exp
/ 10 ));
2220 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 2000 * p
-> level
+ ( p
-> exp
/ 10 ));
2221 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 2300 * p
-> level
+ ( p
-> exp
/ 10 ));
2222 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2223 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2224 notice ( s_GameServ
, u
, "By something will ya!" );
2226 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2228 char * chnum
= strtok ( NULL
, " " );
2229 int num
= stringtoint ( chnum
);
2233 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2234 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2237 if ( num
< 1 || num
> 4 )
2239 notice ( s_GameServ
, u
, "Invalid Choice!" );
2240 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2241 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 1000 * p
-> level
+ ( p
-> exp
/ 10 ));
2242 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 2050 * p
-> level
+ ( p
-> exp
/ 10 ));
2243 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 2000 * p
-> level
+ ( p
-> exp
/ 10 ));
2244 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 2300 * p
-> level
+ ( p
-> exp
/ 10 ));
2245 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2246 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2252 price
= ( 1000 * p
-> level
) + ( p
-> exp
/ 10 );
2253 if ( p
-> gold
>= price
)
2255 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2256 p
-> inventory
. incHealing ();
2260 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2263 price
= ( 2050 * p
-> level
) + ( p
-> exp
/ 10 );
2264 if ( p
-> gold
>= price
)
2266 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2267 p
-> inventory
. incStrength ();
2271 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2274 price
= ( 2000 * p
-> level
) + ( p
-> exp
/ 10 );
2275 if ( p
-> gold
>= price
)
2277 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2278 p
-> inventory
. incDefense ();
2282 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2285 price
= ( 2300 * p
-> level
) + ( p
-> exp
/ 10 );
2286 if ( p
-> gold
>= price
)
2288 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2289 p
-> inventory
. incHP ();
2293 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2296 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2302 notice ( s_GameServ
, u
, "Improper Syntax." );
2303 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2307 void do_bank ( char * u
)
2309 char * cmd
= strtok ( NULL
, " " );
2310 char * amount
= strtok ( NULL
, " " );
2311 char * nick
= strtok ( NULL
, " " );
2316 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2318 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2319 notice ( s_GameServ
, u
, "BANK BALANCE" );
2324 if (! is_playing ( user
))
2326 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2329 else if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2334 else if (! isAlive ( user
-> stats
))
2336 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2339 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2341 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2347 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2349 if ( p
-> bank
== 2000000000 )
2351 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2354 else if ( stricmp ( amount
, "ALL" ) == 0 )
2356 if ( 2000000000 - p
-> bank
< p
-> gold
)
2358 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2359 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2360 p
-> gold
-= ( 2000000000 - p
-> bank
);
2361 p
-> bank
= 2000000000 ;
2366 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2372 else if ( stringtoint ( amount
) > p
-> gold
)
2374 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2380 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2382 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2383 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2384 p
-> gold
-= ( 2000000000 - p
-> bank
);
2385 p
-> bank
= 2000000000 ;
2390 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2391 p
-> bank
+= stringtoint ( amount
);
2392 p
-> gold
-= stringtoint ( amount
);
2397 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2399 if ( p
-> gold
== 2000000000 )
2401 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2405 else if ( stricmp ( amount
, "ALL" ) == 0 )
2407 if ( 2000000000 - p
-> gold
< p
-> bank
)
2409 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2410 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2411 p
-> bank
-= ( 2000000000 - p
-> gold
);
2412 p
-> gold
= 2000000000 ;
2417 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2423 else if ( stringtoint ( amount
) > p
-> bank
)
2425 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2431 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2433 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2434 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2435 ( 2000000000 - p
-> gold
));
2436 p
-> bank
-= ( 2000000000 - p
-> gold
);
2437 p
-> gold
= 2000000000 ;
2442 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2443 p
-> gold
+= stringtoint ( amount
);
2444 p
-> bank
-= stringtoint ( amount
);
2452 void do_master ( char * u
)
2459 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2462 else if ( is_fighting ( user
))
2464 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2467 else if (! isAlive ( user
-> stats
))
2469 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2472 else if (! is_playing ( user
))
2474 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2478 char * cmd
= strtok ( NULL
, " " );
2479 Player
* p
= user
-> stats
;
2484 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2527 notice ( s_GameServ
, u
, "You are at level 12. You are the master. What's left? The DRAGON!" );
2530 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2536 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2540 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2548 notice ( s_GameServ
, u
, "You are not worthy of fighting %s ! You need %l d more experience." , masters
[ p
-> level
- 1 ]-> name
, ( need
- p
-> exp
));
2551 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2554 notice ( s_GameServ
, u
, " %s looks you up and down and decides you are more ready than you will ever be." , masters
[ p
-> level
- 1 ]-> name
);
2556 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2562 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2566 void see_master ( char * u
)
2570 if (!( user
= find ( u
)))
2572 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2576 if (! is_fighting ( user
) && is_playing ( user
))
2578 Player
* p
= user
-> stats
;
2579 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2580 p
-> fight
= p
-> master
;
2581 display_monster ( u
); // Since master is the same structure, use this function
2585 void showBankBalance ( const char * u
)
2590 if (!( user
= find ( u
)))
2598 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2604 ListNode
< aClient
> * it
;
2606 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2608 it
= players
[ x
]. First ();
2612 p
= it
-> getData ()-> stats
;
2619 void refresh ( Player
* p
)
2624 if ( p
-> hp
< p
-> maxhp
)
2626 p
-> forest_fights
= forestfights
;
2627 p
-> player_fights
= 3 ;
2632 void do_refresh ( char * u
)
2634 char * nick
= strtok ( NULL
, " " );
2637 if (!( user
= find ( u
)))
2639 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2640 log ( "Error: aClient not found: %s " , u
);
2643 else if (! isAdmin ( user
))
2645 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2650 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
2653 else if ( stricmp ( nick
, "ALL" ) == 0 )
2655 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
2658 else if (( user
= findbyrealnick ( nick
)))
2660 if ( is_playing ( user
))
2663 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
2665 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
2667 refresh ( user
-> stats
);
2672 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2674 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2680 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2688 ListNode
< aClient
> * it
;
2691 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2693 it
= players
[ x
]. First ();
2697 p
= it
-> getData ()-> stats
;
2704 void reset ( Player
* p
)
2712 void do_reset ( char * u
)
2714 char * nick
= strtok ( NULL
, " " );
2717 if (!( user
= find ( u
)))
2719 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2720 log ( "Error: aClient not found: %s " , u
);
2723 else if (! isAdmin ( user
))
2725 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2730 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
2733 else if ( stricmp ( nick
, "ALL" ) == 0 )
2735 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
2738 else if (( user
= findbyrealnick ( nick
)))
2740 if ( is_playing ( user
))
2743 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
2745 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
2752 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2754 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2760 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2765 void do_help ( char * u
)
2767 char * cmd
= strtok ( NULL
, " " );
2769 display_help ( u
, cmd
);
2772 void display_help ( char * u
, char * file
)
2779 infile
. open ( "helpfiles/help" );
2782 log ( "Error opening helpfiles/help" );
2783 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
2786 buf
= new char [ 1024 ];
2787 while ( infile
. getline ( buf
, 1024 ))
2789 // Written this way, it will process %S in the helpfiles
2790 // Instead of notice(s_GameServ, u, "%s", buf);
2791 notice ( s_GameServ
, u
, buf
);
2795 aClient
* user
= find ( u
);
2796 if ( user
&& isAdmin ( user
))
2797 display_help ( u
, "admin_commands" );
2802 filename
= new char [ strlen ( file
) + 11 ];
2803 strcpy ( filename
, "helpfiles/" );
2804 strcat ( filename
, file
);
2806 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
2807 filename
[ x
] = tolower ( filename
[ x
]);
2809 infile
. open ( filename
);
2813 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
2816 buf
= new char [ 1024 ];
2817 while ( infile
. getline ( buf
, 1024 ))
2819 // Written this way, it will process %S in the helpfiles
2820 // Instead of notice(s_GameServ, u, "%s", buf);
2821 notice ( s_GameServ
, u
, buf
);
2828 void do_admin ( char * u
)
2831 char * pass
= strtok ( NULL
, " " );
2833 if (!( user
= find ( u
)))
2835 log ( "Error: aClient not found: %s " , u
);
2836 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
2841 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
2847 notice ( s_GameServ
, u
, "You already have administrator privledges." );
2850 else if ( strcmp ( pass
, adminpass
) == 0 )
2852 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
2855 log ( " %s became an administrator." , user
-> getRealNick ());
2857 log ( " %s became an administrator." , user
-> getNick ());
2862 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
2867 bool load_monsters ()
2870 infile
. open ( "monsters.dat" );
2876 log ( "Error opening monsters.dat" );
2880 buf
= new char [ 2048 ];
2883 log ( "Loading monsters from monsters.dat" );
2886 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
2888 for ( int m
= 0 ; m
< MONSTERS
;)
2890 infile
. getline ( buf
, 2048 );
2891 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
2895 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
2896 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
2897 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
2898 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
2899 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
2900 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
2901 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
2902 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));
2911 // this will be hash.cpp start
2912 // thank you wcampbel
2913 unsigned long HASH ( const unsigned char * name
, int size_of_table
)
2915 unsigned long h
= 0 , g
;
2920 h
= ( h
<< 4 ) + (* name
++); // Case sensitive for numerics
2922 h
= ( h
<< 4 ) + tolower (* name
++);
2924 if (( g
= ( h
& 0xF0000000 )))
2928 return h
% size_of_table
;
2931 // this will be hash.cpp end