ddnet/datasrc/network.py

392 lines
9.4 KiB
Python
Raw Normal View History

2008-04-27 05:59:38 +00:00
from datatypes import *
2012-08-03 16:46:01 +00:00
Pickups = Enum("PICKUP", ["HEALTH", "ARMOR", "GRENADE", "SHOTGUN", "LASER", "NINJA"])
Emotes = Enum("EMOTE", ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"])
Emoticons = Enum("EMOTICON", ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"])
2008-04-27 05:59:38 +00:00
2012-08-03 16:46:01 +00:00
PlayerFlags = Flags("PLAYERFLAG", ["CHATTING", "SCOREBOARD", "READY", "DEAD", "WATCHING"])
GameFlags = Flags("GAMEFLAG", ["TEAMS", "FLAGS", "SURVIVAL"])
GameStateFlags = Flags("GAMESTATEFLAG", ["WARMUP", "SUDDENDEATH", "ROUNDOVER", "GAMEOVER", "PAUSED", "STARTCOUNTDOWN"])
2012-08-13 08:36:01 +00:00
CoreEventFlags = Flags("COREEVENTFLAG", ["GROUND_JUMP", "AIR_JUMP", "HOOK_ATTACH_PLAYER", "HOOK_ATTACH_GROUND", "HOOK_HIT_NOHOOK"])
GameMsgIDs = Enum("GAMEMSG", ["TEAM_SWAP", "VOTE_ABORT", "VOTE_PASS", "VOTE_FAIL", "VOTE_DENY_SPECCALL", "VOTE_DENY_ACTIVE", "VOTE_DENY_KICK", "VOTE_DENY_KICKID",
"VOTE_DENY_KICKSELF", "VOTE_DENY_KICKADMIN", "VOTE_DENY_SPEC", "VOTE_DENY_SPECID", "VOTE_DENY_SPECSELF", "SPEC_INVALIDID", "TEAM_SHUFFLE",
"TEAM_LOCK", "TEAM_UNLOCK", "TEAM_BALANCE", "TEAM_DENY_LOCK", "TEAM_DENY_BALANCE", "CTF_DROP", "CTF_RETURN",
"VOTE_DENY_WAIT", "VOTE_DENY_KICKMIN", "TEAM_ALL", "TEAM_DENY_MAX", "TEAM_BALANCE_VICTIM", "CTF_GRAB",
"TEAM_DENY_WAIT",
"CTF_CAPTURE",
"VOTE_DENY_INVALIDOP", "VOTE_KICKYOU", "VOTE_FORCE",
"VOTE_FORCEOP", "VOTE_FORCESPEC",
"VOTE_CALLOP", "VOTE_CALLKICK", "VOTE_CALLSPEC"])
RawHeader = '''
2010-05-29 07:25:38 +00:00
#include <engine/message.h>
enum
{
2011-01-03 11:50:38 +00:00
INPUT_STATE_MASK=0x3f
};
enum
{
TEAM_SPECTATORS=-1,
TEAM_RED,
2011-03-04 16:08:10 +00:00
TEAM_BLUE,
2012-02-15 00:39:13 +00:00
NUM_TEAMS,
2011-03-04 16:08:10 +00:00
FLAG_MISSING=-3,
FLAG_ATSTAND,
2011-03-04 16:08:10 +00:00
FLAG_TAKEN,
SPEC_FREEVIEW=-1,
};
'''
RawSource = '''
2010-05-29 07:25:38 +00:00
#include <engine/message.h>
#include "protocol.h"
'''
Enums = [
2012-08-03 16:46:01 +00:00
Pickups,
Emotes,
Emoticons,
GameMsgIDs,
]
2008-04-27 05:59:38 +00:00
2008-08-27 15:51:09 +00:00
Flags = [
2012-08-03 16:46:01 +00:00
PlayerFlags,
GameFlags,
2012-08-13 08:36:01 +00:00
GameStateFlags,
CoreEventFlags,
2008-08-27 15:51:09 +00:00
]
2008-04-27 05:59:38 +00:00
Objects = [
2010-05-29 07:25:38 +00:00
NetObject("PlayerInput", [
2012-08-03 16:46:01 +00:00
NetIntRange("m_Direction", -1, 1),
2010-05-29 07:25:38 +00:00
NetIntAny("m_TargetX"),
NetIntAny("m_TargetY"),
2012-08-03 16:46:01 +00:00
NetBool("m_Jump"),
2010-05-29 07:25:38 +00:00
NetIntAny("m_Fire"),
2012-08-03 16:46:01 +00:00
NetBool("m_Hook"),
2012-08-03 16:46:01 +00:00
NetFlag("m_PlayerFlags", PlayerFlags),
2012-08-03 16:46:01 +00:00
NetIntRange("m_WantedWeapon", 0, 'NUM_WEAPONS-1'),
2010-05-29 07:25:38 +00:00
NetIntAny("m_NextWeapon"),
NetIntAny("m_PrevWeapon"),
2008-04-27 05:59:38 +00:00
]),
2008-04-27 05:59:38 +00:00
NetObject("Projectile", [
2010-05-29 07:25:38 +00:00
NetIntAny("m_X"),
NetIntAny("m_Y"),
NetIntAny("m_VelX"),
NetIntAny("m_VelY"),
2010-05-29 07:25:38 +00:00
NetIntRange("m_Type", 0, 'NUM_WEAPONS-1'),
NetTick("m_StartTick"),
2008-04-27 05:59:38 +00:00
]),
NetObject("Laser", [
2010-05-29 07:25:38 +00:00
NetIntAny("m_X"),
NetIntAny("m_Y"),
NetIntAny("m_FromX"),
NetIntAny("m_FromY"),
2010-05-29 07:25:38 +00:00
NetTick("m_StartTick"),
2008-04-27 05:59:38 +00:00
]),
NetObject("Pickup", [
2010-05-29 07:25:38 +00:00
NetIntAny("m_X"),
NetIntAny("m_Y"),
2012-08-03 16:46:01 +00:00
NetEnum("m_Type", Pickups),
2008-04-27 05:59:38 +00:00
]),
NetObject("Flag", [
2010-05-29 07:25:38 +00:00
NetIntAny("m_X"),
NetIntAny("m_Y"),
2011-03-04 16:08:10 +00:00
NetIntRange("m_Team", 'TEAM_RED', 'TEAM_BLUE')
2008-04-27 05:59:38 +00:00
]),
NetObject("GameData", [
2012-02-15 00:39:40 +00:00
NetTick("m_GameStartTick"),
2012-08-03 16:46:01 +00:00
NetFlag("m_GameStateFlags", GameStateFlags),
NetTick("m_GameStateEndTick"),
2011-03-04 16:08:10 +00:00
]),
2008-04-27 05:59:38 +00:00
NetObject("GameDataTeam", [
2010-05-29 07:25:38 +00:00
NetIntAny("m_TeamscoreRed"),
NetIntAny("m_TeamscoreBlue"),
]),
2011-03-04 16:08:10 +00:00
NetObject("GameDataFlag", [
NetIntRange("m_FlagCarrierRed", 'FLAG_MISSING', 'MAX_CLIENTS-1'),
NetIntRange("m_FlagCarrierBlue", 'FLAG_MISSING', 'MAX_CLIENTS-1'),
2012-03-04 11:46:22 +00:00
NetTick("m_FlagDropTickRed"),
NetTick("m_FlagDropTickBlue"),
2008-04-27 05:59:38 +00:00
]),
2010-05-29 07:25:38 +00:00
NetObject("CharacterCore", [
2012-08-03 16:46:01 +00:00
NetTick("m_Tick"),
2010-05-29 07:25:38 +00:00
NetIntAny("m_X"),
NetIntAny("m_Y"),
NetIntAny("m_VelX"),
NetIntAny("m_VelY"),
2008-04-27 05:59:38 +00:00
2010-05-29 07:25:38 +00:00
NetIntAny("m_Angle"),
NetIntRange("m_Direction", -1, 1),
2010-05-29 07:25:38 +00:00
NetIntRange("m_Jumped", 0, 3),
NetIntRange("m_HookedPlayer", 0, 'MAX_CLIENTS-1'),
NetIntRange("m_HookState", -1, 5),
NetTick("m_HookTick"),
NetIntAny("m_HookX"),
NetIntAny("m_HookY"),
NetIntAny("m_HookDx"),
NetIntAny("m_HookDy"),
]),
NetObject("Character:CharacterCore", [
NetIntRange("m_Health", 0, 10),
NetIntRange("m_Armor", 0, 10),
NetIntAny("m_AmmoCount"),
2010-05-29 07:25:38 +00:00
NetIntRange("m_Weapon", 0, 'NUM_WEAPONS-1'),
2012-08-03 16:46:01 +00:00
NetEnum("m_Emote", Emotes),
NetTick("m_AttackTick"),
2012-08-13 08:36:01 +00:00
NetFlag("m_TriggeredEvents", CoreEventFlags),
]),
2010-05-29 07:25:38 +00:00
NetObject("PlayerInfo", [
2012-08-03 16:46:01 +00:00
NetFlag("m_PlayerFlags", PlayerFlags),
2010-05-29 07:25:38 +00:00
NetIntAny("m_Score"),
NetIntAny("m_Latency"),
2008-04-27 05:59:38 +00:00
]),
NetObject("SpectatorInfo", [
NetIntRange("m_SpectatorID", 'SPEC_FREEVIEW', 'MAX_CLIENTS-1'),
NetIntAny("m_X"),
NetIntAny("m_Y"),
]),
## Demo
NetObject("De_ClientInfo", [
2012-08-03 16:46:01 +00:00
NetBool("m_Local"),
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
NetArray(NetIntAny("m_aName"), 4),
NetArray(NetIntAny("m_aClan"), 3),
NetIntAny("m_Country"),
2012-01-26 18:53:23 +00:00
NetArray(NetArray(NetIntAny("m_aaSkinPartNames"), 6), 6),
2012-08-03 16:46:01 +00:00
NetArray(NetBool("m_aUseCustomColors"), 6),
2012-01-26 18:53:23 +00:00
NetArray(NetIntAny("m_aSkinPartColors"), 6),
]),
NetObject("De_GameInfo", [
2012-08-03 16:46:01 +00:00
NetFlag("m_GameFlags", GameFlags),
NetIntRange("m_ScoreLimit", 0, 'max_int'),
NetIntRange("m_TimeLimit", 0, 'max_int'),
NetIntRange("m_MatchNum", 0, 'max_int'),
NetIntRange("m_MatchCurrent", 0, 'max_int'),
]),
NetObject("De_TuneParams", [
# todo: should be done differently
NetArray(NetIntAny("m_aTuneParams"), 33),
]),
2008-04-27 05:59:38 +00:00
## Events
NetEvent("Common", [
2010-05-29 07:25:38 +00:00
NetIntAny("m_X"),
NetIntAny("m_Y"),
2008-04-27 05:59:38 +00:00
]),
2008-04-27 05:59:38 +00:00
NetEvent("Explosion:Common", []),
NetEvent("Spawn:Common", []),
NetEvent("HammerHit:Common", []),
NetEvent("Death:Common", [
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
]),
NetEvent("SoundWorld:Common", [
NetIntRange("m_SoundID", 0, 'NUM_SOUNDS-1'),
2008-04-27 05:59:38 +00:00
]),
NetEvent("DamageInd:Common", [
2010-05-29 07:25:38 +00:00
NetIntAny("m_Angle"),
2008-04-27 05:59:38 +00:00
]),
]
Messages = [
### Server messages
2010-05-29 07:25:38 +00:00
NetMessage("Sv_Motd", [
NetString("m_pMessage"),
2008-04-27 05:59:38 +00:00
]),
2010-05-29 07:25:38 +00:00
NetMessage("Sv_Chat", [
2011-01-03 11:50:38 +00:00
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'),
2010-05-29 07:25:38 +00:00
NetString("m_pMessage"),
2008-04-27 05:59:38 +00:00
]),
NetMessage("Sv_Team", [
NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'),
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
2012-08-03 16:46:01 +00:00
NetBool("m_Silent"),
]),
2010-05-29 07:25:38 +00:00
NetMessage("Sv_KillMsg", [
NetIntRange("m_Killer", 0, 'MAX_CLIENTS-1'),
NetIntRange("m_Victim", 0, 'MAX_CLIENTS-1'),
NetIntRange("m_Weapon", -3, 'NUM_WEAPONS-1'),
NetIntAny("m_ModeSpecial"),
2008-04-27 05:59:38 +00:00
]),
2010-05-29 07:25:38 +00:00
NetMessage("Sv_TuneParams", []),
NetMessage("Sv_ExtraProjectile", []),
NetMessage("Sv_ReadyToEnter", []),
2008-04-27 05:59:38 +00:00
2010-05-29 07:25:38 +00:00
NetMessage("Sv_WeaponPickup", [
NetIntRange("m_Weapon", 0, 'NUM_WEAPONS-1'),
2008-04-27 05:59:38 +00:00
]),
2010-05-29 07:25:38 +00:00
NetMessage("Sv_Emoticon", [
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
2012-08-03 16:46:01 +00:00
NetEnum("m_Emoticon", Emoticons),
2008-04-27 05:59:38 +00:00
]),
2008-09-24 14:47:03 +00:00
2010-05-29 07:25:38 +00:00
NetMessage("Sv_VoteClearOptions", [
2008-11-08 12:50:46 +00:00
]),
NetMessage("Sv_VoteOptionListAdd", [
NetIntRange("m_NumOptions", 1, 15),
NetStringStrict("m_pDescription0"), NetStringStrict("m_pDescription1"), NetStringStrict("m_pDescription2"),
NetStringStrict("m_pDescription3"), NetStringStrict("m_pDescription4"), NetStringStrict("m_pDescription5"),
NetStringStrict("m_pDescription6"), NetStringStrict("m_pDescription7"), NetStringStrict("m_pDescription8"),
NetStringStrict("m_pDescription9"), NetStringStrict("m_pDescription10"), NetStringStrict("m_pDescription11"),
NetStringStrict("m_pDescription12"), NetStringStrict("m_pDescription13"), NetStringStrict("m_pDescription14"),
]),
2011-03-25 10:49:35 +00:00
NetMessage("Sv_VoteOptionAdd", [
NetStringStrict("m_pDescription"),
]),
NetMessage("Sv_VoteOptionRemove", [
2011-03-25 08:49:21 +00:00
NetStringStrict("m_pDescription"),
2008-11-08 12:50:46 +00:00
]),
2010-05-29 07:25:38 +00:00
NetMessage("Sv_VoteSet", [
NetIntRange("m_Timeout", 0, 60),
NetStringStrict("m_pDescription"),
NetStringStrict("m_pReason"),
2008-09-24 14:47:03 +00:00
]),
2010-05-29 07:25:38 +00:00
NetMessage("Sv_VoteStatus", [
NetIntRange("m_Yes", 0, 'MAX_CLIENTS'),
NetIntRange("m_No", 0, 'MAX_CLIENTS'),
NetIntRange("m_Pass", 0, 'MAX_CLIENTS'),
NetIntRange("m_Total", 0, 'MAX_CLIENTS'),
2008-09-24 14:47:03 +00:00
]),
NetMessage("Sv_ClientInfo", [
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
2012-08-03 16:46:01 +00:00
NetBool("m_Local"),
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
NetStringStrict("m_pName"),
NetStringStrict("m_pClan"),
NetIntAny("m_Country"),
NetArray(NetStringStrict("m_apSkinPartNames"), 6),
NetArray(NetBool("m_aUseCustomColors"), 6),
NetArray(NetIntAny("m_aSkinPartColors"), 6),
]),
NetMessage("Sv_GameInfo", [
2012-08-03 16:46:01 +00:00
NetFlag("m_GameFlags", GameFlags),
NetIntRange("m_ScoreLimit", 0, 'max_int'),
NetIntRange("m_TimeLimit", 0, 'max_int'),
NetIntRange("m_MatchNum", 0, 'max_int'),
NetIntRange("m_MatchCurrent", 0, 'max_int'),
]),
NetMessage("Sv_ClientDrop", [
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
NetStringStrict("m_pReason"),
]),
NetMessage("Sv_GameMsg", []),
## Demo messages
NetMessage("De_ClientEnter", [
NetStringStrict("m_pName"),
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
]),
NetMessage("De_ClientLeave", [
NetStringStrict("m_pName"),
NetStringStrict("m_pReason"),
]),
2008-04-27 05:59:38 +00:00
### Client messages
2010-05-29 07:25:38 +00:00
NetMessage("Cl_Say", [
NetBool("m_Team"),
NetString("m_pMessage"),
2008-04-27 05:59:38 +00:00
]),
2010-05-29 07:25:38 +00:00
NetMessage("Cl_SetTeam", [
2011-01-03 11:50:38 +00:00
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
2008-04-27 05:59:38 +00:00
]),
NetMessage("Cl_SetSpectatorMode", [
NetIntRange("m_SpectatorID", 'SPEC_FREEVIEW', 'MAX_CLIENTS-1'),
]),
2010-05-29 07:25:38 +00:00
NetMessage("Cl_StartInfo", [
NetStringStrict("m_pName"),
NetStringStrict("m_pClan"),
NetIntAny("m_Country"),
2012-01-26 18:53:23 +00:00
NetArray(NetStringStrict("m_apSkinPartNames"), 6),
NetArray(NetBool("m_aUseCustomColors"), 6),
NetArray(NetIntAny("m_aSkinPartColors"), 6),
]),
2008-04-27 05:59:38 +00:00
2010-05-29 07:25:38 +00:00
NetMessage("Cl_Kill", []),
2008-04-27 05:59:38 +00:00
2012-02-15 00:39:24 +00:00
NetMessage("Cl_ReadyChange", []),
2010-05-29 07:25:38 +00:00
NetMessage("Cl_Emoticon", [
2012-08-03 16:46:01 +00:00
NetEnum("m_Emoticon", Emoticons),
2008-04-27 05:59:38 +00:00
]),
2008-09-24 14:47:03 +00:00
2010-05-29 07:25:38 +00:00
NetMessage("Cl_Vote", [
NetIntRange("m_Vote", -1, 1),
2008-09-24 14:47:03 +00:00
]),
2010-05-29 07:25:38 +00:00
NetMessage("Cl_CallVote", [
NetStringStrict("m_Type"),
NetStringStrict("m_Value"),
NetStringStrict("m_Reason"),
2008-09-25 12:23:44 +00:00
]),
2008-04-27 05:59:38 +00:00
]