mirror of https://github.com/OpenRCT2/OpenRCT2.git
refactor NetworkPlayer
This commit is contained in:
parent
3591026078
commit
623318a35d
|
@ -89,6 +89,7 @@
|
|||
<ClCompile Include="src\network\NetworkGroup.cpp" />
|
||||
<ClCompile Include="src\network\NetworkKey.cpp" />
|
||||
<ClCompile Include="src\network\NetworkPacket.cpp" />
|
||||
<ClCompile Include="src\network\NetworkPlayer.cpp" />
|
||||
<ClCompile Include="src\network\NetworkUser.cpp" />
|
||||
<ClCompile Include="src\network\twitch.cpp" />
|
||||
<ClCompile Include="src\object.c" />
|
||||
|
@ -368,6 +369,7 @@
|
|||
<ClInclude Include="src\network\NetworkConnection.h" />
|
||||
<ClInclude Include="src\network\NetworkGroup.h" />
|
||||
<ClInclude Include="src\network\NetworkPacket.h" />
|
||||
<ClInclude Include="src\network\NetworkPlayer.h" />
|
||||
<ClInclude Include="src\network\NetworkTypes.h" />
|
||||
<ClInclude Include="src\network\NetworkUser.h" />
|
||||
<ClInclude Include="src\network\twitch.h" />
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* 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
|
||||
|
||||
#include "NetworkPacket.h"
|
||||
#include "NetworkPlayer.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../interface/window.h"
|
||||
#include "../localisation/localisation.h"
|
||||
}
|
||||
|
||||
void NetworkPlayer::SetName(const std::string &name)
|
||||
{
|
||||
// 36 == 31 + strlen(" #255");
|
||||
NetworkPlayer::name = name.substr(0, 36);
|
||||
utf8_remove_format_codes((utf8 *)NetworkPlayer::name.data(), false);
|
||||
}
|
||||
|
||||
void NetworkPlayer::Read(NetworkPacket &packet)
|
||||
{
|
||||
const utf8 * name = packet.ReadString();
|
||||
SetName(name);
|
||||
packet >> id >> flags >> group;
|
||||
}
|
||||
|
||||
void NetworkPlayer::Write(NetworkPacket &packet)
|
||||
{
|
||||
packet.WriteString((const char*)name.c_str());
|
||||
packet << id << flags << group;
|
||||
}
|
||||
|
||||
void NetworkPlayer::AddMoneySpent(money32 cost)
|
||||
{
|
||||
money_spent += cost;
|
||||
commands_ran++;
|
||||
window_invalidate_by_number(WC_PLAYER, id);
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
||||
/*****************************************************************************
|
||||
* 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "../common.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../world/map.h"
|
||||
}
|
||||
|
||||
class NetworkPacket;
|
||||
|
||||
class NetworkPlayer
|
||||
{
|
||||
public:
|
||||
uint8 id = 0;
|
||||
std::string name;
|
||||
uint16 ping = 0;
|
||||
uint8 flags = 0;
|
||||
uint8 group = 0;
|
||||
money32 money_spent = MONEY(0, 0);
|
||||
uint32 commands_ran = 0;
|
||||
int last_action = -999;
|
||||
uint32 last_action_time = 0;
|
||||
rct_xyz16 last_action_coord = { 0 };
|
||||
std::string keyhash;
|
||||
|
||||
NetworkPlayer() = default;
|
||||
|
||||
void SetName(const std::string &name);
|
||||
|
||||
void Read(NetworkPacket &packet);
|
||||
void Write(NetworkPacket &packet);
|
||||
void AddMoneySpent(money32 cost);
|
||||
};
|
|
@ -90,33 +90,6 @@ static void network_get_private_key_path(utf8 *buffer, size_t bufferSize, const
|
|||
static void network_get_public_key_path(utf8 *buffer, size_t bufferSize, const utf8 * playerName, const utf8 * hash);
|
||||
static void network_get_keymap_path(utf8 *buffer, size_t bufferSize);
|
||||
|
||||
void NetworkPlayer::Read(NetworkPacket& packet)
|
||||
{
|
||||
const char* name = packet.ReadString();
|
||||
SetName(name);
|
||||
packet >> id >> flags >> group;
|
||||
}
|
||||
|
||||
void NetworkPlayer::Write(NetworkPacket& packet)
|
||||
{
|
||||
packet.WriteString((const char*)name.c_str());
|
||||
packet << id << flags << group;
|
||||
}
|
||||
|
||||
void NetworkPlayer::SetName(const std::string &name)
|
||||
{
|
||||
// 36 == 31 + strlen(" #255");
|
||||
NetworkPlayer::name = name.substr(0, 36);
|
||||
utf8_remove_format_codes((utf8*)NetworkPlayer::name.data(), false);
|
||||
}
|
||||
|
||||
void NetworkPlayer::AddMoneySpent(money32 cost)
|
||||
{
|
||||
money_spent += cost;
|
||||
commands_ran++;
|
||||
window_invalidate_by_number(WC_PLAYER, id);
|
||||
}
|
||||
|
||||
Network::Network()
|
||||
{
|
||||
wsa_initialized = false;
|
||||
|
|
|
@ -81,29 +81,9 @@ extern "C" {
|
|||
#include "NetworkGroup.h"
|
||||
#include "NetworkKey.h"
|
||||
#include "NetworkPacket.h"
|
||||
#include "NetworkPlayer.h"
|
||||
#include "NetworkUser.h"
|
||||
|
||||
class NetworkPlayer
|
||||
{
|
||||
public:
|
||||
NetworkPlayer() = default;
|
||||
void Read(NetworkPacket& packet);
|
||||
void Write(NetworkPacket& packet);
|
||||
void SetName(const std::string &name);
|
||||
void AddMoneySpent(money32 cost);
|
||||
uint8 id = 0;
|
||||
std::string name;
|
||||
uint16 ping = 0;
|
||||
uint8 flags = 0;
|
||||
uint8 group = 0;
|
||||
money32 money_spent = MONEY(0, 0);
|
||||
unsigned int commands_ran = 0;
|
||||
int last_action = -999;
|
||||
uint32 last_action_time = 0;
|
||||
rct_xyz16 last_action_coord = { 0 };
|
||||
std::string keyhash;
|
||||
};
|
||||
|
||||
class Network
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue