summaryrefslogtreecommitdiff
blob: 730a69a2f4d09a308fdce09f2c3a8aff32d4c1a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
http://sourceforge.net/p/sauerbraten/code/4699/

--- a/src/shared/iengine.h
+++ b/src/shared/iengine.h
@@ -415,23 +415,6 @@
 extern int getservermtu();
 extern int getnumclients();
 extern uint getclientip(int n);
-extern void putint(ucharbuf &p, int n);
-extern void putint(packetbuf &p, int n);
-extern void putint(vector<uchar> &p, int n);
-extern int getint(ucharbuf &p);
-extern void putuint(ucharbuf &p, int n);
-extern void putuint(packetbuf &p, int n);
-extern void putuint(vector<uchar> &p, int n);
-extern int getuint(ucharbuf &p);
-extern void putfloat(ucharbuf &p, float f);
-extern void putfloat(packetbuf &p, float f);
-extern void putfloat(vector<uchar> &p, float f);
-extern float getfloat(ucharbuf &p);
-extern void sendstring(const char *t, ucharbuf &p);
-extern void sendstring(const char *t, packetbuf &p);
-extern void sendstring(const char *t, vector<uchar> &p);
-extern void getstring(char *t, ucharbuf &p, int len = MAXTRANS);
-extern void filtertext(char *dst, const char *src, bool whitespace = true, int len = sizeof(string)-1);
 extern void localconnect();
 extern const char *disconnectreason(int reason);
 extern void disconnect_client(int n, int reason);
--- a/src/engine/server.cpp
+++ b/src/engine/server.cpp
@@ -99,125 +99,6 @@
     va_end(args);
 }
 #endif
-
-// all network traffic is in 32bit ints, which are then compressed using the following simple scheme (assumes that most values are small).
-
-template<class T>
-static inline void putint_(T &p, int n)
-{
-    if(n<128 && n>-127) p.put(n);
-    else if(n<0x8000 && n>=-0x8000) { p.put(0x80); p.put(n); p.put(n>>8); }
-    else { p.put(0x81); p.put(n); p.put(n>>8); p.put(n>>16); p.put(n>>24); }
-}
-void putint(ucharbuf &p, int n) { putint_(p, n); }
-void putint(packetbuf &p, int n) { putint_(p, n); }
-void putint(vector<uchar> &p, int n) { putint_(p, n); }
-
-int getint(ucharbuf &p)
-{
-    int c = (char)p.get();
-    if(c==-128) { int n = p.get(); n |= char(p.get())<<8; return n; }
-    else if(c==-127) { int n = p.get(); n |= p.get()<<8; n |= p.get()<<16; return n|(p.get()<<24); } 
-    else return c;
-}
-
-// much smaller encoding for unsigned integers up to 28 bits, but can handle signed
-template<class T>
-static inline void putuint_(T &p, int n)
-{
-    if(n < 0 || n >= (1<<21))
-    {
-        p.put(0x80 | (n & 0x7F));
-        p.put(0x80 | ((n >> 7) & 0x7F));
-        p.put(0x80 | ((n >> 14) & 0x7F));
-        p.put(n >> 21);
-    }
-    else if(n < (1<<7)) p.put(n);
-    else if(n < (1<<14))
-    {
-        p.put(0x80 | (n & 0x7F));
-        p.put(n >> 7);
-    }
-    else 
-    { 
-        p.put(0x80 | (n & 0x7F)); 
-        p.put(0x80 | ((n >> 7) & 0x7F));
-        p.put(n >> 14); 
-    }
-}
-void putuint(ucharbuf &p, int n) { putuint_(p, n); }
-void putuint(packetbuf &p, int n) { putuint_(p, n); }
-void putuint(vector<uchar> &p, int n) { putuint_(p, n); }
-
-int getuint(ucharbuf &p)
-{
-    int n = p.get();
-    if(n & 0x80)
-    {
-        n += (p.get() << 7) - 0x80;
-        if(n & (1<<14)) n += (p.get() << 14) - (1<<14);
-        if(n & (1<<21)) n += (p.get() << 21) - (1<<21);
-        if(n & (1<<28)) n |= -1<<28;
-    }
-    return n;
-}
-
-template<class T>
-static inline void putfloat_(T &p, float f)
-{
-    lilswap(&f, 1);
-    p.put((uchar *)&f, sizeof(float));
-}
-void putfloat(ucharbuf &p, float f) { putfloat_(p, f); }
-void putfloat(packetbuf &p, float f) { putfloat_(p, f); }
-void putfloat(vector<uchar> &p, float f) { putfloat_(p, f); }
-
-float getfloat(ucharbuf &p)
-{
-    float f;
-    p.get((uchar *)&f, sizeof(float));
-    return lilswap(f);
-}
-
-template<class T>
-static inline void sendstring_(const char *t, T &p)
-{
-    while(*t) putint(p, *t++);
-    putint(p, 0);
-}
-void sendstring(const char *t, ucharbuf &p) { sendstring_(t, p); }
-void sendstring(const char *t, packetbuf &p) { sendstring_(t, p); }
-void sendstring(const char *t, vector<uchar> &p) { sendstring_(t, p); }
-
-void getstring(char *text, ucharbuf &p, int len)
-{
-    char *t = text;
-    do
-    {
-        if(t>=&text[len]) { text[len-1] = 0; return; }
-        if(!p.remaining()) { *t = 0; return; } 
-        *t = getint(p);
-    }
-    while(*t++);
-}
-
-void filtertext(char *dst, const char *src, bool whitespace, int len)
-{
-    for(int c = uchar(*src); c; c = uchar(*++src))
-    {
-        if(c == '\f')
-        {
-            if(!*++src) break;
-            continue;
-        }
-        if(iscubeprint(c) || (iscubespace(c) && whitespace))
-        {
-            *dst++ = c;
-            if(!--len) break;
-        }
-    }
-    *dst = '\0';
-}
 
 enum { ST_EMPTY, ST_LOCAL, ST_TCPIP };
 
