/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
pc.h
*/
#ifndef _PC_H
#define _PC_H
#include "bit.h"
#include "socket.h"
#include "server.h"
#include "char.h"
#include "skill.h"
#define PLAYER_DIR "../player"
extern const bitType priv_bit_list[];
extern const int exp_table[];
const int N_SUPERUSER = 1;
const int N_DIRECTOR = 2;
const int N_ADMIN = 3;
const int N_OPERATOR = 4;
const int N_MASTERBUILDER = 5;
const int N_BUILDER = 6;
const int N_QUESTER = 7;
const int N_WIZARD = 8;
const int SUPERUSER = BIT(N_SUPERUSER);
const int DIRECTOR = BIT(N_DIRECTOR);
const int ADMIN = BIT(N_ADMIN);
const int OPERATOR = BIT(N_OPERATOR);
const int MASTERBUILDER = BIT(N_MASTERBUILDER);
const int BUILDER = BIT(N_BUILDER);
const int QUESTER = BIT(N_QUESTER);
const int WIZARD = BIT(N_WIZARD);
const int MAX_CLASS = 8;
const int CLASS_IMM = 0;
const int MAX_PC_LEVEL = 31;
const int MAX_PC_BIT_FIELDS = 1;
const int MAX_PRIV_BIT_FIELDS = 1;
const int MAX_INBUF_SIZE = 2048;
const int STATE_BOOT = 0;
const int STATE_INIT = 1;
const int STATE_GET_NAME = 2;
const int STATE_CONFIRM_NAME = 3;
const int STATE_GET_OLD_PASSWORD = 4;
const int STATE_GET_NEW_PASSWORD = 5;
const int STATE_CONFIRM_PASSWORD = 6;
const int STATE_GET_SEX = 7;
const int STATE_GET_CLASS = 8;
const int STATE_GET_RACE = 9;
const int STATE_MAIN_MENU = 10;
const int STATE_DELETE_CHAR = 11;
const int STATE_CHANGE_PASSWD = 12;
const int STATE_READ_WIZ_LIST = 13;
const int STATE_PLAYING = 25;
const int STATE_EMAIL = 35;
const int STATE_EDIT = 37;
const int STATE_EDIT_AREA = 38;
const int STATE_EDIT_NPC = 39;
const int STATE_EDIT_OBJ = 40;
const int STATE_EDIT_RESET = 41;
const int STATE_EDIT_SHOP = 42;
const int STATE_EDIT_ROOM = 43;
const int STATE_EDIT_TEXT = 44;
const int TASK_EDIT_APPEND = 1;
const int TASK_EMAIL_SEND = 20;
const int TASK_EMAIL_QUIT = 21;
// PC bits
const int PC_UNDEFINED = 0; // dont use
const int PC_UNUSED1 = 1; // reserved
const int PC_UNUSED2 = 2; // reserved
const int PC_AFK = 3;
const int PC_COLOR = 4;
const int PC_ANSI = 5;
const int PC_VT100 = 6;
const int PC_UNUSED3 = 7;
const int PC_BANNED = 8;
const int PC_UNUSED4 = 9;
const int PC_NO_HASSLE = 10;
const int PC_SILENCE = 11;
const int PC_UNUSED5 = 12;
const int PC_AUTOLOOT = 13;
const int PC_AUTOGOLD = 14;
const int PC_BRIEF = 15;
const int PC_NO_EMOTE = 16;
const int PC_NO_TELL = 17;
const int PC_LOG = 18;
const int PC_NO_SUMMON = 19; // This goes away, need resist summon as a skill
const int PC_SPIRIT = 20; // For death quest setup
const int PC_QUEST = 21;
const int PC_GOD_PROOF = 22; // Lower gods cant snoop
const int PC_AUTODIR = 23;
const int PC_AUTOEXITS = 24;
const int PC_WIZNET = 25; // Wiz sees the wiz (info) channel
const int PC_AUTOEAT = 26;
const int PC_AUTODRINK = 27;
#ifndef _MSC_VER
class PC;
#else
class __virtual_inheritance PC;
#endif /* _MSC_VER */
class Editor;
struct command_type
{
char *commd;
void (PC::*fun)( const String & );
bool is_action;
};
struct immcmd_type
{
char *commd;
void (PC::*fun)( const String & );
int level;
int bit;
};
class PC : public Char
{
private:
static int total_count;
protected:
static const command_type cmdlist[27][32];
static const immcmd_type immcmdlist[27][12];
Server *server;
Socket *socket;
Descriptor fdpair[2]; // pipe for various IPC stuff
PC * snooper;
PC * snoopvictim;
short state;
short state_last;
short task;
int idletime;
String prompt;
String afk_messg;
String title;
String password;
String incommd;
String args;
String inlast;
char inbuf[MAX_INBUF_SIZE];
char *inptr;
char *intop;
char *inceiling;
char *outbuf;
char *outptr;
long outsize;
char *pagebuf;
char *pageptr;
char *pagelast;
unsigned long pc_bits [ MAX_PC_BIT_FIELDS ];
unsigned long priv;
Editor *editor;
String texteditor;
//EMail **email;
short messages;
short levels[ MAX_CLASS ];
long exp;
short age;
short energy;
short luck;
short security;
short last_hint;
public:
PC()
: server(0), socket(0), snooper(0), snoopvictim(0),
state(STATE_INIT),task(0),idletime(0),prompt(new char('\0')),
incommd(256),args(256),inptr(inbuf),intop(inbuf),
inceiling(inbuf+MAX_INBUF_SIZE-1),
outbuf(new char[2048]),outptr(outbuf),outsize(2048),
pagebuf(0),pageptr(0),pagelast(0),
editor(0), messages(0),exp(0),
energy(100),security(0), last_hint(0)
{
total_count++;
*inbuf = '\0';
*outbuf = '\0';
memset( levels, 0, sizeof( levels[0] ) * MAX_CLASS );
memset( pc_bits, 0,
sizeof( pc_bits[0] ) * MAX_PC_BIT_FIELDS );
skills = new unsigned char[ MAX_SKILL ];
memset( skills, 0, MAX_SKILL );
priv = 0;
}
PC( Server *, Socket *, char * );
virtual ~PC();
virtual vmtype getVMType() { return VMT_PC; }
void setRepop( Repop * ) {}
int startShell( const String &, const String & );
Server *getServer() const { return server; }
Socket * getSocket() const { return socket; }
void setSocket( Socket * x ) { socket = x; }
PC * getSnooper() const { return snooper; }
void setSnooper( PC * x ) { snooper = x; }
PC * getSnoopVictim() const { return snoopvictim; }
void setSnoopVictim( PC * x ) { snoopvictim = x; }
bool isPC() const { return true; }
virtual void out( const char * );
virtual void out( const String & x ) { PC::out( x.chars() ); }
Descriptor * getPipeIn() { return &fdpair[0]; }
Descriptor * getPipeOut() { return &fdpair[1]; }
void setPipeIn( int x ) { fdpair[0] = x; }
void setPipeOut( int x ) { fdpair[1] = x; }
void closePipeIn() { fdpair[0].close(); }
void closePipeOut() { fdpair[1].close(); }
void readInput();
bool getNextCommand();
const String & getCommand() const { return incommd; }
const String & getArgs() const { return args; }
void command( String & );
void command();
virtual bool pulse();
virtual void fromWorld();
virtual void toWorld();
void setTextEditor( const String & x ) { texteditor = x; }
const String & getTextEditor() const { return texteditor; }
void setPrompt( const String & x ) { prompt = x; }
const String & getPrompt() const { return prompt; }
void setTitle( const String & x ) { title = x; }
const String & getTitle() const { return title; }
void putPrompt();
bool inBuf() const;
bool outBuf() const;
int getState() const { return state; }
void setState( int s ) { state = s; }
int lastState() const;
void clrIdle() { idletime = 0; }
int getIdle() { return idletime; }
void idle() { idletime++; }
Editor * getEditor() const { return editor; }
void quitEditor();
bool config( int x ) const { return IS_SET( pc_bits, x ); }
bool isPlaying() const;
bool isAFK() const { return IS_SET( pc_bits, PC_AFK ); }
void toggleAFK() { TOGGLE_BIT( pc_bits, PC_AFK ); }
const String & getAFKMessage() { return afk_messg; }
char *pagePending() const;
void page( const String & );
void flush(); /* not a real flush() */
void view( const char *filename );
void setWindow( int, int );
void checkMail();
//void newMail( EMail * );
void advance( int tolevel );
void setClass( int c ) { classnow = c; }
int getLevel() const { return levels[ classnow ]; }
int gainExp( int );
char *className() const;
int readFrom( StaticInput &in );
int writeTo( Output &out ) const;
const String & getPasswd() const { return password; }
void setPasswd( const String & str ) { password = str; }
void setPrivBit( int );
void rmPrivBit( int );
void clrPrivBits() { priv = 0;}
int authorized( int ) const;
void say( const String & );
void look( Char * );
void look( Object * );
bool save();
void makeCorpse();
static int getTotalCount() { return total_count; }
bool wantHints() { return last_hint >= 0; }
int lastHint();
void setHint(int number);
virtual void describeItself( String &);
void do_debug( const String & );
void do_smite( const String & );
void do_shell( const String & );
void do_snoop( const String & );
// command member functions start here
void do_afk( const String & );
void do_autodir( const String & );
void do_autoexits( const String & );
void do_autoeat( const String & );
void do_autodrink( const String & );
void do_autogold( const String & );
void do_autoloot( const String & );
void do_title( const String & );
void do_up( const String & );
void do_down( const String & );
void do_north( const String & );
void do_south( const String & );
void do_east( const String & );
void do_west( const String & );
void do_break( const String & );
void do_close( const String & );
void do_open( const String & );
void do_buy( const String & );
void do_sell( const String & );
void do_trade( const String & );
void do_price( const String & );
void do_eat( const String & );
void do_give( const String & );
void do_collect( const String & );
void do_kill( const String & );
void do_cast( const String & );
void do_advance( const String & );
void do_dbsave( const String & );
void do_goto( const String & );
void do_grant( const String & );
void do_revoke( const String & );
void do_echo( const String & );
void do_force( const String & );
void do_invis( const String & );
void do_immtalk( const String & );
void do_ls( const String & );
void do_cat( const String & );
void do_cp( const String & );
void do_cset( const String & );
void do_toggle( const String & );
void do_rm( const String & );
void do_memory( const String & );
void do_gc( const String & );
void do_repops( const String & );
void do_mfind( const String & );
void do_ofind( const String & );
void do_owhere( const String & );
void do_reboot( const String & );
void do_rfind( const String & );
void do_page( const String & );
void do_peace( const String & );
void do_purge( const String & );
void do_shutdown( const String & );
void do_slay( const String & );
void do_socials( const String & );
void do_time( const String & );
void do_transfer( const String & );
void do_users( const String & );
void do_use( const String & );
void do_ident( const String & );
void do_areas( const String & );
void do_chat( const String & );
void do_clear( const String & );
void do_commands( const String & );
void do_drop( const String & );
void do_equipment( const String & );
void do_exits( const String & );
void do_get( const String & );
void do_look( const String & );
void do_levels( const String & );
void do_help( const String & );
void do_hide( const String & );
void do_inventory( const String & );
void do_list( const String & );
void do_skills( const String & );
//void do_mail( const String & );
void do_password( const String & );
void do_practice( const String & );
void do_privileges( const String & );
void do_prompt( const String & );
void do_put( const String & );
void do_quaff( const String & );
void do_quit( const String & );
void do_remove( const String & );
void do_save( const String & );
void do_say( const String & );
void do_score( const String & );
void do_show( const String & );
void do_sneak( const String & );
void do_study( const String & );
void do_tell( const String & );
void do_uptime( const String & );
void do_wear( const String & );
void do_weather( const String & );
void do_who( const String & );
void do_where( const String & );
void do_wield( const String & );
void do_wizhelp( const String & );
// helper fun for next 3 reports
void pc_report(const char *, const String &);
void do_bug( const String & );
void do_idea( const String & );
void do_typo( const String & );
void do_checkreport(const String & );
void do_vm( const String & );
void do_hint( const String & );
void do_prosave( const String & );
void do_proload( const String & );
void do_probackup( const String & );
void do_prorestore( const String & );
void do_prodisplay( const String & );
void do_proset( const String & );
// Online Creation/Edit
int getSecurity() { return security; }
bool checkSecurity();
void do_oset( const String & );
void do_ostat( const String & );
void do_mstat( const String & );
void do_rstat( const String & );
void do_mwhere( const String & );
void do_aedit( const String & );
void do_medit( const String & );
void do_oedit( const String & );
void do_redit( const String & );
void do_hedit( const String & );
void do_mload( const String & );
void do_oload( const String & );
};
inline const char * getPrivBitName( int val )
{
return lookupBitName( priv_bit_list, val );
}
inline int getPrivBit( const char * name )
{
return lookupBit( priv_bit_list, name );
}
#endif