update lk-result

This commit is contained in:
Lion Kortlepel 2022-11-13 02:24:59 +01:00
parent b756ce3c3f
commit a8ad9034b2
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
4 changed files with 13 additions and 10 deletions

View File

@ -158,6 +158,7 @@ set(BeamMP_Includes
set(BeamMP_Definitions set(BeamMP_Definitions
SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}" SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}"
BEAMMP_GIT_HASH="${GIT_HASH}" BEAMMP_GIT_HASH="${GIT_HASH}"
LK_RESULT_USE_FMT
) )
if (WIN32) if (WIN32)

2
deps/lk-result vendored

@ -1 +1 @@
Subproject commit c312b20090b07f1fce55630cb4f88c44e30b7f8a Subproject commit 4a4eda8092d99ba39bd0faa76e928f62f1781c1f

View File

@ -32,6 +32,12 @@ namespace fs = std::filesystem;
using TimeType = std::chrono::system_clock; using TimeType = std::chrono::system_clock;
#include <lk/Result.h>
template <typename T>
using Result = lk::Result<T>;
using Error = lk::Error;
// General // General
constexpr std::string_view StrDebug = "Debug"; constexpr std::string_view StrDebug = "Debug";
constexpr std::string_view StrPrivate = "Private"; constexpr std::string_view StrPrivate = "Private";

View File

@ -7,9 +7,8 @@
#include <TLuaPlugin.h> #include <TLuaPlugin.h>
#include <algorithm> #include <algorithm>
#include <any> #include <any>
#include <sstream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <sstream>
#include "LuaAPI.h" #include "LuaAPI.h"
@ -23,11 +22,10 @@ struct VehiclePacket {
int Vid; int Vid;
}; };
static std::optional<std::pair<int, int>> GetPidVid(const std::string& str) { static Result<std::pair<int, int>> GetPidVid(const std::string& str) {
auto IDSep = str.find('-'); auto IDSep = str.find('-');
if (IDSep == std::string::npos) { if (IDSep == std::string::npos) {
beammp_debugf("Invalid packet: Could not parse pid/vid from packet, as there is no '-' separator: '{}'", str); return Error("Invalid packet: Could not parse pid/vid from packet, as there is no '-' separator: '{}'", str);
return std::nullopt;
} }
std::string pid = str.substr(0, IDSep); std::string pid = str.substr(0, IDSep);
std::string vid = str.substr(IDSep + 1); std::string vid = str.substr(IDSep + 1);
@ -38,12 +36,10 @@ static std::optional<std::pair<int, int>> GetPidVid(const std::string& str) {
int VID = std::stoi(vid); int VID = std::stoi(vid);
return { { PID, VID } }; return { { PID, VID } };
} catch (const std::exception&) { } catch (const std::exception&) {
beammp_debugf("Invalid packet: Could not parse pid/vid from packet, as one or both are not valid numbers: '{}'", str); return Error("Invalid packet: Could not parse pid/vid from packet, as one or both are not valid numbers: '{}'", str);
return std::nullopt;
} }
} }
beammp_debugf("Invalid packet: Could not parse pid/vid from packet: '{}'", str); return Error("Invalid packet: Could not parse pid/vid from packet: '{}'", str);
return std::nullopt;
} }
static std::optional<VehiclePacket> ParseVehiclePacket(const std::string& Packet, const int playerID) { static std::optional<VehiclePacket> ParseVehiclePacket(const std::string& Packet, const int playerID) {