Skip to content

Commit

Permalink
Merge branch 'ddnet' into chillerbot
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Sep 16, 2024
2 parents 45c10dd + 20cb020 commit b825b39
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 184 deletions.
5 changes: 4 additions & 1 deletion src/engine/client/serverbrowser_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ void CServerBrowserHttp::Refresh()
}
bool ServerbrowserParseUrl(NETADDR *pOut, const char *pUrl)
{
return net_addr_from_url(pOut, pUrl, nullptr, 0) != 0;
int Failure = net_addr_from_url(pOut, pUrl, nullptr, 0);
if(Failure || pOut->port == 0)
return true;
return false;
}
bool CServerBrowserHttp::Validate(json_value *pJson)
{
Expand Down
1 change: 1 addition & 0 deletions src/engine/server/databases/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class IDbConnection
virtual void BindInt(int Idx, int Value) = 0;
virtual void BindInt64(int Idx, int64_t Value) = 0;
virtual void BindFloat(int Idx, float Value) = 0;
virtual void BindNull(int Idx) = 0;

// Print expanded sql statement
virtual void Print() = 0;
Expand Down
17 changes: 17 additions & 0 deletions src/engine/server/databases/mysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class CMysqlConnection : public IDbConnection
void BindInt(int Idx, int Value) override;
void BindInt64(int Idx, int64_t Value) override;
void BindFloat(int Idx, float Value) override;
void BindNull(int Idx) override;

void Print() override {}
bool Step(bool *pEnd, char *pError, int ErrorSize) override;
Expand Down Expand Up @@ -421,6 +422,22 @@ void CMysqlConnection::BindFloat(int Idx, float Value)
pParam->error = nullptr;
}

void CMysqlConnection::BindNull(int Idx)
{
m_NewQuery = true;
Idx -= 1;
dbg_assert(0 <= Idx && Idx < (int)m_vStmtParameters.size(), "index out of bounds");

MYSQL_BIND *pParam = &m_vStmtParameters[Idx];
pParam->buffer_type = MYSQL_TYPE_NULL;
pParam->buffer = nullptr;
pParam->buffer_length = 0;
pParam->length = nullptr;
pParam->is_null = nullptr;
pParam->is_unsigned = false;
pParam->error = nullptr;
}

bool CMysqlConnection::Step(bool *pEnd, char *pError, int ErrorSize)
{
if(m_NewQuery)
Expand Down
8 changes: 8 additions & 0 deletions src/engine/server/databases/sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CSqliteConnection : public IDbConnection
void BindInt(int Idx, int Value) override;
void BindInt64(int Idx, int64_t Value) override;
void BindFloat(int Idx, float Value) override;
void BindNull(int Idx) override;

void Print() override;
bool Step(bool *pEnd, char *pError, int ErrorSize) override;
Expand Down Expand Up @@ -241,6 +242,13 @@ void CSqliteConnection::BindFloat(int Idx, float Value)
m_Done = false;
}

void CSqliteConnection::BindNull(int Idx)
{
int Result = sqlite3_bind_null(m_pStmt, Idx);
AssertNoError(Result);
m_Done = false;
}

// Keep support for SQLite < 3.14 on older Linux distributions. MinGW does not
// support __attribute__((weak)): https://sourceware.org/bugzilla/show_bug.cgi?id=9687
#if defined(__GNUC__) && !defined(__MINGW32__)
Expand Down
37 changes: 24 additions & 13 deletions src/game/client/components/binds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <engine/config.h>
#include <engine/shared/config.h>

#include <game/client/components/chat.h>
#include <game/client/components/console.h>
#include <game/client/gameclient.h>

