Merge pull request #104 from Mauler125/client_dll

Client dll
This commit is contained in:
Kawe Mazidjatari 2023-07-19 20:16:37 +02:00 committed by GitHub
commit 20bffe4158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 1244 additions and 965 deletions

View File

@ -65,4 +65,6 @@ add_subdirectory( pluginsdk )
set( FOLDER_CONTEXT "Game" )
add_subdirectory( vscript )
add_subdirectory( game )
set( FOLDER_CONTEXT "/" )
add_subdirectory( core )

View File

@ -26,6 +26,8 @@ ConVar* fps_max = nullptr;
ConVar* usercmd_frametime_max = nullptr;
ConVar* usercmd_frametime_min = nullptr;
ConVar* usercmd_dualwield_enable = nullptr;
ConVar* staticProp_no_fade_scalar = nullptr;
ConVar* staticProp_gather_size_weight = nullptr;
@ -115,7 +117,6 @@ ConVar* sv_voiceEcho = nullptr;
ConVar* sv_voiceenable = nullptr;
ConVar* sv_alltalk = nullptr;
ConVar* sv_usercmd_dualwield_enable = nullptr;
ConVar* player_userCmdsQueueWarning = nullptr;
//#ifdef DEDICATED
@ -327,8 +328,6 @@ void ConVar_StaticInit(void)
sv_validatePersonaName = ConVar::StaticCreate("sv_validatePersonaName" , "1" , FCVAR_RELEASE, "Validate the client's textual persona name on connect.", true, 0.f, false, 0.f, nullptr, nullptr);
sv_minPersonaNameLength = ConVar::StaticCreate("sv_minPersonaNameLength", "4" , FCVAR_RELEASE, "The minimum length of the client's textual persona name.", true, 0.f, false, 0.f, nullptr, nullptr);
sv_maxPersonaNameLength = ConVar::StaticCreate("sv_maxPersonaNameLength", "16", FCVAR_RELEASE, "The maximum length of the client's textual persona name.", true, 0.f, false, 0.f, nullptr, nullptr);
sv_usercmd_dualwield_enable = ConVar::StaticCreate("sv_usercmd_dualwield_enable", "0", FCVAR_RELEASE, "Allows setting dual wield cycle slots, and activating multiple inventory weapons from UserCmd.", false, 0.f, false, 0.f, nullptr, nullptr);
#endif // !CLIENT_DLL
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1)
bhit_depth_test = ConVar::StaticCreate("bhit_depth_test", "0", FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED, "Use depth test for bullet ray trace overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
@ -405,6 +404,8 @@ void ConVar_StaticInit(void)
// Taken from S15:
usercmd_frametime_max = ConVar::StaticCreate("usercmd_frametime_max", "0.100", FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "The largest amount of simulation seconds a UserCmd can have.", false, 0.f, false, 0.f, nullptr, nullptr);
usercmd_frametime_min = ConVar::StaticCreate("usercmd_frametime_min", "0.002857", FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "The smallest amount of simulation seconds a UserCmd can have.", false, 0.f, false, 0.f, nullptr, nullptr);
usercmd_dualwield_enable = ConVar::StaticCreate("usercmd_dualwield_enable", "0", FCVAR_RELEASE, "Allows setting dual wield cycle slots, and activating multiple inventory weapons from UserCmd.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// FILESYSTEM |
fs_showWarnings = ConVar::StaticCreate("fs_showWarnings" , "0", FCVAR_DEVELOPMENTONLY, "Logs the FileSystem warnings to the console, filtered by 'fs_warning_level' ( !slower! ).", true, 0.f, true, 2.f, nullptr, "0 = log to file. 1 = 0 + log to console. 2 = 1 + log to notify.");

View File

@ -17,6 +17,8 @@ extern ConVar* fps_max;
extern ConVar* usercmd_frametime_max;
extern ConVar* usercmd_frametime_min;
extern ConVar* usercmd_dualwield_enable;
extern ConVar* staticProp_no_fade_scalar;
extern ConVar* staticProp_gather_size_weight;
@ -105,7 +107,6 @@ extern ConVar* sv_voiceEcho;
extern ConVar* sv_voiceenable;
extern ConVar* sv_alltalk;
extern ConVar* sv_usercmd_dualwield_enable;
extern ConVar* player_userCmdsQueueWarning;
//#ifdef DEDICATED

View File

@ -1,4 +1,5 @@
cmake_minimum_required( VERSION 3.16 )
macro( add_sdk_project PROJECT_NAME )
add_module( "shared_lib" ${PROJECT_NAME} "vpc" ${FOLDER_CONTEXT} TRUE TRUE )
@ -79,7 +80,7 @@ target_link_libraries( ${PROJECT_NAME} PRIVATE
"localize"
"vscript"
"game"
"game_shared_static"
)
if( NOT ${PROJECT_NAME} STREQUAL "dedicated" )
@ -96,32 +97,48 @@ target_link_libraries( ${PROJECT_NAME} PRIVATE
"vgui"
"rui"
"engine"
"d3d11.lib"
)
else()
target_link_libraries( ${PROJECT_NAME} PRIVATE
"engine_ds"
"materialsystem_nodx" # Needs the No-DirectX version for patching.
)
endif()
# Determine the compiler definitions and link libraries per project.
if( ${PROJECT_NAME} STREQUAL "gamesdk" )
end_sources()
target_link_libraries( ${PROJECT_NAME} PRIVATE
"engine"
"server_static"
"client_static"
)
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"GAMESDK"
)
elseif( ${PROJECT_NAME} STREQUAL "dedicated" )
end_sources()
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"DEDICATED"
"MATERIALSYSTEM_NODX" # Needs the No-DirectX version for patching.
target_link_libraries( ${PROJECT_NAME} PRIVATE
"materialsystem_nodx" # Needs the No-DirectX version for patching.
"engine_ds"
"server_static"
)
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"MATERIALSYSTEM_NODX"
"SERVER_DLL"
"DEDICATED"
)
elseif( ${PROJECT_NAME} STREQUAL "client" )
end_sources( "${BUILD_OUTPUT_DIR}/bin/x64_retail/" )
target_link_libraries( ${PROJECT_NAME} PRIVATE
"engine_cl"
"client_static"
)
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"CLIENT_DLL"
)
endif()
target_link_options( ${PROJECT_NAME} PRIVATE
@ -142,18 +159,28 @@ add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -P ${ENGINE_SOURCE_DIR}/cmake/PostBuild.cmake
)
if( NOT ${PROJECT_NAME} STREQUAL "dedicated" )
if( ${PROJECT_NAME} STREQUAL "dedicated" )
set_target_properties( ${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND "r5apex.exe"
VS_DEBUGGER_COMMAND "r5apex_ds.exe"
)
else()
set_target_properties( ${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND "r5apex_ds.exe"
VS_DEBUGGER_COMMAND "r5apex.exe"
)
endif()
if( ${PROJECT_NAME} STREQUAL "client" )
set_target_properties( ${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND_ARGUMENTS "-wconsole -ansicolor -dev -devsdk -noserverdll"
)
else()
set_target_properties( ${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND_ARGUMENTS "-wconsole -ansicolor -dev -devsdk"
VS_DEBUGGER_WORKING_DIRECTORY "$(ProjectDir)../../../${BUILD_OUTPUT_DIR}/"
)
endif()
set_target_properties( ${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND_ARGUMENTS "-wconsole -ansicolor -dev -devsdk"
VS_DEBUGGER_WORKING_DIRECTORY "$(ProjectDir)../../../${BUILD_OUTPUT_DIR}/"
)
@ -161,4 +188,4 @@ endmacro()
add_sdk_project( "gamesdk" )
add_sdk_project( "dedicated" )
#add_sdk_project( "client" )
add_sdk_project( "client" )

View File

@ -122,11 +122,13 @@
#include "game/server/gameinterface.h"
#include "game/server/movehelper_server.h"
#include "game/server/physics_main.h"
#include "game/server/vscript_server.h"
#endif // !CLIENT_DLL
#ifndef DEDICATED
#include "game/client/viewrender.h"
#include "game/client/input.h"
#include "game/client/movehelper_client.h"
#include "game/client/vscript_client.h"
#endif // !DEDICATED
#include "public/edict.h"
#ifndef DEDICATED
@ -147,6 +149,31 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef DEDICATED
// These command line parameters disable a bunch of things in the engine that
// the dedicated server does not need, therefore, reducing a lot of overhead.
void InitCommandLineParameters()
{
CommandLine()->AppendParm("-collate", "");
CommandLine()->AppendParm("-multiple", "");
CommandLine()->AppendParm("-noorigin", "");
CommandLine()->AppendParm("-nodiscord", "");
CommandLine()->AppendParm("-noshaderapi", "");
CommandLine()->AppendParm("-nobakedparticles", "");
CommandLine()->AppendParm("-novid", "");
CommandLine()->AppendParm("-nomenuvid", "");
CommandLine()->AppendParm("-nosound", "");
CommandLine()->AppendParm("-nomouse", "");
CommandLine()->AppendParm("-nojoy", "");
CommandLine()->AppendParm("-nosendtable", "");
}
#endif // DEDICATED
void ScriptConstantRegistrationCallback(CSquirrelVM* s)
{
Script_RegisterListenServerConstants(s);
}
void Systems_Init()
{
DevMsg(eDLL_T::NONE, "+-------------------------------------------------------------+\n");
@ -193,6 +220,28 @@ void Systems_Init()
DevMsg(eDLL_T::NONE, "\n");
ConVar_StaticInit();
#ifdef DEDICATED
InitCommandLineParameters();
#endif // DEDICATED
// Script context registration callbacks.
ScriptConstantRegister_Callback = ScriptConstantRegistrationCallback;
#ifndef CLIENT_DLL
ServerScriptRegister_Callback = Script_RegisterServerFunctions;
CoreServerScriptRegister_Callback = Script_RegisterCoreServerFunctions;
AdminPanelScriptRegister_Callback = Script_RegisterAdminPanelFunctions;
#endif// !CLIENT_DLL
#ifndef SERVER_DLL
ClientScriptRegister_Callback = Script_RegisterClientFunctions;
UiScriptRegister_Callback = Script_RegisterUIFunctions;
#endif // !SERVER_DLL
#ifdef CLIENT_DLL
g_bClientDLL = true;
#endif
}
//////////////////////////////////////////////////////////////////////////
@ -519,11 +568,7 @@ void DetourRegister() // Register detour classes to be searched and hooked.
REGISTER(VGL_Screen);
#endif // !DEDICATED
#ifndef CLIENT_DLL
// !!! SERVER DLL ONLY !!!
REGISTER(HSV_Main);
// !!! END SERVER DLL ONLY !!!
#endif // !CLIENT_DLL
#ifndef DEDICATED
REGISTER(VGame); // REGISTER CLIENT ONLY!
@ -547,10 +592,11 @@ void DetourRegister() // Register detour classes to be searched and hooked.
REGISTER(VAnimation);
REGISTER(VUtil_Shared);
REGISTER(V_Weapon_Bolt);
#ifndef CLIENT_DLL
// In shared code, but weapon bolt is SERVER only.
REGISTER(V_Weapon_Bolt);
// Game/server
REGISTER(VAI_Network);
REGISTER(VAI_NetworkManager);

View File

@ -1,5 +1,4 @@
#include "core/stdafx.h"
#include "tier1/cvar.h"
#include "ebisusdk/EbisuSDK.h"
#include "engine/server/sv_main.h"
@ -44,17 +43,12 @@ bool IsOriginInitialized()
// Input : *pszName -
// Output : true on success, false on failure
//-----------------------------------------------------------------------------
bool IsValidPersonaName(const char* pszName)
bool IsValidPersonaName(const char* pszName, int nMinLen, int nMaxLen)
{
if (!sv_validatePersonaName->GetBool())
{
return true;
}
size_t len = strlen(pszName);
if (len < sv_minPersonaNameLength->GetInt() ||
len > sv_maxPersonaNameLength->GetInt())
if (len < nMinLen ||
len > nMaxLen)
{
return false;
}

View File

@ -19,7 +19,7 @@ inline bool* g_EbisuProfileInit = nullptr;
///////////////////////////////////////////////////////////////////////////////
void HEbisuSDK_Init();
bool IsOriginInitialized();
bool IsValidPersonaName(const char* pszName);
bool IsValidPersonaName(const char* pszName, int nMinLen, int nMaxLen);
///////////////////////////////////////////////////////////////////////////////
class VEbisuSDK : public IDetour

View File

@ -20,14 +20,12 @@ add_sources( SOURCE_GROUP "Collision"
"traceinit.h"
)
if( ${PROJECT_NAME} STREQUAL "engine" )
if( NOT ${PROJECT_NAME} STREQUAL "engine_ds" )
add_sources( SOURCE_GROUP "Debug"
"debugoverlay.cpp"
"debugoverlay.h"
)
endif()
if( ${PROJECT_NAME} STREQUAL "engine" )
add_sources( SOURCE_GROUP "Render"
"gl_matsysiface.h"
"gl_model_private.h"
@ -89,7 +87,7 @@ add_sources( SOURCE_GROUP "System"
"sdk_dll.h"
)
if( ${PROJECT_NAME} STREQUAL "engine" )
if( NOT ${PROJECT_NAME} STREQUAL "engine_ds" )
add_sources( SOURCE_GROUP "System"
"sys_getmodes.cpp"
"sys_getmodes.h"
@ -98,20 +96,22 @@ add_sources( SOURCE_GROUP "System"
)
endif()
if( NOT ${PROJECT_NAME} STREQUAL "engine_cl" )
add_sources( SOURCE_GROUP "Server"
"server/persistence.cpp"
"server/persistence.h"
"server/server.cpp"
"server/server.h"
"server/sv_main.cpp"
"server/sv_main.h"
"server/sv_rcon.cpp"
"server/sv_rcon.h"
"server/sv_main.cpp"
"server/sv_main.h"
"server/vengineserver_impl.cpp"
"server/vengineserver_impl.h"
"server/datablock_sender.cpp"
"server/datablock_sender.h"
)
endif()
add_sources( SOURCE_GROUP "Client"
"client/cdll_engine_int.cpp"
@ -129,7 +129,7 @@ add_sources( SOURCE_GROUP "Shared"
"shared/shared_rcon.h"
)
if( ${PROJECT_NAME} STREQUAL "engine" )
if( NOT ${PROJECT_NAME} STREQUAL "engine_ds" )
add_sources( SOURCE_GROUP "Client" # Client only.
"client/clientstate.cpp"
"client/clientstate.h"
@ -144,9 +144,7 @@ add_sources( SOURCE_GROUP "Client" # Client only.
"client/datablock_receiver.cpp"
"client/datablock_receiver.h"
)
endif()
if( ${PROJECT_NAME} STREQUAL "engine" )
add_sources( SOURCE_GROUP "GameUI"
"${ENGINE_SOURCE_DIR}/gameui/IBrowser.cpp"
"${ENGINE_SOURCE_DIR}/gameui/IBrowser.h"
@ -218,7 +216,7 @@ add_sources( SOURCE_GROUP "Public"
"${ENGINE_SOURCE_DIR}/public/gamebspfile.h"
)
if( ${PROJECT_NAME} STREQUAL "engine" )
if( NOT ${PROJECT_NAME} STREQUAL "engine_ds" )
add_sources( SOURCE_GROUP "Public"
"${ENGINE_SOURCE_DIR}/public/client_class.h"
"${ENGINE_SOURCE_DIR}/public/ivrenderview.h"
@ -232,8 +230,14 @@ if( ${PROJECT_NAME} STREQUAL "engine_ds" )
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"DEDICATED"
)
elseif( ${PROJECT_NAME} STREQUAL "engine_cl" )
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"CLIENT_DLL"
)
endif()
endmacro()
add_engine_project( "engine" )
add_engine_project( "engine_ds" )
add_engine_project( "engine_cl" )

View File

@ -15,6 +15,13 @@ inline int(*CL_ClearState)(void);
inline CMemory p_CL_RunPrediction;
inline void(*CL_RunPrediction)(void);
inline bool g_bClientDLL = false;
// Returns true if this is a client only build.
inline bool IsClientDLL()
{
return g_bClientDLL;
}
///////////////////////////////////////////////////////////////////////////////
class VCL_Main : public IDetour

View File

@ -103,6 +103,7 @@ void CClient::VActivatePlayer(CClient* pClient)
pClient->SetPersistenceState(PERSISTENCE::PERSISTENCE_READY);
v_CClient_ActivatePlayer(pClient);
#ifndef CLIENT_DLL
const CNetChan* pNetChan = pClient->GetNetChan();
if (pNetChan && sv_showconnecting->GetBool())
@ -110,6 +111,7 @@ void CClient::VActivatePlayer(CClient* pClient)
DevMsg(eDLL_T::SERVER, "Activated player #%d; channel %s(%s) ('%llu')\n",
pClient->GetUserID(), pNetChan->GetName(), pNetChan->GetAddress(), pClient->GetNucleusID());
}
#endif // !CLIENT_DLL
}
//---------------------------------------------------------------------------------
@ -216,3 +218,26 @@ bool CClient::VSendNetMsgEx(CClient* pClient, CNetMessage* pMsg, char bLocal, bo
{
return pClient->SendNetMsgEx(pMsg, bLocal, bForceReliable, bVoice);
}
void VClient::Attach(void) const
{
#ifndef CLIENT_DLL
DetourAttach((LPVOID*)&v_CClient_Clear, &CClient::VClear);
DetourAttach((LPVOID*)&v_CClient_Connect, &CClient::VConnect);
DetourAttach((LPVOID*)&v_CClient_ActivatePlayer, &CClient::VActivatePlayer);
DetourAttach((LPVOID*)&v_CClient_ProcessStringCmd, &CClient::VProcessStringCmd);
DetourAttach((LPVOID*)&v_CClient_SendNetMsgEx, &CClient::VSendNetMsgEx);
//DetourAttach((LPVOID*)&p_CClient_SendSnapshot, &CClient::VSendSnapshot);
#endif // !CLIENT_DLL
}
void VClient::Detach(void) const
{
#ifndef CLIENT_DLL
DetourDetach((LPVOID*)&v_CClient_Clear, &CClient::VClear);
DetourDetach((LPVOID*)&v_CClient_Connect, &CClient::VConnect);
DetourDetach((LPVOID*)&v_CClient_ActivatePlayer, &CClient::VActivatePlayer);
DetourDetach((LPVOID*)&v_CClient_ProcessStringCmd, &CClient::VProcessStringCmd);
DetourDetach((LPVOID*)&v_CClient_SendNetMsgEx, &CClient::VSendNetMsgEx);
//DetourDetach((LPVOID*)&p_CClient_SendSnapshot, &CClient::VSendSnapshot);
#endif // !CLIENT_DLL
}

View File

@ -268,24 +268,7 @@ class VClient : public IDetour
}
virtual void GetVar(void) const { }
virtual void GetCon(void) const { }
virtual void Attach(void) const
{
DetourAttach((LPVOID*)&v_CClient_Clear, &CClient::VClear);
DetourAttach((LPVOID*)&v_CClient_Connect, &CClient::VConnect);
DetourAttach((LPVOID*)&v_CClient_ActivatePlayer, &CClient::VActivatePlayer);
DetourAttach((LPVOID*)&v_CClient_ProcessStringCmd, &CClient::VProcessStringCmd);
DetourAttach((LPVOID*)&v_CClient_SendNetMsgEx, &CClient::VSendNetMsgEx);
//DetourAttach((LPVOID*)&p_CClient_SendSnapshot, &CClient::VSendSnapshot);
}
virtual void Detach(void) const
{
DetourDetach((LPVOID*)&v_CClient_Clear, &CClient::VClear);
DetourDetach((LPVOID*)&v_CClient_Connect, &CClient::VConnect);
DetourDetach((LPVOID*)&v_CClient_ActivatePlayer, &CClient::VActivatePlayer);
DetourDetach((LPVOID*)&v_CClient_ProcessStringCmd, &CClient::VProcessStringCmd);
DetourDetach((LPVOID*)&v_CClient_SendNetMsgEx, &CClient::VSendNetMsgEx);
//DetourDetach((LPVOID*)&p_CClient_SendSnapshot, &CClient::VSendSnapshot);
}
virtual void Attach(void) const;
virtual void Detach(void) const;
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -17,6 +17,7 @@
#include "datacache/mdlcache.h"
#ifndef CLIENT_DLL
#include "engine/server/sv_rcon.h"
#include "engine/server/server.h"
#endif // !CLIENT_DLL
#ifndef DEDICATED
#include "engine/client/cl_rcon.h"
@ -53,6 +54,46 @@
#endif // !CLIENT_DLL
#include "game/shared/vscript_shared.h"
#ifndef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: Send keep alive request to Pylon Master Server.
// Input : &netGameServer -
// Output : Returns true on success, false otherwise.
//-----------------------------------------------------------------------------
bool HostState_KeepAlive(const NetGameServer_t& netGameServer)
{
if (!g_pServer->IsActive() || !sv_pylonVisibility->GetBool()) // Check for active game.
{
return false;
}
string errorMsg;
string hostToken;
const bool result = g_pMasterServer->PostServerHost(errorMsg, hostToken, netGameServer);
if (!result)
{
if (!errorMsg.empty() && g_pMasterServer->GetCurrentError().compare(errorMsg) != NULL)
{
g_pMasterServer->SetCurrentError(errorMsg);
Error(eDLL_T::SERVER, NO_ERROR, "%s\n", errorMsg.c_str());
}
}
else // Attempt to log the token, if there is one.
{
if (!hostToken.empty() && g_pMasterServer->GetCurrentToken().compare(hostToken) != NULL)
{
g_pMasterServer->SetCurrentToken(hostToken);
DevMsg(eDLL_T::SERVER, "Published server with token: %s'%s%s%s'\n",
g_svReset, g_svGreyB,
hostToken.c_str(), g_svReset);
}
}
return result;
}
#endif // !CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: state machine's main processing loop
//-----------------------------------------------------------------------------
@ -303,7 +344,7 @@ void CHostState::Think(void) const
).count()
};
std::thread(&CPylon::KeepAlive, g_pMasterServer, netGameServer).detach();
std::thread(&HostState_KeepAlive, netGameServer).detach();
pylonTimer.Start();
}
#endif // DEDICATED
@ -370,9 +411,11 @@ void CHostState::State_NewGame(void)
DevMsg(eDLL_T::ENGINE, "%s: Loading level: '%s'\n", __FUNCTION__, g_pHostState->m_levelName);
LARGE_INTEGER time{};
#ifndef CLIENT_DLL
bool bSplitScreenConnect = m_bSplitScreenConnect;
m_bSplitScreenConnect = 0;
#ifndef CLIENT_DLL
if (!g_pServerGameClients) // Init Game if it ain't valid.
{
SV_InitGameDLL();

View File

@ -105,8 +105,24 @@ CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge)
DevMsg(eDLL_T::SERVER, "Processing connectionless challenge for '[%s]:%i' ('%llu')\n",
pszAddresBuffer, nPort, nNucleusID);
bool bValidName = false;
if (VALID_CHARSTAR(pszPersonaName) &&
V_IsValidUTF8(pszPersonaName))
{
if (sv_validatePersonaName->GetBool() &&
!IsValidPersonaName(pszPersonaName, sv_minPersonaNameLength->GetInt(), sv_maxPersonaNameLength->GetInt()))
{
bValidName = false;
}
else
{
bValidName = true;
}
}
// Only proceed connection if the client's name is valid and UTF-8 encoded.
if (!VALID_CHARSTAR(pszPersonaName) || !V_IsValidUTF8(pszPersonaName) || !IsValidPersonaName(pszPersonaName))
if (!bValidName)
{
pServer->RejectConnection(pServer->m_Socket, &pChallenge->netAdr, "#Valve_Reject_Invalid_Name");
if (bEnableLogging)

View File

@ -192,20 +192,3 @@ void SV_BroadcastVoiceData(CClient* cl, int nBytes, char* data)
pClient->SendNetMsgEx(&voiceData, false, false, true);
}
}
///////////////////////////////////////////////////////////////////////////////
void HSV_Main::Attach(void) const
{
//DetourAttach(&v_SV_InitGameDLL, SV_InitGameDLL);
//DetourAttach(&v_SV_ShutdownGameDLL, SV_ShutdownGameDLL);
//DetourAttach(&v_SV_ActivateServer, SV_ActivateServer);
DetourAttach(&v_SV_BroadcastVoiceData, SV_BroadcastVoiceData);
}
void HSV_Main::Detach(void) const
{
//DetourDetach(&v_SV_InitGameDLL, SV_InitGameDLL);
//DetourDetach(&v_SV_ShutdownGameDLL, SV_ShutdownGameDLL);
//DetourDetach(&v_SV_ActivateServer, SV_ActivateServer);
DetourDetach(&v_SV_BroadcastVoiceData, SV_BroadcastVoiceData);
}

View File

@ -39,6 +39,7 @@ inline bool IsDedicated()
void SV_InitGameDLL();
void SV_ShutdownGameDLL();
bool SV_ActivateServer();
void SV_BroadcastVoiceData(CClient* cl, int nBytes, char* data);
void SV_IsClientBanned(CClient* pClient, const string& svIPAddr, const uint64_t nNucleusID, const string& svPersonaName, const int nPort);
void SV_CheckForBan(const BannedVec_t* pBannedVec = nullptr);
///////////////////////////////////////////////////////////////////////////////
@ -83,7 +84,25 @@ class HSV_Main : public IDetour
.FindPatternSelf("40 38 3D", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast<bool*>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const;
virtual void Detach(void) const;
///////////////////////////////////////////////////////////////////////////////
virtual void Attach(void) const
{
//DetourAttach(&v_SV_InitGameDLL, SV_InitGameDLL);
//DetourAttach(&v_SV_ShutdownGameDLL, SV_ShutdownGameDLL);
//DetourAttach(&v_SV_ActivateServer, SV_ActivateServer);
#ifndef CLIENT_DLL
DetourAttach(&v_SV_BroadcastVoiceData, SV_BroadcastVoiceData);
#endif // !CLIENT_DLL
}
virtual void Detach(void) const
{
//DetourDetach(&v_SV_InitGameDLL, SV_InitGameDLL);
//DetourDetach(&v_SV_ShutdownGameDLL, SV_ShutdownGameDLL);
//DetourDetach(&v_SV_ActivateServer, SV_ActivateServer);
#ifndef CLIENT_DLL
DetourDetach(&v_SV_BroadcastVoiceData, SV_BroadcastVoiceData);
#endif // !CLIENT_DLL
}
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -1,8 +1,12 @@
cmake_minimum_required( VERSION 3.16 )
add_module( "lib" "game" "vpc" ${FOLDER_CONTEXT} TRUE TRUE )
macro( add_game_project PROJECT_NAME )
add_module( "lib" ${PROJECT_NAME} "vpc" ${FOLDER_CONTEXT} TRUE TRUE )
start_sources()
if( ${PROJECT_NAME} STREQUAL "game_shared_static" )
add_sources( SOURCE_GROUP "Shared"
"shared/ai_utility_shared.cpp"
"shared/ai_utility_shared.h"
@ -33,6 +37,10 @@ add_sources( SOURCE_GROUP "Shared/Weapon"
"shared/r1/weapon_bolt.h"
)
endif()
if( ${PROJECT_NAME} STREQUAL "server_static" )
add_sources( SOURCE_GROUP "Server"
"server/ai_network.cpp"
"server/ai_network.h"
@ -61,8 +69,22 @@ add_sources( SOURCE_GROUP "Server"
"server/player.cpp"
"server/player.h"
"server/playerlocaldata.h"
"server/util_server.cpp"
"server/util_server.h"
"server/vscript_server.cpp"
"server/vscript_server.h"
)
add_sources( SOURCE_GROUP "Public"
"${ENGINE_SOURCE_DIR}/public/iserverentity.h"
"${ENGINE_SOURCE_DIR}/public/iservernetworkable.h"
"${ENGINE_SOURCE_DIR}/public/iserverunknown.h"
)
endif()
if( ${PROJECT_NAME} STREQUAL "client_static" )
add_sources( SOURCE_GROUP "Client"
"client/c_baseentity.cpp"
"client/c_baseentity.h"
@ -75,10 +97,27 @@ add_sources( SOURCE_GROUP "Client"
"client/movehelper_client.cpp"
"client/movehelper_client.h"
"client/spritemodel.cpp"
"client/util_client.cpp"
"client/util_client.h"
"client/viewrender.cpp"
"client/viewrender.h"
"client/vscript_client.cpp"
"client/vscript_client.h"
)
add_sources( SOURCE_GROUP "Public"
"${ENGINE_SOURCE_DIR}/public/icliententity.h"
"${ENGINE_SOURCE_DIR}/public/icliententitylist.h"
"${ENGINE_SOURCE_DIR}/public/iclientnetworkable.h"
"${ENGINE_SOURCE_DIR}/public/iclientrenderable.h"
"${ENGINE_SOURCE_DIR}/public/iclientthinkable.h"
"${ENGINE_SOURCE_DIR}/public/iclientunknown.h"
"${ENGINE_SOURCE_DIR}/public/game/client/iinput.h"
)
endif()
add_sources( SOURCE_GROUP "Public"
"${ENGINE_SOURCE_DIR}/public/basehandle.h"
"${ENGINE_SOURCE_DIR}/public/edict.h"
@ -86,25 +125,31 @@ add_sources( SOURCE_GROUP "Public"
"${ENGINE_SOURCE_DIR}/public/globalvars_base.h"
"${ENGINE_SOURCE_DIR}/public/ihandleentity.h"
"${ENGINE_SOURCE_DIR}/public/iserverentity.h"
"${ENGINE_SOURCE_DIR}/public/iservernetworkable.h"
"${ENGINE_SOURCE_DIR}/public/iserverunknown.h"
"${ENGINE_SOURCE_DIR}/public/icliententity.h"
"${ENGINE_SOURCE_DIR}/public/icliententitylist.h"
"${ENGINE_SOURCE_DIR}/public/iclientnetworkable.h"
"${ENGINE_SOURCE_DIR}/public/iclientrenderable.h"
"${ENGINE_SOURCE_DIR}/public/iclientthinkable.h"
"${ENGINE_SOURCE_DIR}/public/iclientunknown.h"
"${ENGINE_SOURCE_DIR}/public/game/shared/weapon_types.h"
"${ENGINE_SOURCE_DIR}/public/game/shared/in_buttons.h"
"${ENGINE_SOURCE_DIR}/public/game/client/iinput.h"
)
end_sources()
if( ${PROJECT_NAME} STREQUAL "server_static" )
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"SERVER_DLL"
)
elseif( ${PROJECT_NAME} STREQUAL "client_static" )
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"CLIENT_DLL"
)
endif()
target_include_directories( ${PROJECT_NAME} PRIVATE
"${ENGINE_SOURCE_DIR}/tier0/"
"${ENGINE_SOURCE_DIR}/tier1/"
)
endmacro()
add_game_project( "server_static" )
add_game_project( "client_static" )
add_game_project( "game_shared_static" )

View File

@ -0,0 +1,8 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#include "util_client.h"
// Currently empty; add client specific game utils here...

View File

@ -0,0 +1,9 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef UTIL_CLIENT_H
#define UTIL_CLIENT_H
#endif // UTIL_CLIENT_H

View File

@ -0,0 +1,417 @@
//=============================================================================//
//
// Purpose: Expose native code to VScript API
//
//-----------------------------------------------------------------------------
//
// See 'game/shared/vscript_shared.cpp' for more details.
//
//=============================================================================//
#include "core/stdafx.h"
#include "vpc/keyvalues.h"
#include "engine/cmodel_bsp.h"
#include "engine/host_state.h"
#include "engine/client/cl_main.h"
#include "networksystem/pylon.h"
#include "networksystem/listmanager.h"
#include "game/shared/vscript_shared.h"
#include "vscript/languages/squirrel_re/include/sqvm.h"
#include "vscript_client.h"
//-----------------------------------------------------------------------------
// Purpose: checks if the server index is valid, raises an error if not
//-----------------------------------------------------------------------------
static SQBool Script_CheckServerIndex(HSQUIRRELVM v, SQInteger iServer)
{
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
if (iServer >= iCount)
{
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
return false;
}
return true;
}
namespace VScriptCode
{
namespace Client
{
//-----------------------------------------------------------------------------
// Purpose: refreshes the server list
//-----------------------------------------------------------------------------
SQRESULT RefreshServerList(HSQUIRRELVM v)
{
string serverMessage; // Refresh list.
size_t iCount = g_pServerListManager->RefreshServerList(serverMessage);
sq_pushinteger(v, static_cast<SQInteger>(iCount));
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get current server count from pylon
//-----------------------------------------------------------------------------
SQRESULT GetServerCount(HSQUIRRELVM v)
{
size_t iCount = g_pServerListManager->m_vServerList.size();
sq_pushinteger(v, static_cast<SQInteger>(iCount));
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get response from private server request
//-----------------------------------------------------------------------------
SQRESULT GetHiddenServerName(HSQUIRRELVM v)
{
SQChar* privateToken = sq_getstring(v, 1);
if (!VALID_CHARSTAR(privateToken))
return SQ_OK;
string hiddenServerRequestMessage;
NetGameServer_t serverListing;
bool result = g_pMasterServer->GetServerByToken(serverListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
if (!result)
{
if (hiddenServerRequestMessage.empty())
{
sq_pushstring(v, "Request failed", -1);
}
else
{
hiddenServerRequestMessage = Format("Request failed: %s", hiddenServerRequestMessage.c_str());
sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1);
}
return SQ_OK;
}
if (serverListing.m_svHostName.empty())
{
if (hiddenServerRequestMessage.empty())
{
hiddenServerRequestMessage = Format("Server listing empty");
}
else
{
hiddenServerRequestMessage = Format("Server listing empty: %s", hiddenServerRequestMessage.c_str());
}
sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1);
}
else
{
hiddenServerRequestMessage = Format("Found server: %s", serverListing.m_svHostName.c_str());
sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1);
}
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current name from serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerName(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
{
return SQ_ERROR;
}
const string& serverName = g_pServerListManager->m_vServerList[iServer].m_svHostName;
sq_pushstring(v, serverName.c_str(), -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current description from serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerDescription(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
{
return SQ_ERROR;
}
const string& serverDescription = g_pServerListManager->m_vServerList[iServer].m_svDescription;
sq_pushstring(v, serverDescription.c_str(), -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current map via serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerMap(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
{
return SQ_ERROR;
}
const string& svServerMapName = g_pServerListManager->m_vServerList[iServer].m_svHostMap;
sq_pushstring(v, svServerMapName.c_str(), -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current playlist via serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerPlaylist(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
{
return SQ_ERROR;
}
const string& serverPlaylist = g_pServerListManager->m_vServerList[iServer].m_svPlaylist;
sq_pushstring(v, serverPlaylist.c_str(), -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current player count via serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerCurrentPlayers(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
{
return SQ_ERROR;
}
const string& playerCount = g_pServerListManager->m_vServerList[iServer].m_svPlayerCount.c_str();
sq_pushinteger(v, strtol(playerCount.c_str(), NULL, NULL));
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current player count via serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerMaxPlayers(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
{
return SQ_ERROR;
}
const string& maxPlayers = g_pServerListManager->m_vServerList[iServer].m_svMaxPlayers;
sq_pushinteger(v, strtol(maxPlayers.c_str(), NULL, NULL));
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get promo data for serverbrowser panels
//-----------------------------------------------------------------------------
SQRESULT GetPromoData(HSQUIRRELVM v)
{
enum class R5RPromoData : SQInteger
{
PromoLargeTitle,
PromoLargeDesc,
PromoLeftTitle,
PromoLeftDesc,
PromoRightTitle,
PromoRightDesc
};
R5RPromoData ePromoIndex = static_cast<R5RPromoData>(sq_getinteger(v, 1));
const char* pszPromoKey;
switch (ePromoIndex)
{
case R5RPromoData::PromoLargeTitle:
{
pszPromoKey = "#PROMO_LARGE_TITLE";
break;
}
case R5RPromoData::PromoLargeDesc:
{
pszPromoKey = "#PROMO_LARGE_DESCRIPTION";
break;
}
case R5RPromoData::PromoLeftTitle:
{
pszPromoKey = "#PROMO_LEFT_TITLE";
break;
}
case R5RPromoData::PromoLeftDesc:
{
pszPromoKey = "#PROMO_LEFT_DESCRIPTION";
break;
}
case R5RPromoData::PromoRightTitle:
{
pszPromoKey = "#PROMO_RIGHT_TITLE";
break;
}
case R5RPromoData::PromoRightDesc:
{
pszPromoKey = "#PROMO_RIGHT_DESCRIPTION";
break;
}
default:
{
pszPromoKey = "#PROMO_SDK_ERROR";
break;
}
}
sq_pushstring(v, pszPromoKey, -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: connect to server from native server browser entries
//-----------------------------------------------------------------------------
SQRESULT ConnectToServer(HSQUIRRELVM v)
{
SQChar* ipAddress = sq_getstring(v, 1);
SQChar* cryptoKey = sq_getstring(v, 2);
if (!VALID_CHARSTAR(ipAddress) || VALID_CHARSTAR(cryptoKey))
return SQ_OK;
DevMsg(eDLL_T::UI, "Connecting to server with ip address '%s' and encryption key '%s'\n", ipAddress, cryptoKey);
g_pServerListManager->ConnectToServer(ipAddress, cryptoKey);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: set netchannel encryption key and connect to server
//-----------------------------------------------------------------------------
SQRESULT ConnectToListedServer(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
if (!Script_CheckServerIndex(v, iServer))
{
return SQ_ERROR;
}
const NetGameServer_t& gameServer = g_pServerListManager->m_vServerList[iServer];
g_pServerListManager->ConnectToServer(gameServer.m_svIpAddress, gameServer.m_svGamePort,
gameServer.m_svEncryptionKey);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: request token from pylon and join server with result.
//-----------------------------------------------------------------------------
SQRESULT ConnectToHiddenServer(HSQUIRRELVM v)
{
SQChar* privateToken = sq_getstring(v, 1);
if (!VALID_CHARSTAR(privateToken))
return SQ_OK;
string hiddenServerRequestMessage;
NetGameServer_t netListing;
bool result = g_pMasterServer->GetServerByToken(netListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
if (result)
{
g_pServerListManager->ConnectToServer(netListing.m_svIpAddress, netListing.m_svGamePort, netListing.m_svEncryptionKey);
}
else
{
Warning(eDLL_T::UI, "Failed to connect to private server: %s\n", hiddenServerRequestMessage.c_str());
}
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: checks whether this SDK build is a client dll
//-----------------------------------------------------------------------------
SQRESULT IsClientDLL(HSQUIRRELVM v)
{
sq_pushbool(v, ::IsClientDLL());
return SQ_OK;
}
}
}
//---------------------------------------------------------------------------------
// Purpose: registers script functions in CLIENT context
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterClientFunctions(CSquirrelVM* s)
{
Script_RegisterCommonAbstractions(s);
Script_RegisterCoreClientFunctions(s);
}
//---------------------------------------------------------------------------------
// Purpose: registers script functions in UI context
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterUIFunctions(CSquirrelVM* s)
{
Script_RegisterCommonAbstractions(s);
Script_RegisterCoreClientFunctions(s);
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, RefreshServerList, "Refreshes the public server list and returns the count", "int", "");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerCount, "Gets the number of public servers", "int", "");
// Functions for retrieving server browser data
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetHiddenServerName, "Gets hidden server name by token", "string", "string");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerName, "Gets the name of the server at the specified index of the server list", "string", "int");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerDescription, "Gets the description of the server at the specified index of the server list", "string", "int");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerMap, "Gets the map of the server at the specified index of the server list", "string", "int");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerPlaylist, "Gets the playlist of the server at the specified index of the server list", "string", "int");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerCurrentPlayers, "Gets the current player count of the server at the specified index of the server list", "int", "int");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetServerMaxPlayers, "Gets the max player count of the server at the specified index of the server list", "int", "int");
// Misc main menu functions
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, GetPromoData, "Gets promo data for specified slot type", "string", "int");
// Functions for connecting to servers
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToServer, "Joins server by ip address and encryption key", "void", "string, string");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToListedServer, "Joins listed server by index", "void", "int");
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, ConnectToHiddenServer, "Joins hidden server by token", "void", "string");
}
//---------------------------------------------------------------------------------
// Purpose: core client script functions
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterCoreClientFunctions(CSquirrelVM* s)
{
DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, IsClientDLL, "Returns whether this build is client only", "bool", "");
}

View File

@ -0,0 +1,40 @@
#ifndef VSCRIPT_CLIENT_H
#define VSCRIPT_CLIENT_H
namespace VScriptCode
{
namespace Client
{
SQRESULT RefreshServerList(HSQUIRRELVM v);
SQRESULT GetServerCount(HSQUIRRELVM v);
SQRESULT GetHiddenServerName(HSQUIRRELVM v);
SQRESULT GetServerName(HSQUIRRELVM v);
SQRESULT GetServerDescription(HSQUIRRELVM v);
SQRESULT GetServerMap(HSQUIRRELVM v);
SQRESULT GetServerPlaylist(HSQUIRRELVM v);
SQRESULT GetServerCurrentPlayers(HSQUIRRELVM v);
SQRESULT GetServerMaxPlayers(HSQUIRRELVM v);
SQRESULT GetPromoData(HSQUIRRELVM v);
SQRESULT ConnectToListedServer(HSQUIRRELVM v);
SQRESULT ConnectToHiddenServer(HSQUIRRELVM v);
SQRESULT ConnectToServer(HSQUIRRELVM v);
SQRESULT IsClientDLL(HSQUIRRELVM v);
}
}
void Script_RegisterClientFunctions(CSquirrelVM* s);
void Script_RegisterUIFunctions(CSquirrelVM* s);
void Script_RegisterCoreClientFunctions(CSquirrelVM* s);
#define DEFINE_CLIENT_SCRIPTFUNC_NAMED(s, functionName, helpString, \
returnType, parameters) \
s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \
helpString, returnType, parameters, VScriptCode::Client::##functionName); \
#endif // VSCRIPT_CLIENT_H

View File

@ -16,7 +16,7 @@
#include "entitylist.h"
#include "baseanimating.h"
#include "game/shared/usercmd.h"
#include "game/shared/util_shared.h"
#include "game/server/util_server.h"
//-----------------------------------------------------------------------------
// This is called when a new game is started. (restart, map)

View File

@ -8,9 +8,9 @@
#include "tier1/cvar.h"
#include "player.h"
#include "physics_main.h"
#include "engine/server/server.h"
#include "engine/server/server.h"
#include "engine/client/client.h"
#include "game/shared/util_shared.h"
#include "game/server/util_server.h"
//-----------------------------------------------------------------------------
// Purpose: Runs the command simulation for fake players

View File

@ -0,0 +1,25 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#include "game/server/player.h"
#include "game/server/gameinterface.h"
#include "util_server.h"
//-----------------------------------------------------------------------------
// Purpose: returns the player instance by edict
//-----------------------------------------------------------------------------
CPlayer* UTIL_PlayerByIndex(int nIndex)
{
if (nIndex < 1 || nIndex >(*g_pGlobals)->m_nMaxClients || nIndex == FL_EDICT_INVALID)
{
assert(0);
return nullptr;
}
// !TODO: Improve this!!!
CPlayer* pPlayer = reinterpret_cast<CPlayer*>((*g_pGlobals)->m_pEdicts[nIndex + 0x7808]);
return pPlayer;
}

View File

@ -0,0 +1,12 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef UTIL_SERVER_H
#define UTIL_SERVER_H
#include "game/server/player.h"
CPlayer* UTIL_PlayerByIndex(int nIndex);
#endif // UTIL_SERVER_H

View File

@ -0,0 +1,236 @@
//=============================================================================//
//
// Purpose: Expose native code to VScript API
//
//-----------------------------------------------------------------------------
//
// See 'game/shared/vscript_shared.cpp' for more details.
//
//=============================================================================//
#include "core/stdafx.h"
#include "engine/server/server.h"
#include "game/shared/vscript_shared.h"
#include "vscript/languages/squirrel_re/include/sqvm.h"
#include "vscript_server.h"
#include <engine/host_state.h>
#include <networksystem/listmanager.h>
namespace VScriptCode
{
namespace Server
{
//-----------------------------------------------------------------------------
// Purpose: create server via native serverbrowser entries
// TODO: return a boolean on failure instead of raising an error, so we could
// determine from scripts whether or not to spin a local server, or connect
// to a dedicated server (for disconnecting and loading the lobby, for example)
//-----------------------------------------------------------------------------
SQRESULT CreateServer(HSQUIRRELVM v)
{
SQChar* serverName = sq_getstring(v, 1);
SQChar* serverDescription = sq_getstring(v, 2);
SQChar* serverMapName = sq_getstring(v, 3);
SQChar* serverPlaylist = sq_getstring(v, 4);
EServerVisibility_t eServerVisibility = static_cast<EServerVisibility_t>(sq_getinteger(v, 5));
if (!VALID_CHARSTAR(serverName) ||
!VALID_CHARSTAR(serverMapName) ||
!VALID_CHARSTAR(serverPlaylist))
{
return SQ_OK;
}
// Adjust browser settings.
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
g_pServerListManager->m_Server.m_svHostName = serverName;
g_pServerListManager->m_Server.m_svDescription = serverDescription;
g_pServerListManager->m_Server.m_svHostMap = serverMapName;
g_pServerListManager->m_Server.m_svPlaylist = serverPlaylist;
g_pServerListManager->m_ServerVisibility = eServerVisibility;
// Launch server.
g_pServerListManager->LaunchServer(g_pServer->IsActive());
return SQ_OK;
//v_SQVM_RaiseError(v, "\"%s\" is not supported on client builds.\n", "CreateServer");
//return SQ_ERROR;
}
//-----------------------------------------------------------------------------
// Purpose: shuts the server down and disconnects all clients
//-----------------------------------------------------------------------------
SQRESULT DestroyServer(HSQUIRRELVM v)
{
if (g_pHostState->m_bActiveGame)
g_pHostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN;
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: kicks a player by given name
//-----------------------------------------------------------------------------
SQRESULT KickPlayerByName(HSQUIRRELVM v)
{
SQChar* playerName = sq_getstring(v, 1);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->KickPlayerByName(playerName, reason);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: kicks a player by given handle or id
//-----------------------------------------------------------------------------
SQRESULT KickPlayerById(HSQUIRRELVM v)
{
SQChar* playerHandle = sq_getstring(v, 1);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->KickPlayerById(playerHandle, reason);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: bans a player by given name
//-----------------------------------------------------------------------------
SQRESULT BanPlayerByName(HSQUIRRELVM v)
{
SQChar* playerName = sq_getstring(v, 1);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->BanPlayerByName(playerName, reason);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: bans a player by given handle or id
//-----------------------------------------------------------------------------
SQRESULT BanPlayerById(HSQUIRRELVM v)
{
SQChar* playerHandle = sq_getstring(v, 1);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->BanPlayerById(playerHandle, reason);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: unbans a player by given nucleus id or ip address
//-----------------------------------------------------------------------------
SQRESULT UnbanPlayer(HSQUIRRELVM v)
{
SQChar* szCriteria = sq_getstring(v, 1);
g_pBanSystem->UnbanPlayer(szCriteria);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: gets the number of real players on this server
//-----------------------------------------------------------------------------
SQRESULT GetNumHumanPlayers(HSQUIRRELVM v)
{
sq_pushinteger(v, g_pServer->GetNumHumanPlayers());
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: gets the number of fake players on this server
//-----------------------------------------------------------------------------
SQRESULT GetNumFakeClients(HSQUIRRELVM v)
{
sq_pushinteger(v, g_pServer->GetNumFakeClients());
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: checks whether the server is active
//-----------------------------------------------------------------------------
SQRESULT IsServerActive(HSQUIRRELVM v)
{
bool isActive = g_pServer->IsActive();
sq_pushbool(v, isActive);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: checks whether this SDK build is a dedicated server
//-----------------------------------------------------------------------------
SQRESULT IsDedicated(HSQUIRRELVM v)
{
sq_pushbool(v, ::IsDedicated());
return SQ_OK;
}
}
}
//---------------------------------------------------------------------------------
// Purpose: registers script functions in SERVER context
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterServerFunctions(CSquirrelVM* s)
{
Script_RegisterCommonAbstractions(s);
Script_RegisterCoreServerFunctions(s);
Script_RegisterAdminPanelFunctions(s);
}
//---------------------------------------------------------------------------------
// Purpose: core server script functions
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterCoreServerFunctions(CSquirrelVM* s)
{
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, IsServerActive, "Returns whether the server is active", "bool", "");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, IsDedicated, "Returns whether this is a dedicated server", "bool", "");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, CreateServer, "Starts server with the specified settings", "void", "string, string, string, string, int");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, DestroyServer, "Shuts the local server down", "void", "");
}
//---------------------------------------------------------------------------------
// Purpose: admin panel script functions
// Input : *s -
//
// Ideally, these get dropped entirely in favor of remote functions. Currently,
// the s3 build only supports remote function calls from server to client/ui.
// Client/ui to server is all done through clientcommands.
//---------------------------------------------------------------------------------
void Script_RegisterAdminPanelFunctions(CSquirrelVM* s)
{
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, GetNumHumanPlayers, "Gets the number of human players on the server", "int", "");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, GetNumFakeClients, "Gets the number of bot players on the server", "int", "");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, KickPlayerByName, "Kicks a player from the server by name", "void", "string");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, KickPlayerById, "Kicks a player from the server by handle or nucleus id", "void", "string");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, BanPlayerByName, "Bans a player from the server by name", "void", "string");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, BanPlayerById, "Bans a player from the server by handle or nucleus id", "void", "string");
DEFINE_SERVER_SCRIPTFUNC_NAMED(s, UnbanPlayer, "Unbans a player from the server by nucleus id or ip address", "void", "string");
}

View File

@ -0,0 +1,34 @@
#ifndef VSCRIPT_SERVER_H
#define VSCRIPT_SERVER_H
namespace VScriptCode
{
namespace Server
{
SQRESULT CreateServer(HSQUIRRELVM v);
SQRESULT DestroyServer(HSQUIRRELVM v);
SQRESULT KickPlayerByName(HSQUIRRELVM v);
SQRESULT KickPlayerById(HSQUIRRELVM v);
SQRESULT BanPlayerByName(HSQUIRRELVM v);
SQRESULT BanPlayerById(HSQUIRRELVM v);
SQRESULT UnbanPlayer(HSQUIRRELVM v);
SQRESULT GetNumHumanPlayers(HSQUIRRELVM v);
SQRESULT GetNumFakeClients(HSQUIRRELVM v);
SQRESULT IsServerActive(HSQUIRRELVM v);
SQRESULT IsDedicated(HSQUIRRELVM v);
}
}
void Script_RegisterServerFunctions(CSquirrelVM* s);
void Script_RegisterCoreServerFunctions(CSquirrelVM* s);
void Script_RegisterAdminPanelFunctions(CSquirrelVM* s);
#define DEFINE_SERVER_SCRIPTFUNC_NAMED(s, functionName, helpString, \
returnType, parameters) \
s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \
helpString, returnType, parameters, VScriptCode::Server::##functionName); \
#endif // VSCRIPT_SERVER_H

View File

@ -1,5 +1,7 @@
#ifndef GAME_WEAPON_BOLT_H
#define GAME_WEAPON_BOLT_H
#include <game/shared/shared_classnames.h>
#ifndef CLIENT_DLL
#include <game/server/baseentity.h>
#include <game/server/player.h>

View File

@ -13,12 +13,12 @@
// Hacky macros to allow shared code to work without even worse macro-izing
#if defined( CLIENT_DLL )
/* // TODO: Uncomment if required for client.
// Uncomment if required for client.
#define CBaseEntity C_BaseEntity
#define CBaseCombatCharacter C_BaseCombatCharacter
#define CBaseAnimating C_BaseAnimating
#define CBasePlayer C_BasePlayer
*/
#define CPlayer C_Player
#endif

View File

@ -52,7 +52,7 @@ int ReadUserCmd(bf_read* buf, CUserCmd* move, CUserCmd* from)
// Checks are only required if cycleslot is valid; see 'CPlayer::UpdateWeaponSlots'.
if (move->cycleslot != WEAPON_INVENTORY_SLOT_INVALID)
{
const bool dualWieldEnabled = sv_usercmd_dualwield_enable->GetBool();
const bool dualWieldEnabled = usercmd_dualwield_enable->GetBool();
// Client could instruct the server to switch cycle slots for inventory
// weapons, however, the client could also cycle to the dual wield slots.

View File

@ -5,28 +5,6 @@
//===========================================================================//
#include "core/stdafx.h"
#include "util_shared.h"
#ifndef CLIENT_DLL
#include "game/server/player.h"
#include "game/server/gameinterface.h"
#endif // !CLIENT_DLL
#ifndef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: returns the player instance by edict
//-----------------------------------------------------------------------------
CPlayer* UTIL_PlayerByIndex(int nIndex)
{
if (nIndex < 1 || nIndex >(*g_pGlobals)->m_nMaxClients || nIndex == FL_EDICT_INVALID)
{
assert(0);
return nullptr;
}
// !TODO: Improve this!!!
CPlayer* pPlayer = reinterpret_cast<CPlayer*>((*g_pGlobals)->m_pEdicts[nIndex + 0x7808]);
return pPlayer;
}
#endif // CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: returns the class name, script name, and edict of the entity

View File

@ -5,16 +5,9 @@
//===========================================================================//
#ifndef UTIL_SHARED_H
#define UTIL_SHARED_H
#ifndef CLIENT_DLL
#include "game/server/player.h"
#endif
#include "public/engine/IEngineTrace.h"
class CTraceFilterSimple;
#ifndef CLIENT_DLL
CPlayer* UTIL_PlayerByIndex(int nIndex);
#endif // CLIENT_DLL
const char* UTIL_GetEntityScriptInfo(CBaseEntity* pEnt);
inline CMemory p_UTIL_GetEntityScriptInfo;
@ -46,7 +39,6 @@ private:
int m_traceType;
};
///////////////////////////////////////////////////////////////////////////////
class VUtil_Shared : public IDetour
{

View File

@ -6,41 +6,22 @@
//
// Create functions here under the target VM namespace. If the function has to
// be registered for 2 or more VM's, put them under the 'SHARED' namespace.
// Ifdef them out for 'DEDICATED' / 'CLIENT_DLL' if the target VM's do not
// Ifdef them out for 'SERVER_DLL' / 'CLIENT_DLL' if the target VM's do not
// include 'SERVER' / 'CLIENT'.
//
//=============================================================================//
#include "core/stdafx.h"
#include "vpc/keyvalues.h"
#ifndef CLIENT_DLL
#include "engine/server/server.h"
#endif // CLIENT_DLL
#include "engine/client/cl_main.h"
#include "engine/cmodel_bsp.h"
#include "engine/host_state.h"
#include "networksystem/pylon.h"
#ifndef CLIENT_DLL
#include "networksystem/bansystem.h"
#endif // !CLIENT_DLL
#ifndef DEDICATED
#include "networksystem/listmanager.h"
#endif // !DEDICATED
#include "vscript_shared.h"
#include "vscript/languages/squirrel_re/include/sqvm.h"
#include "vscript_shared.h"
namespace VScriptCode
{
namespace SHARED
namespace Shared
{
//-----------------------------------------------------------------------------
// Purpose: SDK test and example body
//-----------------------------------------------------------------------------
SQRESULT SDKNativeTest(HSQUIRRELVM v)
{
// Function code goes here.
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: expose SDK version to the VScript API
//-----------------------------------------------------------------------------
@ -89,538 +70,27 @@ namespace VScriptCode
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: checks whether the server is active
//-----------------------------------------------------------------------------
SQRESULT IsServerActive(HSQUIRRELVM v)
{
bool isActive = false;
#ifndef CLIENT_DLL
isActive = g_pServer->IsActive();
#endif // !CLIENT_DLL
sq_pushbool(v, isActive);
return SQ_OK;
}
#ifndef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: kicks a player by given name
//-----------------------------------------------------------------------------
SQRESULT KickPlayerByName(HSQUIRRELVM v)
{
SQChar* playerName = sq_getstring(v, 1);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->KickPlayerByName(playerName, reason);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: kicks a player by given handle or id
//-----------------------------------------------------------------------------
SQRESULT KickPlayerById(HSQUIRRELVM v)
{
SQChar* playerHandle = sq_getstring(v, 1);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->KickPlayerById(playerHandle, reason);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: bans a player by given name
//-----------------------------------------------------------------------------
SQRESULT BanPlayerByName(HSQUIRRELVM v)
{
SQChar* playerName = sq_getstring(v, 1);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->BanPlayerByName(playerName, reason);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: bans a player by given handle or id
//-----------------------------------------------------------------------------
SQRESULT BanPlayerById(HSQUIRRELVM v)
{
SQChar* playerHandle = sq_getstring(v, 1);
SQChar* reason = sq_getstring(v, 2);
// Discard empty strings, this will use the default message instead.
if (!VALID_CHARSTAR(reason))
reason = nullptr;
g_pBanSystem->BanPlayerById(playerHandle, reason);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: unbans a player by given nucleus id or ip address
//-----------------------------------------------------------------------------
SQRESULT UnbanPlayer(HSQUIRRELVM v)
{
SQChar* szCriteria = sq_getstring(v, 1);
g_pBanSystem->UnbanPlayer(szCriteria);
return SQ_OK;
}
#endif // !CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: shutdown local game (host only)
//-----------------------------------------------------------------------------
SQRESULT ShutdownHostGame(HSQUIRRELVM v)
{
if (g_pHostState->m_bActiveGame)
g_pHostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN;
return SQ_OK;
}
#ifndef DEDICATED
//-----------------------------------------------------------------------------
// Purpose: checks whether this SDK build is a client dll
//-----------------------------------------------------------------------------
SQRESULT IsClientDLL(HSQUIRRELVM v)
{
#ifdef CLIENT_DLL
constexpr SQBool bClientOnly = true;
#else
constexpr SQBool bClientOnly = false;
#endif
sq_pushbool(v, bClientOnly);
return SQ_OK;
}
#endif // !DEDICATED
}
#ifndef CLIENT_DLL
namespace SERVER
{
//-----------------------------------------------------------------------------
// Purpose: gets the number of real players on this server
//-----------------------------------------------------------------------------
SQRESULT GetNumHumanPlayers(HSQUIRRELVM v)
{
sq_pushinteger(v, g_pServer->GetNumHumanPlayers());
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: gets the number of fake players on this server
//-----------------------------------------------------------------------------
SQRESULT GetNumFakeClients(HSQUIRRELVM v)
{
sq_pushinteger(v, g_pServer->GetNumFakeClients());
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: checks whether this SDK build is a dedicated server
//-----------------------------------------------------------------------------
SQRESULT IsDedicated(HSQUIRRELVM v)
{
sq_pushbool(v, ::IsDedicated());
return SQ_OK;
}
}
#endif // !CLIENT_DLL
#ifndef DEDICATED
namespace CLIENT
{
}
namespace UI
{
//-----------------------------------------------------------------------------
// Purpose: refreshes the server list
//-----------------------------------------------------------------------------
SQRESULT RefreshServerCount(HSQUIRRELVM v)
{
string serverMessage; // Refresh list.
size_t iCount = g_pServerListManager->RefreshServerList(serverMessage);
sq_pushinteger(v, static_cast<SQInteger>(iCount));
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current name from serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerName(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
if (iServer >= iCount)
{
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
return SQ_ERROR;
}
const string& serverName = g_pServerListManager->m_vServerList[iServer].m_svHostName;
sq_pushstring(v, serverName.c_str(), -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current description from serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerDescription(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
if (iServer >= iCount)
{
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
return SQ_ERROR;
}
const string& serverDescription = g_pServerListManager->m_vServerList[iServer].m_svDescription;
sq_pushstring(v, serverDescription.c_str(), -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current map via serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerMap(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
if (iServer >= iCount)
{
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
return SQ_ERROR;
}
const string& svServerMapName = g_pServerListManager->m_vServerList[iServer].m_svHostMap;
sq_pushstring(v, svServerMapName.c_str(), -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current playlist via serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerPlaylist(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
if (iServer >= iCount)
{
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
return SQ_ERROR;
}
const string& serverPlaylist = g_pServerListManager->m_vServerList[iServer].m_svPlaylist;
sq_pushstring(v, serverPlaylist.c_str(), -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current player count via serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerCurrentPlayers(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
if (iServer >= iCount)
{
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
return SQ_ERROR;
}
const string& playerCount = g_pServerListManager->m_vServerList[iServer].m_svPlayerCount.c_str();
sq_pushinteger(v, strtol(playerCount.c_str(), NULL, NULL));
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get server's current player count via serverlist index
//-----------------------------------------------------------------------------
SQRESULT GetServerMaxPlayers(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
if (iServer >= iCount)
{
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
return SQ_ERROR;
}
const string& maxPlayers = g_pServerListManager->m_vServerList[iServer].m_svMaxPlayers;
sq_pushinteger(v, strtol(maxPlayers.c_str(), NULL, NULL));
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get current server count from pylon
//-----------------------------------------------------------------------------
SQRESULT GetServerCount(HSQUIRRELVM v)
{
size_t iCount = g_pServerListManager->m_vServerList.size();
sq_pushinteger(v, static_cast<SQInteger>(iCount));
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get promo data for serverbrowser panels
//-----------------------------------------------------------------------------
SQRESULT GetPromoData(HSQUIRRELVM v)
{
enum class R5RPromoData : SQInteger
{
PromoLargeTitle,
PromoLargeDesc,
PromoLeftTitle,
PromoLeftDesc,
PromoRightTitle,
PromoRightDesc
};
R5RPromoData ePromoIndex = static_cast<R5RPromoData>(sq_getinteger(v, 1));
const char* pszPromoKey;
switch (ePromoIndex)
{
case R5RPromoData::PromoLargeTitle:
{
pszPromoKey = "#PROMO_LARGE_TITLE";
break;
}
case R5RPromoData::PromoLargeDesc:
{
pszPromoKey = "#PROMO_LARGE_DESCRIPTION";
break;
}
case R5RPromoData::PromoLeftTitle:
{
pszPromoKey = "#PROMO_LEFT_TITLE";
break;
}
case R5RPromoData::PromoLeftDesc:
{
pszPromoKey = "#PROMO_LEFT_DESCRIPTION";
break;
}
case R5RPromoData::PromoRightTitle:
{
pszPromoKey = "#PROMO_RIGHT_TITLE";
break;
}
case R5RPromoData::PromoRightDesc:
{
pszPromoKey = "#PROMO_RIGHT_DESCRIPTION";
break;
}
default:
{
pszPromoKey = "#PROMO_SDK_ERROR";
break;
}
}
sq_pushstring(v, pszPromoKey, -1);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: create server via native serverbrowser entries
// TODO: return a boolean on failure instead of raising an error, so we could
// determine from scripts whether or not to spin a local server, or connect
// to a dedicated server (for disconnecting and loading the lobby, for example)
//-----------------------------------------------------------------------------
SQRESULT CreateServer(HSQUIRRELVM v)
{
#ifndef CLIENT_DLL
SQChar* serverName = sq_getstring(v, 1);
SQChar* serverDescription = sq_getstring(v, 2);
SQChar* serverMapName = sq_getstring(v, 3);
SQChar* serverPlaylist = sq_getstring(v, 4);
EServerVisibility_t eServerVisibility = static_cast<EServerVisibility_t>(sq_getinteger(v, 5));
if (!VALID_CHARSTAR(serverName) ||
!VALID_CHARSTAR(serverMapName) ||
!VALID_CHARSTAR(serverPlaylist))
{
return SQ_OK;
}
// Adjust browser settings.
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
g_pServerListManager->m_Server.m_svHostName = serverName;
g_pServerListManager->m_Server.m_svDescription = serverDescription;
g_pServerListManager->m_Server.m_svHostMap = serverMapName;
g_pServerListManager->m_Server.m_svPlaylist = serverPlaylist;
g_pServerListManager->m_ServerVisibility = eServerVisibility;
// Launch server.
g_pServerListManager->LaunchServer();
return SQ_OK;
#else
v_SQVM_RaiseError(v, "\"%s\" is not supported for client builds.\n", "CreateServer");
return SQ_ERROR;
#endif
}
//-----------------------------------------------------------------------------
// Purpose: connect to server from native server browser entries
//-----------------------------------------------------------------------------
SQRESULT ConnectToServer(HSQUIRRELVM v)
{
SQChar* ipAddress = sq_getstring(v, 1);
SQChar* cryptoKey = sq_getstring(v, 2);
if (!VALID_CHARSTAR(ipAddress) || VALID_CHARSTAR(cryptoKey))
return SQ_OK;
DevMsg(eDLL_T::UI, "Connecting to server with ip address '%s' and encryption key '%s'\n", ipAddress, cryptoKey);
g_pServerListManager->ConnectToServer(ipAddress, cryptoKey);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: set netchannel encryption key and connect to server
//-----------------------------------------------------------------------------
SQRESULT ConnectToListedServer(HSQUIRRELVM v)
{
std::lock_guard<std::mutex> l(g_pServerListManager->m_Mutex);
SQInteger iServer = sq_getinteger(v, 1);
SQInteger iCount = static_cast<SQInteger>(g_pServerListManager->m_vServerList.size());
if (iServer >= iCount)
{
v_SQVM_RaiseError(v, "Index must be less than %i.\n", iCount);
return SQ_ERROR;
}
const NetGameServer_t& gameServer = g_pServerListManager->m_vServerList[iServer];
g_pServerListManager->ConnectToServer(gameServer.m_svIpAddress, gameServer.m_svGamePort,
gameServer.m_svEncryptionKey);
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: request token from pylon and join server with result.
//-----------------------------------------------------------------------------
SQRESULT ConnectToHiddenServer(HSQUIRRELVM v)
{
SQChar* privateToken = sq_getstring(v, 1);
if (!VALID_CHARSTAR(privateToken))
return SQ_OK;
string hiddenServerRequestMessage;
NetGameServer_t netListing;
bool result = g_pMasterServer->GetServerByToken(netListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
if (result)
{
g_pServerListManager->ConnectToServer(netListing.m_svIpAddress, netListing.m_svGamePort, netListing.m_svEncryptionKey);
}
else
{
Warning(eDLL_T::UI, "Failed to connect to private server: %s\n", hiddenServerRequestMessage.c_str());
}
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: get response from private server request
//-----------------------------------------------------------------------------
SQRESULT GetHiddenServerName(HSQUIRRELVM v)
{
SQChar* privateToken = sq_getstring(v, 1);
if (!VALID_CHARSTAR(privateToken))
return SQ_OK;
string hiddenServerRequestMessage;
NetGameServer_t serverListing;
bool result = g_pMasterServer->GetServerByToken(serverListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
if (!result)
{
if (hiddenServerRequestMessage.empty())
{
sq_pushstring(v, "Request failed", -1);
}
else
{
hiddenServerRequestMessage = Format("Request failed: %s", hiddenServerRequestMessage.c_str());
sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1);
}
return SQ_OK;
}
if (serverListing.m_svHostName.empty())
{
if (hiddenServerRequestMessage.empty())
{
hiddenServerRequestMessage = Format("Server listing empty");
}
else
{
hiddenServerRequestMessage = Format("Server listing empty: %s", hiddenServerRequestMessage.c_str());
}
sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1);
}
else
{
hiddenServerRequestMessage = Format("Found server: %s", serverListing.m_svHostName.c_str());
sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1);
}
return SQ_OK;
}
}
#endif // !DEDICATED
}
}
//---------------------------------------------------------------------------------
// Purpose: common script abstractions
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterCommonAbstractions(CSquirrelVM* s)
{
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetSDKVersion, "Gets the SDK version as a string", "string", "");
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailableMaps, "Gets an array of all available maps", "array< string >", "");
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailablePlaylists, "Gets an array of all available playlists", "array< string >", "");
}
//---------------------------------------------------------------------------------
// Purpose: listen server constants (!!! only call on builds containing a listen server !!!)
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterListenServerConstants(CSquirrelVM* s)
{
const SQBool hasListenServer = !IsClientDLL();
s->RegisterConstant("LISTEN_SERVER", hasListenServer);
}

View File

@ -1,6 +1,7 @@
#ifndef VSCRIPT_SHARED_H
#define VSCRIPT_SHARED_H
#include "vscript/languages/squirrel_re/include/squirrel.h"
#include "vscript/languages/squirrel_re/vsquirrel.h"
inline CMemory p_Script_Remote_BeginRegisteringFunctions;
inline void*(*Script_Remote_BeginRegisteringFunctions)(void);
@ -8,66 +9,27 @@ inline void*(*Script_Remote_BeginRegisteringFunctions)(void);
inline CMemory p_RestoreRemoteChecksumsFromSaveGame;
inline void*(*RestoreRemoteChecksumsFromSaveGame)(void* a1, void* a2);
#ifndef CLIENT_DLL
inline uint32_t* g_nServerRemoteChecksum = nullptr;
#endif // !CLIENT_DLL
#ifndef DEDICATED
inline uint32_t* g_nClientRemoteChecksum = nullptr;
#endif // !DEDICATED
namespace VScriptCode
{
namespace SHARED
namespace Shared
{
SQRESULT SDKNativeTest(HSQUIRRELVM v);
SQRESULT GetSDKVersion(HSQUIRRELVM v);
SQRESULT GetAvailableMaps(HSQUIRRELVM v);
SQRESULT GetAvailablePlaylists(HSQUIRRELVM v);
SQRESULT ShutdownHostGame(HSQUIRRELVM v);
#ifndef DEDICATED
SQRESULT IsClientDLL(HSQUIRRELVM v);
#endif // !DEDICATED
SQRESULT IsServerActive(HSQUIRRELVM v);
#ifndef CLIENT_DLL
SQRESULT KickPlayerByName(HSQUIRRELVM v);
SQRESULT KickPlayerById(HSQUIRRELVM v);
SQRESULT BanPlayerByName(HSQUIRRELVM v);
SQRESULT BanPlayerById(HSQUIRRELVM v);
SQRESULT UnbanPlayer(HSQUIRRELVM v);
#endif // !CLIENT_DLL
}
#ifndef CLIENT_DLL
namespace SERVER
{
SQRESULT GetNumHumanPlayers(HSQUIRRELVM v);
SQRESULT GetNumFakeClients(HSQUIRRELVM v);
SQRESULT IsDedicated(HSQUIRRELVM v);
}
#endif // !CLIENT_DLL
#ifndef DEDICATED
namespace CLIENT
{
}
namespace UI
{
SQRESULT RefreshServerCount(HSQUIRRELVM v);
SQRESULT GetServerName(HSQUIRRELVM v);
SQRESULT GetServerDescription(HSQUIRRELVM v);
SQRESULT GetServerMap(HSQUIRRELVM v);
SQRESULT GetServerPlaylist(HSQUIRRELVM v);
SQRESULT GetServerCurrentPlayers(HSQUIRRELVM v);
SQRESULT GetServerMaxPlayers(HSQUIRRELVM v);
SQRESULT GetServerCount(HSQUIRRELVM v);
SQRESULT GetPromoData(HSQUIRRELVM v);
SQRESULT ConnectToListedServer(HSQUIRRELVM v);
SQRESULT CreateServer(HSQUIRRELVM v);
SQRESULT ConnectToHiddenServer(HSQUIRRELVM v);
SQRESULT GetHiddenServerName(HSQUIRRELVM v);
SQRESULT ConnectToServer(HSQUIRRELVM v);
}
#endif // !DEDICATED
}
void Script_RegisterCommonAbstractions(CSquirrelVM* s);
void Script_RegisterListenServerConstants(CSquirrelVM* s);
#define DEFINE_SHARED_SCRIPTFUNC_NAMED(s, functionName, helpString, \
returnType, parameters) \
s->RegisterFunction(#functionName, MKSTRING(Script_##functionName), \
helpString, returnType, parameters, VScriptCode::Shared::##functionName);\
///////////////////////////////////////////////////////////////////////////////
class VScriptShared : public IDetour
{
@ -75,12 +37,8 @@ class VScriptShared : public IDetour
{
LogFunAdr("Remote_BeginRegisteringFunctions", p_Script_Remote_BeginRegisteringFunctions.GetPtr());
LogFunAdr("RestoreRemoteChecksumsFromSaveGame", p_RestoreRemoteChecksumsFromSaveGame.GetPtr());
#ifndef CLIENT_DLL
LogVarAdr("g_nServerRemoteChecksum", reinterpret_cast<uintptr_t>(g_nServerRemoteChecksum));
#endif // !CLIENT_DLL
#ifndef DEDICATED
LogVarAdr("g_nClientRemoteChecksum", reinterpret_cast<uintptr_t>(g_nClientRemoteChecksum));
#endif // !DEDICATED
}
virtual void GetFun(void) const
{
@ -92,12 +50,8 @@ class VScriptShared : public IDetour
}
virtual void GetVar(void) const
{
#ifndef CLIENT_DLL
g_nServerRemoteChecksum = p_RestoreRemoteChecksumsFromSaveGame.Offset(0x1C0).FindPatternSelf("48 8D 15", CMemory::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x3, 0x7).RCast<uint32_t*>();
#endif // !CLIENT_DLL
#ifndef DEDICATED
g_nClientRemoteChecksum = p_Script_Remote_BeginRegisteringFunctions.Offset(0x0).FindPatternSelf("89 05", CMemory::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x2, 0x6).RCast<uint32_t*>();
#endif // !DEDICATED
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }

View File

@ -559,6 +559,9 @@ void CBrowser::HostPanel(void)
}
ImGui::Spacing();
const bool bServerActive = g_pServer->IsActive();
if (!g_pHostState->m_bActiveGame)
{
if (ImGui::Button("Start server", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
@ -568,7 +571,7 @@ void CBrowser::HostPanel(void)
bool bEnforceField = g_pServerListManager->m_ServerVisibility == EServerVisibility_t::OFFLINE ? true : !g_pServerListManager->m_Server.m_svHostName.empty();
if (bEnforceField && !g_pServerListManager->m_Server.m_svPlaylist.empty() && !g_pServerListManager->m_Server.m_svHostMap.empty())
{
g_pServerListManager->LaunchServer(); // Launch server.
g_pServerListManager->LaunchServer(bServerActive); // Launch server.
}
else
{
@ -622,7 +625,7 @@ void CBrowser::HostPanel(void)
{
if (!g_pServerListManager->m_Server.m_svHostMap.empty())
{
g_pServerListManager->LaunchServer();
g_pServerListManager->LaunchServer(bServerActive);
}
else
{
@ -631,7 +634,7 @@ void CBrowser::HostPanel(void)
}
}
if (g_pServer->IsActive())
if (bServerActive)
{
ImGui::Spacing();
ImGui::Separator();

View File

@ -32,8 +32,6 @@ int LauncherMain(HINSTANCE hInstance)
// its own -game parameter, which would supersede the one we really want if we didn't intercede here.
void RemoveSpuriousGameParameters()
{
AppendSDKParametersPreInit();
// Find the last -game parameter.
int nGameArgs = 0;
char lastGameArg[MAX_PATH];
@ -56,29 +54,6 @@ void RemoveSpuriousGameParameters()
}
#endif
// Append required command line parameters.
// This avoids having all these in the startup configuration files
// as all there are required to run the game with the game sdk.
void AppendSDKParametersPreInit()
{
const bool bDedicated = IsDedicated();
if (bDedicated)
{
CommandLine()->AppendParm("-collate", "");
CommandLine()->AppendParm("-multiple", "");
CommandLine()->AppendParm("-noorigin", "");
CommandLine()->AppendParm("-nodiscord", "");
CommandLine()->AppendParm("-noshaderapi", "");
CommandLine()->AppendParm("-nobakedparticles", "");
CommandLine()->AppendParm("-novid", "");
CommandLine()->AppendParm("-nomenuvid", "");
CommandLine()->AppendParm("-nosound", "");
CommandLine()->AppendParm("-nomouse", "");
CommandLine()->AppendParm("-nojoy", "");
CommandLine()->AppendParm("-nosendtable", "");
}
}
const char* ExitCodeToString(int nCode)
{
switch (nCode)

View File

@ -12,7 +12,6 @@ inline CMemory p_RemoveSpuriousGameParameters;
inline void*(*v_RemoveSpuriousGameParameters)(void);
#endif // !GAMEDLL_S0 || !GAMEDLL_S1
void AppendSDKParametersPreInit();
const char* ExitCodeToString(int nCode);
///////////////////////////////////////////////////////////////////////////////

View File

@ -47,7 +47,7 @@ static int (*v_WinMain)(HINSTANCE, HINSTANCE, LPSTR, int) = nullptr;
//-----------------------------------------------------------------------------
// Purpose: Terminates the process with an error when called
//-----------------------------------------------------------------------------
void FatalError(const char* fmt, ...)
static void FatalError(const char* fmt, ...)
{
va_list vArgs;
va_start(vArgs, fmt);
@ -65,7 +65,7 @@ void FatalError(const char* fmt, ...)
//-----------------------------------------------------------------------------
// Purpose: Loads the SDK module
//-----------------------------------------------------------------------------
void InitGameSDK(const LPSTR lpCmdLine)
static void InitGameSDK(const LPSTR lpCmdLine)
{
if (V_strstr(lpCmdLine, "-noworkerdll"))
return;
@ -78,13 +78,22 @@ void InitGameSDK(const LPSTR lpCmdLine)
// Prune the path.
const char* pModuleName = strrchr(moduleName, '\\') + 1;
const bool bDedicated = V_stricmp(pModuleName, SERVER_GAME_DLL) == NULL;
// The dedicated server has its own SDK module,
// so we need to check whether we are running
// the base game or the dedicated server.
if (V_stricmp(pModuleName, MAIN_GAME_DLL) == NULL)
s_SdkModule = LoadLibraryA(MAIN_WORKER_DLL);
else if (V_stricmp(pModuleName, SERVER_GAME_DLL) == NULL)
if (!bDedicated)
{
// Load the client dll if '-noserverdll' is passed,
// as this command lime parameter prevents the
// server dll from initializing in the engine.
if (V_strstr(lpCmdLine, "-noserverdll"))
s_SdkModule = LoadLibraryA(CLIENT_WORKER_DLL);
else
s_SdkModule = LoadLibraryA(MAIN_WORKER_DLL);
}
else
s_SdkModule = LoadLibraryA(SERVER_WORKER_DLL);
if (!s_SdkModule)
@ -103,6 +112,39 @@ int WINAPI hWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
return v_WinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
}
//-----------------------------------------------------------------------------
// Purpose: hooks the entry point
//-----------------------------------------------------------------------------
static void AttachEP()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&v_WinMain, &hWinMain);
HRESULT hr = DetourTransactionCommit();
if (hr != NO_ERROR) // Failed to hook into the process, terminate...
{
Assert(0);
FatalError("Failed to detour process: error code = %08x\n", hr);
}
}
//-----------------------------------------------------------------------------
// Purpose: unhooks the entry point
//-----------------------------------------------------------------------------
static void DetachEP()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&v_WinMain, &hWinMain);
HRESULT hr = DetourTransactionCommit();
Assert(hr != NO_ERROR);
NOTE_UNUSED(hr);
}
//-----------------------------------------------------------------------------
// Purpose: APIENTRY
//-----------------------------------------------------------------------------
@ -120,36 +162,16 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
v_WinMain = CModule::GetExportedSymbol((QWORD)s_DosHeader, "WinMain")
.RCast<int (*)(HINSTANCE, HINSTANCE, LPSTR, int)>();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&v_WinMain, &hWinMain);
HRESULT hr = DetourTransactionCommit();
if (hr != NO_ERROR) // Failed to hook into the process, terminate...
{
Assert(0);
FatalError("Failed to detour process: error code = %08x\n", hr);
}
AttachEP();
break;
}
case DLL_PROCESS_DETACH:
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&v_WinMain, &hWinMain);
HRESULT hr = DetourTransactionCommit();
Assert(hr != NO_ERROR);
NOTE_UNUSED(hr);
if (s_SdkModule)
FreeLibrary(s_SdkModule);
DetachEP();
break;
}
}

View File

@ -55,13 +55,13 @@ void CServerListManager::ClearServerList(void)
//-----------------------------------------------------------------------------
// Purpose: Launch server with given parameters
//-----------------------------------------------------------------------------
void CServerListManager::LaunchServer(void) const
void CServerListManager::LaunchServer(const bool bChangeLevel) const
{
if (!ThreadInMainThread())
{
g_TaskScheduler->Dispatch([this]()
g_TaskScheduler->Dispatch([this, bChangeLevel]()
{
this->LaunchServer();
this->LaunchServer(bChangeLevel);
}, 0);
return;
}
@ -77,7 +77,7 @@ void CServerListManager::LaunchServer(void) const
KeyValues::ParsePlaylists(m_Server.m_svPlaylist.c_str());
mp_gamemode->SetValue(m_Server.m_svPlaylist.c_str());
ProcessCommand(Format("%s \"%s\"", g_pServer->IsActive() ? "changelevel" : "map", m_Server.m_svHostMap.c_str()).c_str());
ProcessCommand(Format("%s \"%s\"", bChangeLevel ? "changelevel" : "map", m_Server.m_svHostMap.c_str()).c_str());
}
//-----------------------------------------------------------------------------

View File

@ -23,7 +23,7 @@ public:
size_t RefreshServerList(string& svMessage);
void ClearServerList(void);
void LaunchServer(void) const;
void LaunchServer(const bool bChangeLevel) const;
void ConnectToServer(const string& svIp, const string& svPort, const string& svNetKey) const;
void ConnectToServer(const string& svServer, const string& svNetKey) const;

View File

@ -187,44 +187,6 @@ bool CPylon::PostServerHost(string& outMessage, string& outToken,
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Send keep alive request to Pylon Master Server.
// Input : &netGameServer -
// Output : Returns true on success, false otherwise.
//-----------------------------------------------------------------------------
bool CPylon::KeepAlive(const NetGameServer_t& netGameServer)
{
if (!g_pServer->IsActive() || !sv_pylonVisibility->GetBool()) // Check for active game.
{
return false;
}
string errorMsg;
string hostToken;
const bool result = PostServerHost(errorMsg, hostToken, netGameServer);
if (!result)
{
if (!errorMsg.empty() && m_ErrorMsg.compare(errorMsg) != NULL)
{
m_ErrorMsg = errorMsg;
Error(eDLL_T::SERVER, NO_ERROR, "%s\n", errorMsg.c_str());
}
}
else // Attempt to log the token, if there is one.
{
if (!hostToken.empty() && m_Token.compare(hostToken) != NULL)
{
m_Token = hostToken;
DevMsg(eDLL_T::SERVER, "Published server with token: %s'%s%s%s'\n",
g_svReset, g_svGreyB,
hostToken.c_str(), g_svReset);
}
}
return result;
}
//-----------------------------------------------------------------------------
// Purpose: Checks a list of clients for their banned status.
// Input : &inBannedVec -

View File

@ -20,7 +20,11 @@ public:
bool SendRequest(const char* endpoint, const nlohmann::json& requestJson, nlohmann::json& responseJson, string& outMessage, CURLINFO& status, const char* errorText = nullptr) const;
bool QueryServer(const char* endpoint, const char* request, string& outResponse, string& outMessage, CURLINFO& outStatus) const;
bool KeepAlive(const NetGameServer_t& netGameServer);
inline const string& GetCurrentToken() const { return m_Token; }
inline const string& GetCurrentError() const { return m_ErrorMsg; }
inline void SetCurrentToken(const string& token) { m_Token = token; }
inline void SetCurrentError(const string& error) { m_ErrorMsg = error; }
private:
string m_Token;

View File

@ -1187,8 +1187,8 @@ eLaunchMode CSurface::BuildParameter(string& svParameters)
}
case eMode::CLIENT:
{
AppendParameterInternal(svParameters, "-noworkerdll"); // This prevents init of worker dll
//(this dll is always imported, but we want client.dll to do the work instead).
// Tells the loader module to only load the client dll.
AppendParameterInternal(svParameters, "-noserverdll");
// GAME ###############################################################
if (this->m_DeveloperToggle->Checked())

View File

@ -882,9 +882,12 @@ template<
LONG DetourAttach(_Inout_ T *ppPointer,
_In_ T pDetour) noexcept
{
return DetourAttach(
LONG result = DetourAttach(
reinterpret_cast<void**>(ppPointer),
reinterpret_cast<void*>(pDetour));
assert(result == NO_ERROR);
return result;
}
template<
@ -896,12 +899,15 @@ LONG DetourAttachEx(_Inout_ T *ppPointer,
_Out_opt_ T *ppRealTarget,
_Out_opt_ T *ppRealDetour) noexcept
{
return DetourAttachEx(
LONG result = DetourAttachEx(
reinterpret_cast<void**>(ppPointer),
reinterpret_cast<void*>(pDetour),
ppRealTrampoline,
reinterpret_cast<void**>(ppRealTarget),
reinterpret_cast<void**>(ppRealDetour));
assert(result == NO_ERROR);
return result;
}
template<
@ -910,9 +916,12 @@ template<
LONG DetourDetach(_Inout_ T *ppPointer,
_In_ T pDetour) noexcept
{
return DetourDetach(
LONG result = DetourDetach(
reinterpret_cast<void**>(ppPointer),
reinterpret_cast<void*>(pDetour));
assert(result == NO_ERROR);
return result;
}
#endif // __cplusplus >= 201103L || _MSVC_LANG >= 201103L

View File

@ -8,6 +8,18 @@
#include "pluginsystem/modsystem.h"
#include "vsquirrel.h"
// Callbacks for registering abstracted script functions.
void(*ServerScriptRegister_Callback)(CSquirrelVM* s) = nullptr;
void(*ClientScriptRegister_Callback)(CSquirrelVM* s) = nullptr;
void(*UiScriptRegister_Callback)(CSquirrelVM* s) = nullptr;
// Admin panel functions, NULL on client only builds.
void(*CoreServerScriptRegister_Callback)(CSquirrelVM* s) = nullptr;
void(*AdminPanelScriptRegister_Callback)(CSquirrelVM* s) = nullptr;
// Registering constants in scripts.
void(*ScriptConstantRegister_Callback)(CSquirrelVM* s) = nullptr;
//---------------------------------------------------------------------------------
// Purpose: Initialises a Squirrel VM instance
// Output : True on success, false on failure
@ -24,22 +36,32 @@ SQBool CSquirrelVM::Init(CSquirrelVM* s, SQCONTEXT context, SQFloat curTime)
switch (context)
{
#ifndef CLIENT_DLL
case SQCONTEXT::SERVER:
g_pServerScript = s;
Script_RegisterServerFunctions(s);
if (ServerScriptRegister_Callback)
ServerScriptRegister_Callback(s);
break;
#endif
#ifndef DEDICATED
case SQCONTEXT::CLIENT:
g_pClientScript = s;
Script_RegisterClientFunctions(s);
if (ClientScriptRegister_Callback)
ClientScriptRegister_Callback(s);
break;
case SQCONTEXT::UI:
g_pUIScript = s;
Script_RegisterUIFunctions(s);
if (UiScriptRegister_Callback)
UiScriptRegister_Callback(s);
if (CoreServerScriptRegister_Callback)
CoreServerScriptRegister_Callback(s);
if (AdminPanelScriptRegister_Callback)
AdminPanelScriptRegister_Callback(s);
break;
#endif
}
return true;
@ -56,6 +78,11 @@ SQBool CSquirrelVM::DestroySignalEntryListHead(CSquirrelVM* s, HSQUIRRELVM v, SQ
{
SQBool result = v_CSquirrelVM_DestroySignalEntryListHead(s, v, f);
s->RegisterConstant("DEVELOPER", developer->GetInt());
// Must have one.
Assert(ScriptConstantRegister_Callback);
ScriptConstantRegister_Callback(s);
return result;
}
@ -99,21 +126,17 @@ void CSquirrelVM::SetAsCompiler(RSON::Node_t* rson)
const SQCONTEXT context = GetContext();
switch (context)
{
#ifndef CLIENT_DLL
case SQCONTEXT::SERVER:
{
v_Script_SetServerPrecompiler(context, rson);
break;
}
#endif
#ifndef DEDICATED
case SQCONTEXT::CLIENT:
case SQCONTEXT::UI:
{
v_Script_SetClientPrecompiler(context, rson);
break;
}
#endif
}
}
@ -176,21 +199,17 @@ void CSquirrelVM::CompileModScripts()
switch (GetVM()->GetContext())
{
#ifndef CLIENT_DLL
case SQCONTEXT::SERVER:
{
v_CSquirrelVM_PrecompileServerScripts(this, GetContext(), (char**)scriptPathArray, scriptCount);
break;
}
#endif
#ifndef DEDICATED
case SQCONTEXT::CLIENT:
case SQCONTEXT::UI:
{
v_CSquirrelVM_PrecompileClientScripts(this, GetContext(), (char**)scriptPathArray, scriptCount);
break;
}
#endif
}
// clean up our allocated script paths

View File

@ -43,6 +43,15 @@ private:
};
#pragma pack(pop)
extern void(*ServerScriptRegister_Callback)(CSquirrelVM* s);
extern void(*ClientScriptRegister_Callback)(CSquirrelVM* s);
extern void(*UiScriptRegister_Callback)(CSquirrelVM* s);
extern void(*CoreServerScriptRegister_Callback)(CSquirrelVM* s);
extern void(*AdminPanelScriptRegister_Callback)(CSquirrelVM* s);
extern void(*ScriptConstantRegister_Callback)(CSquirrelVM* s);
inline CMemory p_CSquirrelVM_Init;
inline bool(*v_CSquirrelVM_Init)(CSquirrelVM* s, SQCONTEXT context, SQFloat curtime);

View File

@ -12,98 +12,6 @@
#include "game/shared/vscript_shared.h"
#include "pluginsystem/modsystem.h"
//---------------------------------------------------------------------------------
// Purpose: registers script functions in SERVER context
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterServerFunctions(CSquirrelVM* s)
{
s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native SERVER test function", "void", "", &VScriptCode::SHARED::SDKNativeTest);
s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion);
s->RegisterFunction("GetNumHumanPlayers", "Script_GetNumHumanPlayers", "Gets the number of human players on the server", "int", "", &VScriptCode::SERVER::GetNumHumanPlayers);
s->RegisterFunction("GetNumFakeClients", "Script_GetNumFakeClients", "Gets the number of bot players on the server", "int", "", &VScriptCode::SERVER::GetNumFakeClients);
s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps);
s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists);
s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string, string", &VScriptCode::SHARED::KickPlayerByName);
s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string, string", &VScriptCode::SHARED::KickPlayerById);
s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::SHARED::BanPlayerByName);
s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string, string", &VScriptCode::SHARED::BanPlayerById);
s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string, string", &VScriptCode::SHARED::UnbanPlayer);
s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame);
s->RegisterFunction("IsDedicated", "Script_IsDedicated", "Returns whether this is a dedicated server", "bool", "", &VScriptCode::SERVER::IsDedicated);
}
//---------------------------------------------------------------------------------
// Purpose: registers script functions in CLIENT context
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterClientFunctions(CSquirrelVM* s)
{
s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native CLIENT test function", "void", "", &VScriptCode::SHARED::SDKNativeTest);
s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion);
s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps);
s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists);
s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame);
s->RegisterFunction("IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VScriptCode::SHARED::IsClientDLL);
}
//---------------------------------------------------------------------------------
// Purpose: registers script functions in UI context
// Input : *s -
//---------------------------------------------------------------------------------
void Script_RegisterUIFunctions(CSquirrelVM* s)
{
s->RegisterFunction("SDKNativeTest", "Script_SDKNativeTest", "Native UI test function", "void", "", &VScriptCode::SHARED::SDKNativeTest);
s->RegisterFunction("GetSDKVersion", "Script_GetSDKVersion", "Gets the SDK version as a string", "string", "", &VScriptCode::SHARED::GetSDKVersion);
s->RegisterFunction("RefreshServerList", "Script_RefreshServerList", "Refreshes the public server list and returns the count", "int", "", &VScriptCode::UI::RefreshServerCount);
// Functions for retrieving server browser data
s->RegisterFunction("GetServerName", "Script_GetServerName", "Gets the name of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerName);
s->RegisterFunction("GetServerDescription", "Script_GetServerDescription", "Gets the description of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerDescription);
s->RegisterFunction("GetServerMap", "Script_GetServerMap", "Gets the map of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerMap);
s->RegisterFunction("GetServerPlaylist", "Script_GetServerPlaylist", "Gets the playlist of the server at the specified index of the server list", "string", "int", &VScriptCode::UI::GetServerPlaylist);
s->RegisterFunction("GetServerCurrentPlayers", "Script_GetServerCurrentPlayers", "Gets the current player count of the server at the specified index of the server list", "int", "int", &VScriptCode::UI::GetServerCurrentPlayers);
s->RegisterFunction("GetServerMaxPlayers", "Script_GetServerMaxPlayers", "Gets the max player count of the server at the specified index of the server list", "int", "int", &VScriptCode::UI::GetServerMaxPlayers);
s->RegisterFunction("GetServerCount", "Script_GetServerCount", "Gets the number of public servers", "int", "", &VScriptCode::UI::GetServerCount);
// Misc main menu functions
s->RegisterFunction("GetPromoData", "Script_GetPromoData", "Gets promo data for specified slot type", "string", "int", &VScriptCode::UI::GetPromoData);
// Functions for creating servers
s->RegisterFunction("CreateServer", "Script_CreateServer", "Starts server with the specified settings", "void", "string, string, string, string, int", &VScriptCode::UI::CreateServer);
s->RegisterFunction("IsServerActive", "Script_IsServerActive", "Returns whether the server is active", "bool", "", &VScriptCode::SHARED::IsServerActive);
// Functions for connecting to servers
s->RegisterFunction("ConnectToServer", "Script_ConnectToServer", "Joins server by ip address and encryption key", "void", "string, string", &VScriptCode::UI::ConnectToServer);
s->RegisterFunction("ConnectToListedServer", "Script_ConnectToListedServer", "Joins listed server by index", "void", "int", &VScriptCode::UI::ConnectToListedServer);
s->RegisterFunction("ConnectToHiddenServer", "Script_ConnectToHiddenServer", "Joins hidden server by token", "void", "string", &VScriptCode::UI::ConnectToHiddenServer);
s->RegisterFunction("GetHiddenServerName", "Script_GetHiddenServerName", "Gets hidden server name by token", "string", "string", &VScriptCode::UI::GetHiddenServerName);
s->RegisterFunction("GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VScriptCode::SHARED::GetAvailableMaps);
s->RegisterFunction("GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VScriptCode::SHARED::GetAvailablePlaylists);
s->RegisterFunction("KickPlayerByName", "Script_KickPlayerByName", "Kicks a player from the server by name", "void", "string", &VScriptCode::SHARED::KickPlayerByName);
s->RegisterFunction("KickPlayerById", "Script_KickPlayerById", "Kicks a player from the server by handle or nucleus id", "void", "string", &VScriptCode::SHARED::KickPlayerById);
s->RegisterFunction("BanPlayerByName", "Script_BanPlayerByName", "Bans a player from the server by name", "void", "string", &VScriptCode::SHARED::BanPlayerByName);
s->RegisterFunction("BanPlayerById", "Script_BanPlayerById", "Bans a player from the server by handle or nucleus id", "void", "string", &VScriptCode::SHARED::BanPlayerById);
s->RegisterFunction("UnbanPlayer", "Script_UnbanPlayer", "Unbans a player from the server by nucleus id or ip address", "void", "string", &VScriptCode::SHARED::UnbanPlayer);
s->RegisterFunction("ShutdownHostGame", "Script_ShutdownHostGame", "Shuts the local host game down", "void", "", &VScriptCode::SHARED::ShutdownHostGame);
s->RegisterFunction("IsClientDLL", "Script_IsClientDLL", "Returns whether this build is client only", "bool", "", &VScriptCode::SHARED::IsClientDLL);
}
//---------------------------------------------------------------------------------
// Purpose: Returns the script VM pointer by context
// Input : context -

View File

@ -34,10 +34,6 @@ inline SQBool(*v_Script_PrecompileClientScripts)(CSquirrelVM* vm);
inline CMemory p_Script_SetClientCompiler;
inline void(*v_Script_SetClientPrecompiler)(SQCONTEXT ctx, RSON::Node_t* rson);
void Script_RegisterServerFunctions(CSquirrelVM* s);
void Script_RegisterClientFunctions(CSquirrelVM* s);
void Script_RegisterUIFunctions(CSquirrelVM* s);
CSquirrelVM* Script_GetScriptHandle(const SQCONTEXT context);
RSON::Node_t* Script_LoadScriptList(const SQChar* rsonfile);
SQBool Script_LoadScriptFile(HSQUIRRELVM v, const SQChar* path, const SQChar* name, SQInteger flags);