OpenRCT2/src/openrct2/network/NetworkPlayer.cpp

53 lines
1.5 KiB
C++
Raw Normal View History

#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
2016-05-28 19:45:39 +02:00
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
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