From: <qr...@us...> - 2006-11-28 20:25:57
|
Revision: 220 http://svn.sourceforge.net/opengate/?rev=220&view=rev Author: qrstuvw Date: 2006-11-28 12:25:56 -0800 (Tue, 28 Nov 2006) Log Message: ----------- Client now auths against META-server Modified Paths: -------------- src/client/Makefile.am src/client/ui/GUIManager.cpp src/client/ui/MainMenu.cpp src/client/ui/MainMenu.h src/opengate_client.cpp src/server/network_meta.cpp Added Paths: ----------- src/client/network_meta.cpp src/client/network_meta.h Modified: src/client/Makefile.am =================================================================== --- src/client/Makefile.am 2006-11-28 20:23:30 UTC (rev 219) +++ src/client/Makefile.am 2006-11-28 20:25:56 UTC (rev 220) @@ -3,9 +3,9 @@ METASOURCES = AUTO noinst_LTLIBRARIES = libopengate-client.la noinst_HEADERS = network.h GameState.h GameStateManager.h Global.h \ - GameManager.h CFunctions.h + GameManager.h CFunctions.h network_meta.h libopengate_client_la_SOURCES = network.cpp GameStateManager.cpp \ - GameManager.cpp + GameManager.cpp network_meta.cpp SUBDIRS = ui libopengate_client_la_LIBADD = $(top_builddir)/src/client/ui/libopengate-ui.la AM_CXXFLAGS = -DTIXML_USE_STL Added: src/client/network_meta.cpp =================================================================== --- src/client/network_meta.cpp (rev 0) +++ src/client/network_meta.cpp 2006-11-28 20:25:56 UTC (rev 220) @@ -0,0 +1,206 @@ +/*************************************************************************** + * network_meta.cpp + * + * Sat Aug 31 21:04:10 2006 + * Copyright 2006 Christoph Brill + * Email <eg...@us...> + ****************************************************************************/ + +/* + * 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 2 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 "network_meta.h" +#include <iostream> +#include <string> +#include <ctime> + +struct MemoryStruct +{ + char *memory; + size_t size; +}; + +void *myrealloc(void *ptr, size_t size) +{ + /* There might be a realloc() out there that doesn't like reallocing NULL pointers, so we take care of it here */ + if(ptr) + return realloc(ptr, size); + else + return malloc(size); +} + +size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) +{ + size_t realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *)data; + + mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); + if (mem->memory) + { + memcpy(&(mem->memory[mem->size]), ptr, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + return realsize; +} + + +NetworkMeta::NetworkMeta() +{ + hostname = "opacma.ontheserver.de"; + curl_global_init(CURL_GLOBAL_ALL); + curl = curl_easy_init(); + //curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); + //curl_easy_setopt(curl, CURLOPT_MUTE, 1); +} + +NetworkMeta::~NetworkMeta() +{ + curl_easy_cleanup(curl); +} + +#define LOGIN_FAILED_NO_USERNAME -1 +#define LOGIN_FAILED_NO_PASSWORD -2 +#define LOGIN_FAILED_USER_NOT_FOUND -3 +#define LOGIN_FAILED_PASSWORD_INCORRECT -4 +#define LOGIN_FAILED_NO_ACTION -101 +#define LOGIN_FAILED_UNKOWN_ACTION -102 +#define LOGIN_FAILED_DATABASE_UNAVAILABLE -103 + +int NetworkMeta::check_login(std::string username, std::string password) +{ + + //FIXME: the password needs some kind of client side encryption to protect against stolen accounts + + std::string request = "http://" + hostname + "/script/schnittstelle/?Action=login&user=" + username + "&password=" + password; + + int retval = -1; + std::string buf; + std::vector<std::string> metaServerData; + struct MemoryStruct chunk; + + chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ + chunk.size = 0; + + curl_easy_setopt(curl, CURLOPT_URL, request.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); + + if (curl_easy_perform(curl) == 0) + { + if (chunk.memory) + { + std::stringstream ss(chunk.memory); + while (ss >> buf) + { + metaServerData.push_back(buf); + } + if (metaServerData.size() != 1) + { + OpenGateConsole::getSingleton().print("Login successful"); + OpenGateConsole::getSingleton().render(); + time_t rawtime; + struct tm * timeinfo; + rawtime = atoi(metaServerData.at(2).c_str()); + timeinfo = localtime ( &rawtime ); + std::string s = asctime (timeinfo); + s = "Last login: "+ s; + std::cout << s; + OpenGateConsole::getSingleton().print(s); + OpenGateConsole::getSingleton().render(); + retval = 1; + } + else + { + OpenGateConsole::getSingleton().print("Login failed!"); + OpenGateConsole::getSingleton().render(); + int errorCode = atoi(metaServerData.at(0).c_str()); + if (errorCode == (LOGIN_FAILED_NO_USERNAME)) + { + OpenGateConsole::getSingleton().print("Reason given by META server: You forgot to enter your username"); + OpenGateConsole::getSingleton().render(); + } + else if (errorCode == LOGIN_FAILED_NO_PASSWORD) + { + OpenGateConsole::getSingleton().print("Reason given by META server: You forgot to enter your password"); + OpenGateConsole::getSingleton().render(); + } + else if (errorCode == LOGIN_FAILED_USER_NOT_FOUND) + { + OpenGateConsole::getSingleton().print("Reason given by META server: User does not exist"); + OpenGateConsole::getSingleton().render(); + } + else if (errorCode == LOGIN_FAILED_PASSWORD_INCORRECT) + { + OpenGateConsole::getSingleton().print("Reason given by META server: Password is incorrect"); + OpenGateConsole::getSingleton().render(); + } + else if (errorCode == LOGIN_FAILED_DATABASE_UNAVAILABLE) + { + OpenGateConsole::getSingleton().print("Reason given by META server: Database is currently unavailable, please try again in a 10 minutes"); + OpenGateConsole::getSingleton().render(); + } + else + { + OpenGateConsole::getSingleton().print("Reason: Unknown error"); + OpenGateConsole::getSingleton().render(); + } + } + } + } + + if (chunk.memory) + { + free(chunk.memory); + } + + return retval; +} + +int NetworkMeta::verify_version() +{ + std::string request = "http://" + hostname + "/script/schnittstelle/termless/version_info.php"; + + int retval = -1; + + struct MemoryStruct chunk; + + chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ + chunk.size = 0; + + curl_easy_setopt(curl, CURLOPT_URL, request.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); + + if (curl_easy_perform(curl) == 0) + { + if (chunk.memory) + { + std::string result = chunk.memory; + retval = result.compare(VERSION); + //TODO: Find out where VERSION comes from!! + } + } + + if (chunk.memory) + { + free(chunk.memory); + } + + return retval; +} Property changes on: src/client/network_meta.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: src/client/network_meta.h =================================================================== --- src/client/network_meta.h (rev 0) +++ src/client/network_meta.h 2006-11-28 20:25:56 UTC (rev 220) @@ -0,0 +1,109 @@ +/*************************************************************************** + * network_meta.h + * + * Sat Aug 31 21:04:10 2006 + * Copyright 2006 Christoph Brill + * Email <eg...@us...> + ****************************************************************************/ + +/* + * 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 2 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 _OPENGATE_NETWORK_META_ +#define _OPENGATE_NETWORK_META_ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <string> +#include <curl/curl.h> +#include "ui/OpenGateConsole.h" +#include <sstream> + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * \brief This class handles the communication from the server to a HTTP-meta-server. + * + * All stuff that needs communication between the server and a metaserver is + * handled here. This so called "stuff" can be anything from the verification + * of the login of a user or informations about the list of active servers + * to current news or economic stuff like prices, availability of products, etc. + * + * \addtogroup Server + * + * \author Christoph Brill + * \version 1.0 + * \date 2006 + */ +class NetworkMeta { +public: + + /*! + * This constructor initializes the networking to the metaserver. It initializes + * libcurl and sets a default hostname of the metaserver. + */ + NetworkMeta(); + + /*! + * This destructor destroys the communication of the meta-server by cleaning up + * libcurl + */ + ~NetworkMeta(); + + /*! + * This function passes the arguments given to the metaserver for getting the + * login-result which is performed against a database. It is part of the + * meta-communication. + * + * \param username The username sent by the client to the server for login + * \param password The password sent by the client to the server for login + */ + int check_login(std::string username, std::string password); + + /*! + * This function allows the server to verify it is running the latest version. It + * should be run on server startup to guarantee that all server run identical + * versions of the game and can talk to each other. It is part of the + * meta-communication. + * + * \return It returns if the version of the metaserver is larger or smaller. + */ + int verify_version(); + +private: + + /*! + * This variable stores the name of the host we use as metaserver + */ + std::string hostname; + + /*! + * This variable holds the reference to curl for communication + */ + CURL *curl; +}; + +#ifdef __cplusplus +} +#endif + + +#endif Property changes on: src/client/network_meta.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: src/client/ui/GUIManager.cpp =================================================================== --- src/client/ui/GUIManager.cpp 2006-11-28 20:23:30 UTC (rev 219) +++ src/client/ui/GUIManager.cpp 2006-11-28 20:25:56 UTC (rev 220) @@ -57,7 +57,7 @@ consoleWindow->addChildWindow(consoleText); consoleText->setPosition(CEGUI::Point(0.0f, 0.0f)); consoleText->setSize(CEGUI::Size(1.0f, 1.0f)); - consoleText->setText("OpenGate 0.1ALPHA\n[Console version 0.0.1BETA]"); + consoleText->setText("OpenGate 0.1ALPHA\nWarning: If you see this, the OpenGateConsole is broken!"); consoleText->setVerticalFormatting(CEGUI::StaticText::BottomAligned); consoleText->setHorizontalFormatting(CEGUI::StaticText::WordWrapLeftAligned); consoleText->setVerticalScrollbarEnabled(true); Modified: src/client/ui/MainMenu.cpp =================================================================== --- src/client/ui/MainMenu.cpp 2006-11-28 20:23:30 UTC (rev 219) +++ src/client/ui/MainMenu.cpp 2006-11-28 20:25:56 UTC (rev 220) @@ -27,11 +27,26 @@ createViewports(); createScene(); createGUI(); + OpenGateConsole::getSingleton().print("Checking OpenGate version..."); + OpenGateConsole::getSingleton().render(); + if (mNWM->verify_version() == 0) + { + OpenGateConsole::getSingleton().print("Version check OK"); + OpenGateConsole::getSingleton().render(); + } + else + { + connectButton->disable(); + usernameBox->disable(); + passwordBox->disable(); + OpenGateConsole::getSingleton().print("Version check failed, press Escape to quit and upgrade your version of OpenGate!"); + OpenGateConsole::getSingleton().render(); + } } //--------------------------------------------------------------------------------// /** Called when exiting this state */ -// Tim: pretty straightforward stuff. Just mail me if there are any questions. +// Tim: pretty straightforward stuff. Just mail me if there are any questions. void MainMenu::exit() { CEGUI::WindowManager::getSingleton().destroyAllWindows(); @@ -66,18 +81,19 @@ void MainMenu::createGUI() { GUI::getSingleton().initGUI(); + GUI::getSingleton().drawConsole(); CEGUI::MouseCursor::getSingleton().show(); // FIXME: Add comment loginWindow = (CEGUI::FrameWindow*)CEGUI::WindowManager::getSingleton().createWindow("OpenGateLook/OGDefaultFrameWindow", (CEGUI::utf8*)"LoginWindow"); mFramework->GUISheet->addChildWindow(loginWindow); - loginWindow->setPosition(CEGUI::Point(0.05f, 0.05f)); + loginWindow->setPosition(CEGUI::Point(0.3f, 0.3f)); loginWindow->setSize(CEGUI::Size(0.4f, 0.6f)); loginWindow->setText("Login"); loginWindow->setTitleBarEnabled(1); loginWindow->setFrameEnabled(1); loginWindow->setTitlebarFont("BlueHighway-10"); loginWindow->setSizingEnabled(false); - loginWindow->setDragMovingEnabled(false); + loginWindow->setDragMovingEnabled(true); //CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)"FrameWindow")->setVisible(true); welcomeText = (CEGUI::StaticText*)CEGUI::WindowManager::getSingleton().createWindow("OpenGateLook/OGStaticText", (CEGUI::utf8*)"WelcomeText"); @@ -121,7 +137,10 @@ // Handle text accepted events usernameBox->subscribeEvent(CEGUI::Editbox::EventTextAccepted, CEGUI::Event::Subscriber(&MainMenu::handleUsernameAccepted, this)); - passwordBox->subscribeEvent(CEGUI::Editbox::EventTextAccepted, CEGUI::Event::Subscriber(&MainMenu::handlePasswordAccepted, this)); + passwordBox->subscribeEvent(CEGUI::Editbox::EventTextAccepted, CEGUI::Event::Subscriber(&MainMenu::handleConnect, this)); + + usernameBox->setSelection(0,64); + usernameBox->activate(); } void MainMenu::createScene() @@ -139,8 +158,46 @@ passwordBox->activate(); } -bool MainMenu::handlePasswordAccepted(const CEGUI::EventArgs& e) + +// TODO: Tim: Omg, wtfbbq make this one function, please +/*bool MainMenu::handlePasswordAccepted(const CEGUI::EventArgs& e) { - GUI::getSingleton().drawConsole(); connectButton->setText("Connecting"); + connectButton->disable(); + usernameBox->disable(); + passwordBox->deactivate(); + passwordBox->disable(); + OpenGateConsole::getSingleton().print("Connecting to the META-server... "); + OpenGateConsole::getSingleton().render(); + if (mNWM->check_login(usernameBox->getText().c_str(), passwordBox->getText().c_str()) != 1) + { + usernameBox->enable(); + usernameBox->activate(); + passwordBox->enable(); + connectButton->enable(); + connectButton->setText("Connect"); + return 0; + } + changeGameState(findByName("PlayState")); +}*/ + +bool MainMenu::handleConnect(const CEGUI::EventArgs& e) +{ + connectButton->setText("Connecting"); + connectButton->disable(); + usernameBox->disable(); + passwordBox->deactivate(); + passwordBox->disable(); + OpenGateConsole::getSingleton().print("Connecting to the META-server... "); + OpenGateConsole::getSingleton().render(); + if (mNWM->check_login(usernameBox->getText().c_str(), passwordBox->getText().c_str()) != 1) + { + usernameBox->enable(); + usernameBox->activate(); + passwordBox->enable(); + connectButton->enable(); + connectButton->setText("Connect"); + return 0; + } + changeGameState(findByName("PlayState")); } Modified: src/client/ui/MainMenu.h =================================================================== --- src/client/ui/MainMenu.h 2006-11-28 20:23:30 UTC (rev 219) +++ src/client/ui/MainMenu.h 2006-11-28 20:25:56 UTC (rev 220) @@ -8,6 +8,8 @@ #include "GameState.h" #include "Global.h" #include "GUIManager.h" +#include "network_meta.h" +#include "OpenGateConsole.h" #include <iostream> @@ -32,25 +34,20 @@ CEGUI::Editbox* passwordBox; CEGUI::PushButton* connectButton; Ogre::Radian mRotScale; + NetworkMeta *mNWM; - /** Ingame GUI stuff */ - CEGUI::ProgressBar* progressBar; - CEGUI::ProgressBar* progressBar1; - CEGUI::ProgressBar* progressBar2; - CEGUI::ProgressBar* progressBar3; - CEGUI::ProgressBar* progressBar4; - CEGUI::ProgressBar* progressBar5; - CEGUI::ProgressBar* progressBar6; // Methods --------------------------------------------------------------------------------- protected: MainMenu() - {} + { + mNWM = new NetworkMeta(); + } ~MainMenu() {} bool handleUsernameAccepted(const CEGUI::EventArgs& e); - bool handlePasswordAccepted(const CEGUI::EventArgs& e); +// bool handlePasswordAccepted(const CEGUI::EventArgs& e); void enter(); void exit(); void createCamera(); @@ -64,10 +61,7 @@ std::cout << "We are in the Main Menu.\n"; } - bool handleConnect(const CEGUI::EventArgs& e) - { - changeGameState(findByName("PlayState")); - } + bool handleConnect(const CEGUI::EventArgs& e); bool frameStarted(const Ogre::FrameEvent& evt) {} Modified: src/opengate_client.cpp =================================================================== --- src/opengate_client.cpp 2006-11-28 20:23:30 UTC (rev 219) +++ src/opengate_client.cpp 2006-11-28 20:25:56 UTC (rev 220) @@ -15,6 +15,10 @@ For now the gui is for CEGUI 0.4.1 */ +/** Killing all network functionality from revision 219 onwards + If you want your old source back, checkout 218 +*/ + // TODO: upgrade CEGUI to latest stable branch bitte /* @@ -50,8 +54,6 @@ #include "client/ui/application.h" #include "common/equipment/capacitor.h" -#include "client/network.h" - #include <OIS/OISException.h> // Tim: maybe everything should be merged in the GameManager class... @@ -140,8 +142,8 @@ } } - Network* nw = new Network(); - nw->login(username, password); +// Network* nw = new Network(); +// nw->login(username, password); /* Loader* loader = new Loader(); loader->parse_file("money.xml"); @@ -229,8 +231,8 @@ */ delete(f_storage); delete(loader); - nw->quit(); - delete(nw); +// nw->quit(); +// delete(nw); cout << "-------------" << std::endl; cout << "Shutting down" << std::endl; Modified: src/server/network_meta.cpp =================================================================== --- src/server/network_meta.cpp 2006-11-28 20:23:30 UTC (rev 219) +++ src/server/network_meta.cpp 2006-11-28 20:25:56 UTC (rev 220) @@ -79,6 +79,8 @@ std::string request = "http://" + hostname + "/script/schnittstelle/?Action=login&user=" + username + "&password=" + password; + std::cout << request; + int retval = -1; struct MemoryStruct chunk; @@ -101,11 +103,12 @@ std::string faction = result.substr(loc1+1, loc2-(loc1+1)); std::string lastlogin = result.substr(loc2+1); - std::cout << userid << ".." << faction << ".." << lastlogin << std::endl; - + std::cout << userid << " " << faction << " " << lastlogin << std::endl; + std::cout << "\n\nther is no spoon in here\n\n"; retval = 1; } else { + std::cout << "\n\nwhat are we doing here?\n\n"; retval = atoi(result.c_str()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |