… | |
… | |
68 | * instead of having a bunch of different fields that needed to |
68 | * instead of having a bunch of different fields that needed to |
69 | * get toggled. |
69 | * get toggled. |
70 | */ |
70 | */ |
71 | enum { Map0Cmd = 0, Map1Cmd = 1, Map1aCmd = 2 }; |
71 | enum { Map0Cmd = 0, Map1Cmd = 1, Map1aCmd = 2 }; |
72 | |
72 | |
73 | /* The following is the setup for a ring buffer for storing output |
|
|
74 | * data that the OS can't handle right away. |
|
|
75 | */ |
|
|
76 | struct Buffer |
|
|
77 | { |
|
|
78 | char data[SOCKETBUFSIZE]; |
|
|
79 | int start; |
|
|
80 | int len; |
|
|
81 | }; |
|
|
82 | |
|
|
83 | // states the socket can be in |
73 | // states the socket can be in |
84 | enum { |
74 | enum { |
85 | ST_DEAD, // socket is dead |
75 | ST_DEAD, // socket is dead |
86 | ST_SETUP, // initial handshake / setup / login |
76 | ST_SETUP, // initial handshake / setup / login |
87 | ST_PLAYING, // logged in an playing |
77 | ST_PLAYING, // logged in an playing |
… | |
… | |
116 | { |
106 | { |
117 | sfree<char> (data, datalen + 1); |
107 | sfree<char> (data, datalen + 1); |
118 | } |
108 | } |
119 | }; |
109 | }; |
120 | |
110 | |
121 | struct refitem |
|
|
122 | { |
|
|
123 | object_ptr op; |
|
|
124 | }; |
|
|
125 | |
|
|
126 | // this represents a container on the client side. |
|
|
127 | // right now, there are only ever two of them: |
|
|
128 | // the inventory and the floor/open container |
|
|
129 | //TODO: unused as of yet |
|
|
130 | struct client_container : vector< refitem, slice_allocator<refitem> > |
|
|
131 | { |
|
|
132 | client *ns; |
|
|
133 | enum { CC_NONE, CC_INVENTORY, CC_MAPSPACE, CC_CONTAINER } type; |
|
|
134 | |
|
|
135 | bool item_changed; // one of the items in here possibly changed |
|
|
136 | |
|
|
137 | // for mapspace and container |
|
|
138 | int x, y; |
|
|
139 | maptile *map; |
|
|
140 | |
|
|
141 | // for container |
|
|
142 | object *env; |
|
|
143 | |
|
|
144 | client_container (client *ns) |
|
|
145 | : ns (ns), type (CC_NONE) { } |
|
|
146 | |
|
|
147 | tag_t tag () const; |
|
|
148 | |
|
|
149 | inline iterator merge_item (iterator i, object *op); |
|
|
150 | |
|
|
151 | void clear (); |
|
|
152 | void update (); |
|
|
153 | |
|
|
154 | void set_mapspace (maptile *map, int x, int y); |
|
|
155 | void set_container (object *env); |
|
|
156 | }; |
|
|
157 | |
|
|
158 | /* how many times we are allowed to give the wrong password before being kicked. */ |
111 | /* how many times we are allowed to give the wrong password before being kicked. */ |
159 | #define MAX_PASSWORD_FAILURES 5 |
112 | #define MAX_PASSWORD_FAILURES 5 |
160 | |
113 | |
161 | INTERFACE_CLASS (client) // should become player when newsocket is a baseclass of player |
114 | INTERFACE_CLASS (client) // should become player when newsocket is a baseclass of player |
162 | struct client : zero_initialised, attachable |
115 | struct client : zero_initialised, attachable |
… | |
… | |
164 | int ACC (RW, fd); |
117 | int ACC (RW, fd); |
165 | unsigned int inbuf_len; // number of bytes valid in inbuf |
118 | unsigned int inbuf_len; // number of bytes valid in inbuf |
166 | statsinfo stats; |
119 | statsinfo stats; |
167 | int ACC (RO, active); |
120 | int ACC (RO, active); |
168 | |
121 | |
169 | Buffer outputbuffer; |
122 | /* The following is the setup for a ring buffer for storing output |
|
|
123 | * data that the OS can't handle right away. |
|
|
124 | */ |
|
|
125 | struct |
|
|
126 | { |
|
|
127 | char data[SOCKETBUFSIZE]; |
|
|
128 | int start; |
|
|
129 | int len; |
|
|
130 | } outputbuffer; |
170 | |
131 | |
171 | char *ACC (RW, host); /* Which host it is connected from (ip address) */ |
132 | char *ACC (RW, host); /* Which host it is connected from (ip address) */ |
172 | uint8 ACC (RW, state); /* Input state of the player (name, password, etc */ |
133 | uint8 ACC (RW, state); /* Input state of the player (name, password, etc */ |
173 | |
134 | |
174 | sint8 ACC (RW, last_level); /* Last level we sent to client */ |
135 | sint8 ACC (RW, last_level); /* Last level we sent to client */ |
… | |
… | |
223 | uint8 ACC (RW, itemcmd); /* What version of the 'item' protocol command to use */ |
184 | uint8 ACC (RW, itemcmd); /* What version of the 'item' protocol command to use */ |
224 | |
185 | |
225 | maptile *ACC (RW, current_map); // CF+ last/current player map |
186 | maptile *ACC (RW, current_map); // CF+ last/current player map |
226 | region *ACC (RW, current_region); // CF+ last/current player region |
187 | region *ACC (RW, current_region); // CF+ last/current player region |
227 | int ACC (RW, current_x), ACC (RW, current_y); // CF+ last/current map position |
188 | int ACC (RW, current_x), ACC (RW, current_y); // CF+ last/current map position |
228 | char ACC (RW, version)[64]; // CF+ client name/version |
189 | shstr ACC (RW, version); // CF+ client name/version |
229 | uint8 ACC (RW, faceset); // CF+ selected faceset |
190 | uint8 ACC (RW, faceset); // CF+ selected faceset |
230 | |
191 | |
231 | player_ptr ACC (RO, pl); |
192 | player_ptr ACC (RO, pl); |
232 | |
193 | |
233 | int ACC (RW, rtt), ACC (RW, rttvar); /* round-trip time and -variance, if known */ |
194 | int ACC (RW, rtt), ACC (RW, rttvar); /* round-trip time and -variance, if known */ |
… | |
… | |
247 | void do_destroy (); |
208 | void do_destroy (); |
248 | void gather_callbacks (AV *&callbacks, event_type event) const; |
209 | void gather_callbacks (AV *&callbacks, event_type event) const; |
249 | |
210 | |
250 | iow socket_ev; void socket_cb (iow &w, int got); |
211 | iow socket_ev; void socket_cb (iow &w, int got); |
251 | iw cmd_ev; void cmd_cb (iw &w); |
212 | iw cmd_ev; void cmd_cb (iw &w); |
252 | client_container cc_inv, cc_other; |
|
|
253 | |
213 | |
254 | std::deque< command, slice_allocator<command> > cmd_queue; |
214 | std::deque< command, slice_allocator<command> > cmd_queue; |
255 | |
215 | |
256 | // large structures at the end please |
216 | // large structures at the end please |
257 | struct Map lastmap; |
217 | struct Map lastmap; |
… | |
… | |
259 | std::bitset<MAX_FACES> faces_sent; |
219 | std::bitset<MAX_FACES> faces_sent; |
260 | |
220 | |
261 | // if we get an incomplete packet, this is used to hold the data. |
221 | // if we get an incomplete packet, this is used to hold the data. |
262 | // we add 2 byte for the header, one for the trailing 0 byte |
222 | // we add 2 byte for the header, one for the trailing 0 byte |
263 | uint8 inbuf[MAXSOCKBUF + 2 + 1]; |
223 | uint8 inbuf[MAXSOCKBUF + 2 + 1]; |
|
|
224 | |
|
|
225 | enum { MSG_BUF_SIZE = 80, MSG_BUF_COUNT = 10 }; |
|
|
226 | struct msg_buf |
|
|
227 | { |
|
|
228 | tick_t expire; |
|
|
229 | int len; |
|
|
230 | int count; |
|
|
231 | char msg[MSG_BUF_SIZE]; |
|
|
232 | } msgbuf[MSG_BUF_COUNT]; |
|
|
233 | |
|
|
234 | MTH bool msg_suppressed (const char *msg); |
264 | |
235 | |
265 | bool may_execute (const packet_type *pkt) const; |
236 | bool may_execute (const packet_type *pkt) const; |
266 | void execute (const packet_type *pkt, char *data, int datalen); |
237 | void execute (const packet_type *pkt, char *data, int datalen); |
267 | |
238 | |
268 | void queue_command (packet_type *handler, char *data, int datalen); |
239 | void queue_command (packet_type *handler, char *data, int datalen); |