--- a/src/shared/tools.h
+++ b/src/shared/tools.h
@@ -1178,5 +1178,24 @@
 extern uint randomMT();
 extern int guessnumcpus();
 
-#endif
-
+extern void putint(ucharbuf &p, int n);
+extern void putint(packetbuf &p, int n);
+extern void putint(vector<uchar> &p, int n);
+extern int getint(ucharbuf &p);
+extern void putuint(ucharbuf &p, int n);
+extern void putuint(packetbuf &p, int n);
+extern void putuint(vector<uchar> &p, int n);
+extern int getuint(ucharbuf &p);
+extern void putfloat(ucharbuf &p, float f);
+extern void putfloat(packetbuf &p, float f);
+extern void putfloat(vector<uchar> &p, float f);
+extern float getfloat(ucharbuf &p);
+extern void sendstring(const char *t, ucharbuf &p);
+extern void sendstring(const char *t, packetbuf &p);
+extern void sendstring(const char *t, vector<uchar> &p);
+extern void getstring(char *t, ucharbuf &p, int len);
+template<class T, size_t N> static inline void getstring(T (&t)[N], ucharbuf &p) { getstring(t, p, N); } 
+extern void filtertext(char *dst, const char *src, bool whitespace = true, int len = sizeof(string)-1);
+
+#endif
+
--- a/src/engine/master.cpp
+++ b/src/engine/master.cpp
@@ -514,7 +514,7 @@
     authreq &a = c.authreqs.add();
     a.reqtime = servtime;
     a.id = id;
-    uint seed[3] = { starttime, servtime, randomMT() };
+    uint seed[3] = { uint(starttime), servtime, randomMT() };
     static vector<char> buf;
     buf.setsize(0);
     a.answer = genchallenge(u->pubkey, seed, sizeof(seed), buf);
--- a/src/shared/tools.cpp
+++ b/src/shared/tools.cpp
@@ -53,3 +53,124 @@
     return y;
 }
 
