Skip to content
Open
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
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ if(POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif()

if(POLICY CMP0017)
cmake_policy(SET CMP0017 NEW)
endif()

if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
if(VERSION_PATCH STREQUAL "0")
Expand Down Expand Up @@ -315,7 +319,7 @@ if(NOT CMAKE_CROSSCOMPILING)
endif()
find_package(ZLIB)
find_package(Crypto)
find_package(OwnFreetype)
find_package(Freetype)
find_package(Git)
find_package(GTest)
if(MYSQL)
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[![DDraceNetwork](https://ddnet.tw/ddnet-small.png)](https://ddnet.tw) [![CircleCI Build Status](https://circleci.com/gh/ddnet/ddnet/tree/master.png)](https://circleci.com/gh/ddnet/ddnet7)

Not updated anymore since we have 0.7 client support in DDNet: https://github.com/ddnet/ddnet

Old description:

DDNet work in progress for teeworlds version 0.7 (server only!)

ported by fokkonaut from https://github.com/ddnet/ddnet to the latest teeworlds base http://github.com/teeworlds/teeworlds
16 changes: 16 additions & 0 deletions src/engine/shared/config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ MACRO_CONFIG_STR(SvDnsblHost, sv_dnsbl_host, 128, "", CFGFLAG_SERVER, "Hostname
MACRO_CONFIG_STR(SvDnsblKey, sv_dnsbl_key, 128, "", CFGFLAG_SERVER, "Optional Authentification Key for the specified DNSBL provider")
MACRO_CONFIG_INT(SvDnsblVote, sv_dnsbl_vote, 0, 0, 1, CFGFLAG_SERVER, "Block votes by blacklisted addresses")
MACRO_CONFIG_INT(SvDnsblBan, sv_dnsbl_ban, 0, 0, 1, CFGFLAG_SERVER, "Automatically ban blacklisted addresses")
MACRO_CONFIG_INT(SvRconVote, sv_rcon_vote, 0, 0, 1, CFGFLAG_SERVER, "Only allow authed clients to call votes")

MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_SAVE|CFGFLAG_ECON, "Address to bind the external console to. Anything but 'localhost' is dangerous")
MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_ECON, "Port to use for the external console")
Expand Down Expand Up @@ -188,6 +189,21 @@ MACRO_CONFIG_INT(SvChatThreshold, sv_chat_threshold, 1000, 50, 10000, CFGFLAG_SE
MACRO_CONFIG_INT(SvSpamMuteDuration, sv_spam_mute_duration, 60, 0, 3600, CFGFLAG_SERVER, "how many seconds to mute, if player triggers mute on spam. 0 = off")
MACRO_CONFIG_INT(SvShutdownWhenEmpty, sv_shutdown_when_empty, 0, 0, 1, CFGFLAG_SERVER, "Shutdown server as soon as no one is on it anymore")

// rules

MACRO_CONFIG_INT(SvDDRaceRules, sv_ddrace_rules, 1, 0, 1, CFGFLAG_SERVER, "Whether the default mod rules are displayed or not")
MACRO_CONFIG_STR(SvRulesLine1, sv_rules_line1, 128, "", CFGFLAG_SERVER, "Rules line 1")
MACRO_CONFIG_STR(SvRulesLine2, sv_rules_line2, 128, "", CFGFLAG_SERVER, "Rules line 2")
MACRO_CONFIG_STR(SvRulesLine3, sv_rules_line3, 128, "", CFGFLAG_SERVER, "Rules line 3")
MACRO_CONFIG_STR(SvRulesLine4, sv_rules_line4, 128, "", CFGFLAG_SERVER, "Rules line 4")
MACRO_CONFIG_STR(SvRulesLine5, sv_rules_line5, 128, "", CFGFLAG_SERVER, "Rules line 5")
MACRO_CONFIG_STR(SvRulesLine6, sv_rules_line6, 128, "", CFGFLAG_SERVER, "Rules line 6")
MACRO_CONFIG_STR(SvRulesLine7, sv_rules_line7, 128, "", CFGFLAG_SERVER, "Rules line 7")
MACRO_CONFIG_STR(SvRulesLine8, sv_rules_line8, 128, "", CFGFLAG_SERVER, "Rules line 8")
MACRO_CONFIG_STR(SvRulesLine9, sv_rules_line9, 128, "", CFGFLAG_SERVER, "Rules line 9")
MACRO_CONFIG_STR(SvRulesLine10, sv_rules_line10, 128, "", CFGFLAG_SERVER, "Rules line 10")


// netlimit
MACRO_CONFIG_INT(SvNetlimit, sv_netlimit, 0, 0, 10000, CFGFLAG_SERVER, "Netlimit: Maximum amount of traffic a client is allowed to use (in kb/s)")
MACRO_CONFIG_INT(SvNetlimitAlpha, sv_netlimit_alpha, 50, 1, 100, CFGFLAG_SERVER, "Netlimit: Alpha of Exponention moving average")
Expand Down
9 changes: 8 additions & 1 deletion src/engine/shared/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ void CNetRecvUnpacker::Start(const NETADDR *pAddr, CNetConnection *pConnection,
// TODO: rename this function
int CNetRecvUnpacker::FetchChunk(CNetChunk *pChunk)
{
// Don't bother with connections that already went offline
if(m_pConnection && m_pConnection->State() != NET_CONNSTATE_ONLINE)
{
Clear();
return 0;
}

CNetChunkHeader Header;
unsigned char *pEnd = m_Data.m_aChunkData + m_Data.m_DataSize;

Expand Down Expand Up @@ -247,7 +254,7 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
pPacket->m_Token = (pBuffer[3] << 24) | (pBuffer[4] << 16) | (pBuffer[5] << 8) | pBuffer[6];
// TTTTTTTT TTTTTTTT TTTTTTTT TTTTTTTT
pPacket->m_ResponseToken = NET_TOKEN_NONE;

if(pPacket->m_Flags&NET_PACKETFLAG_COMPRESSION)
pPacket->m_DataSize = Decompress(&pBuffer[NET_PACKETHEADERSIZE], pPacket->m_DataSize, pPacket->m_aChunkData, sizeof(pPacket->m_aChunkData));
else
Expand Down
3 changes: 3 additions & 0 deletions src/game/ddracecommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ CONSOLE_COMMAND("list", "?s[filter]", CFGFLAG_CHAT, ConList, this, "List connect
CONSOLE_COMMAND("set_team_ddr", "v[id] ?i[team]", CFGFLAG_SERVER, ConSetDDRTeam, this, "Set ddrace team of a player")
CONSOLE_COMMAND("uninvite", "v[id] ?i[team]", CFGFLAG_SERVER, ConUninvite, this, "Uninvite player from team")

CONSOLE_COMMAND("vote_mute", "v[id] i[seconds]", CFGFLAG_SERVER, ConVoteMute, this, "Remove v's right to vote for i seconds")
CONSOLE_COMMAND("vote_unmute", "v[id]", CFGFLAG_SERVER, ConVoteUnmute, this, "Give back v's right to vote.")
CONSOLE_COMMAND("vote_mutes", "", CFGFLAG_SERVER, ConVoteMutes, this, "List the current active vote mutes.")
CONSOLE_COMMAND("mute", "", CFGFLAG_SERVER, ConMute, this, "")
CONSOLE_COMMAND("muteid", "v[id] i[seconds] ?r[reason]", CFGFLAG_SERVER, ConMuteID, this, "")
CONSOLE_COMMAND("muteip", "s[ip] i[seconds] ?r[reason]", CFGFLAG_SERVER, ConMuteIP, this, "")
Expand Down
1 change: 1 addition & 0 deletions src/game/server/ddracechat.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CHAT_COMMAND("top5team", "?i", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamTop5, this, "
CHAT_COMMAND("top5", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTop5, this, "Shows five ranks of the ladder beginning with rank i (1 by default)")
CHAT_COMMAND("points", "?r[player name]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConPoints, this, "Shows the global points of a player beginning with name r (your rank by default)")
CHAT_COMMAND("top5points", "?i[number]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTopPoints, this, "Shows five points of the global point ladder beginning with rank i (1 by default)")
CHAT_COMMAND("rules", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConRules, this, "Shows the server rules")

CHAT_COMMAND("team", "?i[id]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConJoinTeam, this, "Lets you join team i (shows your team if left blank)")
CHAT_COMMAND("lock", "?i['0'|'1']", CFGFLAG_CHAT|CFGFLAG_SERVER, ConLockTeam, this, "Lock team so no-one else can join it")
Expand Down
144 changes: 143 additions & 1 deletion src/game/server/ddracecommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,148 @@ void CGameContext::ConForcePause(IConsole::IResult *pResult, void *pUserData)
pPlayer->ForcePause(Seconds);
}


bool CGameContext::TryVoteMute(const NETADDR *pAddr, int Secs)
{
// find a matching vote mute for this ip, update expiration time if found
for(int i = 0; i < m_NumVoteMutes; i++)
{
if(net_addr_comp_noport(&m_aVoteMutes[i].m_Addr, pAddr) == 0)
{
m_aVoteMutes[i].m_Expire = Server()->Tick()
+ Secs * Server()->TickSpeed();
return true;
}
}

// nothing to update create new one
if(m_NumVoteMutes < MAX_VOTE_MUTES)
{
m_aVoteMutes[m_NumVoteMutes].m_Addr = *pAddr;
m_aVoteMutes[m_NumVoteMutes].m_Expire = Server()->Tick()
+ Secs * Server()->TickSpeed();
m_NumVoteMutes++;
return true;
}
// no free slot found
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemute", "vote mute array is full");
return false;
}

bool CGameContext::VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplayName, int AuthedID)
{
if (!TryVoteMute(pAddr, Secs))
return false;

if(!pDisplayName)
return true;

char aBuf[128];
str_format(aBuf, sizeof aBuf, "'%s' banned '%s' for %d seconds from voting.",
Server()->ClientName(AuthedID), pDisplayName, Secs);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemute", aBuf);
return true;
}

bool CGameContext::VoteUnmute(const NETADDR *pAddr, const char *pDisplayName, int AuthedID)
{
for(int i = 0; i < m_NumVoteMutes; i++)
{
if(net_addr_comp_noport(&m_aVoteMutes[i].m_Addr, pAddr) == 0)
{
m_NumVoteMutes--;
m_aVoteMutes[i] = m_aVoteMutes[m_NumVoteMutes];
if(pDisplayName)
{
char aBuf[128];
str_format(aBuf, sizeof aBuf, "'%s' unbanned '%s' from voting.",
Server()->ClientName(AuthedID), pDisplayName);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "voteunmute", aBuf);
}
return true;
}
}
return false;
}


void CGameContext::ConVoteMute(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = pResult->GetVictim();

if(Victim < 0 || Victim > MAX_CLIENTS || !pSelf->m_apPlayers[Victim])
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemute", "Client ID not found");
return;
}

NETADDR Addr;
pSelf->Server()->GetClientAddr(Victim, &Addr);

int Seconds = clamp(pResult->GetInteger(1), 1, 86400);
bool Found = pSelf->VoteMute(&Addr, Seconds, pSelf->Server()->ClientName(Victim), pResult->m_ClientID);

if(Found)
{
char aBuf[128];
str_format(aBuf, sizeof aBuf, "'%s' banned '%s' for %d seconds from voting.",
pSelf->Server()->ClientName(pResult->m_ClientID), pSelf->Server()->ClientName(Victim), Seconds);
pSelf->SendChat(-1, CHAT_ALL, -1, aBuf);
}
}

void CGameContext::ConVoteUnmute(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = pResult->GetVictim();

if(Victim < 0 || Victim > MAX_CLIENTS || !pSelf->m_apPlayers[Victim])
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "voteunmute", "Client ID not found");
return;
}

NETADDR Addr;
pSelf->Server()->GetClientAddr(Victim, &Addr);

bool Found = pSelf->VoteUnmute(&Addr, pSelf->Server()->ClientName(Victim), pResult->m_ClientID);
if(Found)
{
char aBuf[128];
str_format(aBuf, sizeof aBuf, "'%s' unbanned '%s' from voting.",
pSelf->Server()->ClientName(pResult->m_ClientID), pSelf->Server()->ClientName(Victim));
pSelf->SendChat(-1, CHAT_ALL, -1, aBuf);
}
}

void CGameContext::ConVoteMutes(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *) pUserData;

if (pSelf->m_NumVoteMutes <= 0)
{
// Just to make sure.
pSelf->m_NumVoteMutes = 0;
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemutes",
"There are no active vote mutes.");
return;
}

char aIpBuf[64];
char aBuf[128];
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemutes",
"Active vote mutes:");
for (int i = 0; i < pSelf->m_NumVoteMutes; i++)
{
net_addr_str(&pSelf->m_aVoteMutes[i].m_Addr, aIpBuf, sizeof(aIpBuf), false);
str_format(aBuf, sizeof aBuf, "%d: \"%s\", %d seconds left", i,
aIpBuf, (pSelf->m_aVoteMutes[i].m_Expire - pSelf->Server()->Tick()) / pSelf->Server()->TickSpeed());
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemutes", aBuf);
}
}


bool CGameContext::TryMute(const NETADDR *pAddr, int Secs, const char *pReason)
{
// find a matching mute for this ip, update expiration time if found
Expand Down Expand Up @@ -381,7 +523,7 @@ void CGameContext::Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName
if (pReason[0])
str_format(aBuf, sizeof aBuf, "'%s' has been muted for %d seconds (%s)", pDisplayName, Secs, pReason);
else
str_format(aBuf, sizeof aBuf, "'%s' has been muted for %d seconds", pDisplayName, Secs, pReason);
str_format(aBuf, sizeof aBuf, "'%s' has been muted for %d seconds", pDisplayName, Secs);
SendChat(-1, CHAT_ALL, -1, aBuf);
}

Expand Down
60 changes: 58 additions & 2 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,13 @@ void CGameContext::OnTick()
// send vote options
ProgressVoteOptions(i);

m_apPlayers[i]->Tick();
m_apPlayers[i]->PostTick();
// ProgressVoteOptions calls SendMsg which can cause a player to be
// kicked on network problems, have to recheck
if(m_apPlayers[i])
{
m_apPlayers[i]->Tick();
m_apPlayers[i]->PostTick();
}
}
}

