Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/game/client/cdll_client_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,9 @@ void OnRenderEnd()

void CHLClient::FrameStageNotify( ClientFrameStage_t curStage )
{
// this needs to run on every frame
SteamAPI_RunCallbacks();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably only run callbacks once per frame (check for a specific value for curStage)


g_CurFrameStage = curStage;
g_bEngineIsHLTV = engine->IsHLTV();

Expand Down
1 change: 0 additions & 1 deletion src/game/client/swarm/c_rd_infection_deathmatch_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void CRD_Infection_Deathmatch_Stats::OnUpdate( C_RD_HUD_VScript *pHUD )

if ( !m_bStatsRequested && SteamUserStats() )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably remove this entire variable and the code that references it

{
SteamUserStats()->RequestCurrentStats();
m_bStatsRequested = true;
}

Expand Down
10 changes: 10 additions & 0 deletions src/game/server/gameinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
#undef CreateEvent

#ifndef CLIENT_DLL
// include gameserver interface
#include "rd_gameserver.h"

// expose server helper interface
#include "serverhelper.h"
static CServerHelper g_ServerHelper;
Expand Down Expand Up @@ -619,6 +622,10 @@ bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory,
CGlobalVars *pGlobals)
{

#ifndef CLIENT_DLL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file isn't compiled with CLIENT_DLL - I think you should be asking the engine whether it's a dedicated server here instead

GameServerInit();
#endif

COM_TimestampedLog( "ConnectTier1/2/3Libraries - Start" );

ConnectTier1Libraries( &appSystemFactory, 1 );
Expand Down Expand Up @@ -1457,6 +1464,9 @@ static void OnServerUpdateRequested()

void CServerGameDLL::Think( bool finalTick )
{
// run callbacks on every tick
GameServerCallbacks();

static bool s_bUpdateCheckInit = engine->IsDedicatedServer();
if ( s_bUpdateCheckInit )
{
Expand Down
92 changes: 92 additions & 0 deletions src/game/server/swarm/rd_gameserver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "cbase.h"
#include "rd_gameserver.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

inline uint16 GetCommandLinePort(const char* type, uint16 defaultPort = 0)
{
uint port = 0;

if (CommandLine()->CheckParm(type)) {
const char* sPortStr = CommandLine()->ParmValue(type, nullptr);
port = atoi(sPortStr);
}

if (port < 1024) port = defaultPort;

return port;
}

inline const char* GetGameVersion()
{
static char version[64] = "0.0.0.0";

FILE* f = fopen("reactivedrop/steam.inf", "r");
if (!f)
return version;

char line[256];
while (fgets(line, sizeof(line), f))
{
if (strncmp(line, "PatchVersion=", 13) == 0)
{
strncpy(version, line + 13, sizeof(version));
version[strcspn(version, "\r\n")] = '\0';
break;
}
}

fclose(f);
return version;
}

bool GameServerInit()
{
// initialize the gameserver, srcds already binds to the correct ip and ports, so we can just pass the same parameters here
// get ip
uint32 ip = INADDR_ANY;
const char* ipStr = CommandLine()->ParmValue("-ip", nullptr);

if (CommandLine()->CheckParm("-ip")) {
struct sockaddr_in sa;
if (inet_pton(AF_INET, ipStr, &sa.sin_addr) == 1) {
ip = ntohl(sa.sin_addr.s_addr);
}
}

// get ports
uint16 gamePort = GetCommandLinePort("-port", 0);
uint16 clientPort = GetCommandLinePort("-clientport", 0);

// get version
const char* version = GetGameVersion();

// show some debug
ConMsg("Using ip: %s:%d (%u) [%s]\n", ip > 0 ? ipStr : "0.0.0.0", gamePort, ip, version);

// load steam api
// this is done in engine, but needs to be redone at exactly this timing, to reconnect all steam interfaces
SteamAPI_Init();

// we can spawn a gameserver immediately
const bool result = SteamGameServer_Init(ip, gamePort, clientPort, eServerModeAuthenticationAndSecure, version);
ConMsg("StartGameServer_Init resulted in %s\n", result ? "success" : "failure");
return result;
}

void GameServerCallbacks()
{
// steam callbacks
SteamGameServer_RunCallbacks();

// this is normally done in engine, but not anymore
// we need to put this here
if (SteamGameServer()) {
bool bLoggedIn = SteamGameServer()->BLoggedOn();
if (!bLoggedIn) {
SteamGameServer()->LogOnAnonymous();
}
}
}

14 changes: 14 additions & 0 deletions src/game/server/swarm/rd_gameserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef GAMESERVER_H
#define GAMESERVER_H

#ifdef _WIN32
#pragma once
#endif

#include "cbase.h"
#include "ws2tcpip.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include isn't used in this header, so it can be moved to the cpp file


bool GameServerInit();
void GameServerCallbacks();

#endif
6 changes: 4 additions & 2 deletions src/game/server/swarm_sdk_server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ exit /b 0
<ClCompile Include="inforemarkable.cpp" />
<ClCompile Include="info_camera_link.cpp" />
<ClCompile Include="info_overlay_accessor.cpp" />
<ClCompile Include="info_player_start.cpp" />
<ClCompile Include="info_player_start.cpp" />
<ClCompile Include="init_factory.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
Expand Down Expand Up @@ -1394,6 +1394,7 @@ exit /b 0
<ClCompile Include="swarm\rd_boss_bar.cpp" />
<ClCompile Include="swarm\asw_trigger_marine_melee.cpp" />
<ClCompile Include="swarm\rd_func_jumpjet.cpp" />
<ClCompile Include="swarm\rd_gameserver.cpp" />
<ClCompile Include="swarm\rd_memlimit.cpp" />
<ClCompile Include="tanktrain.cpp" />
<ClCompile Include="te.cpp" />
Expand Down Expand Up @@ -2066,7 +2067,7 @@ exit /b 0
<ClInclude Include="ilagcompensationmanager.h" />
<ClInclude Include="inforemarkable.h" />
<ClInclude Include="info_camera_link.h" />
<ClInclude Include="info_player_start.h" />
<ClInclude Include="info_player_start.h" />
<ClInclude Include="init_factory.h" />
<ClInclude Include="iservervehicle.h" />
<ClInclude Include="items.h" />
Expand Down Expand Up @@ -2331,6 +2332,7 @@ exit /b 0
<ClInclude Include="swarm\rd_boss_bar.h" />
<ClInclude Include="swarm\asw_trigger_marine_melee.h" />
<ClInclude Include="swarm\rd_func_jumpjet.h" />
<ClInclude Include="swarm\rd_gameserver.h" />
<ClInclude Include="te.h" />
<ClInclude Include="team.h" />
<ClInclude Include="TemplateEntities.h" />
Expand Down
5 changes: 0 additions & 5 deletions src/game/shared/achievementmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,6 @@ void CAchievementMgr::UserConnected( int nUserSlot )
if ( IsPC() )
{
// ASSERT( STEAM_PLAYER_SLOT == nUserSlot )
if ( SteamUserStats() )
{
// request stat download; will get called back at OnUserStatsReceived when complete
SteamUserStats()->RequestCurrentStats();
}

m_bUserSlotActive[STEAM_PLAYER_SLOT] = true;

Expand Down
6 changes: 1 addition & 5 deletions src/game/shared/swarm/asw_player_experience.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,7 @@ void CASW_Player::RequestExperience()
Assert( SteamUserStats() );
if ( SteamUserStats() )
{
if ( IsLocalPlayer( this ) )
{
SteamUserStats()->RequestCurrentStats();
}
else
if ( ! IsLocalPlayer( this ) )
{
player_info_t pi;
if ( engine->GetPlayerInfo( entindex(), &pi ) && pi.friendsID )
Expand Down
88 changes: 78 additions & 10 deletions src/game/shared/swarm/rd_workshop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ bool CReactiveDropWorkshop::DedicatedServerWorkshopSetup()
engine->ServerCommand( "exec workshop.cfg\n" );
engine->ServerExecute();
}

m_bStartingUp = false;
if ( m_bAnyServerUpdates )
{
Expand Down Expand Up @@ -498,6 +499,11 @@ void CReactiveDropWorkshop::RestartEnabledAddonsQuery()
m_hEnabledAddonsQuery = hQuery;
pUGC->SetReturnLongDescription( hQuery, true );
pUGC->SetReturnKeyValueTags( hQuery, true );

#ifndef CLIENT_DLL
pUGC->SetAllowCachedResponse(hQuery, rd_workshop_query_cache.GetInt());
#endif

SteamAPICall_t hAPICall = pUGC->SendQueryUGCRequest( hQuery );
m_SteamUGCQueryCompleted.Set( hAPICall, this, &CReactiveDropWorkshop::SteamUGCQueryCompletedCallback );
}
Expand Down Expand Up @@ -2021,11 +2027,51 @@ static bool ShouldUnconditionalDownload( PublishedFileId_t id )
cooldown--;
}
#endif

return false;
}

bool CReactiveDropWorkshop::UpdateAndLoadAddon( PublishedFileId_t id, bool bHighPriority, bool bUnload )

#ifndef CLIENT_DLL
void CReactiveDropWorkshop::OnPublishedFileDetails(RemoteStorageGetPublishedFileDetailsResult_t* pResult, bool bIOFailure)
{
if (bIOFailure)
{
Warning("Steam Workshop PublishedFile API call failed! (IO Failure)\n");
return;
}
if (pResult->m_eResult != k_EResultOK)
{
Warning("Steam Workshop PublishedFile API call failed! EResult: %d (%s)\n", pResult->m_eResult, UTIL_RD_EResultToString(pResult->m_eResult));
return;
}

// find the original id and ugc timestamp
PublishedFileId_t id = pResult->m_nPublishedFileId;
uint32 publishedTimestamp = pResult->m_rtimeUpdated;

if (sv_workshop_debug.GetBool()) {
Msg("Remote storage answer for item %llu with timestamp %d\n", id, publishedTimestamp);
}

unsigned short index = s_SteamRemoteStorageChecked.Find(id);
if (s_SteamRemoteStorageChecked.IsValidIndex(index)) {
uint32 timestamp = s_SteamRemoteStorageChecked.Element(index);

if (timestamp != publishedTimestamp) {
if (sv_workshop_debug.GetBool()) {
Msg("Workshop item %llu seems outdated [%d / %d], forcing update..\n", id, publishedTimestamp, timestamp);
}

UpdateAndLoadAddon(id, true, false, true);
}
}
else if (sv_workshop_debug.GetBool()) {
Msg("Remote storage check cannot find workshop %llu\n", id);
}
}
#endif

bool CReactiveDropWorkshop::UpdateAndLoadAddon( PublishedFileId_t id, bool bHighPriority, bool bUnload, bool forceUpdate )
{
ISteamUGC *pWorkshop = SteamUGC();
#ifdef GAME_DLL
Expand All @@ -2044,20 +2090,42 @@ bool CReactiveDropWorkshop::UpdateAndLoadAddon( PublishedFileId_t id, bool bHigh
g_ReactiveDropWorkshop.TryQueryAddon( id );

uint32 iState = pWorkshop->GetItemState( id );
if ( !ShouldUnconditionalDownload( id ) && ( iState & k_EItemStateInstalled ) && !( iState & k_EItemStateNeedsUpdate ) )
if (!forceUpdate && !ShouldUnconditionalDownload(id) && (iState & k_EItemStateInstalled) && !(iState & k_EItemStateNeedsUpdate))
{
if ( rd_workshop_debug.GetBool() )
if (rd_workshop_debug.GetBool())
{
Msg( "Addon %llu is installed and does not need an update.\n", id );
Msg("Addon %llu is installed and does not need an update.\n", id);
}

uint64 sizeOnDisk;
char szFolder[MAX_PATH];
uint32 timeStamp;
if ( pWorkshop->GetItemInstallInfo( id, &sizeOnDisk, szFolder, sizeof( szFolder ), &timeStamp ) )
uint64 sizeOnDisk;
char szFolder[MAX_PATH];
uint32 timeStamp;
if (pWorkshop->GetItemInstallInfo(id, &sizeOnDisk, szFolder, sizeof(szFolder), &timeStamp))
{
if (rd_workshop_debug.GetBool())
{
Msg( " size: %llu bytes; timestamp: %u; folder: %s\n", sizeOnDisk, timeStamp, szFolder );
Msg(" size: %llu bytes; timestamp: %u; folder: %s\n", sizeOnDisk, timeStamp, szFolder);
}
}

#ifndef CLIENT_DLL
// the item is reported up-to-date, however steam ugc doesn't report updates correctly
// load the addon as normal for now, but chain an additional check
unsigned short index = s_SteamRemoteStorageChecked.Find(id);
if (!s_SteamRemoteStorageChecked.IsValidIndex(index))
{
// we have not checked this addon, store the ugc timestamp and check it
s_SteamRemoteStorageChecked.Insert(id, timeStamp);

SteamAPICall_t hCall = SteamRemoteStorage()->GetPublishedFileDetails(id, 0);
m_PublishedFileDetailsCallResult.Set(hCall, this, &CReactiveDropWorkshop::OnPublishedFileDetails);

if (sv_workshop_debug.GetBool()) {
Msg("Remote storage check started for item %llu with timestamp %u..\n", id, timeStamp);
}
}
#endif

return LoadAddon( id, false );
}
if ( bUnload )
Expand Down
8 changes: 6 additions & 2 deletions src/game/shared/swarm/rd_workshop.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CReactiveDropWorkshop : public CAutoGameSystem
void ClearCaches( const char *szReason );
void DoClearCaches();
void GetActiveAddons( CUtlVector<PublishedFileId_t> &active );
bool UpdateAndLoadAddon( PublishedFileId_t id, bool bHighPriority = false, bool bUnload = false );
bool UpdateAndLoadAddon( PublishedFileId_t id, bool bHighPriority = false, bool bUnload = false, bool forceUpdate = false );
void RealLoadAddon( PublishedFileId_t id );
bool LoadAddon( PublishedFileId_t id, bool bFromDownload );
void RealUnloadAddon( PublishedFileId_t id );
Expand All @@ -81,7 +81,9 @@ class CReactiveDropWorkshop : public CAutoGameSystem
void SetupThink();
bool DedicatedServerWorkshopSetup();
void EnableServerWorkshopItem( PublishedFileId_t id );
void OnPublishedFileDetails(RemoteStorageGetPublishedFileDetailsResult_t* pResult, bool bIOFailure);
bool m_bWorkshopSetupCompleted;
CUtlMap<PublishedFileId_t, int> s_SteamRemoteStorageChecked{DefLessFunc(PublishedFileId_t)};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't static, so it shouldn't start with s_

#endif

PublishedFileId_t FindAddonProvidingFile( const char *pszFileName );
Expand Down Expand Up @@ -139,6 +141,8 @@ class CReactiveDropWorkshop : public CAutoGameSystem
const WorkshopItem_t & TryQueryAddon( PublishedFileId_t nPublishedFileID );
#ifdef CLIENT_DLL
bool LoadAddonEarly( PublishedFileId_t nPublishedFileID );
#else
CCallResult<CReactiveDropWorkshop, RemoteStorageGetPublishedFileDetailsResult_t> m_PublishedFileDetailsCallResult;
#endif

private:
Expand Down Expand Up @@ -306,7 +310,7 @@ class CReactiveDropWorkshop : public CAutoGameSystem
CCallResult<CReactiveDropWorkshop, SteamUGCQueryCompleted_t> m_UpdateWorkshopItemQueryResultCallback;
void UpdateWorkshopItemQueryResultCallback( SteamUGCQueryCompleted_t *pResult, bool bIOFailure );
CCallResult<CReactiveDropWorkshop, CreateItemResult_t> m_CreateItemResultCallbackCurated;
void CreateItemResultCallbackCurated( CreateItemResult_t *pResult, bool bIOFailure );
void CreateItemResultCallbackCurated( CreateItemResult_t *pResult, bool bIOFailure );
friend static void ugc_create(const CCommand & args);
friend static void ugc_curated_create(const CCommand & args);
friend static void ugc_update(const CCommand & args);
Expand Down
Binary file modified src/lib/public/steam_api.lib
Binary file not shown.
Loading
Loading