static const ColorRGBA gs_BindPrintColor{1.0f, 1.0f, 0.8f, 1.0f};
Expand Down Expand Up @@ -126,7 +128,7 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
});
if(ActiveBind == m_vActiveBinds.end())
{
const auto &&OnPress = [&](int Mask) {
const auto &&OnKeyPress = [&](int Mask) {
const char *pBind = m_aapKeyBindings[Mask][Event.m_Key];
if(g_Config.m_ClSubTickAiming)
{
Expand All @@ -141,14 +143,14 @@ bool CBinds::OnInput(const IInput::CEvent &Event)

if(m_aapKeyBindings[ModifierMask][Event.m_Key])
{
OnPress(ModifierMask);
OnKeyPress(ModifierMask);
Handled = true;
}
else if(m_aapKeyBindings[MODIFIER_NONE][Event.m_Key] &&
ModifierMask != ((1 << MODIFIER_CTRL) | (1 << MODIFIER_SHIFT)) &&
ModifierMask != ((1 << MODIFIER_GUI) | (1 << MODIFIER_SHIFT)))
{
OnPress(MODIFIER_NONE);
OnKeyPress(MODIFIER_NONE);
Handled = true;
}
}
Expand All @@ -166,17 +168,30 @@ bool CBinds::OnInput(const IInput::CEvent &Event)

if(Event.m_Flags & IInput::FLAG_RELEASE)
{
const auto &&OnKeyRelease = [&](const CBindSlot &Bind) {
// Prevent binds from being deactivated while chat, console and menus are open, as these components will
// still allow key release events to be forwarded to this component, so the active binds can be cleared.
if(GameClient()->m_Chat.IsActive() ||
!GameClient()->m_GameConsole.IsClosed() ||
GameClient()->m_Menus.IsActive())
{
return;
}
// Have to check for nullptr again because the previous execute can unbind itself
if(!m_aapKeyBindings[Bind.m_ModifierMask][Bind.m_Key])
{
return;
}
Console()->ExecuteLineStroked(0, m_aapKeyBindings[Bind.m_ModifierMask][Bind.m_Key]);
};

// Release active bind that uses this primary key
auto ActiveBind = std::find_if(m_vActiveBinds.begin(), m_vActiveBinds.end(), [&](const CBindSlot &Bind) {
return Event.m_Key == Bind.m_Key;
});
if(ActiveBind != m_vActiveBinds.end())
{
// Have to check for nullptr again because the previous execute can unbind itself
if(m_aapKeyBindings[ActiveBind->m_ModifierMask][ActiveBind->m_Key])
{
Console()->ExecuteLineStroked(0, m_aapKeyBindings[ActiveBind->m_ModifierMask][ActiveBind->m_Key]);
}
OnKeyRelease(*ActiveBind);
m_vActiveBinds.erase(ActiveBind);
Handled = true;
}
Expand All @@ -191,11 +206,7 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
});
if(ActiveModifierBind == m_vActiveBinds.end())
break;
// Have to check for nullptr again because the previous execute can unbind itself
if(m_aapKeyBindings[ActiveModifierBind->m_ModifierMask][ActiveModifierBind->m_Key])
{
Console()->ExecuteLineStroked(0, m_aapKeyBindings[ActiveModifierBind->m_ModifierMask][ActiveModifierBind->m_Key]);
}
OnKeyRelease(*ActiveModifierBind);
m_vActiveBinds.erase(ActiveModifierBind);
Handled = true;
}
Expand Down
80 changes: 6 additions & 74 deletions src/game/client/components/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,50 +811,9 @@ void CChat::AddLine(int ClientId, int Team, const char *pLine)
{
if(!g_Config.m_ClChatOld)
{
pCurrentLine->m_CustomColoredSkin = LineAuthor.m_RenderInfo.m_CustomColoredSkin;
if(pCurrentLine->m_CustomColoredSkin)
pCurrentLine->m_RenderSkin = LineAuthor.m_RenderInfo.m_ColorableRenderSkin;
else
pCurrentLine->m_RenderSkin = LineAuthor.m_RenderInfo.m_OriginalRenderSkin;

str_copy(pCurrentLine->m_aSkinName, LineAuthor.m_aSkinName);
pCurrentLine->m_ColorBody = LineAuthor.m_RenderInfo.m_ColorBody;
pCurrentLine->m_ColorFeet = LineAuthor.m_RenderInfo.m_ColorFeet;

pCurrentLine->m_RenderSkinMetrics = LineAuthor.m_RenderInfo.m_SkinMetrics;
pCurrentLine->m_TeeRenderInfo = LineAuthor.m_RenderInfo;
pCurrentLine->m_HasRenderTee = true;

// 0.7
if(Client()->IsSixup())
{
for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
{
const char *pPartName = LineAuthor.m_aSixup[g_Config.m_ClDummy].m_aaSkinPartNames[Part];
int Id = m_pClient->m_Skins7.FindSkinPart(Part, pPartName, false);
const CSkins7::CSkinPart *pSkinPart = m_pClient->m_Skins7.GetSkinPart(Part, Id);
if(LineAuthor.m_aSixup[g_Config.m_ClDummy].m_aUseCustomColors[Part])
{
pCurrentLine->m_Sixup.m_aTextures[Part] = pSkinPart->m_ColorTexture;
pCurrentLine->m_Sixup.m_aColors[Part] = m_pClient->m_Skins7.GetColor(
LineAuthor.m_aSixup[g_Config.m_ClDummy].m_aSkinPartColors[Part],
Part == protocol7::SKINPART_MARKING);
}
else
{
pCurrentLine->m_Sixup.m_aTextures[Part] = pSkinPart->m_OrgTexture;
pCurrentLine->m_Sixup.m_aColors[Part] = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}

if(LineAuthor.m_SkinInfo.m_aSixup[g_Config.m_ClDummy].m_HatTexture.IsValid())
{
if(Part == protocol7::SKINPART_BODY && str_comp(pPartName, "standard"))
pCurrentLine->m_Sixup.m_HatSpriteIndex = CSkins7::HAT_OFFSET_SIDE + (ClientId % CSkins7::HAT_NUM);
if(Part == protocol7::SKINPART_DECORATION && str_comp(pPartName, "twinbopp"))
pCurrentLine->m_Sixup.m_HatSpriteIndex = CSkins7::HAT_OFFSET_SIDE + (ClientId % CSkins7::HAT_NUM);
pCurrentLine->m_Sixup.m_HatTexture = LineAuthor.m_SkinInfo.m_aSixup[g_Config.m_ClDummy].m_HatTexture;
}
}
}
}
}
}
Expand Down Expand Up @@ -923,17 +882,11 @@ void CChat::OnRefreshSkins()
{
if(Line.m_HasRenderTee)
{
const CSkin *pSkin = m_pClient->m_Skins.Find(Line.m_aSkinName);
if(Line.m_CustomColoredSkin)
Line.m_RenderSkin = pSkin->m_ColorableSkin;
else
Line.m_RenderSkin = pSkin->m_OriginalSkin;

Line.m_RenderSkinMetrics = pSkin->m_Metrics;
Line.m_TeeRenderInfo.Apply(m_pClient->m_Skins.Find(Line.m_aSkinName));
}
else
{
Line.m_RenderSkin.Reset();
Line.m_TeeRenderInfo.Reset();
}
}
}
Expand Down Expand Up @@ -1297,38 +1250,17 @@ void CChat::OnRender()
if(!g_Config.m_ClChatOld && Line.m_HasRenderTee)
{
const int TeeSize = MessageTeeSize();
CTeeRenderInfo RenderInfo;
RenderInfo.m_CustomColoredSkin = Line.m_CustomColoredSkin;
if(Line.m_CustomColoredSkin)
RenderInfo.m_ColorableRenderSkin = Line.m_RenderSkin;
else
RenderInfo.m_OriginalRenderSkin = Line.m_RenderSkin;
RenderInfo.m_SkinMetrics = Line.m_RenderSkinMetrics;

RenderInfo.m_ColorBody = Line.m_ColorBody;
RenderInfo.m_ColorFeet = Line.m_ColorFeet;
RenderInfo.m_Size = TeeSize;

if(Client()->IsSixup())
{
for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
{
RenderInfo.m_aSixup[g_Config.m_ClDummy].m_aColors[Part] = Line.m_Sixup.m_aColors[Part];
RenderInfo.m_aSixup[g_Config.m_ClDummy].m_aTextures[Part] = Line.m_Sixup.m_aTextures[Part];
RenderInfo.m_aSixup[g_Config.m_ClDummy].m_HatSpriteIndex = Line.m_Sixup.m_HatSpriteIndex;
RenderInfo.m_aSixup[g_Config.m_ClDummy].m_HatTexture = Line.m_Sixup.m_HatTexture;
}
}
Line.m_TeeRenderInfo.m_Size = TeeSize;

float RowHeight = FontSize() + RealMsgPaddingY;
float OffsetTeeY = TeeSize / 2.0f;
float FullHeightMinusTee = RowHeight - TeeSize;

const CAnimState *pIdleState = CAnimState::GetIdle();
vec2 OffsetToMid;
CRenderTools::GetRenderTeeOffsetToRenderedTee(pIdleState, &RenderInfo, OffsetToMid);
CRenderTools::GetRenderTeeOffsetToRenderedTee(pIdleState, &Line.m_TeeRenderInfo, OffsetToMid);
vec2 TeeRenderPos(x + (RealMsgPaddingX + TeeSize) / 2.0f, y + OffsetTeeY + FullHeightMinusTee / 2.0f + OffsetToMid.y);
RenderTools()->RenderTee(pIdleState, &RenderInfo, EMOTE_NORMAL, vec2(1, 0.1f), TeeRenderPos, Blend);
RenderTools()->RenderTee(pIdleState, &Line.m_TeeRenderInfo, EMOTE_NORMAL, vec2(1, 0.1f), TeeRenderPos, Blend);
}

