]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
14 #if defined(HAVE_CRYPT_H)
18 #elif defined(HAVE_UNISTD_H)
24 // this will be hash.cpp start
26 unsigned long HASH ( const unsigned char * name
, int size_of_table
);
27 List
< aClient
> players
[ U_TABLE_SIZE
];
28 // this will be hash.cpp end
31 Monster
* monsters
[ LEVELS
][ MONSTERS
]; // Monsters per level. Total = MONSTERS * LEVELS
32 Monster boss
; // The boss monster
34 Monster
* masters
[ LEVELS
]; // A master for each level
42 char * strtok ( char * str
, const char * delim
);
45 int stricmp ( const char * s1
, const char * s2
);
46 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 **********/
61 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
62 bool is_playing ( aClient
* user
);
64 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
65 bool is_fighting ( aClient
* user
);
67 bool player_fight ( char * u
); // True if the player is fighting another player.
68 bool player_fight ( aClient
* user
);
70 bool master_fight ( char * u
); // True if the player is fighting their master.
71 bool master_fight ( aClient
* user
);
73 /********** GameServ Booleans **********/
75 void display_help ( char * u
, char * file
= NULL
);
76 void display_monster ( char * u
);
77 void display_players ( char * u
);
78 void display_players ( aClient
* user
);
79 long int chartoint ( char ch
);
80 int isstringnum ( char * num
);
81 long int pow ( int x
, int y
);
82 long int stringtoint ( char * number
);
84 char * spaces ( int len
, char * seperator
);
85 void refresh ( Player
* p
);
87 void reset ( Player
* p
);
91 void delete_monsters ();
92 void delete_masters ();
94 void do_admin ( char * u
);
95 void do_attack ( char * u
);
96 void do_bank ( char * u
);
97 void do_fight ( char * u
);
98 void do_heal ( char * u
);
99 void do_help ( char * u
);
100 void do_identify ( char * u
);
101 void do_inventory ( char * u
);
102 void do_refresh ( char * u
);
103 void do_register ( char * u
);
104 void do_list ( char * u
);
105 void do_logout ( char * u
);
106 void do_master ( char * u
);
107 void do_play ( char * u
);
108 void do_quitg ( char * u
);
109 void do_reset ( char * u
);
110 void do_run ( char * u
);
111 void do_stats ( char * u
);
112 void do_store ( char * u
);
113 void do_tavern ( char * u
);
114 void do_use ( char * u
);
115 void see_master ( char * u
);
117 void logout ( aClient
* user
);
118 void showstats ( const char * u
, const char * nick
);
119 void showinventory ( aClient
* from
, aClient
* to
);
120 void showBankBalance ( const char * u
);
121 void end_turn ( aClient
* user
);
124 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
125 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
126 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
127 "Light Saber" , "Masamune" , "Mystical Sword" };
129 char * armors
[ WNA
] = { "Nothing" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
130 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
131 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
132 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
134 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
135 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
136 int webonus
[ WNA
] = { 1 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
137 int arbonus
[ WNA
] = { 1 , 2 , 4 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
139 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
140 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
141 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
143 void gameserv ( char * source
, char * buf
)
146 cmd
= strtok ( buf
, " " );
149 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
153 cmd
++; // Get rid of that : at the beginning of the :text (command)
156 log ( "Source: %s Command: %s " , source
, cmd
);
164 int curday
= tm
-> tm_mday
;
170 save_day (); // here i come to save the day!
173 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
176 ts
= strtok ( NULL
, "\1" );
177 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
178 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
179 notice ( s_GameServ
, source
, "\1VERSION %s %s +devel\1" , PACKAGE
, VERSION
);
180 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
181 cmd
= strtok ( NULL
, " " );
184 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
188 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
190 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
192 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
194 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
196 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
198 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
199 do_inventory ( source
);
200 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
202 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
204 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
206 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
208 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
210 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
212 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
214 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
216 } else if ( stricmp ( cmd
, "LOGOUT" ) == 0 ) {
218 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
220 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
222 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
224 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
226 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
229 if (!( user
= find ( source
)))
231 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
232 log ( "Error: aClient not found: %s " , source
);
234 else if (! isAdmin ( user
))
236 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
242 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
244 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
247 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
250 if (!( user
= find ( source
)))
252 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
253 log ( "Error: aClient not found: %s " , source
);
255 else if (! isAdmin ( user
))
257 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
263 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
266 if (!( user
= find ( source
)))
268 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
269 log ( "Error: aClient not found: %s " , source
);
271 else if (! isAdmin ( user
))
273 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
277 char * cmd2
= strtok ( NULL
, " " );
280 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
283 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
285 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
289 display_help ( source
, cmd
);
292 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
295 if (!( user
= find ( source
)))
297 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
298 log ( "Error: aClient not found: %s " , source
);
300 else if (! isAdmin ( user
))
302 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
306 char * rest
= strtok ( NULL
, "" );
311 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
314 source
--; // Bring the ':' back so we don't leak memory
315 cmd
--; // Same thing :)
318 int stricmp ( const char * s1
, const char * s2
)
322 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
328 if ( c
< tolower (* s2
))
333 void showstats ( const char * u
, const char * nick
)
335 aClient
* ni
, * sender
= find ( u
);
341 if (!( ni
= findplayer ( nick
)))
343 notice ( s_GameServ
, u
, " %s not found" , nick
);
347 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
349 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
350 space
= spaces ( strlen ( buf
), " " );
351 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
355 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
356 space
= spaces ( strlen ( buf
), " " );
357 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
360 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
363 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
364 space
= spaces ( strlen ( buf
), " " );
365 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
366 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
369 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
370 space
= spaces ( strlen ( buf
), " " );
371 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
372 weapons
[ ni
-> stats
-> weapon
]);
375 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
376 space
= spaces ( strlen ( buf
), " " );
377 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
382 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
387 char * spaces ( int len
, char * seperator
)
390 final
= new char [ 30 ];
392 strcpy ( final
, seperator
);
393 for ( y
= 0 ; y
< 30 - len
; y
++)
394 strcat ( final
, seperator
);
398 void raw ( const char * fmt
, ...)
403 input
= new char [ 1024 ];
405 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
411 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
412 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
413 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
416 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
421 sprintf ( input
, " %s%c " , input
, * t
);
426 log ( "Input: %s " , input
);
429 sprintf ( input
, " %s%s " , input
, " \r\n " );
430 sock_puts ( sock
, input
);
434 /* Send a NOTICE from the given source to the given nick. */
436 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
444 input
= new char [ 1024 ];
451 sprintf ( input
, ": %s NOTICE %s :" , source
, dest
);
453 sprintf ( input
, " %s O %s :" , gsnum
, dest
);
461 sprintf ( input
, ": %s NOTICE %s :" , source
, dest
);
463 sprintf ( input
, " %s O %s :" , gsnum
, dest
);
472 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
473 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
474 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
477 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
482 sprintf ( input
, " %s%c " , input
, * t
);
487 log ( "Input: %s " , input
);
489 sprintf ( input
, " %s%s " , input
, " \r\n " );
490 sock_puts ( sock
, input
);
496 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
502 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
503 if ( c
== 0 || -- len
== 0 )
508 if ( c
< tolower (* s2
))
514 char * strtok ( char * str
, const char * delim
)
516 static char * current
= NULL
;
523 current
+= strspn ( current
, delim
);
524 ret
= * current
? current
: NULL
;
525 current
+= strcspn ( current
, delim
);
534 void do_list ( char * u
)
536 ListNode
< aClient
> * temp
;
538 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
540 temp
= players
[ x
]. First ();
541 if (! players
[ x
]. isEmpty ())
545 notice ( s_GameServ
, u
, "People Playing:" );
551 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
552 temp
-> getData ()-> stats
-> name
);
554 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
555 temp
-> getData ()-> stats
-> name
);
563 notice ( s_GameServ
, u
, "No one is playing" );
565 notice ( s_GameServ
, u
, "End of List" );
569 void do_logout ( char * u
)
572 if (!( user
= find ( u
)))
574 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. " \
575 "Buf: %s LOGOUT" , u
);
576 log ( "Could not find aClient Buf: %s LOGOUT" ,
579 else if (! is_playing ( user
))
581 notice ( s_GameServ
, u
, "You're not logged in!" );
583 else if ( is_fighting ( user
))
585 notice ( s_GameServ
, u
, "You can't logout while fighting!" );
589 notice ( s_GameServ
, u
, "You have left the fields. You have lived to kill another day!" );
593 void logout ( aClient
* user
)
595 if ( is_playing ( user
))
597 ListNode
< aClient
> * it
;
599 unsigned long hv
= HASH (( unsigned char *) user
-> stats
-> name
,
601 it
= players
[ hv
]. Find ( user
);
604 notice ( s_GameServ
, user
-> getNick (), "Fatal error. Contact " \
605 " %S Admin. Cannot find you in the players list." );
606 log ( "Error on logout(). Can't find %s in the players list" ,
617 temp
-> stats
= new Player
;
618 temp
-> stats
-> setData ( user
-> stats
);
619 user
-> stats
-> user
= NULL
;
621 if ( player_fight ( user
))
622 user
-> stats
-> battle
-> stats
-> battle
= NULL
;
626 temp
-> stats
-> user
= NULL
;
628 temp
-> setRealNick ( "!NULL!" );
630 temp
-> setNick ( "!NULL!" );
634 log ( "Logged out player %s " ,
644 void do_register ( char * u
)
646 char * password
, * name
;
648 name
= strtok ( NULL
, " " );
649 password
= strtok ( NULL
, " " );
651 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
654 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
655 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
660 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
664 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
666 else if (( user
= findplayer ( name
)))
668 notice ( s_GameServ
, u
, " %s is already registered!" , name
);
669 notice ( s_GameServ
, u
, "Choose another name!" );
671 else if (( user
= find ( u
)))
674 if (! user
-> stats
&& ! p
)
676 user
-> stats
= new Player ( user
);
677 user
-> stats
-> user
= user
; // Set the backwards pointer
678 strcpy ( user
-> stats
-> password
, crypt ( password
, salt
));
679 strcpy ( user
-> stats
-> name
, name
);
680 unsigned long hv
= HASH (( unsigned char *) name
, U_TABLE_SIZE
);
681 players
[ hv
]. insertAtBack ( user
);
682 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
683 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
684 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
688 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
693 void do_identify ( char * u
)
695 char * password
, * name
;
697 name
= strtok ( NULL
, " " );
698 password
= strtok ( NULL
, " " );
700 if (! password
|| ! name
)
702 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
706 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
707 log ( "Error: aClient not found: %s " , u
);
709 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
710 notice ( s_GameServ
, u
, "Player %s not found" , name
);
711 else if ( is_playing ( user
))
713 notice ( s_GameServ
, u
, "You are already playing!" );
715 else if ( p
-> stats
-> user
!= NULL
&& ! isAdmin ( user
))
717 notice ( s_GameServ
, u
, "That player has already identified." );
719 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
721 notice ( s_GameServ
, u
, "Password incorrect" );
724 ListNode
< aClient
> * temp
;
725 unsigned long hv
= HASH (( unsigned char *) p
-> stats
-> name
,
727 temp
= players
[ hv
]. Find ( p
);
730 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
734 user
-> stats
= new Player ( p
-> stats
-> name
);
736 log ( "Setting data for identified" );
738 user
-> stats
-> setData ( p
-> stats
);
741 log ( "Player Identified" );
745 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
749 void do_stats ( char * u
)
754 nick
= strtok ( NULL
, " " );
758 if (!( user
= find ( u
)))
760 notice ( s_GameServ
, u
, "Fatal Error in do_stats(). Contact a %S admin for help!" );
761 log ( "Error: aClient not found: %s " , u
);
764 else if (! is_playing ( user
))
766 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
770 showstats ( u
, user
-> stats
-> name
);
778 log ( "Calling delete_masters()" );
784 log ( "Initializing masters" );
787 for ( int x
= 0 ; x
< LEVELS
; x
++)
788 masters
[ x
] = new Monster
;
790 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
791 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
792 masters
[ 0 ]-> strength
= 15 ;
793 masters
[ 0 ]-> gold
= 0 ;
795 masters
[ 0 ]-> maxhp
= 30 ;
797 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!" );
799 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
800 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
801 masters
[ 1 ]-> strength
= 30 ;
802 masters
[ 1 ]-> gold
= 0 ;
804 masters
[ 1 ]-> maxhp
= 40 ;
806 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." );
808 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
809 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
810 masters
[ 2 ]-> strength
= 85 ;
811 masters
[ 2 ]-> gold
= 0 ;
813 masters
[ 2 ]-> maxhp
= 70 ;
815 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!" );
818 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
819 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
820 masters
[ 3 ]-> strength
= 120 ;
821 masters
[ 3 ]-> gold
= 0 ;
823 masters
[ 3 ]-> maxhp
= 120 ;
824 masters
[ 3 ]-> hp
= 120 ;
825 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
827 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
828 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
829 masters
[ 4 ]-> strength
= 135 ;
830 masters
[ 4 ]-> gold
= 0 ;
832 masters
[ 4 ]-> maxhp
= 200 ;
833 masters
[ 4 ]-> hp
= 200 ;
834 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!" );
836 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
837 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
838 masters
[ 5 ]-> strength
= 160 ;
839 masters
[ 5 ]-> gold
= 0 ;
841 masters
[ 5 ]-> maxhp
= 400 ;
842 masters
[ 5 ]-> hp
= 400 ;
843 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
846 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
847 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
848 masters
[ 6 ]-> strength
= 185 ;
849 masters
[ 6 ]-> gold
= 0 ;
851 masters
[ 6 ]-> maxhp
= 600 ;
852 masters
[ 6 ]-> hp
= 600 ;
853 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
855 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
856 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
857 masters
[ 7 ]-> strength
= 210 ;
858 masters
[ 7 ]-> gold
= 0 ;
860 masters
[ 7 ]-> maxhp
= 800 ;
861 masters
[ 7 ]-> hp
= 800 ;
862 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
865 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
866 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
867 masters
[ 8 ]-> strength
= 275 ;
868 masters
[ 8 ]-> gold
= 0 ;
870 masters
[ 8 ]-> maxhp
= 1200 ;
871 masters
[ 8 ]-> hp
= 1200 ;
872 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
874 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
875 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
876 masters
[ 9 ]-> strength
= 360 ;
877 masters
[ 9 ]-> gold
= 0 ;
879 masters
[ 9 ]-> maxhp
= 1800 ;
880 masters
[ 9 ]-> hp
= 1800 ;
881 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
883 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
884 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
885 masters
[ 10 ]-> strength
= 575 ;
886 masters
[ 10 ]-> gold
= 0 ;
887 masters
[ 10 ]-> exp
= 0 ;
888 masters
[ 10 ]-> maxhp
= 2500 ;
889 masters
[ 10 ]-> hp
= 2500 ;
890 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." );
896 log ( "Calling delete_monsters" );
901 for ( int x
= 0 ; x
< LEVELS
; x
++)
902 for ( int y
= 0 ; y
< MONSTERS
; y
++)
903 monsters
[ x
][ y
] = new Monster ();
906 void delete_monsters ()
908 for ( int x
= 0 ; x
< LEVELS
; x
++)
909 for ( int y
= 0 ; y
< MONSTERS
; y
++)
911 delete monsters
[ x
][ y
];
914 void delete_masters ()
916 for ( int x
= 0 ; x
< LEVELS
; x
++)
921 void display_monster ( char * u
)
925 aClient
* user
= find ( u
);
926 Player
* ni
= user
-> stats
;
928 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
929 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
930 notice ( s_GameServ
, u
, "Here are your commands:" );
931 notice ( s_GameServ
, u
, "/msg %S attack" );
932 notice ( s_GameServ
, u
, "/msg %S run" );
933 notice ( s_GameServ
, u
, "What will you do?" );
937 void display_players ( char * u
)
941 aClient
* ni
= find ( u
);
943 aClient
* battle
= ni
-> stats
-> battle
;
945 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> stats
-> hp
);
946 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
,
948 notice ( s_GameServ
, u
, "Here are your commands:" );
949 notice ( s_GameServ
, u
, "/msg %S attack" );
950 notice ( s_GameServ
, u
, "/msg %S run" );
951 notice ( s_GameServ
, u
, "What will you do?" );
954 void display_players ( aClient
* user
)
956 char * u
= user
-> getNick ();
957 if ( is_playing ( user
) && player_fight ( user
))
959 aClient
* battle
= user
-> stats
-> battle
;
960 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
961 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
962 notice ( s_GameServ
, u
, "Here are your commands:" );
963 notice ( s_GameServ
, u
, "/msg %S attack" );
964 notice ( s_GameServ
, u
, "/msg %S run" );
965 notice ( s_GameServ
, u
, "What will you do?" );
970 bool is_playing ( char * u
)
973 if (!( user
= find ( u
)))
979 return user
-> stats
!= NULL
;
983 bool is_playing ( aClient
* user
)
985 return user
-> stats
!= NULL
&& ( stricmp ( user
-> getNick (), "!NULL!" ) != 0 );
988 bool is_fighting ( char * u
)
992 if (!( user
= find ( u
)))
996 else if ( user
-> stats
)
998 return user
-> stats
-> fight
!= NULL
|| user
-> stats
-> battle
!= NULL
999 || user
-> stats
-> master
!= NULL
;
1004 bool is_fighting ( aClient
* user
)
1006 if (! is_playing ( user
))
1009 return ( user
-> stats
-> fight
!= NULL
|| user
-> stats
-> battle
!= NULL
|| user
-> stats
-> master
!= NULL
);
1012 bool player_fight ( char * u
)
1016 if (!( user
= find ( u
)))
1018 else if ( user
-> stats
)
1019 return user
-> stats
-> battle
!= NULL
;
1023 bool player_fight ( aClient
* user
)
1025 if (! is_fighting ( user
))
1028 return user
-> stats
-> battle
!= NULL
;
1031 bool master_fight ( char * u
)
1035 if (!( user
= find ( u
)))
1037 else if ( user
-> stats
)
1038 return user
-> stats
-> master
!= NULL
;
1042 bool master_fight ( aClient
* user
)
1044 if (! is_playing ( user
))
1047 return user
-> stats
-> master
!= NULL
;
1050 void do_fight ( char * u
)
1052 aClient
* ni
, * battle
;
1054 char * nick
= strtok ( NULL
, " " );
1058 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
1060 else if (!( ni
= find ( u
)))
1062 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1064 else if (! is_playing ( ni
))
1066 notice ( s_GameServ
, u
, "You are not playing!" );
1068 else if ( ni
-> stats
-> player_fights
<= 0 )
1070 ni
-> stats
-> player_fights
= 0 ; // just to be safe
1071 notice ( s_GameServ
, u
, "You are out of player fights for the " \
1072 "day. You have to wait until tomorrow!" );
1074 else if (!( battle
= findplayer ( nick
)))
1076 notice ( s_GameServ
, u
, "Player %s not found!" , nick
);
1078 else if (! is_playing ( battle
))
1080 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
1083 * Offline fighting not implemented yet.
1084 * else if (!(fight = finduser(nick)))
1086 * ni->stats->battle = battle;
1087 * battle->battle = ni;
1089 * battle->yourturn = 0;
1090 * notice(s_GameServ, u, "You decide to fight %s while they're not online!",
1091 * battle->stats->name);
1092 * display_players(u);
1095 else if (! isAlive ( ni
-> stats
))
1097 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1099 else if ( stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) == 0 )
1101 notice ( s_GameServ
, u
, "Are you trying to commit suicide!?" );
1103 else if (! isAlive ( battle
-> stats
))
1105 notice ( s_GameServ
, u
, "They are dead. Cannot fight dead players!" );
1107 else if ( player_fight ( battle
))
1109 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1111 else if ( is_fighting ( battle
))
1113 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1115 else if ( ni
-> stats
-> level
- battle
-> stats
-> level
> maxbfightdistance
)
1117 // You can't fight someone below you by more than X level(s)
1118 // level 12 can fight level (12 - X) but not < (12 - X)
1119 notice ( s_GameServ
, u
, "You may not fight %s . You're too strong!" ,
1120 battle
-> stats
-> level
);
1122 else if ( battle
-> stats
-> level
- ni
-> stats
-> level
> maxafightdistance
)
1124 // You can't fight someone above you by more than X level(S)
1125 // level 1 can fight level (1 + X), but not > (1 + X)
1126 notice ( s_GameServ
, u
, " %s , do you really have a death wish? Try the forest you " \
1127 "weakling!" , ni
-> stats
-> name
);
1131 // Set your battle pointer to the other player
1132 ni
-> stats
-> battle
= battle
;
1134 // Set the other player's battle pointer to you
1135 battle
-> stats
-> battle
= ni
;
1137 // The initiator gets the first move (perhaps this should be 50/50)
1138 setYourTurn ( ni
-> stats
);
1139 clearYourTurn ( battle
-> stats
);
1141 // Initiate Battle sequence!
1142 ni
-> stats
-> player_fights
-= 1 ;
1144 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1145 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1146 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first " \
1147 "because they initiated!" , ni
-> stats
-> name
);
1148 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1152 void do_use ( char * u
)
1157 char * item
= strtok ( NULL
, " " );
1161 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1162 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1165 else if (!( user
= find ( u
)))
1167 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1170 else if (! is_playing ( user
))
1172 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1176 p
= & user
-> stats
-> inventory
;
1178 if ( stricmp ( item
, "HEALTH" ) == 0 )
1180 if ( p
-> Healing () <= 0 )
1182 notice ( s_GameServ
, u
, "You are out of Health Potions!" );
1185 int oldhealth
= user
-> stats
-> hp
;
1186 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1187 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1188 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1189 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealth
);
1192 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1194 if ( p
-> Strength () <= 0 )
1196 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1199 int oldstrength
= user
-> stats
-> strength
;
1200 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1201 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1202 user
-> stats
-> strength
+= 1 + rand () % 2 ; // 1 - 2 Strength Added
1203 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1206 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1208 if ( p
-> Defense () <= 0 )
1210 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1213 int olddefense
= user
-> stats
-> defense
;
1214 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1215 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1216 user
-> stats
-> defense
+= 1 + rand () % 2 ; // 1 - 2 Defense Added
1217 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1220 else if ( stricmp ( item
, "HP" ) == 0 )
1224 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1227 int oldHP
= user
-> stats
-> maxhp
;
1228 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1229 user
-> stats
-> maxhp
+= 1 + rand () % 5 ; // 1 - 5 Maxhp
1230 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1235 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALTH | STRENGTH | DEFENSE}" );
1239 end_turn ( user
); // If they're fighting, end their turn
1241 void do_run ( char * u
)
1244 Player
* p
, * p2
= NULL
;
1246 if (!( user
= find ( u
)))
1248 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1252 else if (! is_playing ( user
))
1254 notice ( s_GameServ
, u
, "You must be playing to run!" );
1261 p2
= p
-> battle
-> stats
;
1263 if (! is_fighting ( user
))
1264 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1265 else if (! player_fight ( user
) && ! master_fight ( user
))
1267 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1271 else if ( player_fight ( user
) && isYourTurn ( p
))
1273 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1274 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1277 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1279 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1281 else if ( master_fight ( user
))
1283 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1288 void end_turn ( aClient
* user
)
1290 char * nick
, * u
= user
-> getNick ();
1295 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1297 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1300 if (! player_fight ( user
) && ! master_fight ( user
))
1301 fight
= user
-> stats
-> fight
;
1303 fight
= user
-> stats
-> master
;
1304 battle
= user
-> stats
-> battle
;
1306 if (! player_fight ( user
))
1309 mhit
= ( fight
-> strength
/ 2 ) +
1310 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1311 arbonus
[ user
-> stats
-> armor
]));
1316 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1317 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1318 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1320 if (! player_fight ( user
))
1325 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1326 fight
-> name
, fight
-> weapon
, mhit
);
1329 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1331 if ( mhit
>= user
-> stats
-> hp
)
1333 if (! master_fight ( user
))
1335 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1336 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1337 "of your experience!" );
1338 user
-> stats
-> gold
= 0 ;
1339 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1340 user
-> stats
-> fight
= NULL
;
1341 clearAlive ( user
-> stats
);
1346 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1347 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1348 user
-> stats
-> fight
= NULL
;
1349 user
-> stats
-> master
= NULL
;
1356 user
-> stats
-> hp
-= mhit
;
1363 clearYourTurn ( user
-> stats
);
1364 setYourTurn ( battle
-> stats
);
1365 display_players ( battle
);
1371 void do_attack ( char * u
)
1374 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1375 Monster
* fight
; // The monster they may be fighting
1377 if (!( ni
= find ( u
)))
1379 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1382 else if (! is_playing ( ni
))
1384 notice ( s_GameServ
, u
, "You're not playing!" );
1387 else if (! is_fighting ( ni
))
1389 notice ( s_GameServ
, u
, "You're not in battle!" );
1394 if (! ni
-> stats
-> master
) // This is not a master fight
1395 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1396 else // This IS a master fight
1397 fight
= ni
-> stats
-> master
; // Master Could be NULL
1399 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1401 // One has to be !NULL based on the previous else if
1402 // We wouldn't be here if they were all NULL
1405 if (! player_fight ( ni
))
1408 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1409 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1412 mhit
= ( fight
-> strength
/ 2 ) +
1413 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1414 arbonus
[ ni
-> stats
-> armor
]));
1419 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1420 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1421 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1424 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1425 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1426 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1429 if (! player_fight ( ni
))
1432 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1434 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1436 if ( hit
>= fight
-> hp
)
1438 if ( master_fight ( ni
))
1439 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1441 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1443 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1444 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1445 fight
-> exp
, fight
-> gold
);
1447 // If your new experience (or gold) will be greater than 2 billion,
1448 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1449 // This could be a problem with overflowing out of the sign bit.
1450 // Unsigned long int maybe? Leave it for now.
1451 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1452 ni
-> stats
-> exp
+ fight
-> exp
);
1454 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1455 ni
-> stats
-> gold
+ fight
-> gold
);
1458 if ( master_fight ( ni
))
1460 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1461 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1462 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1464 // Increase your level
1467 // Increase your maximum hit points
1468 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1470 // Heal the player by setting hp to their max
1471 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1473 // Add to your strength
1474 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1476 // Add to your defensive power
1477 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1479 // Clear the pointer for your master
1480 ni
-> stats
-> master
= NULL
;
1483 // They're dead so remove the pointer
1484 delete ni
-> stats
-> fight
;
1485 ni
-> stats
-> fight
= NULL
;
1486 ni
-> stats
-> master
= NULL
;
1496 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1497 fight
-> name
, fight
-> weapon
, mhit
);
1500 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1502 if ( mhit
>= ni
-> stats
-> hp
)
1504 if (! master_fight ( ni
))
1506 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1507 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1508 "of your experience!" );
1509 ni
-> stats
-> gold
= 0 ;
1510 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1511 ni
-> stats
-> fight
= NULL
;
1512 clearAlive ( ni
-> stats
);
1517 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1518 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1519 ni
-> stats
-> fight
= NULL
;
1520 ni
-> stats
-> master
= NULL
;
1527 ni
-> stats
-> hp
-= mhit
;
1533 else if ( player_fight ( ni
))
1535 /* Offline fighting not available yet
1536 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1539 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1541 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1542 if (hit >= battle->stats->hp)
1544 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1545 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1546 (long int)(battle->stats->exp * .10), battle->stats->gold);
1547 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1549 ni->stats->exp += (long int)(battle->stats->exp * .10);
1550 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1554 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1555 ni->stats->exp = 2000000000;
1558 if (2000000000 - ni->stats->gold > battle->stats->gold)
1560 * ni->stats->gold += battle->stats->gold;
1561 battle->stats->gold = 0;
1565 battle->stats->gold = 2000000000 - ni->stats->gold;
1566 ni->stats->gold = 2000000000;
1568 * ni->stats->battle->stats->alive = 0;
1569 ni->stats->battle->battle = NULL;
1570 ni->stats->battle = NULL;
1576 * battle->stats->hp -= hit;
1579 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1580 battle->nick, weapons[battle->stats->weapon], mhit);
1583 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1585 if (mhit >= ni->stats->hp)
1587 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1588 if (2000000000 - battle->stats->gold > ni->stats->gold)
1590 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1591 battle->stats->gold += ni->stats->gold;
1592 * ni->stats->gold = 0;
1596 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1598 ni->stats->gold -= (2000000000 - battle->stats->gold);
1599 notice(s_GameServ, u, "You were left dead with %d gold.",
1600 * (long int)ni->stats->gold);
1601 battle->stats->gold = 2000000000;
1603 ni->stats->battle->battle = NULL;
1604 ni->stats->battle = NULL;
1605 ni->stats->alive = 0;
1611 ni->stats->hp -= mhit;
1617 * end offline fighting */
1619 if ( is_playing ( battle
))
1621 if (! isYourTurn ( ni
-> stats
))
1623 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1624 battle
-> stats
-> name
);
1629 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1631 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1632 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1633 weapons
[ ni
-> stats
-> weapon
], hit
);
1634 clearYourTurn ( ni
-> stats
);
1635 setYourTurn ( battle
-> stats
);
1636 display_players ( battle
-> getNick ());
1640 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1641 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1642 clearYourTurn ( ni
-> stats
);
1643 setYourTurn ( battle
-> stats
);
1644 display_players ( battle
-> getNick ());
1646 if ( hit
>= battle
-> stats
-> hp
)
1648 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1649 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1650 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1651 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1653 battle
-> stats
-> hp
= 0 ;
1654 clearAlive ( battle
-> stats
);
1656 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1658 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1659 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1663 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1664 ni
-> stats
-> exp
= 2000000000 ;
1667 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1669 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1670 "all gold on hand!" );
1671 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1672 battle
-> stats
-> gold
= 0 ;
1676 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1677 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1679 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1680 "gold." , ni
-> stats
-> name
);
1682 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1683 "left. All is not lost!" , battle
-> stats
-> gold
);
1685 ni
-> stats
-> gold
= 2000000000 ;
1687 battle
-> stats
-> battle
= NULL
;
1688 ni
-> stats
-> battle
= NULL
;
1694 battle
-> stats
-> hp
-= hit
;
1695 clearYourTurn ( ni
-> stats
);
1696 setYourTurn ( battle
-> stats
);
1697 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1698 battle
-> stats
-> name
);
1706 void do_heal ( char * u
)
1709 char * amount
= strtok ( NULL
, " " );
1714 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1716 else if (!( ni
= find ( u
)))
1718 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1721 else if (! is_playing ( ni
))
1723 notice ( s_GameServ
, u
, "You aren't playing!" );
1726 else if (! isAlive ( ni
-> stats
))
1728 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1731 else if ( is_fighting ( ni
))
1733 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1735 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1737 notice ( s_GameServ
, u
, "You don't need healing!" );
1739 else if ( stricmp ( amount
, "ALL" ) == 0 )
1741 price
= ni
-> stats
-> level
* 3 ;
1742 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1744 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1745 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1746 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1747 ni
-> stats
-> gold
%= price
;
1751 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1752 "per point." , price
);
1753 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1754 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1755 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1756 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1757 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1760 else if ( isstringnum ( amount
))
1762 num
= stringtoint ( amount
);
1763 price
= ni
-> stats
-> level
* 3 ;
1764 if ( ni
-> stats
-> gold
< price
* num
)
1766 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1767 ( long int ) ni
-> stats
-> gold
/ price
);
1769 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1771 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
1773 ni
-> stats
-> hp
+= num
;
1774 ni
-> stats
-> gold
-= num
* price
;
1776 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1778 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1779 "per point." , price
);
1780 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
1781 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
1782 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1783 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1786 else if ( amount
[ 0 ] == '-' )
1787 notice ( s_GameServ
, u
, "You trying to cheat?" );
1789 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1792 int isstringnum ( char * num
)
1795 for ( x
= 0 ; x
< strlen ( num
); x
++)
1797 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
1803 long int stringtoint ( char * number
)
1805 long int x
, len
= strlen ( number
), sum
= 0 ;
1807 return chartoint ( number
[ 0 ]);
1808 sum
+= chartoint ( number
[ len
- 1 ]);
1809 for ( x
= len
- 2 ; x
>= 0 ; x
--)
1810 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
1814 long int pow ( int x
, int y
)
1820 if ( x
!= 0 && y
!= 0 )
1822 for ( count
= 1 ; count
<= y
- 1 ; count
++)
1830 long int chartoint ( char ch
)
1832 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
1833 return int ( ch
) - 48 ;
1840 ListNode
< aClient
> * ptr
;
1844 outfile
. open ( playerdata
);
1848 log ( "Error opening %s " , playerdata
);
1852 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
1854 ptr
= players
[ x
]. First ();
1857 it
= ptr
-> getData ()-> stats
;
1858 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
1859 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
1860 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
1861 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
1862 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
1863 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
1876 char * tempname
, * buf
, * password
;
1877 buf
= new char [ 1023 ];
1879 infile
. open ( playerdata
);
1883 log ( "Error opening %s " , playerdata
);
1887 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
1890 tempname
= strtok ( buf
, " " );
1891 temp
-> stats
= new Player ( tempname
);
1894 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
1895 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
1896 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
1897 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
1898 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
1899 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
1900 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
1901 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
1902 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
1903 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
1904 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
1905 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
1906 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
1908 password
= strtok ( NULL
, " " );
1909 strcpy ( p
-> password
, password
);
1910 temp
-> setNick ( "!NULL!" );
1912 temp
-> setRealNick ( "!NULL!" );
1915 p
-> inventory
. reset (); // Set inventory to all 0s
1916 // Old player databases didn't have these three extra values
1917 // If they come up null, leave them to 0 as the default.
1918 // On the next gameserv database save, it will save the values.
1919 tempname
= strtok ( NULL
, " " );
1921 p
-> inventory
. setHealing ( stringtoint ( tempname
));
1923 tempname
= strtok ( NULL
, " " );
1925 p
-> inventory
. setStrength ( stringtoint ( tempname
));
1927 tempname
= strtok ( NULL
, " " );
1929 p
-> inventory
. setDefense ( stringtoint ( tempname
));
1931 tempname
= strtok ( NULL
, " " );
1933 p
-> inventory
. setHP ( stringtoint ( tempname
));
1934 temp
-> stats
-> user
= NULL
;
1935 unsigned long hv
= HASH (( unsigned char *) temp
-> stats
-> name
, U_TABLE_SIZE
);
1936 players
[ hv
]. insertAtBack ( temp
);
1944 bool passcmp ( char * encrypted
, char * plaintext
)
1947 char * plaintext2
, * plainToencrypt
;
1950 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
1951 strcpy ( plaintext2
, plaintext
);
1953 salt
[ 0 ] = encrypted
[ 0 ];
1954 salt
[ 1 ] = encrypted
[ 1 ];
1957 plainToencrypt
= crypt ( plaintext2
, salt
);
1959 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
1961 delete [] plaintext2
;
1966 bool check_password ( char * name
, char * plaintext
)
1970 if (!( client
= findplayer ( name
)))
1974 return passcmp ( client
-> stats
-> password
, plaintext
);
1978 void do_store ( char * u
)
1980 char * cmd
= strtok ( NULL
, " " );
1981 char * item
= strtok ( NULL
, " " );
1982 char * num
= strtok ( NULL
, " " );
1990 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
1991 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
1992 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
1994 else if (!( user
= find ( u
)) || ! is_playing ( user
))
1995 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
1996 else if (! isAlive ( user
-> stats
))
1998 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
2001 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2003 if ( stricmp ( item
, "WEAPONS" ) == 0 )
2005 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2006 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
2007 for ( int x
= 1 ; x
< WNA
; x
++)
2009 space
= spaces ( strlen ( weapons
[ x
]), "." );
2010 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
2013 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
2014 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
2017 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2019 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
2020 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
2021 for ( int x
= 1 ; x
< WNA
; x
++)
2023 space
= spaces ( strlen ( armors
[ x
]), "." );
2024 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
2027 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
2028 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
2032 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
2035 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2038 else if (! isstringnum ( num
))
2040 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
2043 if ( stricmp ( item
, "WEAPON" ) == 0 )
2045 wep
= stringtoint ( num
);
2046 if ( wep
>= WNA
|| wep
< 1 )
2048 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2055 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
2056 else if ( p
-> gold
< prices
[ wep
- 1 ])
2057 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
2060 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
2062 p
-> gold
-= prices
[ wep
- 1 ];
2065 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2067 wep
= stringtoint ( num
);
2068 if ( wep
>= WNA
|| wep
< 1 )
2070 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
2077 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
2078 else if ( p
-> gold
< prices
[ wep
- 1 ])
2079 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
2082 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
2084 p
-> gold
-= prices
[ wep
- 1 ];
2088 else if ( stricmp ( cmd
, "SELL" ) == 0 )
2092 if ( stricmp ( item
, "WEAPON" ) == 0 )
2096 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
2099 else if ( p
-> gold
== 2000000000 )
2101 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2104 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
2106 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2107 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
2108 p
-> gold
= 2000000000 ;
2113 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
2114 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
2118 else if ( stricmp ( item
, "ARMOR" ) == 0 )
2124 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
2127 if ( p
-> gold
== 2000000000 )
2129 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2132 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2134 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2135 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2136 p
-> gold
= 2000000000 ;
2141 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2142 ( prices
[ p
-> armor
- 1 ] / 2 ));
2144 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2150 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2151 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2152 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2156 void do_inventory ( char * u
)
2160 if (!( user
= find ( u
)))
2162 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2165 else if (! is_playing ( user
))
2167 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2170 showinventory ( user
, user
);
2172 void showinventory ( aClient
* from
, aClient
* to
)
2174 char * nick
= to
-> getNick ();
2178 if ( is_playing ( from
))
2180 Pouch
* p
= & from
-> stats
-> inventory
;
2181 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2182 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2183 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2184 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2185 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2188 void do_tavern ( char * u
)
2190 char * cmd
= strtok ( NULL
, " " );
2195 if (!( user
= find ( u
)))
2197 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2200 else if (! is_playing ( user
))
2202 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2205 else if ( is_fighting ( user
))
2207 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2213 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2214 notice ( s_GameServ
, u
, "Your commands:" );
2215 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2216 notice ( s_GameServ
, u
, "What'll it be?" );
2218 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2220 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2221 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 1000 * p
-> level
+ ( p
-> exp
/ 10 ));
2222 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 2050 * p
-> level
+ ( p
-> exp
/ 10 ));
2223 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 2000 * p
-> level
+ ( p
-> exp
/ 10 ));
2224 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 2300 * p
-> level
+ ( p
-> exp
/ 10 ));
2225 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2226 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2227 notice ( s_GameServ
, u
, "By something will ya!" );
2229 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2231 char * chnum
= strtok ( NULL
, " " );
2232 int num
= stringtoint ( chnum
);
2236 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2237 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2240 if ( num
< 1 || num
> 4 )
2242 notice ( s_GameServ
, u
, "Invalid Choice!" );
2243 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2244 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 1000 * p
-> level
+ ( p
-> exp
/ 10 ));
2245 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 2050 * p
-> level
+ ( p
-> exp
/ 10 ));
2246 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 2000 * p
-> level
+ ( p
-> exp
/ 10 ));
2247 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 2300 * p
-> level
+ ( p
-> exp
/ 10 ));
2248 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2249 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2255 price
= ( 1000 * p
-> level
) + ( p
-> exp
/ 10 );
2256 if ( p
-> gold
>= price
)
2258 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2259 p
-> inventory
. incHealing ();
2263 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2266 price
= ( 2050 * p
-> level
) + ( p
-> exp
/ 10 );
2267 if ( p
-> gold
>= price
)
2269 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2270 p
-> inventory
. incStrength ();
2274 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2277 price
= ( 2000 * p
-> level
) + ( p
-> exp
/ 10 );
2278 if ( p
-> gold
>= price
)
2280 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2281 p
-> inventory
. incDefense ();
2285 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2288 price
= ( 2300 * p
-> level
) + ( p
-> exp
/ 10 );
2289 if ( p
-> gold
>= price
)
2291 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2292 p
-> inventory
. incHP ();
2296 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2299 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2305 notice ( s_GameServ
, u
, "Improper Syntax." );
2306 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2310 void do_bank ( char * u
)
2312 char * cmd
= strtok ( NULL
, " " );
2313 char * amount
= strtok ( NULL
, " " );
2314 char * nick
= strtok ( NULL
, " " );
2319 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2321 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2322 notice ( s_GameServ
, u
, "BANK BALANCE" );
2327 if (! is_playing ( user
))
2329 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2332 else if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2337 else if (! isAlive ( user
-> stats
))
2339 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2342 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2344 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2350 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2352 if ( p
-> bank
== 2000000000 )
2354 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2357 else if ( stricmp ( amount
, "ALL" ) == 0 )
2359 if ( 2000000000 - p
-> bank
< p
-> gold
)
2361 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2362 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2363 p
-> gold
-= ( 2000000000 - p
-> bank
);
2364 p
-> bank
= 2000000000 ;
2369 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2375 else if ( stringtoint ( amount
) > p
-> gold
)
2377 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2383 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2385 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2386 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2387 p
-> gold
-= ( 2000000000 - p
-> bank
);
2388 p
-> bank
= 2000000000 ;
2393 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2394 p
-> bank
+= stringtoint ( amount
);
2395 p
-> gold
-= stringtoint ( amount
);
2400 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2402 if ( p
-> gold
== 2000000000 )
2404 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2408 else if ( stricmp ( amount
, "ALL" ) == 0 )
2410 if ( 2000000000 - p
-> gold
< p
-> bank
)
2412 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2413 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2414 p
-> bank
-= ( 2000000000 - p
-> gold
);
2415 p
-> gold
= 2000000000 ;
2420 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2426 else if ( stringtoint ( amount
) > p
-> bank
)
2428 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2434 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2436 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2437 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2438 ( 2000000000 - p
-> gold
));
2439 p
-> bank
-= ( 2000000000 - p
-> gold
);
2440 p
-> gold
= 2000000000 ;
2445 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2446 p
-> gold
+= stringtoint ( amount
);
2447 p
-> bank
-= stringtoint ( amount
);
2455 void do_master ( char * u
)
2462 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2465 else if ( is_fighting ( user
))
2467 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2470 else if (! isAlive ( user
-> stats
))
2472 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2475 else if (! is_playing ( user
))
2477 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2481 char * cmd
= strtok ( NULL
, " " );
2482 Player
* p
= user
-> stats
;
2487 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2530 notice ( s_GameServ
, u
, "You are at level 12. You are the master. What's left? The DRAGON!" );
2533 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2539 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2543 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2551 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
));
2554 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2557 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
);
2559 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2565 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2569 void see_master ( char * u
)
2573 if (!( user
= find ( u
)))
2575 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2579 if (! is_fighting ( user
) && is_playing ( user
))
2581 Player
* p
= user
-> stats
;
2582 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2583 p
-> fight
= p
-> master
;
2584 display_monster ( u
); // Since master is the same structure, use this function
2588 void showBankBalance ( const char * u
)
2593 if (!( user
= find ( u
)))
2601 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2607 ListNode
< aClient
> * it
;
2609 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2611 it
= players
[ x
]. First ();
2615 p
= it
-> getData ()-> stats
;
2622 void refresh ( Player
* p
)
2627 if ( p
-> hp
< p
-> maxhp
)
2629 p
-> forest_fights
= forestfights
;
2630 p
-> player_fights
= 3 ;
2635 void do_refresh ( char * u
)
2637 char * nick
= strtok ( NULL
, " " );
2640 if (!( user
= find ( u
)))
2642 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2643 log ( "Error: aClient not found: %s " , u
);
2646 else if (! isAdmin ( user
))
2648 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2653 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
2656 else if ( stricmp ( nick
, "ALL" ) == 0 )
2658 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
2661 else if (( user
= findbyrealnick ( nick
)))
2663 if ( is_playing ( user
))
2666 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
2668 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
2670 refresh ( user
-> stats
);
2675 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2677 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2683 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2691 ListNode
< aClient
> * it
;
2694 for ( unsigned long x
= 0 ; x
< U_TABLE_SIZE
; x
++)
2696 it
= players
[ x
]. First ();
2700 p
= it
-> getData ()-> stats
;
2707 void reset ( Player
* p
)
2715 void do_reset ( char * u
)
2717 char * nick
= strtok ( NULL
, " " );
2720 if (!( user
= find ( u
)))
2722 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2723 log ( "Error: aClient not found: %s " , u
);
2726 else if (! isAdmin ( user
))
2728 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2733 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
2736 else if ( stricmp ( nick
, "ALL" ) == 0 )
2738 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
2741 else if (( user
= findbyrealnick ( nick
)))
2743 if ( is_playing ( user
))
2746 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
2748 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
2755 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2757 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2763 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2768 void do_help ( char * u
)
2770 char * cmd
= strtok ( NULL
, " " );
2772 display_help ( u
, cmd
);
2775 void display_help ( char * u
, char * file
)
2782 infile
. open ( "helpfiles/help" );
2785 log ( "Error opening helpfiles/help" );
2786 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
2789 buf
= new char [ 1024 ];
2790 while ( infile
. getline ( buf
, 1024 ))
2792 // Written this way, it will process %S in the helpfiles
2793 // Instead of notice(s_GameServ, u, "%s", buf);
2794 notice ( s_GameServ
, u
, buf
);
2798 aClient
* user
= find ( u
);
2799 if ( user
&& isAdmin ( user
))
2800 display_help ( u
, "admin_commands" );
2805 filename
= new char [ strlen ( file
) + 11 ];
2806 strcpy ( filename
, "helpfiles/" );
2807 strcat ( filename
, file
);
2809 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
2810 filename
[ x
] = tolower ( filename
[ x
]);
2812 infile
. open ( filename
);
2816 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
2819 buf
= new char [ 1024 ];
2820 while ( infile
. getline ( buf
, 1024 ))
2822 // Written this way, it will process %S in the helpfiles
2823 // Instead of notice(s_GameServ, u, "%s", buf);
2824 notice ( s_GameServ
, u
, buf
);
2831 void do_admin ( char * u
)
2834 char * pass
= strtok ( NULL
, " " );
2836 if (!( user
= find ( u
)))
2838 log ( "Error: aClient not found: %s " , u
);
2839 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
2844 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
2850 notice ( s_GameServ
, u
, "You already have administrator privledges." );
2853 else if ( strcmp ( pass
, adminpass
) == 0 )
2855 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
2858 log ( " %s became an administrator." , user
-> getRealNick ());
2860 log ( " %s became an administrator." , user
-> getNick ());
2865 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
2870 bool load_monsters ()
2873 infile
. open ( "monsters.dat" );
2879 log ( "Error opening monsters.dat" );
2883 buf
= new char [ 2048 ];
2886 log ( "Loading monsters from monsters.dat" );
2889 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
2891 for ( int m
= 0 ; m
< MONSTERS
;)
2893 infile
. getline ( buf
, 2048 );
2894 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
2898 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
2899 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
2900 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
2901 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
2902 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
2903 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
2904 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
2905 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));
2914 // this will be hash.cpp start
2915 // thank you wcampbel
2916 unsigned long HASH ( const unsigned char * name
, int size_of_table
)
2918 unsigned long h
= 0 , g
;
2922 h
= ( h
<< 4 ) + tolower (* name
++);
2923 if (( g
= ( h
& 0xF0000000 )))
2927 return h
% size_of_table
;
2930 // this will be hash.cpp end