[JaMUDe-cvs] test/src/include montrey
Status: Pre-Alpha
Brought to you by:
xenith
From: JaMUDe C. C. <jam...@li...> - 2002-10-18 18:20:15
|
JaMUDe CVS commit Author : montrey Tree : test Dir : test/src/include Modified Files: mud.h Log Message: did a lot of general cleanup and reorganizing. top level class is now Jame, characters are redone a bit, some other odds and ends. I gotta start committing more frequently so I can remember all the changes :) oh well, to be expected when you're working on the engine I suppose. also adding in support for the Aapl library of double linked list templates =================================================================== RCS file: /cvsroot/jamude/test/src/include/mud.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- mud.h 18 Oct 2002 00:55:03 -0000 1.1 +++ mud.h 18 Oct 2002 18:19:44 -0000 1.2 @@ -1,42 +1,119 @@ #include <stdio.h> #include <ctype.h> -#ifndef WIN32 #include <netinet/in.h> #include <sys/socket.h> #include <sys/time.h> #include <sys/fcntl.h> #include <unistd.h> -#else -#include <Winsock2.h> -#endif #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream.h> -#define MAX_INPUT_LENGTH 1024 -#define MAX_STRING_LENGTH 4096 -#define MAX_AREAS 5 +/* Aapl doubly linked list module */ +#include "include/aapl/dlist.h" +#include "include/aapl/dlistmel.h" +#include "include/aapl/dlistval.h" + +#define MIL 1024 /* max input length */ +#define MSL 4096 /* max string length */ +#define MAX_AREAS 5 -#define LOGIN_NAME 0 +#define LOGIN_NAME 0 #define LOGIN_PASSWORD 1 #define LOGIN_NEWPASSWORD 2 -#define LOGIN_CHECKPASSWORD 3 +#define LOGIN_CHECKPASSWORD 3 #define LOGIN_PLAYING 4 // OK #define OK 0 -class Player; -class Dnode; -class Room; -class Communication; +/* basic hierarchy of classes */ +class Jame; /* top level */ + + class Communication; + class Descriptor; + class Dnode; + + class Area; + class Room; + + class Character; + class Player; + class Mobile; // Error Codes #define E_OPEN -1 #define E_INVALID -2 +class Jame +{ + public: + Jame(int port); + ~Jame(); + void iterate_loop(); + + private: + Communication *comm; +}; + + +#define PFILE_VERSION 1 +#define CHAR_TYPE_MOBILE 0 +#define CHAR_TYPE_PLAYER 1 + +class Character +{ + public: + Character(int type); + ~Character(); + Player *get_player(); + Mobile *get_mobile(); + void set_desc(Dnode *d); + Dnode *get_desc(); + void send(char *text); + + private: + Player *player; /* this is not necessarily initialized */ + Mobile *mobile; /* this is not necessarily initialized */ + Dnode *desc; +}; + + +class Player +{ + public: + Player(); + ~Player(); + + Character *get_char(); + bool check_password(char *pass); + bool load(); + bool save(); + + + private: + Character *ch; /* reverse pointer to what character it is */ + char *password; + int state; + int level; +}; + + +class Mobile +{ + public: + Mobile(); + ~Mobile(); + + Character *get_char(); + + private: + Character *ch; /* reverse pointer to what character it is */ +}; + + class Room { public: int load(FILE *fp); @@ -47,81 +124,65 @@ }; -#define PFILE_VERSION 1 - -class Player { -public: - Player(){state=LOGIN_NAME;level=0;next=NULL;prev=NULL;name=NULL;password=NULL;room=NULL;desc=NULL;}; - ~Player(){remove();name?free(name):(void)(name=NULL);password?free(password):(void)(password=NULL);}; - bool check_password(char *pass){ return (strcmp(pass,password)?false:true);} - char *name; - bool load(); - bool save(); - int state; - int level; - char *password; - void insert(); - void remove(); - Room *room; - Dnode *desc; -protected: - Player *next; - Player *prev; +class Dnode +{ + friend class Descriptor; + friend class Communication; + + public: + send(char *text); /* send text to the node */ + + protected: + Dnode(int); + ~Dnode(); + Dnode *next; + Dnode *prev; + Player ch; + int fd; + char *name; + char instr[MIL]; + int iStart; }; -class Dnode { -friend class Descriptor; -friend class Communication; -public: - void send( char *arg ); -protected: - Dnode(int); - ~Dnode(); - Dnode *next; - Dnode *prev; - Player ch; - int fd; - char *name; - char instr[MAX_INPUT_LENGTH]; - int iStart; +class Descriptor +{ + public: + Descriptor(); + ~Descriptor(); + + void first(); // select first node + void next(); // select next node + void prev(); // select previous node + bool is_at_end(); // check if we're at the end + void append_node(Dnode *); // append a new node + void delete_node(); // delete the current node + Dnode *get_node(); // get the current node + + protected: + Dnode *cursor; // current position + Dnode *head; // head of the list }; -class Descriptor { -public: - Descriptor(); - ~Descriptor(); - void next() { cursor = cursor->next; } // select next node - void prev() { cursor = cursor->prev; } // select previous node - bool endOfList() { // check if we're at the end - return cursor->fd ? false : true; - } - void first() { cursor = head->next; } // select first node - void append(Dnode *); // append a new node - Dnode *getNode() { return cursor; } // get the current node - void deleteNode(); // delete the current node -protected: - Dnode *cursor; // current position - Dnode *head; // head of the list -}; -class Communication { -public: - Communication(int port); - ~Communication(); - void send(Dnode *d, char *arg); // send string to node - void accept_new_socket(); // accept new connections - void recv(); // receive all input - void close(Dnode *d); // close a connection to a node - void parse_command(Dnode *d, char *arg); // parse input -protected: - int listen_fd; - Descriptor *fd_list; - fd_set in_set, out_set; +#define closesocket close + +class Communication +{ + public: + Communication(int port); + ~Communication(); + + void accept_new_socket(); // accept new connections + void close_socket(Dnode *d); // close a connection to a node + void recv(); // receive all input + void parse_command(Dnode *d, char *arg); // parse input + + protected: + int listen_fd; + Descriptor *fd_list; + fd_set in_set, out_set; }; -#ifndef WIN32 - #define closesocket close -#endif class Area { public: |