const ColorRGBA TextColor = TextRender()->DefaultTextColor().WithMultipliedAlpha(Blend);
Expand Down
23 changes: 3 additions & 20 deletions src/game/client/components/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <game/client/component.h>
#include <game/client/lineinput.h>
#include <game/client/render.h>
#include <game/client/skin.h>
#include <game/generated/protocol7.h>

Expand Down Expand Up @@ -45,30 +46,12 @@ class CChat : public CComponent
int m_QuadContainerIndex;

char m_aSkinName[std::size(g_Config.m_ClPlayerSkin)];
CSkin::SSkinTextures m_RenderSkin;
CSkin::SSkinMetrics m_RenderSkinMetrics;
bool m_CustomColoredSkin;
ColorRGBA m_ColorBody;
ColorRGBA m_ColorFeet;

bool m_HasRenderTee;
CTeeRenderInfo m_TeeRenderInfo;

float m_TextYOffset;

int m_TimesRepeated;

class CSixup
{
public:
IGraphics::CTextureHandle m_aTextures[protocol7::NUM_SKINPARTS];
IGraphics::CTextureHandle m_HatTexture;
IGraphics::CTextureHandle m_BotTexture;
int m_HatSpriteIndex;
ColorRGBA m_BotColor;
ColorRGBA m_aColors[protocol7::NUM_SKINPARTS];
};

