Base for having users and connection with server.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@12884 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-06-19 01:12:45 +00:00
parent aa9eb45c8b
commit 98274f59d5
13 changed files with 368 additions and 7 deletions

View File

@ -143,6 +143,9 @@ src/network/network_manager.cpp
src/network/race_info_message.cpp src/network/race_info_message.cpp
src/network/race_result_message.cpp src/network/race_result_message.cpp
src/network/race_state.cpp src/network/race_state.cpp
src/online/current_online_user.cpp
src/online/http_functions.cpp
src/online/online_user.cpp
src/physics/btKart.cpp src/physics/btKart.cpp
src/physics/btKartRaycast.cpp src/physics/btKartRaycast.cpp
src/physics/btUprightConstraint.cpp src/physics/btUprightConstraint.cpp
@ -402,6 +405,9 @@ src/network/race_start_message.hpp
src/network/race_state.hpp src/network/race_state.hpp
src/network/remote_kart_info.hpp src/network/remote_kart_info.hpp
src/network/world_loaded_message.hpp src/network/world_loaded_message.hpp
src/online/current_online_user.hpp
src/online/http_functions.hpp
src/online/online_user.hpp
src/physics/btKart.hpp src/physics/btKart.hpp
src/physics/btKartRaycast.hpp src/physics/btKartRaycast.hpp
src/physics/btUprightConstraint.hpp src/physics/btUprightConstraint.hpp

View File

@ -302,7 +302,33 @@ XMLNode *FileManager::createXMLTree(const std::string &filename)
} }
return NULL; return NULL;
} }
} // getXMLTree } // createXMLTree
//-----------------------------------------------------------------------------
/** Reads in XML from a string and converts it into a XMLNode tree.
* \param content the string containing the XML content.
*/
XMLNode *FileManager::createXMLTreeFromString(const std::string & content)
{
try
{
char *b = new char[content.size()];
memcpy(b, content.c_str(), content.size());
io::IReadFile * ireadfile = m_file_system->createMemoryReadFile(b, strlen(b), "tempfile", true);
io::IXMLReader * reader = m_file_system->createXMLReader(ireadfile);
XMLNode* node = new XMLNode(reader);
reader->drop();
return node;
}
catch (std::runtime_error& e)
{
if (UserConfigParams::logMisc())
{
Log::error("FileManager", "createXMLTreeFromString: %s\n", e.what());
}
return NULL;
}
} // createXMLTreeFromString
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** In order to add and later remove paths we have to specify the absolute /** In order to add and later remove paths we have to specify the absolute

View File

@ -88,6 +88,7 @@ public:
void dropFileSystem(); void dropFileSystem();
io::IXMLReader *createXMLReader(const std::string &filename); io::IXMLReader *createXMLReader(const std::string &filename);
XMLNode *createXMLTree(const std::string &filename); XMLNode *createXMLTree(const std::string &filename);
XMLNode *createXMLTreeFromString(const std::string & content);
std::string getConfigDir() const; std::string getConfigDir() const;
std::string getTextureDir() const; std::string getTextureDir() const;

View File

@ -0,0 +1,77 @@
//
// 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.
#include "online/current_online_user.hpp"
#include <sstream>
#include <stdlib.h>
#include <assert.h>
static CurrentOnlineUser* user_singleton = NULL;
CurrentOnlineUser* CurrentOnlineUser::get()
{
if (user_singleton == NULL)
user_singleton = new CurrentOnlineUser();
return user_singleton;
} // get
void CurrentOnlineUser::deallocate()
{
delete user_singleton;
user_singleton = NULL;
} // deallocate
// ============================================================================
CurrentOnlineUser::CurrentOnlineUser(){
m_is_signed_in = false;
}
// ============================================================================
bool CurrentOnlineUser::logIn(const std::string &username, const std::string &password)
{
assert(m_is_signed_in == false);
//Sign in
if(/*succes*/true)
{
m_user = new OnlineUser(username);
m_is_signed_in = true;
}
else
{
//I don't know if something should happen here yet
}
return m_is_signed_in;
}
// ============================================================================
std::string CurrentOnlineUser::getUserName() const
{
if(m_is_signed_in){
assert(m_user != NULL);
return m_user->getUserName();
}else{
return "Guest";
}
}

View File

