/* * This is the main headerfile */ #ifndef MUD_H #define MUD_H #include <zlib.h> #include <pthread.h> #include <arpa/telnet.h> #include "list.h" #include "stack.h" /************************ * Standard definitions * ************************/ /* define TRUE and FALSE */ #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif #define eTHIN 0 #define eBOLD 1 /* A few globals */ #define PULSES_PER_SECOND 4 /* must divide 1000 : 4, 5 or 8 works */ #define MAX_BUFFER 8192 /* seems like a decent amount */ #define MAX_OUTPUT 8192 /* well shoot me if it isn't enough */ #define MAX_HELP_ENTRY 8192 /* roughly 40 lines of blocktext */ #define MUDPORT 9009 /* just set whatever port you want */ #define FILE_TERMINATOR "EOF" /* end of file marker */ #define COPYOVER_FILE "../data/copyover.dat" /* tempfile to store copyover data */ #define EXE_FILE "../src/SocketMud" /* the name of the mud binary */ /* Connection states */ #define STATE_NEW_NAME 0 #define STATE_NEW_PASSWORD 1 #define STATE_VERIFY_PASSWORD 2 #define STATE_ASK_PASSWORD 3 #define STATE_PLAYING 4 #define STATE_CLOSED 5 /* Thread states - please do not change the order of these states */ #define TSTATE_LOOKUP 0 /* Socket is in host_lookup */ #define TSTATE_DONE 1 /* The lookup is done. */ #define TSTATE_WAIT 2 /* Closed while in thread. */ #define TSTATE_CLOSED 3 /* Closed, ready to be recycled. */ /* player levels */ #define LEVEL_GUEST 1 /* Dead players and actual guests */ #define LEVEL_PLAYER 2 /* Almost everyone is this level */ #define LEVEL_ADMIN 3 /* Any admin without shell access */ #define LEVEL_GOD 4 /* Any admin with shell access */ /* Communication Ranges */ #define COMM_LOCAL 0 /* same room only */ #define COMM_OOC 1 /* Global, OOC */ #define COMM_LOG 10 /* admins only */ /* define simple types */ typedef unsigned char bool; typedef short int sh_int; #define ptc printf_to_char /****************************** * End of standard definitons * ******************************/ /*********************** * Defintion of Macros * ***********************/ #define UMIN(a, b) ((a) < (b) ? (a) : (b)) #define IS_ADMIN(dMob) ((dMob->admin_level) > LEVEL_PLAYER ? TRUE : FALSE) #define IREAD(sKey, sPtr) \ { \ if (!strcasecmp(sKey, word)) \ { \ int sValue = fread_number(fp); \ sPtr = sValue; \ found = TRUE; \ break; \ } \ } #define SREAD(sKey, sPtr) \ { \ if (!strcasecmp(sKey, word)) \ { \ sPtr = fread_string(fp); \ found = TRUE; \ break; \ } \ } /*********************** * End of Macros * ***********************/ /****************************** * New structures * ******************************/ /* type defintions */ typedef struct dSocket D_SOCKET; typedef struct dMobile D_MOBILE; typedef struct help_data HELP_DATA; typedef struct lookup_data LOOKUP_DATA; typedef struct event_data EVENT_DATA; /* the actual structures */ struct dSocket { D_MOBILE * player; SOCK_LIST * events; char * hostname; char inbuf[MAX_BUFFER]; char outbuf[MAX_OUTPUT]; char next_command[MAX_BUFFER]; bool bust_prompt; sh_int lookup_status; sh_int state; sh_int control; sh_int top_output; unsigned char compressing; /* MCCP support */ z_stream * out_compress; /* MCCP support */ unsigned char * out_compress_buf; /* MCCP support */ }; struct dMobile { D_SOCKET * socket; SOCK_LIST * events; char * name; char * password; sh_int admin_level; }; struct help_data { time_t load_time; char * keyword; char * text; }; struct lookup_data { D_SOCKET * dsock; /* the socket we wish to do a hostlookup on */ char * buf; /* the buffer it should be stored in */ }; struct typCmd { char * cmd_name; void (* cmd_funct)(D_MOBILE *dMOb, char *arg); sh_int level; }; typedef struct buffer_type { char * data; /* The data */ int len; /* The current len of the buffer */ int size; /* The allocated size of data */ } BUFFER; /* here we include external structure headers */ #include "event.h" /****************************** * End of new structures * ******************************/ /*************************** * Global Variables * ***************************/ extern STACK * dsock_free; /* the socket free list */ extern SOCK_LIST * dsock_list; /* the linked list of active sockets */ extern STACK * dmobile_free; /* the mobile free list */ extern SOCK_LIST * dmobile_list; /* the mobile list of active mobiles */ extern SOCK_LIST * help_list; /* the linked list of help files */ extern bool shut_down; /* used for shutdown */ extern char * greeting; /* the welcome greeting */ extern char * motd; /* the MOTD help file */ extern int control; /* boot control socket thingy */ extern time_t current_time; /* let's cut down on calls to time() */ extern const struct typCmd tabCmd[]; /* the command table */ /*************************** * End of Global Variables * ***************************/ /*********************** * MCCP support * ***********************/ extern const unsigned char compress_will[]; extern const unsigned char compress_will2[]; #define TELOPT_COMPRESS 85 #define TELOPT_COMPRESS2 86 #define COMPRESS_BUF_SIZE 8192 /*********************** * End of MCCP support * ***********************/ /*********************************** * Prototype function declerations * ***********************************/ /* more compact */ #define D_S D_SOCKET #define D_M D_MOBILE #define buffer_new(size) __buffer_new ( size) #define buffer_strcat(buffer,text) __buffer_strcat ( buffer, text ) char *crypt ( const char *key, const char *salt ); /* * socket.c */ int init_socket ( void ); bool new_socket ( int sock ); void close_socket ( D_S *dsock, bool reconnect ); bool read_from_socket ( D_S *dsock ); void printf_to_char ( D_MOBILE * ch, char *fmt, ... ); bool text_to_socket ( D_S *dsock, const char *txt ); /* sends the output directly */ void text_to_buffer ( D_S *dsock, const char *txt ); /* buffers the output */ void text_to_mobile ( D_M *dMob, const char *txt ); /* buffers the output */ void next_cmd_from_buffer ( D_S *dsock ); bool flush_output ( D_S *dsock ); void handle_new_connections ( D_S *dsock, char *arg ); void clear_socket ( D_S *sock_new, int sock ); void recycle_sockets ( void ); void * lookup_address ( void *arg ); /* * interpret.c */ void handle_cmd_input ( D_S *dsock, char *arg ); /* * io.c */ void log_string ( const char *txt, ... ); void bug ( const char *txt, ... ); time_t last_modified ( char *helpfile ); char *fread_line ( FILE *fp ); /* pointer */ char *fread_string ( FILE *fp ); /* allocated data */ char *fread_word ( FILE *fp ); /* pointer */ int fread_number ( FILE *fp ); /* just an integer */ /* * strings.c */ bool compares ( const char *aStr, const char *bStr ); char *one_arg ( char *fStr, char *bStr ); char *strdup ( const char *s ); int strcasecmp ( const char *s1, const char *s2 ); bool is_prefix ( const char *aStr, const char *bStr ); char *capitalize ( char *txt ); BUFFER *__buffer_new ( int size ); void __buffer_strcat ( BUFFER *buffer, const char *text ); void buffer_free ( BUFFER *buffer ); void buffer_clear ( BUFFER *buffer ); int bprintf ( BUFFER *buffer, char *fmt, ... ); bool is_name (char *str, char *namelist); /* * help.c */ void sql_help_summary (D_MOBILE * ch); void load_helps (void); void cmd_help (D_MOBILE * ch, char * arg); void cmd_sql_help (D_MOBILE * ch, char * argument); char * find_greeting (void); void do_sql_help_dump (D_MOBILE * ch, char *arg); void mysql_log_ohelp (char * who, char * topic); char * find_motd (void); void cmd_orphanhelps (D_MOBILE * ch, char * arg); /* * utils.c */ bool check_name ( const char *name ); void clear_mobile ( D_M *dMob ); void free_mobile ( D_M *dMob ); void communicate ( D_M *dMob, char *txt, int range ); void load_muddata ( bool fCopyOver ); char *get_time ( void ); void copyover_recover ( void ); D_M *check_reconnect ( char *player ); /* * action_safe.c */ void cmd_say ( D_M *dMob, char *arg ); void cmd_ooc ( D_M *dMob, char *arg ); void cmd_quit ( D_M *dMob, char *arg ); void cmd_shutdown ( D_M *dMob, char *arg ); void cmd_commands ( D_M *dMob, char *arg ); void cmd_who ( D_M *dMob, char *arg ); void cmd_help ( D_M *dMob, char *arg ); void cmd_compress ( D_M *dMob, char *arg ); void cmd_save ( D_M *dMob, char *arg ); void cmd_copyover ( D_M *dMob, char *arg ); void cmd_linkdead ( D_M *dMob, char *arg ); void cmd_admin ( D_M *dMob, char *arg ); /* * mccp.c */ bool compressStart ( D_S *dsock, unsigned char teleopt ); bool compressEnd ( D_S *dsock, unsigned char teleopt, bool forced ); /* * save.c */ void save_player ( D_M *dMob ); D_M *load_player ( char *player ); void MySQL_save_profile (D_MOBILE * dMob); void MySQL_create_profile (D_MOBILE * dMob); D_MOBILE * MySQL_load_profile (char *player); /* * MySQL.c */ void load_mysql (void); int MySQLQuery (char * query); int open_db (void); void close_db (void); int mysql_safe_query (char *fmt, ...); void MySQL_optimize (void); /* * Log.c */ void MySQL_log_logins (char * txt, ...); void MySQL_clear_logins (void); void MySQL_log_chat (char * who, char * channel, char * txt); void MySQL_clear_chatlog (void); /* * web.c */ int html_colour ( char type, char *string ); void html_colourconv ( char *buffer, const char *txt); void cmd_fix_online_helps (D_MOBILE * ch, char * arg); /******************************* * End of prototype declartion * *******************************/ #endif /* MUD_H */ #ifndef md5_INCLUDED #define md5_INCLUDED typedef unsigned char md5_byte_t; /* 8-bit byte */ typedef unsigned int md5_word_t; /* 32-bit word */ /* Define the state of the MD5 Algorithm. */ typedef struct md5_state_s { md5_word_t count[2]; /* message length in bits, lsw first */ md5_word_t abcd[4]; /* digest buffer */ md5_byte_t buf[64]; /* accumulate block */ } md5_state_t; #ifdef __cplusplus extern "C" { #endif /* Initialize the algorithm. */ void md5_init(md5_state_t *pms); /* Append a string to the message. */ void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); /* Finish the message and return the digest. */ void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); #ifdef __cplusplus } /* end extern "C" */ #endif #endif /* md5_INCLUDED */ char * md5_crypt(char * test);