1 | |
|
|
2 | /* |
1 | /* |
3 | CrossFire, A Multiplayer game for the X Window System |
2 | CrossFire, A Multiplayer game for the X Window System |
4 | |
3 | |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
20 | |
22 | The author can be reached via e-mail to crossfire@schmorp.de |
21 | The author can be reached via e-mail to crossfire@schmorp.de |
23 | */ |
22 | */ |
24 | |
23 | |
25 | /* |
|
|
26 | newserver.h defines various structures and values that are use for the |
|
|
27 | new client server communication method. Values defined here are only |
|
|
28 | used on the server side code. For shared client/server values, see |
|
|
29 | newclient.h |
|
|
30 | */ |
|
|
31 | |
|
|
32 | #ifndef CLIENT_H |
24 | #ifndef CLIENT_H |
33 | #define CLIENT_H |
25 | #define CLIENT_H |
34 | |
26 | |
35 | /* Reduce this from 50 to 5 - as it is now, there will never be more |
27 | #include <deque> |
36 | * than 3 anyways. |
|
|
37 | */ |
|
|
38 | |
28 | |
|
|
29 | // (possibly) max. number of objects "per page" in the ground container |
39 | #define NUM_LOOK_OBJECTS 50 |
30 | #define NUM_LOOK_OBJECTS 50 |
40 | |
31 | |
41 | struct MapCell |
32 | struct MapCell |
42 | { |
33 | { |
43 | UUID player; // this is, unfortunately, very wasteful of memory space, but pretty bandwidth-efficient |
34 | UUID player; // this is, unfortunately, very wasteful of memory space, but pretty bandwidth-efficient |
… | |
… | |
92 | struct Buffer |
83 | struct Buffer |
93 | { |
84 | { |
94 | char data[SOCKETBUFSIZE]; |
85 | char data[SOCKETBUFSIZE]; |
95 | int start; |
86 | int start; |
96 | int len; |
87 | int len; |
|
|
88 | }; |
|
|
89 | |
|
|
90 | // a handler for a specific type of packet |
|
|
91 | enum { |
|
|
92 | PF_PLAYER = 0x01, // must have valid player |
|
|
93 | PF_IMMEDIATE = 0x02, // TODO: hack, can be executed immediately |
|
|
94 | PF_PLAYING = 0x04, // must be in playing state |
|
|
95 | }; |
|
|
96 | |
|
|
97 | struct packet_type |
|
|
98 | { |
|
|
99 | const char *name; |
|
|
100 | void *cb; |
|
|
101 | int flags; |
|
|
102 | }; |
|
|
103 | |
|
|
104 | struct command |
|
|
105 | { |
|
|
106 | tstamp stamp; |
|
|
107 | const packet_type *handler; |
|
|
108 | char *data; |
|
|
109 | int datalen; |
|
|
110 | |
|
|
111 | command (tstamp stamp, const packet_type *handler, char *data, int datalen) |
|
|
112 | : stamp (stamp), handler (handler), data (data), datalen (datalen) |
|
|
113 | { |
|
|
114 | } |
97 | }; |
115 | }; |
98 | |
116 | |
99 | /* how many times we are allowed to give the wrong password before being kicked. */ |
117 | /* how many times we are allowed to give the wrong password before being kicked. */ |
100 | #define MAX_PASSWORD_FAILURES 5 |
118 | #define MAX_PASSWORD_FAILURES 5 |
101 | |
119 | |
… | |
… | |
146 | |
164 | |
147 | maptile *ACC (RW, current_map); // CF+ last/current player map |
165 | maptile *ACC (RW, current_map); // CF+ last/current player map |
148 | int ACC (RW, current_x), ACC (RW, current_y); // CF+ last/current map position |
166 | int ACC (RW, current_x), ACC (RW, current_y); // CF+ last/current map position |
149 | char ACC (RW, version)[64]; // CF+ client name/version |
167 | char ACC (RW, version)[64]; // CF+ client name/version |
150 | |
168 | |
151 | /* If we get an incomplete packet, this is used to hold the data. */ |
169 | // if we get an incomplete packet, this is used to hold the data. |
|
|
170 | // we add 2 byte for the header, one for the trailing 0 byte |
152 | uint8 inbuf[MAXSOCKBUF]; |
171 | uint8 inbuf[MAXSOCKBUF + 2 + 1]; |
153 | player *ACC (RO, pl);//TODO should not be here, preferably |
172 | player *ACC (RO, pl);//TODO should not be here, preferably |
154 | |
173 | |
155 | int ACC (RW, rtt), ACC (RW, rttvar); /* round-trip time and -variance, if known */ |
174 | int ACC (RW, rtt), ACC (RW, rttvar); /* round-trip time and -variance, if known */ |
156 | |
|
|
157 | iow socket_ev; void socket_cb (iow &w, int got); |
|
|
158 | |
175 | |
159 | client (int fd, const char *from_ip); |
176 | client (int fd, const char *from_ip); |
160 | ~client (); |
177 | ~client (); |
|
|
178 | void destroy (); |
161 | |
179 | |
|
|
180 | iw cmd_ev; void cmd_cb (iw &w); |
|
|
181 | iow socket_ev; void socket_cb (iow &w, int got); |
|
|
182 | |
|
|
183 | std::deque< command, slice_allocator<command> > cmd_queue; |
|
|
184 | |
|
|
185 | // those should probably be client methods |
|
|
186 | bool may_execute (const packet_type *pkt) const; |
|
|
187 | void execute (const packet_type *pkt, char *data, int datalen); |
|
|
188 | |
|
|
189 | void queue_command (packet_type *handler, char *data, int datalen); |
|
|
190 | bool handle_command (); |
|
|
191 | |
|
|
192 | bool handle_packet (); |
162 | int read_packet (); // returns length of packet or 0 |
193 | int next_packet (); // returns length of packet or 0 |
163 | void skip_packet (int len); // we have processed the packet, skip it |
194 | void skip_packet (int len); // we have processed the packet, skip it |
164 | |
195 | |
165 | void flush (); |
196 | void flush (); |
166 | void write_outputbuffer (); |
197 | void write_outputbuffer (); |
167 | void send (void *buf_, int len); |
198 | void send (void *buf_, int len); |
168 | |
199 | |
169 | void send_packet (const char *buf); |
200 | void send_packet (const char *buf); |
170 | void send_packet (const char *buf, int len); |
201 | void send_packet (const char *buf, int len); |
|
|
202 | void send_packet_printf (const char *format, ...); |
171 | void send_packet (packet &sl); |
203 | void send_packet (packet &sl); |
172 | }; |
204 | }; |
173 | |
205 | |
174 | #define CLIENT_SUPPORT_READABLES(__sockPtr,__type)\ |
206 | #define CLIENT_SUPPORT_READABLES(__sockPtr,__type)\ |
175 | ( ((__type)>0) &&\ |
207 | ( ((__type)>0) &&\ |