+///////////////////////// network ///////////////////////
+
+// all network traffic is in 32bit ints, which are then compressed using the following simple scheme (assumes that most values are small).
+
+template<class T>
+static inline void putint_(T &p, int n)
+{
+    if(n<128 && n>-127) p.put(n);
+    else if(n<0x8000 && n>=-0x8000) { p.put(0x80); p.put(n); p.put(n>>8); }
+    else { p.put(0x81); p.put(n); p.put(n>>8); p.put(n>>16); p.put(n>>24); }
+}
+void putint(ucharbuf &p, int n) { putint_(p, n); }
+void putint(packetbuf &p, int n) { putint_(p, n); }
+void putint(vector<uchar> &p, int n) { putint_(p, n); }
+
+int getint(ucharbuf &p)
+{
+    int c = (char)p.get();
+    if(c==-128) { int n = p.get(); n |= char(p.get())<<8; return n; }
+    else if(c==-127) { int n = p.get(); n |= p.get()<<8; n |= p.get()<<16; return n|(p.get()<<24); }
+    else return c;
+}
+
+// much smaller encoding for unsigned integers up to 28 bits, but can handle signed
+template<class T>
+static inline void putuint_(T &p, int n)
+{
+    if(n < 0 || n >= (1<<21))
+    {
+        p.put(0x80 | (n & 0x7F));
+        p.put(0x80 | ((n >> 7) & 0x7F));
+        p.put(0x80 | ((n >> 14) & 0x7F));
+        p.put(n >> 21);
+    }
+    else if(n < (1<<7)) p.put(n);
+    else if(n < (1<<14))
+    {
+        p.put(0x80 | (n & 0x7F));
+        p.put(n >> 7);
+    }
+    else
+    {
+        p.put(0x80 | (n & 0x7F));
+        p.put(0x80 | ((n >> 7) & 0x7F));
+        p.put(n >> 14);
+    }
+}
+void putuint(ucharbuf &p, int n) { putuint_(p, n); }
+void putuint(packetbuf &p, int n) { putuint_(p, n); }
+void putuint(vector<uchar> &p, int n) { putuint_(p, n); }
+
+int getuint(ucharbuf &p)
+{
+    int n = p.get();
+    if(n & 0x80)
+    {
+        n += (p.get() << 7) - 0x80;
+        if(n & (1<<14)) n += (p.get() << 14) - (1<<14);
+        if(n & (1<<21)) n += (p.get() << 21) - (1<<21);
+        if(n & (1<<28)) n |= -1<<28;
+    }
+    return n;
+}
+
+template<class T>
+static inline void putfloat_(T &p, float f)
+{
+    lilswap(&f, 1);
+    p.put((uchar *)&f, sizeof(float));
+}
+void putfloat(ucharbuf &p, float f) { putfloat_(p, f); }
+void putfloat(packetbuf &p, float f) { putfloat_(p, f); }
+void putfloat(vector<uchar> &p, float f) { putfloat_(p, f); }
+
+float getfloat(ucharbuf &p)
+{
+    float f;
+    p.get((uchar *)&f, sizeof(float));
+    return lilswap(f);
+}
+
+template<class T>
+static inline void sendstring_(const char *t, T &p)
+{
+    while(*t) putint(p, *t++);
+    putint(p, 0);
+}
+void sendstring(const char *t, ucharbuf &p) { sendstring_(t, p); }
+void sendstring(const char *t, packetbuf &p) { sendstring_(t, p); }
+void sendstring(const char *t, vector<uchar> &p) { sendstring_(t, p); }
+
+void getstring(char *text, ucharbuf &p, int len)
+{
+    char *t = text;
+    do
+    {
+        if(t>=&text[len]) { text[len-1] = 0; return; }
+        if(!p.remaining()) { *t = 0; return; }
+        *t = getint(p);
+    }
+    while(*t++);
+}
+
+void filtertext(char *dst, const char *src, bool whitespace, int len)
+{
+    for(int c = uchar(*src); c; c = uchar(*++src))
+    {
+        if(c == '\f')
+        {
+            if(!*++src) break;
+            continue;
+        }
+        if(iscubeprint(c) || (iscubespace(c) && whitespace))
+        {
+            *dst++ = c;
+            if(!--len) break;
+        }
+    }
+    *dst = '\0';
+}
+