Removed server creation request (which is now down automatically
from STKHost).
This commit is contained in:
parent
bec317b9ed
commit
847a788a9c
@ -194,9 +194,16 @@ void ServerLobbyRoomProtocol::registerServer()
|
||||
std::string rec_success;
|
||||
|
||||
if (result->get("success", &rec_success) && rec_success == "yes")
|
||||
{
|
||||
Log::info("RegisterServer", "Server is now online.");
|
||||
STKHost::get()->setRegistered(true);
|
||||
}
|
||||
else
|
||||
Log::error("RegisterServer", "Fail to start server.");
|
||||
{
|
||||
irr::core::stringc error(request->getInfo().c_str());
|
||||
Log::error("RegisterServer", "%s", error.c_str());
|
||||
STKHost::get()->setErrorMessage(_("Failed to register server"));
|
||||
}
|
||||
|
||||
} // registerServer
|
||||
|
||||
|
@ -46,9 +46,15 @@ int STKHost::m_max_players = 0;
|
||||
bool STKHost::m_is_server = false;
|
||||
STKHost::NetworkType STKHost::m_network_type = STKHost::NETWORK_NONE;
|
||||
|
||||
|
||||
/** \class STKHost. This is the main class for online games. It can be
|
||||
* either instantiated as server, or as client. The online game works
|
||||
/** \class STKHost
|
||||
* \brief Represents the local host. It is the main managing point for
|
||||
* networking. It is responsible for sending and receiving messages,
|
||||
* and keeping track of onnected peers. It also provides some low
|
||||
* level socket functions (i.e. to avoid that enet adds its headers
|
||||
* to messages, useful for broadcast in LAN and for stun). It can be
|
||||
* either instantiated as server, or as client.
|
||||
* Additionally this object stores information from the various protocols,
|
||||
* which can be queried by the GUI. The online game works
|
||||
* closely together with the stk server: a (game) server first connects
|
||||
* to the stk server and registers itself, clients find the list of servers
|
||||
* from the stk server. They insert a connections request into the stk
|
||||
@ -180,6 +186,8 @@ void STKHost::init()
|
||||
m_network = NULL;
|
||||
m_listening_thread = NULL;
|
||||
m_game_setup = NULL;
|
||||
m_is_registered = false;
|
||||
m_error_message = "";
|
||||
|
||||
m_public_address.lock();
|
||||
m_public_address.getData().clear();
|
||||
@ -291,7 +299,24 @@ void STKHost::abort()
|
||||
ProtocolManager::getInstance()->abort();
|
||||
} // abort
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------
|
||||
/** Sets an error message for the gui.
|
||||
*/
|
||||
void STKHost::setErrorMessage(const irr::core::stringw &message)
|
||||
{
|
||||
irr::core::stringc s(message.c_str());
|
||||
Log::error("STKHost", "%s", s.c_str());
|
||||
m_error_message = message;
|
||||
} // setErrorMessage
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the last error (or "" if no error has happened). */
|
||||
const irr::core::stringw& STKHost::getErrorMessage() const
|
||||
{
|
||||
return m_error_message;
|
||||
} // getErrorMessage
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** \brief Try to establish a connection to a given transport address.
|
||||
* \param peer : The transport address which you want to connect to.
|
||||
* \return True if we're successfully connected. False elseway.
|
||||
|
@ -41,16 +41,6 @@ class GameSetup;
|
||||
class NetworkConsole;
|
||||
class STKPeer;
|
||||
|
||||
/** \class STKHost
|
||||
* \brief Represents the local host. It is the main managing point for
|
||||
* networking. It is responsible for sending and receiving messages,
|
||||
* and keeping track of onnected peers. It also provides some low
|
||||
* level socket functions (i.e. to avoid that enet adds its headers
|
||||
* to messages, useful for broadcast in LAN and for stun).
|
||||
* This host is either a server host or a client host. A client host is in
|
||||
* charge of connecting to a server. A server opens a socket for incoming
|
||||
* connections.
|
||||
*/
|
||||
class STKHost
|
||||
{
|
||||
public:
|
||||
@ -99,9 +89,17 @@ private:
|
||||
/** Maximum number of players on the server. */
|
||||
static int m_max_players;
|
||||
|
||||
/** If this is a server, it indicates if this server is registered
|
||||
* with the stk server. */
|
||||
bool m_is_registered;
|
||||
|
||||
/** If this is a server, the server name. */
|
||||
irr::core::stringw m_server_name;
|
||||
|
||||
/** An error message, which is set by a protocol to be displayed
|
||||
* in the GUI. */
|
||||
irr::core::stringw m_error_message;
|
||||
|
||||
enum NetworkType
|
||||
{ NETWORK_NONE, NETWORK_WAN, NETWORK_LAN };
|
||||
|
||||
@ -195,6 +193,9 @@ public:
|
||||
bool isConnectedTo(const TransportAddress& peer_address);
|
||||
int mustStopListening();
|
||||
uint16_t getPort() const;
|
||||
void setErrorMessage(const irr::core::stringw &message);
|
||||
const irr::core::stringw&
|
||||
getErrorMessage() const;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the current game setup. */
|
||||
@ -261,13 +262,6 @@ public:
|
||||
/** Returns if this instance is a client. */
|
||||
static bool isclient() { return !m_is_server; }
|
||||
// --------------------------------------------------------------------
|
||||
/** Sets the name of the server if this instance is a server. */
|
||||
void setServerName(const irr::core::stringw &name)
|
||||
{
|
||||
assert(isServer());
|
||||
m_server_name = name;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the server name. */
|
||||
const irr::core::stringw& getServerName() const
|
||||
{
|
||||
@ -275,6 +269,19 @@ public:
|
||||
return m_server_name;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
/** Sets if this server is registered with the stk server. */
|
||||
void setRegistered(bool registered)
|
||||
{
|
||||
assert(isServer());
|
||||
m_is_registered = registered;
|
||||
} // setRegistered
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns if this server is registered with the stk server. */
|
||||
bool isRegistered() const
|
||||
{
|
||||
assert(isServer());
|
||||
return m_is_registered;
|
||||
} // isRegistered
|
||||
|
||||
}; // class STKHost
|
||||
|
||||
|
@ -47,7 +47,6 @@ DEFINE_SCREEN_SINGLETON( CreateServerScreen );
|
||||
|
||||
CreateServerScreen::CreateServerScreen() : Screen("online/create_server.stkgui")
|
||||
{
|
||||
m_server_creation_request = NULL;
|
||||
} // CreateServerScreen
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -119,10 +118,24 @@ void CreateServerScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
*/
|
||||
void CreateServerScreen::onUpdate(float delta)
|
||||
{
|
||||
if (!m_server_creation_request) return;
|
||||
// If no host has been created, keep on waiting.
|
||||
if(!STKHost::isNetworking())
|
||||
return;
|
||||
|
||||
// If the request is not ready, wait till it is done.
|
||||
if (!m_server_creation_request->isDone())
|
||||
// First check if an error happened while registering the server:
|
||||
// --------------------------------------------------------------
|
||||
const irr::core::stringw &error = STKHost::get()->getErrorMessage();
|
||||
if(error!="")
|
||||
{
|
||||
SFXManager::get()->quickSound("anvil");
|
||||
m_info_widget->setErrorColor();
|
||||
m_info_widget->setText(error, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise wait till we get an answer from the server:
|
||||
// -----------------------------------------------------
|
||||
if(!STKHost::get()->isRegistered())
|
||||
{
|
||||
m_info_widget->setDefaultColor();
|
||||
m_info_widget->setText(StringUtils::loadingDots(_("Creating server")),
|
||||
@ -130,21 +143,10 @@ void CreateServerScreen::onUpdate(float delta)
|
||||
return;
|
||||
}
|
||||
|
||||
// Now the request has been executed.
|
||||
// ----------------------------------
|
||||
if (m_server_creation_request->isSuccess())
|
||||
{
|
||||
new ServerInfoDialog(m_server_creation_request->getCreatedServerID(),
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SFXManager::get()->quickSound("anvil");
|
||||
m_info_widget->setErrorColor();
|
||||
m_info_widget->setText(m_server_creation_request->getInfo(), false);
|
||||
}
|
||||
delete m_server_creation_request;
|
||||
m_server_creation_request = NULL;
|
||||
|
||||
// Go to lobby screen now
|
||||
// ----------------------
|
||||
|
||||
|
||||
} // onUpdate
|
||||
|
||||
@ -189,36 +191,11 @@ void CreateServerScreen::createServer()
|
||||
STKHost::setMaxPlayers(max_players);
|
||||
STKHost::create(name);
|
||||
|
||||
// Now must be WAN: forward request to the stk server
|
||||
m_server_creation_request = new ServerCreationRequest();
|
||||
PlayerManager::setUserDetails(m_server_creation_request, "create",
|
||||
Online::API::SERVER_PATH);
|
||||
m_server_creation_request->addParameter("name", name);
|
||||
m_server_creation_request->addParameter("max_players", max_players);
|
||||
m_server_creation_request->queue();
|
||||
|
||||
} // createServer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Callbacks from the online create server request.
|
||||
*/
|
||||
void CreateServerScreen::ServerCreationRequest::callback()
|
||||
{
|
||||
if (isSuccess())
|
||||
{
|
||||
// Must be a WAN server
|
||||
Server *server = new Server(*getXMLData()->getNode("server"),
|
||||
/*is lan*/false);
|
||||
ServersManager::get()->addServer(server);
|
||||
m_created_server_id = server->getServerId();
|
||||
} // isSuccess
|
||||
} // callback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void CreateServerScreen::tearDown()
|
||||
{
|
||||
delete m_server_creation_request;
|
||||
m_server_creation_request = NULL;
|
||||
} // tearDown
|
||||
|
||||
|
@ -46,22 +46,6 @@ private:
|
||||
GUIEngine::IconButtonWidget * m_create_widget;
|
||||
GUIEngine::IconButtonWidget * m_cancel_widget;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
class ServerCreationRequest : public Online::XMLRequest
|
||||
{
|
||||
virtual void callback();
|
||||
uint32_t m_created_server_id;
|
||||
public:
|
||||
const uint32_t getCreatedServerID() const
|
||||
{
|
||||
assert(isDone());
|
||||
return m_created_server_id;
|
||||
} // getCreatedServerID
|
||||
}; // ServerCreationRequest
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
ServerCreationRequest *m_server_creation_request;
|
||||
|
||||
void createServer();
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user