// 0.7 Skin
CSixup m_Sixup;
};

bool m_PrevScoreBoardShowed;
Expand Down
17 changes: 3 additions & 14 deletions src/game/client/components/ghost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,7 @@ void CGhost::OnRender()
IsTeamplay = (m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS) != 0;

GhostNinjaRenderInfo = Ghost.m_RenderInfo;
GhostNinjaRenderInfo.m_OriginalRenderSkin = pSkin->m_OriginalSkin;
GhostNinjaRenderInfo.m_ColorableRenderSkin = pSkin->m_ColorableSkin;
GhostNinjaRenderInfo.m_BloodColor = pSkin->m_BloodColor;
GhostNinjaRenderInfo.m_SkinMetrics = pSkin->m_Metrics;
GhostNinjaRenderInfo.Apply(pSkin);
GhostNinjaRenderInfo.m_CustomColoredSkin = IsTeamplay;
if(!IsTeamplay)
{
Expand All @@ -392,11 +389,7 @@ void CGhost::InitRenderInfos(CGhostItem *pGhost)
IntsToStr(&pGhost->m_Skin.m_Skin0, 6, aSkinName, std::size(aSkinName));
CTeeRenderInfo *pRenderInfo = &pGhost->m_RenderInfo;

const CSkin *pSkin = m_pClient->m_Skins.Find(aSkinName);
pRenderInfo->m_OriginalRenderSkin = pSkin->m_OriginalSkin;
pRenderInfo->m_ColorableRenderSkin = pSkin->m_ColorableSkin;
pRenderInfo->m_BloodColor = pSkin->m_BloodColor;
pRenderInfo->m_SkinMetrics = pSkin->m_Metrics;
pRenderInfo->Apply(m_pClient->m_Skins.Find(aSkinName));
pRenderInfo->m_CustomColoredSkin = pGhost->m_Skin.m_UseCustomColor;
if(pGhost->m_Skin.m_UseCustomColor)
{
Expand Down Expand Up @@ -697,11 +690,7 @@ void CGhost::OnRefreshSkins()
CTeeRenderInfo *pRenderInfo = &Ghost.m_RenderInfo;
if(aSkinName[0] != '\0')
{
const CSkin *pSkin = m_pClient->m_Skins.Find(aSkinName);
pRenderInfo->m_OriginalRenderSkin = pSkin->m_OriginalSkin;
pRenderInfo->m_ColorableRenderSkin = pSkin->m_ColorableSkin;
pRenderInfo->m_BloodColor = pSkin->m_BloodColor;
pRenderInfo->m_SkinMetrics = pSkin->m_Metrics;
pRenderInfo->Apply(m_pClient->m_Skins.Find(aSkinName));
}
else
{
Expand Down
Loading

0 comments on commit b825b39

Please sign in to comment.