Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions data/commands.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,13 @@ here later. For now, please refer to the code for the strings being used. -->
permissions="UP_HAMMER"
state-scope="SS_ALWAYS"
/>
<command name="room"
usage="/room (username) (number 0+)"
permissions-verbose="hammers"
description="Allows to move a player to another lobby room"
permissions="UP_HAMMER"
state-scope="SS_LOBBY"
/>
<command name="addondownloadprogress"
usage="/addondownloadprogress"
permissions-verbose="everyone (client command)"
Expand Down
3 changes: 1 addition & 2 deletions src/network/child_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ void ChildLoop::run()
if (m_port == 0 && STKHost::existHost())
{
auto sl = LobbyProtocol::get<ServerLobby>();
if (sl &&
sl->getCurrentState() >= ServerLobby::WAITING_FOR_START_GAME)
if (sl && sl->isPastRegistrationPhase())
{
m_port = STKHost::get()->getPrivatePort();
m_server_online_id = sl->getServerIdOnline();
Expand Down
6 changes: 1 addition & 5 deletions src/network/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
#include "network/stk_peer.hpp"

/** \brief Constructor
* Sets the basic protocol parameters, as the callback object and the
* protocol type.
* \param callback_object The callback object that will be used by the
* protocol. Protocols that do not use callback objects must set
* it to NULL.
* Sets the protocol type.
* \param type The type of the protocol.
*/
Protocol::Protocol(ProtocolType type)
Expand Down
25 changes: 1 addition & 24 deletions src/network/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,9 @@ enum ProtocolType
}; // ProtocolType

// ----------------------------------------------------------------------------
/** \enum ProtocolState
* \brief Defines the three states that a protocol can have.
*/
enum ProtocolState
{
PROTOCOL_STATE_INITIALISING, //!< The protocol is waiting to be started
PROTOCOL_STATE_RUNNING, //!< The protocol is being updated everytime.
PROTOCOL_STATE_PAUSED, //!< The protocol is paused.
PROTOCOL_STATE_TERMINATED //!< The protocol is terminated/does not exist.
}; // ProtocolState

class Protocol;

// ============================================================================*
/** \class CallbackObject
* \brief Class that must be inherited to pass objects to protocols.
*/
class CallbackObject
{
public:
CallbackObject() {}
virtual ~CallbackObject() {}

virtual void callback(Protocol *protocol) = 0;
}; // CallbackObject

// ============================================================================
/** \class Protocol
* \brief Abstract class used to define the global protocol functions.
Expand All @@ -96,7 +73,7 @@ class Protocol : public std::enable_shared_from_this<Protocol>,
/** True if this protocol should receive connection events. */
bool m_handle_connections;

/** TRue if this protocol should recceiver disconnection events. */
/** True if this protocol should receive disconnection events. */
bool m_handle_disconnections;
public:
Protocol(ProtocolType type);
Expand Down
6 changes: 2 additions & 4 deletions src/network/protocol_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ std::shared_ptr<ProtocolManager> ProtocolManager::createInstance()
auto sl = LobbyProtocol::get<ServerLobby>();
if (sl)
{
ServerLobby::ServerState ss = sl->getCurrentState();
if (!(ss >= ServerLobby::WAIT_FOR_WORLD_LOADED &&
ss <= ServerLobby::RACING))
if (sl->canIgnoreControllerEvents())
{
delete event_top;
continue;
Expand Down Expand Up @@ -297,7 +295,7 @@ bool ProtocolManager::OneProtocolType::notifyEvent(Event *event)
if (m_protocols.empty()) return false;

// Either all protocols of a certain type handle connects, or none.
// So we tet only one of them
// So we test only one of them
if (event->getType() == EVENT_TYPE_CONNECTED &&
!m_protocols[0]->handleConnects()) return false;
if (event->getType() == EVENT_TYPE_DISCONNECTED &&
Expand Down
2 changes: 0 additions & 2 deletions src/network/protocols/client_lobby.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ class ClientLobby : public LobbyProtocol
virtual void setup() OVERRIDE;
virtual void update(int ticks) OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE {}
virtual bool allPlayersReady() const OVERRIDE
{ return m_state.load() >= RACING; }
bool waitingForServerRespond() const
{ return m_state.load() == REQUESTING_CONNECTION; }
bool isLobbyReady() const { return !m_first_connect; }
Expand Down
47 changes: 45 additions & 2 deletions src/network/protocols/command_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ void CommandManager::initCommands()
applyFunctionIfPossible("network", &CM::process_net);
applyFunctionIfPossible("everynet", &CM::process_everynet);
applyFunctionIfPossible("temp", &CM::process_temp250318);
applyFunctionIfPossible("room", &CM::process_room);

applyFunctionIfPossible("addondownloadprogress", &CM::special);
applyFunctionIfPossible("stopaddondownload", &CM::special);
Expand Down Expand Up @@ -1355,8 +1356,7 @@ void CommandManager::process_spectate(Context& context)
}
if (value >= 1)
{
if (getLobby()->isChildProcess() &&
getLobby()->isClientServerHost(acting_peer))
if (getLobby()->isChildProcess() && getLobby()->isClientServerHost(acting_peer))
{
context.say("Graphical client server cannot spectate");
return;
Expand Down Expand Up @@ -3877,6 +3877,49 @@ void CommandManager::process_temp250318(Context& context)
} // process_temp250318
// ========================================================================

void CommandManager::process_room(Context& context)
{
auto& argv = context.m_argv;
auto acting_peer = context.actingPeer();

if (argv.size() < 3)
{
error(context);
return;
}

if (!validate(context, 1, TFT_PRESENT_USERS, false, false))
return;

std::string player_name = argv[1];
std::shared_ptr<STKPeer> player_peer = STKHost::get()->findPeerByName(
StringUtils::utf8ToWide(player_name));
if (player_name.empty() || !player_peer)
{
error(context);
return;
}

int room = -2;

if (!StringUtils::parseString<int>(argv[2], &room) || room < -1 || room >= 256)
{
error(context);
return;
}

player_peer->setRoomNumber(room);

auto npp = player_peer->getMainProfile();
context.say(StringUtils::insertValues("Moved player %s to room %d",
getLobby()->encodeProfileNameForPeer(npp, acting_peer.get()).c_str(),
room
));

getLobby()->updatePlayerList();
} // process_room
// ========================================================================

void CommandManager::special(Context& context)
{
auto command = context.command();
Expand Down
1 change: 1 addition & 0 deletions src/network/protocols/command_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class CommandManager: public LobbyContextComponent
void process_countteams(Context& context);
void process_net(Context& context);
void process_everynet(Context& context);
void process_room(Context& context);

// Temporary command
void process_temp250318(Context& context);
Expand Down
1 change: 0 additions & 1 deletion src/network/protocols/lobby_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class LobbyProtocol : public Protocol
virtual void update(int ticks) = 0;
virtual void finishedLoadingWorld() = 0;
virtual void loadWorld();
virtual bool allPlayersReady() const = 0;
virtual bool isRacing() const = 0;
void startVotingPeriod(float max_time);
float getRemainingVotingTime();
Expand Down
Loading