mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-09 13:01:29 -10:00
* multi pxo api (cherry picked from commit 9af26da728a19b9d6c890968a314e8e56ecc1ddf) * multi pxo help api (cherry picked from commit f4df704576ddb648e9c486907b07ae172c859feb) * minor fixes * not extern * break out chat message data into a table * address some feedback * return empty strings if not in multi * use GetChannelByUser() instead * once more with feeling * correct documentation
135 lines
3.2 KiB
C++
135 lines
3.2 KiB
C++
#include "multi_objects.h"
|
|
|
|
#include "network/multi_pxo.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
channel_h::channel_h() : channel(-1) {}
|
|
channel_h::channel_h(int l_channel) : channel(l_channel) {}
|
|
|
|
pxo_channel* channel_h::getChannel() const
|
|
{
|
|
if (!isValid())
|
|
return nullptr;
|
|
|
|
return &Multi_pxo_channels[channel];
|
|
}
|
|
|
|
bool channel_h::isCurrent() const
|
|
{
|
|
return !stricmp(Multi_pxo_channels[channel].name, Multi_pxo_channel_current.name);
|
|
}
|
|
|
|
bool channel_h::isValid() const
|
|
{
|
|
return channel >= 0 && channel < static_cast<int>(Multi_pxo_channels.size());
|
|
}
|
|
|
|
//**********HANDLE: channel section
|
|
ADE_OBJ(l_Channel, channel_h, "pxo_channel", "Channel Section handle");
|
|
|
|
ADE_FUNC(isValid,
|
|
l_Channel,
|
|
nullptr,
|
|
"Detects whether handle is valid",
|
|
"boolean",
|
|
"true if valid, false if handle is invalid, nil if a syntax/type error occurs")
|
|
{
|
|
channel_h current;
|
|
if (!ade_get_args(L, "o", l_Channel.Get(¤t)))
|
|
return ADE_RETURN_NIL;
|
|
|
|
return ade_set_args(L, "b", current.isValid());
|
|
}
|
|
|
|
ADE_VIRTVAR(Name, l_Channel, nullptr, "The name of the channel", "string", "The name")
|
|
{
|
|
channel_h current;
|
|
if (!ade_get_args(L, "o", l_Channel.Get(¤t))) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
if (!current.isValid()) {
|
|
return ade_set_error(L, "s", "");
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "This property is read only.");
|
|
}
|
|
|
|
return ade_set_args(L, "s", current.getChannel()->name);
|
|
}
|
|
|
|
ADE_VIRTVAR(Description, l_Channel, nullptr, "The description of the channel", "string", "The description")
|
|
{
|
|
channel_h current;
|
|
if (!ade_get_args(L, "o", l_Channel.Get(¤t))) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
if (!current.isValid()) {
|
|
return ade_set_error(L, "s", "");
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "This property is read only.");
|
|
}
|
|
|
|
return ade_set_args(L, "s", current.getChannel()->desc);
|
|
}
|
|
|
|
ADE_VIRTVAR(NumPlayers, l_Channel, nullptr, "The number of players in the channel", "string", "The number of players")
|
|
{
|
|
channel_h current;
|
|
if (!ade_get_args(L, "o", l_Channel.Get(¤t))) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
if (!current.isValid()) {
|
|
return ade_set_error(L, "s", "");
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "This property is read only.");
|
|
}
|
|
|
|
return ade_set_args(L, "i", static_cast<int>(current.getChannel()->num_users));
|
|
}
|
|
|
|
ADE_VIRTVAR(NumGames, l_Channel, nullptr, "The number of games the channel", "string", "The number of games")
|
|
{
|
|
channel_h current;
|
|
if (!ade_get_args(L, "o", l_Channel.Get(¤t))) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
if (!current.isValid()) {
|
|
return ade_set_error(L, "s", "");
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "This property is read only.");
|
|
}
|
|
|
|
return ade_set_args(L, "i", static_cast<int>(current.getChannel()->num_servers));
|
|
}
|
|
|
|
ADE_FUNC(isCurrent, l_Channel, nullptr, "Returns whether this is the current channel", "boolean", "true for current, false otherwise. Nil if invalid.")
|
|
{
|
|
channel_h current;
|
|
if (!ade_get_args(L, "o", l_Channel.Get(¤t)))
|
|
return ADE_RETURN_NIL;
|
|
|
|
return ade_set_args(L, "b", current.isCurrent());
|
|
}
|
|
|
|
ADE_FUNC(joinChannel, l_Channel, nullptr, "Joins the specified channel", nullptr, nullptr)
|
|
{
|
|
channel_h current;
|
|
if (!ade_get_args(L, "o", l_Channel.Get(¤t)))
|
|
return ADE_RETURN_NIL;
|
|
|
|
multi_pxo_maybe_join_channel(current.getChannel());
|
|
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
} // namespace api
|
|
} // namespace scripting
|