/*
* This is the main headerfile
*/
#ifndef MUD_H
#define MUD_H
#include <zlib.h>
#include <pthread.h>
#include <arpa/telnet.h>
#include <event2/event.h>
#include <event2/buffer.h>
#include <event2/bufferevent.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 1024 /* seems like a decent amount */
#define MAX_OUTPUT 2048 /* well shoot me if it isn't enough */
#define MAX_HELP_ENTRY 4096 /* 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 "../txt/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_LOG 10 /* admins only */
/* define simple types */
typedef unsigned char bool;
typedef short int sh_int;
/******************************
* End of standard definitons *
******************************/
/***********************
* Defintion of Macros *
***********************/
#define UMIN(a, b) ((a) < (b) ? (a) : (b))
#define IS_ADMIN(dMob) ((dMob->level) > LEVEL_PLAYER ? TRUE : FALSE)
#define IREAD(sKey, sPtr) \
{ \
if (compares(sKey, word)) \
{ \
int sValue = fread_number(fp); \
sPtr = sValue; \
found = TRUE; \
break; \
} \
}
#define SREAD(sKey, sPtr) \
{ \
if (compares(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;
/* the actual structures */
struct dSocket
{
D_SOCKET * next;
D_MOBILE * player;
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;
#ifndef NOMCCP
unsigned char compressing; /* MCCP support */
z_stream * out_compress; /* MCCP support */
unsigned char * out_compress_buf; /* MCCP support */
#endif
void * context; /* libevent context */
};
struct dMobile
{
D_MOBILE * next;
D_SOCKET * socket;
char * name;
char * password;
sh_int level;
};
struct help_data
{
HELP_DATA * next;
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;
/******************************
* End of new structures *
******************************/
/***************************
* Global Variables *
***************************/
extern struct event_base *io_base;
extern evutil_socket_t io_sock;
extern struct event *io_sock_event;
extern D_SOCKET * dsock_free; /* the socket free list */
extern D_SOCKET * dsock_list; /* the linked list of active sockets */
extern D_MOBILE * dmobile_free; /* the mobile free list */
extern D_MOBILE * dmobile_list; /* the mobile list of active mobiles */
extern HELP_DATA * help_list; /* the linked list of help files */
extern const struct typCmd tabCmd[]; /* the command table */
extern char * greeting; /* the welcome greeting */
extern char * motd; /* the MOTD help file */
#ifdef CYGWIN32
extern pthread_mutex_t lookup_mutex; /* to lock gethostbyaddr() calls */
#endif
/***************************
* End of Global Variables *
***************************/
/***********************
* MCCP support *
***********************/
#ifndef NOMCCP
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
#endif
/***********************
* End of MCCP support *
***********************/
/***********************************
* Prototype function declerations *
***********************************/
#define buffer_new(size) __buffer_new ( size)
#define buffer_strcat(buffer,text) __buffer_strcat ( buffer, text )
#ifdef NOCRYPT
#define crypt(s1, s2) (s1)
#else
char *crypt ( const char *key, const char *salt );
#endif
/*
* socket.c
*/
void init_io ( bool copyover );
void kill_io ( void );
void new_socket ( int fd );
void close_socket ( D_SOCKET *dsock, bool reconnect );
bool text_to_socket ( D_SOCKET *dsock, const char *txt ); /* sends the output directly */
void text_to_buffer ( D_SOCKET *dsock, const char *txt ); /* buffers the output */
void text_to_mobile ( D_MOBILE *dMob, const char *txt ); /* buffers the output */
void retrieve_cmd ( D_SOCKET *dsock );
void process_cmd ( D_SOCKET *dsock );
void handle_new_connections ( D_SOCKET *dsock, char *arg );
void reset_socket ( D_SOCKET *sock_new, int sock );
void recycle_sockets ( void );
void *lookup_address ( void *arg );
/*
* interpret.c
*/
void handle_cmd_input ( D_SOCKET *dsock, char *arg );
/*
* io.c
*/
void log_string ( const char *txt, ... );
void bug ( const char *txt, ... );
time_t last_modified ( char *helpfile );
char *read_help_entry ( const char *helpfile ); /* pointer */
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
*/
char *one_arg ( char *fStr, char *bStr );
bool compares ( const char *aStr, const char *bStr );
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, ... );
/*
* update.c
*/
void update_handler ( void );
/*
* help.c
*/
bool check_help ( D_MOBILE *dMob, char *helpfile );
void load_helps ( void );
void add_help ( HELP_DATA *help );
/*
* utils.c
*/
bool check_name ( const char *name );
void clear_mobile ( D_MOBILE *dMob );
void free_mobile ( D_MOBILE *dMob );
void ex_free_mob ( D_MOBILE * dMob );
void communicate ( D_MOBILE *dMob, char *txt, int range );
void load_muddata ( bool copyover );
char *get_time ( void );
void copyover_recover ( void );
D_MOBILE *check_reconnect ( char *player );
/*
* action_safe.c
*/
void cmd_say ( D_MOBILE *dMob, char *arg );
void cmd_quit ( D_MOBILE *dMob, char *arg );
void cmd_shutdown ( D_MOBILE *dMob, char *arg );
void cmd_commands ( D_MOBILE *dMob, char *arg );
void cmd_who ( D_MOBILE *dMob, char *arg );
void cmd_help ( D_MOBILE *dMob, char *arg );
#ifndef NOMCCP
void cmd_compress ( D_MOBILE *dMob, char *arg );
#endif
void cmd_save ( D_MOBILE *dMob, char *arg );
void cmd_copyover ( D_MOBILE *dMob, char *arg );
void cmd_linkdead ( D_MOBILE *dMob, char *arg );
/*
* mccp.c
*/
#ifndef NOMCCP
bool compressStart ( D_SOCKET *dsock, unsigned char teleopt );
bool compressEnd ( D_SOCKET *dsock, unsigned char teleopt, bool forced );
#endif
/*
* save.c
*/
void save_player ( D_MOBILE *dMob );
D_MOBILE *load_player ( char *player );
D_MOBILE *load_profile ( char *player );
/*******************************
* End of prototype declartion *
*******************************/
#endif /* MUD_H */