Added '--auto-connect' command line option to automatically connect

a client to the first LAN server it finds and start a race - strictly
for debuggint ;)
This commit is contained in:
hiker
2017-01-25 14:29:48 +11:00
parent b8bf4a3c2e
commit 426cbaaff5
9 changed files with 70 additions and 11 deletions

View File

@@ -583,6 +583,7 @@ void cmdLineHelp()
" --port=n Port number to use.\n"
" --my-address=1.1.1.1:1 Own IP address (can replace stun protocol)\n"
" --disable-lan Disable LAN detection (connect using WAN).\n"
" --auto-connect Automatically connect to fist server and start race\n"
" --max-players=n Maximum number of clients (server only).\n"
" --no-console Does not write messages in the console but to\n"
" stdout.log.\n"
@@ -1030,7 +1031,10 @@ int handleCmdLine()
{
NetworkConfig::get()->setPassword(s);
}
if (CommandLine::has("--auto-connect"))
{
NetworkConfig::get()->setAutoConnect(true);
}
if(CommandLine::has("--max-players", &n))
UserConfigParams::m_server_max_players=n;

View File

@@ -36,6 +36,7 @@ bool NetworkConfig::m_disable_lan = false;
NetworkConfig::NetworkConfig()
{
m_network_type = NETWORK_NONE;
m_auto_connect = false;
m_is_server = false;
m_is_public_server = false;
m_max_players = 4;

View File

@@ -73,6 +73,10 @@ private:
* with the stk server. */
bool m_is_registered;
/** True if a client should connect to the first server it finds and
* immediately start a race. */
bool m_auto_connect;
/** If this is a server, the server name. */
irr::core::stringw m_server_name;
@@ -207,6 +211,13 @@ public:
m_my_address.unlock();
return a;
} // getMyAddress
// --------------------------------------------------------------------
/** Sets if a client should immediately connect to the first server. */
void setAutoConnect(bool b) { m_auto_connect = b; }
// --------------------------------------------------------------------
/** Returns if an immediate connection to the first server was
* requested. */
bool isAutoConnect() const { return m_auto_connect; }
}; // class NetworkConfig

View File

@@ -507,6 +507,15 @@ void ClientLobby::connectionAccepted(Event* event)
NetworkingLobby::getInstance()->addPlayer(profile);
m_server = event->getPeer();
m_state = CONNECTED;
if (NetworkConfig::get()->isAutoConnect())
{
// Send a message to the server to start
NetworkString start(PROTOCOL_LOBBY_ROOM);
start.setSynchronous(true);
start.addUInt8(LobbyProtocol::LE_REQUEST_BEGIN);
STKHost::get()->sendToServer(&start, true);
}
} // connectionAccepted
//-----------------------------------------------------------------------------
@@ -609,8 +618,7 @@ void ClientLobby::kartSelectionUpdate(Event* event)
//-----------------------------------------------------------------------------
/*! \brief Called when the server broadcasts to start the race.
race needs to be started.
/*! \brief Called when the server broadcasts to start the race to all clients.
* \param event : Event providing the information (no additional information
* in this case).
*/

View File

@@ -54,7 +54,6 @@ private:
/** The cancel button. */
GUIEngine::IconButtonWidget *m_cancel_widget;
void requestJoin();
public:
ServerInfoDialog(uint32_t server_id, uint32_t host_id, bool just_created = false);
@@ -65,6 +64,7 @@ public:
virtual bool onEscapePressed();
virtual void onUpdate(float dt);
void requestJoin();
}; // class ServerInfoDialog
#endif

View File

@@ -425,7 +425,7 @@ void KartSelectionScreen::tearDown()
void KartSelectionScreen::unloaded()
{
// these pointer is no more valid (have been deleted along other widgets)
// This pointer is no longer valid (has been deleted along other widgets)
m_dispatcher = NULL;
}

View File

@@ -30,6 +30,7 @@
#include "network/protocol_manager.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/stk_host.hpp"
#include "states_screens/race_setup_screen.hpp"
#include "states_screens/server_selection.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/tracks_screen.hpp"
@@ -106,6 +107,15 @@ void NetworkKartSelectionScreen::init()
m_kart_widgets[n].move( fullarea->m_x + splitWidth*n,
fullarea->m_y, splitWidth, fullarea->m_h);
}
// In case of auto-connect, select default kart and go to track selection.
if (NetworkConfig::get()->isAutoConnect())
{
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
assert(w != NULL);
w->setSelection(UserConfigParams::m_default_kart, /*player id*/0, /*focus*/true);
playerConfirm(0);
RaceSetupScreen::getInstance()->push();
}
} // init
@@ -145,7 +155,7 @@ void NetworkKartSelectionScreen::playerConfirm(const int playerID)
for(unsigned int i=0; i<players.size(); i++)
{
clrp->requestKartSelection(players[i]->getGlobalPlayerId(),
selection);
selection );
}
}
} // playerConfirm
@@ -168,11 +178,16 @@ void NetworkKartSelectionScreen::playerSelected(uint8_t player_id,
if(widget_id==-1)
return;
KartSelectionScreen::updateKartWidgetModel(widget_id, kart_name,
irr::core::stringw(kart_name.c_str()));
KartSelectionScreen::updateKartStats(widget_id, kart_name);
m_kart_widgets[widget_id].setKartInternalName(kart_name);
m_kart_widgets[widget_id].markAsReady(); // mark player ready
// In case of auto-connect the screen is already replaced, so
// m_kart_widget is empty.
if (! STKHost::get()->isAuthorisedToControl())
{
KartSelectionScreen::updateKartWidgetModel(widget_id, kart_name,
irr::core::stringw(kart_name.c_str()));
KartSelectionScreen::updateKartStats(widget_id, kart_name);
m_kart_widgets[widget_id].setKartInternalName(kart_name);
m_kart_widgets[widget_id].markAsReady(); // mark player ready
}
// If this is the authorised client, send the currently set race config
// to the server.

View File

@@ -19,6 +19,7 @@
#include "audio/sfx_manager.hpp"
#include "guiengine/modaldialog.hpp"
#include "network/network_config.hpp"
#include "network/servers_manager.hpp"
#include "online/xml_request.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
@@ -208,6 +209,7 @@ void ServerSelection::eventCallback( GUIEngine::Widget* widget,
* if so, update the list of servers.
*/
void ServerSelection::onUpdate(float dt)
{
if (!m_refresh_request) return;
@@ -250,4 +252,14 @@ void ServerSelection::onUpdate(float dt)
if (selection != -1 && selection_str != "spacer" && selection_str != "loading")
m_server_list_widget->setSelectionID(selection);
}
// In case of auto-connect command line parameter, select the first server asap
if (NetworkConfig::get()->isAutoConnect() &&
m_refresh_request == NULL &&
m_server_list_widget->getItemCount() > 0)
{
ServerInfoDialog *sid = new ServerInfoDialog(/*server*/0,
/*host id*/0, false);
sid->requestJoin();
}
} // onUpdate

View File

@@ -171,6 +171,14 @@ void TracksScreen::init()
tracks_widget->setSelection(0, PLAYER_ID_GAME_MASTER, true);
}
irr_driver->unsetTextureErrorMessage();
if (NetworkConfig::get()->isAutoConnect())
{
DynamicRibbonWidget* tw = getWidget<DynamicRibbonWidget>("tracks");
tw->setSelection(UserConfigParams::m_last_track, 0,
/*focus*/true);
eventCallback(tw, "tracks",
/*player id*/0);
}
} // init
// -----------------------------------------------------------------------------