2016-05-28 19:45:39 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2016-05-28 19:45:39 +02: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 19:45:39 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-28 19:45:39 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-05-28 23:27:08 +02:00
|
|
|
#ifndef DISABLE_NETWORK
|
|
|
|
|
2018-07-21 16:17:06 +02:00
|
|
|
# include "NetworkPlayer.h"
|
2016-05-28 19:45:39 +02:00
|
|
|
|
2018-07-21 16:17:06 +02:00
|
|
|
# include "../interface/Window.h"
|
|
|
|
# include "../localisation/Localisation.h"
|
|
|
|
# include "NetworkPacket.h"
|
2016-05-28 19:45:39 +02:00
|
|
|
|
2021-09-17 22:46:58 +02:00
|
|
|
void NetworkPlayer::SetName(std::string_view name)
|
2016-05-28 19:45:39 +02:00
|
|
|
{
|
|
|
|
// 36 == 31 + strlen(" #255");
|
2017-01-12 14:23:16 +01:00
|
|
|
Name = name.substr(0, 36);
|
2016-05-28 19:45:39 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:02:47 +02:00
|
|
|
void NetworkPlayer::Read(NetworkPacket& packet)
|
2016-05-28 19:45:39 +02:00
|
|
|
{
|
2021-09-17 22:46:58 +02:00
|
|
|
auto name = packet.ReadString();
|
2016-05-28 19:45:39 +02: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 19:45:39 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:02:47 +02:00
|
|
|
void NetworkPlayer::Write(NetworkPacket& packet)
|
2016-05-28 19:45:39 +02:00
|
|
|
{
|
2020-04-22 17:09:29 +02:00
|
|
|
packet.WriteString(static_cast<const char*>(Name.c_str()));
|
2019-02-28 20:15:11 +01:00
|
|
|
packet << Id << Flags << Group << LastAction << LastActionCoord.x << LastActionCoord.y << LastActionCoord.z << MoneySpent
|
|
|
|
<< CommandsRan;
|
2016-05-28 19:45:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkPlayer::AddMoneySpent(money32 cost)
|
|
|
|
{
|
2017-01-12 14:23:16 +01:00
|
|
|
MoneySpent += cost;
|
|
|
|
CommandsRan++;
|
|
|
|
window_invalidate_by_number(WC_PLAYER, Id);
|
2016-05-28 19:45:39 +02:00
|
|
|
}
|
2016-05-28 23:27:08 +02:00
|
|
|
|
|
|
|
#endif
|