@ -0,0 +1,55 @@
//
// 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.
#ifndef HEADER_CURRENT_ONLINE_USER_HPP
#define HEADER_CURRENT_ONLINE_USER_HPP
#include <string>
#include "online/online_user.hpp"
// ============================================================================
/**
* \brief Class that represents an online registered user
* \ingroup online
*/
class CurrentOnlineUser
{
private:
protected:
std::string m_token;
bool m_is_signed_in;
OnlineUser * m_user;
CurrentOnlineUser();
public:
// singleton
static CurrentOnlineUser* get();
static void deallocate();
bool logIn(const std::string &username, const std::string &password);
/** Returns the username if signed in. */
std::string getUserName() const;
}; // class CurrentOnlineUser
#endif
/*EOF*/

View File

@ -0,0 +1,70 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 SuperTuxKart-Team
//
// 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.
#include "http_functions.hpp"
#include <iostream>
#include <curl/curl.h>
#include <stdio.h>
#include <memory.h>
#include "io/file_manager.hpp"
namespace HTTP
{
CURL *curl;
CURLcode res;
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
void init()
{
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(!curl)
printf("Error while loading cURL library.\n");
}
XMLNode * getXMLFromPage(std::string url)
{
return NULL;
}
std::string getPage(std::string url)
{
std::string readBuffer;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
return readBuffer;
}
void shutdown()
{
curl_easy_cleanup(curl);
curl_global_cleanup();
}
}

View File

@ -0,0 +1,44 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 SuperTuxKart-Team
//
// 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.
#ifndef HTTP_FUNCTIONS_HPP
#define HTTP_FUNCTIONS_HPP
#include <string>
#include "io/xml_node.hpp"
/**
* \brief HTTP functions to connect with the server
* \ingroup online
*/
namespace HTTP
{
void init();
void shutdown();
std::string getPage(std::string url);
XMLNode * getXMLFromPage(std::string url);
}
#endif // HTTP_FUNCTIONS_HPP
/*EOF*/

View File

@ -0,0 +1,31 @@
//
// 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.
#include "online/online_user.hpp"
#include <sstream>
#include <stdlib.h>
// ============================================================================
OnlineUser::OnlineUser(const std::string &username)
{
} // OnlineUser

View File

@ -0,0 +1,53 @@
//
// 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.
#ifndef HEADER_ONLINE_USER_HPP
#define HEADER_ONLINE_USER_HPP
#include <string>
// ============================================================================
/**
* \brief Class that represents an online registered user
* \ingroup online
*/
class OnlineUser
{
private:
protected:
std::string m_username;
public:
/**
* Constructor
*/
OnlineUser(const std::string &username);
/** Returns the username. */
std::string getUserName() const { return m_username; }
}; // class OnlineUser
#endif
/*EOF*/

View File

@ -1,5 +1,5 @@
// SuperTuxKart - a fun racing game with go-kart // SuperTuxKart - a fun racing game with go-kart
// Copyright (C) Glenn De Jonghe // Copyright (C) 2013 Glenn De Jonghe
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License // modify it under the terms of the GNU General Public License
@ -98,8 +98,6 @@ void LoginDialog::onEnterPressedInternal()
if (size > 0 && nonEmptyChars > 0) if (size > 0 && nonEmptyChars > 0)
{ {
Log::info("Login Dialog","Username : %ls", username.c_str()); Log::info("Login Dialog","Username : %ls", username.c_str());
// It's unsafe to delete from inside the event handler so we do it
// in onUpdate (which checks for m_self_destroy)
m_self_destroy = true; m_self_destroy = true;
} // if valid name } // if valid name
else else

View File

@ -1,5 +1,5 @@
// SuperTuxKart - a fun racing game with go-kart // SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Marianne Gagnon // Copyright (C) 2013 Glenn De Jonghe
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License // modify it under the terms of the GNU General Public License

View File

@ -1,5 +1,5 @@
// SuperTuxKart - a fun racing game with go-kart // SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Marianne Gagnon // Copyright (C) 2013 Glenn De Jonghe
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License // modify it under the terms of the GNU General Public License

View File

@ -202,7 +202,7 @@ void StateManager::onGameStateChange(GameState new_state)
if (new_state == MENU) if (new_state == MENU)
{ {
Screen* screen = GUIEngine::getCurrentScreen(); GUIEngine::Screen* screen = GUIEngine::getCurrentScreen();
if (screen != NULL) if (screen != NULL)
{ {
music_manager->startMusic( music_manager->startMusic(