Skip to content

Commit 3340da0

Browse files
Bamcaneheinrich5991
andcommitted
Uuid from the community
Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
1 parent 8feca48 commit 3340da0

File tree

22 files changed

+656
-35
lines changed

22 files changed

+656
-35
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if(NOT POLICY CMP0048)
2626
endif()
2727

2828
project(teeworlds VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
29+
project(teeworlds C CXX)
2930

3031
set(ORIGINAL_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
3132
set(ORIGINAL_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
@@ -1272,6 +1273,8 @@ set_src(BASE GLOB_RECURSE src/base
12721273
tl/sorted_array.h
12731274
tl/string.h
12741275
tl/threading.h
1276+
uuid.c
1277+
uuid.h
12751278
vmath.h
12761279
)
12771280
set_src(ENGINE_INTERFACE GLOB src/engine
@@ -1295,6 +1298,7 @@ set_src(ENGINE_INTERFACE GLOB src/engine
12951298
sound.h
12961299
storage.h
12971300
textrender.h
1301+
uuid.h
12981302
)
12991303
set_src(ENGINE_SHARED GLOB src/engine/shared
13001304
compression.cpp
@@ -1343,11 +1347,16 @@ set_src(ENGINE_SHARED GLOB src/engine/shared
13431347
packer.cpp
13441348
packer.h
13451349
protocol.h
1350+
protocol_ex.cpp
1351+
protocol_ex.h
1352+
protocol_ex_msgs.h
13461353
ringbuffer.cpp
13471354
ringbuffer.h
13481355
snapshot.cpp
13491356
snapshot.h
13501357
storage.cpp
1358+
uuid_manager.cpp
1359+
uuid_manager.h
13511360
)
13521361
set(ENGINE_GENERATED_SHARED src/generated/nethash.cpp src/generated/protocol.cpp src/generated/protocol.h)
13531362
set_src(GAME_SHARED GLOB src/game

bam.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ function GenerateMacOSSettings(settings, conf, arch, compiler)
150150
-- Build server launcher before adding game stuff
151151
local serverlaunch = Link(settings, "serverlaunch", Compile(settings, "src/macoslaunch/server.m"))
152152

153+
-- Add requirements for Server & Client
154+
BuildGameCommon(settings)
155+
153156
-- Master server, version server and tools
154157
BuildEngineCommon(settings)
155158
BuildMasterserver(settings)
156159
BuildVersionserver(settings)
157160
BuildTools(settings)
158161

159-
-- Add requirements for Server & Client
160-
BuildGameCommon(settings)
161-
162162
-- Server
163163
settings.link.frameworks:Add("Cocoa")
164164
local server_exe = BuildServer(settings)
@@ -198,15 +198,15 @@ function GenerateLinuxSettings(settings, conf, arch, compiler)
198198

199199
GenerateCommonSettings(settings, conf, arch, compiler)
200200

201+
-- Add requirements for Server & Client
202+
BuildGameCommon(settings)
203+
201204
-- Master server, version server and tools
202205
BuildEngineCommon(settings)
203206
BuildTools(settings)
204207
BuildMasterserver(settings)
205208
BuildVersionserver(settings)
206209

207-
-- Add requirements for Server & Client
208-
BuildGameCommon(settings)
209-
210210
-- Server
211211
BuildServer(settings)
212212

@@ -262,15 +262,15 @@ function GenerateWindowsSettings(settings, conf, target_arch, compiler)
262262

263263
GenerateCommonSettings(settings, conf, target_arch, compiler)
264264

265+
-- Add requirements for Server & Client
266+
BuildGameCommon(settings)
267+
265268
-- Master server, version server and tools
266269
BuildEngineCommon(settings)
267270
BuildMasterserver(settings)
268271
BuildVersionserver(settings)
269272
BuildTools(settings)
270273

271-
-- Add requirements for Server & Client
272-
BuildGameCommon(settings)
273-
274274
-- Server
275275
local server_settings = settings:Copy()
276276
server_settings.link.extrafiles:Add(icons.server)

datasrc/compile.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import content
44
import network
55

6-
def create_enum_table(names, num):
6+
def create_enum_table(names, num, start = "0"):
77
lines = []
88
lines += ["enum", "{"]
9-
lines += ["\t%s=0,"%names[0]]
9+
lines += [f"\t{names[0]} = {start},"]
1010
for name in names[1:]:
1111
lines += ["\t%s,"%name]
1212
lines += ["\t%s" % num, "};"]
@@ -109,9 +109,16 @@ def EmitFlags(names, num):
109109
for l in create_flags_table(["%s_%s" % (e.name, v) for v in e.values]): print(l)
110110
print("")
111111

112-
for l in create_enum_table(["NETOBJ_INVALID"]+[o.enum_name for o in network.Objects], "NUM_NETOBJTYPES"): print(l)
112+
non_extended = [o for o in network.Objects if o.ex is None]
113+
extended = [o for o in network.Objects if o.ex is not None]
114+
for l in create_enum_table(["NETOBJTYPE_EX"]+[o.enum_name for o in non_extended], "NUM_NETOBJTYPES"): print(l)
115+
for l in create_enum_table(["__NETOBJTYPE_UUID_HELPER"]+[o.enum_name for o in extended], "OFFSET_NETMSGTYPE_UUID", "OFFSET_GAME_UUID - 1"): print(l)
113116
print("")
114-
for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print(l)
117+
118+
non_extended = [o for o in network.Messages if o.ex is None]
119+
extended = [o for o in network.Messages if o.ex is not None]
120+
for l in create_enum_table(["NETMSGTYPE_EX"]+[o.enum_name for o in non_extended], "NUM_NETMSGTYPES"): print(l)
121+
for l in create_enum_table(["__NETMSGTYPE_UUID_HELPER"]+[o.enum_name for o in extended], "OFFSET_MAPITEMTYPE_UUID", "OFFSET_NETMSGTYPE_UUID - 1"): print(l)
115122
print("")
116123

117124
for item in network.Objects + network.Messages:
@@ -267,6 +274,10 @@ class CNetObjHandler
267274
lines += ['{']
268275
lines += ['\tswitch(Type)']
269276
lines += ['\t{']
277+
lines += ['\tcase NETOBJTYPE_EX:']
278+
lines += ['\t{']
279+
lines += ['\t\treturn 0;']
280+
lines += ['\t}']
270281

271282
for item in network.Objects:
272283
base_item = None
@@ -332,6 +343,13 @@ class CNetObjHandler
332343
lines += ['};']
333344
lines += ['']
334345

346+
lines += ['void RegisterGameUuids(CUuidManager *pManager)']
347+
lines += ['{']
348+
349+
for item in network.Objects + network.Messages:
350+
if item.ex is not None:
351+
lines += ['\tpManager->RegisterName(%s, "%s");' % (item.enum_name, item.ex)]
352+
lines += ['}']
335353

336354
for l in lines:
337355
print(l)

datasrc/datatypes.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __init__(self, name, values):
210210
self.values = values
211211

212212
class NetObject:
213-
def __init__(self, name, variables):
213+
def __init__(self, name, variables, ex=None, fixup=True):
214214
l = name.split(":")
215215
self.name = l[0]
216216
self.base = ""
@@ -220,6 +220,10 @@ def __init__(self, name, variables):
220220
self.struct_name = "CNetObj_%s" % self.name
221221
self.enum_name = "NETOBJTYPE_%s" % self.name.upper()
222222
self.variables = variables
223+
if fixup and ex != None:
224+
ex = "object-{}".format(ex)
225+
self.ex = ex
226+
223227
def emit_declaration(self):
224228
if self.base:
225229
lines = ["struct %s : public %s"%(self.struct_name,self.base_struct_name), "{"]
@@ -245,15 +249,17 @@ def emit_validate(self, base_item):
245249

246250

247251
class NetEvent(NetObject):
248-
def __init__(self, name, variables):
249-
NetObject.__init__(self, name, variables)
252+
def __init__(self, name, variables, ex=None):
253+
NetObject.__init__(self, name, variables, ex=ex)
250254
self.base_struct_name = "CNetEvent_%s" % self.base
251255
self.struct_name = "CNetEvent_%s" % self.name
252256
self.enum_name = "NETEVENTTYPE_%s" % self.name.upper()
253257

254258
class NetMessage(NetObject):
255-
def __init__(self, name, variables):
256-
NetObject.__init__(self, name, variables)
259+
def __init__(self, name, variables, ex=None):
260+
if ex != None:
261+
ex = "message-{}".format(ex)
262+
NetObject.__init__(self, name, variables, ex=ex, fixup=False)
257263
self.base_struct_name = "CNetMsg_%s" % self.base
258264
self.struct_name = "CNetMsg_%s" % self.name
259265
self.enum_name = "NETMSGTYPE_%s" % self.name.upper()
@@ -399,3 +405,15 @@ def emit_unpack_check(self):
399405
self.var.name = self.base_name + "[%d]"%i
400406
lines += self.var.emit_unpack_check()
401407
return lines
408+
409+
class NetObjectEx(NetObject):
410+
def __init__(self, name, ex, variables):
411+
NetObject.__init__(self, name, variables, ex=ex)
412+
413+
class NetEventEx(NetEvent):
414+
def __init__(self, name, ex, variables):
415+
NetEvent.__init__(self, name, variables, ex=ex)
416+
417+
class NetMessageEx(NetMessage):
418+
def __init__(self, name, ex, variables):
419+
NetMessage.__init__(self, name, variables, ex=ex)

datasrc/network.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
RawHeader = '''
2525
2626
#include <engine/message.h>
27+
#include <engine/shared/protocol_ex.h>
2728
2829
enum
2930
{

src/base/system.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,65 @@ const char *str_find(const char *haystack, const char *needle)
29082908
return 0;
29092909
}
29102910

2911+
static int hexval(char x)
2912+
{
2913+
switch(x)
2914+
{
2915+
case '0': return 0;
2916+
case '1': return 1;
2917+
case '2': return 2;
2918+
case '3': return 3;
2919+
case '4': return 4;
2920+
case '5': return 5;
2921+
case '6': return 6;
2922+
case '7': return 7;
2923+
case '8': return 8;
2924+
case '9': return 9;
2925+
case 'a':
2926+
case 'A': return 10;
2927+
case 'b':
2928+
case 'B': return 11;
2929+
case 'c':
2930+
case 'C': return 12;
2931+
case 'd':
2932+
case 'D': return 13;
2933+
case 'e':
2934+
case 'E': return 14;
2935+
case 'f':
2936+
case 'F': return 15;
2937+
default: return -1;
2938+
}
2939+
}
2940+
2941+
static int byteval(const char *hex, unsigned char *dst)
2942+
{
2943+
int v1 = hexval(hex[0]);
2944+
int v2 = hexval(hex[1]);
2945+
2946+
if(v1 < 0 || v2 < 0)
2947+
return 1;
2948+
2949+
*dst = v1 * 16 + v2;
2950+
return 0;
2951+
}
2952+
2953+
int str_hex_decode(void *dst, int dst_size, const char *src)
2954+
{
2955+
unsigned char *cdst = (unsigned char *) dst;
2956+
int slen = str_length(src);
2957+
int len = slen / 2;
2958+
int i;
2959+
if(slen != dst_size * 2)
2960+
return 2;
2961+
2962+
for(i = 0; i < len && dst_size; i++, dst_size--)
2963+
{
2964+
if(byteval(src + i * 2, cdst++))
2965+
return 1;
2966+
}
2967+
return 0;
2968+
}
2969+
29112970
void str_hex(char *dst, int dst_size, const void *data, int data_size)
29122971
{
29132972
static const char hex[] = "0123456789ABCDEF";

src/base/system.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,26 @@ const char *str_find_nocase(const char *haystack, const char *needle);
14021402
*/
14031403
const char *str_find(const char *haystack, const char *needle);
14041404

1405+
/*
1406+
Function: str_hex_decode
1407+
Takes a hex string *without spaces between bytes* and returns a
1408+
byte array.
1409+
1410+
Parameters:
1411+
dst - Buffer for the byte array
1412+
dst_size - size of the buffer
1413+
data - String to decode
1414+
1415+
Returns:
1416+
2 - String doesn't exactly fit the buffer
1417+
1 - Invalid character in string
1418+
0 - Success
1419+
1420+
Remarks:
1421+
- The contents of the buffer is only valid on success
1422+
*/
1423+
int str_hex_decode(void *dst, int dst_size, const char *src);
1424+
14051425
/*
14061426
Function: str_hex
14071427
Takes a datablock and generates a hexstring of it.

0 commit comments

Comments
 (0)