Compare commits

...

8 commits

Author SHA1 Message Date
furo f97297e4db
Merge e9a2ffde38 into a2e0ab2dbe 2024-09-18 14:16:35 +03:00
Robert Müller a2e0ab2dbe
Merge pull request #8973 from furo321/improve-annoucements
Various improvements to announcements
2024-09-18 10:34:53 +00:00
Robert Müller 255694c061
Merge pull request #8975 from furo321/android-save-minimized
Save the config file when the app is minimized on Android
2024-09-18 10:29:09 +00:00
furo b475c67039 Various improvements to announcements 2024-09-18 12:16:29 +02:00
furo a266cd2f70 Save the config file when the app is minimized on Android 2024-09-18 12:10:25 +02:00
Robert Müller 2c77e79061
Merge pull request #8980 from ChillerDragon/pr_fix_team_colors_sixup
Fix 0.7 client team colors (Closed #8977)
2024-09-18 09:51:35 +00:00
ChillerDragon 46c5344d71 Fix 0.7 client team colors (Closed #8977) 2024-09-18 16:50:23 +08:00
furo e9a2ffde38 Add verify_url field to master for automatic verification 2024-09-06 16:32:56 +02:00
19 changed files with 98 additions and 37 deletions

View file

@ -996,6 +996,7 @@ endif()
########################################################################
set(EXPECTED_DATA
announcement.txt
arrow.png
assets/entities/comfort/ddnet.png
assets/entities/license.txt

0
data/announcement.txt Normal file
View file

View file

@ -80,10 +80,10 @@ sv_rescue_delay 5
# Message on chat displayed when joining
sv_welcome "Welcome to my server!"
# File which will have the announcements (each one in new line)
# File which contains the announcements (One on each line)
sv_announcement_filename "announcement.txt"
# Number of minutes before next announcement will be displayed (from the announcement file)
# Number of minutes before the next announcement will be displayed (from the announcement file)
sv_announcement_interval 120
# Whether announcements will be displayed in their order or chosen randomly

View file

@ -621,6 +621,18 @@ void CClient::Connect(const char *pAddress, const char *pPassword)
else
m_aNetClient[CONN_MAIN].Connect(aConnectAddrs, NumConnectAddrs);
const CServerBrowser::CServerEntry *pEntry = m_ServerBrowser.Find(aConnectAddrs[0]);
if(pEntry != nullptr && pEntry->m_GotInfo)
{
if(str_length(pEntry->m_Info.m_aVerifyUrl))
{
std::shared_ptr<CHttpRequest> pVerifyGet = HttpGet(pEntry->m_Info.m_aVerifyUrl);
pVerifyGet->Timeout(CTimeout{10000, 0, 500, 10});
pVerifyGet->IpResolve(aConnectAddrs[0].type == NETTYPE_IPV4 ? IPRESOLVE::V4 : IPRESOLVE::V6);
Http()->Run(pVerifyGet);
}
}
m_aNetClient[CONN_MAIN].RefreshStun();
SetState(IClient::STATE_CONNECTING);

View file

@ -80,6 +80,7 @@ void CInput::Init()
m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>();
m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pConfigManager = Kernel()->RequestInterface<IConfigManager>();
MouseModeRelative();
@ -824,6 +825,9 @@ int CInput::Update()
}
break;
case SDL_WINDOWEVENT_MINIMIZED:
#if defined(CONF_PLATFORM_ANDROID) // Save the config when minimized on Android.
m_pConfigManager->Save();
#endif
Graphics()->WindowDestroyNtf(Event.window.windowID);
break;

View file

@ -14,6 +14,7 @@
#include <vector>
class IEngineGraphics;
class IConfigManager;
class CInput : public IEngineInput
{
@ -59,6 +60,7 @@ public:
private:
IEngineGraphics *m_pGraphics;
IConsole *m_pConsole;
IConfigManager *m_pConfigManager;
IEngineGraphics *Graphics() const { return m_pGraphics; }
IConsole *Console() const { return m_pConsole; }

View file

@ -273,7 +273,8 @@ public:
virtual bool DnsblWhite(int ClientId) = 0;
virtual bool DnsblPending(int ClientId) = 0;
virtual bool DnsblBlack(int ClientId) = 0;
virtual const char *GetAnnouncementLine(const char *pFileName) = 0;
virtual const char *GetAnnouncementLine() = 0;
virtual void ReadAnnouncementsFile(const char *pFileName) = 0;
virtual bool ClientPrevIngame(int ClientId) = 0;
virtual const char *GetNetErrorString(int ClientId) = 0;
virtual void ResetNetErrorString(int ClientId) = 0;

View file

@ -537,8 +537,7 @@ int CServer::Init()
m_CurrentGameTick = MIN_TICK;
m_AnnouncementLastLine = 0;
m_aAnnouncementFile[0] = '\0';
m_AnnouncementLastLine = -1;
mem_zero(m_aPrevStates, sizeof(m_aPrevStates));
return 0;
@ -2364,6 +2363,10 @@ void CServer::UpdateRegisterServerInfo()
JsonWriter.WriteAttribute("requires_login");
JsonWriter.WriteBoolValue(false);
// Client will send a HTTP GET request to the url of sv_verify_url upon connecting
JsonWriter.WriteAttribute("verify_url");
JsonWriter.WriteStrValue(g_Config.m_SvVerifyUrl);
JsonWriter.WriteAttribute("clients");
JsonWriter.BeginArray();
@ -2783,6 +2786,8 @@ int CServer::Run()
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
}
ReadAnnouncementsFile(g_Config.m_SvAnnouncementFileName);
// process pending commands
m_pConsole->StoreCommands(false);
m_pRegister->OnConfigChange();
@ -3809,6 +3814,17 @@ void CServer::ConchainStdoutOutputLevel(IConsole::IResult *pResult, void *pUserD
}
}
void CServer::ConchainAnnouncementFileName(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
CServer *pSelf = (CServer *)pUserData;
bool Changed = pResult->NumArguments() && str_comp(pResult->GetString(0), g_Config.m_SvAnnouncementFileName);
pfnCallback(pResult, pCallbackUserData);
if(Changed)
{
pSelf->ReadAnnouncementsFile(g_Config.m_SvAnnouncementFileName);
}
}
#if defined(CONF_FAMILY_UNIX)
void CServer::ConchainConnLoggingServerChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
@ -3887,6 +3903,8 @@ void CServer::RegisterCommands()
Console()->Chain("loglevel", ConchainLoglevel, this);
Console()->Chain("stdout_output_level", ConchainStdoutOutputLevel, this);
Console()->Chain("sv_announcement_filename", ConchainAnnouncementFileName, this);
#if defined(CONF_FAMILY_UNIX)
Console()->Chain("sv_conn_logging_server", ConchainConnLoggingServerChange, this);
#endif
@ -3930,17 +3948,18 @@ void CServer::GetClientAddr(int ClientId, NETADDR *pAddr) const
}
}
const char *CServer::GetAnnouncementLine(const char *pFileName)
void CServer::ReadAnnouncementsFile(const char *pFileName)
{
if(str_comp(pFileName, m_aAnnouncementFile) != 0)
{
str_copy(m_aAnnouncementFile, pFileName);
m_vAnnouncements.clear();
if(pFileName[0] == '\0')
return;
CLineReader LineReader;
if(!LineReader.OpenFile(m_pStorage->OpenFile(pFileName, IOFLAG_READ, IStorage::TYPE_ALL)))
{
return 0;
dbg_msg("announcements", "failed to open '%s'", pFileName);
return;
}
while(const char *pLine = LineReader.Get())
{
@ -3949,8 +3968,10 @@ const char *CServer::GetAnnouncementLine(const char *pFileName)
m_vAnnouncements.emplace_back(pLine);
}
}
}
}
const char *CServer::GetAnnouncementLine()
{
if(m_vAnnouncements.empty())
{
return 0;
@ -3959,7 +3980,7 @@ const char *CServer::GetAnnouncementLine(const char *pFileName)
{
m_AnnouncementLastLine = 0;
}
else if(!Config()->m_SvAnnouncementRandom)
else if(!g_Config.m_SvAnnouncementRandom)
{
if(++m_AnnouncementLastLine >= m_vAnnouncements.size())
m_AnnouncementLastLine %= m_vAnnouncements.size();

View file

@ -259,7 +259,6 @@ public:
size_t m_AnnouncementLastLine;
std::vector<std::string> m_vAnnouncements;
char m_aAnnouncementFile[IO_MAX_PATH_LENGTH];
std::shared_ptr<ILogger> m_pFileLogger = nullptr;
std::shared_ptr<ILogger> m_pStdoutLogger = nullptr;
@ -427,6 +426,7 @@ public:
static void ConchainSixupUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainLoglevel(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainStdoutOutputLevel(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainAnnouncementFileName(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
#if defined(CONF_FAMILY_UNIX)
static void ConchainConnLoggingServerChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
@ -443,7 +443,8 @@ public:
void GetClientAddr(int ClientId, NETADDR *pAddr) const override;
int m_aPrevStates[MAX_CLIENTS];
const char *GetAnnouncementLine(const char *pFileName) override;
const char *GetAnnouncementLine() override;
void ReadAnnouncementsFile(const char *pFileName) override;
int *GetIdMap(int ClientId) override;

View file

@ -118,6 +118,7 @@ public:
CClient m_aClients[SERVERINFO_MAX_CLIENTS];
int m_NumFilteredPlayers;
bool m_RequiresLogin;
char m_aVerifyUrl[128];
static int EstimateLatency(int Loc1, int Loc2);
static bool ParseLocation(int *pResult, const char *pString);

View file

@ -445,6 +445,7 @@ MACRO_CONFIG_INT(SvDnsblBan, sv_dnsbl_ban, 0, 0, 1, CFGFLAG_SERVER, "Automatical
MACRO_CONFIG_STR(SvDnsblBanReason, sv_dnsbl_ban_reason, 128, "VPN detected, try connecting without. Contact admin if mistaken", CFGFLAG_SERVER, "Ban reason for 'sv_dnsbl_ban'")
MACRO_CONFIG_INT(SvDnsblChat, sv_dnsbl_chat, 0, 0, 1, CFGFLAG_SERVER, "Don't allow chat from blacklisted addresses")
MACRO_CONFIG_INT(SvRconVote, sv_rcon_vote, 0, 0, 1, CFGFLAG_SERVER, "Only allow authed clients to call votes")
MACRO_CONFIG_STR(SvVerifyUrl, sv_verify_url, 128, "", CFGFLAG_SERVER, "A URL which the client will send a HTTP GET request to upon connecting")
MACRO_CONFIG_INT(SvPlayerDemoRecord, sv_player_demo_record, 0, 0, 1, CFGFLAG_SERVER, "Automatically record demos for each player")
MACRO_CONFIG_INT(SvDemoChat, sv_demo_chat, 0, 0, 1, CFGFLAG_SERVER, "Record chat for demos")
@ -548,8 +549,8 @@ MACRO_CONFIG_INT(SvMinTeamSize, sv_min_team_size, 2, 1, MAX_CLIENTS, CFGFLAG_SER
MACRO_CONFIG_INT(SvMaxTeamSize, sv_max_team_size, MAX_CLIENTS, 1, MAX_CLIENTS, CFGFLAG_SERVER | CFGFLAG_GAME, "Maximum team size")
MACRO_CONFIG_INT(SvMapVote, sv_map_vote, 1, 0, 1, CFGFLAG_SERVER, "Whether to allow /map")
MACRO_CONFIG_STR(SvAnnouncementFileName, sv_announcement_filename, 24, "announcement.txt", CFGFLAG_SERVER, "file which will have the announcement, each one at a line")
MACRO_CONFIG_INT(SvAnnouncementInterval, sv_announcement_interval, 300, 1, 9999, CFGFLAG_SERVER, "time(minutes) in which the announcement will be displayed from the announcement file")
MACRO_CONFIG_STR(SvAnnouncementFileName, sv_announcement_filename, IO_MAX_PATH_LENGTH, "announcement.txt", CFGFLAG_SERVER, "File which contains the announcements, one on each line")
MACRO_CONFIG_INT(SvAnnouncementInterval, sv_announcement_interval, 120, 1, 9999, CFGFLAG_SERVER, "The time (minutes) for how often an announcement will be displayed from the announcement file")
MACRO_CONFIG_INT(SvAnnouncementRandom, sv_announcement_random, 1, 0, 1, CFGFLAG_SERVER, "Whether announcements are sequential or random")
MACRO_CONFIG_INT(SvOldLaser, sv_old_laser, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_GAME, "Whether lasers can hit you if you shot them and that they pull you towards the bounce origin (0 for all new maps) or lasers can't hit you if you shot them, and they pull others towards the shooter")

View file

@ -72,6 +72,7 @@ bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson)
const json_value &Version = ServerInfo["version"];
const json_value &Clients = ServerInfo["clients"];
const json_value &RequiresLogin = ServerInfo["requires_login"];
const json_value &VerifyUrl = ServerInfo["verify_url"];
Error = false;
Error = Error || MaxClients.type != json_integer;
@ -103,6 +104,11 @@ bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson)
{
pOut->m_RequiresLogin = RequiresLogin;
}
str_copy(pOut->m_aVerifyUrl, "");
if(VerifyUrl.type == json_string)
{
str_copy(pOut->m_aVerifyUrl, VerifyUrl);
}
pOut->m_Passworded = Passworded;
str_copy(pOut->m_aGameType, GameType);
str_copy(pOut->m_aName, Name);
@ -239,6 +245,7 @@ CServerInfo2::operator CServerInfo() const
str_copy(Result.m_aName, m_aName);
str_copy(Result.m_aMap, m_aMapName);
str_copy(Result.m_aVersion, m_aVersion);
str_copy(Result.m_aVerifyUrl, m_aVerifyUrl);
for(int i = 0; i < minimum(m_NumClients, (int)SERVERINFO_MAX_CLIENTS); i++)
{

View file

@ -39,6 +39,7 @@ public:
char m_aMapName[MAX_MAP_LENGTH];
char m_aVersion[32];
bool m_RequiresLogin;
char m_aVerifyUrl[128];
bool operator==(const CServerInfo2 &Other) const;
bool operator!=(const CServerInfo2 &Other) const { return !(*this == Other); }

View file

@ -1565,7 +1565,7 @@ void CGameClient::OnNewSnapshot()
pClient->m_SkinInfo.m_ColorFeet = ColorRGBA(1, 1, 1);
}
pClient->UpdateRenderInfo(IsTeamPlay(), g_Config.m_ClDummy);
pClient->UpdateRenderInfo(IsTeamPlay());
}
}
else if(Item.m_Type == NETOBJTYPE_PLAYERINFO)
@ -2388,7 +2388,7 @@ void CGameClient::CClientStats::Reset()
m_FlagCaptures = 0;
}
void CGameClient::CClientData::UpdateRenderInfo(bool IsTeamPlay, int Conn)
void CGameClient::CClientData::UpdateRenderInfo(bool IsTeamPlay)
{
m_RenderInfo = m_SkinInfo;
@ -2403,6 +2403,7 @@ void CGameClient::CClientData::UpdateRenderInfo(bool IsTeamPlay, int Conn)
m_RenderInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(aTeamColors[m_Team]));
// 0.7
for(auto &Sixup : m_RenderInfo.m_aSixup)
{
const ColorRGBA aTeamColorsSixup[2] = {
ColorRGBA(0.753f, 0.318f, 0.318f, 1.0f),
@ -2410,18 +2411,19 @@ void CGameClient::CClientData::UpdateRenderInfo(bool IsTeamPlay, int Conn)
const ColorRGBA aMarkingColorsSixup[2] = {
ColorRGBA(0.824f, 0.345f, 0.345f, 1.0f),
ColorRGBA(0.345f, 0.514f, 0.824f, 1.0f)};
float MarkingAlpha = m_RenderInfo.m_aSixup[Conn].m_aColors[protocol7::SKINPART_MARKING].a;
for(auto &Color : m_RenderInfo.m_aSixup[Conn].m_aColors)
float MarkingAlpha = Sixup.m_aColors[protocol7::SKINPART_MARKING].a;
for(auto &Color : Sixup.m_aColors)
Color = aTeamColorsSixup[m_Team];
if(MarkingAlpha > 0.1f)
m_RenderInfo.m_aSixup[Conn].m_aColors[protocol7::SKINPART_MARKING] = aMarkingColorsSixup[m_Team];
Sixup.m_aColors[protocol7::SKINPART_MARKING] = aMarkingColorsSixup[m_Team];
}
}
else
{
m_RenderInfo.m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(12829350));
m_RenderInfo.m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(12829350));
for(auto &Color : m_RenderInfo.m_aSixup[Conn].m_aColors)
for(auto &Sixup : m_RenderInfo.m_aSixup)
for(auto &Color : Sixup.m_aColors)
Color = color_cast<ColorRGBA>(ColorHSLA(12829350));
}
}
@ -3757,8 +3759,7 @@ void CGameClient::RefreshSkins()
Client.m_SkinInfo.m_OriginalRenderSkin.Reset();
Client.m_SkinInfo.m_ColorableRenderSkin.Reset();
}
for(int Dummy = 0; Dummy < NUM_DUMMIES; Dummy++)
Client.UpdateRenderInfo(IsTeamPlay(), Dummy);
Client.UpdateRenderInfo(IsTeamPlay());
}
for(auto &pComponent : m_vpAll)

