1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-26 00:04:43 +01:00
Files
OpenRCT2/src/openrct2/scripting/bindings/network/ScPlayer.cpp
James103 73738bbdc8 Replace 2022 with 2023 in copyright headers
Replace all instances of the year 2022 with 2023 in all copyright headers
2023-01-01 11:58:01 +01:00

123 lines
3.4 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2023 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#ifdef ENABLE_SCRIPTING
# include "ScPlayer.hpp"
# include "../../../Context.h"
# include "../../../actions/PlayerSetGroupAction.h"
# include "../../../network/NetworkAction.h"
# include "../../../network/network.h"
namespace OpenRCT2::Scripting
{
ScPlayer::ScPlayer(int32_t id)
: _id(id)
{
}
int32_t ScPlayer::id_get() const
{
return _id;
}
std::string ScPlayer::name_get() const
{
# ifndef DISABLE_NETWORK
auto index = network_get_player_index(_id);
if (index == -1)
return {};
return network_get_player_name(index);
# else
return {};
# endif
}
int32_t ScPlayer::group_get() const
{
# ifndef DISABLE_NETWORK
auto index = network_get_player_index(_id);
if (index == -1)
return {};
return network_get_player_group(index);
# else
return 0;
# endif
}
void ScPlayer::group_set(int32_t value)
{
# ifndef DISABLE_NETWORK
auto playerSetGroupAction = PlayerSetGroupAction(_id, value);
GameActions::Execute(&playerSetGroupAction);
# endif
}
int32_t ScPlayer::ping_get() const
{
# ifndef DISABLE_NETWORK
auto index = network_get_player_index(_id);
if (index == -1)
return {};
return network_get_player_ping(index);
# else
return 0;
# endif
}
int32_t ScPlayer::commandsRan_get() const
{
# ifndef DISABLE_NETWORK
auto index = network_get_player_index(_id);
if (index == -1)
return {};
return network_get_player_commands_ran(index);
# else
return 0;
# endif
}
int32_t ScPlayer::moneySpent_get() const
{
# ifndef DISABLE_NETWORK
auto index = network_get_player_index(_id);
if (index == -1)
return {};
return network_get_player_money_spent(index);
# else
return 0;
# endif
}
std::string ScPlayer::ipAddress_get() const
{
return network_get_player_ip_address(_id);
}
std::string ScPlayer::publicKeyHash_get() const
{
return network_get_player_public_key_hash(_id);
}
void ScPlayer::Register(duk_context* ctx)
{
dukglue_register_property(ctx, &ScPlayer::id_get, nullptr, "id");
dukglue_register_property(ctx, &ScPlayer::name_get, nullptr, "name");
dukglue_register_property(ctx, &ScPlayer::group_get, &ScPlayer::group_set, "group");
dukglue_register_property(ctx, &ScPlayer::ping_get, nullptr, "ping");
dukglue_register_property(ctx, &ScPlayer::commandsRan_get, nullptr, "commandsRan");
dukglue_register_property(ctx, &ScPlayer::moneySpent_get, nullptr, "moneySpent");
dukglue_register_property(ctx, &ScPlayer::ipAddress_get, nullptr, "ipAddress");
dukglue_register_property(ctx, &ScPlayer::publicKeyHash_get, nullptr, "publicKeyHash");
}
} // namespace OpenRCT2::Scripting
#endif