Expand Down Expand Up @@ -1200,6 +1205,12 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
int64 Now = Server()->Tick();
int64 TickSpeed = Server()->TickSpeed();

if(g_Config.m_SvRconVote && !Server()->GetAuthedState(ClientID))
{
SendChatTarget(ClientID, "You can only vote after logging in.");
return;
}

if (g_Config.m_SvDnsblVote && !m_pServer->DnsblWhite(ClientID))
{
// blacklisted by dnsbl
Expand All @@ -1225,6 +1236,20 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
pPlayer->m_LastVoteTry = Now;
}

NETADDR Addr;
Server()->GetClientAddr(ClientID, &Addr);
int VoteMuted = 0;
for(int i = 0; i < m_NumVoteMutes && !VoteMuted; i++)
if(!net_addr_comp_noport(&Addr, &m_aVoteMutes[i].m_Addr))
VoteMuted = (m_aVoteMutes[i].m_Expire - Server()->Tick()) / Server()->TickSpeed();
if(VoteMuted > 0)
{
char aChatmsg[64];
str_format(aChatmsg, sizeof(aChatmsg), "You are not permitted to vote for the next %d seconds.", VoteMuted);
SendChatTarget(ClientID, aChatmsg);
return;
}

char aChatmsg[512] = {0};
m_VoteType = VOTE_UNKNOWN;
char aDesc[VOTE_DESC_LENGTH] = {0};
Expand Down Expand Up @@ -2028,6 +2053,37 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData)
pSelf->m_NumVoteOptions = NumVoteOptions;
}

void CGameContext::ConRules(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *) pUserData;
bool Printed = false;
if (g_Config.m_SvDDRaceRules)
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "rules",
"Be nice.");
Printed = true;
}
#define _RL(n) g_Config.m_SvRulesLine ## n
char *pRuleLines[] = {
_RL(1), _RL(2), _RL(3), _RL(4), _RL(5),
_RL(6), _RL(7), _RL(8), _RL(9), _RL(10),
};
for(unsigned i = 0; i < sizeof(pRuleLines) / sizeof(pRuleLines[0]); i++)
{
if(pRuleLines[i][0])
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD,
"rules", pRuleLines[i]);
Printed = true;
}
}
if (!Printed)
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "rules",
"No Rules Defined, Kill em all!!");
}
}

void CGameContext::ConClearVotes(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
Expand Down
7 changes: 7 additions & 0 deletions src/game/server/gamecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class CGameContext : public IGameServer
static void ConchainGameinfoUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void NewCommandHook(const CCommandManager::CCommand *pCommand, void *pContext);
static void RemoveCommandHook(const CCommandManager::CCommand *pCommand, void *pContext);
static void ConRules(IConsole::IResult *pResult, void *pUserData);

static void LegacyCommandCallback(IConsole::IResult *pResult, void *pContext);
void RegisterLegacyDDRaceCommands();
Expand Down Expand Up @@ -348,6 +349,9 @@ class CGameContext : public IGameServer
static void ConRescue(IConsole::IResult* pResult, void* pUserData);
static void ConProtectedKill(IConsole::IResult* pResult, void* pUserData);

static void ConVoteMute(IConsole::IResult *pResult, void *pUserData);
static void ConVoteUnmute(IConsole::IResult *pResult, void *pUserData);
static void ConVoteMutes(IConsole::IResult *pResult, void *pUserData);
static void ConMute(IConsole::IResult* pResult, void* pUserData);
static void ConMuteID(IConsole::IResult* pResult, void* pUserData);
static void ConMuteIP(IConsole::IResult* pResult, void* pUserData);
Expand Down Expand Up @@ -384,6 +388,9 @@ class CGameContext : public IGameServer
int m_NumVoteMutes;
bool TryMute(const NETADDR *pAddr, int Secs, const char *pReason);
void Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName, const char *pReason = "");
bool TryVoteMute(const NETADDR *pAddr, int Secs);
bool VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplayName, int AuthedID);
bool VoteUnmute(const NETADDR *pAddr, const char *pDisplayName, int AuthedID);

public:
CLayers* Layers() { return &m_Layers; }
Expand Down
2 changes: 1 addition & 1 deletion src/game/server/teams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void CGameTeams::OnCharacterStart(int ClientID)
}
}

if(g_Config.m_SvTeam < 3 && g_Config.m_SvTeamMaxSize != 2 && g_Config.m_SvPauseable)
if(g_Config.m_SvTeam < 3 && g_Config.m_SvTeamMaxSize != 2 && g_Config.m_SvPauseable && m_MembersCount[m_Core.Team(ClientID)] > 1)
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{
Expand Down