Skip to content

Commit

Permalink
Revert "Fix #741: Add new CServerRPCControlPacket to toggle RPCs from…
Browse files Browse the repository at this point in the history
… server (#1978)"

This reverts commit 146bd15.
  • Loading branch information
patrikjuvonen committed May 5, 2021
1 parent 17a2f84 commit 9c3411c
Show file tree
Hide file tree
Showing 21 changed files with 283 additions and 433 deletions.
1 change: 0 additions & 1 deletion Client/mods/deathmatch/StdInc.h
Expand Up @@ -47,7 +47,6 @@
#include <ijsify.h>
#include <Common.h>
#include "net/Packets.h"
#include "net/rpc_enums.h"
#include "Enums.h"
#include "net/SyncStructures.h"
#include "CIdArray.h"
Expand Down
8 changes: 0 additions & 8 deletions Client/mods/deathmatch/logic/CClientGame.h
Expand Up @@ -440,12 +440,6 @@ class CClientGame

void TriggerDiscordJoin(SString strSecret);

inline const bool IsServerRPCFunctionDisabled(const eServerRPCFunctions eServerRPCFunction) const { return m_disabledServerRPCFunctions[eServerRPCFunction]; };
inline void SetServerRPCFunctionDisabled(const eServerRPCFunctions eServerRPCFunction, const bool bDisabled = true)
{
m_disabledServerRPCFunctions[eServerRPCFunction] = bDisabled;
};

private:
// CGUI Callbacks
bool OnKeyDown(CGUIKeyEventArgs Args);
Expand Down Expand Up @@ -830,8 +824,6 @@ class CClientGame
SString m_strACInfo;
std::map<uint, uint> m_SentMessageIds;

std::array<bool, eServerRPCFunctions::NUM_SERVER_RPC_FUNCS> m_disabledServerRPCFunctions;

bool m_bLastKeyWasEscapeCancelled;
std::set<SString> m_AllowKeyUpMap;
uint m_uiPrecisionCallDepth;
Expand Down
3 changes: 0 additions & 3 deletions Client/mods/deathmatch/logic/CNetAPI.cpp
Expand Up @@ -1993,9 +1993,6 @@ void CNetAPI::WriteCameraSync(NetBitStreamInterface& BitStream)

void CNetAPI::RPC(eServerRPCFunctions ID, NetBitStreamInterface* pBitStream)
{
if (g_pClientGame->IsServerRPCFunctionDisabled(ID))
return;

NetBitStreamInterface* pRPCBitStream = g_pNet->AllocateNetBitStream();
if (pRPCBitStream)
{
Expand Down
11 changes: 11 additions & 0 deletions Client/mods/deathmatch/logic/CNetAPI.h
Expand Up @@ -25,6 +25,17 @@ class CNetAPI;
#define CAM_SYNC_RATE ( g_TickRateSettings.iCamSync )
#define TICK_RATE_AIM ( std::min ( TICK_RATE, g_TickRateSettings.iKeySyncRotation ) ) // Keysync or puresync update the aim, so use the shortest interval

enum eServerRPCFunctions
{
PLAYER_INGAME_NOTICE,
INITIAL_DATA_STREAM,
PLAYER_TARGET,
PLAYER_WEAPON,
KEY_BIND,
CURSOR_EVENT,
REQUEST_STEALTH_KILL,
};

class CNetAPI
{
public:
Expand Down
19 changes: 0 additions & 19 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Expand Up @@ -210,10 +210,6 @@ bool CPacketHandler::ProcessPacket(unsigned char ucPacketID, NetBitStreamInterfa
Packet_ServerInfoSync(bitStream);
return true;

case PACKET_ID_SERVER_RPC_CONTROL:
Packet_ServerRPCControl(bitStream);
return true;

default:
break;
}
Expand Down Expand Up @@ -5324,21 +5320,6 @@ void CPacketHandler::Packet_ServerInfoSync(NetBitStreamInterface& bitStream)
}
}

void CPacketHandler::Packet_ServerRPCControl(NetBitStreamInterface& bitStream)
{
unsigned short usNumFunctions;
if (bitStream.ReadCompressed(usNumFunctions))
{
for (unsigned short us = 0; us < usNumFunctions; us++)
{
unsigned int uiServerRPCFunction;
bool bDisabled;
if (bitStream.Read(uiServerRPCFunction) && bitStream.ReadBit(bDisabled))
g_pClientGame->SetServerRPCFunctionDisabled(static_cast<eServerRPCFunctions>(uiServerRPCFunction), bDisabled);
}
}
}

//
//
//
Expand Down
1 change: 0 additions & 1 deletion Client/mods/deathmatch/logic/CPacketHandler.h
Expand Up @@ -100,7 +100,6 @@ class CPacketHandler
void Packet_ChatClear(NetBitStreamInterface& bitStream);
void Packet_ServerInfoSync(NetBitStreamInterface& bitStream);
void Packet_PolygonHeight(NetBitStreamInterface& bitStream);
void Packet_ServerRPCControl(NetBitStreamInterface& bitStream);

// For debugging protocol errors during ENTITY_ADD packet
void EntityAddDebugBegin(uint uiNumEntities, NetBitStreamInterface* pBitStream);
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/rpc/CRPCFunctions.cpp
Expand Up @@ -49,8 +49,8 @@ CBlendedWeather* CRPCFunctions::m_pBlendedWeather;
CClientGame* CRPCFunctions::m_pClientGame;
CClientWaterManager* CRPCFunctions::m_pWaterManager;

SFixedArray<CRPCFunctions::SRPCHandler, eElementRPCFunctions::NUM_RPC_FUNCS> CRPCFunctions::m_RPCHandlers;
SFixedArray<CRPCFunctions::SElementRPCHandler, eElementRPCFunctions::NUM_RPC_FUNCS> CRPCFunctions::m_ElementRPCHandlers;
SFixedArray<CRPCFunctions::SRPCHandler, CRPCFunctions::NUM_RPC_FUNCS> CRPCFunctions::m_RPCHandlers;
SFixedArray<CRPCFunctions::SElementRPCHandler, CRPCFunctions::NUM_RPC_FUNCS> CRPCFunctions::m_ElementRPCHandlers;

CRPCFunctions::CRPCFunctions(CClientGame* pClientGame)
{
Expand Down
2 changes: 0 additions & 2 deletions Server/mods/deathmatch/StdInc.h
Expand Up @@ -40,7 +40,6 @@ struct SAclRequest;
#include "CBox.h"
#include "CMatrix.h"
#include "net/Packets.h"
#include "net/rpc_enums.h"
#include "Enums.h"
#include <bochs_internal/bochs_crc32.h>
#include "CChecksum.h"
Expand Down Expand Up @@ -96,7 +95,6 @@ struct SAclRequest;
#include "packets/CResourceStopPacket.h"
#include "packets/CResourceClientScriptsPacket.h"
#include "packets/CReturnSyncPacket.h"
#include "packets/CServerRPCControlPacket.h"
#include "packets/CServerTextItemPacket.h"
#include "packets/CUpdateInfoPacket.h"
#include "packets/CUnoccupiedVehicleStartSyncPacket.h"
Expand Down
3 changes: 1 addition & 2 deletions Server/mods/deathmatch/logic/CEvents.cpp
Expand Up @@ -17,7 +17,7 @@ CEvents::CEvents()
m_bEventCancelled = false;
}

bool CEvents::AddEvent(const char* szName, const char* szArguments, CLuaMain* pLuaMain, bool bAllowRemoteTrigger, eServerRPCFunctions eServerRPCFunction)
bool CEvents::AddEvent(const char* szName, const char* szArguments, CLuaMain* pLuaMain, bool bAllowRemoteTrigger)
{
assert(szName);
assert(szArguments);
Expand All @@ -32,7 +32,6 @@ bool CEvents::AddEvent(const char* szName, const char* szArguments, CLuaMain* pL
pEvent->strArguments = szArguments;
pEvent->pLuaMain = pLuaMain;
pEvent->bAllowRemoteTrigger = bAllowRemoteTrigger;
pEvent->eServerRPCFunction = eServerRPCFunction;

m_EventHashMap[szName] = pEvent;

Expand Down
12 changes: 5 additions & 7 deletions Server/mods/deathmatch/logic/CEvents.h
Expand Up @@ -17,11 +17,10 @@

struct SEvent
{
class CLuaMain* pLuaMain;
std::string strName;
std::string strArguments;
bool bAllowRemoteTrigger;
eServerRPCFunctions eServerRPCFunction;
class CLuaMain* pLuaMain;
std::string strName;
std::string strArguments;
bool bAllowRemoteTrigger;
};

class CEvents
Expand All @@ -30,8 +29,7 @@ class CEvents
CEvents();
~CEvents() { RemoveAllEvents(); };

bool AddEvent(const char* szName, const char* szArguments, class CLuaMain* pLuaMain, bool bAllowRemoteTrigger,
eServerRPCFunctions eServerRPCFunction = eServerRPCFunctions::NUM_SERVER_RPC_FUNCS);
bool AddEvent(const char* szName, const char* szArguments, class CLuaMain* pLuaMain, bool bAllowRemoteTrigger);
void RemoveEvent(SEvent* pEvent);
void RemoveEvent(const char* szName);
void RemoveAllEvents(class CLuaMain* pMain);
Expand Down
22 changes: 5 additions & 17 deletions Server/mods/deathmatch/logic/CGame.cpp
Expand Up @@ -1245,18 +1245,6 @@ void CGame::JoinPlayer(CPlayer& Player)
if (Player.CanBitStream(eBitStreamVersion::Discord_InitialImplementation))
Player.Send(CServerInfoSyncPacket(SERVER_INFO_FLAG_ALL));

// Control server RPC functions
std::array<bool, eServerRPCFunctions::NUM_SERVER_RPC_FUNCS> disabledServerRPCFunctions;

// Disable CURSOR_EVENT RPC by default
disabledServerRPCFunctions[eServerRPCFunctions::CURSOR_EVENT] = true;

// If suitable event exists (e.g. onPlayerClick/onElementClicked), tell client to enable RPC function instead
if (!m_pMapManager->GetRootElement()->GetEventManager()->GetHandlesByServerRPCFunction(eServerRPCFunctions::CURSOR_EVENT).empty())
disabledServerRPCFunctions[eServerRPCFunctions::CURSOR_EVENT] = false;

Player.Send(CServerRPCControlPacket(disabledServerRPCFunctions));

// Add debug info if wanted
if (CPerfStatDebugInfo::GetSingleton()->IsActive("PlayerInGameNotice"))
CPerfStatDebugInfo::GetSingleton()->AddLine("PlayerInGameNotice", marker.GetString());
Expand Down Expand Up @@ -1512,22 +1500,22 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerJoin", "", NULL, false);
m_Events.AddEvent("onPlayerQuit", "reason", NULL, false);
m_Events.AddEvent("onPlayerSpawn", "spawnpoint, team", NULL, false);
m_Events.AddEvent("onPlayerTarget", "target", NULL, false, eServerRPCFunctions::PLAYER_TARGET);
m_Events.AddEvent("onPlayerTarget", "target", NULL, false);
m_Events.AddEvent("onPlayerWasted", "ammo, killer, weapon, bodypart", NULL, false);
m_Events.AddEvent("onPlayerWeaponSwitch", "previous, current", NULL, false, eServerRPCFunctions::PLAYER_WEAPON);
m_Events.AddEvent("onPlayerWeaponSwitch", "previous, current", NULL, false);
m_Events.AddEvent("onPlayerMarkerHit", "marker, matchingDimension", NULL, false);
m_Events.AddEvent("onPlayerMarkerLeave", "marker, matchingDimension", NULL, false);
m_Events.AddEvent("onPlayerPickupHit", "pickup", NULL, false);
m_Events.AddEvent("onPlayerPickupLeave", "pickup", NULL, false);
m_Events.AddEvent("onPlayerPickupUse", "pickup", NULL, false);
m_Events.AddEvent("onPlayerClick", "button, state, element, posX, posY, posZ", NULL, false, eServerRPCFunctions::CURSOR_EVENT);
m_Events.AddEvent("onPlayerClick", "button, state, element, posX, posY, posZ", NULL, false);
m_Events.AddEvent("onPlayerContact", "previous, current", NULL, false);
m_Events.AddEvent("onPlayerBan", "ban", NULL, false);
m_Events.AddEvent("onPlayerLogin", "guest_account, account, auto-login", NULL, false);
m_Events.AddEvent("onPlayerLogout", "account, guest_account", NULL, false);
m_Events.AddEvent("onPlayerChangeNick", "oldnick, newnick, manuallyChanged", NULL, false);
m_Events.AddEvent("onPlayerPrivateMessage", "text, player", NULL, false);
m_Events.AddEvent("onPlayerStealthKill", "target", NULL, false, eServerRPCFunctions::REQUEST_STEALTH_KILL);
m_Events.AddEvent("onPlayerStealthKill", "target", NULL, false);
m_Events.AddEvent("onPlayerMute", "", NULL, false);
m_Events.AddEvent("onPlayerUnmute", "", NULL, false);
m_Events.AddEvent("onPlayerCommand", "command", NULL, false);
Expand All @@ -1546,7 +1534,7 @@ void CGame::AddBuiltInEvents()
// Element events
m_Events.AddEvent("onElementColShapeHit", "colshape, matchingDimension", NULL, false);
m_Events.AddEvent("onElementColShapeLeave", "colshape, matchingDimension", NULL, false);
m_Events.AddEvent("onElementClicked", "button, state, clicker, posX, posY, posZ", NULL, false, eServerRPCFunctions::CURSOR_EVENT);
m_Events.AddEvent("onElementClicked", "button, state, clicker, posX, posY, posZ", NULL, false);
m_Events.AddEvent("onElementDataChange", "key, oldValue", NULL, false);
m_Events.AddEvent("onElementDestroy", "", NULL, false);
m_Events.AddEvent("onElementStartSync", "newSyncer", NULL, false);
Expand Down
76 changes: 12 additions & 64 deletions Server/mods/deathmatch/logic/CMapEventManager.cpp
Expand Up @@ -78,12 +78,11 @@ bool CMapEventManager::Delete(CLuaMain* pLuaMain, const char* szName, const CLua
}
else
{
// Remove from list and remember that we deleted something
m_EventsMap.erase(iter++);

// Delete the object
DeleteInternal(pMapEvent);
delete pMapEvent;

// Remove from list and remember that we deleted something
m_EventsMap.erase(iter++);
bRemovedSomeone = true;
continue;
}
Expand Down Expand Up @@ -112,8 +111,8 @@ void CMapEventManager::DeleteAll()
// Delete it if it's not already being destroyed
if (!pMapEvent->IsBeingDestroyed())
{
delete pMapEvent;
m_EventsMap.erase(iter++);
DeleteInternal(pMapEvent);
}
else
++iter;
Expand Down Expand Up @@ -301,7 +300,7 @@ void CMapEventManager::TakeOutTheTrash()
}

// Delete it
DeleteInternal(pMapEvent);
delete pMapEvent;
}

m_bHasEvents = !m_EventsMap.empty();
Expand Down Expand Up @@ -342,58 +341,18 @@ bool CMapEventManager::HandleExists(CLuaMain* pLuaMain, const char* szName, cons
return false;
}

void CMapEventManager::DisableServerRPCFunction(eServerRPCFunctions eServerRPCFunction, bool bDisable)
{
// Check no active handle exists here
bool bFound = !GetHandlesByServerRPCFunction(eServerRPCFunction).empty();
if (bFound)
return;

// Check no active handle exists on root
if (bFound = !g_pGame->GetMapManager()->GetRootElement()->GetEventManager()->GetHandlesByServerRPCFunction(eServerRPCFunction).empty())
return;

// Check no active handle exists under root
auto iter = g_pGame->GetMapManager()->GetRootElement()->IterBegin();
for (; iter != g_pGame->GetMapManager()->GetRootElement()->IterEnd(); iter++)
if (bFound = !(*iter)->GetEventManager()->GetHandlesByServerRPCFunction(eServerRPCFunction).empty())
return;

// Let players know that the function got toggled
std::array<bool, eServerRPCFunctions::NUM_SERVER_RPC_FUNCS> disabledServerRPCFunctions;
disabledServerRPCFunctions[eServerRPCFunction] = bDisable;
CServerRPCControlPacket Packet(disabledServerRPCFunctions);
g_pGame->GetPlayerManager()->BroadcastOnlyJoined(Packet);
}

void CMapEventManager::DeleteInternal(CMapEvent* pMapEvent)
void CMapEventManager::AddInternal(CMapEvent* pEvent)
{
SEvent* pEvent = g_pGame->GetEvents()->Get(pMapEvent->GetName());

// For now we only care about CURSOR_EVENT
if (pEvent && pEvent->eServerRPCFunction == eServerRPCFunctions::CURSOR_EVENT)
DisableServerRPCFunction(pEvent->eServerRPCFunction, true); // Disable RPC if no longer used

delete pMapEvent;
}

void CMapEventManager::AddInternal(CMapEvent* pMapEvent)
{
SEvent* pEvent = g_pGame->GetEvents()->Get(pMapEvent->GetName());

// For now we only care about CURSOR_EVENT
if (pEvent && pEvent->eServerRPCFunction == eServerRPCFunctions::CURSOR_EVENT)
DisableServerRPCFunction(pEvent->eServerRPCFunction, false); // Enable RPC if used

// Find place to insert
EventsIterPair itPair = m_EventsMap.equal_range(pMapEvent->GetName());
EventsIterPair itPair = m_EventsMap.equal_range(pEvent->GetName());
EventsIter iter;
for (iter = itPair.first; iter != itPair.second; ++iter)
if (pMapEvent->IsHigherPriorityThan(iter->second))
{
if (pEvent->IsHigherPriorityThan(iter->second))
break;

}
// Do insert
m_EventsMap.insert(iter, std::pair<SString, CMapEvent*>(pMapEvent->GetName(), pMapEvent));
m_EventsMap.insert(iter, std::pair<SString, CMapEvent*>(pEvent->GetName(), pEvent));
}

void CMapEventManager::GetHandles(CLuaMain* pLuaMain, const char* szName, lua_State* luaVM)
Expand All @@ -420,15 +379,4 @@ void CMapEventManager::GetHandles(CLuaMain* pLuaMain, const char* szName, lua_St
}
}
}
}

