Moved ServerJoinRequest from CurrentUser into RequestConnection
(from which file it is also used in online_screen). And cosmetic changes everywhere.
This commit is contained in:
parent
cb8daa4977
commit
d88f513ad6
@ -19,38 +19,63 @@
|
||||
#include "network/protocols/request_connection.hpp"
|
||||
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "online/request_manager.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
|
||||
RequestConnection::RequestConnection(uint32_t server_id) : Protocol(NULL, PROTOCOL_SILENT)
|
||||
using namespace Online;
|
||||
|
||||
/** Constructor. Stores the server id.
|
||||
* \param server_id Id of the server.
|
||||
*/
|
||||
RequestConnection::RequestConnection(uint32_t server_id)
|
||||
: Protocol(NULL, PROTOCOL_SILENT)
|
||||
{
|
||||
m_server_id = server_id;
|
||||
}
|
||||
} // RequestConnection
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
RequestConnection::~RequestConnection()
|
||||
{
|
||||
}
|
||||
} // ~RequestConnection
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Setup of this request, sets state to none.
|
||||
*/
|
||||
void RequestConnection::setup()
|
||||
{
|
||||
m_state = NONE;
|
||||
}
|
||||
} // setup
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** The callback for the server join request. It informs the server manager
|
||||
* of a successful join request.
|
||||
*/
|
||||
void RequestConnection::ServerJoinRequest::callback()
|
||||
{
|
||||
if (isSuccess())
|
||||
{
|
||||
uint32_t server_id;
|
||||
getXMLData()->get("serverid", &server_id);
|
||||
ServersManager::get()->setJoinedServer(server_id);
|
||||
}
|
||||
} // ServerJoinRequest::callback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** This implements a finite state machine to monitor the server join
|
||||
* request asynchronously.
|
||||
*/
|
||||
void RequestConnection::asynchronousUpdate()
|
||||
{
|
||||
switch (m_state)
|
||||
{
|
||||
case NONE:
|
||||
{
|
||||
m_request = new Online::CurrentUser::ServerJoinRequest();
|
||||
m_request = new ServerJoinRequest();
|
||||
CurrentUser::setUserDetails(m_request, "request-connection");
|
||||
m_request->setServerURL("address-management.php");
|
||||
m_request->addParameter("id",Online::CurrentUser::get()->getID());
|
||||
m_request->addParameter("token",Online::CurrentUser::get()->getToken());
|
||||
m_request->addParameter("server_id",m_server_id);
|
||||
m_request->addParameter("action","request-connection");
|
||||
|
||||
Online::RequestManager::get()->addRequest(m_request);
|
||||
m_request->queue();
|
||||
m_state = REQUEST_PENDING;
|
||||
break;
|
||||
}
|
||||
@ -65,11 +90,14 @@ void RequestConnection::asynchronousUpdate()
|
||||
{
|
||||
if (rec_success == "yes")
|
||||
{
|
||||
Log::debug("RequestConnection", "Connection Request made successfully.");
|
||||
Log::debug("RequestConnection",
|
||||
"Connection Request made successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::error("RequestConnection", "Fail to make a request to connecto to server %d", m_server_id);
|
||||
Log::error("RequestConnection",
|
||||
"Fail to make a request to connecto to server %d",
|
||||
m_server_id);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -89,5 +117,5 @@ void RequestConnection::asynchronousUpdate()
|
||||
case EXITING:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // asynchronousUpdate
|
||||
|
||||
|
@ -1,33 +1,52 @@
|
||||
#ifndef REQUEST_CONNECTION_HPP
|
||||
#define REQUEST_CONNECTION_HPP
|
||||
#ifndef HEADER_REQUEST_CONNECTION_HPP
|
||||
#define HEADER_REQUEST_CONNECTION_HPP
|
||||
|
||||
#include "network/protocol.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "online/xml_request.hpp"
|
||||
|
||||
class RequestConnection : public Protocol
|
||||
{
|
||||
protected:
|
||||
/** Id of the server to join. */
|
||||
uint32_t m_server_id;
|
||||
|
||||
/** The request to join a server. */
|
||||
Online::XMLRequest *m_request;
|
||||
enum STATE
|
||||
{
|
||||
NONE,
|
||||
REQUEST_PENDING,
|
||||
DONE,
|
||||
EXITING
|
||||
};
|
||||
|
||||
/** State of this connection. */
|
||||
STATE m_state;
|
||||
|
||||
public:
|
||||
// --------------------------------------------------------------------
|
||||
/** A simple request class to ask to join a server.
|
||||
*/
|
||||
class ServerJoinRequest : public Online::XMLRequest
|
||||
{
|
||||
virtual void callback();
|
||||
public:
|
||||
RequestConnection(uint32_t server_id);
|
||||
virtual ~RequestConnection();
|
||||
ServerJoinRequest() : Online::XMLRequest() {}
|
||||
}; // ServerJoinRequest
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
virtual bool notifyEvent(Event* event) { return true; }
|
||||
virtual bool notifyEventAsynchronous(Event* event) { return true; }
|
||||
virtual void setup();
|
||||
virtual void update() {}
|
||||
virtual void asynchronousUpdate();
|
||||
|
||||
protected:
|
||||
uint32_t m_server_id;
|
||||
Online::CurrentUser::ServerJoinRequest* m_request;
|
||||
enum STATE
|
||||
{
|
||||
NONE,
|
||||
REQUEST_PENDING,
|
||||
DONE,
|
||||
EXITING
|
||||
};
|
||||
STATE m_state;
|
||||
RequestConnection(uint32_t server_id);
|
||||
virtual ~RequestConnection();
|
||||
|
||||
};
|
||||
virtual bool notifyEvent(Event* event) { return true; }
|
||||
virtual bool notifyEventAsynchronous(Event* event) { return true; }
|
||||
virtual void setup();
|
||||
virtual void update() {}
|
||||
virtual void asynchronousUpdate();
|
||||
|
||||
|
||||
}; // RequestConnection
|
||||
|
||||
#endif // REQUEST_CONNECTION_HPP
|
||||
|
@ -236,35 +236,6 @@ namespace Online
|
||||
UserConfigParams::m_saved_session = false;
|
||||
} // signOut
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
CurrentUser::ServerJoinRequest*
|
||||
CurrentUser::requestServerJoin(uint32_t server_id,
|
||||
bool request_now)
|
||||
{
|
||||
assert(m_state == US_SIGNED_IN || m_state == US_GUEST);
|
||||
ServerJoinRequest * request = new ServerJoinRequest();
|
||||
request->setServerURL("address-management.php");
|
||||
request->addParameter("action","request-connection");
|
||||
request->addParameter("token", getToken());
|
||||
request->addParameter("id", getID());
|
||||
request->addParameter("server_id", server_id);
|
||||
if (request_now)
|
||||
request->queue();
|
||||
return request;
|
||||
} // requestServerJoin
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void CurrentUser::ServerJoinRequest::callback()
|
||||
{
|
||||
if(isSuccess())
|
||||
{
|
||||
uint32_t server_id;
|
||||
getXMLData()->get("serverid", &server_id);
|
||||
ServersManager::get()->setJoinedServer(server_id);
|
||||
}
|
||||
//FIXME needs changes for actual valid joining
|
||||
} // ServerJoinRequest::callback
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sends a request to the server to see if any new information is
|
||||
* available. (online friends, notifications, etc.).
|
||||
|
@ -72,14 +72,6 @@ namespace Online
|
||||
SignOutRequest() : XMLRequest(true,/*priority*/10) {}
|
||||
}; // SignOutRequest
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
class ServerJoinRequest : public XMLRequest {
|
||||
virtual void callback ();
|
||||
public:
|
||||
ServerJoinRequest() : XMLRequest() {}
|
||||
}; // ServerJoinRequest
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
class PollRequest : public XMLRequest {
|
||||
virtual void callback ();
|
||||
@ -113,7 +105,6 @@ namespace Online
|
||||
bool save_session,
|
||||
bool request_now = true);
|
||||
void requestSignOut();
|
||||
ServerJoinRequest * requestServerJoin(uint32_t server_id, bool request_now = true);
|
||||
|
||||
void requestFriendRequest(const uint32_t friend_id) const;
|
||||
void onSTKQuit() const;
|
||||
|
@ -17,22 +17,20 @@
|
||||
|
||||
#include "states_screens/dialogs/server_info_dialog.hpp"
|
||||
|
||||
#include <IGUIEnvironment.h>
|
||||
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/connect_to_server.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
#include "online/messages.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
#include "states_screens/dialogs/registration_dialog.hpp"
|
||||
#include "states_screens/networking_lobby.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
|
||||
#include <IGUIEnvironment.h>
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr;
|
||||
@ -80,6 +78,7 @@ ServerInfoDialog::~ServerInfoDialog()
|
||||
// -----------------------------------------------------------------------------
|
||||
void ServerInfoDialog::requestJoin()
|
||||
{
|
||||
// FIXME - without this next line, it appears that m_server_join is completely unused.
|
||||
//m_server_join_request = Online::CurrentUser::get()->requestServerJoin(m_server_id);
|
||||
Online::ServersManager::get()->setJoinedServer(m_server_id);
|
||||
ProtocolManager::getInstance()->requestStart(new ConnectToServer(m_server_id, m_host_id));
|
||||
|
@ -25,8 +25,9 @@
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "online/server.hpp"
|
||||
#include "network/protocols/request_connection.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "online/server.hpp"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
|
||||
@ -42,7 +43,7 @@ private:
|
||||
bool m_self_destroy;
|
||||
bool m_enter_lobby;
|
||||
bool m_from_server_creation;
|
||||
const Online::CurrentUser::ServerJoinRequest * m_server_join_request;
|
||||
const RequestConnection::ServerJoinRequest * m_server_join_request;
|
||||
|
||||
const uint32_t m_server_id;
|
||||
uint32_t m_host_id;
|
||||
|
@ -29,24 +29,21 @@
|
||||
#include "input/input_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "main_loop.hpp"
|
||||
#include "modes/demo_world.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/connect_to_server.hpp"
|
||||
#include "network/protocols/request_connection.hpp"
|
||||
#include "online/messages.hpp"
|
||||
#include "online/profile_manager.hpp"
|
||||
#include "online/request.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "states_screens/networking_lobby.hpp"
|
||||
#include "states_screens/server_selection.hpp"
|
||||
#include "states_screens/create_server_screen.hpp"
|
||||
#include "states_screens/online_profile_overview.hpp"
|
||||
#include "online/servers_manager.hpp"
|
||||
#include "online/messages.hpp"
|
||||
#include "online/profile_manager.hpp"
|
||||
#include "online/request.hpp"
|
||||
#include "modes/demo_world.hpp"
|
||||
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/connect_to_server.hpp"
|
||||
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/connect_to_server.hpp"
|
||||
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace Online;
|
||||
@ -95,6 +92,8 @@ void OnlineScreen::loadedFromFile()
|
||||
} // loadedFromFile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Checks if the recorded state differs from the actual state and sets it.
|
||||
*/
|
||||
bool OnlineScreen::hasStateChanged()
|
||||
{
|
||||
CurrentUser::UserState previous_state = m_recorded_state;
|
||||
@ -102,7 +101,7 @@ bool OnlineScreen::hasStateChanged()
|
||||
if (previous_state != m_recorded_state)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
} // hasStateChanged
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void OnlineScreen::beforeAddingWidget()
|
||||
@ -130,8 +129,6 @@ void OnlineScreen::beforeAddingWidget()
|
||||
|
||||
} // beforeAddingWidget
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void OnlineScreen::init()
|
||||
{
|
||||
@ -139,6 +136,8 @@ void OnlineScreen::init()
|
||||
setInitialFocus();
|
||||
DemoWorld::resetIdleTime();
|
||||
m_online_status_widget->setText(Messages::signedInAs(CurrentUser::get()->getUserName()), false);
|
||||
core::stringw m = _("Signed in as: %s.", CurrentUser::get()->getUserName());
|
||||
//m_online_status_widget->setText(-_("Signed in as: %s.", CurrentUser::get()->getUserName().c_str()), false);
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -161,8 +160,57 @@ void OnlineScreen::onUpdate(float delta)
|
||||
} // onUpdate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Executes the quick play selection. Atm this is all blocking.
|
||||
*/
|
||||
void OnlineScreen::doQuickPlay()
|
||||
{
|
||||
// Refresh server list.
|
||||
HTTPRequest* request = ServersManager::get()->refreshRequest(false);
|
||||
if (request != NULL) // consider request done
|
||||
{
|
||||
request->executeNow();
|
||||
delete request;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::error("OnlineScreen", "Could not get the server list.");
|
||||
return;
|
||||
}
|
||||
// select first one
|
||||
const Server * server = ServersManager::get()->getQuickPlay();
|
||||
|
||||
void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const int playerID)
|
||||
|
||||
XMLRequest *request2 = new RequestConnection::ServerJoinRequest();
|
||||
if (!request2)
|
||||
{
|
||||
sfx_manager->quickSound("anvil");
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentUser::setUserDetails(request2, "request-connection");
|
||||
request2->setServerURL("address-management.php");
|
||||
request2->addParameter("server_id", server->getServerId());
|
||||
|
||||
request2->executeNow();
|
||||
if (request2->isSuccess())
|
||||
{
|
||||
delete request2;
|
||||
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
|
||||
ConnectToServer *cts = new ConnectToServer(server->getServerId(),
|
||||
server->getHostId());
|
||||
ProtocolManager::getInstance()->requestStart(cts);
|
||||
}
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound("anvil");
|
||||
}
|
||||
|
||||
} // doQuickPlay
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
const int playerID)
|
||||
{
|
||||
if (name == m_back_widget->m_properties[PROP_ID])
|
||||
{
|
||||
@ -194,41 +242,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
|
||||
}
|
||||
else if (selection == m_quick_play_widget->m_properties[PROP_ID])
|
||||
{
|
||||
//FIXME temporary and the request join + join sequence should be placed in one method somewhere
|
||||
// refresh server list
|
||||
Online::ServersManager::RefreshRequest* request = ServersManager::get()->refreshRequest(false);
|
||||
if (request != NULL) // consider request done
|
||||
{
|
||||
request->executeNow();
|
||||
delete request;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::error("OnlineScreen", "Could not get the server list.");
|
||||
return;
|
||||
}
|
||||
// select first one
|
||||
const Server * server = ServersManager::get()->getQuickPlay();
|
||||
|
||||
Online::CurrentUser::ServerJoinRequest* request2 = Online::CurrentUser::get()->requestServerJoin( server->getServerId(), false);
|
||||
if (request2)
|
||||
{
|
||||
request2->executeNow();
|
||||
if (request2->isSuccess())
|
||||
{
|
||||
delete request2;
|
||||
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
|
||||
ProtocolManager::getInstance()->requestStart(new ConnectToServer(server->getServerId(), server->getHostId()));
|
||||
}
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
}
|
||||
doQuickPlay();
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
@ -239,6 +253,8 @@ void OnlineScreen::tearDown()
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets which widget has to be focused. Depends on the user state.
|
||||
*/
|
||||
void OnlineScreen::setInitialFocus()
|
||||
{
|
||||
if(m_recorded_state == CurrentUser::US_SIGNED_IN)
|
||||
|
@ -56,11 +56,10 @@ private:
|
||||
|
||||
Online::CurrentUser::UserState m_recorded_state;
|
||||
|
||||
/** \brief Checks if the recorded state differs from the actual state and sets it. */
|
||||
bool hasStateChanged();
|
||||
/** \brief Sets which widget has to be focused. Depends on the user state. */
|
||||
void setInitialFocus();
|
||||
|
||||
void doQuickPlay();
|
||||
public:
|
||||
|
||||
virtual void onUpdate(float delta) OVERRIDE;
|
||||
|
Loading…
Reference in New Issue
Block a user