… | |
… | |
17 | |
17 | |
18 | You should have received a copy of the GNU General Public License |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
21 | |
22 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
22 | The authors can be reached via e-mail at crossfire@schmorp.de |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /* This file defines various flags that both the new client and |
25 | /* This file defines various flags that both the new client and |
26 | * newserver uses. These should never be changed, only expanded. |
26 | * newserver uses. These should never be changed, only expanded. |
27 | * Changing them will likely cause all old clients to not work properly. |
27 | * Changing them will likely cause all old clients to not work properly. |
… | |
… | |
39 | * more reliable, as both the client and server will definately be |
39 | * more reliable, as both the client and server will definately be |
40 | * talking about the same values. |
40 | * talking about the same values. |
41 | */ |
41 | */ |
42 | |
42 | |
43 | |
43 | |
44 | #ifndef NEWCLIENT_H |
44 | #ifndef NETWORK_H |
45 | #define NEWCLIENT_H |
45 | #define NETWORK_H |
|
|
46 | |
|
|
47 | #include <cstdarg> |
46 | |
48 | |
47 | /* Maximum size of any packet we expect. Using this makes it so we don't need to |
49 | /* Maximum size of any packet we expect. Using this makes it so we don't need to |
48 | * allocated and deallocated the same buffer over and over again and the price |
50 | * allocated and deallocated the same buffer over and over again and the price |
49 | * of using a bit of extra memory. It also makes the code simpler. |
51 | * of using a bit of extra memory. It also makes the code simpler. |
50 | * |
52 | * |
… | |
… | |
274 | // strategy: only check on variable-length adds |
276 | // strategy: only check on variable-length adds |
275 | // and allow 256 bytes for any headers. |
277 | // and allow 256 bytes for any headers. |
276 | uint8 *cur; |
278 | uint8 *cur; |
277 | uint8 buf_ [hdrlen + bufsize + 256]; |
279 | uint8 buf_ [hdrlen + bufsize + 256]; |
278 | |
280 | |
279 | packet () { reset (); } |
281 | packet () |
|
|
282 | { |
|
|
283 | reset (); |
|
|
284 | } |
|
|
285 | |
|
|
286 | packet (const char *name); |
280 | |
287 | |
281 | uint8 operator [](unsigned int i) const { return buf_ [i + hdrlen]; } |
288 | uint8 operator [](unsigned int i) const { return buf_ [i + hdrlen]; } |
282 | uint8 &operator [](unsigned int i) { return buf_ [i + hdrlen]; } |
289 | uint8 &operator [](unsigned int i) { return buf_ [i + hdrlen]; } |
283 | |
290 | |
284 | uint8 *buf () { return buf_ + hdrlen; } |
291 | uint8 *buf () { return buf_ + hdrlen; } |
… | |
… | |
306 | packet &operator <<(const data16 &v); |
313 | packet &operator <<(const data16 &v); |
307 | |
314 | |
308 | packet &operator <<(const char *v); |
315 | packet &operator <<(const char *v); |
309 | packet &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); } |
316 | packet &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); } |
310 | |
317 | |
|
|
318 | void vprintf (const char *format, va_list ap); |
|
|
319 | |
311 | void printf (const char *format, ...); |
320 | void printf (const char *format, ...) |
|
|
321 | { |
|
|
322 | va_list ap; |
|
|
323 | va_start (ap, format); |
|
|
324 | vprintf (format, ap); |
|
|
325 | va_end (ap); |
|
|
326 | } |
312 | }; |
327 | }; |
313 | |
328 | |
314 | inline uint16 net_uint16 (uint8 *data) { return (data [0] << 8) | data [1]; } |
329 | inline uint16 net_uint16 (uint8 *data) { return (data [0] << 8) | data [1]; } |
315 | inline uint32 net_uint32 (uint8 *data) { return (net_uint16 (data) << 16) | net_uint16 (data + 2); } |
330 | inline uint32 net_uint32 (uint8 *data) { return (net_uint16 (data) << 16) | net_uint16 (data + 2); } |
316 | inline sint16 net_sint16 (uint8 *data) { return sint16 (net_uint16 (data)); } |
331 | inline sint16 net_sint16 (uint8 *data) { return sint16 (net_uint16 (data)); } |