2016-05-28 19:45:39 +02:00
|
|
|
/*****************************************************************************
|
2018-06-15 14:07:34 +02:00
|
|
|
* Copyright (c) 2014-2018 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
|
|
|
|
|
2016-05-28 19:45:39 +02:00
|
|
|
#include "NetworkPacket.h"
|
|
|
|
#include "NetworkPlayer.h"
|
|
|
|
|
2018-01-06 01:05:16 +01:00
|
|
|
#include "../interface/Window.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "../localisation/Localisation.h"
|
2016-05-28 19:45:39 +02:00
|
|
|
|
|
|
|
void NetworkPlayer::SetName(const std::string &name)
|
|
|
|
{
|
|
|
|
// 36 == 31 + strlen(" #255");
|
2017-01-12 14:23:16 +01:00
|
|
|
Name = name.substr(0, 36);
|
|
|
|
utf8_remove_format_codes((utf8 *)Name.data(), false);
|
2016-05-28 19:45:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkPlayer::Read(NetworkPacket &packet)
|
|
|
|
{
|
|
|
|
const utf8 * name = packet.ReadString();
|
|
|
|
SetName(name);
|
2017-01-12 14:23:16 +01:00
|
|
|
packet >> Id >> Flags >> Group;
|
2016-05-28 19:45:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkPlayer::Write(NetworkPacket &packet)
|
|
|
|
{
|
2017-01-12 14:23:16 +01:00
|
|
|
packet.WriteString((const char*)Name.c_str());
|
|
|
|
packet << Id << Flags << Group;
|
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
|