Skip to content

Commit 82a2288

Browse files
authored
Fixed "reverse search for NPC id in player pool" (#1088)
1 parent 82cb5ec commit 82a2288

File tree

7 files changed

+49
-10
lines changed

7 files changed

+49
-10
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ on:
3333
jobs:
3434
build-windows:
3535
name: Windows build
36-
runs-on: windows-2019
36+
runs-on: windows-latest
3737

3838
strategy:
3939
matrix:

Server/Components/LegacyConfig/config_main.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const FlatHashMap<StringView, ParamType> types = {
6666
{ "timestamp", ParamType::Bool },
6767
{ "logtimeformat", ParamType::String },
6868
{ "logqueries", ParamType::Bool },
69-
{ "chatlogging", ParamType::Bool },
69+
{ "chatlogging", ParamType::Custom },
7070
{ "db_logging", ParamType::Bool },
7171
{ "db_log_queries", ParamType::Bool },
7272
{ "onfoot_rate", ParamType::Int },
@@ -209,6 +209,30 @@ class LegacyConfigComponent final : public ILegacyConfigComponent, public Consol
209209
return true;
210210
}
211211

212+
if (name.find("chatlogging") == 0)
213+
{
214+
auto it = dictionary.find("chatlogging");
215+
216+
Impl::String lower(right);
217+
std::transform(lower.begin(), lower.end(), lower.begin(), [](unsigned char c)
218+
{
219+
return std::tolower(c);
220+
});
221+
222+
if (lower == "true" || lower == "1")
223+
{
224+
config.setBool(it->second, true);
225+
config.setBool("logging.log_deaths", true);
226+
}
227+
else if (lower == "false" || lower == "0")
228+
{
229+
config.setBool(it->second, false);
230+
config.setBool("logging.log_deaths", false);
231+
}
232+
233+
return true;
234+
}
235+
212236
return false;
213237
}
214238

Server/Components/Vehicles/vehicle.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,11 @@ bool Vehicle::isDead()
685685

686686
void Vehicle::_respawn()
687687
{
688-
respawning = true;
688+
if (!isTrainCarriage())
689+
{
690+
respawning = true;
691+
}
692+
689693
const auto& entries = streamedFor_.entries();
690694
for (IPlayer* player : entries)
691695
{

Server/Components/Vehicles/vehicle.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ class Vehicle final : public IVehicle, public PoolIDProvider, public NoCopy
4848
uint8_t landingGear = 1;
4949
bool respawning = false;
5050
bool detaching = false;
51+
bool beenOccupied = false;
5152
FlatHashSet<IPlayer*> passengers;
5253
HybridString<16> numberPlate = StringView("XYZSR998");
5354
uint8_t objective;
5455
uint8_t doorsLocked;
56+
uint8_t sirenState = 0;
5557
VehicleDeathData deathData;
5658
TimePoint timeOfSpawn;
5759
TimePoint lastOccupiedChange;
58-
bool beenOccupied = false;
5960
Vector3 velocity = Vector3(0.0f, 0.0f, 0.0f);
6061
Vector3 angularVelocity = Vector3(0.0f, 0.0f, 0.0f);
6162
TimePoint trailerUpdateTime;
6263
Vehicle* trailer = nullptr;
6364
Vehicle* cab = nullptr;
6465
StaticArray<IVehicle*, MAX_VEHICLE_CARRIAGES> carriages;
6566
VehicleParams params;
66-
uint8_t sirenState = 0;
6767
uint32_t hydraThrustAngle = 0;
6868
float trainSpeed = 0.0f;
6969
int lastDriverPoolID = INVALID_PLAYER_ID;
@@ -391,6 +391,12 @@ class Vehicle final : public IVehicle, public PoolIDProvider, public NoCopy
391391
return carriages;
392392
}
393393

394+
bool isTrainCarriage()
395+
{
396+
const int model = getModel();
397+
return (model == 569 || model == 570);
398+
}
399+
394400
/// Sets the velocity of the vehicle.
395401
void setVelocity(Vector3 velocity) override;
396402

Server/Components/Vehicles/vehicles_impl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class VehiclesComponent final : public IVehiclesComponent, public CoreEventHandl
4848
return false;
4949
}
5050

51-
if (!lock.entry->isStreamedInForPlayer(peer) || peer.getState() != PlayerState_OnFoot)
51+
Vehicle* lockedVehicle = static_cast<Vehicle*>(lock.entry);
52+
if ((!lockedVehicle->isStreamedInForPlayer(peer) && !lockedVehicle->isTrainCarriage()) || peer.getState() != PlayerState_OnFoot)
5253
{
5354
return false;
5455
}
@@ -90,8 +91,9 @@ class VehiclesComponent final : public IVehiclesComponent, public CoreEventHandl
9091
return false;
9192
}
9293

94+
Vehicle* lockedVehicle = static_cast<Vehicle*>(lock.entry);
9395
IPlayerVehicleData* vehData = queryExtension<IPlayerVehicleData>(peer);
94-
if (vehData == nullptr || !lock.entry->isStreamedInForPlayer(peer) || !(peer.getState() == PlayerState_Driver || peer.getState() == PlayerState_Passenger) || vehData->getVehicle() != lock.entry)
96+
if (vehData == nullptr || (!lockedVehicle->isStreamedInForPlayer(peer) && !lockedVehicle->isTrainCarriage()) || !(peer.getState() == PlayerState_Driver || peer.getState() == PlayerState_Passenger) || vehData->getVehicle() != lock.entry)
9597
{
9698
return false;
9799
}

Server/Source/player_pool.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,9 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
13901390
Player& player = static_cast<Player&>(peer);
13911391

13921392
if (vehicle.isRespawning())
1393+
{
13931394
return false;
1395+
}
13941396

13951397
const bool vehicleOk = vehicle.updateFromPassengerSync(passengerSync, peer);
13961398

@@ -1695,7 +1697,8 @@ struct PlayerPool final : public IPlayerPool, public NetworkEventHandler, public
16951697

16961698
if (params.bot)
16971699
{
1698-
for (auto index = storage.Capacity - 1; index >= 0; --index)
1700+
static const auto maxPlayers = core.getConfig().getInt("max_players");
1701+
for (auto index = *maxPlayers - 1; index >= 0; --index)
16991702
{
17001703
if (storage.get(index) == nullptr)
17011704
{

Shared/NetCode/vehicle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ namespace RPC
111111
float Angle;
112112
uint8_t Colour1;
113113
uint8_t Colour2;
114-
float Health;
115114
uint8_t Interior;
115+
uint8_t Paintjob;
116+
float Health;
116117
uint32_t DoorDamage;
117118
uint32_t PanelDamage;
118119
uint8_t LightDamage;
119120
uint8_t TyreDamage;
120121
uint8_t Siren;
121122
StaticArray<int, MAX_VEHICLE_COMPONENT_SLOT_IN_RPC> Mods;
122-
uint8_t Paintjob;
123123
int32_t BodyColour1;
124124
int32_t BodyColour2;
125125

0 commit comments

Comments
 (0)