fec77632ef
* Fix issues with seedlist for AutomatedTesting Fixes error reporting so it will show the file hint in the tool. Removes any missing assets from the .seed file. Remove an unnecessary dependency from AutomatedTesting dependencies file. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Make ArchiveComponent use AZ::IO::IArchive Initial changes that will get the sychronous calls in ArchiveComponent to use IArchive interface rather than external zip/7z tools. Some of the asynchronous api are still in place, anything that wasn't being used has been removed for now. This may change later if we move towards all the api being asynchronous. Until then, we can't remove the reliance upon the external archive tools completely. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Updates AZStd::thread constructors Adds a variadic constructor which forwards args to the functor. Because of our thread_desc extension, there was confusion on the arugments, so the args were reordered to take the thread_desc first, before the functor and args. Also the thread_desc is taken as reference rather than by pointer. Update callsites to account for this change. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Async operation of ArchiveComponent api This sets up the ArchiveComponent to operate asynchronously. It uses promise/future to transfer results to caller. This is still broken, there's a few things that need to get fixed up, but this is a good checkpoint for the work as it solidifies the api, cleans up a bunch of unused code, and compiles. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the platform-specific ArchiveComponen These are no longer needed, as they control the direct interaction with host OS tools like 7za.exe or /bin/zip. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the platform-specific files from cmake Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the 7za.exe (and legal notice) This tool is no longer needed in the repo. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fixes usage of IArchive::GetFullPath() This changed to return a PathView, updated to reflect that. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix promises and threads Make sure promises are only set exactly once. This meant reworking some of the initial error checking. Detach threads when created. Adds [[nodiscard]] to the functions that return a future. Since threads are detached, the future is the main way to get communication from the thread. Clean up interface, add comments. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * More edits to thread creation Changes to thread construction to account for parameter change. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix some remaining issues with ArchiveComponent Put created threads inside a container, then join them at Deactivate. Fix asset bundler case when injecting a file with no working directory. Fix thread constructor that applies args to a function. Fix lambdas to take string args by value rather than reference. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fixes some remaining bugs in ArchiveComponent Open archive as read-only during extract & list operations. Fixes paths issues. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix initialize of opaque thread handle in thread_UnixLike.h Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed unused variable in AssetBundleComponent.cpp to fix compiler warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fix some issues with archives File paths in the CDR and the local headers need to match, but there were issues with path separators and case that made it possible to get invalid headers errors in some archives. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Adds some new ArchiveComponent unit tests Adds new tests for extraction of archive and adding files from a file list to an archive. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix file data offset issues when opening archives When opening an INestedArchive it would run through the CDR headers to create file entries in the zip cache. The offsets to the compressed data were being calculated incorrectly because they were using the CDR headers rather than jumping to the local file headers and getting offsets from those sizes. Removed and refactored some archive validation flow and zip cache factory init methods to either init default or init w/ additional validation checks. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Addresses PR feedback Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address more points of feedback in PR Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address additional PR feedback Fixes up some error checks and uses of strings vs paths. Enable archive component tests on Linux so we can see if they will pass. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address PR feedback Change the INestedArchive interface to list files as AZ::IO::Path. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Disabling the ArchiveComponent tests on Linux They failed so we will revisit them to attempt a fix. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Rename a member variable to be more accurate Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address feedback on PR Bump version of Archive Components for serialize context. Improve error messages during archive open and validation. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Revert recent changes Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
589 lines
19 KiB
C++
589 lines
19 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
#include <AzCore/PlatformDef.h>
|
|
#include <AzCore/Socket/AzSocket.h>
|
|
|
|
#include <AzFramework/StringFunc/StringFunc.h>
|
|
|
|
#include <platform.h>
|
|
#include <IConsole.h>
|
|
#include <ILevelSystem.h>
|
|
#include <ISystem.h>
|
|
|
|
#include "RemoteConsoleCore.h"
|
|
#include <RemoteConsole_Traits_Platform.h>
|
|
|
|
|
|
|
|
const int defaultRemoteConsolePort = 4600; // externed in the header to expose publicly
|
|
|
|
|
|
namespace
|
|
{
|
|
static const int kDefaultBufferSize = 32768;
|
|
|
|
static const AZ::u16 kMaxBindPorts = 8; // max range of ports to bind to for remote console
|
|
|
|
static const char* kServerThreadName = "RemoteConsoleServer";
|
|
static const char* kClientThreadName = "RemoteConsoleClient";
|
|
}
|
|
|
|
|
|
bool RCON_IsRemoteAllowedToConnect(const AZ::AzSock::AzSocketAddress& connectee)
|
|
{
|
|
if ((!gEnv) || (!gEnv->pConsole))
|
|
{
|
|
CryLog("Cannot allow incoming connection for remote console, because we do not yet have a console or an environment.");
|
|
return false;
|
|
}
|
|
ICVar* remoteConsoleAllowedHostList = gEnv->pConsole->GetCVar("log_RemoteConsoleAllowedAddresses");
|
|
if (!remoteConsoleAllowedHostList)
|
|
{
|
|
CryLog("Cannot allow incoming connection for remote console, because there is no registered log_RemoteConsoleAllowedAddresses console variable.");
|
|
return false;
|
|
}
|
|
|
|
const char* value = remoteConsoleAllowedHostList->GetString();
|
|
// the default or empty string indicates localhost.
|
|
if (!value)
|
|
{
|
|
value = "";
|
|
}
|
|
|
|
AZStd::vector<AZStd::string> addresses;
|
|
AzFramework::StringFunc::Tokenize(value, addresses, ',');
|
|
|
|
if (addresses.empty())
|
|
{
|
|
addresses.push_back("127.0.0.1");
|
|
}
|
|
|
|
AZ::AzSock::AzSocketAddress testAddress;
|
|
for (const AZStd::string& address : addresses)
|
|
{
|
|
// test the approved addresses with connectee's port to see if we have a match
|
|
testAddress.SetAddress(address.c_str(), connectee.GetAddrPort());
|
|
|
|
if (testAddress == connectee)
|
|
{
|
|
// its an exact match.
|
|
if (gEnv->pLog)
|
|
{
|
|
gEnv->pLog->LogToConsole("Remote console connected from ip %s (matches: %s)", connectee.GetAddress().c_str(), address.c_str());
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (gEnv->pLog)
|
|
{
|
|
gEnv->pLog->LogToConsole("An attempt to connect to remote console from ip %s failed because it is not on the ApprovedList.", connectee.GetAddress().c_str());
|
|
gEnv->pLog->LogToConsole("Add to the ApprovedList using the CVAR log_RemoteConsoleAllowedAddresses (comma separated IPs or hostnames)");
|
|
gEnv->pLog->LogToConsole("Example: log_RemoteConsoleAllowedAddresses localhost,joescomputer");
|
|
}
|
|
return false; // return false by default, so you MUST pass an above check for you to be allowed in.
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteThreadedObject::Start(const char* name)
|
|
{
|
|
AZStd::thread_desc desc;
|
|
desc.m_name = name;
|
|
|
|
auto function = AZStd::bind(&SRemoteThreadedObject::ThreadFunction, this);
|
|
m_thread = AZStd::thread(desc, function);
|
|
}
|
|
|
|
void SRemoteThreadedObject::WaitForThread()
|
|
{
|
|
if (m_thread.joinable())
|
|
{
|
|
m_thread.join();
|
|
}
|
|
}
|
|
|
|
void SRemoteThreadedObject::ThreadFunction()
|
|
{
|
|
Run();
|
|
Terminate();
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteServer::StartServer()
|
|
{
|
|
StopServer();
|
|
m_bAcceptClients = true;
|
|
Start(kServerThreadName);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteServer::StopServer()
|
|
{
|
|
m_bAcceptClients = false;
|
|
AZ::AzSock::CloseSocket(m_socket);
|
|
m_socket = SOCKET_ERROR;
|
|
|
|
AZStd::unique_lock<AZStd::recursive_mutex> lock(m_mutex);
|
|
for (TClients::iterator it = m_clients.begin(); it != m_clients.end(); ++it)
|
|
{
|
|
it->pClient->StopClient();
|
|
}
|
|
m_stopCondition.wait(lock, [this] { return m_clients.empty(); });
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteServer::ClientDone(SRemoteClient* pClient)
|
|
{
|
|
AZStd::scoped_lock lock(m_mutex);
|
|
for (TClients::iterator it = m_clients.begin(); it != m_clients.end(); ++it)
|
|
{
|
|
if (it->pClient == pClient)
|
|
{
|
|
delete it->pClient;
|
|
delete it->pEvents;
|
|
m_clients.erase(it);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (m_clients.empty())
|
|
{
|
|
m_stopCondition.notify_all();
|
|
}
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteServer::Terminate()
|
|
{
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteServer::Run()
|
|
{
|
|
AZ_TRAIT_REMOTECONSOLE_SET_THREAD_AFFINITY
|
|
|
|
AZSOCKET sClient;
|
|
AZ::AzSock::AzSocketAddress local;
|
|
int result = 0;
|
|
|
|
if (AZ::AzSock::SocketErrorOccured(AZ::AzSock::Startup()))
|
|
{
|
|
gEnv->pLog->LogError("[RemoteKeyboard] Failed to load Winsock!\n");
|
|
return;
|
|
}
|
|
|
|
m_socket = AZ::AzSock::Socket();
|
|
if (!AZ::AzSock::IsAzSocketValid(m_socket))
|
|
{
|
|
CryLog("Remote console FAILED. socket() => SOCKET_ERROR");
|
|
return;
|
|
}
|
|
|
|
// this CVAR is optional.
|
|
AZ::u16 remotePort = defaultRemoteConsolePort;
|
|
ICVar* remoteConsolePort = gEnv->pConsole->GetCVar("log_RemoteConsolePort");
|
|
if (remoteConsolePort)
|
|
{
|
|
remotePort = static_cast<AZ::u16>(remoteConsolePort->GetIVal());
|
|
}
|
|
|
|
//
|
|
// There may be multiple processes running, and each process will require a unique port for remote console to work.
|
|
// So we need to be able to bind to ascending ports so that automated tests can connect to each process. QA's Automated
|
|
// tools depend on this behavior for successful testing to occur.
|
|
// Please check with ly-networking, ly-systems or ly-qa before changing this.
|
|
// Thanks.
|
|
//
|
|
|
|
bool bindOk = false;
|
|
for (AZ::u16 port=remotePort; port < (remotePort + kMaxBindPorts); port++)
|
|
{
|
|
local.SetAddrPort(port);
|
|
|
|
result = AZ::AzSock::Bind(m_socket, local);
|
|
if (!AZ::AzSock::SocketErrorOccured(result))
|
|
{
|
|
bindOk = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ( !bindOk )
|
|
{
|
|
CryLog("Failed to bind Remote Console to ports %hu to %hu", remotePort, static_cast<AZ::u16>(remotePort + kMaxBindPorts - 1) );
|
|
return;
|
|
}
|
|
|
|
AZ::AzSock::Listen(m_socket, 8);
|
|
AZ::AzSock::AzSocketAddress sockName;
|
|
result = AZ::AzSock::GetSockName(m_socket, sockName);
|
|
|
|
if (!AZ::AzSock::SocketErrorOccured(result))
|
|
{
|
|
CryLog("Remote console listening on: %d\n", sockName.GetAddrPort());
|
|
}
|
|
else
|
|
{
|
|
CryLog("Remote console FAILED to listen on: %d\n", sockName.GetAddrPort());
|
|
}
|
|
|
|
while (m_bAcceptClients)
|
|
{
|
|
AZTIMEVAL timeout { 1, 0 };
|
|
if (!AZ::AzSock::IsRecvPending(m_socket, &timeout))
|
|
{
|
|
continue;
|
|
}
|
|
AZ::AzSock::AzSocketAddress clientAddress;
|
|
sClient = AZ::AzSock::Accept(m_socket, clientAddress);
|
|
if (!m_bAcceptClients || !AZ::AzSock::IsAzSocketValid(sClient))
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (!RCON_IsRemoteAllowedToConnect(clientAddress))
|
|
{
|
|
AZ::AzSock::CloseSocket(sClient);
|
|
continue;
|
|
}
|
|
|
|
AZStd::scoped_lock lock(m_mutex);
|
|
SRemoteClient* pClient = new SRemoteClient(this);
|
|
m_clients.push_back(SRemoteClientInfo(pClient));
|
|
pClient->StartClient(sClient);
|
|
}
|
|
AZ::AzSock::CloseSocket(m_socket);
|
|
CryLog("Remote console terminating.\n");
|
|
//AZ::AzSock::Shutdown();
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteServer::AddEvent(IRemoteEvent* pEvent)
|
|
{
|
|
AZStd::scoped_lock lock(m_mutex);
|
|
for (TClients::iterator it = m_clients.begin(); it != m_clients.end(); ++it)
|
|
{
|
|
it->pEvents->push_back(pEvent->Clone());
|
|
}
|
|
delete pEvent;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteServer::GetEvents(TEventBuffer& buffer)
|
|
{
|
|
AZStd::scoped_lock lock(m_mutex);
|
|
buffer = m_eventBuffer;
|
|
m_eventBuffer.clear();
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
bool SRemoteServer::WriteBuffer(SRemoteClient* pClient, char* buffer, int& size)
|
|
{
|
|
IRemoteEvent* pEvent = nullptr;
|
|
{
|
|
AZStd::scoped_lock lock(m_mutex);
|
|
for (TClients::iterator it = m_clients.begin(); it != m_clients.end(); ++it)
|
|
{
|
|
if (it->pClient == pClient)
|
|
{
|
|
TEventBuffer* pEvents = it->pEvents;
|
|
if (!pEvents->empty())
|
|
{
|
|
pEvent = pEvents->front();
|
|
pEvents->pop_front();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
const bool res = (pEvent != nullptr);
|
|
if (pEvent)
|
|
{
|
|
SRemoteEventFactory::GetInst()->WriteToBuffer(pEvent, buffer, size, kDefaultBufferSize);
|
|
delete pEvent;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
bool SRemoteServer::ReadBuffer(const char* buffer, int data)
|
|
{
|
|
bool result = true;
|
|
|
|
// Sometimes multiple events can come in a single buffer, so make sure we look
|
|
// at the entire thing.
|
|
int bytesRemaining = data;
|
|
const char* curBuffer = buffer;
|
|
while (bytesRemaining > 0)
|
|
{
|
|
// Create the event from the current sub string in the buffer.
|
|
IRemoteEvent* event = SRemoteEventFactory::GetInst()->CreateEventFromBuffer(curBuffer, bytesRemaining);
|
|
|
|
result &= (event != nullptr);
|
|
if (event)
|
|
{
|
|
if (event->GetType() != eCET_Noop)
|
|
{
|
|
AZStd::scoped_lock lock(m_mutex);
|
|
m_eventBuffer.push_back(event);
|
|
}
|
|
else
|
|
{
|
|
delete event;
|
|
}
|
|
}
|
|
|
|
// Advance to the next null terminated string in the buffer
|
|
const int currentSize = static_cast<int>(strnlen(curBuffer, bytesRemaining));
|
|
bytesRemaining -= currentSize + 1;
|
|
curBuffer += currentSize + 1;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteClient::StartClient(AZSOCKET socket)
|
|
{
|
|
m_socket = socket;
|
|
Start(kClientThreadName);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteClient::StopClient()
|
|
{
|
|
AZ::AzSock::CloseSocket(m_socket);
|
|
m_socket = AZ_SOCKET_INVALID;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteClient::Terminate()
|
|
{
|
|
m_pServer->ClientDone(this);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteClient::Run()
|
|
{
|
|
AZ_TRAIT_REMOTECONSOLE_SET_THREAD_AFFINITY
|
|
|
|
char szBuff[kDefaultBufferSize];
|
|
int size;
|
|
SNoDataEvent<eCET_Req> reqEvt;
|
|
|
|
AZStd::vector<AZStd::string> autoCompleteList;
|
|
FillAutoCompleteList(autoCompleteList);
|
|
|
|
bool ok = true;
|
|
bool autoCompleteDoneSent = false;
|
|
|
|
// Send a message that is used to verify that the Remote Console connected
|
|
SNoDataEvent<eCET_ConnectMessage> connectMessage;
|
|
SRemoteEventFactory::GetInst()->WriteToBuffer(&connectMessage, szBuff, size, kDefaultBufferSize);
|
|
ok &= SendPackage(szBuff, size);
|
|
ok &= RecvPackage(szBuff, size);
|
|
ok &= m_pServer->ReadBuffer(szBuff, size);
|
|
while (ok)
|
|
{
|
|
// read data
|
|
SRemoteEventFactory::GetInst()->WriteToBuffer(&reqEvt, szBuff, size, kDefaultBufferSize);
|
|
ok &= SendPackage(szBuff, size);
|
|
ok &= RecvPackage(szBuff, size);
|
|
ok &= m_pServer->ReadBuffer(szBuff, size);
|
|
|
|
for (int i = 0; i < 20 && !autoCompleteList.empty(); ++i)
|
|
{
|
|
SStringEvent<eCET_AutoCompleteList> autoCompleteListEvt(autoCompleteList.back().c_str());
|
|
SRemoteEventFactory::GetInst()->WriteToBuffer(&autoCompleteListEvt, szBuff, size, kDefaultBufferSize);
|
|
ok &= SendPackage(szBuff, size);
|
|
ok &= RecvPackage(szBuff, size);
|
|
ok &= m_pServer->ReadBuffer(szBuff, size);
|
|
autoCompleteList.pop_back();
|
|
}
|
|
if (autoCompleteList.empty() && !autoCompleteDoneSent)
|
|
{
|
|
SNoDataEvent<eCET_AutoCompleteListDone> autoCompleteDone;
|
|
SRemoteEventFactory::GetInst()->WriteToBuffer(&autoCompleteDone, szBuff, size, kDefaultBufferSize);
|
|
|
|
ok &= SendPackage(szBuff, size);
|
|
ok &= RecvPackage(szBuff, size);
|
|
ok &= m_pServer->ReadBuffer(szBuff, size);
|
|
autoCompleteDoneSent = true;
|
|
}
|
|
|
|
// send data
|
|
while (ok && m_pServer->WriteBuffer(this, szBuff, size))
|
|
{
|
|
ok &= SendPackage(szBuff, size);
|
|
ok &= RecvPackage(szBuff, size);
|
|
ok &= m_pServer->ReadBuffer(szBuff, size);
|
|
}
|
|
}
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
bool SRemoteClient::RecvPackage(char* buffer, int& size)
|
|
{
|
|
size = 0;
|
|
int ret, idx = 0;
|
|
do
|
|
{
|
|
ret = AZ::AzSock::Recv(m_socket, buffer + idx, kDefaultBufferSize - idx, 0);
|
|
if (AZ::AzSock::SocketErrorOccured(ret))
|
|
{
|
|
return false;
|
|
}
|
|
idx += ret;
|
|
} while (buffer[idx - 1] != '\0');
|
|
size = idx;
|
|
return true;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
bool SRemoteClient::SendPackage(const char* buffer, int size)
|
|
{
|
|
int ret, idx = 0;
|
|
int left = size + 1;
|
|
assert(buffer[size] == '\0');
|
|
while (left > 0)
|
|
{
|
|
ret = AZ::AzSock::Send(m_socket, &buffer[idx], left, 0);
|
|
if (AZ::AzSock::SocketErrorOccured(ret))
|
|
{
|
|
return false;
|
|
}
|
|
left -= ret;
|
|
idx += ret;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteClient::FillAutoCompleteList(AZStd::vector<AZStd::string>& list)
|
|
{
|
|
AZStd::vector<AZStd::string_view> cmds;
|
|
size_t count = gEnv->pConsole->GetSortedVars(cmds);
|
|
cmds.resize(count);
|
|
count = gEnv->pConsole->GetSortedVars(cmds);
|
|
for (size_t i = 0; i < count; ++i)
|
|
{
|
|
list.push_back(cmds[i]);
|
|
}
|
|
|
|
if (!gEnv->pSystem || !gEnv->pSystem->GetILevelSystem())
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0, end = gEnv->pSystem->GetILevelSystem()->GetLevelCount(); i < end; ++i)
|
|
{
|
|
ILevelInfo* pLevel = gEnv->pSystem->GetILevelSystem()->GetLevelInfo(i);
|
|
AZStd::string item = "map ";
|
|
const char* levelName = pLevel->GetName();
|
|
int start = 0;
|
|
for (int k = 0, kend = static_cast<int>(strlen(levelName)); k < kend; ++k)
|
|
{
|
|
if ((levelName[k] == '\\' || levelName[k] == '/') && k + 1 < kend)
|
|
{
|
|
start = k + 1;
|
|
}
|
|
}
|
|
item += levelName + start;
|
|
list.push_back(item);
|
|
}
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////// Event factory ///////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
#define REGISTER_EVENT_NODATA(evt) RegisterEvent(new SNoDataEvent<evt>());
|
|
#define REGISTER_EVENT_STRING(evt) RegisterEvent(new SStringEvent<evt>(""));
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
SRemoteEventFactory::SRemoteEventFactory()
|
|
{
|
|
REGISTER_EVENT_NODATA(eCET_Noop);
|
|
REGISTER_EVENT_NODATA(eCET_Req);
|
|
REGISTER_EVENT_STRING(eCET_LogMessage);
|
|
REGISTER_EVENT_STRING(eCET_LogWarning);
|
|
REGISTER_EVENT_STRING(eCET_LogError);
|
|
REGISTER_EVENT_STRING(eCET_ConsoleCommand);
|
|
REGISTER_EVENT_STRING(eCET_AutoCompleteList);
|
|
REGISTER_EVENT_NODATA(eCET_AutoCompleteListDone);
|
|
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_GetThreads);
|
|
REGISTER_EVENT_STRING(eCET_Strobo_ThreadAdd);
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_ThreadDone);
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_GetResult);
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_ResultStart);
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_ResultDone);
|
|
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_StatStart);
|
|
REGISTER_EVENT_STRING(eCET_Strobo_StatAdd);
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_ThreadInfoStart);
|
|
REGISTER_EVENT_STRING(eCET_Strobo_ThreadInfoAdd);
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_SymStart);
|
|
REGISTER_EVENT_STRING(eCET_Strobo_SymAdd);
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_CallstackStart);
|
|
REGISTER_EVENT_STRING(eCET_Strobo_CallstackAdd);
|
|
|
|
REGISTER_EVENT_STRING(eCET_GameplayEvent);
|
|
|
|
REGISTER_EVENT_NODATA(eCET_Strobo_FrameInfoStart);
|
|
REGISTER_EVENT_STRING(eCET_Strobo_FrameInfoAdd);
|
|
REGISTER_EVENT_NODATA(eCET_ConnectMessage);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
SRemoteEventFactory::~SRemoteEventFactory()
|
|
{
|
|
for (TPrototypes::iterator it = m_prototypes.begin(), end = m_prototypes.end(); it != end; ++it)
|
|
{
|
|
delete it->second;
|
|
}
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
IRemoteEvent* SRemoteEventFactory::CreateEventFromBuffer(const char* buffer, int size)
|
|
{
|
|
if (size > 1 && buffer[size - 1] == '\0')
|
|
{
|
|
EConsoleEventType type = EConsoleEventType(buffer[0] - '0');
|
|
TPrototypes::const_iterator it = m_prototypes.find(type);
|
|
if (it != m_prototypes.end())
|
|
{
|
|
IRemoteEvent* pEvent = it->second->CreateFromBuffer(buffer + 1, size - 1);
|
|
return pEvent;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteEventFactory::WriteToBuffer(IRemoteEvent* pEvent, char* buffer, int& size, int maxsize)
|
|
{
|
|
assert(m_prototypes.find(pEvent->GetType()) != m_prototypes.end());
|
|
buffer[0] = '0' + (char)pEvent->GetType();
|
|
pEvent->WriteToBuffer(buffer + 1, size, maxsize - 2);
|
|
buffer[++size] = '\0';
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SRemoteEventFactory::RegisterEvent(IRemoteEvent* pEvent)
|
|
{
|
|
assert(m_prototypes.find(pEvent->GetType()) == m_prototypes.end());
|
|
m_prototypes[pEvent->GetType()] = pEvent;
|
|
}
|