Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ teeworlds*
teeworlds_srv*
!other/bash-completion/teeworlds_srv
testrunner
uuid*
versionsrv*

# IDE project files
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ set_src(ENGINE_INTERFACE GLOB src/engine
sound.h
storage.h
textrender.h
uuid.h
)
set_src(ENGINE_SHARED GLOB src/engine/shared
compression.cpp
Expand All @@ -1313,6 +1314,7 @@ set_src(ENGINE_SHARED GLOB src/engine/shared
engine.cpp
filecollection.cpp
filecollection.h
global_uuid_manager.cpp
huffman.cpp
huffman.h
jobs.cpp
Expand Down Expand Up @@ -1343,11 +1345,16 @@ set_src(ENGINE_SHARED GLOB src/engine/shared
packer.cpp
packer.h
protocol.h
protocol_ex.cpp
protocol_ex.h
protocol_ex_msgs.h
ringbuffer.cpp
ringbuffer.h
snapshot.cpp
snapshot.h
storage.cpp
uuid_manager.cpp
uuid_manager.h
)
set(ENGINE_GENERATED_SHARED src/generated/nethash.cpp src/generated/protocol.cpp src/generated/protocol.h)
set_src(GAME_SHARED GLOB src/game
Expand Down Expand Up @@ -1691,6 +1698,7 @@ set_src(TOOLS GLOB src/tools
map_resave.cpp
map_version.cpp
packetgen.cpp
uuid.cpp
)
foreach(ABS_T ${TOOLS})
file(RELATIVE_PATH T "${PROJECT_SOURCE_DIR}/src/tools/" ${ABS_T})
Expand Down Expand Up @@ -1723,6 +1731,7 @@ if(GTEST_FOUND OR DOWNLOAD_GTEST)
bytes_be.cpp
compression.cpp
datafile.cpp
ex.cpp
fs.cpp
git_revision.cpp
hash.cpp
Expand Down
34 changes: 27 additions & 7 deletions datasrc/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
def create_enum_table(names, num):
lines = []
lines += ["enum", "{"]
lines += ["\t%s=0,"%names[0]]
for name in names[1:]:
for name in names:
lines += ["\t%s,"%name]
lines += ["\t%s" % num, "};"]
return lines
Expand Down Expand Up @@ -109,9 +108,17 @@ def EmitFlags(names, num):
for l in create_flags_table(["%s_%s" % (e.name, v) for v in e.values]): print(l)
print("")

for l in create_enum_table(["NETOBJ_INVALID"]+[o.enum_name for o in network.Objects], "NUM_NETOBJTYPES"): print(l)
non_extended = [o for o in network.Objects if o.ex is None]
extended = [o for o in network.Objects if o.ex is not None]
for l in create_enum_table(["NETOBJTYPE_EX"]+[o.enum_name for o in non_extended], "NUM_NETOBJTYPES"): print(l)
for l in create_enum_table(["__NETOBJTYPE_UUID_HELPER=OFFSET_GAME_UUID-1"]+[o.enum_name for o in extended], "OFFSET_NETMSGTYPE_UUID"): print(l)
print("")

non_extended = [o for o in network.Messages if o.ex is None]
extended = [o for o in network.Messages if o.ex is not None]
for l in create_enum_table(["NETMSGTYPE_EX"]+[o.enum_name for o in non_extended], "NUM_NETMSGTYPES"): print(l)
print("")
for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print(l)
for l in create_enum_table(["__NETMSGTYPE_UUID_HELPER=OFFSET_NETMSGTYPE_UUID-1"]+[o.enum_name for o in extended], "END_NETMSGTYPE_UUID"): print(l)
print("")

for item in network.Objects + network.Messages:
Expand Down Expand Up @@ -198,19 +205,20 @@ class CNetObjHandler

lines += ["const char *CNetObjHandler::ms_apObjNames[] = {"]
lines += ['\t"invalid",']
lines += ['\t"%s",' % o.name for o in network.Objects]
lines += ['\t"%s",' % o.name for o in network.Objects if o.ex is None]
lines += ['\t""', "};", ""]

lines += ["int CNetObjHandler::ms_aObjSizes[] = {"]
lines += ['\t0,']
lines += ['\tsizeof(%s),' % o.struct_name for o in network.Objects]
lines += ['\tsizeof(%s),' % o.struct_name for o in network.Objects if o.ex is None]
lines += ['\t0', "};", ""]


lines += ['const char *CNetObjHandler::ms_apMsgNames[] = {']
lines += ['\t"invalid",']
for msg in network.Messages:
lines += ['\t"%s",' % msg.name]
if msg.ex is None:
lines += ['\t"%s",' % msg.name]
lines += ['\t""']
lines += ['};']
lines += ['']
Expand Down Expand Up @@ -267,6 +275,10 @@ class CNetObjHandler
lines += ['{']
lines += ['\tswitch(Type)']
lines += ['\t{']
lines += ['\tcase NETOBJTYPE_EX:']
lines += ['\t{']
lines += ['\t\treturn 0;']
lines += ['\t}']

for item in network.Objects:
base_item = None
Expand Down Expand Up @@ -333,6 +345,14 @@ class CNetObjHandler
lines += ['']


lines += ['void RegisterGameUuids(CUuidManager *pManager)']
lines += ['{']

for item in network.Objects + network.Messages:
if item.ex is not None:
lines += ['\tpManager->RegisterName(%s, "%s");' % (item.enum_name, item.ex)]
lines += ['}']

for l in lines:
print(l)

Expand Down
34 changes: 24 additions & 10 deletions datasrc/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def __init__(self, name, values):
self.values = values

class NetObject:
def __init__(self, name, variables):
def __init__(self, name, variables, ex=None, fixup=True):
l = name.split(":")
self.name = l[0]
self.base = ""
Expand All @@ -220,6 +220,10 @@ def __init__(self, name, variables):
self.struct_name = "CNetObj_%s" % self.name
self.enum_name = "NETOBJTYPE_%s" % self.name.upper()
self.variables = variables
if fixup and ex != None:
ex = "object-{}".format(ex)
self.ex = ex

def emit_declaration(self):
if self.base:
lines = ["struct %s : public %s"%(self.struct_name,self.base_struct_name), "{"]
Expand All @@ -234,26 +238,24 @@ def emit_validate(self, base_item):
lines += ["{"]
lines += ["\tconst %s *pObj = (const %s *)pData;"%(self.struct_name, self.struct_name)]
lines += ["\tif(sizeof(*pObj) != Size) return -1;"]
variables = self.variables
if base_item:
variables += base_item.variables
for v in variables:
for v in self.variables:
lines += ["\t"+line for line in v.emit_validate()]
lines += ["\treturn 0;"]
lines += ["}"]
return lines


class NetEvent(NetObject):
def __init__(self, name, variables):
NetObject.__init__(self, name, variables)
def __init__(self, name, variables, ex=None):
NetObject.__init__(self, name, variables, ex=ex)
self.base_struct_name = "CNetEvent_%s" % self.base
self.struct_name = "CNetEvent_%s" % self.name
self.enum_name = "NETEVENTTYPE_%s" % self.name.upper()

class NetMessage(NetObject):
def __init__(self, name, variables):
NetObject.__init__(self, name, variables)
def __init__(self, name, variables, ex=None):
if ex != None:
ex = "message-{}".format(ex)
NetObject.__init__(self, name, variables, ex=ex, fixup=False)
self.base_struct_name = "CNetMsg_%s" % self.base
self.struct_name = "CNetMsg_%s" % self.name
self.enum_name = "NETMSGTYPE_%s" % self.name.upper()
Expand Down Expand Up @@ -286,6 +288,18 @@ def emit_declaration(self):
lines = lines[:-1] + extra + lines[-1:]
return lines

class NetObjectEx(NetObject):
def __init__(self, name, ex, variables):
NetObject.__init__(self, name, variables, ex=ex)

class NetEventEx(NetEvent):
def __init__(self, name, ex, variables):
NetEvent.__init__(self, name, variables, ex=ex)

class NetMessageEx(NetMessage):
def __init__(self, name, ex, variables):
NetMessage.__init__(self, name, variables, ex=ex)


class NetVariable:
def __init__(self, name, default=None):
Expand Down
14 changes: 14 additions & 0 deletions datasrc/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
RawHeader = '''

#include <engine/message.h>
#include <engine/shared/protocol_ex.h>

enum
{
Expand Down Expand Up @@ -229,6 +230,10 @@
NetArray(NetIntAny("m_aTuneParams"), 32),
]),

NetObjectEx("MyOwnObject", "my-own-object@heinrich5991.de", [
NetIntAny("m_Test"),
]),

## Events

NetEvent("Common", [
Expand Down Expand Up @@ -268,6 +273,10 @@
NetIntRange("m_Precision", 0, 3),
NetFlag("m_RaceFlags", RaceFlags),
]),

NetObjectEx("MyOwnEvent", "my-own-event@heinrich5991.de", [
NetIntAny("m_Test"),
]),
]

Messages = [
Expand Down Expand Up @@ -481,4 +490,9 @@
NetStringStrict("m_Arguments")
]),

# Can't add any NetMessages here!

NetMessageEx("Sv_MyOwnMessage", "my-own-message@heinrich5991.de", [
NetIntAny("m_Test"),
]),
]
Loading
Loading