server creating and joining. (server side code not complete)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13313 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-07-21 23:30:04 +00:00
parent c2159306e8
commit 20e6fe74b2
13 changed files with 236 additions and 182 deletions

View File

@ -19,13 +19,16 @@
</div>
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" text=""/>
<buttonbar id="options" x="0" y="0" width="100%" height="10%" align="center">
<icon-button id="create" width="64" height="64" icon="gui/tutorial.png" extend_label="75"
I18N="Main menu button" text="Create" label_location="hover"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png" extend_label="70"
I18N="Main menu button" text="Cancel" label_location="hover"/>
</buttonbar>
</box>
<spacer width="10" height="7%"/>
<bottombar x="2%" width="96%" height="10%" layout="horizontal-row">
</bottombar>
</div>

View File

@ -170,6 +170,7 @@ src/replay/replay_play.cpp
src/replay/replay_recorder.cpp
src/states_screens/addons_screen.cpp
src/states_screens/arenas_screen.cpp
src/states_screens/create_server_screen.cpp
src/states_screens/credits.cpp
src/states_screens/cutscene_gui.cpp
src/states_screens/dialogs/add_device_dialog.cpp
@ -198,7 +199,6 @@ src/states_screens/help_screen_4.cpp
src/states_screens/kart_selection.cpp
src/states_screens/main_menu_screen.cpp
src/states_screens/networking_lobby.cpp
src/states_screens/networking_lobby_settings.cpp
src/states_screens/online_screen.cpp
src/states_screens/options_screen_audio.cpp
src/states_screens/options_screen_input2.cpp
@ -444,6 +444,7 @@ src/replay/replay_play.hpp
src/replay/replay_recorder.hpp
src/states_screens/addons_screen.hpp
src/states_screens/arenas_screen.hpp
src/states_screens/create_server_screen.hpp
src/states_screens/credits.hpp
src/states_screens/cutscene_gui.hpp
src/states_screens/dialogs/add_device_dialog.hpp
@ -472,7 +473,6 @@ src/states_screens/help_screen_4.hpp
src/states_screens/kart_selection.hpp
src/states_screens/main_menu_screen.hpp
src/states_screens/networking_lobby.hpp
src/states_screens/networking_lobby_settings.hpp
src/states_screens/online_screen.hpp
src/states_screens/options_screen_audio.hpp
src/states_screens/options_screen_input2.hpp

View File

