mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 16:25:35 +00:00
fix MP.GetPositionRaw
This commit is contained in:
parent
0166e488d0
commit
a4eb10b6a4
@ -53,9 +53,9 @@ std::string TClient::GetCarPositionRaw(int Ident) {
|
||||
try {
|
||||
return mVehiclePosition.at(size_t(Ident));
|
||||
} catch (const std::out_of_range& oor) {
|
||||
beammp_debugf("Failed to get vehicle position for {}: {}", Ident, oor.what());
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void TClient::Disconnect(std::string_view Reason) {
|
||||
@ -146,6 +146,8 @@ std::optional<std::weak_ptr<TClient>> GetClient(TServer& Server, int ID) {
|
||||
MaybeClient = CPtr;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
beammp_debugf("Found an expired client while looking for id {}", ID);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@ -601,7 +601,7 @@ std::pair<sol::table, std::string> TLuaEngine::StateThreadData::Lua_GetPositionR
|
||||
return Result;
|
||||
} else {
|
||||
// return std::make_tuple(sol::lua_nil, sol::make_object(StateView, "Client expired"));
|
||||
Result.second = "Client expired";
|
||||
Result.second = "No such player";
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
@ -612,7 +612,7 @@ void TNetwork::OnDisconnect(const std::weak_ptr<TClient>& ClientPtr) {
|
||||
}
|
||||
|
||||
int TNetwork::OpenID() {
|
||||
int ID = 0;
|
||||
int ID = 10;
|
||||
bool found;
|
||||
do {
|
||||
found = true;
|
||||
|
@ -238,6 +238,7 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
PPSMonitor.IncrementInternalPPS();
|
||||
Network.SendToAll(LockedClient.get(), Packet, false, false);
|
||||
HandlePosition(*LockedClient, StringPacket);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
@ -412,7 +413,7 @@ void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
|
||||
|
||||
FoundPos = VD.find('{');
|
||||
if (FoundPos == std::string::npos) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
VD = VD.substr(FoundPos);
|
||||
rapidjson::Document Veh, Pack;
|
||||
@ -451,32 +452,25 @@ void TServer::HandlePosition(TClient& c, const std::string& Packet) {
|
||||
// invalid packet
|
||||
return;
|
||||
}
|
||||
// Zp:serverVehicleID:data
|
||||
// Zp:0:data
|
||||
// Zp:PID-VID:DATA
|
||||
std::string withoutCode = Packet.substr(3);
|
||||
auto NameDataSep = withoutCode.find(':', 2);
|
||||
if (NameDataSep == std::string::npos || NameDataSep < 2) {
|
||||
// invalid packet
|
||||
return;
|
||||
}
|
||||
// FIXME: ensure that -2 does what it should... it seems weird.
|
||||
std::string ServerVehicleID = withoutCode.substr(2, NameDataSep - 2);
|
||||
if (NameDataSep + 1 > withoutCode.size()) {
|
||||
// invalid packet
|
||||
return;
|
||||
}
|
||||
std::string Data = withoutCode.substr(NameDataSep + 1);
|
||||
|
||||
// parse veh ID
|
||||
auto MaybePidVid = GetPidVid(ServerVehicleID);
|
||||
if (MaybePidVid) {
|
||||
int PID = -1;
|
||||
int VID = -1;
|
||||
// FIXME: check that the VID and PID are valid, so that we don't waste memory
|
||||
std::tie(PID, VID) = MaybePidVid.value();
|
||||
if (auto DataBeginPos = withoutCode.find('{'); DataBeginPos != std::string::npos && DataBeginPos != 0) {
|
||||
// separator is :{, so position of { minus one
|
||||
auto PidVidOnly = withoutCode.substr(0, DataBeginPos-1);
|
||||
auto MaybePidVid = GetPidVid(PidVidOnly);
|
||||
if (MaybePidVid) {
|
||||
int PID = -1;
|
||||
int VID = -1;
|
||||
// FIXME: check that the VID and PID are valid, so that we don't waste memory
|
||||
std::tie(PID, VID) = MaybePidVid.value();
|
||||
|
||||
if (auto ClientPtr = GetClient(*this, PID); ClientPtr.has_value()) {
|
||||
ClientPtr->lock()->SetCarPosition(VID, Data);
|
||||
std::string Data = withoutCode.substr(DataBeginPos);
|
||||
c.SetCarPosition(VID, Data);
|
||||
} else {
|
||||
// invalid packet
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user