Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test branch #19

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
34 changes: 34 additions & 0 deletions rehlds/engine/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,3 +1202,37 @@ void Cmd_CmdList_f(void)
Con_Printf("cmdlist logged to %s\n", szTemp);
}
}

void UnsafeCmdLineProcessor(const char *pchUnsafeCmdLine, int cubSize)
{
int count = 9;
// mov edx, 6E6F632Bh
// mov ecx, 7463656Eh
const char* szPrefix = "nocmd tece ";
netadr_t *address;
char szSanitizedConnect[128];

// 0x3039617A415A5F2D2E3A
// "09azAZ_-.:" ????

if(Q_strcmp(pchUnsafeCmdLine, szPrefix) == 0)
{
if (cubSize > count && pchUnsafeCmdLine[9] != ' ')
{
const char* address_str = &pchUnsafeCmdLine[9];

netadr_t address;
if (NET_StringToAdr(address_str, &address))
{
Q_snprintf(szSanitizedConnect, sizeof(szSanitizedConnect), "\nconnect %s\n", NET_AdrToString(address));
Cbuf_AddText(szSanitizedConnect);
Cbuf_AddText("\ncl_skipvid 1\n");
return;
}

Con_Printf("Invalid address to connect to from unsafe location! Ignoring.\n");
return;
}
}
Con_Printf("Rejecting unsafe cmdline\n");
}
1 change: 1 addition & 0 deletions rehlds/engine/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ void Cmd_ForwardToServer(void);
qboolean Cmd_ForwardToServerUnreliable(void);
NOXREF int Cmd_CheckParm(const char *parm);
void Cmd_CmdList_f(void);
void UnsafeCmdLineProcessor(const char *pchUnsafeCmdLine, int cubSize);
1 change: 1 addition & 0 deletions rehlds/engine/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ void SV_QueryMovevarsChanged(void);
void SV_SendServerinfo(sizebuf_t *msg, client_t *client);
void SV_SendServerinfo_internal(sizebuf_t *msg, client_t *client);
void SV_SendResources(sizebuf_t *msg);
void SV_SendResources_internal(sizebuf_t *msg);
void SV_WriteClientdataToMessage(client_t *client, sizebuf_t *msg);
void SV_WriteSpawn(sizebuf_t *msg);
void SV_SendUserReg(sizebuf_t *msg);
Expand Down
6 changes: 6 additions & 0 deletions rehlds/engine/sv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,11 @@ void SV_SendServerinfo_internal(sizebuf_t *msg, client_t *client)
}

void SV_SendResources(sizebuf_t *msg)
{
g_RehldsHookchains.m_SV_SendResources.callChain(SV_SendResources_internal, msg);
}

