Start of creating servers

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13108 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-07-07 00:45:31 +00:00
parent 4208a28f7d
commit 2bf2ed0002
8 changed files with 106 additions and 24 deletions

View File

@ -17,6 +17,8 @@
<gauge id="max_players" proportion="2" min_value="2" max_value="12"/>
</div>
</div>
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" text=""/>
</box>
<spacer width="10" height="7%"/>

View File

@ -1,4 +1,4 @@
# Generated by ./update_file_list.sh. Do not edit this file manually.
# Generated by /home/gl3nn/repos/gsoc-stk-branch/update_file_list.sh. Do not edit this file manually.
set(STK_SOURCES
src/addons/addon.cpp
src/addons/addons_manager.cpp

View File

@ -47,6 +47,7 @@ void CurrentOnlineUser::deallocate()
CurrentOnlineUser::CurrentOnlineUser(){
m_is_signed_in = false;
m_is_guest = false;
m_is_server_host = false;
m_id = 0;
m_name = "";
m_token = "";
@ -117,6 +118,40 @@ bool CurrentOnlineUser::signIn( const irr::core::stringw &username,
return m_is_signed_in;
}
// ============================================================================
bool CurrentOnlineUser::createServer( const irr::core::stringw &name,
int max_players,
irr::core::stringw &info)
{
assert(m_is_signed_in && !m_is_guest && !m_is_server_host);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
connector->setParameter("action", std::string("create_server"));
connector->setParameter("token", m_token);
connector->setParameter("userid", m_id);
connector->setParameter("name", name);
connector->setParameter("max_players", max_players);
const XMLNode * result = connector->getXMLFromPage();
std::string rec_success = "";
if(result->get("success", &rec_success))
{
if (rec_success =="yes")
{
// FIXME
m_is_server_host = true;
}
result->get("info", &info);
}
else
{
info = _("Unable to connect to the server. Check your internet connection or try again later.");
}
return m_is_server_host;
}
// ============================================================================
bool CurrentOnlineUser::signOut(){
assert(m_is_signed_in == true);

View File

@ -57,6 +57,11 @@ class CurrentOnlineUser : public OnlineUser
irr::core::stringw &info);
// Logout - Best to be followed by CurrentOnlineUser::deallocate
bool signOut();
bool createServer( const irr::core::stringw &name,
int max_players,
irr::core::stringw &info);
/** Returns the username if signed in. */
irr::core::stringw getUserName() const;
bool isSignedIn(){ return m_is_signed_in; }

View File

@ -34,18 +34,16 @@ class OnlineUser
protected:
bool m_is_server_host;
irr::core::stringw m_name;
uint32_t m_id;
OnlineUser(){}
public:
/**
* Constructor
*/
OnlineUser(const irr::core::stringw &username);
/** Returns the username. */
irr::core::stringw getUserName() const { return m_name; }
uint32_t getUserID() const { return m_id; }

View File

@ -24,17 +24,13 @@
#include "challenges/game_slot.hpp"
#include "challenges/unlock_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/scalable_font.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "main_loop.hpp"
#include "audio/sfx_manager.hpp"
#include "states_screens/online_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
#include "modes/demo_world.hpp"
#include "utils/translation.hpp"
#include "states_screens/networking_lobby.hpp"
#include "online/current_online_user.hpp"
@ -55,6 +51,20 @@ NetworkingLobbySettings::NetworkingLobbySettings() : Screen("online/lobby_settin
void NetworkingLobbySettings::loadedFromFile()
{
m_name_widget = getWidget<TextBoxWidget>("name");
assert(m_name_widget != NULL);
m_max_players_widget = getWidget<SpinnerWidget>("max_players");
assert(m_max_players_widget != NULL);
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
m_create_widget = getWidget<ButtonWidget>("create");
assert(m_create_widget != NULL);
m_cancel_widget = getWidget<ButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
} // loadedFromFile
// ----------------------------------------------------------------------------
@ -76,18 +86,44 @@ void NetworkingLobbySettings::init()
{
Screen::init();
setInitialFocus();
DemoWorld::resetIdleTime(); //FIXME : what's this?} // init
DemoWorld::resetIdleTime();
}
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
} // onUpdate
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::createServer()
{
const stringw name = m_name_widget->getText().trim();
int max_players = m_max_players_widget->getValue();
stringw info = "";
if(CurrentOnlineUser::get()->createServer(name, max_players, info))
{
StateManager::get()->escapePressed();
StateManager::get()->pushScreen(NetworkingLobby::getInstance());
}
else
{
sfx_manager->quickSound( "anvil" );
m_info_widget->setColor(irr::video::SColor(255, 255, 0, 0));
m_info_widget->setText(info, false);
}
}
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::eventCallback(Widget* widget, const std::string& name, const int playerID)
{
if (name == m_cancel_widget->m_properties[PROP_ID])
{
StateManager::get()->escapePressed();
}
else if (name == m_create_widget->m_properties[PROP_ID])
{
createServer();
}
} // eventCallback
// ----------------------------------------------------------------------------

View File

@ -19,9 +19,10 @@
#define HEADER_NETWORKING_LOBBY_SETTINGS_HPP
#include "guiengine/screen.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "guiengine/widgets/spinner_widget.hpp"
namespace GUIEngine { class Widget; class ListWidget; }
@ -37,18 +38,22 @@ private:
NetworkingLobbySettings();
GUIEngine::TextBoxWidget * m_name_widget;
GUIEngine::SpinnerWidget * m_max_players_widget;
GUIEngine::LabelWidget * m_info_widget;
GUIEngine::ButtonWidget * m_create_widget;
GUIEngine::ButtonWidget * m_cancel_widget;
/** \brief Checks if the user is still signed in. */
bool hasLostConnection();
/** \brief Sets which widget has to be focused. Depends on the user state. */
void setInitialFocus();
public:
void createServer();
enum Action
{
Create = 1, // A new server should be created
Edit = 2, // The settings of the server should be edited
};
public:
virtual void onUpdate(float delta, irr::video::IVideoDriver* driver) OVERRIDE;

View File

@ -154,6 +154,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
if (name == "back")
{
StateManager::get()->escapePressed();
return;
}
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);