--- deliantra/server/include/client.h 2006/12/19 05:41:21 1.11 +++ deliantra/server/include/client.h 2006/12/22 16:34:00 1.16 @@ -26,6 +26,7 @@ #include #include +#include // (possibly) max. number of objects "per page" in the ground container #define FLOORBOX_PAGESIZE 50 @@ -69,15 +70,13 @@ * are using. */ -enum Sock_Status { Ns_Add, Ns_Dead }; - /* Only one map mode can actually be used, so lets make it a switch * instead of having a bunch of different fields that needed to * get toggled. */ enum MapMode { Map0Cmd = 0, Map1Cmd = 1, Map1aCmd = 2 }; -/* The following is the setup for a ring buffer for storing outbut +/* The following is the setup for a ring buffer for storing output * data that the OS can't handle right away. */ @@ -88,6 +87,19 @@ int len; }; +// states the socket can be in +enum { + ST_DEAD, // socket is dead + ST_SETUP, // initial handshake / setup / login + ST_PLAYING, // logged in an playing + ST_CUSTOM, // waiting for custom reply + + ST_CONFIRM_QUIT, + ST_CHANGE_CLASS, + ST_CONFIGURE, + ST_GET_PARTY_PASSWORD, +}; + // a handler for a specific type of packet enum { PF_PLAYER = 0x01, // must have valid player / will by synchronised @@ -114,21 +126,60 @@ } }; +struct refitem +{ + object_ptr op; +}; + +// this represents a container on the client side. +// right now, there are only ever two of them: +// the inventory and the floor/open container +//TODO: unused as of yet +struct client_container : vector< refitem, slice_allocator > +{ + client *ns; + enum { CC_NONE, CC_INVENTORY, CC_MAPSPACE, CC_CONTAINER } type; + + bool item_changed; // one of the items in here possibly changed + + // for mapspace and container + int x, y; + maptile *map; + + // for container + object *env; + + client_container (client *ns) + : ns (ns), type (CC_NONE) { } + + tag_t tag () const; + + inline iterator merge_item (iterator i, object *op); + + void clear (); + void update (); + + void set_mapspace (maptile *map, int x, int y); + void set_container (object *env); +}; + /* how many times we are allowed to give the wrong password before being kicked. */ #define MAX_PASSWORD_FAILURES 5 ACC_CLASS (client) // should become player when newsocket is a baseclass of player -struct client : zero_initialised, attachable_base +struct client : zero_initialised, attachable { - enum Sock_Status status; int ACC (RW, fd); unsigned int inbuf_len; // number of bytes valid in inbuf uint8 *faces_sent; // This is a bitmap on sent face status - struct statsinfo stats; + statsinfo stats; + + client_container cc_inv, cc_other; + Buffer outputbuffer; char *ACC (RW, host); /* Which host it is connected from (ip address) */ + uint8 ACC (RW, state); /* Input state of the player (name, password, etc */ uint8 ACC (RW, password_fails); /* how many times the player has failed to give the right password */ - Buffer outputbuffer; bool ACC (RW, facecache); /* If true, client is caching images */ bool ACC (RW, sent_scroll); @@ -170,18 +221,26 @@ client (int fd, const char *from_ip); ~client (); void destroy (); + bool destroyed () const { return state == ST_DEAD; } iw cmd_ev; void cmd_cb (iw &w); iow socket_ev; void socket_cb (iow &w, int got); std::deque< command, slice_allocator > cmd_queue; - // resets movement state + // large structures at the end please + struct Map lastmap; + std::bitset anims_sent; + // if we get an incomplete packet, this is used to hold the data. + // we add 2 byte for the header, one for the trailing 0 byte + uint8 inbuf[MAXSOCKBUF + 2 + 1]; + bool may_execute (const packet_type *pkt) const; void execute (const packet_type *pkt, char *data, int datalen); void queue_command (packet_type *handler, char *data, int datalen); bool handle_command (); + // resets movement state void reset_state (); bool handle_packet (); @@ -202,12 +261,7 @@ // called when the player has been moved void floorbox_reset () { look_position = 0; floorbox_update (); } - // large structures at the end please - struct Map lastmap; - std::bitset anims_sent; - // if we get an incomplete packet, this is used to hold the data. - // we add 2 byte for the header, one for the trailing 0 byte - uint8 inbuf[MAXSOCKBUF + 2 + 1]; + static client *create (int fd, const char *peername); }; #define CLIENT_SUPPORT_READABLES(__sockPtr,__type)\