OpenRCT2/src/openrct2/network/NetworkPlayer.cpp

47 lines
1.4 KiB
C++
Raw Normal View History

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
*
* 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
*
* 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
2018-06-22 23:02:47 +02:00
void NetworkPlayer::SetName(const std::string& 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
{
2018-06-22 23:02:47 +02:00
const utf8* name = packet.ReadString();
2016-05-28 19:45:39 +02:00
SetName(name);
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
{
packet.WriteString(static_cast<const char*>(Name.c_str()));
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