View file

@ -438,7 +438,7 @@ public:
bool m_SpecCharPresent;
vec2 m_SpecChar;
void UpdateRenderInfo(bool IsTeamPlay, int Conn);
void UpdateRenderInfo(bool IsTeamPlay);
void Reset();
class CSixup

View file

@ -196,7 +196,7 @@ void *CGameClient::TranslateGameMsg(int *pMsgId, CUnpacker *pUnpacker, int Conn)
{
m_aClients[pMsg7->m_ClientId].m_Team = pMsg7->m_Team;
m_pClient->m_TranslationContext.m_aClients[pMsg7->m_ClientId].m_Team = pMsg7->m_Team;
m_aClients[pMsg7->m_ClientId].UpdateRenderInfo(IsTeamPlay(), Conn);
m_aClients[pMsg7->m_ClientId].UpdateRenderInfo(IsTeamPlay());
// if(pMsg7->m_ClientId == m_LocalClientId)
// {

View file

@ -893,6 +893,12 @@ void CGameContext::ConReloadCensorlist(IConsole::IResult *pResult, void *pUserDa
pSelf->ReadCensorList();
}
void CGameContext::ConReloadAnnouncement(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->Server()->ReadAnnouncementsFile(g_Config.m_SvAnnouncementFileName);
}
void CGameContext::ConDumpAntibot(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;

View file

@ -1253,7 +1253,7 @@ void CGameContext::OnTick()
if(Server()->Tick() % (g_Config.m_SvAnnouncementInterval * Server()->TickSpeed() * 60) == 0)
{
const char *pLine = Server()->GetAnnouncementLine(g_Config.m_SvAnnouncementFileName);
const char *pLine = Server()->GetAnnouncementLine();
if(pLine)
SendChat(-1, TEAM_ALL, pLine);
}
@ -3643,6 +3643,7 @@ void CGameContext::OnConsoleInit()
Console()->Register("set_team_all", "i[team-id]", CFGFLAG_SERVER, ConSetTeamAll, this, "Set team of all players to team");
Console()->Register("hot_reload", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConHotReload, this, "Reload the map while preserving the state of tees and teams");
Console()->Register("reload_censorlist", "", CFGFLAG_SERVER, ConReloadCensorlist, this, "Reload the censorlist");
Console()->Register("reload_announcement", "", CFGFLAG_SERVER, ConReloadAnnouncement, this, "Reload the announcements");
Console()->Register("add_vote", "s[name] r[command]", CFGFLAG_SERVER, ConAddVote, this, "Add a voting option");
Console()->Register("remove_vote", "r[name]", CFGFLAG_SERVER, ConRemoveVote, this, "remove a voting option");

View file

@ -516,6 +516,7 @@ private:
static void ConUnFreezeHammer(IConsole::IResult *pResult, void *pUserData);
static void ConReloadCensorlist(IConsole::IResult *pResult, void *pUserData);
static void ConReloadAnnouncement(IConsole::IResult *pResult, void *pUserData);
CCharacter *GetPracticeCharacter(IConsole::IResult *pResult);