mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix concurrency of g_svNetKey
* Fix concurrency of g_svNetKey. * Improve logging. * Overall code cleanup.
This commit is contained in:
parent
71c5ff2416
commit
8712f7db81
@ -65,15 +65,15 @@ int NET_SendDatagram(SOCKET s, void* pPayload, int iLenght, v_netadr_t* pAdr, bo
|
||||
//-----------------------------------------------------------------------------
|
||||
void NET_SetKey(const string& svNetKey)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(g_NetKeyMutex);
|
||||
|
||||
g_svNetKey.clear();
|
||||
g_svNetKey = svNetKey;
|
||||
|
||||
DevMsg(eDLL_T::ENGINE, "______________________________________________________________\n");
|
||||
DevMsg(eDLL_T::ENGINE, "] NET_KEY ----------------------------------------------------\n");
|
||||
DevMsg(eDLL_T::ENGINE, "] BASE64: %s%s%s\n", g_svGreyB.c_str(), g_svNetKey.c_str(), g_svReset.c_str());
|
||||
DevMsg(eDLL_T::ENGINE, "--------------------------------------------------------------\n");
|
||||
|
||||
v_NET_SetKey(g_pNetKey, g_svNetKey.c_str());
|
||||
|
||||
DevMsg(eDLL_T::ENGINE, "Installed NetKey: '%s%s%s'\n",
|
||||
g_svGreyB.c_str(), g_svNetKey.c_str(), g_svReset.c_str());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -81,8 +81,8 @@ void NET_SetKey(const string& svNetKey)
|
||||
//-----------------------------------------------------------------------------
|
||||
void NET_GenerateKey()
|
||||
{
|
||||
g_svNetKey.clear();
|
||||
net_useRandomKey->SetValue(1);
|
||||
if (!net_useRandomKey->GetBool())
|
||||
net_useRandomKey->SetValue(1);
|
||||
|
||||
BCRYPT_ALG_HANDLE hAlgorithm;
|
||||
if (BCryptOpenAlgorithmProvider(&hAlgorithm, L"RNG", 0, 0) < 0)
|
||||
@ -90,26 +90,15 @@ void NET_GenerateKey()
|
||||
Error(eDLL_T::ENGINE, false, "Failed to open rng algorithm\n");
|
||||
return;
|
||||
}
|
||||
unsigned char pBuffer[0x10u];
|
||||
if (BCryptGenRandom(hAlgorithm, pBuffer, 0x10u, 0) < 0)
|
||||
|
||||
uint8_t pBuffer[AES_128_KEY_SIZE];
|
||||
if (BCryptGenRandom(hAlgorithm, pBuffer, AES_128_KEY_SIZE, 0) < 0)
|
||||
{
|
||||
Error(eDLL_T::ENGINE, false, "Failed to generate random data\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 0x10u; i++)
|
||||
{
|
||||
g_svNetKey += pBuffer[i];
|
||||
}
|
||||
|
||||
g_svNetKey = Base64Encode(g_svNetKey);
|
||||
|
||||
DevMsg(eDLL_T::ENGINE, "______________________________________________________________\n");
|
||||
DevMsg(eDLL_T::ENGINE, "] NET_KEY ----------------------------------------------------\n");
|
||||
DevMsg(eDLL_T::ENGINE, "] BASE64: %s%s%s\n", g_svGreyB.c_str(), g_svNetKey.c_str(), g_svReset.c_str());
|
||||
DevMsg(eDLL_T::ENGINE, "--------------------------------------------------------------\n");
|
||||
|
||||
v_NET_SetKey(g_pNetKey, g_svNetKey.c_str());
|
||||
NET_SetKey(Base64Encode(string(reinterpret_cast<char*>(&pBuffer), AES_128_KEY_SIZE)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -13,6 +13,8 @@
|
||||
#define NETMSG_LENGTH_BITS 12 // 512 bytes (11 in Valve Source, 256 bytes).
|
||||
#define NET_MIN_MESSAGE 5 // Even connectionless packets require int32 value (-1) + 1 byte content
|
||||
|
||||
#define AES_128_KEY_SIZE 16
|
||||
|
||||
/* ==== CNETCHAN ======================================================================================================================================================== */
|
||||
inline CMemory p_NET_Init;
|
||||
inline auto v_NET_Init = p_NET_Init.RCast<void* (*)(bool bDeveloper)>();
|
||||
@ -47,6 +49,7 @@ void NET_Detach();
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
extern string g_svNetKey;
|
||||
extern uintptr_t g_pNetKey;
|
||||
inline std::mutex g_NetKeyMutex;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class VNet : public IDetour
|
||||
|
@ -68,13 +68,7 @@ CClient* CServer::Authenticate(CServer* pServer, user_creds_s* pInpacket)
|
||||
string svIpAddress = pInpacket->m_nAddr.GetAddress();
|
||||
if (sv_showconnecting->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::SERVER, "\n");
|
||||
DevMsg(eDLL_T::SERVER, "______________________________________________________________\n");
|
||||
DevMsg(eDLL_T::SERVER, "] AUTHENTICATION ---------------------------------------------\n");
|
||||
DevMsg(eDLL_T::SERVER, "] UID : | '%s'\n", pInpacket->m_pUserID);
|
||||
DevMsg(eDLL_T::SERVER, "] OID : | '%llu'\n", pInpacket->m_nNucleusID);
|
||||
DevMsg(eDLL_T::SERVER, "] ADR : | '%s'\n", svIpAddress.c_str());
|
||||
DevMsg(eDLL_T::SERVER, "--------------------------------------------------------------\n");
|
||||
DevMsg(eDLL_T::SERVER, "Processing connectionless challenge from '%s' ('%llu')\n", svIpAddress.c_str(), pInpacket->m_nNucleusID);
|
||||
}
|
||||
|
||||
if (g_pBanSystem->IsBanListValid()) // Is the banlist vector valid?
|
||||
@ -90,10 +84,6 @@ CClient* CServer::Authenticate(CServer* pServer, user_creds_s* pInpacket)
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (sv_showconnecting->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::SERVER, "\n");
|
||||
}
|
||||
|
||||
if (g_bCheckCompBanDB)
|
||||
{
|
||||
|
@ -586,6 +586,7 @@ void CBrowser::UpdateHostingStatus(void)
|
||||
break;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> l(g_NetKeyMutex);
|
||||
NetGameServer_t netGameServer // !FIXME: create from main thread.
|
||||
{
|
||||
g_pServerListManager->m_Server.m_svHostName,
|
||||
@ -670,6 +671,8 @@ void CBrowser::SettingsPanel(void)
|
||||
{
|
||||
ProcessCommand(fmt::format("{:s} \"{:s}\"", "pylon_matchmaking_hostname", m_szMatchmakingHostName).c_str());
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> l(g_NetKeyMutex);
|
||||
ImGui::InputText("Netkey", const_cast<char*>(g_svNetKey.c_str()), ImGuiInputTextFlags_ReadOnly);
|
||||
if (ImGui::Button("Regenerate Encryption Key"))
|
||||
{
|
||||
|
@ -13,11 +13,13 @@
|
||||
#if !defined( INETMSGHANDLER_H )
|
||||
#define INETMSGHANDLER_H
|
||||
|
||||
typedef struct netpacket_s netpacket_t;
|
||||
|
||||
abstract_class IConnectionlessPacketHandler
|
||||
{
|
||||
public:
|
||||
virtual ~IConnectionlessPacketHandler(void) = 0;
|
||||
virtual bool ProcessConnectionlessPacket(void* packet) = 0;
|
||||
virtual bool ProcessConnectionlessPacket(netpacket_t* packet) = 0;
|
||||
};
|
||||
|
||||
abstract_class INetMessageHandler
|
||||
|
@ -1,8 +1,9 @@
|
||||
#ifndef ISERVER_H
|
||||
#define ISERVER_H
|
||||
#include "inetchannel.h"
|
||||
#include "inetmsghandler.h"
|
||||
|
||||
class IServer
|
||||
abstract_class IServer : public IConnectionlessPacketHandler
|
||||
{
|
||||
public:
|
||||
virtual ~IServer(void) = 0;
|
||||
|
@ -214,12 +214,7 @@ SQInteger Script_LoadRson(const SQChar* szRsonName)
|
||||
{
|
||||
if (sq_showrsonloading->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::ENGINE, "\n");
|
||||
DevMsg(eDLL_T::ENGINE, "______________________________________________________________\n");
|
||||
DevMsg(eDLL_T::ENGINE, "] RSON ]------------------------------------------------------\n");
|
||||
DevMsg(eDLL_T::ENGINE, "] PATH: '%s'\n", szRsonName);
|
||||
DevMsg(eDLL_T::ENGINE, "--------------------------------------------------------------\n");
|
||||
DevMsg(eDLL_T::ENGINE, "\n");
|
||||
DevMsg(eDLL_T::ENGINE, "Loading RSON: '%s'\n", szRsonName);
|
||||
}
|
||||
return v_Script_LoadRson(szRsonName);
|
||||
}
|
||||
|
@ -525,7 +525,7 @@ void RTech_StringToGUID_f(const CCommand& args)
|
||||
unsigned long long guid = g_pRTech->StringToGuid(args.Arg(1));
|
||||
|
||||
DevMsg(eDLL_T::RTECH, "______________________________________________________________\n");
|
||||
DevMsg(eDLL_T::RTECH, "] RTECH_HASH -------------------------------------------------\n");
|
||||
DevMsg(eDLL_T::RTECH, "] RTECH_HASH ]------------------------------------------------\n");
|
||||
DevMsg(eDLL_T::RTECH, "] GUID: '0x%llX'\n", guid);
|
||||
}
|
||||
|
||||
|
@ -345,7 +345,7 @@ void DestroyRenderTarget()
|
||||
if (mat_showdxoutput->GetBool())
|
||||
{
|
||||
DevMsg(eDLL_T::MS, "+----------------------------------------------------------------+\n");
|
||||
DevMsg(eDLL_T::MS, "| >>>>>>>>>>>>>>>| RENDER TARGET VIEW DESTROYED |<<<<<<<<<<<<<<< |\n");
|
||||
DevMsg(eDLL_T::MS, "| >>>>>>>>>>>>| !! RENDER TARGET VIEW DESTROYED !! |<<<<<<<<<<<< |\n");
|
||||
DevMsg(eDLL_T::MS, "+----------------------------------------------------------------+\n");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user