@ -214,7 +214,6 @@ namespace Online{
void CurrentUser::ServerJoinRequest::callback()
{
//FIXME
}
// ============================================================================

View File

@ -184,6 +184,7 @@ namespace Online{
public :
XMLRequest(int type = 0, bool manage_memory = false, int priority = 1);
virtual ~XMLRequest() {delete m_result;}
virtual XMLNode * getResult() const { return m_result; }
const irr::core::stringw & getInfo() const { return m_info; }

View File

@ -41,6 +41,7 @@ namespace Online{
m_lower_case_name = StringUtils::toLowerCase(m_lower_case_name);
xml.get("id", &m_server_id);
xml.get("hostid", &m_host_id);
xml.get("max_players", &m_max_players);
xml.get("current_players", &m_current_players);

View File

@ -51,6 +51,7 @@ namespace Online{
std::string m_lower_case_name; //Used for comparison
uint32_t m_server_id;
uint32_t m_host_id;
int m_max_players;

View File

@ -0,0 +1,191 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define DEBUG_MENU_ITEM 0
#include "states_screens/create_server_screen.hpp"
#include <string>
#include <iostream>
#include "challenges/game_slot.hpp"
#include "challenges/unlock_manager.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 "states_screens/dialogs/server_info_dialog.hpp"
#include "online/servers_manager.hpp"
#include "online/messages.hpp"
using namespace GUIEngine;
using namespace Online;
DEFINE_SCREEN_SINGLETON( CreateServerScreen );
// ----------------------------------------------------------------------------
CreateServerScreen::CreateServerScreen() : Screen("online/create_server.stkgui")
{
m_server_creation_request = NULL;
m_enter_server = true;
} // CreateServerScreen
// ----------------------------------------------------------------------------
void CreateServerScreen::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_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget != NULL);
m_create_widget = getWidget<IconButtonWidget>("create");
assert(m_create_widget != NULL);
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
} // loadedFromFile
// ----------------------------------------------------------------------------
void CreateServerScreen::beforeAddingWidget()
{
} // beforeAddingWidget
// ----------------------------------------------------------------------------
void CreateServerScreen::init()
{
Screen::init();
setInitialFocus();
DemoWorld::resetIdleTime();
}
// ----------------------------------------------------------------------------
void CreateServerScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
if(m_server_creation_request != NULL)
{
if(m_server_creation_request->isDone())
{
if(m_server_creation_request->isSuccess())
{
if (m_enter_server){
Server * server = new Server(*m_server_creation_request->getResult()->getNode("server"));
new ServerInfoDialog(server,true);
}
else
{
StateManager::get()->escapePressed();
}
}
else
{
sfx_manager->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;
//m_options_widget->setActivated();
}
else
{
m_info_widget->setDefaultColor();
m_info_widget->setText(Online::Messages::creatingServer(), false);
}
}
} // onUpdate
// ----------------------------------------------------------------------------
void CreateServerScreen::serverCreationRequest()
{
const stringw name = m_name_widget->getText().trim();
const int max_players = m_max_players_widget->getValue();
m_info_widget->setErrorColor();
if (name.size() < 4 || name.size() > 30)
{
m_info_widget->setText(_("Name has to be between 4 and 30 characters long!"), false);
}
else if (max_players < 2 || max_players > 12)
{
m_info_widget->setText(_("The maxinum number of players has to be between 2 and 12."), false);
}
else
{
//m_options_widget->setDeactivated();
m_server_creation_request = Online::CurrentUser::acquire()->requestServerCreation(name, max_players);
Online::CurrentUser::release();
return;
}
sfx_manager->quickSound("anvil");
}
// ----------------------------------------------------------------------------
void CreateServerScreen::eventCallback(Widget* widget, const std::string& name, const int playerID)
{
if (name == m_options_widget->m_properties[PROP_ID])
{
const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == m_cancel_widget->m_properties[PROP_ID])
{
StateManager::get()->escapePressed();
}
else if (selection == m_create_widget->m_properties[PROP_ID])
{
serverCreationRequest();
}
}
} // eventCallback
// ----------------------------------------------------------------------------
void CreateServerScreen::tearDown()
{
delete m_server_creation_request;
m_server_creation_request = NULL;
} // tearDown
// ----------------------------------------------------------------------------
void CreateServerScreen::onDisabledItemClicked(const std::string& item)
{
} // onDisabledItemClicked
// ----------------------------------------------------------------------------
void CreateServerScreen::setInitialFocus()
{
} // setInitialFocus
// ----------------------------------------------------------------------------
void CreateServerScreen::onDialogClose()
{
setInitialFocus();
} // onDialogClose()

View File

@ -15,14 +15,13 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_NETWORKING_LOBBY_SETTINGS_HPP
#define HEADER_NETWORKING_LOBBY_SETTINGS_HPP
#ifndef HEADER_CREATE_SERVER_SCREEN_HPP
#define HEADER_CREATE_SERVER_SCREEN_HPP
#include "guiengine/screen.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "guiengine/widgets/spinner_widget.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
namespace GUIEngine { class Widget; class ListWidget; }
@ -30,26 +29,33 @@ namespace GUIEngine { class Widget; class ListWidget; }
* \brief Handles the main menu
* \ingroup states_screens
*/
class NetworkingLobbySettings : public GUIEngine::Screen,
public GUIEngine::ScreenSingleton<NetworkingLobbySettings>
class CreateServerScreen : public GUIEngine::Screen,
public GUIEngine::ScreenSingleton<CreateServerScreen>
{
private:
friend class GUIEngine::ScreenSingleton<NetworkingLobbySettings>;
friend class GUIEngine::ScreenSingleton<CreateServerScreen>;
NetworkingLobbySettings();
CreateServerScreen();
bool m_enter_server;
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;
GUIEngine::RibbonWidget * m_options_widget;
GUIEngine::IconButtonWidget * m_create_widget;
GUIEngine::IconButtonWidget * m_cancel_widget;
Online::CurrentUser::ServerCreationRequest * m_server_creation_request;
/** \brief Sets which widget has to be focused. Depends on the user state. */
void setInitialFocus();
void createServer();
void serverCreationRequest();
public:

View File

@ -100,7 +100,6 @@ void RegistrationDialog::showRegistrationInfo(){
LabelWidget* label = getWidget<LabelWidget>("info");
assert(label != NULL);
label->setErrorColor();
label->setText(m_registration_error, false);
ButtonWidget * button = getWidget<ButtonWidget>("next");
@ -150,29 +149,26 @@ bool RegistrationDialog::processInfoEvent(const std::string& eventSource){
m_email_confirm = getWidget<TextBoxWidget>("email_confirm")->getText().trim();
LabelWidget * info_widget = getWidget<LabelWidget>("info");
//FIXME More validation of registration information
info_widget->setErrorColor();
if (m_password != m_password_confirm)
{
info_widget->setText(_("Passwords don't match!"), false);
sfx_manager->quickSound( "anvil" );
}
else if (m_email != m_email_confirm)
{
info_widget->setText(_("Emails don't match!"), false);
sfx_manager->quickSound( "anvil" );
}
else if (m_username.size() < 4 || m_username.size() > 30)
{
info_widget->setText(_("Username has to be between 5 and 30 characters long!"), false);
sfx_manager->quickSound( "anvil" );
info_widget->setText(_("Username has to be between 4 and 30 characters long!"), false);
}
else if (m_password.size() < 8 || m_password.size() > 30)
{
info_widget->setText(_("Password has to be between 5 and 30 characters long!"), false);
sfx_manager->quickSound( "anvil" );
info_widget->setText(_("Password has to be between 8 and 30 characters long!"), false);
}
else if (m_email.size() < 4 || m_email.size() > 50)
{
info_widget->setText(_("Email has to be between 5 and 50 characters long!"), false);
info_widget->setText(_("Email has to be between 4 and 50 characters long!"), false);
}
else
{

View File

@ -40,7 +40,7 @@ using namespace Online;
// -----------------------------------------------------------------------------
ServerInfoDialog::ServerInfoDialog(Server * server) :
ServerInfoDialog::ServerInfoDialog(Server * server, bool join) :
ModalDialog(0.8f,0.8f)
{
m_server = server;
@ -64,6 +64,7 @@ ServerInfoDialog::ServerInfoDialog(Server * server) :
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
requestJoin();
}
// -----------------------------------------------------------------------------
@ -121,7 +122,7 @@ void ServerInfoDialog::onUpdate(float dt)
{
if(m_server_join_request->isSuccess())
{
m_self_destroy = true;
m_enter_lobby = true;
}
else
{

View File

@ -56,7 +56,7 @@ private:
void requestJoin();
public:
ServerInfoDialog(Online::Server * server);
ServerInfoDialog(Online::Server * server, bool join = false);
~ServerInfoDialog();
void onEnterPressedInternal();

View File

@ -1,145 +0,0 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define DEBUG_MENU_ITEM 0
#include "states_screens/networking_lobby_settings.hpp"
#include <string>
#include <iostream>
#include "challenges/game_slot.hpp"
#include "challenges/unlock_manager.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_user.hpp"
using namespace GUIEngine;
using namespace Online;
DEFINE_SCREEN_SINGLETON( NetworkingLobbySettings );
// ----------------------------------------------------------------------------
NetworkingLobbySettings::NetworkingLobbySettings() : Screen("online/lobby_settings.stkgui")
{
} // NetworkingLobbySettings
// ----------------------------------------------------------------------------
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
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::beforeAddingWidget()
{
} // beforeAddingWidget
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::init()
{
Screen::init();
setInitialFocus();
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(online::CurrentUser::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
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::tearDown()
{
} // tearDown
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::onDisabledItemClicked(const std::string& item)
{
} // onDisabledItemClicked
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::setInitialFocus()
{
} // setInitialFocus
// ----------------------------------------------------------------------------
void NetworkingLobbySettings::onDialogClose()
{
setInitialFocus();
} // onDialogClose()

View File

@ -34,8 +34,8 @@
#include "states_screens/dialogs/login_dialog.hpp"
#include "states_screens/dialogs/registration_dialog.hpp"
#include "states_screens/networking_lobby.hpp"
#include "states_screens/networking_lobby_settings.hpp"
#include "states_screens/server_selection.hpp"
#include "states_screens/create_server_screen.hpp"
#include "modes/demo_world.hpp"
#include "online/servers_manager.hpp"
#include "online/messages.hpp"
@ -198,7 +198,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
}
RibbonWidget* ribbon = dynamic_cast<RibbonWidget*>(widget);
if (ribbon == NULL) return; // what's that event??
if (ribbon == NULL) return;
std::string selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == "sign_in")
@ -220,7 +220,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
}
else if (selection == "create_server")
{
StateManager::get()->pushScreen(NetworkingLobbySettings::getInstance());
StateManager::get()->pushScreen(CreateServerScreen::getInstance());
}
else if (selection == "quick_play")
{