Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#pragma once

enum ENetworkConnectionState
{
NOT_CONNECTED,
CONNECTED_DIRECT,
CONNECTED_RELAYED
};

class NetworkMemberBase
{
public:
int64_t user_id = -1;
std::string display_name;

ENetworkConnectionState m_connectionState = ENetworkConnectionState::NOT_CONNECTED;
bool m_bIsHost = false;

bool m_bIsReady = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@
#include <ws2ipdef.h>
#include <mutex>
#include "ValveNetworkingSockets/steam/steamnetworkingcustomsignaling.h"
#include "PluginInterfaces.h"

class NetRoom_ChatMessagePacket;

enum class EConnectionState
{
NOT_CONNECTED,
CONNECTING_DIRECT,
FINDING_ROUTE,
CONNECTED_DIRECT,
CONNECTION_FAILED,
CONNECTION_DISCONNECTED
};

// trivial signalling client interface
class ISignalingClient
{
Expand All @@ -29,16 +20,26 @@ class ISignalingClient
virtual void Release() = 0;
};

enum class EConnectionType
{
Unknown = -1,
BuiltIn_ValveSockets = 0,
MiddlewarePluginGeneric = 1
};

class NetworkMesh;
class PlayerConnection
{
public:
PlayerConnection()
{

}
PlayerConnection()
{
m_ConnectionType = EConnectionType::Unknown;
m_hSteamConnection = k_HSteamNetConnection_Invalid;
m_strMiddlewareID = std::string("NOT SET");
}

PlayerConnection(int64_t userID, HSteamNetConnection hSteamConnection);
PlayerConnection(int64_t userID, const char* szMiddlewareID);

EConnectionState GetState() const { return m_State; }

Expand All @@ -48,13 +49,22 @@ class PlayerConnection

void UpdateLatencyHistogram();

void Close();

bool IsIPV4();
bool IsDirect()
{
std::string strConnectionType = GetConnectionType();
return strConnectionType.find("Relayed") == std::string::npos;
}

bool IsValid() const
{
return m_State != EConnectionState::NOT_CONNECTED &&
m_State != EConnectionState::CONNECTION_FAILED &&
m_State != EConnectionState::CONNECTION_DISCONNECTED;
}

int Recv(SteamNetworkingMessage_t** pMsg);

int GetHighestHistoricalLatency()
Expand All @@ -81,6 +91,7 @@ class PlayerConnection
void SetDisconnected(bool bWasError, NetworkMesh* pOwningMesh, bool bIsRetrying);

int64_t m_userID = -1;
EConnectionType m_ConnectionType = EConnectionType::Unknown;

EConnectionState m_State = EConnectionState::NOT_CONNECTED;

Expand All @@ -93,8 +104,12 @@ class PlayerConnection
float GetConnectionQuality();
int ComputeConnectionScore();

// Only set for Steam connections
HSteamNetConnection m_hSteamConnection = k_HSteamNetConnection_Invalid;

// Only set for MW connections
std::string m_strMiddlewareID = std::string("NOT SET");

void LiteUpdateForAC();
};

Expand Down Expand Up @@ -175,7 +190,7 @@ class NetworkMesh

void SendACPacket(uint32_t userID, const void* pData, uint32_t dataLen);

void StartConnectionSignalling(int64_t remoteUserID, uint16_t preferredPort);
void StartConnectionSignalling(const char* szMiddlewareID, int64_t remoteUserID, uint16_t preferredPort);
void DisconnectUser(int64_t remoteUserID);
void Disconnect();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +0,0 @@
#pragma once

#include <stdint.h>

class CBitStream;

enum EPacketReliability : uint8_t
{
PACKET_RELIABILITY_UNRELIABLE_UNORDERED, /* Packets will only be sent once and may be received out of order */
PACKET_RELIABILITY_UNRELIABLE_UNORDERED_DISCARD_OUT_OF_ORDER, /* Packets will only be sent once and will be discarded if out of order */
PACKET_RELIABILITY_RELIABLE_UNORDERED, /* Packets may be sent multiple times and may be received out of order */
PACKET_RELIABILITY_RELIABLE_ORDERED, /* Packets may be sent multiple times and will be received in order */
};

enum EPacketCategory
{
EVENT
};

class NetworkPacket
{
public:
// send
NetworkPacket(EPacketReliability reliability)
{
m_Reliability = reliability;
}

// receive
NetworkPacket(CBitStream& bitstream)
{
// We don't really care on the receivers side
m_Reliability = EPacketReliability::PACKET_RELIABILITY_UNRELIABLE_UNORDERED;
}

virtual CBitStream* Serialize() = 0;

EPacketReliability GetReliability() const { return m_Reliability; }
protected:
EPacketReliability m_Reliability;
};
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class NGMP_OnlineServicesManager

static void CreateInstance()
{
std::scoped_lock<std::mutex> lock(m_singletonMutex);
if (m_pOnlineServicesManager == nullptr)
{
m_pOnlineServicesManager = new NGMP_OnlineServicesManager();
Expand All @@ -347,6 +348,7 @@ class NGMP_OnlineServicesManager

static void DestroyInstance()
{
std::scoped_lock<std::mutex> lock(m_singletonMutex);
if (m_pOnlineServicesManager != nullptr)
{
m_pOnlineServicesManager->Shutdown();
Expand All @@ -360,8 +362,11 @@ class NGMP_OnlineServicesManager

void CommitReplay(AsciiString absoluteReplayPath);

static std::mutex m_singletonMutex;

static NGMP_OnlineServicesManager* GetInstance()
{
std::scoped_lock<std::mutex> lock(m_singletonMutex);
return m_pOnlineServicesManager;
}

Expand Down Expand Up @@ -591,6 +596,7 @@ class NGMP_OnlineServicesManager
std::queue<int64_t> m_vecFilesSizes;
std::vector<std::string> m_vecFilesDownloaded;
std::function<void(void)> m_updateCompleteCallback = nullptr;
mutable std::mutex m_updateCallbackMutex;

std::string m_patcher_name;
std::string m_patcher_path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,16 @@ class NGMP_OnlineServices_LobbyInterface

// lobby roster
std::function<void()> m_RosterNeedsRefreshCallback = nullptr;
mutable std::mutex m_rosterCallbackMutex;
void RegisterForRosterNeedsRefreshCallback(std::function<void()> cb)
{
std::scoped_lock<std::mutex> lock(m_rosterCallbackMutex);
m_RosterNeedsRefreshCallback = cb;
}

void DeregisterForRosterNeedsRefreshCallback()
{
std::scoped_lock<std::mutex> lock(m_rosterCallbackMutex);
m_RosterNeedsRefreshCallback = nullptr;
}

Expand Down Expand Up @@ -374,6 +377,7 @@ class NGMP_OnlineServices_LobbyInterface
{
m_CurrentLobby = LobbyEntry();

std::scoped_lock<std::mutex> lock(m_rosterCallbackMutex);
if (m_RosterNeedsRefreshCallback != nullptr)
{
m_RosterNeedsRefreshCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ class NGMP_OnlineServices_RoomsInterface
}

std::function<void()> m_RosterNeedsRefreshCallback = nullptr;
mutable std::mutex m_rosterCallbackMutex;
void RegisterForRosterNeedsRefreshCallback(std::function<void()> cb)
{
std::scoped_lock<std::mutex> lock(m_rosterCallbackMutex);
m_RosterNeedsRefreshCallback = cb;
}

void DeregisterForRosterNeedsRefreshCallback()
{
std::scoped_lock<std::mutex> lock(m_rosterCallbackMutex);
m_RosterNeedsRefreshCallback = nullptr;
}

Expand Down Expand Up @@ -170,6 +173,7 @@ class NGMP_OnlineServices_RoomsInterface
{
m_mapMembers.clear();

std::scoped_lock<std::mutex> lock(m_rosterCallbackMutex);
if (m_RosterNeedsRefreshCallback != nullptr)
{
m_RosterNeedsRefreshCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class NGMP_OnlineServices_SocialInterface
std::function<void(int newNumNotifications)> m_cbOnNumberGlobalNotificationsChanged = nullptr;

std::function<void()> m_cbOnGetFriendsList = nullptr;
mutable std::mutex m_friendsListCallbackMutex;
std::function<void(BlockedResult blockResult)> m_cbOnGetBlockList = nullptr;

std::function<void(std::string strDisplayName)> m_cbOnNewFriendRequest = nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#pragma once

#define AC_ENABLED 1

enum class EConnectionState : uint8_t
{
NOT_CONNECTED,
CONNECTING_DIRECT,
FINDING_ROUTE,
CONNECTED_DIRECT,
CONNECTION_FAILED,
CONNECTION_DISCONNECTED
};

enum class EAnticheatActionType : int32_t
{
Expand All @@ -22,6 +33,20 @@ enum class EAnticheatActionReason : int32_t
PermaBanned = 10
};

enum class ENetworkChannels : uint8_t
{
Game = 0,
Anticheat,
Signalling
};

enum class EPacketReliability : int32_t
{
PACKET_RELIABILITY_UNRELIABLE_UNORDERED = 0,
PACKET_RELIABILITY_RELIABLE_UNORDERED = 1,
PACKET_RELIABILITY_RELIABLE_ORDERED = 2
};


class AnticheatPlugInterface
{
Expand All @@ -41,6 +66,8 @@ class AnticheatPlugInterface

static int GetAnticheatIdentifier();

static int GetConnectionLatencyForUser(std::string mwUserID, uint32_t goUserID);

static void LoadPlugin(const char* szPluginName);
static void Authenticate();
static void UnloadPlugin();
Expand All @@ -54,6 +81,26 @@ class AnticheatPlugInterface
static void BeginSession();
static void EndSession();

// transport related
static bool DoesACPluginProvideSecureGameTransport();
static void SendPacket(const char* szMiddlewareUserID, uint64_t targetGoUserID, void* pData, int numBytes, ENetworkChannels channel, EPacketReliability reliability);
static void StartSignalling(const char* szMiddlewareUserID, uint64_t goUserID);
static int GetNextRecvPacketSize(uint8_t channelToReceiveOn);
static bool RecvPacket(uint8_t** pOutData, uint8_t channelToReceiveOn);

static void DisconnectPlayer(const char* szMiddlewareUserID, uint64_t goUserID);
static void DisconnectAll();

#if defined(AC_ENABLED)
typedef void (*FuncDefStartSignalling)(const char* szMiddlewareUserID, uint64_t goUserID);
typedef void (*FuncDefSendPacket)(const char* szMiddlewareUserID, uint64_t targetGoUserID, void* pData, int numBytes, ENetworkChannels channel, EPacketReliability reliability);
typedef bool (*FuncDefDoesACPluginProvideSecureGameTransport)(void);
typedef int (*FuncDefGetNextRecvPacketSize)(uint8_t channelToReceiveOn);
typedef bool (*FuncDefRecvPacket)(uint8_t** pOutData, uint8_t channelToReceiveOn);
typedef void (*FuncDefFreePacket)(void* pPacketData);
typedef void (*FuncDefDisconnectPlayer)(const char* szMiddlewareUserID, uint64_t goUserID);
typedef void (*FuncDefDisconnectAll)();

// Callbacks from plugin
typedef void (*LoginCallback)(bool bSuccess);
typedef void (*LoggingFunc)(const char*);
Expand All @@ -66,10 +113,13 @@ class AnticheatPlugInterface

// Func defs
typedef void (*FuncDefSetLoggingFunction)(LoggingFunc);
typedef int (*FuncDefInitialize)(void);

typedef void (*OnConnectionStateChangedCallbackFunc)(const char*, uint64_t, EConnectionState);
typedef int (*FuncDefInitialize)(OnConnectionStateChangedCallbackFunc connectionStateChangedCB);
typedef bool (*FuncDefIsExternalProcessRunning)(void);

typedef int (*FuncDefGetAnticheatIdentifier)(void);
typedef int (*FuncDefGetConnectionLatencyForUser)(const char* szMiddlewareUserID, uint32_t goUserID);

typedef void (*FuncDefSetSendMessageViaTransportCallback)(SendMessageViaTransportCallbackFunc);
typedef void (*FuncDefACMessageArrivedViaTransport)(uint32_t, void*, uint32_t);
Expand Down Expand Up @@ -105,8 +155,33 @@ class AnticheatPlugInterface
FuncDefDeregisterPlayer fnDeregisterPlayer = nullptr;
FuncDefTick fnTick = nullptr;
FuncDefShutdown fnShutdown = nullptr;

// transport related
FuncDefDoesACPluginProvideSecureGameTransport fnDoesACPluginProvideSecureGameTransport = nullptr;
FuncDefStartSignalling fnStartSignalling = nullptr;
FuncDefSendPacket fnSendPacket = nullptr;
FuncDefGetNextRecvPacketSize fnGetNextRecvPacketSize = nullptr;
FuncDefRecvPacket fnRecvPacket = nullptr;

FuncDefGetConnectionLatencyForUser fnGetConnectionLatencyForUser = nullptr;

FuncDefDisconnectPlayer fnDisconnectPlayer = nullptr;
FuncDefDisconnectAll fnDisconnectAll = nullptr;
};
static AnticheatPluginFunctionPtrs Functions;
#else
typedef bool (*FuncDefIsExternalProcessRunning)(void);
typedef int (*FuncDefGetAnticheatIdentifier)(void);
typedef int (*FuncDefInitialize)();

struct AnticheatPluginFunctionPtrs
{
FuncDefIsExternalProcessRunning fnIsExternalProcessRunning = nullptr;
FuncDefGetAnticheatIdentifier fnGetAnticheatIdentifier = nullptr;
FuncDefInitialize fnInitialize = nullptr;
};
static AnticheatPluginFunctionPtrs Functions;
#endif

// Module
static HMODULE g_hACPluginModule;
Expand Down
Loading
Loading