-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(devtools): add a server version of neteventlog #1748
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#include <StdInc.h> | ||
|
||
#ifndef IS_FXSERVER | ||
#include <ResourceEventComponent.h> | ||
#include <ResourceManager.h> | ||
|
||
#ifndef IS_FXSERVER | ||
#include <NetLibrary.h> | ||
|
||
#endif | ||
#include <boost/circular_buffer.hpp> | ||
|
||
#include <ConsoleHost.h> | ||
|
@@ -18,17 +18,27 @@ struct EventLogEntry | |
std::string eventName; | ||
size_t payloadSize; | ||
bool out; | ||
std::optional<std::string> eventSource; | ||
}; | ||
|
||
static boost::circular_buffer<EventLogEntry> g_eventLog(150); | ||
static boost::circular_buffer<EventLogEntry> g_eventLog( | ||
// We want a bigger buffer on the server because it will send/receive *a lot* more events, and 150 will quickly get filled | ||
#if IS_FXSERVER | ||
600 | ||
#else | ||
150 | ||
#endif | ||
); | ||
static std::mutex g_eventLogMutex; | ||
|
||
static void EventLog_Add(const std::string& eventName, size_t payloadSize, bool out) | ||
static void EventLog_Add(const std::string& eventName, size_t payloadSize, bool out, std::optional<std::string> eventSource = std::nullopt) | ||
{ | ||
EventLogEntry eve; | ||
eve.eventName = eventName; | ||
eve.payloadSize = payloadSize; | ||
eve.out = out; | ||
// this should always be nullopt on client | ||
eve.eventSource = eventSource; | ||
|
||
std::unique_lock<std::mutex> lock(g_eventLogMutex); | ||
g_eventLog.push_front(std::move(eve)); | ||
|
@@ -55,24 +65,46 @@ static InitFunction initFunction([]() | |
|
||
if (ImGui::Begin("Network Event Log", &eventLogEnabled)) | ||
{ | ||
ImGui::Columns(3); | ||
// If we're on the server we're going to have the "Sender/Receiver" field so we need an extra column | ||
ImGui::Columns( | ||
#ifdef IS_FXSERVER | ||
4 | ||
#else | ||
3 | ||
#endif | ||
); | ||
|
||
{ | ||
ImGui::Text("Dir"); | ||
ImGui::NextColumn(); | ||
ImGui::Text("Name"); | ||
ImGui::NextColumn(); | ||
#ifdef IS_FXSERVER | ||
ImGui::Text("Sender/Receiver"); | ||
ImGui::NextColumn(); | ||
#endif | ||
ImGui::Text("Size"); | ||
ImGui::NextColumn(); | ||
|
||
std::unique_lock<std::mutex> lock(g_eventLogMutex); | ||
|
||
for (auto& entry : g_eventLog) | ||
{ | ||
ImGui::Text((entry.out) ? "C->S" : "S->C"); | ||
|
||
ImGui::Text( | ||
#ifndef IS_FXSERVER | ||
(entry.out) ? "C->S" : "S->C" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One could rename |
||
#else | ||
(entry.out) ? "S->C" : "C->S" | ||
#endif | ||
); | ||
ImGui::NextColumn(); | ||
ImGui::Text("%s", entry.eventName.c_str()); | ||
ImGui::NextColumn(); | ||
#if IS_FXSERVER | ||
ImGui::Text("%s", entry.eventSource.value_or("server").c_str()); | ||
ImGui::NextColumn(); | ||
#endif | ||
ImGui::Text("%lld B", entry.payloadSize); | ||
ImGui::NextColumn(); | ||
} | ||
|
@@ -92,17 +124,30 @@ static InitFunction initFunction([]() | |
{ | ||
if (eventSource.find("net:") == 0) | ||
{ | ||
#if IS_FXSERVER | ||
EventLog_Add(eventName, eventPayload.size(), false, std::optional{ eventSource.substr(4) }); | ||
#else | ||
EventLog_Add(eventName, eventPayload.size(), false); | ||
#endif | ||
|
||
} | ||
}); | ||
|
||
eventManager->OnClientEventTriggered.Connect([](const std::string_view& eventName, size_t& eventSize, const std::optional<std::string_view>& eventTarget) | ||
{ | ||
EventLog_Add(std::string{ eventName }, eventSize, true, std::string{ eventTarget.value_or("-1") }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of showing the target as a number, maybe showing their name (plus a shortcut to the (similarly, instead of enabling this for the server in |
||
}); | ||
|
||
}, INT32_MAX); | ||
|
||
#ifndef IS_FXSERVER | ||
NetLibrary::OnNetLibraryCreate.Connect([](NetLibrary* library) | ||
{ | ||
library->OnTriggerServerEvent.Connect([](const std::string& eventName, const std::string& eventPayload) | ||
{ | ||
EventLog_Add(eventName, eventPayload.size(), true); | ||
}); | ||
}); | ||
}); | ||
#endif | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,9 @@ class RESOURCES_CORE_EXPORT ResourceEventManagerComponent : public fwRefCountabl | |
// | ||
fwEvent<const std::string&, const std::string&, const std::string&> OnQueueEvent; | ||
|
||
// Arguments: eventName, eventPayloadSize, eventSource | ||
fwEvent<const std::string_view&, size_t&, const std::optional<std::string_view>&> OnClientEventTriggered; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little odd as the concept of server->client events only exists on the server and is part of ServerResources - I wonder if there'd be a better place for this callout across components, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ServerEventComponent might be a better place to put something like this and just change the initialization to |
||
|
||
// | ||
// Triggers an event immediately. Returns a value indicating whether the event was not canceled. | ||
// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For moving this to citizen:server:gui, instead of this, the global define guard would instead be like
#if !defined(IS_FXSERVER) || defined(COMPILING_CITIZEN_SERVER_GUI)
.