Compat: fix clash with socket() macro, Sentry: Add LogDebug

This commit is contained in:
Lion Kortlepel 2021-08-10 12:23:36 +02:00 committed by Lion
parent 72950fdab2
commit 51e662fdda
4 changed files with 18 additions and 6 deletions

View File

@ -12,9 +12,9 @@ using DWORD = unsigned long;
using PDWORD = unsigned long*; using PDWORD = unsigned long*;
using LPDWORD = unsigned long*; using LPDWORD = unsigned long*;
char _getch(); char _getch();
inline void CloseSocketProper(int socket) { inline void CloseSocketProper(int TheSocket) {
shutdown(socket, SHUT_RDWR); shutdown(TheSocket, SHUT_RDWR);
close(socket); close(TheSocket);
} }
#endif // unix #endif // unix
@ -23,9 +23,9 @@ inline void CloseSocketProper(int socket) {
#ifdef WIN32 #ifdef WIN32
#include <conio.h> #include <conio.h>
#include <winsock2.h> #include <winsock2.h>
inline void CloseSocketProper(SOCKET socket) { inline void CloseSocketProper(SOCKET TheSocket) {
shutdown(socket, SD_BOTH); shutdown(TheSocket, SD_BOTH);
closesocket(socket); closesocket(TheSocket);
} }
#endif // WIN32 #endif // WIN32

View File

@ -4,6 +4,7 @@
#include <sentry.h> #include <sentry.h>
#include <string> #include <string>
#include <mutex>
// TODO possibly use attach_stacktrace // TODO possibly use attach_stacktrace
@ -16,6 +17,7 @@ public:
void PrintWelcome(); void PrintWelcome();
void SetupUser(); void SetupUser();
void Log(sentry_level_t level, const std::string& logger, const std::string& text); void Log(sentry_level_t level, const std::string& logger, const std::string& text);
void LogDebug(const std::string& text, const std::string& file, const std::string& line);
void AddExtra(const std::string& key, const sentry_value_t& value); void AddExtra(const std::string& key, const sentry_value_t& value);
void AddExtra(const std::string& key, const std::string& value); void AddExtra(const std::string& key, const std::string& value);
void LogException(const std::exception& e, const std::string& file, const std::string& line); void LogException(const std::exception& e, const std::string& file, const std::string& line);
@ -25,6 +27,7 @@ public:
private: private:
bool mValid { true }; bool mValid { true };
std::mutex mMutex;
}; };
#endif // SENTRY_H #endif // SENTRY_H

View File

@ -45,6 +45,11 @@ void TSentry::Log(sentry_level_t level, const std::string& logger, const std::st
sentry_remove_transaction(); sentry_remove_transaction();
} }
void TSentry::LogDebug(const std::string& text, const std::string& file, const std::string& line) {
SetTransaction(file + ":" + line);
Log(SENTRY_LEVEL_DEBUG, "default", file + ": " + text);
}
void TSentry::AddExtra(const std::string& key, const sentry_value_t& value) { void TSentry::AddExtra(const std::string& key, const sentry_value_t& value) {
if (!mValid) { if (!mValid) {
return; return;

View File

@ -323,6 +323,10 @@ void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
std::string VD = c.GetCarData(VID); std::string VD = c.GetCarData(VID);
if (VD.empty()) { if (VD.empty()) {
error("Tried to apply change to vehicle that does not exist"); error("Tried to apply change to vehicle that does not exist");
Sentry.AddExtra("packet", Packet);
Sentry.AddExtra("vehicle-id", std::to_string(VID));
Sentry.AddExtra("client-car-count", std::to_string(c.GetCarCount()));
Sentry.LogDebug("attempt to apply change to nonexistent vehicle", _file_basename, _line);
return; return;
} }
std::string Header = VD.substr(0, VD.find('{')); std::string Header = VD.substr(0, VD.find('{'));