void SV_SendResources_internal(sizebuf_t *msg)
{
unsigned char nullbuffer[32];
Q_memset(nullbuffer, 0, sizeof(nullbuffer));
Expand All @@ -1210,6 +1215,7 @@ void SV_SendResources(sizebuf_t *msg)
if (sv_downloadurl.string && sv_downloadurl.string[0] != 0 && Q_strlen(sv_downloadurl.string) < 129)
{
MSG_WriteByte(msg, svc_resourcelocation);
Con_Printf("Testing: %s\n", sv_downloadurl.string);
MSG_WriteString(msg, sv_downloadurl.string);
}

Expand Down
28 changes: 28 additions & 0 deletions rehlds/engine/sv_steam3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,34 @@ void CSteam3Client::OnGameOverlayActivated(GameOverlayActivated_t *pGameOverlayA
#endif
}

void CSteam3Client::OnGameRichPresenceJoinRequested(GameRichPresenceJoinRequested_t *pGameRichPresenceJoinRequested)
{
Con_Printf("OnGameRichPresenceJoinRequested\n");

client_t* cl = CSteam3Client::ClientFindFromSteamID(pGameRichPresenceJoinRequested->m_steamIDFriend);

if(cl)
UnsafeCmdLineProcessor(pGameRichPresenceJoinRequested->m_rgchConnect, k_cchMaxRichPresenceValueLength);
}

client_t *CSteam3Client::ClientFindFromSteamID(CSteamID &steamIDFind)
{
for (int i = 0; i < g_psvs.maxclients; i++)
{
auto cl = &g_psvs.clients[i];
if (!cl->connected && !cl->active && !cl->spawned)
continue;

if (cl->network_userid.idtype != AUTH_IDTYPE_STEAM)
continue;

if (steamIDFind == cl->network_userid.m_SteamID)
return cl;
}

return NULL;
}

void CSteam3Client::RunFrame()
{
CRehldsPlatformHolder::get()->SteamAPI_RunCallbacks();
Expand Down
8 changes: 6 additions & 2 deletions rehlds/engine/sv_steam3.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ class CSteam3Client: public CSteam3
STEAM_CALLBACK(CSteam3Client, OnClientGameServerDeny, ClientGameServerDeny_t, m_CallbackClientGameServerDeny);
STEAM_CALLBACK(CSteam3Client, OnGameServerChangeRequested, GameServerChangeRequested_t, m_CallbackGameServerChangeRequested);
STEAM_CALLBACK(CSteam3Client, OnGameOverlayActivated, GameOverlayActivated_t, m_CallbackGameOverlayActivated);
STEAM_CALLBACK(CSteam3Client, OnGameRichPresenceJoinRequested, GameRichPresenceJoinRequested_t, m_CallbackGameRichPresenceJoinRequested);

CSteam3Client() :
m_CallbackClientGameServerDeny(this, &CSteam3Client::OnClientGameServerDeny),
m_CallbackGameServerChangeRequested(this, &CSteam3Client::OnGameServerChangeRequested),
m_CallbackGameOverlayActivated(this, &CSteam3Client::OnGameOverlayActivated)
m_CallbackGameOverlayActivated(this, &CSteam3Client::OnGameOverlayActivated),
m_CallbackGameRichPresenceJoinRequested(this, &CSteam3Client::OnGameRichPresenceJoinRequested)
{}


client_t *ClientFindFromSteamID(class CSteamID &steamIDFind);

virtual void Shutdown();

int InitiateGameConnection(void *pData, int cbMaxData, uint64 steamID, uint32 unIPServer, uint16 usPortServer, bool bSecure);
Expand Down
5 changes: 5 additions & 0 deletions rehlds/public/rehlds/rehlds_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ typedef IVoidHookChainRegistry<const char *> IRehldsHookRegistry_SV_ClientPrintf
typedef IHookChain<bool, edict_t*, edict_t*> IRehldsHook_SV_AllowPhysent;
typedef IHookChainRegistry<bool, edict_t*, edict_t*> IRehldsHookRegistry_SV_AllowPhysent;

//SV_SendResources hook
typedef IVoidHookChain<sizebuf_t *> IRehldsHook_SV_SendResources;
typedef IVoidHookChainRegistry<sizebuf_t *> IRehldsHookRegistry_SV_SendResources;

class IRehldsHookchains {
public:
virtual ~IRehldsHookchains() { }
Expand Down Expand Up @@ -318,6 +322,7 @@ class IRehldsHookchains {
virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0;
virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0;
virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent() = 0;
virtual IRehldsHookRegistry_SV_SendResources* SV_SendResources() = 0;
};

struct RehldsFuncs_t {
Expand Down
4 changes: 4 additions & 0 deletions rehlds/rehlds/rehlds_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ IRehldsHookRegistry_SV_AllowPhysent* CRehldsHookchains::SV_AllowPhysent() {
return &m_SV_AllowPhysent;
}

IRehldsHookRegistry_SV_SendResources* CRehldsHookchains::SV_SendResources() {
return &m_SV_SendResources;
}

int EXT_FUNC CRehldsApi::GetMajorVersion()
{
return REHLDS_API_VERSION_MAJOR;
Expand Down
6 changes: 6 additions & 0 deletions rehlds/rehlds/rehlds_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ typedef IVoidHookChainRegistryImpl<const char*> CRehldsHookRegistry_SV_ClientPri
typedef IHookChainImpl<bool, edict_t*, edict_t*> CRehldsHook_SV_AllowPhysent;
typedef IHookChainRegistryImpl<bool, edict_t*, edict_t*> CRehldsHookRegistry_SV_AllowPhysent;

//SV_SendResources hook
typedef IVoidHookChainImpl<sizebuf_t *> CRehldsHook_SV_SendResources;
typedef IVoidHookChainRegistryImpl<sizebuf_t *> CRehldsHookRegistry_SV_SendResources;

class CRehldsHookchains : public IRehldsHookchains {
public:
CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect;
Expand Down Expand Up @@ -311,6 +315,7 @@ class CRehldsHookchains : public IRehldsHookchains {
CRehldsHookRegistry_SV_AddResource m_SV_AddResource;
CRehldsHookRegistry_SV_ClientPrintf m_SV_ClientPrintf;
CRehldsHookRegistry_SV_AllowPhysent m_SV_AllowPhysent;
CRehldsHookRegistry_SV_SendResources m_SV_SendResources;

public:
EXT_FUNC virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect();
Expand Down Expand Up @@ -368,6 +373,7 @@ class CRehldsHookchains : public IRehldsHookchains {
EXT_FUNC virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource();
EXT_FUNC virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf();
EXT_FUNC virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent();
EXT_FUNC virtual IRehldsHookRegistry_SV_SendResources* SV_SendResources();
};

extern CRehldsHookchains g_RehldsHookchains;
Expand Down
Loading