]>
jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
14 #if defined(HAVE_CRYPT_H)
18 #elif defined(HAVE_UNISTD_H)
24 List
< aClient
> players
;
26 Monster
* monsters
[ LEVELS
][ MONSTERS
]; // Monsters per level. Total = MONSTERS * LEVELS
28 Monster
* masters
[ LEVELS
]; // A master for each level
36 char * strtok ( char * str
, const char * delim
);
39 int stricmp ( const char * s1
, const char * s2
);
40 int strnicmp ( const char * s1
, const char * s2
, size_t len
);
44 /********** Password functions **********/
46 bool passcmp ( char * encrypted
, char * plaintext
); // Compares an encrypted pass with a plain text one
48 bool check_password ( char * name
, char * plaintext
); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
50 /********** Password functions **********/
53 /********** GameServ Booleans **********/
55 bool is_playing ( char * u
); // True if the given nickname in the clients list is playing.
56 bool is_playing ( aClient
* user
);
58 bool is_fighting ( char * u
); // True if the given nick in the clients list is fighting anything.
59 bool is_fighting ( aClient
* user
);
61 bool player_fight ( char * u
); // True if the player is fighting another player.
62 bool player_fight ( aClient
* user
);
64 bool master_fight ( char * u
); // True if the player is fighting their master.
65 bool master_fight ( aClient
* user
);
67 /********** GameServ Booleans **********/
69 void display_help ( char * u
, char * file
= NULL
);
70 void display_monster ( char * u
);
71 void display_players ( char * u
);
72 void display_players ( aClient
* user
);
73 long int chartoint ( char ch
);
74 int isstringnum ( char * num
);
75 long int pow ( int x
, int y
);
76 long int stringtoint ( char * number
);
78 char * spaces ( int len
, char * seperator
);
79 void refresh ( Player
* p
);
81 void reset ( Player
* p
);
85 void delete_monsters ();
86 void delete_masters ();
88 void do_admin ( char * u
);
89 void do_attack ( char * u
);
90 void do_bank ( char * u
);
91 void do_fight ( char * u
);
92 void do_heal ( char * u
);
93 void do_help ( char * u
);
94 void do_identify ( char * u
);
95 void do_inventory ( char * u
);
96 void do_refresh ( char * u
);
97 void do_register ( char * u
);
98 void do_list ( char * u
);
99 void do_master ( char * u
);
100 void do_play ( char * u
);
101 void do_quitg ( char * u
);
102 void do_reset ( char * u
);
103 void do_run ( char * u
);
104 void do_stats ( char * u
);
105 void do_store ( char * u
);
106 void do_tavern ( char * u
);
107 void do_use ( char * u
);
108 void see_master ( char * u
);
110 void showstats ( const char * u
, const char * nick
);
111 void showinventory ( aClient
* from
, aClient
* to
);
112 void showBankBalance ( const char * u
);
113 void end_turn ( aClient
* user
);
116 char * weapons
[ WNA
] = { "Fists" , "Stick" , "Dagger" , "Quarterstaff" , "Short Sword" ,
117 "Long Sword" , "Silver Spear" , "Battle Axe" , "The Ragnarok" ,
118 "Chain Saw" , "Poison Sword" , "Flame Sword" , "Earth Hammer" ,
119 "Light Saber" , "Masamune" , "Mystical Sword" };
121 char * armors
[ WNA
] = { "Nothing" , "Clothes" , "Leather Vest" , "Chain Mail" , "Plate Armor" ,
122 "Full Body Armor" , "Magic Mail" , "Graphite Suit" , "Steel Suit" ,
123 "Force Field" , "Armor of Light" , "Mythril Vest" , "DemiGod Armor" ,
124 "Hades' Cloak" , "Dragon Scales" , "Adamantium" };
126 int prices
[ WNA
- 1 ] = { 200 , 1000 , 3000 , 10000 , 30000 , 100000 , 150000 , 200000 , 400000 ,
127 1000000 , 4000000 , 10000000 , 40000000 , 100000000 , 400000000 };
128 int webonus
[ WNA
] = { 0 , 10 , 15 , 25 , 35 , 45 , 65 , 85 , 125 , 185 , 255 , 355 , 505 , 805 , 1205 , 1805 };
129 int arbonus
[ WNA
] = { 0 , 1 , 3 , 10 , 15 , 25 , 35 , 50 , 75 , 100 , 150 , 225 , 300 , 400 , 600 , 1000 };
131 int hpbonus
[ 11 ] = { 10 , 15 , 20 , 30 , 50 , 75 , 125 , 185 , 250 , 350 , 550 };
132 int strbonus
[ 11 ] = { 5 , 7 , 10 , 12 , 20 , 35 , 50 , 75 , 110 , 150 , 200 };
133 int defbonus
[ 11 ] = { 2 , 3 , 5 , 10 , 15 , 22 , 35 , 60 , 80 , 120 , 150 };
135 void gameserv ( char * source
, char * buf
)
138 cmd
= strtok ( buf
, " " );
141 source
++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
145 cmd
++; // Get rid of that : at the beginning of the :text (command)
148 log ( "Source: %s Command: %s " , source
, cmd
);
156 int curday
= tm
-> tm_mday
;
165 if ( strnicmp ( cmd
, "\1PING" , 6 ) == 0 )
168 ts
= strtok ( NULL
, "\1" );
169 notice ( s_GameServ
, source
, "\1PING %s \1" , ts
);
170 } else if ( stricmp ( cmd
, "\1VERSION\1" ) == 0 ) {
171 notice ( s_GameServ
, source
, "\1VERSION %s %s +devel\1" , PACKAGE
, VERSION
);
172 } else if ( stricmp ( cmd
, "SEARCH" ) == 0 ) {
173 cmd
= strtok ( NULL
, " " );
176 notice ( s_GameServ
, source
, "SYNTAX: /msg %S SEARCH FOREST" );
180 } else if ( stricmp ( cmd
, "FIGHT" ) == 0 ) {
182 } else if ( stricmp ( cmd
, "ATTACK" ) == 0 ) {
184 } else if ( stricmp ( cmd
, "RUN" ) == 0 ) {
186 } else if ( stricmp ( cmd
, "USE" ) == 0 ) {
188 } else if ( stricmp ( cmd
, "HEAL" ) == 0 ) {
190 } else if ( stricmp ( cmd
, "INVENTORY" ) == 0 ) {
191 do_inventory ( source
);
192 } else if ( stricmp ( cmd
, "MASTER" ) == 0 ) {
194 } else if ( stricmp ( cmd
, "STORE" ) == 0 ) {
196 } else if ( stricmp ( cmd
, "BANK" ) == 0 ) {
198 } else if ( stricmp ( cmd
, "ADMIN" ) == 0 ) {
200 } else if ( stricmp ( cmd
, "REFRESH" ) == 0 ) {
202 } else if ( stricmp ( cmd
, "RESET" ) == 0 ) {
204 } else if ( stricmp ( cmd
, "TAVERN" ) == 0 ) {
206 } else if ( stricmp ( cmd
, "LIST" ) == 0 ) {
209 } else if ( stricmp ( cmd
, "PRINT" ) == 0 ) {
210 cout
<< "Printing the clients list:" << endl
;
212 cout
<< " \n Printing the players list:" << endl
;
215 } else if ( stricmp ( cmd
, "REGISTER" ) == 0 ) {
217 } else if ( stricmp ( cmd
, "IDENTIFY" ) == 0 ) {
219 } else if ( stricmp ( cmd
, "HELP" ) == 0 ) {
221 } else if ( stricmp ( cmd
, "STATS" ) == 0 ) {
223 } else if ( stricmp ( cmd
, "SHUTDOWN" ) == 0 ) {
226 if (!( user
= find ( source
)))
228 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
229 log ( "Error: aClient not found: %s " , source
);
231 else if (! isAdmin ( user
))
233 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
239 raw ( "[] SQ %s 0 :leaving: %s used the Shutdown command." , servername
, user
-> getRealNick ());
241 raw ( "SQUIT %s :leaving: %s used the Shutdown command." , servername
, source
);
244 } else if ( stricmp ( cmd
, "SAVE" ) == 0 ) {
247 if (!( user
= find ( source
)))
249 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
250 log ( "Error: aClient not found: %s " , source
);
252 else if (! isAdmin ( user
))
254 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
260 } else if ( stricmp ( cmd
, "LOAD" ) == 0 ) {
263 if (!( user
= find ( source
)))
265 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
266 log ( "Error: aClient not found: %s " , source
);
268 else if (! isAdmin ( user
))
270 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
274 char * cmd2
= strtok ( NULL
, " " );
277 notice ( s_GameServ
, source
, "Loading player data from %s " , playerdata
);
280 else if ( stricmp ( cmd2
, "MONSTERS" ) == 0 )
282 notice ( s_GameServ
, source
, "Loading monster data from %s " , monsterdata
);
286 display_help ( source
, cmd
);
288 } else if ( stricmp ( cmd
, "RAW" ) == 0 ) {
291 if (!( user
= find ( source
)))
293 notice ( s_GameServ
, source
, "Error: aClient not found. Contact a %S admin" );
294 log ( "Error: aClient not found: %s " , source
);
296 else if (! isAdmin ( user
))
298 notice ( s_GameServ
, source
, "You must be a %S admin to use this command!" );
302 char * rest
= strtok ( NULL
, "" );
306 notice ( s_GameServ
, source
, "Unknown command \002 %s \002 . Type /msg %S \002 HELP \002 to get a list of commands." , cmd
);
309 source
--; // Bring the ':' back so we don't leak memory
310 cmd
--; // Same thing :)
313 int stricmp ( const char * s1
, const char * s2
)
317 while (( c
= tolower (* s1
)) == tolower (* s2
)) {
323 if ( c
< tolower (* s2
))
328 void showstats ( const char * u
, const char * nick
)
330 aClient
* ni
, * sender
= find ( u
);
336 if (!( ni
= findplayer ( nick
)))
338 notice ( s_GameServ
, u
, " %s not found" , nick
);
342 notice ( s_GameServ
, sender
-> getNick (), "Stats for %s :" , ni
-> stats
-> name
);
344 sprintf ( buf
, "Experience: %l d" , ni
-> stats
-> exp
);
345 space
= spaces ( strlen ( buf
), " " );
346 notice ( s_GameServ
, sender
-> getNick (), " %s%s Level: %d " , buf
, space
,
350 sprintf ( buf
, "Gold: %l d" , ni
-> stats
-> gold
);
351 space
= spaces ( strlen ( buf
), " " );
352 notice ( s_GameServ
, sender
-> getNick (), " %s%s Gold in Bank: %l d" , buf
, space
, ni
-> stats
-> bank
);
355 notice ( s_GameServ
, sender
-> getNick (), "Hit Points: %d of %d " , ni
-> stats
-> hp
,
358 sprintf ( buf
, "Strength: %d " , ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]);
359 space
= spaces ( strlen ( buf
), " " );
360 notice ( s_GameServ
, sender
-> getNick (), " %s%s Defense: %d " ,
361 buf
, space
, ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]);
364 sprintf ( buf
, "Armor: %s " , armors
[ ni
-> stats
-> armor
]);
365 space
= spaces ( strlen ( buf
), " " );
366 notice ( s_GameServ
, sender
-> getNick (), " %s%s Weapon: %s " , buf
, space
,
367 weapons
[ ni
-> stats
-> weapon
]);
370 sprintf ( buf
, "Forest Fights: %d " , ni
-> stats
-> forest_fights
);
371 space
= spaces ( strlen ( buf
), " " );
372 notice ( s_GameServ
, sender
-> getNick (), " %s%s Player Fights: %d " , buf
, space
, ni
-> stats
-> player_fights
);
377 notice ( s_GameServ
, u
, " %s is not playing!" , ni
-> stats
-> name
);
382 char * spaces ( int len
, char * seperator
)
385 final
= new char [ 30 ];
387 strcpy ( final
, seperator
);
388 for ( y
= 0 ; y
< 30 - len
; y
++)
389 strcat ( final
, seperator
);
393 void raw ( const char * fmt
, ...)
398 input
= new char [ 1024 ];
400 memset ( input
, 0 , sizeof ( input
)); // Initialize to NULL
406 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
407 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
408 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
411 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
416 sprintf ( input
, " %s%c " , input
, * t
);
421 log ( "Input: %s " , input
);
424 sprintf ( input
, " %s%s " , input
, " \r\n " );
425 sock_puts ( sock
, input
);
429 /* Send a NOTICE from the given source to the given nick. */
431 void notice ( const char * source
, const char * dest
, const char * fmt
, ...)
439 input
= new char [ 1024 ];
446 sprintf ( input
, ": %s NOTICE %s :" , source
, dest
);
448 sprintf ( input
, " %s O %s :" , gsnum
, dest
);
456 sprintf ( input
, ": %s NOTICE %s :" , source
, dest
);
458 sprintf ( input
, " %s O %s :" , gsnum
, dest
);
467 case 'd' : sprintf ( input
, " %s%d " , input
, va_arg ( args
, int )); break ;
468 case 's' : sprintf ( input
, " %s%s " , input
, va_arg ( args
, char *)); break ;
469 case 'S' : sprintf ( input
, " %s%s " , input
, s_GameServ
); break ;
472 sprintf ( input
, " %s%l d" , input
, va_arg ( args
, long int )); break ;
477 sprintf ( input
, " %s%c " , input
, * t
);
482 log ( "Input: %s " , input
);
484 sprintf ( input
, " %s%s " , input
, " \r\n " );
485 sock_puts ( sock
, input
);
491 int strnicmp ( const char * s1
, const char * s2
, size_t len
)
497 while (( c
= tolower (* s1
)) == tolower (* s2
) && len
> 0 ) {
498 if ( c
== 0 || -- len
== 0 )
503 if ( c
< tolower (* s2
))
509 char * strtok ( char * str
, const char * delim
)
511 static char * current
= NULL
;
518 current
+= strspn ( current
, delim
);
519 ret
= * current
? current
: NULL
;
520 current
+= strcspn ( current
, delim
);
529 void do_list ( char * u
)
531 ListNode
< aClient
> * temp
;
532 temp
= players
. First ();
533 if (! players
. isEmpty ())
535 notice ( s_GameServ
, u
, "People Playing:" );
540 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getRealNick (),
541 temp
-> getData ()-> stats
-> name
);
543 notice ( s_GameServ
, u
, "IRC: %s Game: %s " , temp
-> getData ()-> getNick (),
544 temp
-> getData ()-> stats
-> name
);
549 notice ( s_GameServ
, u
, "End of List" );
552 notice ( s_GameServ
, u
, "No one is playing" );
555 void do_register ( char * u
)
557 char * password
, * name
;
559 name
= strtok ( NULL
, " " );
560 password
= strtok ( NULL
, " " );
562 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./" ;
565 salt
[ 0 ] = saltChars
[ rand () % strlen ( saltChars
)];
566 salt
[ 1 ] = saltChars
[ rand () % strlen ( saltChars
)];
571 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
575 notice ( s_GameServ
, u
, "SYNTAX: /msg %S REGISTER NAME PASSWORD" );
577 else if (( user
= find ( u
)))
580 if (! user
-> stats
&& ! p
)
582 user
-> stats
= new Player ( user
);
583 user
-> stats
-> user
= user
; // Set the backwards pointer
584 strcpy ( user
-> stats
-> password
, crypt ( password
, salt
));
585 strcpy ( user
-> stats
-> name
, name
);
586 players
. insertAtBack ( user
);
587 notice ( s_GameServ
, u
, "Player %s registered with password %s ." , user
-> stats
-> name
, password
);
588 notice ( s_GameServ
, u
, "Write this password down. If you lose it, there is no way to retrieve it!" );
589 log ( "Nickname %s registered player %s ." , u
, user
-> stats
-> name
);
593 notice ( s_GameServ
, u
, "Already registered. Contact a %S admin for help." );
598 void do_identify ( char * u
)
600 char * password
, * name
;
602 name
= strtok ( NULL
, " " );
603 password
= strtok ( NULL
, " " );
605 if (! password
|| ! name
)
607 notice ( s_GameServ
, u
, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD" );
611 notice ( s_GameServ
, u
, "Fatal error. Cannot find aClient. Buf: %s " , strtok ( NULL
, "" ));
612 log ( "Error: aClient not found: %s " , u
);
614 else if (!( p
= findplayer ( name
)) || ! p
-> stats
)
615 notice ( s_GameServ
, u
, "Player %s not found" , name
);
616 else if (! check_password ( name
, password
) && ! isAdmin ( user
))
618 notice ( s_GameServ
, u
, "Password incorrect" );
622 if ( p
-> stats
-> user
&& ! isAdmin ( user
))
624 notice ( s_GameServ
, u
, "That player has already identified." );
629 ListNode
< aClient
> * temp
;
630 temp
= players
. Find ( p
);
633 notice ( s_GameServ
, u
, "Fatal error. Contact %S Admin. Buf: %s " ,
637 user
-> stats
= new Player ( p
-> stats
-> name
);
639 log ( "Setting data for identified" );
641 user
-> stats
-> setData ( p
-> stats
);
644 log ( "Player Identified" );
649 notice ( s_GameServ
, u
, "Password Accepted. Identified." );
654 notice ( s_GameServ
, u
, "Already identified. Contact a %S admin for help." );
659 void do_stats ( char * u
)
664 nick
= strtok ( NULL
, " " );
668 if (!( user
= find ( u
)))
670 notice ( s_GameServ
, u
, "Fatal Error in do_stats(). Contact a %S admin for help!" );
671 log ( "Error: aClient not found: %s " , u
);
674 else if (! is_playing ( user
))
676 notice ( s_GameServ
, u
, "You're not playing, so you have no stats!" );
680 showstats ( u
, user
-> stats
-> name
);
688 log ( "Calling delete_masters()" );
694 log ( "Initializing masters" );
697 for ( int x
= 0 ; x
< LEVELS
; x
++)
698 masters
[ x
] = new Monster
;
700 strcpy ( masters
[ 0 ]-> name
, "Old Bones" );
701 strcpy ( masters
[ 0 ]-> weapon
, "Dull Sword Cane" );
702 masters
[ 0 ]-> strength
= 15 ;
703 masters
[ 0 ]-> gold
= 0 ;
705 masters
[ 0 ]-> maxhp
= 30 ;
707 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!" );
709 strcpy ( masters
[ 1 ]-> name
, "Master Chang" );
710 strcpy ( masters
[ 1 ]-> weapon
, "Nanchaku" );
711 masters
[ 1 ]-> strength
= 30 ;
712 masters
[ 1 ]-> gold
= 0 ;
714 masters
[ 1 ]-> maxhp
= 40 ;
716 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." );
718 strcpy ( masters
[ 2 ]-> name
, "Chuck Norris" );
719 strcpy ( masters
[ 2 ]-> weapon
, "Ranger Kick" );
720 masters
[ 2 ]-> strength
= 85 ;
721 masters
[ 2 ]-> gold
= 0 ;
723 masters
[ 2 ]-> maxhp
= 70 ;
725 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!" );
728 strcpy ( masters
[ 3 ]-> name
, "Mr. Miagi" );
729 strcpy ( masters
[ 3 ]-> weapon
, "Petrified Bonsai" );
730 masters
[ 3 ]-> strength
= 120 ;
731 masters
[ 3 ]-> gold
= 0 ;
733 masters
[ 3 ]-> maxhp
= 120 ;
734 masters
[ 3 ]-> hp
= 120 ;
735 strcpy ( masters
[ 3 ]-> death
, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!" );
737 strcpy ( masters
[ 4 ]-> name
, "Jackie Chan" );
738 strcpy ( masters
[ 4 ]-> weapon
, "Kung Fu Kick" );
739 masters
[ 4 ]-> strength
= 135 ;
740 masters
[ 4 ]-> gold
= 0 ;
742 masters
[ 4 ]-> maxhp
= 200 ;
743 masters
[ 4 ]-> hp
= 200 ;
744 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!" );
746 strcpy ( masters
[ 5 ]-> name
, "Jet Li" );
747 strcpy ( masters
[ 5 ]-> weapon
, "Motorcycle" );
748 masters
[ 5 ]-> strength
= 160 ;
749 masters
[ 5 ]-> gold
= 0 ;
751 masters
[ 5 ]-> maxhp
= 400 ;
752 masters
[ 5 ]-> hp
= 400 ;
753 strcpy ( masters
[ 5 ]-> death
, "Failure is a fuel for excuses. It's the doing the do, that makes the making." );
756 strcpy ( masters
[ 6 ]-> name
, "Muhammad Ali" );
757 strcpy ( masters
[ 6 ]-> weapon
, "Quick Jab" );
758 masters
[ 6 ]-> strength
= 185 ;
759 masters
[ 6 ]-> gold
= 0 ;
761 masters
[ 6 ]-> maxhp
= 600 ;
762 masters
[ 6 ]-> hp
= 600 ;
763 strcpy ( masters
[ 6 ]-> death
, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up." );
765 strcpy ( masters
[ 7 ]-> name
, "Li Mu Bai" );
766 strcpy ( masters
[ 7 ]-> weapon
, "Green Destiny" );
767 masters
[ 7 ]-> strength
= 210 ;
768 masters
[ 7 ]-> gold
= 0 ;
770 masters
[ 7 ]-> maxhp
= 800 ;
771 masters
[ 7 ]-> hp
= 800 ;
772 strcpy ( masters
[ 7 ]-> death
, "No growth without resistance. No action without reaction. No desire without restraint." );
775 strcpy ( masters
[ 8 ]-> name
, "Jimmy Wang Yu" );
776 strcpy ( masters
[ 8 ]-> weapon
, "Flying Guillotine" );
777 masters
[ 8 ]-> strength
= 275 ;
778 masters
[ 8 ]-> gold
= 0 ;
780 masters
[ 8 ]-> maxhp
= 1200 ;
781 masters
[ 8 ]-> hp
= 1200 ;
782 strcpy ( masters
[ 8 ]-> death
, "You have beaten the one armed boxer. Proceed with caution!" );
784 strcpy ( masters
[ 9 ]-> name
, "Wong Fei Hung" );
785 strcpy ( masters
[ 9 ]-> weapon
, "Drunken Boxing" );
786 masters
[ 9 ]-> strength
= 360 ;
787 masters
[ 9 ]-> gold
= 0 ;
789 masters
[ 9 ]-> maxhp
= 1800 ;
790 masters
[ 9 ]-> hp
= 1800 ;
791 strcpy ( masters
[ 9 ]-> death
, "Hiccup! Monkey drinks master's wine!" );
793 strcpy ( masters
[ 10 ]-> name
, "Bruce Lee" );
794 strcpy ( masters
[ 10 ]-> weapon
, "Fists of fury" );
795 masters
[ 10 ]-> strength
= 575 ;
796 masters
[ 10 ]-> gold
= 0 ;
797 masters
[ 10 ]-> exp
= 0 ;
798 masters
[ 10 ]-> maxhp
= 2500 ;
799 masters
[ 10 ]-> hp
= 2500 ;
800 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." );
806 log ( "Calling delete_monsters" );
811 for ( int x
= 0 ; x
< LEVELS
; x
++)
812 for ( int y
= 0 ; y
< MONSTERS
; y
++)
813 monsters
[ x
][ y
] = new Monster ();
816 void delete_monsters ()
818 for ( int x
= 0 ; x
< LEVELS
; x
++)
819 for ( int y
= 0 ; y
< MONSTERS
; y
++)
821 delete monsters
[ x
][ y
];
824 void delete_masters ()
826 for ( int x
= 0 ; x
< LEVELS
; x
++)
831 void display_monster ( char * u
)
835 aClient
* user
= find ( u
);
836 Player
* ni
= user
-> stats
;
838 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> hp
);
839 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", ni
-> fight
-> name
, ni
-> fight
-> hp
);
840 notice ( s_GameServ
, u
, "Here are your commands:" );
841 notice ( s_GameServ
, u
, "/msg %S attack" );
842 notice ( s_GameServ
, u
, "/msg %S run" );
843 notice ( s_GameServ
, u
, "What will you do?" );
847 void display_players ( char * u
)
851 aClient
* ni
= find ( u
);
853 aClient
* battle
= ni
-> stats
-> battle
;
855 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", ni
-> stats
-> hp
);
856 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
,
858 notice ( s_GameServ
, u
, "Here are your commands:" );
859 notice ( s_GameServ
, u
, "/msg %S attack" );
860 notice ( s_GameServ
, u
, "/msg %S run" );
861 notice ( s_GameServ
, u
, "What will you do?" );
864 void display_players ( aClient
* user
)
866 char * u
= user
-> getNick ();
867 if ( is_playing ( user
) && player_fight ( user
))
869 aClient
* battle
= user
-> stats
-> battle
;
870 notice ( s_GameServ
, u
, "Your Hitpoints: \ 2 %d \ 2 ", user
-> stats
-> hp
);
871 notice ( s_GameServ
, u
, " %s 's Hitpoints: \ 2 %d \ 2 ", battle
-> stats
-> name
, battle
-> stats
-> hp
);
872 notice ( s_GameServ
, u
, "Here are your commands:" );
873 notice ( s_GameServ
, u
, "/msg %S attack" );
874 notice ( s_GameServ
, u
, "/msg %S run" );
875 notice ( s_GameServ
, u
, "What will you do?" );
880 bool is_playing ( char * u
)
883 if (!( user
= find ( u
)))
889 return user
-> stats
!= NULL
;
893 bool is_playing ( aClient
* user
)
895 return user
-> stats
!= NULL
&& ( stricmp ( user
-> getNick (), "!NULL!" ) != 0 );
898 bool is_fighting ( char * u
)
902 if (!( user
= find ( u
)))
906 else if ( user
-> stats
)
908 return user
-> stats
-> fight
!= NULL
|| user
-> stats
-> battle
!= NULL
909 || user
-> stats
-> master
!= NULL
;
914 bool is_fighting ( aClient
* user
)
916 if (! is_playing ( user
))
919 return ( user
-> stats
-> fight
!= NULL
|| user
-> stats
-> battle
!= NULL
|| user
-> stats
-> master
!= NULL
);
922 bool player_fight ( char * u
)
926 if (!( user
= find ( u
)))
928 else if ( user
-> stats
)
929 return user
-> stats
-> battle
!= NULL
;
933 bool player_fight ( aClient
* user
)
935 if (! is_fighting ( user
))
938 return user
-> stats
-> battle
!= NULL
;
941 bool master_fight ( char * u
)
945 if (!( user
= find ( u
)))
947 else if ( user
-> stats
)
948 return user
-> stats
-> master
!= NULL
;
952 bool master_fight ( aClient
* user
)
954 if (! is_playing ( user
))
957 return user
-> stats
-> master
!= NULL
;
960 void do_fight ( char * u
)
962 aClient
* ni
, * battle
;
964 char * nick
= strtok ( NULL
, " " );
968 notice ( s_GameServ
, u
, "SYNTAX: /msg %S FIGHT PLAYER" );
970 else if (!( ni
= find ( u
)))
972 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
975 else if (!( battle
= findbyrealnick ( nick
)))
977 notice ( s_GameServ
, u
, "You can't attack %s while they aren't playing!" , nick
);
980 else if (! is_playing ( ni
))
982 notice ( s_GameServ
, u
, "You are not playing!" );
986 * Offline fighting not implemented yet.
987 * else if (!(fight = finduser(nick)))
989 * ni->stats->battle = battle;
990 * battle->battle = ni;
992 * battle->yourturn = 0;
993 * notice(s_GameServ, u, "You decide to fight %s while they're not online!",
994 * battle->stats->name);
995 * display_players(u);
998 else if (! isAlive ( ni
-> stats
))
1000 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to fight others!" );
1003 else if ( player_fight ( battle
))
1005 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> battle
-> stats
-> name
);
1008 else if ( is_fighting ( battle
))
1010 notice ( s_GameServ
, u
, " %s is fighting %s already!" , battle
-> stats
-> name
, battle
-> stats
-> fight
-> name
);
1013 else if ( is_playing ( ni
) && is_playing ( battle
) && stricmp ( ni
-> stats
-> name
, battle
-> stats
-> name
) != 0 )
1015 // Set your battle pointer to the other player
1016 ni
-> stats
-> battle
= battle
;
1018 // Set the other player's battle pointer to you
1019 battle
-> stats
-> battle
= ni
;
1021 // The initiator gets the first move (perhaps this should be 50/50)
1022 setYourTurn ( ni
-> stats
);
1023 clearYourTurn ( battle
-> stats
);
1025 // Initiate Battle sequence!
1026 notice ( s_GameServ
, u
, "You challenge %s to an online duel!" , battle
-> stats
-> name
);
1027 notice ( s_GameServ
, battle
-> getNick (), " %s has challenged you to an online duel!" , ni
-> stats
-> name
);
1028 notice ( s_GameServ
, battle
-> getNick (), " %s gets to go first because he initiated!" , ni
-> stats
-> name
);
1029 notice ( s_GameServ
, battle
-> getNick (), "Please wait while %s decides what to do." , ni
-> stats
-> name
);
1033 void do_use ( char * u
)
1038 char * item
= strtok ( NULL
, " " );
1042 notice ( s_GameServ
, u
, "SYNTAX: USE ITEM" );
1043 notice ( s_GameServ
, u
, "Type /msg %S HELP USE for more information." );
1046 else if (!( user
= find ( u
)))
1048 notice ( s_GameServ
, u
, "Fatal Error in do_use. Contact a(n) %S Admin" );
1051 else if (! is_playing ( user
))
1053 notice ( s_GameServ
, u
, "You must be playing to use items!" );
1057 p
= & user
-> stats
-> inventory
;
1059 if ( stricmp ( item
, "HEALTH" ) == 0 )
1061 if ( p
-> Healing () <= 0 )
1063 notice ( s_GameServ
, u
, "You are out of Health Potions!" );
1066 int oldhealth
= user
-> stats
-> hp
;
1067 notice ( s_GameServ
, u
, "You hastiliy gulp down the flask of cool life-giving waters." );
1068 notice ( s_GameServ
, u
, "Rejuvination spreads throughout your body." );
1069 user
-> stats
-> hp
+= ( 10 * user
-> stats
-> level
) + ( rand () % 10 ) * user
-> stats
-> level
;
1070 notice ( s_GameServ
, u
, "You gain %d HP!" , user
-> stats
-> hp
- oldhealth
);
1073 else if ( stricmp ( item
, "STRENGTH" ) == 0 )
1075 if ( p
-> Strength () <= 0 )
1077 notice ( s_GameServ
, u
, "You are out of Strength Potions!" );
1080 int oldstrength
= user
-> stats
-> strength
;
1081 notice ( s_GameServ
, u
, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!" );
1082 notice ( s_GameServ
, u
, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!" );
1083 user
-> stats
-> strength
+= 1 + rand () % 2 ; // 1 - 2 Strength Added
1084 notice ( s_GameServ
, u
, "You gain %d Strength points!" , user
-> stats
-> strength
- oldstrength
);
1087 else if ( stricmp ( item
, "DEFENSE" ) == 0 )
1089 if ( p
-> Defense () <= 0 )
1091 notice ( s_GameServ
, u
, "You are out of Defense Potions!" );
1094 int olddefense
= user
-> stats
-> defense
;
1095 notice ( s_GameServ
, u
, "You drink the foul tasting viscous liquid while pinching your nose in disgust." );
1096 notice ( s_GameServ
, u
, "It tasted bad, but you feel like you are unbeatable!" );
1097 user
-> stats
-> defense
+= 1 + rand () % 2 ; // 1 - 2 Defense Added
1098 notice ( s_GameServ
, u
, "You gain %d Defense points!" , user
-> stats
-> defense
- olddefense
);
1101 else if ( stricmp ( item
, "HP" ) == 0 )
1105 notice ( s_GameServ
, u
, "You are out of HP Potions!" );
1108 int oldHP
= user
-> stats
-> maxhp
;
1109 notice ( s_GameServ
, u
, "You feel your life growing longer as you drink the green glowing liquid." );
1110 user
-> stats
-> maxhp
+= 1 + rand () % 5 ; // 1 - 5 Maxhp
1111 notice ( s_GameServ
, u
, "You gain %d Maximum hit points!" , user
-> stats
-> maxhp
- oldHP
);
1116 notice ( s_GameServ
, u
, "SYNTAX: /msg %S USE {HEALTH | STRENGTH | DEFENSE}" );
1120 end_turn ( user
); // If they're fighting, end their turn
1122 void do_run ( char * u
)
1125 Player
* p
, * p2
= NULL
;
1127 if (!( user
= find ( u
)))
1129 notice ( s_GameServ
, u
, "Couldn't find you. Error. Contact a %S admin" );
1136 p2
= p
-> battle
-> stats
;
1138 if (! is_fighting ( user
))
1139 notice ( s_GameServ
, u
, "You run in place... try fighting next time." );
1140 else if (! player_fight ( user
) && ! master_fight ( user
))
1142 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p
-> fight
-> name
);
1146 else if ( player_fight ( user
) && isYourTurn ( p
))
1148 notice ( s_GameServ
, u
, "You run away from \ 2 %s \ 2 like a little baby!", p2
-> name
);
1149 notice ( s_GameServ
, p
-> battle
-> getNick (), "\ 2 %s \ 2 ran away from you like a little baby!", p
-> name
);
1152 else if ( player_fight ( user
) && ! isYourTurn ( p
))
1154 notice ( s_GameServ
, u
, "It is not your turn. Please wait until \ 2 %s \ 2 decides what to do.", p2
-> name
);
1156 else if ( master_fight ( user
))
1158 notice ( s_GameServ
, u
, "You cannot run from \ 2 %s \ 2 ! FIGHT!", p
-> master
-> name
);
1163 void end_turn ( aClient
* user
)
1165 char * nick
, * u
= user
-> getNick ();
1170 nick
= new char [ strlen ( user
-> getNick ()) + 1 ];
1172 if (! user
|| ! is_playing ( user
) || ! is_fighting ( user
))
1175 if (! player_fight ( user
) && ! master_fight ( user
))
1176 fight
= user
-> stats
-> fight
;
1178 fight
= user
-> stats
-> master
;
1179 battle
= user
-> stats
-> battle
;
1181 if (! player_fight ( user
))
1184 mhit
= ( fight
-> strength
/ 2 ) +
1185 ( rand () % ( fight
-> strength
/ 2 ) - ( user
-> stats
-> defense
+
1186 arbonus
[ user
-> stats
-> armor
]));
1191 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1192 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1193 ( user
-> stats
-> defense
+ arbonus
[ user
-> stats
-> armor
]));
1195 if (! player_fight ( user
))
1200 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1201 fight
-> name
, fight
-> weapon
, mhit
);
1204 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1206 if ( mhit
>= user
-> stats
-> hp
)
1208 if (! master_fight ( user
))
1210 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1211 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1212 "of your experience!" );
1213 user
-> stats
-> gold
= 0 ;
1214 user
-> stats
-> exp
-= ( long int )( user
-> stats
-> exp
* .10 );
1215 user
-> stats
-> fight
= NULL
;
1216 clearAlive ( user
-> stats
);
1221 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1222 "until tomorrow to try again" , user
-> stats
-> master
-> name
);
1223 user
-> stats
-> fight
= NULL
;
1224 user
-> stats
-> master
= NULL
;
1231 user
-> stats
-> hp
-= mhit
;
1238 clearYourTurn ( user
-> stats
);
1239 setYourTurn ( battle
-> stats
);
1240 display_players ( battle
);
1246 void do_attack ( char * u
)
1249 aClient
* ni
, * battle
; // The player and perhaps the player they're fighting
1250 Monster
* fight
; // The monster they may be fighting
1252 if (!( ni
= find ( u
)))
1254 notice ( s_GameServ
, u
, "Fatal error in do_attack. Contact a(n) %S admin for help." );
1257 else if (! is_playing ( ni
))
1259 notice ( s_GameServ
, u
, "You're not playing!" );
1262 else if (! is_fighting ( ni
))
1264 notice ( s_GameServ
, u
, "You're not in battle!" );
1269 if (! ni
-> stats
-> master
) // This is not a master fight
1270 fight
= ni
-> stats
-> fight
; // Monster Could be NULL
1271 else // This IS a master fight
1272 fight
= ni
-> stats
-> master
; // Master Could be NULL
1274 battle
= ni
-> stats
-> battle
; // Player Could be NULL
1276 // One has to be !NULL based on the previous else if
1277 // We wouldn't be here if they were all NULL
1280 if (! player_fight ( ni
))
1283 hit
= (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1284 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ));
1287 mhit
= ( fight
-> strength
/ 2 ) +
1288 ( rand () % ( fight
-> strength
/ 2 ) - ( ni
-> stats
-> defense
+
1289 arbonus
[ ni
-> stats
-> armor
]));
1294 mhit
= ((( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
]) / 2 ) +
1295 ( rand () % (( battle
-> stats
-> strength
+ webonus
[ battle
-> stats
-> weapon
])) / 2 ) -
1296 ( ni
-> stats
-> defense
+ arbonus
[ ni
-> stats
-> armor
]));
1299 hit
= ((( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
]) / 2 ) +
1300 ( rand () % (( ni
-> stats
-> strength
+ webonus
[ ni
-> stats
-> weapon
])) / 2 ) -
1301 ( battle
-> stats
-> defense
+ arbonus
[ battle
-> stats
-> armor
]));
1304 if (! player_fight ( ni
))
1307 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", fight
-> name
, hit
);
1309 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", fight
-> name
);
1311 if ( hit
>= fight
-> hp
)
1313 if ( master_fight ( ni
))
1314 notice ( s_GameServ
, u
, "You have bested %s !" , fight
-> name
);
1316 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", fight
-> name
);
1318 notice ( s_GameServ
, u
, " %s " , fight
-> death
);
1319 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %d \ 2 gold!",
1320 fight
-> exp
, fight
-> gold
);
1322 // If your new experience (or gold) will be greater than 2 billion,
1323 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1324 // This could be a problem with overflowing out of the sign bit.
1325 // Unsigned long int maybe? Leave it for now.
1326 ni
-> stats
-> exp
= ( ( ni
-> stats
-> exp
+ fight
-> exp
) > 2000000000 ? 2000000000 :
1327 ni
-> stats
-> exp
+ fight
-> exp
);
1329 ni
-> stats
-> gold
= ( ni
-> stats
-> gold
+ fight
-> gold
> 2000000000 ? 2000000000 :
1330 ni
-> stats
-> gold
+ fight
-> gold
);
1333 if ( master_fight ( ni
))
1335 notice ( s_GameServ
, u
, "You are now level %d !" , ni
-> stats
-> level
+ 1 );
1336 notice ( s_GameServ
, u
, "You gain %d Strength, and %d Defense points!" ,
1337 strbonus
[ ni
-> stats
-> level
- 1 ], defbonus
[ ni
-> stats
-> level
- 1 ]);
1339 // Increase your level
1342 // Increase your maximum hit points
1343 ni
-> stats
-> maxhp
+= hpbonus
[ ni
-> stats
-> level
- 1 ];
1345 // Heal the player by setting hp to their max
1346 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1348 // Add to your strength
1349 ni
-> stats
-> strength
+= strbonus
[ ni
-> stats
-> level
- 1 ];
1351 // Add to your defensive power
1352 ni
-> stats
-> defense
+= defbonus
[ ni
-> stats
-> level
- 1 ];
1354 // Clear the pointer for your master
1355 ni
-> stats
-> master
= NULL
;
1358 // They're dead so remove the pointer
1359 delete ni
-> stats
-> fight
;
1360 ni
-> stats
-> fight
= NULL
;
1361 ni
-> stats
-> master
= NULL
;
1371 notice ( s_GameServ
, u
, "\1f %s \1f attacks with their \1f %s \1f for \ 2 %d \ 2 damage!",
1372 fight
-> name
, fight
-> weapon
, mhit
);
1375 notice ( s_GameServ
, u
, " %s completely misses you!" , fight
-> name
);
1377 if ( mhit
>= ni
-> stats
-> hp
)
1379 if (! master_fight ( ni
))
1381 notice ( s_GameServ
, u
, "You have been \ 2 \1f killed\1f \ 2 by %s !" , fight
-> name
);
1382 notice ( s_GameServ
, u
, "You lose all gold on hand and lose 10 percent " \
1383 "of your experience!" );
1384 ni
-> stats
-> gold
= 0 ;
1385 ni
-> stats
-> exp
-= ( long int )( ni
-> stats
-> exp
* .10 );
1386 ni
-> stats
-> fight
= NULL
;
1387 clearAlive ( ni
-> stats
);
1392 notice ( s_GameServ
, u
, " %s has bested you! You will have to wait " \
1393 "until tomorrow to try again" , ni
-> stats
-> master
-> name
);
1394 ni
-> stats
-> fight
= NULL
;
1395 ni
-> stats
-> master
= NULL
;
1402 ni
-> stats
-> hp
-= mhit
;
1408 else if ( player_fight ( ni
))
1410 /* Offline fighting not available yet
1411 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1414 notice(s_GameServ, u, "You attack \1f %s\1f for \ 2 %d\ 2 points!", battle->nick, hit);
1416 notice(s_GameServ, u, "You miss \1f %s\1f completely!", battle->nick);
1417 if (hit >= battle->stats->hp)
1419 notice(s_GameServ, u, "You have killed \ 2 %s\ 2 !", battle->nick);
1420 * notice(s_GameServ, u, "You recieve \ 2 %d\ 2 experience and \ 2 %ld\ 2 gold!",
1421 (long int)(battle->stats->exp * .10), battle->stats->gold);
1422 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1424 ni->stats->exp += (long int)(battle->stats->exp * .10);
1425 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1429 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1430 ni->stats->exp = 2000000000;
1433 if (2000000000 - ni->stats->gold > battle->stats->gold)
1435 * ni->stats->gold += battle->stats->gold;
1436 battle->stats->gold = 0;
1440 battle->stats->gold = 2000000000 - ni->stats->gold;
1441 ni->stats->gold = 2000000000;
1443 * ni->stats->battle->stats->alive = 0;
1444 ni->stats->battle->battle = NULL;
1445 ni->stats->battle = NULL;
1451 * battle->stats->hp -= hit;
1454 notice(s_GameServ, u, "\1f %s\1f hits you with their \1f %s\1f for \ 2 %d\ 2 damage!",
1455 battle->nick, weapons[battle->stats->weapon], mhit);
1458 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1460 if (mhit >= ni->stats->hp)
1462 notice(s_GameServ, u, "You have been \ 2 \1f killed\1f \ 2 by %s!", battle->nick);
1463 if (2000000000 - battle->stats->gold > ni->stats->gold)
1465 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1466 battle->stats->gold += ni->stats->gold;
1467 * ni->stats->gold = 0;
1471 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1473 ni->stats->gold -= (2000000000 - battle->stats->gold);
1474 notice(s_GameServ, u, "You were left dead with %d gold.",
1475 * (long int)ni->stats->gold);
1476 battle->stats->gold = 2000000000;
1478 ni->stats->battle->battle = NULL;
1479 ni->stats->battle = NULL;
1480 ni->stats->alive = 0;
1486 ni->stats->hp -= mhit;
1492 * end offline fighting */
1494 if ( is_playing ( battle
))
1496 if (! isYourTurn ( ni
-> stats
))
1498 notice ( s_GameServ
, u
, "Please wait until %s decides what to do!" ,
1499 battle
-> stats
-> name
);
1504 notice ( s_GameServ
, u
, "You attack \1f %s \1f for \ 2 %d \ 2 points!", battle
-> stats
-> name
, hit
);
1506 notice ( s_GameServ
, battle
-> getNick (), " %s has hit you with their %s for " \
1507 "\ 2 %d \ 2 damage!", ni
-> stats
-> name
,
1508 weapons
[ ni
-> stats
-> weapon
], hit
);
1509 clearYourTurn ( ni
-> stats
);
1510 setYourTurn ( battle
-> stats
);
1511 display_players ( battle
-> getNick ());
1515 notice ( s_GameServ
, u
, "You miss \1f %s \1f completely!", battle
-> stats
-> name
);
1516 notice ( s_GameServ
, battle
-> getNick (), " %s misses you completely!" , ni
-> stats
-> name
);
1517 clearYourTurn ( ni
-> stats
);
1518 setYourTurn ( battle
-> stats
);
1519 display_players ( battle
-> getNick ());
1521 if ( hit
>= battle
-> stats
-> hp
)
1523 notice ( s_GameServ
, u
, "You have killed \ 2 %s \ 2 !", battle
-> stats
-> name
);
1524 notice ( s_GameServ
, u
, "You recieve \ 2 %d \ 2 experience and \ 2 %l d\ 2 gold!" ,
1525 ( long int )( battle
-> stats
-> exp
* .10 ), battle
-> stats
-> gold
);
1526 notice ( s_GameServ
, battle
-> getNick (), "You have been killed by \ 2 %s \ 2 !",
1528 battle
-> stats
-> hp
= 0 ;
1529 clearAlive ( battle
-> stats
);
1531 if ( 2000000000 - ni
-> stats
-> exp
> ( long int )( battle
-> stats
-> exp
* .10 ))
1533 ni
-> stats
-> exp
+= ( long int )( battle
-> stats
-> exp
* .10 );
1534 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1538 battle
-> stats
-> exp
-= ( long int )( battle
-> stats
-> exp
* .10 );
1539 ni
-> stats
-> exp
= 2000000000 ;
1542 if ( 2000000000 - ni
-> stats
-> gold
> battle
-> stats
-> gold
)
1544 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of experience and " \
1545 "all gold on hand!" );
1546 ni
-> stats
-> gold
+= battle
-> stats
-> gold
;
1547 battle
-> stats
-> gold
= 0 ;
1551 battle
-> stats
-> gold
= 2000000000 - ni
-> stats
-> gold
;
1552 notice ( s_GameServ
, battle
-> getNick (), "You lose ten percent of your experience!" );
1554 notice ( s_GameServ
, battle
-> getNick (), "However, %s could not carry all of your " \
1555 "gold." , ni
-> stats
-> name
);
1557 notice ( s_GameServ
, battle
-> getNick (), "Luckily, you still have \ 2 %l d\ 2 gold " \
1558 "left. All is not lost!" , battle
-> stats
-> gold
);
1560 ni
-> stats
-> gold
= 2000000000 ;
1562 battle
-> stats
-> battle
= NULL
;
1563 ni
-> stats
-> battle
= NULL
;
1569 battle
-> stats
-> hp
-= hit
;
1570 clearYourTurn ( ni
-> stats
);
1571 setYourTurn ( battle
-> stats
);
1572 notice ( s_GameServ
, u
, "Please wait while %s decides what to do!" ,
1573 battle
-> stats
-> name
);
1581 void do_heal ( char * u
)
1584 char * amount
= strtok ( NULL
, " " );
1589 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1591 else if (!( ni
= find ( u
)))
1593 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
1596 else if (! is_playing ( ni
))
1598 notice ( s_GameServ
, u
, "You aren't playing!" );
1601 else if (! isAlive ( ni
-> stats
))
1603 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow for healing." );
1606 else if ( is_fighting ( ni
))
1608 notice ( s_GameServ
, u
, "You can't heal in battle!" );
1610 else if ( ni
-> stats
-> hp
>= ni
-> stats
-> maxhp
)
1612 notice ( s_GameServ
, u
, "You don't need healing!" );
1614 else if ( stricmp ( amount
, "ALL" ) == 0 )
1616 price
= ni
-> stats
-> level
* 3 ;
1617 if ( ni
-> stats
-> gold
< ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
) * price
)
1619 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points for \ 2 %d \ 2 gold per point.",
1620 ( long int ) ni
-> stats
-> gold
/ price
, price
);
1621 ni
-> stats
-> hp
+= ni
-> stats
-> gold
/ price
;
1622 ni
-> stats
-> gold
%= price
;
1626 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1627 "per point." , price
);
1628 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed for \ 2 %l d\ 2 gold. HP at MAX!" ,
1629 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
),
1630 ( price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)) );
1631 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1632 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1635 else if ( isstringnum ( amount
))
1637 num
= stringtoint ( amount
);
1638 price
= ni
-> stats
-> level
* 3 ;
1639 if ( ni
-> stats
-> gold
< price
* num
)
1641 notice ( s_GameServ
, u
, "You only have enough gold to heal \ 2 %d \ 2 points!",
1642 ( long int ) ni
-> stats
-> gold
/ price
);
1644 else if ( num
<= ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1646 notice ( s_GameServ
, u
, "Healing \ 2 %d \ 2 points at \ 2 %d \ 2 gold per point.",
1648 ni
-> stats
-> hp
+= num
;
1649 ni
-> stats
-> gold
-= num
* price
;
1651 else if ( num
> ni
-> stats
-> maxhp
- ni
-> stats
-> hp
)
1653 notice ( s_GameServ
, u
, "Healing all possible points at \ 2 %d \ 2 gold "\
1654 "per point." , price
);
1655 notice ( s_GameServ
, u
, "\ 2 %d \ 2 points healed. HP at MAX!",
1656 ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
));
1657 ni
-> stats
-> gold
-= price
* ( ni
-> stats
-> maxhp
- ni
-> stats
-> hp
);
1658 ni
-> stats
-> hp
= ni
-> stats
-> maxhp
;
1661 else if ( amount
[ 0 ] == '-' )
1662 notice ( s_GameServ
, u
, "You trying to cheat?" );
1664 notice ( s_GameServ
, u
, "SYNTAX: /msg %S HEAL {ALL | #}" );
1667 int isstringnum ( char * num
)
1670 for ( x
= 0 ; x
< strlen ( num
); x
++)
1672 if (( int ) num
[ x
] < 48 || ( int ) num
[ x
] > 57 )
1678 long int stringtoint ( char * number
)
1680 long int x
, len
= strlen ( number
), sum
= 0 ;
1682 return chartoint ( number
[ 0 ]);
1683 sum
+= chartoint ( number
[ len
- 1 ]);
1684 for ( x
= len
- 2 ; x
>= 0 ; x
--)
1685 sum
+= chartoint ( number
[ x
]) * pow ( 10 , abs ( x
- len
+ 1 ));
1689 long int pow ( int x
, int y
)
1695 if ( x
!= 0 && y
!= 0 )
1697 for ( count
= 1 ; count
<= y
- 1 ; count
++)
1705 long int chartoint ( char ch
)
1707 if ( int ( ch
) >= 48 && int ( ch
) <= 57 )
1708 return int ( ch
) - 48 ;
1715 ListNode
< aClient
> * ptr
= players
. First ();
1719 outfile
. open ( playerdata
);
1723 log ( "Error opening %s " , playerdata
);
1729 it
= ptr
-> getData ()-> stats
;
1730 outfile
<< it
-> name
<< ' ' << it
-> level
<< ' ' << it
-> exp
<< ' ' << it
-> gold
<< ' ' << it
-> bank
<< ' '
1731 << it
-> hp
<< ' ' << it
-> maxhp
<< ' ' << it
-> strength
<< ' ' << it
-> defense
<< ' '
1732 << it
-> armor
<< ' ' << it
-> weapon
<< ' '
1733 << it
-> forest_fights
<< ' ' << it
-> player_fights
<< ' '
1734 << it
-> getFlags () << ' ' << it
-> password
<< ' ' << it
-> inventory
. Healing ()
1735 << ' ' << it
-> inventory
. Strength () << ' ' << it
-> inventory
. Defense () << ' ' << it
-> inventory
. HP () << endl
;
1747 char * tempname
, * buf
, * password
;
1748 buf
= new char [ 1023 ];
1750 infile
. open ( playerdata
);
1754 log ( "Error opening %s " , playerdata
);
1758 while ( infile
. getline ( buf
, 1024 , ' \n ' ))
1761 tempname
= strtok ( buf
, " " );
1762 temp
-> stats
= new Player ( tempname
);
1765 p
-> level
= stringtoint ( strtok ( NULL
, " " ));
1766 p
-> exp
= stringtoint ( strtok ( NULL
, " " ));
1767 p
-> gold
= stringtoint ( strtok ( NULL
, " " ));
1768 p
-> bank
= stringtoint ( strtok ( NULL
, " " ));
1769 p
-> hp
= stringtoint ( strtok ( NULL
, " " ));
1770 p
-> maxhp
= stringtoint ( strtok ( NULL
, " " ));
1771 p
-> strength
= stringtoint ( strtok ( NULL
, " " ));
1772 p
-> defense
= stringtoint ( strtok ( NULL
, " " ));
1773 p
-> armor
= stringtoint ( strtok ( NULL
, " " ));
1774 p
-> weapon
= stringtoint ( strtok ( NULL
, " " ));
1775 p
-> forest_fights
= stringtoint ( strtok ( NULL
, " " ));
1776 p
-> player_fights
= stringtoint ( strtok ( NULL
, " " ));
1777 p
-> setFlags ( stringtoint ( strtok ( NULL
, " " )));
1779 password
= strtok ( NULL
, " " );
1780 strcpy ( p
-> password
, password
);
1781 temp
-> setNick ( "!NULL!" );
1783 temp
-> setRealNick ( "!NULL!" );
1786 p
-> inventory
. reset (); // Set inventory to all 0s
1787 // Old player databases didn't have these three extra values
1788 // If they come up null, leave them to 0 as the default.
1789 // On the next gameserv database save, it will save the values.
1790 tempname
= strtok ( NULL
, " " );
1792 p
-> inventory
. setHealing ( stringtoint ( tempname
));
1794 tempname
= strtok ( NULL
, " " );
1796 p
-> inventory
. setStrength ( stringtoint ( tempname
));
1798 tempname
= strtok ( NULL
, " " );
1800 p
-> inventory
. setDefense ( stringtoint ( tempname
));
1802 tempname
= strtok ( NULL
, " " );
1804 p
-> inventory
. setHP ( stringtoint ( tempname
));
1806 players
. insertAtBack ( temp
);
1814 bool passcmp ( char * encrypted
, char * plaintext
)
1817 char * plaintext2
, * plainToencrypt
;
1820 plaintext2
= new char [ strlen ( encrypted
) + strlen ( plaintext
)]; // Extra
1821 strcpy ( plaintext2
, plaintext
);
1823 salt
[ 0 ] = encrypted
[ 0 ];
1824 salt
[ 1 ] = encrypted
[ 1 ];
1827 plainToencrypt
= crypt ( plaintext2
, salt
);
1829 same
= ( strcmp (( const char *) encrypted
, plainToencrypt
) == 0 ? true : false );
1831 delete [] plaintext2
;
1836 bool check_password ( char * name
, char * plaintext
)
1840 if (!( client
= findplayer ( name
)))
1844 return passcmp ( client
-> stats
-> password
, plaintext
);
1848 void do_store ( char * u
)
1850 char * cmd
= strtok ( NULL
, " " );
1851 char * item
= strtok ( NULL
, " " );
1852 char * num
= strtok ( NULL
, " " );
1860 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
1861 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
1862 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
1864 else if (!( user
= find ( u
)) || ! is_playing ( user
))
1865 notice ( s_GameServ
, u
, "You must be playing to use the store!" );
1866 else if (! isAlive ( user
-> stats
))
1868 notice ( s_GameServ
, u
, "You are dead. Wait until tomorrow to purchase weapons and armor!" );
1871 else if ( stricmp ( cmd
, "LIST" ) == 0 )
1873 if ( stricmp ( item
, "WEAPONS" ) == 0 )
1875 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
1876 notice ( s_GameServ
, u
, "Here are the weapons we have available for the killing, sire:" );
1877 for ( int x
= 1 ; x
< WNA
; x
++)
1879 space
= spaces ( strlen ( weapons
[ x
]), "." );
1880 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, weapons
[ x
], space
, prices
[ x
- 1 ]);
1883 notice ( s_GameServ
, u
, "To purchase a weapon, type /msg %S STORE BUY \ 2 NUM\ 2 ." );
1884 notice ( s_GameServ
, u
, "Where num. is the weapon number from the menu above." );
1887 else if ( stricmp ( item
, "ARMOR" ) == 0 )
1889 notice ( s_GameServ
, u
, "Welcome to Kain's Armory" );
1890 notice ( s_GameServ
, u
, "I hope you enjoy the fine armor we have available for your protection:" );
1891 for ( int x
= 1 ; x
< WNA
; x
++)
1893 space
= spaces ( strlen ( armors
[ x
]), "." );
1894 notice ( s_GameServ
, u
, " %s%d . %s%s%d " ,( x
< 10 ? " " : "" ), x
, armors
[ x
], space
, prices
[ x
- 1 ]);
1897 notice ( s_GameServ
, u
, "To purchase armor, type /msg %S store buy armor num." );
1898 notice ( s_GameServ
, u
, "Where num. is the armor number from the menu above." );
1902 } else if ( stricmp ( cmd
, "BUY" ) == 0 ) {
1905 notice ( s_GameServ
, u
, "SYNTAX: \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
1908 else if (! isstringnum ( num
))
1910 notice ( s_GameServ
, u
, "You must specify a number between 1 and %d . Not %s !" , WNA
- 1 , num
);
1913 if ( stricmp ( item
, "WEAPON" ) == 0 )
1915 wep
= stringtoint ( num
);
1916 if ( wep
>= WNA
|| wep
< 1 )
1918 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
1925 notice ( s_GameServ
, u
, "You have to sell your %s first!" , weapons
[ p
-> weapon
]);
1926 else if ( p
-> gold
< prices
[ wep
- 1 ])
1927 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , weapons
[ wep
]);
1930 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , weapons
[ wep
]);
1932 p
-> gold
-= prices
[ wep
- 1 ];
1935 else if ( stricmp ( item
, "ARMOR" ) == 0 )
1937 wep
= stringtoint ( num
);
1938 if ( wep
>= WNA
|| wep
< 1 )
1940 notice ( s_GameServ
, u
, "The number %d is out of range. The number you provide must be between 1 and %d ." , wep
, WNA
- 1 );
1947 notice ( s_GameServ
, u
, "You have to sell your %s first!" , armors
[ p
-> armor
]);
1948 else if ( p
-> gold
< prices
[ wep
- 1 ])
1949 notice ( s_GameServ
, u
, "You don't have enough gold for %s !" , armors
[ wep
]);
1952 notice ( s_GameServ
, u
, "You have purchased %s ! Thanks for the gold!" , armors
[ wep
]);
1954 p
-> gold
-= prices
[ wep
- 1 ];
1958 else if ( stricmp ( cmd
, "SELL" ) == 0 )
1962 if ( stricmp ( item
, "WEAPON" ) == 0 )
1966 notice ( s_GameServ
, u
, "You want me to chop off your hands?" );
1969 else if ( p
-> gold
== 2000000000 )
1971 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
1974 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> weapon
- 1 ] / 2 ))
1976 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
1977 notice ( s_GameServ
, u
, "However, you have no weapon... can I interest you in the %s ?" , weapons
[ WNA
- 1 ]);
1978 p
-> gold
= 2000000000 ;
1983 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no weapon!" , ( prices
[ p
-> weapon
- 1 ] / 2 ));
1984 p
-> gold
+= ( prices
[ p
-> weapon
- 1 ] / 2 );
1988 else if ( stricmp ( item
, "ARMOR" ) == 0 )
1994 notice ( s_GameServ
, u
, "I don't think you can be any more naked..." );
1997 if ( p
-> gold
== 2000000000 )
1999 notice ( s_GameServ
, u
, "You have enough gold. I'll just take that off your hands, sire." );
2002 else if ( 2000000000 - p
-> gold
< ( prices
[ p
-> armor
- 1 ] / 2 ))
2004 notice ( s_GameServ
, u
, "Thank you for your business! You now have as much gold as you can carry." );
2005 notice ( s_GameServ
, u
, "However, you have no armor... can I interest you in %s ?" , armors
[ WNA
- 1 ]);
2006 p
-> gold
= 2000000000 ;
2011 notice ( s_GameServ
, u
, "Thank you for your business! You now have %d more gold but no armor!" ,
2012 ( prices
[ p
-> armor
- 1 ] / 2 ));
2014 p
-> gold
+= ( prices
[ p
-> armor
- 1 ] / 2 );
2020 notice ( s_GameServ
, u
, "SYNTAX: STORE LIST {ARMOR | WEAPONS}" );
2021 notice ( s_GameServ
, u
, " \ 2 STORE SELL {ARMOR | WEAPON}\ 2 " );
2022 notice ( s_GameServ
, u
, " \ 2 STORE BUY {ARMOR | WEAPON} \1f NUMBER\1f \ 2 " );
2026 void do_inventory ( char * u
)
2030 if (!( user
= find ( u
)))
2032 notice ( s_GameServ
, u
, "Fatal Error. Contact a %S admin!" );
2035 else if (! is_playing ( user
))
2037 notice ( s_GameServ
, u
, "You must be playing to check your inventory!" );
2040 showinventory ( user
, user
);
2042 void showinventory ( aClient
* from
, aClient
* to
)
2044 char * nick
= to
-> getNick ();
2048 if ( is_playing ( from
))
2050 Pouch
* p
= & from
-> stats
-> inventory
;
2051 notice ( s_GameServ
, nick
, "Inventory for %s :" , from
-> stats
-> name
);
2052 notice ( s_GameServ
, nick
, " Healing Potions: %d " , p
-> Healing ());
2053 notice ( s_GameServ
, nick
, "Strength Potions: %d " , p
-> Strength ());
2054 notice ( s_GameServ
, nick
, " Defense Potions: %d " , p
-> Defense ());
2055 notice ( s_GameServ
, nick
, " HP Potions: %d " , p
-> HP ());
2058 void do_tavern ( char * u
)
2060 char * cmd
= strtok ( NULL
, " " );
2065 if (!( user
= find ( u
)))
2067 notice ( s_GameServ
, u
, "Fatal Error. See a %S admin for help" );
2070 else if (! is_playing ( user
))
2072 notice ( s_GameServ
, u
, "You must be playing to go to the Tavern" );
2075 else if ( is_fighting ( user
))
2077 notice ( s_GameServ
, u
, "You cannot go to the Tavern during a fight!" );
2083 notice ( s_GameServ
, u
, "Welcome to Boot Liquors Mystic Apothecary" );
2084 notice ( s_GameServ
, u
, "Your commands:" );
2085 notice ( s_GameServ
, u
, "/msg %S TAVERN {LIST | BUY} [NUMBER]" );
2086 notice ( s_GameServ
, u
, "What'll it be?" );
2088 else if ( stricmp ( cmd
, "LIST" ) == 0 )
2090 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2091 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 1000 * p
-> level
+ ( p
-> exp
/ 10 ));
2092 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 2050 * p
-> level
+ ( p
-> exp
/ 10 ));
2093 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 2000 * p
-> level
+ ( p
-> exp
/ 10 ));
2094 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 2300 * p
-> level
+ ( p
-> exp
/ 10 ));
2095 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2096 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2097 notice ( s_GameServ
, u
, "By something will ya!" );
2099 else if ( stricmp ( cmd
, "BUY" ) == 0 )
2101 char * chnum
= strtok ( NULL
, " " );
2102 int num
= stringtoint ( chnum
);
2106 notice ( s_GameServ
, u
, "SYNTAX: TAVERN BUY #" );
2107 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1" );
2110 if ( num
< 1 || num
> 4 )
2112 notice ( s_GameServ
, u
, "Invalid Choice!" );
2113 notice ( s_GameServ
, u
, "Here is a list of what we have to offer:" );
2114 notice ( s_GameServ
, u
, "1. Healing Potions for %l d Gold" , 1000 * p
-> level
+ ( p
-> exp
/ 10 ));
2115 notice ( s_GameServ
, u
, "2. Strength Potions for %l d Gold" , 2050 * p
-> level
+ ( p
-> exp
/ 10 ));
2116 notice ( s_GameServ
, u
, "3. Defense Potions for %l d Gold" , 2000 * p
-> level
+ ( p
-> exp
/ 10 ));
2117 notice ( s_GameServ
, u
, "4. HP Potions for %l d Gold" , 2300 * p
-> level
+ ( p
-> exp
/ 10 ));
2118 notice ( s_GameServ
, u
, "To buy a potion, type /msg %S TAVERN BUY #" );
2119 notice ( s_GameServ
, u
, "Example: /msg %S TAVERN BUY 1 buys a healing potion!" );
2125 price
= ( 1000 * p
-> level
) + ( p
-> exp
/ 10 );
2126 if ( p
-> gold
>= price
)
2128 notice ( s_GameServ
, u
, "One healing potion coming right up!" );
2129 p
-> inventory
. incHealing ();
2133 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2136 price
= ( 2050 * p
-> level
) + ( p
-> exp
/ 10 );
2137 if ( p
-> gold
>= price
)
2139 notice ( s_GameServ
, u
, "One strength boost coming right up!" );
2140 p
-> inventory
. incStrength ();
2144 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2147 price
= ( 2000 * p
-> level
) + ( p
-> exp
/ 10 );
2148 if ( p
-> gold
>= price
)
2150 notice ( s_GameServ
, u
, "One defense boost coming right up!" );
2151 p
-> inventory
. incDefense ();
2155 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2158 price
= ( 2300 * p
-> level
) + ( p
-> exp
/ 10 );
2159 if ( p
-> gold
>= price
)
2161 notice ( s_GameServ
, u
, "One HP Potion coming right up!" );
2162 p
-> inventory
. incHP ();
2166 notice ( s_GameServ
, u
, "You don't have enough gold!" );
2169 notice ( s_GameServ
, u
, "Logical Error. See a %S admin for help!" );
2175 notice ( s_GameServ
, u
, "Improper Syntax." );
2176 notice ( s_GameServ
, u
, "Type /msg %S HELP TAVERN for help" );
2180 void do_bank ( char * u
)
2182 char * cmd
= strtok ( NULL
, " " );
2183 char * amount
= strtok ( NULL
, " " );
2184 char * nick
= strtok ( NULL
, " " );
2189 if (! cmd
|| (! amount
&& stricmp ( cmd
, "BALANCE" ) != 0 ) || ( stricmp ( cmd
, "TRANSFER" ) == 0 && ! nick
))
2191 notice ( s_GameServ
, u
, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}" );
2192 notice ( s_GameServ
, u
, "BANK BALANCE" );
2197 if (! is_playing ( user
))
2199 notice ( s_GameServ
, u
, "You must be playing to use the bank!" );
2202 else if ( stricmp ( cmd
, "BALANCE" ) == 0 )
2207 else if (! isAlive ( user
-> stats
))
2209 notice ( s_GameServ
, u
, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!" );
2212 else if (! isstringnum ( amount
) && stricmp ( amount
, "ALL" ) != 0 )
2214 notice ( s_GameServ
, u
, "I don't know how to convert alphabet letters into currency, sire!" );
2220 if ( stricmp ( cmd
, "DEPOSIT" ) == 0 )
2222 if ( p
-> bank
== 2000000000 )
2224 notice ( s_GameServ
, u
, "Your bank account is full, sire!" );
2227 else if ( stricmp ( amount
, "ALL" ) == 0 )
2229 if ( 2000000000 - p
-> bank
< p
-> gold
)
2231 notice ( s_GameServ
, u
, "You don't have enough room for all of your gold." );
2232 notice ( s_GameServ
, u
, "Depositing %l d gold into your account" , ( 2000000000 - p
-> bank
));
2233 p
-> gold
-= ( 2000000000 - p
-> bank
);
2234 p
-> bank
= 2000000000 ;
2239 notice ( s_GameServ
, u
, "Depositing %l d gold into your account!" , p
-> gold
);
2245 else if ( stringtoint ( amount
) > p
-> gold
)
2247 notice ( s_GameServ
, u
, "Sire, you only have %l d gold!" , p
-> gold
);
2253 if ( 2000000000 - p
-> bank
< stringtoint ( amount
))
2255 notice ( s_GameServ
, u
, "You don't have room in your account for that much." );
2256 notice ( s_GameServ
, u
, "Capping off your account with %l d gold!" , ( 2000000000 - p
-> bank
));
2257 p
-> gold
-= ( 2000000000 - p
-> bank
);
2258 p
-> bank
= 2000000000 ;
2263 notice ( s_GameServ
, u
, "Depositing %d gold into your account!" , stringtoint ( amount
));
2264 p
-> bank
+= stringtoint ( amount
);
2265 p
-> gold
-= stringtoint ( amount
);
2270 else if ( stricmp ( cmd
, "WITHDRAW" ) == 0 )
2272 if ( p
-> gold
== 2000000000 )
2274 notice ( s_GameServ
, u
, "You cannot carry any more gold, sire!" );
2278 else if ( stricmp ( amount
, "ALL" ) == 0 )
2280 if ( 2000000000 - p
-> gold
< p
-> bank
)
2282 notice ( s_GameServ
, u
, "You don't have enough room to carry all that gold." );
2283 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account" , ( 2000000000 - p
-> gold
));
2284 p
-> bank
-= ( 2000000000 - p
-> gold
);
2285 p
-> gold
= 2000000000 ;
2290 notice ( s_GameServ
, u
, "Withdrawing %l d gold from your account!" , p
-> bank
);
2296 else if ( stringtoint ( amount
) > p
-> bank
)
2298 notice ( s_GameServ
, u
, "Sire, you only have %l d gold in the bank!" , p
-> bank
);
2304 if ( 2000000000 - p
-> gold
< stringtoint ( amount
))
2306 notice ( s_GameServ
, u
, "You don't enough have room to carry that much gold!" );
2307 notice ( s_GameServ
, u
, "You fill your pockets with %l d gold!" ,
2308 ( 2000000000 - p
-> gold
));
2309 p
-> bank
-= ( 2000000000 - p
-> gold
);
2310 p
-> gold
= 2000000000 ;
2315 notice ( s_GameServ
, u
, "Withdrawing %d gold from your account!" , stringtoint ( amount
));
2316 p
-> gold
+= stringtoint ( amount
);
2317 p
-> bank
-= stringtoint ( amount
);
2325 void do_master ( char * u
)
2332 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2335 else if ( is_fighting ( user
))
2337 notice ( s_GameServ
, u
, "You're in the middle of a fight! Pay attention!" );
2340 else if (! isAlive ( user
-> stats
))
2342 notice ( s_GameServ
, u
, "You're dead. Wait until tomorrow to see your master!" );
2345 else if (! is_playing ( user
))
2347 notice ( s_GameServ
, u
, "You must be playing to see your master!" );
2351 char * cmd
= strtok ( NULL
, " " );
2352 Player
* p
= user
-> stats
;
2357 notice ( s_GameServ
, u
, "You have already seen your master today. Wait until tomorrow to try again" );
2400 notice ( s_GameServ
, u
, "You are at level 12. You are the master. What's left? The DRAGON!" );
2403 need
= p
-> exp
+ 1 ; // Unknown level... don't let them fight a fake master!
2409 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2413 if ( stricmp ( cmd
, "FIGHT" ) == 0 )
2421 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
));
2424 else if ( stricmp ( cmd
, "QUESTION" ) == 0 )
2427 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
);
2429 notice ( s_GameServ
, u
, "You pathetic fool! You are no match for %s , %s !" , masters
[ p
-> level
- 1 ]-> name
, p
-> name
);
2435 notice ( s_GameServ
, u
, "SYNTAX: MASTER {FIGHT | QUESTION}" );
2439 void see_master ( char * u
)
2443 if (!( user
= find ( u
)))
2445 notice ( s_GameServ
, u
, "Fatal error. Contact a(n) %S admin. buf: %s " , strtok ( NULL
, "" ));
2449 if (! is_fighting ( user
) && is_playing ( user
))
2451 Player
* p
= user
-> stats
;
2452 p
-> master
= new Monster ( masters
[ p
-> level
- 1 ]);
2453 p
-> fight
= p
-> master
;
2454 display_monster ( u
); // Since master is the same structure, use this function
2458 void showBankBalance ( const char * u
)
2463 if (!( user
= find ( u
)))
2471 notice ( s_GameServ
, u
, "Account Balance: %l d Gold On hand: %l d" , p
-> bank
, p
-> gold
);
2477 ListNode
< aClient
> * it
;
2480 it
= players
. First ();
2484 p
= it
-> getData ()-> stats
;
2490 void refresh ( Player
* p
)
2495 if ( p
-> hp
< p
-> maxhp
)
2497 p
-> forest_fights
= forestfights
;
2498 p
-> player_fights
= 3 ;
2503 void do_refresh ( char * u
)
2505 char * nick
= strtok ( NULL
, " " );
2508 if (!( user
= find ( u
)))
2510 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2511 log ( "Error: aClient not found: %s " , u
);
2514 else if (! isAdmin ( user
))
2516 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2521 notice ( s_GameServ
, u
, "SYNTAX: REFRESH {ALL | NICK}" );
2524 else if ( stricmp ( nick
, "ALL" ) == 0 )
2526 notice ( s_GameServ
, u
, "Refreshing everyone's stats!" );
2529 else if (( user
= findbyrealnick ( nick
)))
2531 if ( is_playing ( user
))
2534 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getRealNick ());
2536 notice ( s_GameServ
, u
, "Refreshing %s ." , user
-> getNick ());
2538 refresh ( user
-> stats
);
2543 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2545 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2551 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2559 ListNode
< aClient
> * it
;
2562 it
= players
. First ();
2566 p
= it
-> getData ()-> stats
;
2572 void reset ( Player
* p
)
2580 void do_reset ( char * u
)
2582 char * nick
= strtok ( NULL
, " " );
2585 if (!( user
= find ( u
)))
2587 notice ( s_GameServ
, u
, "Error: aClient not found. Contact a %S admin" );
2588 log ( "Error: aClient not found: %s " , u
);
2591 else if (! isAdmin ( user
))
2593 notice ( s_GameServ
, u
, "You must be a %S admin to use this command!" );
2598 notice ( s_GameServ
, u
, "SYNTAX: RESET {ALL | NICK}" );
2601 else if ( stricmp ( nick
, "ALL" ) == 0 )
2603 notice ( s_GameServ
, u
, "Resetting everyone's stats!" );
2606 else if (( user
= findbyrealnick ( nick
)))
2608 if ( is_playing ( user
))
2611 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getRealNick ());
2613 notice ( s_GameServ
, u
, "Resetting %s ." , user
-> getNick ());
2620 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getRealNick ());
2622 notice ( s_GameServ
, u
, " %s is not playing." , user
-> getNick ());
2628 notice ( s_GameServ
, u
, "Nick %s not found." , nick
);
2633 void do_help ( char * u
)
2635 char * cmd
= strtok ( NULL
, " " );
2637 display_help ( u
, cmd
);
2640 void display_help ( char * u
, char * file
)
2647 infile
. open ( "helpfiles/help" );
2650 log ( "Error opening helpfiles/help" );
2651 notice ( s_GameServ
, u
, "Error opening helpfiles/help" );
2654 buf
= new char [ 1024 ];
2655 while ( infile
. getline ( buf
, 1024 ))
2657 // Written this way, it will process %S in the helpfiles
2658 // Instead of notice(s_GameServ, u, "%s", buf);
2659 notice ( s_GameServ
, u
, buf
);
2663 aClient
* user
= find ( u
);
2664 if ( user
&& isAdmin ( user
))
2665 display_help ( u
, "admin_commands" );
2670 filename
= new char [ strlen ( file
) + 11 ];
2671 strcpy ( filename
, "helpfiles/" );
2672 strcat ( filename
, file
);
2674 for ( unsigned int x
= 10 ; x
< strlen ( filename
); x
++)
2675 filename
[ x
] = tolower ( filename
[ x
]);
2677 infile
. open ( filename
);
2681 notice ( s_GameServ
, u
, "No help for \ 2 %s \ 2 ", file
);
2684 buf
= new char [ 1024 ];
2685 while ( infile
. getline ( buf
, 1024 ))
2687 // Written this way, it will process %S in the helpfiles
2688 // Instead of notice(s_GameServ, u, "%s", buf);
2689 notice ( s_GameServ
, u
, buf
);
2696 void do_admin ( char * u
)
2699 char * pass
= strtok ( NULL
, " " );
2701 if (!( user
= find ( u
)))
2703 log ( "Error: aClient not found: %s " , u
);
2704 notice ( s_GameServ
, u
, "Error: aClient not found. Contact %S admin." );
2709 notice ( s_GameServ
, u
, "SYNTAX: \ 2 ADMIN\ 2 \ 2 \1f password\1f \ 2 " );
2715 notice ( s_GameServ
, u
, "You already have administrator privledges." );
2718 else if ( strcmp ( pass
, adminpass
) == 0 )
2720 notice ( s_GameServ
, u
, "Password accepted. You now have administrator privledges." );
2723 log ( " %s became an administrator." , user
-> getRealNick ());
2725 log ( " %s became an administrator." , user
-> getNick ());
2730 notice ( s_GameServ
, u
, "Invalid password. Remember: case sensitive" );
2735 bool load_monsters ()
2738 infile
. open ( "monsters.dat" );
2744 log ( "Error opening monsters.dat" );
2748 buf
= new char [ 2048 ];
2751 log ( "Loading monsters from monsters.dat" );
2754 for ( int l
= 0 ; l
< REALLEVELS
; l
++)
2756 for ( int m
= 0 ; m
< MONSTERS
;)
2758 infile
. getline ( buf
, 2048 );
2759 if ( buf
[ 0 ] == ' \n ' || buf
[ 0 ] == '\0' || buf
[ 0 ] == '#' )
2763 strcpy ( monsters
[ l
][ m
]-> name
, strtok ( buf
, "~" ));
2764 strcpy ( monsters
[ l
][ m
]-> weapon
, strtok ( NULL
, "~" ));
2765 monsters
[ l
][ m
]-> strength
= stringtoint ( strtok ( NULL
, "~" ));
2766 monsters
[ l
][ m
]-> gold
= stringtoint ( strtok ( NULL
, "~" ));
2767 monsters
[ l
][ m
]-> exp
= stringtoint ( strtok ( NULL
, "~" ));
2768 monsters
[ l
][ m
]-> maxhp
= stringtoint ( strtok ( NULL
, "~" ));
2769 monsters
[ l
][ m
]-> hp
= monsters
[ l
][ m
]-> maxhp
;
2770 strcpy ( monsters
[ l
][ m
]-> death
, strtok ( NULL
, "" ));