diff --git a/data/gui/online/lobby_settings.stkgui b/data/gui/online/lobby_settings.stkgui
index fc5ff8deb..27bba564c 100644
--- a/data/gui/online/lobby_settings.stkgui
+++ b/data/gui/online/lobby_settings.stkgui
@@ -17,6 +17,8 @@
+
+
diff --git a/sources.cmake b/sources.cmake
index ed3f136cd..a72fa0434 100644
--- a/sources.cmake
+++ b/sources.cmake
@@ -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
diff --git a/src/online/current_online_user.cpp b/src/online/current_online_user.cpp
index 7df8191b2..bdf64cc19 100644
--- a/src/online/current_online_user.cpp
+++ b/src/online/current_online_user.cpp
@@ -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);
diff --git a/src/online/current_online_user.hpp b/src/online/current_online_user.hpp
index 987d77a9d..ab694ddeb 100644
--- a/src/online/current_online_user.hpp
+++ b/src/online/current_online_user.hpp
@@ -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; }
diff --git a/src/online/online_user.hpp b/src/online/online_user.hpp
index cf9bae7f8..6d67a12f6 100644
--- a/src/online/online_user.hpp
+++ b/src/online/online_user.hpp
@@ -34,18 +34,16 @@ class OnlineUser
protected:
- irr::core::stringw m_name;
- uint32_t m_id;
+ 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; }
diff --git a/src/states_screens/networking_lobby_settings.cpp b/src/states_screens/networking_lobby_settings.cpp
index 8e82fc313..7cc6a423b 100644
--- a/src/states_screens/networking_lobby_settings.cpp
+++ b/src/states_screens/networking_lobby_settings.cpp
@@ -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("name");
+ assert(m_name_widget != NULL);
+ m_max_players_widget = getWidget("max_players");
+ assert(m_max_players_widget != NULL);
+
+ m_info_widget = getWidget("info");
+ assert(m_info_widget != NULL);
+
+ m_create_widget = getWidget("create");
+ assert(m_create_widget != NULL);
+ m_cancel_widget = getWidget("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
// ----------------------------------------------------------------------------
diff --git a/src/states_screens/networking_lobby_settings.hpp b/src/states_screens/networking_lobby_settings.hpp
index 234af94df..d27718b12 100644
--- a/src/states_screens/networking_lobby_settings.hpp
+++ b/src/states_screens/networking_lobby_settings.hpp
@@ -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;
diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp
index 2e891b6f7..0cb20d045 100644
--- a/src/states_screens/online_screen.cpp
+++ b/src/states_screens/online_screen.cpp
@@ -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(widget);