2016-05-28 18:45:39 +01:00
|
|
|
/*****************************************************************************
|
2023-01-01 04:58:01 -06:00
|
|
|
* Copyright (c) 2014-2023 OpenRCT2 developers
|
2016-05-28 18:45:39 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-05-28 18:45:39 +01:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-28 18:45:39 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2016-05-28 22:27:08 +01:00
|
|
|
#ifndef DISABLE_NETWORK
|
|
|
|
|
|
2018-07-21 16:17:06 +02:00
|
|
|
# include "NetworkPlayer.h"
|
2016-05-28 18:45:39 +01:00
|
|
|
|
2018-07-21 16:17:06 +02:00
|
|
|
# include "../interface/Window.h"
|
|
|
|
|
# include "../localisation/Localisation.h"
|
|
|
|
|
# include "NetworkPacket.h"
|
2016-05-28 18:45:39 +01:00
|
|
|
|
2021-09-17 23:46:58 +03:00
|
|
|
void NetworkPlayer::SetName(std::string_view name)
|
2016-05-28 18:45:39 +01:00
|
|
|
{
|
|
|
|
|
// 36 == 31 + strlen(" #255");
|
2017-01-12 13:23:16 +00:00
|
|
|
Name = name.substr(0, 36);
|
2016-05-28 18:45:39 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:02:47 +02:00
|
|
|
void NetworkPlayer::Read(NetworkPacket& packet)
|
2016-05-28 18:45:39 +01:00
|
|
|
{
|
2021-09-17 23:46:58 +03:00
|
|
|
auto name = packet.ReadString();
|
2016-05-28 18:45:39 +01:00
|
|
|
SetName(name);
|
2019-02-28 20:15:11 +01:00
|
|
|
packet >> Id >> Flags >> Group >> LastAction >> LastActionCoord.x >> LastActionCoord.y >> LastActionCoord.z >> MoneySpent
|
|
|
|
|
>> CommandsRan;
|
2016-05-28 18:45:39 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:02:47 +02:00
|
|
|
void NetworkPlayer::Write(NetworkPacket& packet)
|
2016-05-28 18:45:39 +01:00
|
|
|
{
|
2022-02-10 05:57:25 +09:00
|
|
|
packet.WriteString(Name);
|
2019-02-28 20:15:11 +01:00
|
|
|
packet << Id << Flags << Group << LastAction << LastActionCoord.x << LastActionCoord.y << LastActionCoord.z << MoneySpent
|
|
|
|
|
<< CommandsRan;
|
2016-05-28 18:45:39 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-07 08:19:27 +02:00
|
|
|
void NetworkPlayer::IncrementNumCommands()
|
2016-05-28 18:45:39 +01:00
|
|
|
{
|
2017-01-12 13:23:16 +00:00
|
|
|
CommandsRan++;
|
2023-01-16 21:13:42 +01:00
|
|
|
WindowInvalidateByNumber(WindowClass::Player, Id);
|
2016-05-28 18:45:39 +01:00
|
|
|
}
|
2016-05-28 22:27:08 +01:00
|
|
|
|
2023-09-07 08:19:27 +02:00
|
|
|
void NetworkPlayer::AddMoneySpent(money64 cost)
|
|
|
|
|
{
|
|
|
|
|
MoneySpent += cost;
|
|
|
|
|
WindowInvalidateByNumber(WindowClass::Player, Id);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-28 22:27:08 +01:00
|
|
|
#endif
|