const std::vector<CMapEvent*> CMapEventManager::GetHandlesByServerRPCFunction(eServerRPCFunctions eServerRPCFunction) const
{
std::vector<CMapEvent*> vecResult;
SEvent* pOtherEvent;
for (auto&& [strName, pMapEvent] : m_EventsMap)
if ((pOtherEvent = g_pGame->GetEvents()->Get(pMapEvent->GetName())) && pOtherEvent->eServerRPCFunction == eServerRPCFunction)
vecResult.push_back(pMapEvent);

return vecResult;
}
}
18 changes: 8 additions & 10 deletions Server/mods/deathmatch/logic/CMapEventManager.h
Expand Up @@ -21,21 +21,19 @@ class CMapEventManager
CMapEventManager();
~CMapEventManager();

bool Add(CLuaMain* pLuaMain, const char* szName, const CLuaFunctionRef& iLuaFunction, bool bPropagated, EEventPriorityType eventPriority, float fPriorityMod);
bool Delete(CLuaMain* pLuaMain, const char* szName = NULL, const CLuaFunctionRef& iLuaFunction = CLuaFunctionRef());
void DeleteAll();
bool HandleExists(CLuaMain* pLuaMain, const char* szName, const CLuaFunctionRef& iLuaFunction);
bool HasEvents() const { return m_bHasEvents; }
void GetHandles(CLuaMain* pLuaMain, const char* szName, lua_State* luaVM);
const std::vector<CMapEvent*> GetHandlesByServerRPCFunction(eServerRPCFunctions eServerRPCFunction) const;
bool Add(CLuaMain* pLuaMain, const char* szName, const CLuaFunctionRef& iLuaFunction, bool bPropagated, EEventPriorityType eventPriority,
float fPriorityMod);
bool Delete(CLuaMain* pLuaMain, const char* szName = NULL, const CLuaFunctionRef& iLuaFunction = CLuaFunctionRef());
void DeleteAll();
bool HandleExists(CLuaMain* pLuaMain, const char* szName, const CLuaFunctionRef& iLuaFunction);
bool HasEvents() const { return m_bHasEvents; }
void GetHandles(CLuaMain* pLuaMain, const char* szName, lua_State* luaVM);

bool Call(const char* szName, const CLuaArguments& Arguments, class CElement* pSource, class CElement* pThis, class CPlayer* pCaller = NULL);

private:
void TakeOutTheTrash();
void AddInternal(CMapEvent* pMapEvent);
void DeleteInternal(CMapEvent* pMapEvent);
void DisableServerRPCFunction(eServerRPCFunctions eServerRPCFunction, bool bDisable = true);
void AddInternal(CMapEvent* pEvent);

bool m_bHasEvents;
bool m_bIteratingList;
Expand Down

0 comments on commit 9c3411c

Please sign in to comment.