branch was too much full of bugs
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13148 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="SocketsBase" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/SocketsBase" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/SocketsBase" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
<Add directory="../../src" />
|
||||
<Add directory="/home/hilnius/Development/svn/supertuxkart/main/branches/hilnius/dev/SocketsBase/" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-lpthread" />
|
||||
<Add option="-lcurl" />
|
||||
<Add option="-lenet" />
|
||||
</Linker>
|
||||
<Unit filename="client_network_manager.cpp" />
|
||||
<Unit filename="client_network_manager.hpp" />
|
||||
<Unit filename="event.cpp" />
|
||||
<Unit filename="event.hpp" />
|
||||
<Unit filename="http_functions.cpp" />
|
||||
<Unit filename="http_functions.hpp" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="network_interface.cpp" />
|
||||
<Unit filename="network_interface.hpp" />
|
||||
<Unit filename="network_manager.cpp" />
|
||||
<Unit filename="network_manager.hpp" />
|
||||
<Unit filename="protocol.cpp" />
|
||||
<Unit filename="protocol.hpp" />
|
||||
<Unit filename="protocol_manager.cpp" />
|
||||
<Unit filename="protocol_manager.hpp" />
|
||||
<Unit filename="protocols/connect_to_server.cpp" />
|
||||
<Unit filename="protocols/connect_to_server.hpp" />
|
||||
<Unit filename="protocols/get_peer_address.cpp" />
|
||||
<Unit filename="protocols/get_peer_address.hpp" />
|
||||
<Unit filename="protocols/get_public_address.cpp" />
|
||||
<Unit filename="protocols/get_public_address.hpp" />
|
||||
<Unit filename="protocols/hide_public_address.cpp" />
|
||||
<Unit filename="protocols/hide_public_address.hpp" />
|
||||
<Unit filename="protocols/show_public_address.cpp" />
|
||||
<Unit filename="protocols/show_public_address.hpp" />
|
||||
<Unit filename="server_network_manager.cpp" />
|
||||
<Unit filename="server_network_manager.hpp" />
|
||||
<Unit filename="singleton.hpp" />
|
||||
<Unit filename="stk_host.cpp" />
|
||||
<Unit filename="stk_host.hpp" />
|
||||
<Unit filename="stk_peer.cpp" />
|
||||
<Unit filename="stk_peer.hpp" />
|
||||
<Unit filename="time.cpp" />
|
||||
<Unit filename="time.hpp" />
|
||||
<Unit filename="types.hpp" />
|
||||
<Extensions>
|
||||
<code_completion />
|
||||
<debugger />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
@@ -1,128 +0,0 @@
|
||||
//
|
||||
// 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 "client_network_manager.hpp"
|
||||
|
||||
#include "protocols/get_public_address.hpp"
|
||||
#include "protocols/hide_public_address.hpp"
|
||||
#include "protocols/show_public_address.hpp"
|
||||
#include "protocols/get_peer_address.hpp"
|
||||
#include "protocols/connect_to_server.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
ClientNetworkManager::ClientNetworkManager()
|
||||
{
|
||||
}
|
||||
|
||||
ClientNetworkManager::~ClientNetworkManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ClientNetworkManager::run()
|
||||
{
|
||||
if (enet_initialize() != 0)
|
||||
{
|
||||
printf("Could not initialize enet.\n");
|
||||
return;
|
||||
}
|
||||
m_localhost = new STKHost();
|
||||
m_localhost->setupClient(1, 2, 0, 0);
|
||||
m_localhost->startListening();
|
||||
|
||||
NetworkManager::run();
|
||||
}
|
||||
|
||||
bool ClientNetworkManager::connectToHost(std::string serverNickname)
|
||||
{
|
||||
printf("_NetworkInterface>Starting the connection to host protocol\n");
|
||||
// step 1 : retreive public address
|
||||
Protocol* protocol = new GetPublicAddress(&m_public_address);
|
||||
ProtocolManager::getInstance()->requestStart(protocol);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(protocol) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
printf("_NetworkInterface> The public address is known.\n");
|
||||
|
||||
// step 2 : show the public address for others (here, the server)
|
||||
ShowPublicAddress* spa = new ShowPublicAddress(NULL);
|
||||
spa->setPassword(m_player_login.password);
|
||||
spa->setUsername(m_player_login.username);
|
||||
spa->setPublicAddress(m_public_address.ip, m_public_address.port);
|
||||
ProtocolManager::getInstance()->requestStart(spa);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(spa) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
printf("_NetworkInterface> The public address is being shown online.\n");
|
||||
|
||||
// step 3 : get the server's addres.
|
||||
TransportAddress addr;
|
||||
GetPeerAddress* gpa = new GetPeerAddress(&addr);
|
||||
gpa->setPeerName(serverNickname);
|
||||
ProtocolManager::getInstance()->requestStart(gpa);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(gpa) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
printf("_NetworkInterface> The public address of the server is known.\n");
|
||||
|
||||
// step 4 : connect to the server
|
||||
ConnectToServer* cts = new ConnectToServer(NULL);
|
||||
cts->setServerAddress(addr.ip, addr.port);
|
||||
ProtocolManager::getInstance()->requestStart(cts);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(cts) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
bool success = false;
|
||||
if (m_localhost->isConnectedTo(TransportAddress(addr.ip, addr.port)))
|
||||
{
|
||||
success = true;
|
||||
printf("_NetworkInterface> CONNECTION SUCCES : YOU ARE NOW CONNECTED TO A SERVER.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("_NetworkInterface> We are NOT connected to the server.\n");
|
||||
}
|
||||
// step 5 : hide our public address
|
||||
HidePublicAddress* hpa = new HidePublicAddress(NULL);
|
||||
hpa->setPassword(m_player_login.password);
|
||||
hpa->setUsername(m_player_login.username);
|
||||
ProtocolManager::getInstance()->requestStart(hpa);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(hpa) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
printf("_NetworkInterface> The public address is now hidden online.\n");
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void ClientNetworkManager::packetReceived(char* data)
|
||||
{
|
||||
printf("ClientNetworkManager::packetReceived()\n");
|
||||
puts(data);
|
||||
}
|
||||
void ClientNetworkManager::sendPacket(char* data)
|
||||
{
|
||||
if (m_peers.size() > 1)
|
||||
printf("Ambiguous send of data\n");
|
||||
m_peers[0]->sendPacket(data);
|
||||
}
|
||||
|
||||
STKPeer* ClientNetworkManager::getPeer()
|
||||
{
|
||||
return m_peers[0];
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//
|
||||
// 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 CLIENT_NETWORK_MANAGER_HPP
|
||||
#define CLIENT_NETWORK_MANAGER_HPP
|
||||
|
||||
#include "network_manager.hpp"
|
||||
|
||||
class ClientNetworkManager : public NetworkManager
|
||||
{
|
||||
friend class Singleton<NetworkManager>;
|
||||
public:
|
||||
static ClientNetworkManager* getInstance()
|
||||
{
|
||||
return Singleton<NetworkManager>::getInstance<ClientNetworkManager>();
|
||||
}
|
||||
|
||||
virtual void run();
|
||||
|
||||
bool connectToHost(std::string serverNickname);
|
||||
|
||||
virtual void packetReceived(char* data);
|
||||
virtual void sendPacket(char* data);
|
||||
|
||||
STKPeer* getPeer();
|
||||
|
||||
protected:
|
||||
ClientNetworkManager();
|
||||
virtual ~ClientNetworkManager();
|
||||
};
|
||||
|
||||
#endif // CLIENT_NETWORK_MANAGER_HPP
|
||||
@@ -1,73 +0,0 @@
|
||||
//
|
||||
// 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 "event.hpp"
|
||||
|
||||
#include "network_manager.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
|
||||
Event::Event(ENetEvent* event)
|
||||
{
|
||||
switch (event->type)
|
||||
{
|
||||
case ENET_EVENT_TYPE_CONNECT:
|
||||
type = EVENT_TYPE_CONNECTED;
|
||||
break;
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
type = EVENT_TYPE_DISCONNECTED;
|
||||
break;
|
||||
case ENET_EVENT_TYPE_RECEIVE:
|
||||
type = EVENT_TYPE_MESSAGE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (type == EVENT_TYPE_MESSAGE)
|
||||
data = std::string((char*)(event->packet->data));
|
||||
else if (event->data)
|
||||
data = std::string((char*)(event->data));
|
||||
|
||||
if (event->packet)
|
||||
m_packet = event->packet;
|
||||
|
||||
std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
|
||||
peer = NULL;
|
||||
for (unsigned int i = 0; i < peers.size(); i++)
|
||||
{
|
||||
if (*peers[i] == event->peer)
|
||||
{
|
||||
peer = peers[i];
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (peer == NULL)
|
||||
{
|
||||
printf("The peer still does not exist in %lu peers\n", peers.size());
|
||||
STKPeer* newPeer = new STKPeer();
|
||||
newPeer->m_peer = event->peer;
|
||||
peer = newPeer;
|
||||
}
|
||||
}
|
||||
|
||||
Event::~Event()
|
||||
{
|
||||
if (m_packet)
|
||||
enet_packet_destroy(m_packet);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// 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 EVENT_HPP
|
||||
#define EVENT_HPP
|
||||
|
||||
#include "stk_peer.hpp"
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
/*!
|
||||
* \enum EVENT_TYPE
|
||||
* \brief Represents a network event type.
|
||||
*/
|
||||
enum EVENT_TYPE
|
||||
{
|
||||
EVENT_TYPE_CONNECTED, //!< A peer is connected
|
||||
EVENT_TYPE_DISCONNECTED,//!< A peer is disconnected
|
||||
EVENT_TYPE_MESSAGE //!< A message between server and client protocols
|
||||
};
|
||||
|
||||
/*!
|
||||
* \class Event
|
||||
* \brief Class representing an event that need to pass trough the system.
|
||||
* This is used to remove ENet dependency in the network.
|
||||
* It interfaces the ENetEvent structure.
|
||||
*/
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param event : The event that needs to be translated.
|
||||
*/
|
||||
Event(ENetEvent* event);
|
||||
/*!
|
||||
* \brief Destructor
|
||||
* frees the memory of the ENetPacket.
|
||||
*/
|
||||
~Event();
|
||||
|
||||
EVENT_TYPE type; //!< Type of the event
|
||||
std::string data; //!< Copy of the data passed by the event
|
||||
STKPeer* peer; //!< Pointer to the peer that triggered that event
|
||||
|
||||
private:
|
||||
ENetPacket* m_packet; //!< A pointer on the ENetPacket to be deleted.
|
||||
};
|
||||
|
||||
#endif // EVENT_HPP
|
||||
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// 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 <string>
|
||||
#include <curl/curl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
//
|
||||
// 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 <iostream>
|
||||
#include <enet/enet.h>
|
||||
|
||||
#include "client_network_manager.hpp"
|
||||
#include "server_network_manager.hpp"
|
||||
#include "protocol_manager.hpp"
|
||||
#include "protocols/get_public_address.hpp"
|
||||
#include "http_functions.hpp"
|
||||
#include "protocols/connect_to_server.hpp"
|
||||
#include "protocols/hide_public_address.hpp"
|
||||
#include "network_interface.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
HTTP::init();
|
||||
|
||||
std::string answer;
|
||||
cout << "host or client:";
|
||||
answer = "client";
|
||||
cin >> answer;
|
||||
if (answer == "client")
|
||||
{
|
||||
ClientNetworkManager::getInstance()->run();
|
||||
|
||||
std::string nickname;
|
||||
std::string password;
|
||||
std::string hostNickname;
|
||||
std::cout << "Username=";
|
||||
std::cin >> nickname;
|
||||
std::cout << "Password=";
|
||||
std::cin >> password;
|
||||
|
||||
//NetworkManager::getInstance()->run();
|
||||
|
||||
NetworkManager::getInstance()->setLogin(nickname, password);
|
||||
bool connected = false;
|
||||
//clt.connect(0x0100007f, 7000); // addr in little endian, real address is 7f 00 00 01 (127.0.0.1)
|
||||
std::string buffer;
|
||||
while (1)
|
||||
{
|
||||
getline(std::cin, buffer);
|
||||
if (buffer == "cmd=connect")
|
||||
{
|
||||
cout << "Host Nickname=";
|
||||
std::cin >> hostNickname;
|
||||
connected = ClientNetworkManager::getInstance()->connectToHost(hostNickname);
|
||||
continue;
|
||||
}
|
||||
if (buffer == "cmd=login")
|
||||
{
|
||||
std::cout << "Username=";
|
||||
std::cin >> nickname;
|
||||
std::cout << "Password=";
|
||||
std::cin >> password;
|
||||
NetworkManager::getInstance()->setLogin(nickname, password);
|
||||
}
|
||||
if (buffer.size() == 0) { continue; }
|
||||
char buffer2[256];
|
||||
strcpy(buffer2, buffer.c_str());
|
||||
if (connected)
|
||||
ClientNetworkManager::getInstance()->sendPacket(buffer2);
|
||||
}
|
||||
|
||||
|
||||
enet_deinitialize();
|
||||
}
|
||||
else if (answer == "host")
|
||||
{
|
||||
std::string nickname;
|
||||
std::string password;
|
||||
std::cout << "Username=";
|
||||
std::cin >> nickname;
|
||||
std::cout << "Password=";
|
||||
std::cin >> password;
|
||||
//NetworkInterface::getInstance()->initNetwork(true);
|
||||
ServerNetworkManager::getInstance()->setLogin(nickname, password);
|
||||
ServerNetworkManager::getInstance()->run();
|
||||
ServerNetworkManager::getInstance()->start();
|
||||
//GetPublicAddress
|
||||
|
||||
std::string buffer;
|
||||
while (1)
|
||||
{
|
||||
getline(std::cin, buffer);
|
||||
if (buffer == "cmd=connect")
|
||||
{
|
||||
std::string peer;
|
||||
std::cout << "Peer nickname=";
|
||||
std::cin >> peer;
|
||||
ServerNetworkManager::getInstance()->connectToPeer(peer);
|
||||
continue;
|
||||
}
|
||||
if (buffer == "cmd=talkto")
|
||||
{
|
||||
uint32_t peer;
|
||||
std::cout << "Peer ip=";
|
||||
std::cin >> peer;
|
||||
uint32_t port;
|
||||
std::cout << "Peer port=";
|
||||
std::cin >> port;
|
||||
ServerNetworkManager::getInstance()->setManualSocketsMode(true);
|
||||
char msg[] = "test";
|
||||
ServerNetworkManager::getInstance()->getHost()->sendRawPacket((uint8_t*)(msg), sizeof(msg), TransportAddress(peer, port));
|
||||
ServerNetworkManager::getInstance()->setManualSocketsMode(false);
|
||||
continue;
|
||||
}
|
||||
if (buffer.size() == 0) { continue; }
|
||||
char buffer2[256];
|
||||
strcpy(buffer2, buffer.c_str());
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
//
|
||||
// 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 "network_manager.hpp"
|
||||
|
||||
#include "protocols/hide_public_address.hpp"
|
||||
#include "protocols/show_public_address.hpp"
|
||||
#include "protocols/get_public_address.hpp"
|
||||
|
||||
#include "protocol_manager.hpp"
|
||||
#include "client_network_manager.hpp"
|
||||
#include "server_network_manager.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void* protocolManagerUpdate(void* data)
|
||||
{
|
||||
ProtocolManager* manager = static_cast<ProtocolManager*>(data);
|
||||
while(1)
|
||||
{
|
||||
manager->update();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
NetworkManager::NetworkManager()
|
||||
{
|
||||
m_public_address.ip = 0;
|
||||
m_public_address.port = 0;
|
||||
m_protocol_manager_update_thread = NULL;
|
||||
}
|
||||
|
||||
NetworkManager::~NetworkManager()
|
||||
{
|
||||
}
|
||||
|
||||
void NetworkManager::run()
|
||||
{
|
||||
ProtocolManager::getInstance<ProtocolManager>();
|
||||
m_protocol_manager_update_thread = (pthread_t*)(malloc(sizeof(pthread_t)));
|
||||
pthread_create(m_protocol_manager_update_thread, NULL, protocolManagerUpdate, ProtocolManager::getInstance());
|
||||
}
|
||||
|
||||
bool NetworkManager::connect(TransportAddress peer)
|
||||
{
|
||||
if (peerExists(peer))
|
||||
return isConnectedTo(peer);
|
||||
|
||||
return STKPeer::connectToHost(m_localhost, peer, 2, 0);
|
||||
}
|
||||
|
||||
void NetworkManager::setManualSocketsMode(bool manual)
|
||||
{
|
||||
if (manual)
|
||||
m_localhost->stopListening();
|
||||
else
|
||||
m_localhost->startListening();
|
||||
}
|
||||
|
||||
void NetworkManager::notifyEvent(Event* event)
|
||||
{
|
||||
printf("EVENT received\n");
|
||||
switch (event->type)
|
||||
{
|
||||
case EVENT_TYPE_MESSAGE:
|
||||
printf("Message, Sender : %u, message = \"%s\"\n", event->peer->getAddress(), event->data.c_str());
|
||||
break;
|
||||
case EVENT_TYPE_DISCONNECTED:
|
||||
printf("Somebody is now disconnected. There are now %lu peers.\n", m_peers.size());
|
||||
printf("Disconnected host: %i.%i.%i.%i:%i\n", event->peer->getAddress()>>24&0xff, event->peer->getAddress()>>16&0xff, event->peer->getAddress()>>8&0xff, event->peer->getAddress()&0xff,event->peer->getPort());
|
||||
// remove the peer:
|
||||
for (unsigned int i = 0; i < m_peers.size(); i++)
|
||||
{
|
||||
if (m_peers[i] == event->peer)
|
||||
{
|
||||
delete m_peers[i];
|
||||
m_peers.erase(m_peers.begin()+i, m_peers.begin()+i+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("ERROR : the peer that has been disconnected was not registered by the Network Manager.\n");
|
||||
break;
|
||||
case EVENT_TYPE_CONNECTED:
|
||||
printf("A client has just connected. There are now %lu peers.\n", m_peers.size() + 1);
|
||||
// create the new peer:
|
||||
m_peers.push_back(event->peer);
|
||||
break;
|
||||
}
|
||||
ProtocolManager::getInstance()->notifyEvent(event);
|
||||
}
|
||||
|
||||
void NetworkManager::setLogin(std::string username, std::string password)
|
||||
{
|
||||
m_player_login.username = username;
|
||||
m_player_login.password = password;
|
||||
}
|
||||
|
||||
void NetworkManager::setPublicAddress(TransportAddress addr)
|
||||
{
|
||||
m_public_address = addr;
|
||||
}
|
||||
|
||||
bool NetworkManager::peerExists(TransportAddress peer)
|
||||
{
|
||||
return m_localhost->peerExists(peer);
|
||||
}
|
||||
|
||||
bool NetworkManager::isConnectedTo(TransportAddress peer)
|
||||
{
|
||||
return m_localhost->isConnectedTo(peer);
|
||||
}
|
||||
|
||||
STKHost* NetworkManager::getHost()
|
||||
{
|
||||
return m_localhost;
|
||||
}
|
||||
|
||||
std::vector<STKPeer*> NetworkManager::getPeers()
|
||||
{
|
||||
return m_peers;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
//
|
||||
// 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 NETWORKMANAGER_HPP
|
||||
#define NETWORKMANAGER_HPP
|
||||
|
||||
#include "stk_peer.hpp"
|
||||
#include "stk_host.hpp"
|
||||
#include <vector>
|
||||
|
||||
#include "protocol_manager.hpp"
|
||||
#include "singleton.hpp"
|
||||
#include "types.hpp"
|
||||
#include "event.hpp"
|
||||
|
||||
class NetworkManager : public Singleton<NetworkManager>
|
||||
{
|
||||
friend class Singleton<NetworkManager>;
|
||||
public:
|
||||
virtual void run();
|
||||
|
||||
// network management functions
|
||||
virtual bool connect(TransportAddress peer);
|
||||
virtual void setManualSocketsMode(bool manual);
|
||||
virtual void notifyEvent(Event* event);
|
||||
virtual void packetReceived(char* data) = 0;
|
||||
|
||||
// raw data management
|
||||
void setLogin(std::string username, std::string password);
|
||||
void setPublicAddress(TransportAddress addr);
|
||||
|
||||
// getters
|
||||
virtual bool peerExists(TransportAddress peer);
|
||||
virtual bool isConnectedTo(TransportAddress peer);
|
||||
STKHost* getHost();
|
||||
std::vector<STKPeer*> getPeers();
|
||||
protected:
|
||||
NetworkManager();
|
||||
virtual ~NetworkManager();
|
||||
|
||||
// protected members
|
||||
std::vector<STKPeer*> m_peers;
|
||||
STKHost* m_localhost;
|
||||
|
||||
TransportAddress m_public_address;
|
||||
PlayerLogin m_player_login;
|
||||
|
||||
pthread_t* m_protocol_manager_update_thread;
|
||||
};
|
||||
|
||||
#endif // NETWORKMANAGER_HPP
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// 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 "protocol.hpp"
|
||||
|
||||
Protocol::Protocol(CallbackObject* callback_object, PROTOCOL_TYPE type)
|
||||
{
|
||||
m_callback_object = callback_object;
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
Protocol::~Protocol()
|
||||
{
|
||||
}
|
||||
|
||||
void Protocol::pause()
|
||||
{
|
||||
m_listener->requestPause(this);
|
||||
}
|
||||
void Protocol::unpause()
|
||||
{
|
||||
m_listener->requestUnpause(this);
|
||||
}
|
||||
|
||||
|
||||
void Protocol::setListener(ProtocolManager* listener)
|
||||
{
|
||||
m_listener = listener;
|
||||
}
|
||||
|
||||
PROTOCOL_TYPE Protocol::getProtocolType()
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
//
|
||||
// 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 PROTOCOL_HPP
|
||||
#define PROTOCOL_HPP
|
||||
|
||||
#include "protocol_manager.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/** \enum PROTOCOL_TYPE
|
||||
* \brief The types that protocols can have. This is used to select which protocol receives which event.
|
||||
* \ingroup network
|
||||
*/
|
||||
enum PROTOCOL_TYPE
|
||||
{
|
||||
PROTOCOL_NONE = 0, //!< No protocol type assigned.
|
||||
PROTOCOL_CONNECTION = 1, //!< Protocol that deals with client-server connection.
|
||||
PROTOCOL_LOBBY_ROOM = 2, //!< Protocol that is used during the lobby room phase.
|
||||
PROTOCOL_SILENT = 0xffff //!< Used for protocols that do not subscribe to any network event.
|
||||
};
|
||||
|
||||
/** \class Protocol
|
||||
* \brief Abstract class used to define the global protocol functions.
|
||||
* A protocol is an entity that is started at a point, and that is updated by a thread.
|
||||
* A protocol can be terminated by an other class, or it can terminate itself if has fulfilled its role.
|
||||
* This class must be inherited to make any network job.
|
||||
* \ingroup network
|
||||
*/
|
||||
class Protocol
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Constructor
|
||||
*
|
||||
* Sets the basic protocol parameters, as the callback object and the protocol type.
|
||||
*
|
||||
* \param callback_object The callback object that will be used by the protocol. Protocols that do not use callback objects must set it to NULL.
|
||||
* \param type The type of the protocol.
|
||||
*/
|
||||
Protocol(CallbackObject* callback_object, PROTOCOL_TYPE type);
|
||||
/*!
|
||||
* \brief Destructor
|
||||
*/
|
||||
virtual ~Protocol();
|
||||
|
||||
/*!
|
||||
* \brief Notify a protocol matching the Event type of that event.
|
||||
* \param event : Pointer to the event.
|
||||
*/
|
||||
virtual void notifyEvent(Event* event) = 0;
|
||||
|
||||
/*!
|
||||
* \brief Set the protocol listener.
|
||||
* \param listener : Pointer to the listener.
|
||||
*/
|
||||
void setListener(ProtocolManager* listener);
|
||||
|
||||
/*!
|
||||
* \brief Called when the protocol is going to start. Must be re-defined by subclasses.
|
||||
*/
|
||||
virtual void setup() = 0;
|
||||
/*!
|
||||
* \brief Called when the protocol is paused (by an other entity or by itself).
|
||||
* This function must be called by the subclasse's pause function if re-defined.
|
||||
*/
|
||||
virtual void pause();
|
||||
/*!
|
||||
* \brief Called when the protocol is unpaused.
|
||||
* This function must be called by the subclasse's unpause function if re-defined.
|
||||
*/
|
||||
virtual void unpause();
|
||||
/*!
|
||||
* \brief Called by the protocol listener as often as possible. Must be re-defined.
|
||||
*/
|
||||
virtual void update() = 0;
|
||||
|
||||
/*!
|
||||
* \brief Method to get a protocol's type.
|
||||
* \return The protocol type.
|
||||
*/
|
||||
PROTOCOL_TYPE getProtocolType();
|
||||
protected:
|
||||
ProtocolManager* m_listener; //!< The protocol listener
|
||||
PROTOCOL_TYPE m_type; //!< The type of the protocol
|
||||
CallbackObject* m_callback_object; //!< The callback object, if needed
|
||||
};
|
||||
|
||||
#endif // PROTOCOL_HPP
|
||||
@@ -1,287 +0,0 @@
|
||||
//
|
||||
// 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 "protocol_manager.hpp"
|
||||
|
||||
#include "protocol.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#define RAND_MAX 65536
|
||||
|
||||
ProtocolManager::ProtocolManager()
|
||||
{
|
||||
pthread_mutex_init(&m_events_mutex, NULL);
|
||||
pthread_mutex_init(&m_protocols_mutex, NULL);
|
||||
pthread_mutex_init(&m_requests_mutex, NULL);
|
||||
pthread_mutex_init(&m_id_mutex, NULL);
|
||||
m_next_protocol_id = 0;
|
||||
}
|
||||
|
||||
ProtocolManager::~ProtocolManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ProtocolManager::notifyEvent(Event* event)
|
||||
{
|
||||
pthread_mutex_lock(&m_events_mutex);
|
||||
m_events_to_process.push_back(event); // add the event to the queue
|
||||
pthread_mutex_unlock(&m_events_mutex);
|
||||
}
|
||||
|
||||
void ProtocolManager::sendMessage(std::string message)
|
||||
{
|
||||
std::string newMessage = " " + message; // add one byte
|
||||
newMessage[0] = (char)(0);
|
||||
}
|
||||
|
||||
int ProtocolManager::requestStart(Protocol* protocol)
|
||||
{
|
||||
// create the request
|
||||
ProtocolRequest req;
|
||||
ProtocolInfo info;
|
||||
info.protocol = protocol;
|
||||
info.state = PROTOCOL_STATE_RUNNING;
|
||||
assignProtocolId(&info); // assign a unique id to the protocol.
|
||||
req.protocol_info = info;
|
||||
req.type = PROTOCOL_REQUEST_START;
|
||||
// add it to the request stack
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
|
||||
return info.id;
|
||||
}
|
||||
|
||||
void ProtocolManager::requestStop(Protocol* protocol)
|
||||
{
|
||||
// create the request
|
||||
ProtocolRequest req;
|
||||
req.protocol_info.protocol = protocol;
|
||||
req.type = PROTOCOL_REQUEST_STOP;
|
||||
// add it to the request stack
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
|
||||
void ProtocolManager::requestPause(Protocol* protocol)
|
||||
{
|
||||
// create the request
|
||||
ProtocolRequest req;
|
||||
req.protocol_info.protocol = protocol;
|
||||
req.type = PROTOCOL_REQUEST_PAUSE;
|
||||
// add it to the request stack
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
|
||||
void ProtocolManager::requestUnpause(Protocol* protocol)
|
||||
{
|
||||
// create the request
|
||||
ProtocolRequest req;
|
||||
req.protocol_info.protocol = protocol;
|
||||
req.type = PROTOCOL_REQUEST_UNPAUSE;
|
||||
// add it to the request stack
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
|
||||
void ProtocolManager::requestTerminate(Protocol* protocol)
|
||||
{
|
||||
// create the request
|
||||
ProtocolRequest req;
|
||||
req.protocol_info.protocol = protocol;
|
||||
req.type = PROTOCOL_REQUEST_TERMINATE;
|
||||
// add it to the request stack
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
m_requests.push_back(req);
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
|
||||
void ProtocolManager::startProtocol(ProtocolInfo protocol)
|
||||
{
|
||||
printf("__ProtocolManager> A new protocol with id=%u has been started. There are %ld protocols running.\n", protocol.id, m_protocols.size()+1);
|
||||
// add the protocol to the protocol vector so that it's updated
|
||||
pthread_mutex_lock(&m_protocols_mutex);
|
||||
m_protocols.push_back(protocol);
|
||||
pthread_mutex_unlock(&m_protocols_mutex);
|
||||
// setup the protocol and notify it that it's started
|
||||
protocol.protocol->setListener(this);
|
||||
protocol.protocol->setup();
|
||||
}
|
||||
void ProtocolManager::stopProtocol(ProtocolInfo protocol)
|
||||
{
|
||||
|
||||
}
|
||||
void ProtocolManager::pauseProtocol(ProtocolInfo protocol)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol == protocol.protocol && m_protocols[i].state == PROTOCOL_STATE_RUNNING)
|
||||
{
|
||||
m_protocols[i].state = PROTOCOL_STATE_PAUSED;
|
||||
m_protocols[i].protocol->pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
void ProtocolManager::unpauseProtocol(ProtocolInfo protocol)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol == protocol.protocol && m_protocols[i].state == PROTOCOL_STATE_PAUSED)
|
||||
{
|
||||
m_protocols[i].state = PROTOCOL_STATE_RUNNING;
|
||||
m_protocols[i].protocol->unpause();
|
||||
}
|
||||
}
|
||||
}
|
||||
void ProtocolManager::protocolTerminated(ProtocolInfo protocol)
|
||||
{
|
||||
pthread_mutex_lock(&m_protocols_mutex); // be sure that noone accesses the protocols vector while we erase a protocol
|
||||
int offset = 0;
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
{
|
||||
if (m_protocols[i-offset].protocol == protocol.protocol)
|
||||
{
|
||||
delete m_protocols[i].protocol;
|
||||
m_protocols.erase(m_protocols.begin()+(i-offset), m_protocols.begin()+(i-offset)+1);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
printf("__ProtocolManager> A protocol has been terminated. There are %ld protocols running.\n", m_protocols.size());
|
||||
pthread_mutex_unlock(&m_protocols_mutex);
|
||||
}
|
||||
|
||||
void ProtocolManager::update()
|
||||
{
|
||||
// before updating, notice protocols that they have received information
|
||||
pthread_mutex_lock(&m_events_mutex); // secure threads
|
||||
int size = m_events_to_process.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
Event* event = m_events_to_process.back();
|
||||
|
||||
PROTOCOL_TYPE searchedProtocol = PROTOCOL_NONE;
|
||||
if (event->data.size() > 0)
|
||||
searchedProtocol = (PROTOCOL_TYPE)(event->data[0]);
|
||||
for (unsigned int i = 0; i < m_protocols.size() ; i++)
|
||||
{
|
||||
if (m_protocols[i].protocol->getProtocolType() == searchedProtocol || event->type != EVENT_TYPE_MESSAGE) // pass data to protocols even when paused
|
||||
m_protocols[i].protocol->notifyEvent(event);
|
||||
}
|
||||
delete event;
|
||||
m_events_to_process.pop_back();
|
||||
}
|
||||
pthread_mutex_unlock(&m_events_mutex); // release the mutex
|
||||
|
||||
// now update all protocols
|
||||
pthread_mutex_lock(&m_protocols_mutex);
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
{
|
||||
if (m_protocols[i].state == PROTOCOL_STATE_RUNNING)
|
||||
m_protocols[i].protocol->update();
|
||||
}
|
||||
pthread_mutex_unlock(&m_protocols_mutex);
|
||||
|
||||
// process queued events for protocols
|
||||
pthread_mutex_lock(&m_requests_mutex);
|
||||
for (unsigned int i = 0; i < m_requests.size(); i++)
|
||||
{
|
||||
switch (m_requests[i].type)
|
||||
{
|
||||
case PROTOCOL_REQUEST_START:
|
||||
startProtocol(m_requests[i].protocol_info);
|
||||
break;
|
||||
case PROTOCOL_REQUEST_STOP:
|
||||
stopProtocol(m_requests[i].protocol_info);
|
||||
break;
|
||||
case PROTOCOL_REQUEST_PAUSE:
|
||||
pauseProtocol(m_requests[i].protocol_info);
|
||||
break;
|
||||
case PROTOCOL_REQUEST_UNPAUSE:
|
||||
unpauseProtocol(m_requests[i].protocol_info);
|
||||
break;
|
||||
case PROTOCOL_REQUEST_TERMINATE:
|
||||
protocolTerminated(m_requests[i].protocol_info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_requests.clear();
|
||||
pthread_mutex_unlock(&m_requests_mutex);
|
||||
}
|
||||
|
||||
int ProtocolManager::runningProtocolsCount()
|
||||
{
|
||||
return m_protocols.size();
|
||||
}
|
||||
|
||||
PROTOCOL_STATE ProtocolManager::getProtocolState(uint32_t id)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
{
|
||||
if (m_protocols[i].id == id) // we know a protocol with that id
|
||||
return m_protocols[i].state; // return its state
|
||||
}
|
||||
// the protocol isn't running right now
|
||||
for (unsigned int i = 0; i < m_requests.size(); i++)
|
||||
{
|
||||
if (m_requests[i].protocol_info.id == id) // the protocol is going to be started
|
||||
return PROTOCOL_STATE_RUNNING; // we can say it's running
|
||||
}
|
||||
return PROTOCOL_STATE_TERMINATED; // else, it's already finished
|
||||
}
|
||||
|
||||
PROTOCOL_STATE ProtocolManager::getProtocolState(Protocol* protocol)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol == protocol) // the protocol is known
|
||||
return m_protocols[i].state; // return its state
|
||||
}
|
||||
for (unsigned int i = 0; i < m_requests.size(); i++)
|
||||
{
|
||||
if (m_requests[i].protocol_info.protocol == protocol) // the protocol is going to be started
|
||||
return PROTOCOL_STATE_RUNNING; // we can say it's running
|
||||
}
|
||||
return PROTOCOL_STATE_TERMINATED; // we don't know this protocol at all, it's finished
|
||||
}
|
||||
|
||||
int ProtocolManager::getProtocolID(Protocol* protocol)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_protocols.size(); i++)
|
||||
{
|
||||
if (m_protocols[i].protocol == protocol)
|
||||
return m_protocols[i].id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ProtocolManager::assignProtocolId(ProtocolInfo* protocol_info)
|
||||
{
|
||||
pthread_mutex_lock(&m_id_mutex);
|
||||
protocol_info->id = m_next_protocol_id;
|
||||
m_next_protocol_id++;
|
||||
pthread_mutex_unlock(&m_id_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,266 +0,0 @@
|
||||
//
|
||||
// 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.
|
||||
|
||||
/*! \file protocol_manager.hpp
|
||||
* \brief Contains structures and enumerations related to protocol management.
|
||||
*/
|
||||
|
||||
#ifndef PROTOCOL_MANAGER_HPP
|
||||
#define PROTOCOL_MANAGER_HPP
|
||||
|
||||
#include "singleton.hpp"
|
||||
#include "event.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
class Protocol;
|
||||
|
||||
/*!
|
||||
* \enum PROTOCOL_STATE
|
||||
* \brief Defines the three states that a protocol can have.
|
||||
*/
|
||||
enum PROTOCOL_STATE
|
||||
{
|
||||
PROTOCOL_STATE_RUNNING, //!< The protocol is being updated everytime.
|
||||
PROTOCOL_STATE_PAUSED, //!< The protocol is paused.
|
||||
PROTOCOL_STATE_TERMINATED //!< The protocol is terminated/does not exist.
|
||||
};
|
||||
|
||||
/*!
|
||||
* \enum PROTOCOL_REQUEST_TYPE
|
||||
* \brief Defines actions that can be done about protocols.
|
||||
* This enum is used essentially to keep the manager thread-safe and
|
||||
* to avoid protocols modifying directly their state.
|
||||
*/
|
||||
enum PROTOCOL_REQUEST_TYPE
|
||||
{
|
||||
PROTOCOL_REQUEST_START, //!< Start a protocol
|
||||
PROTOCOL_REQUEST_STOP, //!< Stop a protocol
|
||||
PROTOCOL_REQUEST_PAUSE, //!< Pause a protocol
|
||||
PROTOCOL_REQUEST_UNPAUSE, //!< Unpause a protocol
|
||||
PROTOCOL_REQUEST_TERMINATE //!< Terminate a protocol
|
||||
};
|
||||
|
||||
/*!
|
||||
* \struct ProtocolInfo
|
||||
* \brief Stores the information needed to manage protocols
|
||||
*/
|
||||
typedef struct ProtocolInfo
|
||||
{
|
||||
PROTOCOL_STATE state; //!< The state of the protocol
|
||||
Protocol* protocol; //!< A pointer to the protocol
|
||||
uint32_t id; //!< The unique id of the protocol
|
||||
} ProtocolInfo;
|
||||
|
||||
/*!
|
||||
* \struct ProtocolRequest
|
||||
* \brief Represents a request to do an action about a protocol.
|
||||
*/
|
||||
typedef struct ProtocolRequest
|
||||
{
|
||||
PROTOCOL_REQUEST_TYPE type; //!< The type of request
|
||||
ProtocolInfo protocol_info; //!< The concerned protocol information
|
||||
} ProtocolRequest;
|
||||
|
||||
/*!
|
||||
* \class ProtocolManager
|
||||
* \brief Manages the protocols at runtime.
|
||||
*
|
||||
* This class is in charge of storing and managing protocols.
|
||||
* It is a singleton as there can be only one protocol manager per game
|
||||
* instance. Any game object that wants to start a protocol must create a
|
||||
* protocol and give it to this singleton. The protocols are updated in a
|
||||
* special thread, to ensure that they are processed independently from the
|
||||
* frames per second. Then, the management of protocols is thread-safe: any
|
||||
* object can start/pause/stop protocols whithout problems.
|
||||
*/
|
||||
class ProtocolManager : public Singleton<ProtocolManager>
|
||||
{
|
||||
friend class Singleton<ProtocolManager>;
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Function that processes incoming events.
|
||||
* This function is called by the network manager each time there is an
|
||||
* incoming packet.
|
||||
*/
|
||||
virtual void notifyEvent(Event* event);
|
||||
/*!
|
||||
* \brief WILL BE COMMENTED LATER
|
||||
*/
|
||||
virtual void sendMessage(std::string message);
|
||||
|
||||
/*!
|
||||
* \brief Asks the manager to start a protocol.
|
||||
* This function will store the request, and process it at a time it is
|
||||
* thread-safe.
|
||||
* \param protocol : A pointer to the protocol to start
|
||||
* \return The unique id of the protocol that is being started.
|
||||
*/
|
||||
virtual int requestStart(Protocol* protocol);
|
||||
/*!
|
||||
* \brief Asks the manager to stop a protocol.
|
||||
* This function will store the request, and process it at a time it is
|
||||
* thread-safe.
|
||||
* \param protocol : A pointer to the protocol to stop
|
||||
*/
|
||||
virtual void requestStop(Protocol* protocol);
|
||||
/*!
|
||||
* \brief Asks the manager to pause a protocol.
|
||||
* This function will store the request, and process it at a time it is
|
||||
* thread-safe.
|
||||
* \param protocol : A pointer to the protocol to pause
|
||||
*/
|
||||
virtual void requestPause(Protocol* protocol);
|
||||
/*!
|
||||
* \brief Asks the manager to unpause a protocol.
|
||||
* This function will store the request, and process it at a time it is
|
||||
* thread-safe.
|
||||
* \param protocol : A pointer to the protocol to unpause
|
||||
*/
|
||||
virtual void requestUnpause(Protocol* protocol);
|
||||
/*!
|
||||
* \brief Notifies the manager that a protocol is terminated.
|
||||
* This function will store the request, and process it at a time it is
|
||||
* thread-safe.
|
||||
* \param protocol : A pointer to the protocol that is finished
|
||||
*/
|
||||
virtual void requestTerminate(Protocol* protocol);
|
||||
|
||||
/*!
|
||||
* \brief Updates the manager.
|
||||
*
|
||||
* This function processes the events queue, notifies the concerned
|
||||
* protocols that they have events to process. Then ask all protocols
|
||||
* to update themselves. Finally processes stored requests about
|
||||
* starting, stoping, pausing etc... protocols.
|
||||
* This function is called by a thread as often as possible.
|
||||
* This function is not FPS-dependant.
|
||||
*/
|
||||
virtual void update();
|
||||
|
||||
/*!
|
||||
* \brief Get the number of protocols running.
|
||||
* \return The number of protocols that are actually running.
|
||||
*/
|
||||
virtual int runningProtocolsCount();
|
||||
/*!
|
||||
* \brief Get the state of a protocol using its id.
|
||||
* \param id : The id of the protocol you seek the state.
|
||||
* \return The state of the protocol.
|
||||
*/
|
||||
virtual PROTOCOL_STATE getProtocolState(uint32_t id);
|
||||
/*!
|
||||
* \brief Get the state of a protocol using a pointer on it.
|
||||
* \param protocol : A pointer to the protocol you seek the state.
|
||||
* \return The state of the protocol.
|
||||
*/
|
||||
virtual PROTOCOL_STATE getProtocolState(Protocol* protocol);
|
||||
/*!
|
||||
* \brief Get the id of a protocol.
|
||||
* \param protocol : A pointer to the protocol you seek the id.
|
||||
* \return The id of the protocol pointed by the protocol parameter.
|
||||
*/
|
||||
virtual int getProtocolID(Protocol* protocol);
|
||||
|
||||
protected:
|
||||
// protected functions
|
||||
/*!
|
||||
* \brief Constructor
|
||||
*/
|
||||
ProtocolManager();
|
||||
/*!
|
||||
* \brief Destructor
|
||||
*/
|
||||
virtual ~ProtocolManager();
|
||||
/*!
|
||||
* \brief Assign an id to a protocol.
|
||||
* This function will assign m_next_protocol_id as the protocol id.
|
||||
* This id starts at 0 at the beginning and is increased by 1 each time
|
||||
* a protocol starts.
|
||||
* \param protocol_info : The protocol info that needs an id.
|
||||
*/
|
||||
void assignProtocolId(ProtocolInfo* protocol_info);
|
||||
|
||||
/*!
|
||||
* \brief Starts a protocol.
|
||||
* Add the protocol info to the m_protocols vector.
|
||||
* \param protocol : ProtocolInfo to start.
|
||||
*/
|
||||
virtual void startProtocol(ProtocolInfo protocol);
|
||||
/*!
|
||||
* \brief Stops a protocol.
|
||||
* Coes nothing. Noone can stop running protocols for now.
|
||||
* \param protocol : ProtocolInfo to stop.
|
||||
*/
|
||||
virtual void stopProtocol(ProtocolInfo protocol);
|
||||
/*!
|
||||
* \brief Pauses a protocol.
|
||||
* Pauses a protocol and tells it that it's being paused.
|
||||
* \param protocol : ProtocolInfo to pause.
|
||||
*/
|
||||
virtual void pauseProtocol(ProtocolInfo protocol);
|
||||
/*!
|
||||
* \brief Unpauses a protocol.
|
||||
* Unpauses a protocol and notifies it.
|
||||
* \param protocol : ProtocolInfo to unpause.
|
||||
*/
|
||||
virtual void unpauseProtocol(ProtocolInfo protocol);
|
||||
/*!
|
||||
* \brief Notes that a protocol is terminated.
|
||||
* Remove a protocol from the protocols vector.
|
||||
* \param protocol : ProtocolInfo concerned.
|
||||
*/
|
||||
virtual void protocolTerminated(ProtocolInfo protocol);
|
||||
|
||||
// protected members
|
||||
/*!
|
||||
* \brief Contains the running protocols.
|
||||
* This stores the protocols that are either running or paused, their
|
||||
* state and their unique id.
|
||||
*/
|
||||
std::vector<ProtocolInfo> m_protocols;
|
||||
/*!
|
||||
* \brief Contains the network events to pass to protocols.
|
||||
*/
|
||||
std::vector<Event*> m_events_to_process;
|
||||
/*!
|
||||
* \brief Contains the requests to start/stop etc... protocols.
|
||||
*/
|
||||
std::vector<ProtocolRequest> m_requests;
|
||||
/*! \brief The next id to assign to a protocol.
|
||||
* This value is incremented by 1 each time a protocol is started.
|
||||
* If a protocol has an id lower than this value, it means that it have
|
||||
* been formerly started.
|
||||
*/
|
||||
unsigned int m_next_protocol_id;
|
||||
|
||||
// mutexes:
|
||||
/*! Used to ensure that the event queue is used thread-safely. */
|
||||
pthread_mutex_t m_events_mutex;
|
||||
/*! Used to ensure that the protocol vector is used thread-safely. */
|
||||
pthread_mutex_t m_protocols_mutex;
|
||||
/*! Used to ensure that the request vector is used thread-safely. */
|
||||
pthread_mutex_t m_requests_mutex;
|
||||
/*! Used to ensure that the protocol id is used in a thread-safe way.*/
|
||||
pthread_mutex_t m_id_mutex;
|
||||
|
||||
};
|
||||
|
||||
#endif // PROTOCOL_MANAGER_HPP
|
||||
@@ -1,110 +0,0 @@
|
||||
//
|
||||
// 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 "protocols/connect_to_server.hpp"
|
||||
|
||||
#include "client_network_manager.hpp"
|
||||
#include "time.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ConnectToServer::ConnectToServer(CallbackObject* callback_object) :
|
||||
Protocol(callback_object, PROTOCOL_CONNECTION)
|
||||
{
|
||||
m_server_ip = 0;
|
||||
m_server_port = 0;
|
||||
m_state = NONE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ConnectToServer::~ConnectToServer()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ConnectToServer::notifyEvent(Event* event)
|
||||
{
|
||||
if (event->type == EVENT_TYPE_CONNECTED &&
|
||||
event->peer->getAddress() == m_server_ip &&
|
||||
event->peer->getPort() == m_server_port)
|
||||
{
|
||||
printf("The Connect To Server protocol has received an event notifying \
|
||||
that he's connected to the peer. The peer sent \"%s\"\n",
|
||||
event->data.c_str());
|
||||
m_state = DONE; // we received a message, we are connected
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ConnectToServer::setup()
|
||||
{
|
||||
m_state = NONE;
|
||||
if (m_server_ip == 0 || m_server_port == 0 )
|
||||
{
|
||||
printf("You have to set the server's public ip:port of the server.\n");
|
||||
m_listener->requestTerminate(this);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ConnectToServer::update()
|
||||
{
|
||||
if (m_state == NONE)
|
||||
{
|
||||
static double target = 0;
|
||||
double currentTime = Time::getSeconds();
|
||||
// sometimes the getSeconds method forgets 3600 seconds.
|
||||
while (currentTime < target-1800)
|
||||
currentTime += 3600;
|
||||
if (currentTime > target)
|
||||
{
|
||||
NetworkManager::getInstance()->connect(
|
||||
TransportAddress(m_server_ip, m_server_port));
|
||||
if (NetworkManager::getInstance()->isConnectedTo(
|
||||
TransportAddress(m_server_ip, m_server_port)))
|
||||
{
|
||||
m_state = DONE;
|
||||
return;
|
||||
}
|
||||
target = currentTime+5;
|
||||
printf("Retrying to connect in 5 seconds.\n");
|
||||
}
|
||||
}
|
||||
else if (m_state == DONE)
|
||||
{
|
||||
m_listener->requestTerminate(this);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ConnectToServer::setServerAddress(uint32_t ip, uint16_t port)
|
||||
{
|
||||
m_server_ip = ip;
|
||||
m_server_port = port;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
//
|
||||
// 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 "protocols/get_peer_address.hpp"
|
||||
|
||||
#include "time.hpp"
|
||||
#include "http_functions.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
GetPeerAddress::GetPeerAddress(CallbackObject* callback_object) : Protocol(callback_object, PROTOCOL_SILENT)
|
||||
{
|
||||
}
|
||||
|
||||
GetPeerAddress::~GetPeerAddress()
|
||||
{
|
||||
}
|
||||
|
||||
void GetPeerAddress::notifyEvent(Event* event)
|
||||
{
|
||||
}
|
||||
|
||||
void GetPeerAddress::setup()
|
||||
{
|
||||
m_state = NONE;
|
||||
}
|
||||
|
||||
void GetPeerAddress::update()
|
||||
{
|
||||
if (m_state == NONE)
|
||||
{
|
||||
static double target = 0;
|
||||
double current_time = Time::getSeconds();
|
||||
while (current_time < target-1800) // sometimes the getSeconds method forgets 3600 seconds.
|
||||
current_time += 3600;
|
||||
if (current_time > target)
|
||||
{
|
||||
char url[512];
|
||||
sprintf(url, "http://stkconnect.freeserver.me/log.php?get&nick=%s", m_peer_name.c_str());
|
||||
std::string result = HTTP::getPage(url);
|
||||
if (result == "")
|
||||
{
|
||||
printf("__GetPeerAddress> The host you try to reach does not exist. Change the host name please.\n");
|
||||
pause();
|
||||
return;
|
||||
}
|
||||
std::string ip_addr = result;
|
||||
ip_addr.erase(ip_addr.find_first_of(':'));
|
||||
std::string port_nb = result;
|
||||
port_nb.erase(0, port_nb.find_first_of(':')+1);
|
||||
uint32_t dst_ip = (uint32_t)(atoi(ip_addr.c_str()));
|
||||
uint16_t dst_port = (uint32_t)(atoi(port_nb.c_str()));
|
||||
if (dst_ip == 0 || dst_port == 0)
|
||||
{
|
||||
printf("__GetPeerAddress> The host you try to reach is not online. There will be a new try in 10 seconds.\n");
|
||||
target = current_time+10;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("__GetPeerAddress> Public ip of target is %i.%i.%i.%i:%i\n", (dst_ip>>24)&0xff, (dst_ip>>16)&0xff, (dst_ip>>8)&0xff, dst_ip&0xff, dst_port);
|
||||
uint32_t server_ip = ((dst_ip&0x000000ff)<<24) // change the server IP to have a network-byte order
|
||||
+ ((dst_ip&0x0000ff00)<<8)
|
||||
+ ((dst_ip&0x00ff0000)>>8)
|
||||
+ ((dst_ip&0xff000000)>>24);
|
||||
uint16_t server_port = dst_port;
|
||||
TransportAddress* addr = static_cast<TransportAddress*>(m_callback_object);
|
||||
addr->ip = server_ip;
|
||||
addr->port = server_port;
|
||||
m_state = DONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_state == DONE)
|
||||
{
|
||||
m_listener->requestTerminate(this);
|
||||
}
|
||||
}
|
||||
|
||||
void GetPeerAddress::setPeerName(std::string peer_name)
|
||||
{
|
||||
m_peer_name = peer_name;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//
|
||||
// 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 GET_PEER_ADDRESS_HPP
|
||||
#define GET_PEER_ADDRESS_HPP
|
||||
|
||||
#include "protocol.hpp"
|
||||
|
||||
class GetPeerAddress : public Protocol
|
||||
{
|
||||
public:
|
||||
GetPeerAddress(CallbackObject* callback_object);
|
||||
virtual ~GetPeerAddress();
|
||||
|
||||
virtual void notifyEvent(Event* event);
|
||||
virtual void setup();
|
||||
virtual void update();
|
||||
|
||||
void setPeerName(std::string peer_name);
|
||||
protected:
|
||||
std::string m_peer_name;
|
||||
|
||||
enum STATE
|
||||
{
|
||||
NONE,
|
||||
DONE
|
||||
};
|
||||
STATE m_state;
|
||||
|
||||
};
|
||||
|
||||
#endif // GET_PEER_ADDRESS_HPP
|
||||
@@ -1,207 +0,0 @@
|
||||
//
|
||||
// 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 "protocols/get_public_address.hpp"
|
||||
|
||||
#include "network_manager.hpp"
|
||||
#include "client_network_manager.hpp"
|
||||
#include "protocols/connect_to_server.hpp"
|
||||
#include "network_interface.hpp"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int stunRand()
|
||||
{
|
||||
static bool init = false;
|
||||
if (!init)
|
||||
{
|
||||
srand(time(NULL));
|
||||
init = true;
|
||||
}
|
||||
return rand();
|
||||
}
|
||||
|
||||
GetPublicAddress::GetPublicAddress(CallbackObject* callback_object) : Protocol(callback_object, PROTOCOL_SILENT)
|
||||
{
|
||||
}
|
||||
|
||||
GetPublicAddress::~GetPublicAddress()
|
||||
{
|
||||
}
|
||||
|
||||
void GetPublicAddress::notifyEvent(Event* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GetPublicAddress::setup()
|
||||
{
|
||||
m_state = NOTHING_DONE;
|
||||
}
|
||||
|
||||
void GetPublicAddress::update()
|
||||
{
|
||||
if (m_state == NOTHING_DONE)
|
||||
{
|
||||
// format : 00MMMMMCMMMCMMMM (cf rfc 5389)
|
||||
uint16_t message_type = 0b0000000000000001; // binding request
|
||||
m_stun_tansaction_id[0] = stunRand();
|
||||
m_stun_tansaction_id[1] = stunRand();
|
||||
m_stun_tansaction_id[2] = stunRand();
|
||||
uint16_t message_length = 0x0000;
|
||||
|
||||
uint8_t bytes[21]; // the message to be sent
|
||||
// bytes 0-1 : the type of the message,
|
||||
bytes[0] = (uint8_t)(message_type>>8);
|
||||
bytes[1] = (uint8_t)(message_type);
|
||||
|
||||
// bytes 2-3 : message length added to header (attributes)
|
||||
bytes[2] = (uint8_t)(message_length>>8);
|
||||
bytes[3] = (uint8_t)(message_length);
|
||||
|
||||
// bytes 4-7 : magic cookie to recognize the stun protocol
|
||||
bytes[4] = (uint8_t)(m_stun_magic_cookie>>24);
|
||||
bytes[5] = (uint8_t)(m_stun_magic_cookie>>16);
|
||||
bytes[6] = (uint8_t)(m_stun_magic_cookie>>8);
|
||||
bytes[7] = (uint8_t)(m_stun_magic_cookie);
|
||||
|
||||
// bytes 8-19 : the transaction id
|
||||
bytes[8] = (uint8_t)(m_stun_tansaction_id[0]>>24);
|
||||
bytes[9] = (uint8_t)(m_stun_tansaction_id[0]>>16);
|
||||
bytes[10] = (uint8_t)(m_stun_tansaction_id[0]>>8);
|
||||
bytes[11] = (uint8_t)(m_stun_tansaction_id[0]);
|
||||
bytes[12] = (uint8_t)(m_stun_tansaction_id[1]>>24);
|
||||
bytes[13] = (uint8_t)(m_stun_tansaction_id[1]>>16);
|
||||
bytes[14] = (uint8_t)(m_stun_tansaction_id[1]>>8);
|
||||
bytes[15] = (uint8_t)(m_stun_tansaction_id[1]);
|
||||
bytes[16] = (uint8_t)(m_stun_tansaction_id[2]>>24);
|
||||
bytes[17] = (uint8_t)(m_stun_tansaction_id[2]>>16);
|
||||
bytes[18] = (uint8_t)(m_stun_tansaction_id[2]>>8);
|
||||
bytes[19] = (uint8_t)(m_stun_tansaction_id[2]);
|
||||
bytes[20] = '\0';
|
||||
|
||||
printf("__GetPublicAddress> Querrying STUN server 132.177.123.6\n");
|
||||
unsigned int dst = (132<<24)+(177<<16)+(123<<8)+6;
|
||||
NetworkManager::getInstance()->setManualSocketsMode(true);
|
||||
NetworkManager::getInstance()->getHost()->sendRawPacket(bytes, 20, TransportAddress(dst, 3478));
|
||||
m_state = TEST_SENT;
|
||||
}
|
||||
if (m_state == TEST_SENT)
|
||||
{
|
||||
unsigned int dst = (132<<24)+(177<<16)+(123<<8)+6;
|
||||
uint8_t* data = NetworkManager::getInstance()->getHost()->receiveRawPacket(TransportAddress(dst, 3478));
|
||||
assert(data);
|
||||
|
||||
// check that the stun response is a response, contains the magic cookie and the transaction ID
|
||||
if ( data[0] == 0b01 &&
|
||||
data[1] == 0b01 &&
|
||||
data[4] == (uint8_t)(m_stun_magic_cookie>>24) &&
|
||||
data[5] == (uint8_t)(m_stun_magic_cookie>>16) &&
|
||||
data[6] == (uint8_t)(m_stun_magic_cookie>>8) &&
|
||||
data[7] == (uint8_t)(m_stun_magic_cookie))
|
||||
{
|
||||
if(
|
||||
data[8] == (uint8_t)(m_stun_tansaction_id[0]>>24) &&
|
||||
data[9] == (uint8_t)(m_stun_tansaction_id[0]>>16) &&
|
||||
data[10] == (uint8_t)(m_stun_tansaction_id[0]>>8 ) &&
|
||||
data[11] == (uint8_t)(m_stun_tansaction_id[0] ) &&
|
||||
data[12] == (uint8_t)(m_stun_tansaction_id[1]>>24) &&
|
||||
data[13] == (uint8_t)(m_stun_tansaction_id[1]>>16) &&
|
||||
data[14] == (uint8_t)(m_stun_tansaction_id[1]>>8 ) &&
|
||||
data[15] == (uint8_t)(m_stun_tansaction_id[1] ) &&
|
||||
data[16] == (uint8_t)(m_stun_tansaction_id[2]>>24) &&
|
||||
data[17] == (uint8_t)(m_stun_tansaction_id[2]>>16) &&
|
||||
data[18] == (uint8_t)(m_stun_tansaction_id[2]>>8 ) &&
|
||||
data[19] == (uint8_t)(m_stun_tansaction_id[2] ))
|
||||
{
|
||||
printf("__GetPublicAddress> The STUN server responded with a valid answer\n");
|
||||
int message_size = data[2]*256+data[3];
|
||||
|
||||
// parse the stun message now:
|
||||
bool finish = false;
|
||||
uint8_t* attributes = data+20;
|
||||
if (message_size == 0)
|
||||
{
|
||||
printf("__GetPublicAddress> STUN answer does not contain any information.\n");
|
||||
finish = true;
|
||||
}
|
||||
if (message_size < 4) // cannot even read the size
|
||||
{
|
||||
printf("__GetPublicAddress> STUN message is not valid.\n");
|
||||
finish = true;
|
||||
}
|
||||
uint16_t port;
|
||||
uint32_t address;
|
||||
bool valid = false;
|
||||
while(!finish)
|
||||
{
|
||||
int type = attributes[0]*256+attributes[1];
|
||||
int size = attributes[2]*256+attributes[3];
|
||||
switch(type)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
assert(size == 8);
|
||||
assert(attributes[5] = 0x01); // IPv4 only
|
||||
port = attributes[6]*256+attributes[7];
|
||||
address = (attributes[8]<<24 & 0xFF000000)+(attributes[9]<<16 & 0x00FF0000)+(attributes[10]<<8 & 0x0000FF00)+(attributes[11] & 0x000000FF);
|
||||
finish = true;
|
||||
valid = true;
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
attributes = attributes + 4 + size;
|
||||
message_size -= 4 + size;
|
||||
if (message_size == 0)
|
||||
finish = true;
|
||||
if (message_size < 4) // cannot even read the size
|
||||
{
|
||||
printf("__GetPublicAddress> STUN message is not valid.\n");
|
||||
finish = true;
|
||||
}
|
||||
}
|
||||
// finished parsing, we know our public transport address
|
||||
if (valid)
|
||||
{
|
||||
printf("__The public address has been found : %i.%i.%i.%i:%i\n", address>>24&0xff, address>>16&0xff, address>>8&0xff, address&0xff, port);
|
||||
m_state = ADDRESS_KNOWN;
|
||||
NetworkManager::getInstance()->setManualSocketsMode(false);
|
||||
TransportAddress* addr = static_cast<TransportAddress*>(m_callback_object);
|
||||
addr->ip = address;
|
||||
addr->port = port;
|
||||
}
|
||||
else
|
||||
m_state = NOTHING_DONE; // need to re-send the stun request
|
||||
}
|
||||
else
|
||||
{
|
||||
m_state = NOTHING_DONE; // need to re-send the stun request
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_state == ADDRESS_KNOWN)
|
||||
{
|
||||
// terminate the protocol
|
||||
m_listener->requestTerminate(this);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//
|
||||
// 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 GET_PUBLIC_ADDRESS_HPP
|
||||
#define GET_PUBLIC_ADDRESS_HPP
|
||||
|
||||
#include "../protocol.hpp"
|
||||
|
||||
class GetPublicAddress : public Protocol
|
||||
{
|
||||
public:
|
||||
GetPublicAddress(CallbackObject* callback_object);
|
||||
virtual ~GetPublicAddress();
|
||||
|
||||
virtual void notifyEvent(Event* event);
|
||||
|
||||
virtual void setup();
|
||||
virtual void update();
|
||||
|
||||
protected:
|
||||
enum STATE
|
||||
{
|
||||
NOTHING_DONE,
|
||||
TEST_SENT,
|
||||
ADDRESS_KNOWN
|
||||
};
|
||||
STATE m_state;
|
||||
uint32_t m_stun_tansaction_id[3];
|
||||
static const uint32_t m_stun_magic_cookie = 0x2112A442;
|
||||
};
|
||||
|
||||
#endif // GET_PUBLIC_ADDRESS_HPP
|
||||
@@ -1,74 +0,0 @@
|
||||
//
|
||||
// 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 "protocols/hide_public_address.hpp"
|
||||
|
||||
#include "http_functions.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
HidePublicAddress::HidePublicAddress(CallbackObject* callback_object) : Protocol(callback_object, PROTOCOL_SILENT)
|
||||
{
|
||||
}
|
||||
|
||||
HidePublicAddress::~HidePublicAddress()
|
||||
{
|
||||
}
|
||||
|
||||
void HidePublicAddress::notifyEvent(Event* event)
|
||||
{
|
||||
}
|
||||
|
||||
void HidePublicAddress::setup()
|
||||
{
|
||||
m_state = NONE;
|
||||
}
|
||||
|
||||
void HidePublicAddress::update()
|
||||
{
|
||||
if (m_state == NONE)
|
||||
{
|
||||
char url[512];
|
||||
sprintf(url, "http://stkconnect.freeserver.me/log.php?logout&nick=%s&pwd=%s", m_username.c_str(), m_password.c_str());
|
||||
std::string result = HTTP::getPage(url);
|
||||
if (result[0] == 's' && result[1] == 'u' && result[2] == 'c' && result[3] == 'c' && result[4] == 'e' && result[5] == 's' && result[6] == 's')
|
||||
{
|
||||
printf("__HidePublicAddress> Public address hidden successfully.\n");
|
||||
m_state = DONE;
|
||||
}
|
||||
if (result[0] == 'f' && result[1] == 'a' && result[2] == 'i' && result[3] == 'l')
|
||||
{
|
||||
printf("__HidePublicAddress> Public address still visible. Re-set nick:password and retry.\n");
|
||||
m_state = NONE;
|
||||
pause();
|
||||
}
|
||||
}
|
||||
else if (m_state == DONE)
|
||||
{
|
||||
m_listener->requestTerminate(this);
|
||||
}
|
||||
}
|
||||
|
||||
void HidePublicAddress::setUsername(std::string username)
|
||||
{
|
||||
m_username = username;
|
||||
}
|
||||
void HidePublicAddress::setPassword(std::string password)
|
||||
{
|
||||
m_password = password;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// 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 HIDE_PUBLIC_ADDRESS_HPP
|
||||
#define HIDE_PUBLIC_ADDRESS_HPP
|
||||
|
||||
#include "protocol.hpp"
|
||||
#include <string>
|
||||
|
||||
class HidePublicAddress : public Protocol
|
||||
{
|
||||
public:
|
||||
HidePublicAddress(CallbackObject* callback_object);
|
||||
virtual ~HidePublicAddress();
|
||||
|
||||
virtual void notifyEvent(Event* event);
|
||||
virtual void setup();
|
||||
virtual void update();
|
||||
|
||||
virtual void setUsername(std::string username);
|
||||
virtual void setPassword(std::string password);
|
||||
protected:
|
||||
std::string m_username;
|
||||
std::string m_password;
|
||||
|
||||
enum STATE
|
||||
{
|
||||
NONE,
|
||||
DONE
|
||||
};
|
||||
STATE m_state;
|
||||
};
|
||||
|
||||
#endif // HIDE_PUBLIC_ADDRESS_HPP
|
||||
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// 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 "lobby_room_protocol.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
LobbyRoomProtocol::LobbyRoomProtocol(CallbackObject* callback_object) : Protocol(callback_object, PROTOCOL_LOBBY_ROOM)
|
||||
{
|
||||
}
|
||||
|
||||
LobbyRoomProtocol::~LobbyRoomProtocol()
|
||||
{
|
||||
}
|
||||
|
||||
void LobbyRoomProtocol::notifyEvent(Event* event)
|
||||
{
|
||||
if (event->type == EVENT_TYPE_MESSAGE)
|
||||
{
|
||||
printf("Message from %u : \"%s\"\n", event->peer->getAddress(), event->data.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void LobbyRoomProtocol::setup()
|
||||
{
|
||||
}
|
||||
|
||||
void LobbyRoomProtocol::update()
|
||||
{
|
||||
}
|
||||
|
||||
void LobbyRoomProtocol::sendMessage(std::string message)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//
|
||||
// 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 LOBBY_ROOM_PROTOCOL_HPP
|
||||
#define LOBBY_ROOM_PROTOCOL_HPP
|
||||
|
||||
#include "protocol.hpp"
|
||||
|
||||
/*!
|
||||
* \class LobbyRoomProtocol
|
||||
* \brief Class used while the game is being prepared.
|
||||
* This protocol starts when a server opens a game, or when a client joins a game.
|
||||
* It is used to exchange data about the race settings, like kart selection.
|
||||
*/
|
||||
class LobbyRoomProtocol : public Protocol
|
||||
{
|
||||
public:
|
||||
LobbyRoomProtocol(CallbackObject* callback_object);
|
||||
virtual ~LobbyRoomProtocol();
|
||||
|
||||
virtual void notifyEvent(Event* event);
|
||||
|
||||
virtual void setup();
|
||||
|
||||
virtual void update();
|
||||
|
||||
void sendMessage(std::string message);
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif // LOBBY_ROOM_PROTOCOL_HPP
|
||||
@@ -1,84 +0,0 @@
|
||||
//
|
||||
// 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 "show_public_address.hpp"
|
||||
|
||||
#include "../http_functions.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
ShowPublicAddress::ShowPublicAddress(CallbackObject* callback_object) : Protocol(callback_object, PROTOCOL_SILENT)
|
||||
{
|
||||
}
|
||||
|
||||
ShowPublicAddress::~ShowPublicAddress()
|
||||
{
|
||||
}
|
||||
|
||||
void ShowPublicAddress::notifyEvent(Event* event)
|
||||
{
|
||||
}
|
||||
|
||||
void ShowPublicAddress::setup()
|
||||
{
|
||||
m_state = NONE;
|
||||
if (m_public_ip == 0 || m_public_port == 0 || m_username == "" || m_password == "")
|
||||
{
|
||||
printf("__ShowPublicAddress> You have to set the public ip:port, username:password and the host nickname before starting this protocol.\n");
|
||||
m_listener->requestTerminate(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowPublicAddress::update()
|
||||
{
|
||||
if (m_state == NONE)
|
||||
{
|
||||
char url[512];
|
||||
sprintf(url, "http://stkconnect.freeserver.me/log.php?set&nick=%s&ip=%u&port=%u&pwd=%s", m_username.c_str(), m_public_ip, m_public_port, m_password.c_str());
|
||||
std::string result = HTTP::getPage(url);
|
||||
if (result[0] == 's' && result[1] == 'u' && result[2] == 'c' && result[3] == 'c' && result[4] == 'e' && result[5] == 's' && result[6] == 's')
|
||||
{
|
||||
printf("__ShowPublicAddress> Address set.\n");
|
||||
m_state = DONE;
|
||||
}
|
||||
if (result[0] == 'f' && result[1] == 'a' && result[2] == 'i' && result[3] == 'l')
|
||||
{
|
||||
printf("__ShowPublicAddress> Login fail. Please re-set username:password and unpause the protocol.\n");
|
||||
m_state = NONE;
|
||||
pause();
|
||||
}
|
||||
}
|
||||
else if (m_state == DONE)
|
||||
{
|
||||
m_listener->requestTerminate(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowPublicAddress::setUsername(std::string username)
|
||||
{
|
||||
m_username = username;
|
||||
}
|
||||
void ShowPublicAddress::setPassword(std::string password)
|
||||
{
|
||||
m_password = password;
|
||||
}
|
||||
void ShowPublicAddress::setPublicAddress(uint32_t ip, uint16_t port)
|
||||
{
|
||||
m_public_ip = ip;
|
||||
m_public_port = port;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// 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 SHOW_PUBLIC_ADDRESS_HPP
|
||||
#define SHOW_PUBLIC_ADDRESS_HPP
|
||||
|
||||
#include "protocol.hpp"
|
||||
#include <string>
|
||||
|
||||
class ShowPublicAddress : public Protocol
|
||||
{
|
||||
public:
|
||||
ShowPublicAddress(CallbackObject* callback_object);
|
||||
virtual ~ShowPublicAddress();
|
||||
|
||||
virtual void notifyEvent(Event* event);
|
||||
virtual void setup();
|
||||
virtual void update();
|
||||
|
||||
virtual void setUsername(std::string username);
|
||||
virtual void setPassword(std::string password);
|
||||
virtual void setPublicAddress(uint32_t ip, uint16_t port);
|
||||
|
||||
protected:
|
||||
std::string m_username;
|
||||
std::string m_password;
|
||||
uint32_t m_public_ip;
|
||||
uint16_t m_public_port;
|
||||
|
||||
enum STATE
|
||||
{
|
||||
NONE,
|
||||
DONE
|
||||
};
|
||||
STATE m_state;
|
||||
};
|
||||
|
||||
#endif // HIDE_PUBLIC_ADDRESS_HPP
|
||||
@@ -1,123 +0,0 @@
|
||||
//
|
||||
// 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 "server_network_manager.hpp"
|
||||
|
||||
#include "protocols/get_public_address.hpp"
|
||||
#include "protocols/hide_public_address.hpp"
|
||||
#include "protocols/show_public_address.hpp"
|
||||
#include "protocols/get_peer_address.hpp"
|
||||
#include "protocols/connect_to_server.hpp"
|
||||
|
||||
#include <enet/enet.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
ServerNetworkManager::ServerNetworkManager()
|
||||
{
|
||||
m_localhost = NULL;
|
||||
}
|
||||
|
||||
ServerNetworkManager::~ServerNetworkManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ServerNetworkManager::run()
|
||||
{
|
||||
if (enet_initialize() != 0)
|
||||
{
|
||||
printf("Could not initialize enet.\n");
|
||||
return;
|
||||
}
|
||||
NetworkManager::run();
|
||||
}
|
||||
|
||||
void ServerNetworkManager::start()
|
||||
{
|
||||
m_localhost = new STKHost();
|
||||
m_localhost->setupServer(STKHost::HOST_ANY, 7321, 32, 2, 0, 0);
|
||||
m_localhost->startListening();
|
||||
printf("Server now setup, listening on port 7321.\n");
|
||||
|
||||
printf("_NetworkInterface>Starting the global protocol\n");
|
||||
// step 1 : retreive public address
|
||||
Protocol* protocol = new GetPublicAddress(&m_public_address);
|
||||
ProtocolManager::getInstance()->requestStart(protocol);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(protocol) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
printf("_NetworkInterface> The public address is known.\n");
|
||||
|
||||
// step 2 : show the public address for others (here, the server)
|
||||
ShowPublicAddress* spa = new ShowPublicAddress(NULL);
|
||||
spa->setPassword(m_player_login.password);
|
||||
spa->setUsername(m_player_login.username);
|
||||
spa->setPublicAddress(m_public_address.ip, m_public_address.port);
|
||||
ProtocolManager::getInstance()->requestStart(spa);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(spa) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
printf("_NetworkInterface> The public address is being shown online.\n");
|
||||
}
|
||||
|
||||
bool ServerNetworkManager::connectToPeer(std::string peer_username)
|
||||
{
|
||||
printf("_NetworkInterface>Starting the connection to host protocol\n");
|
||||
|
||||
// step 3 : get the peer's addres.
|
||||
TransportAddress addr;
|
||||
GetPeerAddress* gpa = new GetPeerAddress(&addr);
|
||||
gpa->setPeerName(peer_username);
|
||||
ProtocolManager::getInstance()->requestStart(gpa);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(gpa) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
printf("_NetworkInterface> The public address of the peer is known.\n");
|
||||
|
||||
// step 2 : connect to the peer
|
||||
ConnectToServer* cts = new ConnectToServer(NULL);
|
||||
cts->setServerAddress(addr.ip, addr.port);
|
||||
ProtocolManager::getInstance()->requestStart(cts);
|
||||
while (ProtocolManager::getInstance()->getProtocolState(cts) != PROTOCOL_STATE_TERMINATED )
|
||||
{
|
||||
}
|
||||
bool success = false;
|
||||
if (isConnectedTo(addr))
|
||||
{
|
||||
success = true;
|
||||
printf("_NetworkInterface> CONNECTION SUCCES : YOU ARE NOW CONNECTED TO A PEER.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("_NetworkInterface> We are NOT connected to the server.\n");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void ServerNetworkManager::packetReceived(char* data)
|
||||
{
|
||||
printf("ServerNetworkManager::packetReceived()\n");
|
||||
puts(data);
|
||||
sendPacket(data);
|
||||
}
|
||||
void ServerNetworkManager::sendPacket(char* data)
|
||||
{
|
||||
m_localhost->broadcastPacket(data);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//
|
||||
// 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 SERVER_NETWORK_MANAGER_HPP
|
||||
#define SERVER_NETWORK_MANAGER_HPP
|
||||
|
||||
#include "network_manager.hpp"
|
||||
|
||||
|
||||
class ServerNetworkManager : public NetworkManager
|
||||
{
|
||||
friend class Singleton<NetworkManager>;
|
||||
public:
|
||||
static ServerNetworkManager* getInstance()
|
||||
{
|
||||
return Singleton<NetworkManager>::getInstance<ServerNetworkManager>();
|
||||
}
|
||||
|
||||
virtual void run();
|
||||
|
||||
void start();
|
||||
bool connectToPeer(std::string peer_username);
|
||||
|
||||
virtual void packetReceived(char* data);
|
||||
virtual void sendPacket(char* data);
|
||||
protected:
|
||||
ServerNetworkManager();
|
||||
virtual ~ServerNetworkManager();
|
||||
|
||||
};
|
||||
|
||||
#endif // SERVER_NETWORK_MANAGER_HPP
|
||||
@@ -1,66 +0,0 @@
|
||||
//
|
||||
// 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 SINGLETON_HPP
|
||||
#define SINGLETON_HPP
|
||||
|
||||
#include <iostream>
|
||||
|
||||
template <typename T>
|
||||
class Singleton
|
||||
{
|
||||
protected:
|
||||
Singleton () { }
|
||||
virtual ~Singleton () { std::cout << "destroying singleton." << std::endl; delete m_singleton; }
|
||||
|
||||
public:
|
||||
template<typename S>
|
||||
static S *getInstance ()
|
||||
{
|
||||
if (m_singleton == NULL)
|
||||
m_singleton = new S;
|
||||
|
||||
S* result = (dynamic_cast<S*> (m_singleton));
|
||||
if (result == NULL)
|
||||
{
|
||||
std::cout << "BE CAREFUL : Reallocating singleton" << std::endl;
|
||||
m_singleton = new S;
|
||||
}
|
||||
return (dynamic_cast<S*> (m_singleton));
|
||||
}
|
||||
static T *getInstance()
|
||||
{
|
||||
return (dynamic_cast<T*> (m_singleton));
|
||||
}
|
||||
|
||||
static void kill ()
|
||||
{
|
||||
if (NULL != m_singleton)
|
||||
{
|
||||
delete m_singleton;
|
||||
m_singleton = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static T *m_singleton;
|
||||
};
|
||||
|
||||
template <typename T> T *Singleton<T>::m_singleton = NULL;
|
||||
|
||||
#endif // SINGLETON_HPP
|
||||
@@ -1,218 +0,0 @@
|
||||
//
|
||||
// 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 "stk_host.hpp"
|
||||
|
||||
#include "network_manager.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void* STKHost::receive_data(void* self)
|
||||
{
|
||||
ENetEvent event;
|
||||
ENetHost* host = (((STKHost*)(self))->m_host);
|
||||
while (1)
|
||||
{
|
||||
while (enet_host_service(host, &event, 0) != 0) {
|
||||
Event* evt = new Event(&event);
|
||||
NetworkManager::getInstance()->notifyEvent(evt);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
STKHost::STKHost()
|
||||
{
|
||||
m_host = NULL;
|
||||
m_listening_thread = (pthread_t*)(malloc(sizeof(pthread_t)));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
STKHost::~STKHost()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void STKHost::setupServer(uint32_t address, uint16_t port, int peer_count,
|
||||
int channel_limit, uint32_t max_incoming_bandwidth,
|
||||
uint32_t max_outgoing_bandwidth)
|
||||
{
|
||||
ENetAddress* addr = (ENetAddress*)(malloc(sizeof(ENetAddress)));
|
||||
addr->host = address;
|
||||
addr->port = port;
|
||||
|
||||
m_host = enet_host_create(addr, peer_count, channel_limit,
|
||||
max_incoming_bandwidth, max_outgoing_bandwidth);
|
||||
if (m_host == NULL)
|
||||
{
|
||||
fprintf (stderr, "An error occurred while trying to create an ENet \
|
||||
server host.\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void STKHost::setupClient(int peer_count, int channel_limit,
|
||||
uint32_t max_incoming_bandwidth,
|
||||
uint32_t max_outgoing_bandwidth)
|
||||
{
|
||||
m_host = enet_host_create(NULL, peer_count, channel_limit,
|
||||
max_incoming_bandwidth, max_outgoing_bandwidth);
|
||||
if (m_host == NULL)
|
||||
{
|
||||
fprintf (stderr, "An error occurred while trying to create an ENet \
|
||||
client host.\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void STKHost::startListening()
|
||||
{
|
||||
pthread_create(m_listening_thread, NULL, &STKHost::receive_data, this);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void STKHost::stopListening()
|
||||
{
|
||||
pthread_cancel(*m_listening_thread);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void STKHost::sendRawPacket(uint8_t* data, int length, TransportAddress dst)
|
||||
{
|
||||
struct sockaddr_in to;
|
||||
int to_len = sizeof(to);
|
||||
memset(&to,0,to_len);
|
||||
|
||||
to.sin_family = AF_INET;
|
||||
to.sin_port = htons(dst.port);
|
||||
to.sin_addr.s_addr = htonl(dst.ip);
|
||||
|
||||
sendto(m_host->socket, data, length, 0,(sockaddr*)&to, to_len);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
uint8_t* STKHost::receiveRawPacket()
|
||||
{
|
||||
uint8_t* buffer; // max size needed normally (only used for stun)
|
||||
buffer = (uint8_t*)(malloc(sizeof(uint8_t)*2048));
|
||||
memset(buffer, 0, 2048);
|
||||
|
||||
int len = recv(m_host->socket,buffer,2048, 0);
|
||||
int i = 0;
|
||||
// wait to receive the message because enet sockets are non-blocking
|
||||
while(len < 0)
|
||||
{
|
||||
i++;
|
||||
len = recv(m_host->socket,buffer,2048, 0);
|
||||
usleep(1000); // wait 1 millisecond between two checks
|
||||
}
|
||||
printf("Packet received after %i milliseconds\n", i);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
uint8_t* STKHost::receiveRawPacket(TransportAddress sender)
|
||||
{
|
||||
uint8_t* buffer; // max size needed normally (only used for stun)
|
||||
buffer = (uint8_t*)(malloc(sizeof(uint8_t)*2048));
|
||||
memset(buffer, 0, 2048);
|
||||
|
||||
socklen_t from_len;
|
||||
struct sockaddr addr;
|
||||
|
||||
from_len = sizeof(addr);
|
||||
int len = recvfrom(m_host->socket, buffer, 2048, 0, &addr, &from_len);
|
||||
|
||||
int i = 0;
|
||||
// wait to receive the message because enet sockets are non-blocking
|
||||
while(len < 0 || (
|
||||
(uint8_t)(addr.sa_data[2]) != (sender.ip>>24&0xff)
|
||||
&& (uint8_t)(addr.sa_data[3]) != (sender.ip>>16&0xff)
|
||||
&& (uint8_t)(addr.sa_data[4]) != (sender.ip>>8&0xff)
|
||||
&& (uint8_t)(addr.sa_data[5]) != (sender.ip&0xff)))
|
||||
{
|
||||
i++;
|
||||
len = recvfrom(m_host->socket, buffer, 2048, 0, &addr, &from_len);
|
||||
usleep(1000); // wait 1 millisecond between two checks
|
||||
}
|
||||
if (addr.sa_family == AF_INET)
|
||||
{
|
||||
char s[20];
|
||||
inet_ntop(AF_INET, &(((struct sockaddr_in *)&addr)->sin_addr), s, 20);
|
||||
printf("IPv4 Address %s\n", s);
|
||||
}
|
||||
printf("Packet received after %i milliseconds\n", i);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void STKHost::broadcastPacket(char* data)
|
||||
{
|
||||
ENetPacket* packet = enet_packet_create(data, strlen(data)+1,
|
||||
ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_host_broadcast(m_host, 0, packet);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool STKHost::peerExists(TransportAddress peer)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_host->peerCount; i++)
|
||||
{
|
||||
if (m_host->peers[i].address.host == peer.ip &&
|
||||
m_host->peers[i].address.port == peer.port)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool STKHost::isConnectedTo(TransportAddress peer)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_host->peerCount; i++)
|
||||
{
|
||||
if (m_host->peers[i].address.host == peer.ip &&
|
||||
m_host->peers[i].address.port == peer.port &&
|
||||
m_host->peers[i].state == ENET_PEER_STATE_CONNECTED)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
//
|
||||
// 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.
|
||||
|
||||
/*! \file stk_host.hpp
|
||||
* \brief Defines an interface to use network low-level functions easily.
|
||||
*/
|
||||
#ifndef STK_HOST_HPP
|
||||
#define STK_HOST_HPP
|
||||
|
||||
#include <enet/enet.h>
|
||||
#include "types.hpp"
|
||||
|
||||
/*! \class STKHost
|
||||
* \brief Represents the local host.
|
||||
* This host is either a server host or a client host. A client host is in
|
||||
* charge of connecting to a server. A server opens a socket for incoming
|
||||
* connections.
|
||||
* By default, this host will use ENet to exchange packets. It also defines an
|
||||
* interface for ENet use. Nevertheless, this class can be used to send and/or
|
||||
* receive packets whithout ENet adding its headers.
|
||||
* This class is used by the Network Manager to send packets.
|
||||
*/
|
||||
class STKHost
|
||||
{
|
||||
friend class STKPeer; // allow direct enet modifications in implementations
|
||||
public:
|
||||
/*! \enum HOST_TYPE
|
||||
* \brief Defines three host types for the server.
|
||||
* These values tells the host where he will accept connections from.
|
||||
*/
|
||||
enum HOST_TYPE
|
||||
{
|
||||
HOST_ANY = 0, //!< Any host.
|
||||
HOST_BROADCAST = 0xFFFFFFFF, //!< Defines the broadcast address.
|
||||
PORT_ANY = 0 //!< Any port.
|
||||
};
|
||||
|
||||
/*! \brief Constructor */
|
||||
STKHost();
|
||||
/*! \brief Destructor */
|
||||
virtual ~STKHost();
|
||||
|
||||
/*! \brief Thread function checking if data is received.
|
||||
* This function tries to get data from network low-level functions as
|
||||
* often as possible. When something is received, it generates an
|
||||
* event and passes it to the Network Manager.
|
||||
* \param self : used to pass the ENet host to the function.
|
||||
*/
|
||||
static void* receive_data(void* self);
|
||||
|
||||
/*! \brief Setups the host as a server.
|
||||
* \param address : The IPv4 address of incoming connections.
|
||||
* \param port : The port on which the server listens.
|
||||
* \param peer_count : The maximum number of peers.
|
||||
* \param channel_limit : The maximum number of channels per peer.
|
||||
* \param max_incoming_bandwidth : The maximum incoming bandwidth.
|
||||
* \param max_outgoing_bandwidth : The maximum outgoing bandwidth.
|
||||
*/
|
||||
void setupServer(uint32_t address, uint16_t port,
|
||||
int peer_count, int channel_limit,
|
||||
uint32_t max_incoming_bandwidth,
|
||||
uint32_t max_outgoing_bandwidth);
|
||||
/*! \brief Setups the host as a client.
|
||||
* In fact there is only one peer connected to this host.
|
||||
* \param peer_count : The maximum number of peers.
|
||||
* \param channel_limit : The maximum number of channels per peer.
|
||||
* \param max_incoming_bandwidth : The maximum incoming bandwidth.
|
||||
* \param max_outgoing_bandwidth : The maximum outgoing bandwidth.
|
||||
*/
|
||||
void setupClient(int peer_count, int channel_limit,
|
||||
uint32_t max_incoming_bandwidth,
|
||||
uint32_t max_outgoing_bandwidth);
|
||||
|
||||
/*! \brief Starts the listening of events from ENet.
|
||||
* Starts a thread that updates it as often as possible.
|
||||
*/
|
||||
void startListening();
|
||||
/*! \brief Stops the listening of events from ENet.
|
||||
* Stops the thread that was receiving events.
|
||||
*/
|
||||
void stopListening();
|
||||
|
||||
/*! \brief Sends a packet whithout ENet adding its headers.
|
||||
* This function is used in particular to achieve the STUN protocol.
|
||||
* \param data : Data to send.
|
||||
* \param length : Length of the sent data.
|
||||
* \param dst : Destination of the packet.
|
||||
*/
|
||||
void sendRawPacket(uint8_t* data, int length,
|
||||
TransportAddress dst);
|
||||
/*! \brief Receives a packet directly from the network interface.
|
||||
* Receive a packet whithout ENet processing it.
|
||||
* \return A string containing the data of the received packet.
|
||||
*/
|
||||
uint8_t* receiveRawPacket();
|
||||
/*! \brief Receives a packet directly from the network interface and
|
||||
* filter its address.
|
||||
* Receive a packet whithout ENet processing it. Checks that the
|
||||
* sender of the packet is the one that corresponds to the sender
|
||||
* parameter. Does not check the port right now.
|
||||
* \param sender : Transport address of the original sender of the
|
||||
* wanted packet.
|
||||
* \return A string containing the data of the received packet
|
||||
* matching the sender's ip address.
|
||||
*/
|
||||
uint8_t* receiveRawPacket(TransportAddress sender);
|
||||
/*! \brief Broadcasts a packet to all peers.
|
||||
* \param data : Data to send.
|
||||
*/
|
||||
void broadcastPacket(char* data);
|
||||
|
||||
/*! \brief Tells if a peer is known.
|
||||
* \return True if the peer is known, false elseway.
|
||||
*/
|
||||
bool peerExists(TransportAddress peer_address);
|
||||
/*! \brief Tells if a peer is known and connected.
|
||||
* \return True if the peer is known and connected, false elseway.
|
||||
*/
|
||||
bool isConnectedTo(TransportAddress peer_address);
|
||||
protected:
|
||||
ENetHost* m_host; //!< ENet host interfacing sockets.
|
||||
pthread_t* m_listening_thread; //!< Thread listening network events.
|
||||
|
||||
};
|
||||
|
||||
#endif // STK_HOST_HPP
|
||||
@@ -1,77 +0,0 @@
|
||||
//
|
||||
// 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 "stk_peer.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
STKPeer::STKPeer()
|
||||
{
|
||||
m_peer = NULL;
|
||||
}
|
||||
|
||||
STKPeer::~STKPeer()
|
||||
{
|
||||
if (m_peer)
|
||||
delete m_peer;
|
||||
}
|
||||
|
||||
bool STKPeer::connectToHost(STKHost* localhost, TransportAddress host, uint32_t channel_count, uint32_t data)
|
||||
{
|
||||
ENetAddress address;
|
||||
address.host = host.ip;
|
||||
address.port = host.port;
|
||||
|
||||
ENetPeer* peer = enet_host_connect(localhost->m_host, &address, 2, 0);
|
||||
if (peer == NULL)
|
||||
{
|
||||
printf("Could not try to connect to server.\n");
|
||||
return false;
|
||||
}
|
||||
printf("Connecting to %i.%i.%i.%i:%i.\n", (peer->address.host>>0)&0xff,(peer->address.host>>8)&0xff,(peer->address.host>>16)&0xff,(peer->address.host>>24)&0xff,peer->address.port);
|
||||
return true;
|
||||
}
|
||||
|
||||
void STKPeer::sendPacket(char* data)
|
||||
{
|
||||
//printf("sending packet to %i.%i.%i.%i:%i", (m_peer->address.host>>24)&0xff,(m_peer->address.host>>16)&0xff,(m_peer->address.host>>8)&0xff,(m_peer->address.host>>0)&0xff,m_peer->address.port);
|
||||
|
||||
ENetPacket* packet = enet_packet_create(data, strlen(data)+1,ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(m_peer, 0, packet);
|
||||
}
|
||||
|
||||
uint32_t STKPeer::getAddress()
|
||||
{
|
||||
return m_peer->address.host;
|
||||
}
|
||||
|
||||
uint16_t STKPeer::getPort()
|
||||
{
|
||||
return m_peer->address.port;
|
||||
}
|
||||
|
||||
bool STKPeer::isConnected()
|
||||
{
|
||||
printf("PEER STATE %i\n", m_peer->state);
|
||||
return (m_peer->state == ENET_PEER_STATE_CONNECTED);
|
||||
}
|
||||
bool STKPeer::operator==(ENetPeer* peer)
|
||||
{
|
||||
return peer==m_peer;
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
//
|
||||
// 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 STK_PEER_HPP
|
||||
#define STK_PEER_HPP
|
||||
|
||||
#include "stk_host.hpp"
|
||||
#include <enet/enet.h>
|
||||
|
||||
class STKPeer
|
||||
{
|
||||
friend class Event;
|
||||
public:
|
||||
STKPeer();
|
||||
virtual ~STKPeer();
|
||||
|
||||
|
||||
static void* receive_data(void* self);
|
||||
|
||||
virtual void sendPacket(char* data);
|
||||
|
||||
static bool connectToHost(STKHost* localhost, TransportAddress host, uint32_t channel_count, uint32_t data);
|
||||
|
||||
bool isConnected();
|
||||
|
||||
uint32_t getAddress();
|
||||
uint16_t getPort();
|
||||
bool operator==(ENetPeer* peer);
|
||||
protected:
|
||||
ENetPeer* m_peer;
|
||||
};
|
||||
|
||||
#endif // STK_PEER_HPP
|
||||
@@ -1,32 +0,0 @@
|
||||
//
|
||||
// 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 "time.hpp"
|
||||
|
||||
namespace Time
|
||||
{
|
||||
double getSeconds()
|
||||
{
|
||||
time_t timer;
|
||||
time(&timer);
|
||||
struct tm y2k;
|
||||
y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0;
|
||||
y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
|
||||
return difftime(timer,mktime(&y2k)); // get the seconds elapsed since january 2000
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
//
|
||||
// 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 TIME_HPP
|
||||
#define TIME_HPP
|
||||
|
||||
#include <time.h>
|
||||
|
||||
namespace Time
|
||||
{
|
||||
double getSeconds();
|
||||
}
|
||||
|
||||
#endif // TIME_HPP_INCLUDED
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// 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.
|
||||
|
||||
/*! \file types.hpp
|
||||
* \brief Declares the general types that are used by the network.
|
||||
*/
|
||||
#ifndef TYPES_HPP
|
||||
#define TYPES_HPP
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
/*! \class CallbackObject
|
||||
* \brief Class that must be inherited to pass objects to protocols.
|
||||
*/
|
||||
class CallbackObject
|
||||
{
|
||||
public:
|
||||
CallbackObject() {}
|
||||
|
||||
};
|
||||
|
||||
/*! \class TransportAddress
|
||||
* \brief Describes a transport-layer address.
|
||||
* For IP networks, a transport address is the couple ip:port.
|
||||
*/
|
||||
class TransportAddress : public CallbackObject
|
||||
{
|
||||
public:
|
||||
TransportAddress(uint32_t p_ip = 0, uint16_t p_port = 0)
|
||||
{ ip = p_ip; port = p_port; }
|
||||
|
||||
uint32_t ip; //!< The IPv4 address
|
||||
uint16_t port; //!< The port number
|
||||
};
|
||||
|
||||
/*! \class PlayerLogin
|
||||
* \brief Contains the information needed to authenticate a user.
|
||||
*/
|
||||
class PlayerLogin : public CallbackObject
|
||||
{
|
||||
public:
|
||||
PlayerLogin() {}
|
||||
|
||||
std::string username; //!< Username of the player
|
||||
std::string password; //!< Password of the player
|
||||
};
|
||||
|
||||
|
||||
#endif // TYPES_HPP
|
||||
BIN
doc/protocols.xls
Normal file
BIN
doc/protocols.xls
Normal file
Binary file not shown.
549
sources.cmake
549
sources.cmake
@@ -1,549 +0,0 @@
|
||||
# Generated by ./update_file_list.sh. Do not edit this file manually.
|
||||
set(STK_SOURCES
|
||||
src/addons/addon.cpp
|
||||
src/addons/addons_manager.cpp
|
||||
src/addons/inetwork_http.cpp
|
||||
src/addons/network_http.cpp
|
||||
src/addons/news_manager.cpp
|
||||
src/addons/request.cpp
|
||||
src/addons/zip.cpp
|
||||
src/animations/animation_base.cpp
|
||||
src/animations/ipo.cpp
|
||||
src/animations/three_d_animation.cpp
|
||||
src/audio/music_information.cpp
|
||||
src/audio/music_manager.cpp
|
||||
src/audio/music_ogg.cpp
|
||||
src/audio/sfx_buffer.cpp
|
||||
src/audio/sfx_manager.cpp
|
||||
src/audio/sfx_openal.cpp
|
||||
src/challenges/challenge.cpp
|
||||
src/challenges/challenge_data.cpp
|
||||
src/challenges/game_slot.cpp
|
||||
src/challenges/unlock_manager.cpp
|
||||
src/config/device_config.cpp
|
||||
src/config/player.cpp
|
||||
src/config/saved_grand_prix.cpp
|
||||
src/config/stk_config.cpp
|
||||
src/config/user_config.cpp
|
||||
src/graphics/camera.cpp
|
||||
src/graphics/CBatchingMesh.cpp
|
||||
src/graphics/explosion.cpp
|
||||
src/graphics/hardware_skinning.cpp
|
||||
src/graphics/hit_sfx.cpp
|
||||
src/graphics/irr_driver.cpp
|
||||
src/graphics/lod_node.cpp
|
||||
src/graphics/material.cpp
|
||||
src/graphics/material_manager.cpp
|
||||
src/graphics/mesh_tools.cpp
|
||||
src/graphics/moving_texture.cpp
|
||||
src/graphics/particle_emitter.cpp
|
||||
src/graphics/particle_kind.cpp
|
||||
src/graphics/particle_kind_manager.cpp
|
||||
src/graphics/per_camera_node.cpp
|
||||
src/graphics/post_processing.cpp
|
||||
src/graphics/rain.cpp
|
||||
src/graphics/referee.cpp
|
||||
src/graphics/shadow.cpp
|
||||
src/graphics/show_curve.cpp
|
||||
src/graphics/skid_marks.cpp
|
||||
src/graphics/slip_stream.cpp
|
||||
src/graphics/stars.cpp
|
||||
src/guiengine/abstract_state_manager.cpp
|
||||
src/guiengine/abstract_top_level_container.cpp
|
||||
src/guiengine/CGUISpriteBank.cpp
|
||||
src/guiengine/engine.cpp
|
||||
src/guiengine/event_handler.cpp
|
||||
src/guiengine/layout_manager.cpp
|
||||
src/guiengine/modaldialog.cpp
|
||||
src/guiengine/scalable_font.cpp
|
||||
src/guiengine/screen.cpp
|
||||
src/guiengine/screen_loader.cpp
|
||||
src/guiengine/skin.cpp
|
||||
src/guiengine/widget.cpp
|
||||
src/guiengine/widgets/bubble_widget.cpp
|
||||
src/guiengine/widgets/button_widget.cpp
|
||||
src/guiengine/widgets/CGUIEditBox.cpp
|
||||
src/guiengine/widgets/check_box_widget.cpp
|
||||
src/guiengine/widgets/dynamic_ribbon_widget.cpp
|
||||
src/guiengine/widgets/icon_button_widget.cpp
|
||||
src/guiengine/widgets/label_widget.cpp
|
||||
src/guiengine/widgets/list_widget.cpp
|
||||
src/guiengine/widgets/model_view_widget.cpp
|
||||
src/guiengine/widgets/progress_bar_widget.cpp
|
||||
src/guiengine/widgets/rating_bar_widget.cpp
|
||||
src/guiengine/widgets/ribbon_widget.cpp
|
||||
src/guiengine/widgets/spinner_widget.cpp
|
||||
src/guiengine/widgets/text_box_widget.cpp
|
||||
src/input/binding.cpp
|
||||
src/input/device_manager.cpp
|
||||
src/input/input_device.cpp
|
||||
src/input/input_manager.cpp
|
||||
src/input/wiimote.cpp
|
||||
src/input/wiimote_manager.cpp
|
||||
src/io/file_manager.cpp
|
||||
src/io/xml_node.cpp
|
||||
src/io/xml_writer.cpp
|
||||
src/items/attachment.cpp
|
||||
src/items/attachment_manager.cpp
|
||||
src/items/bowling.cpp
|
||||
src/items/cake.cpp
|
||||
src/items/flyable.cpp
|
||||
src/items/item.cpp
|
||||
src/items/item_manager.cpp
|
||||
src/items/plunger.cpp
|
||||
src/items/powerup.cpp
|
||||
src/items/powerup_manager.cpp
|
||||
src/items/projectile_manager.cpp
|
||||
src/items/rubber_ball.cpp
|
||||
src/items/rubber_band.cpp
|
||||
src/items/swatter.cpp
|
||||
src/karts/abstract_kart_animation.cpp
|
||||
src/karts/abstract_kart.cpp
|
||||
src/karts/cannon_animation.cpp
|
||||
src/karts/controller/ai_base_controller.cpp
|
||||
src/karts/controller/ai_properties.cpp
|
||||
src/karts/controller/controller.cpp
|
||||
src/karts/controller/end_controller.cpp
|
||||
src/karts/controller/player_controller.cpp
|
||||
src/karts/controller/skidding_ai.cpp
|
||||
src/karts/explosion_animation.cpp
|
||||
src/karts/ghost_kart.cpp
|
||||
src/karts/kart.cpp
|
||||
src/karts/kart_gfx.cpp
|
||||
src/karts/kart_model.cpp
|
||||
src/karts/kart_properties.cpp
|
||||
src/karts/kart_properties_manager.cpp
|
||||
src/karts/kart_with_stats.cpp
|
||||
src/karts/max_speed.cpp
|
||||
src/karts/moveable.cpp
|
||||
src/karts/rescue_animation.cpp
|
||||
src/karts/skidding.cpp
|
||||
src/karts/skidding_properties.cpp
|
||||
src/main.cpp
|
||||
src/main_loop.cpp
|
||||
src/modes/cutscene_world.cpp
|
||||
src/modes/demo_world.cpp
|
||||
src/modes/easter_egg_hunt.cpp
|
||||
src/modes/follow_the_leader.cpp
|
||||
src/modes/linear_world.cpp
|
||||
src/modes/overworld.cpp
|
||||
src/modes/profile_world.cpp
|
||||
src/modes/soccer_world.cpp
|
||||
src/modes/standard_race.cpp
|
||||
src/modes/three_strikes_battle.cpp
|
||||
src/modes/tutorial_world.cpp
|
||||
src/modes/world.cpp
|
||||
src/modes/world_status.cpp
|
||||
src/modes/world_with_rank.cpp
|
||||
src/network/client_network_manager.cpp
|
||||
src/network/event.cpp
|
||||
src/network/game_setup.cpp
|
||||
src/network/http_functions.cpp
|
||||
src/network/network_interface.cpp
|
||||
src/network/network_manager.cpp
|
||||
src/network/network_string.cpp
|
||||
src/network/protocol.cpp
|
||||
src/network/protocol_manager.cpp
|
||||
src/network/protocols/connect_to_peer.cpp
|
||||
src/network/protocols/connect_to_server.cpp
|
||||
src/network/protocols/get_peer_address.cpp
|
||||
src/network/protocols/get_public_address.cpp
|
||||
src/network/protocols/hide_public_address.cpp
|
||||
src/network/protocols/lobby_room_protocol.cpp
|
||||
src/network/protocols/ping_protocol.cpp
|
||||
src/network/protocols/request_connection.cpp
|
||||
src/network/protocols/show_public_address.cpp
|
||||
src/network/protocols/start_server.cpp
|
||||
src/network/protocols/stop_server.cpp
|
||||
src/network/server_network_manager.cpp
|
||||
src/network/stk_host.cpp
|
||||
src/network/stk_peer.cpp
|
||||
src/network/types.cpp
|
||||
src/online/current_online_user.cpp
|
||||
src/online/http_connector.cpp
|
||||
src/online/online_user.cpp
|
||||
src/physics/btKart.cpp
|
||||
src/physics/btKartRaycast.cpp
|
||||
src/physics/btUprightConstraint.cpp
|
||||
src/physics/irr_debug_drawer.cpp
|
||||
src/physics/physical_object.cpp
|
||||
src/physics/physics.cpp
|
||||
src/physics/triangle_mesh.cpp
|
||||
src/race/grand_prix_data.cpp
|
||||
src/race/grand_prix_manager.cpp
|
||||
src/race/highscore_manager.cpp
|
||||
src/race/highscores.cpp
|
||||
src/race/history.cpp
|
||||
src/race/race_manager.cpp
|
||||
src/replay/replay_base.cpp
|
||||
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/credits.cpp
|
||||
src/states_screens/cutscene_gui.cpp
|
||||
src/states_screens/dialogs/add_device_dialog.cpp
|
||||
src/states_screens/dialogs/addons_loading.cpp
|
||||
src/states_screens/dialogs/confirm_resolution_dialog.cpp
|
||||
src/states_screens/dialogs/custom_video_settings.cpp
|
||||
src/states_screens/dialogs/enter_player_name_dialog.cpp
|
||||
src/states_screens/dialogs/gp_info_dialog.cpp
|
||||
src/states_screens/dialogs/login_dialog.cpp
|
||||
src/states_screens/dialogs/message_dialog.cpp
|
||||
src/states_screens/dialogs/player_info_dialog.cpp
|
||||
src/states_screens/dialogs/press_a_key_dialog.cpp
|
||||
src/states_screens/dialogs/race_paused_dialog.cpp
|
||||
src/states_screens/dialogs/registration_dialog.cpp
|
||||
src/states_screens/dialogs/select_challenge.cpp
|
||||
src/states_screens/dialogs/track_info_dialog.cpp
|
||||
src/states_screens/dialogs/tutorial_message_dialog.cpp
|
||||
src/states_screens/feature_unlocked.cpp
|
||||
src/states_screens/grand_prix_lose.cpp
|
||||
src/states_screens/grand_prix_win.cpp
|
||||
src/states_screens/help_screen_1.cpp
|
||||
src/states_screens/help_screen_2.cpp
|
||||
src/states_screens/help_screen_3.cpp
|
||||
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
|
||||
src/states_screens/options_screen_input.cpp
|
||||
src/states_screens/options_screen_players.cpp
|
||||
src/states_screens/options_screen_ui.cpp
|
||||
src/states_screens/options_screen_video.cpp
|
||||
src/states_screens/race_gui_base.cpp
|
||||
src/states_screens/race_gui.cpp
|
||||
src/states_screens/race_gui_overworld.cpp
|
||||
src/states_screens/race_result_gui.cpp
|
||||
src/states_screens/race_setup_screen.cpp
|
||||
src/states_screens/soccer_setup_screen.cpp
|
||||
src/states_screens/state_manager.cpp
|
||||
src/states_screens/story_mode_lobby.cpp
|
||||
src/states_screens/tracks_screen.cpp
|
||||
src/tinygettext/dictionary.cpp
|
||||
src/tinygettext/dictionary_manager.cpp
|
||||
src/tinygettext/iconv.cpp
|
||||
src/tinygettext/language.cpp
|
||||
src/tinygettext/plural_forms.cpp
|
||||
src/tinygettext/po_parser.cpp
|
||||
src/tinygettext/stk_file_system.cpp
|
||||
src/tinygettext/tgt_log.cpp
|
||||
src/tinygettext/tinygettext.cpp
|
||||
src/tracks/ambient_light_sphere.cpp
|
||||
src/tracks/bezier_curve.cpp
|
||||
src/tracks/check_cannon.cpp
|
||||
src/tracks/check_goal.cpp
|
||||
src/tracks/check_lap.cpp
|
||||
src/tracks/check_line.cpp
|
||||
src/tracks/check_manager.cpp
|
||||
src/tracks/check_sphere.cpp
|
||||
src/tracks/check_structure.cpp
|
||||
src/tracks/graph_node.cpp
|
||||
src/tracks/lod_node_loader.cpp
|
||||
src/tracks/quad.cpp
|
||||
src/tracks/quad_graph.cpp
|
||||
src/tracks/quad_set.cpp
|
||||
src/tracks/terrain_info.cpp
|
||||
src/tracks/track.cpp
|
||||
src/tracks/track_manager.cpp
|
||||
src/tracks/track_object.cpp
|
||||
src/tracks/track_object_manager.cpp
|
||||
src/tracks/track_object_presentation.cpp
|
||||
src/tracks/track_sector.cpp
|
||||
src/utils/constants.cpp
|
||||
src/utils/leak_check.cpp
|
||||
src/utils/log.cpp
|
||||
src/utils/profiler.cpp
|
||||
src/utils/random_generator.cpp
|
||||
src/utils/string_utils.cpp
|
||||
src/utils/translation.cpp
|
||||
src/utils/vec3.cpp
|
||||
)
|
||||
set(STK_HEADERS
|
||||
src/addons/addon.hpp
|
||||
src/addons/addons_manager.hpp
|
||||
src/addons/dummy_network_http.hpp
|
||||
src/addons/inetwork_http.hpp
|
||||
src/addons/network_http.hpp
|
||||
src/addons/news_manager.hpp
|
||||
src/addons/request.hpp
|
||||
src/addons/zip.hpp
|
||||
src/animations/animation_base.hpp
|
||||
src/animations/ipo.hpp
|
||||
src/animations/three_d_animation.hpp
|
||||
src/audio/dummy_sfx.hpp
|
||||
src/audio/music_dummy.hpp
|
||||
src/audio/music.hpp
|
||||
src/audio/music_information.hpp
|
||||
src/audio/music_manager.hpp
|
||||
src/audio/music_ogg.hpp
|
||||
src/audio/sfx_base.hpp
|
||||
src/audio/sfx_buffer.hpp
|
||||
src/audio/sfx_manager.hpp
|
||||
src/audio/sfx_openal.hpp
|
||||
src/challenges/challenge_data.hpp
|
||||
src/challenges/challenge.hpp
|
||||
src/challenges/game_slot.hpp
|
||||
src/challenges/unlock_manager.hpp
|
||||
src/config/device_config.hpp
|
||||
src/config/player.hpp
|
||||
src/config/saved_grand_prix.hpp
|
||||
src/config/stk_config.hpp
|
||||
src/config/user_config.hpp
|
||||
src/graphics/camera.hpp
|
||||
src/graphics/CBatchingMesh.hpp
|
||||
src/graphics/explosion.hpp
|
||||
src/graphics/hardware_skinning.hpp
|
||||
src/graphics/hit_effect.hpp
|
||||
src/graphics/hit_sfx.hpp
|
||||
src/graphics/irr_driver.hpp
|
||||
src/graphics/lod_node.hpp
|
||||
src/graphics/material.hpp
|
||||
src/graphics/material_manager.hpp
|
||||
src/graphics/mesh_tools.hpp
|
||||
src/graphics/moving_texture.hpp
|
||||
src/graphics/particle_emitter.hpp
|
||||
src/graphics/particle_kind.hpp
|
||||
src/graphics/particle_kind_manager.hpp
|
||||
src/graphics/per_camera_node.hpp
|
||||
src/graphics/post_processing.hpp
|
||||
src/graphics/rain.hpp
|
||||
src/graphics/referee.hpp
|
||||
src/graphics/shadow.hpp
|
||||
src/graphics/show_curve.hpp
|
||||
src/graphics/skid_marks.hpp
|
||||
src/graphics/slip_stream.hpp
|
||||
src/graphics/stars.hpp
|
||||
src/guiengine/abstract_state_manager.hpp
|
||||
src/guiengine/abstract_top_level_container.hpp
|
||||
src/guiengine/engine.hpp
|
||||
src/guiengine/event_handler.hpp
|
||||
src/guiengine/layout_manager.hpp
|
||||
src/guiengine/modaldialog.hpp
|
||||
src/guiengine/scalable_font.hpp
|
||||
src/guiengine/screen.hpp
|
||||
src/guiengine/skin.hpp
|
||||
src/guiengine/widget.hpp
|
||||
src/guiengine/widgets/bubble_widget.hpp
|
||||
src/guiengine/widgets/button_widget.hpp
|
||||
src/guiengine/widgets/check_box_widget.hpp
|
||||
src/guiengine/widgets/dynamic_ribbon_widget.hpp
|
||||
src/guiengine/widgets.hpp
|
||||
src/guiengine/widgets/icon_button_widget.hpp
|
||||
src/guiengine/widgets/label_widget.hpp
|
||||
src/guiengine/widgets/list_widget.hpp
|
||||
src/guiengine/widgets/model_view_widget.hpp
|
||||
src/guiengine/widgets/progress_bar_widget.hpp
|
||||
src/guiengine/widgets/rating_bar_widget.hpp
|
||||
src/guiengine/widgets/ribbon_widget.hpp
|
||||
src/guiengine/widgets/spinner_widget.hpp
|
||||
src/guiengine/widgets/text_box_widget.hpp
|
||||
src/input/binding.hpp
|
||||
src/input/device_manager.hpp
|
||||
src/input/input_device.hpp
|
||||
src/input/input.hpp
|
||||
src/input/input_manager.hpp
|
||||
src/input/wiimote.hpp
|
||||
src/input/wiimote_manager.hpp
|
||||
src/io/file_manager.hpp
|
||||
src/io/xml_node.hpp
|
||||
src/io/xml_writer.hpp
|
||||
src/items/attachment.hpp
|
||||
src/items/attachment_manager.hpp
|
||||
src/items/attachment_plugin.hpp
|
||||
src/items/bowling.hpp
|
||||
src/items/cake.hpp
|
||||
src/items/flyable.hpp
|
||||
src/items/item.hpp
|
||||
src/items/item_manager.hpp
|
||||
src/items/plunger.hpp
|
||||
src/items/powerup.hpp
|
||||
src/items/powerup_manager.hpp
|
||||
src/items/projectile_manager.hpp
|
||||
src/items/rubber_ball.hpp
|
||||
src/items/rubber_band.hpp
|
||||
src/items/swatter.hpp
|
||||
src/karts/abstract_kart_animation.hpp
|
||||
src/karts/abstract_kart.hpp
|
||||
src/karts/cannon_animation.hpp
|
||||
src/karts/controller/ai_base_controller.hpp
|
||||
src/karts/controller/ai_properties.hpp
|
||||
src/karts/controller/controller.hpp
|
||||
src/karts/controller/end_controller.hpp
|
||||
src/karts/controller/kart_control.hpp
|
||||
src/karts/controller/player_controller.hpp
|
||||
src/karts/controller/skidding_ai.hpp
|
||||
src/karts/explosion_animation.hpp
|
||||
src/karts/ghost_kart.hpp
|
||||
src/karts/kart_gfx.hpp
|
||||
src/karts/kart.hpp
|
||||
src/karts/kart_model.hpp
|
||||
src/karts/kart_properties.hpp
|
||||
src/karts/kart_properties_manager.hpp
|
||||
src/karts/kart_with_stats.hpp
|
||||
src/karts/max_speed.hpp
|
||||
src/karts/moveable.hpp
|
||||
src/karts/rescue_animation.hpp
|
||||
src/karts/skidding.hpp
|
||||
src/karts/skidding_properties.hpp
|
||||
src/main_loop.hpp
|
||||
src/modes/cutscene_world.hpp
|
||||
src/modes/demo_world.hpp
|
||||
src/modes/easter_egg_hunt.hpp
|
||||
src/modes/follow_the_leader.hpp
|
||||
src/modes/linear_world.hpp
|
||||
src/modes/overworld.hpp
|
||||
src/modes/profile_world.hpp
|
||||
src/modes/soccer_world.hpp
|
||||
src/modes/standard_race.hpp
|
||||
src/modes/three_strikes_battle.hpp
|
||||
src/modes/tutorial_world.hpp
|
||||
src/modes/world.hpp
|
||||
src/modes/world_status.hpp
|
||||
src/modes/world_with_rank.hpp
|
||||
src/network/client_network_manager.hpp
|
||||
src/network/event.hpp
|
||||
src/network/game_setup.hpp
|
||||
src/network/http_functions.hpp
|
||||
src/network/network_interface.hpp
|
||||
src/network/network_manager.hpp
|
||||
src/network/network_string.hpp
|
||||
src/network/protocol.hpp
|
||||
src/network/protocol_manager.hpp
|
||||
src/network/protocols/connect_to_peer.hpp
|
||||
src/network/protocols/connect_to_server.hpp
|
||||
src/network/protocols/get_peer_address.hpp
|
||||
src/network/protocols/get_public_address.hpp
|
||||
src/network/protocols/hide_public_address.hpp
|
||||
src/network/protocols/lobby_room_protocol.hpp
|
||||
src/network/protocols/ping_protocol.hpp
|
||||
src/network/protocols/request_connection.hpp
|
||||
src/network/protocols/show_public_address.hpp
|
||||
src/network/protocols/start_server.hpp
|
||||
src/network/protocols/stop_server.hpp
|
||||
src/network/remote_kart_info.hpp
|
||||
src/network/server_network_manager.hpp
|
||||
src/network/singleton.hpp
|
||||
src/network/stk_host.hpp
|
||||
src/network/stk_peer.hpp
|
||||
src/network/types.hpp
|
||||
src/online/current_online_user.hpp
|
||||
src/online/http_connector.hpp
|
||||
src/online/online_user.hpp
|
||||
src/physics/btKart.hpp
|
||||
src/physics/btKartRaycast.hpp
|
||||
src/physics/btUprightConstraint.hpp
|
||||
src/physics/irr_debug_drawer.hpp
|
||||
src/physics/kart_motion_state.hpp
|
||||
src/physics/physical_object.hpp
|
||||
src/physics/physics.hpp
|
||||
src/physics/stk_dynamics_world.hpp
|
||||
src/physics/triangle_mesh.hpp
|
||||
src/physics/user_pointer.hpp
|
||||
src/race/grand_prix_data.hpp
|
||||
src/race/grand_prix_manager.hpp
|
||||
src/race/highscore_manager.hpp
|
||||
src/race/highscores.hpp
|
||||
src/race/history.hpp
|
||||
src/race/race_manager.hpp
|
||||
src/replay/replay_base.hpp
|
||||
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/credits.hpp
|
||||
src/states_screens/cutscene_gui.hpp
|
||||
src/states_screens/dialogs/add_device_dialog.hpp
|
||||
src/states_screens/dialogs/addons_loading.hpp
|
||||
src/states_screens/dialogs/confirm_resolution_dialog.hpp
|
||||
src/states_screens/dialogs/custom_video_settings.hpp
|
||||
src/states_screens/dialogs/enter_player_name_dialog.hpp
|
||||
src/states_screens/dialogs/gp_info_dialog.hpp
|
||||
src/states_screens/dialogs/login_dialog.hpp
|
||||
src/states_screens/dialogs/message_dialog.hpp
|
||||
src/states_screens/dialogs/player_info_dialog.hpp
|
||||
src/states_screens/dialogs/press_a_key_dialog.hpp
|
||||
src/states_screens/dialogs/race_paused_dialog.hpp
|
||||
src/states_screens/dialogs/registration_dialog.hpp
|
||||
src/states_screens/dialogs/select_challenge.hpp
|
||||
src/states_screens/dialogs/track_info_dialog.hpp
|
||||
src/states_screens/dialogs/tutorial_message_dialog.hpp
|
||||
src/states_screens/feature_unlocked.hpp
|
||||
src/states_screens/grand_prix_lose.hpp
|
||||
src/states_screens/grand_prix_win.hpp
|
||||
src/states_screens/help_screen_1.hpp
|
||||
src/states_screens/help_screen_2.hpp
|
||||
src/states_screens/help_screen_3.hpp
|
||||
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
|
||||
src/states_screens/options_screen_input.hpp
|
||||
src/states_screens/options_screen_players.hpp
|
||||
src/states_screens/options_screen_ui.hpp
|
||||
src/states_screens/options_screen_video.hpp
|
||||
src/states_screens/race_gui_base.hpp
|
||||
src/states_screens/race_gui.hpp
|
||||
src/states_screens/race_gui_overworld.hpp
|
||||
src/states_screens/race_result_gui.hpp
|
||||
src/states_screens/race_setup_screen.hpp
|
||||
src/states_screens/soccer_setup_screen.hpp
|
||||
src/states_screens/state_manager.hpp
|
||||
src/states_screens/story_mode_lobby.hpp
|
||||
src/states_screens/tracks_screen.hpp
|
||||
src/tinygettext/dictionary.hpp
|
||||
src/tinygettext/dictionary_manager.hpp
|
||||
src/tinygettext/file_system.hpp
|
||||
src/tinygettext/iconv.hpp
|
||||
src/tinygettext/language.hpp
|
||||
src/tinygettext/log_stream.hpp
|
||||
src/tinygettext/plural_forms.hpp
|
||||
src/tinygettext/po_parser.hpp
|
||||
src/tinygettext/stk_file_system.hpp
|
||||
src/tinygettext/tgt_log.hpp
|
||||
src/tinygettext/tinygettext.hpp
|
||||
src/tracks/ambient_light_sphere.hpp
|
||||
src/tracks/bezier_curve.hpp
|
||||
src/tracks/check_cannon.hpp
|
||||
src/tracks/check_goal.hpp
|
||||
src/tracks/check_lap.hpp
|
||||
src/tracks/check_line.hpp
|
||||
src/tracks/check_manager.hpp
|
||||
src/tracks/check_sphere.hpp
|
||||
src/tracks/check_structure.hpp
|
||||
src/tracks/graph_node.hpp
|
||||
src/tracks/lod_node_loader.hpp
|
||||
src/tracks/quad_graph.hpp
|
||||
src/tracks/quad.hpp
|
||||
src/tracks/quad_set.hpp
|
||||
src/tracks/terrain_info.hpp
|
||||
src/tracks/track.hpp
|
||||
src/tracks/track_manager.hpp
|
||||
src/tracks/track_object.hpp
|
||||
src/tracks/track_object_manager.hpp
|
||||
src/tracks/track_object_presentation.hpp
|
||||
src/tracks/track_sector.hpp
|
||||
src/utils/aligned_array.hpp
|
||||
src/utils/constants.hpp
|
||||
src/utils/interpolation_array.hpp
|
||||
src/utils/leak_check.hpp
|
||||
src/utils/log.hpp
|
||||
src/utils/no_copy.hpp
|
||||
src/utils/profiler.hpp
|
||||
src/utils/ptr_vector.hpp
|
||||
src/utils/random_generator.hpp
|
||||
src/utils/string_utils.hpp
|
||||
src/utils/synchronised.hpp
|
||||
src/utils/time.hpp
|
||||
src/utils/translation.hpp
|
||||
src/utils/types.hpp
|
||||
src/utils/vec3.hpp
|
||||
)
|
||||
@@ -164,6 +164,8 @@ supertuxkart_SOURCES = \
|
||||
guiengine/widgets/text_box_widget.hpp \
|
||||
guiengine/widgets/progress_bar_widget.cpp \
|
||||
guiengine/widgets/progress_bar_widget.hpp \
|
||||
guiengine/widgets/rating_bar_widget.cpp \
|
||||
guiengine/widgets/rating_bar_widget.hpp \
|
||||
input/binding.cpp \
|
||||
input/binding.hpp \
|
||||
input/device_manager.cpp \
|
||||
@@ -397,8 +399,6 @@ supertuxkart_SOURCES = \
|
||||
states_screens/kart_selection.hpp \
|
||||
states_screens/main_menu_screen.cpp \
|
||||
states_screens/main_menu_screen.hpp \
|
||||
states_screens/minimal_race_gui.cpp \
|
||||
states_screens/minimal_race_gui.hpp \
|
||||
states_screens/options_screen_audio.cpp \
|
||||
states_screens/options_screen_audio.hpp \
|
||||
states_screens/options_screen_input.cpp \
|
||||
|
||||
@@ -177,3 +177,42 @@ bool Addon::testIncluded(const std::string &min_ver, const std::string &max_ver)
|
||||
|
||||
return (min_version <= current_version && max_version >= current_version);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/**
|
||||
* \brief Filter the add-on with a list of words.
|
||||
* \param words A list of words separated by ' '.
|
||||
* \return true if the add-on contains one of the words, otherwise false.
|
||||
*/
|
||||
bool Addon::filterByWords(const core::stringw words) const
|
||||
{
|
||||
if (words == NULL || words.empty())
|
||||
return true;
|
||||
|
||||
std::vector<core::stringw> list = StringUtils::split(words, ' ', false);
|
||||
|
||||
for (unsigned int i = 0; i < list.size(); i++)
|
||||
{
|
||||
list[i].make_lower();
|
||||
|
||||
core::stringw name = core::stringw(m_name).make_lower();
|
||||
if (name.find(list[i].c_str()) != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
core::stringw designer = core::stringw(m_designer).make_lower();
|
||||
if (designer.find(list[i].c_str()) != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
core::stringw description = core::stringw(m_description).make_lower();
|
||||
if (description.find(list[i].c_str()) != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} // filterByWords
|
||||
|
||||
@@ -266,6 +266,9 @@ public:
|
||||
return file_manager->getAddonsFile(getTypeDirectory()+m_dir_name);
|
||||
} // getDataDir
|
||||
// ------------------------------------------------------------------------
|
||||
bool filterByWords(const core::stringw words) const;
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/** Compares two addons according to the sort order currently defined.
|
||||
* \param a The addon to compare this addon to.
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "addons/inetwork_http.hpp"
|
||||
#include "addons/request.hpp"
|
||||
#include "addons/zip.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
|
||||
@@ -43,14 +43,6 @@
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
// Use Sleep, which takes time in msecs. It must be defined after the
|
||||
// includes, since otherwise irrlicht's sleep function is changed.
|
||||
# define sleep(s) Sleep(1000*(s))
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Create a thread that handles all network functions independent of the
|
||||
* main program. NetworkHttp supports only a single thread (i.e. it's not
|
||||
@@ -179,7 +171,7 @@ void *NetworkHttp::mainLoop(void *obj)
|
||||
switch(me->m_current_request->getCommand())
|
||||
{
|
||||
case Request::HC_INIT:
|
||||
status = me->init();
|
||||
status = me->init(false);
|
||||
break;
|
||||
case Request::HC_REINIT:
|
||||
status = me->reInit();
|
||||
@@ -269,7 +261,7 @@ NetworkHttp::~NetworkHttp()
|
||||
* \return 0 if an error happened and no online connection will be available,
|
||||
* 1 otherwise.
|
||||
*/
|
||||
CURLcode NetworkHttp::init()
|
||||
CURLcode NetworkHttp::init(bool forceRefresh)
|
||||
{
|
||||
news_manager->clearErrorMessage();
|
||||
core::stringw error_message("");
|
||||
@@ -278,7 +270,7 @@ CURLcode NetworkHttp::init()
|
||||
bool download = UserConfigParams::m_news_last_updated==0 ||
|
||||
UserConfigParams::m_news_last_updated
|
||||
+UserConfigParams::m_news_frequency
|
||||
< Time::getTimeSinceEpoch();
|
||||
< Time::getTimeSinceEpoch() || forceRefresh;
|
||||
|
||||
if(!download)
|
||||
{
|
||||
@@ -332,7 +324,7 @@ CURLcode NetworkHttp::init()
|
||||
xml = new XMLNode(xml_file);
|
||||
}
|
||||
news_manager->init();
|
||||
status = loadAddonsList(xml, xml_file);
|
||||
status = loadAddonsList(xml, xml_file, forceRefresh);
|
||||
delete xml;
|
||||
if(status==CURLE_OK)
|
||||
{
|
||||
@@ -401,14 +393,10 @@ CURLcode NetworkHttp::reInit()
|
||||
m_all_requests.getData().pop();
|
||||
m_all_requests.unlock();
|
||||
|
||||
std::string news_file = file_manager->getAddonsFile("news.xml");
|
||||
file_manager->removeFile(news_file);
|
||||
std::string addons_file = file_manager->getAddonsFile("addons.xml");
|
||||
file_manager->removeFile(addons_file);
|
||||
if(UserConfigParams::logAddons())
|
||||
printf("[addons] Xml files deleted, re-initialising addon manager.\n");
|
||||
|
||||
return init();
|
||||
return init(true /* force refresh */);
|
||||
|
||||
} // reInit
|
||||
|
||||
@@ -424,7 +412,8 @@ CURLcode NetworkHttp::reInit()
|
||||
* \return curl error code (esp. CURLE_OK if no error occurred)
|
||||
*/
|
||||
CURLcode NetworkHttp::loadAddonsList(const XMLNode *xml,
|
||||
const std::string &filename)
|
||||
const std::string &filename,
|
||||
bool forceRefresh)
|
||||
{
|
||||
std::string addon_list_url("");
|
||||
Time::TimeType mtime(0);
|
||||
@@ -445,7 +434,8 @@ CURLcode NetworkHttp::loadAddonsList(const XMLNode *xml,
|
||||
return CURLE_COULDNT_CONNECT;
|
||||
}
|
||||
|
||||
bool download = mtime > UserConfigParams::m_addons_last_updated;
|
||||
bool download = (mtime > UserConfigParams::m_addons_last_updated) || forceRefresh;
|
||||
|
||||
if(!download)
|
||||
{
|
||||
std::string filename=file_manager->getAddonsFile("addons.xml");
|
||||
@@ -453,6 +443,11 @@ CURLcode NetworkHttp::loadAddonsList(const XMLNode *xml,
|
||||
download = true;
|
||||
}
|
||||
|
||||
if (download)
|
||||
Log::info("NetworkHttp", "Downloading updated addons.xml");
|
||||
else
|
||||
Log::info("NetworkHttp", "Using cached addons.xml");
|
||||
|
||||
Request r(Request::HC_DOWNLOAD_FILE, 9999, false,
|
||||
addon_list_url, "addons.xml");
|
||||
CURLcode status = download ? downloadFileInternal(&r)
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <vector>
|
||||
|
||||
#ifdef WIN32
|
||||
# include <winsock2.h>
|
||||
# include <WinSock2.h>
|
||||
#endif
|
||||
#include <curl/curl.h>
|
||||
|
||||
@@ -65,9 +65,10 @@ private:
|
||||
CURL *m_curl_session;
|
||||
|
||||
static void *mainLoop(void *obj);
|
||||
CURLcode init();
|
||||
CURLcode init(bool forceRefresh);
|
||||
CURLcode loadAddonsList(const XMLNode *xml,
|
||||
const std::string &filename);
|
||||
const std::string &filename,
|
||||
bool forceRefresh);
|
||||
CURLcode downloadFileInternal(Request *request);
|
||||
static int progressDownload(void *clientp, double dltotal, double dlnow,
|
||||
double ultotal, double ulnow);
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#include "animations/animation_base.hpp"
|
||||
|
||||
#include "animations/ipo.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "audio/sfx_base.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/mesh_tools.hpp"
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "audio/music_dummy.hpp"
|
||||
#include "audio/music_ogg.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include "audio/music_manager.hpp"
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
|
||||
MusicOggStream::MusicOggStream()
|
||||
|
||||
@@ -101,8 +101,6 @@ private:
|
||||
|
||||
void loadSfx();
|
||||
|
||||
bool loadVorbisBuffer(const std::string &name,
|
||||
ALuint buffer);
|
||||
public:
|
||||
SFXManager();
|
||||
virtual ~SFXManager();
|
||||
|
||||
@@ -331,9 +331,7 @@ void ChallengeData::setUnlocks(const std::string &id, RewardType reward)
|
||||
}
|
||||
case UNLOCK_DIFFICULTY:
|
||||
{
|
||||
//TODO: difficulty names when unlocking
|
||||
irr::core::stringw user_name = "?";
|
||||
addUnlockDifficultyReward(id, user_name);
|
||||
addUnlockDifficultyReward(id, core::stringw(id.c_str()));
|
||||
break;
|
||||
}
|
||||
case UNLOCK_KART: {
|
||||
|
||||
@@ -57,7 +57,6 @@ public:
|
||||
}; // UnlockableFeature
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
/** The various types of challenges that we support, which esp. determine
|
||||
* when a challenge is tested if it is fulfilled. For now we have GP
|
||||
* (a GP challenge, tested at the end of a GP), Race (tested at the
|
||||
@@ -74,6 +73,9 @@ private:
|
||||
CM_ANY
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** The challenge mode of this challenge. */
|
||||
ChallengeModeType m_mode;
|
||||
|
||||
|
||||
@@ -434,12 +434,12 @@ void UnlockManager::findWhatWasUnlocked(int points_before, int points_now,
|
||||
if (c->getNumTrophies() > points_before &&
|
||||
c->getNumTrophies() <= points_now )
|
||||
{
|
||||
if (c->getTrackId() != "")
|
||||
if (c->getMode() == ChallengeData::CM_SINGLE_RACE && c->getTrackId() != "")
|
||||
{
|
||||
if (!getCurrentSlot()->isLocked(c->getTrackId()))
|
||||
tracks.push_back(c->getTrackId());
|
||||
}
|
||||
else if (c->getGPId() != "")
|
||||
else if (c->getMode() == ChallengeData::CM_GRAND_PRIX && c->getGPId() != "")
|
||||
{
|
||||
if (!getCurrentSlot()->isLocked(c->getGPId()))
|
||||
gps.push_back(c->getGPId());
|
||||
|
||||
@@ -47,6 +47,7 @@ irr::core::stringw DeviceConfig::getMappingIdString (const PlayerAction action)
|
||||
const Input::InputType type = m_bindings[action].getType();
|
||||
const int id = m_bindings[action].getId();
|
||||
const Input::AxisDirection dir = m_bindings[action].getDirection();
|
||||
const Input::AxisRange range = m_bindings[action].getRange();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@@ -60,6 +61,8 @@ irr::core::stringw DeviceConfig::getMappingIdString (const PlayerAction action)
|
||||
returnString += id;
|
||||
returnString += "$";
|
||||
returnString += dir;
|
||||
returnString += "$";
|
||||
returnString += range;
|
||||
break;
|
||||
|
||||
case Input::IT_STICKBUTTON:
|
||||
@@ -114,9 +117,10 @@ void DeviceConfig::setBinding ( const PlayerAction action,
|
||||
const Input::InputType type,
|
||||
const int id,
|
||||
Input::AxisDirection direction,
|
||||
Input::AxisRange range,
|
||||
wchar_t character)
|
||||
{
|
||||
m_bindings[action].set(type, id, direction, character);
|
||||
m_bindings[action].set(type, id, direction, range, character);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -124,7 +128,7 @@ void DeviceConfig::setBinding ( const PlayerAction action,
|
||||
// Don't call this directly unless you are KeyboardDevice or GamepadDevice
|
||||
bool DeviceConfig::getGameAction(Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
int* value, /* inout */
|
||||
PlayerAction* action /* out */ )
|
||||
{
|
||||
return doGetAction(type, id, value, PA_FIRST_GAME_ACTION, PA_LAST_GAME_ACTION, action);
|
||||
@@ -135,7 +139,7 @@ bool DeviceConfig::getGameAction(Input::InputType type,
|
||||
// Don't call this directly unless you are KeyboardDevice or GamepadDevice
|
||||
bool DeviceConfig::getMenuAction(Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
int* value,
|
||||
PlayerAction* action /* out */ )
|
||||
{
|
||||
return doGetAction(type, id, value, PA_FIRST_MENU_ACTION, PA_LAST_MENU_ACTION, action);
|
||||
@@ -145,7 +149,7 @@ bool DeviceConfig::getMenuAction(Input::InputType type,
|
||||
|
||||
bool DeviceConfig::doGetAction(Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
int* value, /* inout */
|
||||
const PlayerAction firstActionToCheck,
|
||||
const PlayerAction lastActionToCheck,
|
||||
PlayerAction* action /* out */ )
|
||||
@@ -162,13 +166,30 @@ bool DeviceConfig::doGetAction(Input::InputType type,
|
||||
|
||||
if (type == Input::IT_STICKMOTION)
|
||||
{
|
||||
if ( ((m_bindings[n].getDirection() == Input::AD_POSITIVE)
|
||||
&& (value > 0)) ||
|
||||
((m_bindings[n].getDirection() == Input::AD_NEGATIVE)
|
||||
&& (value < 0)) )
|
||||
if(m_bindings[n].getRange() == Input::AR_HALF)
|
||||
{
|
||||
success = true;
|
||||
*action = (PlayerAction)n;
|
||||
if ( ((m_bindings[n].getDirection() == Input::AD_POSITIVE)
|
||||
&& (*value > 0)) ||
|
||||
((m_bindings[n].getDirection() == Input::AD_NEGATIVE)
|
||||
&& (*value < 0)) )
|
||||
{
|
||||
success = true;
|
||||
*action = (PlayerAction)n;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ((m_bindings[n].getDirection() == Input::AD_POSITIVE)
|
||||
&& (*value != -Input::MAX_VALUE)) ||
|
||||
((m_bindings[n].getDirection() == Input::AD_NEGATIVE)
|
||||
&& (*value != Input::MAX_VALUE)) )
|
||||
{
|
||||
success = true;
|
||||
*action = (PlayerAction)n;
|
||||
if(m_bindings[n].getDirection() == Input::AD_NEGATIVE)
|
||||
*value = -*value;
|
||||
*value = (*value + Input::MAX_VALUE) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -68,7 +68,7 @@ protected:
|
||||
*/
|
||||
bool doGetAction(Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
int* value, /* inout */
|
||||
const PlayerAction firstActionToCheck,
|
||||
const PlayerAction lastActionToCheck,
|
||||
PlayerAction* action /* out */ );
|
||||
@@ -92,6 +92,7 @@ public:
|
||||
const Input::InputType type,
|
||||
const int id,
|
||||
Input::AxisDirection direction = Input::AD_NEUTRAL,
|
||||
Input::AxisRange range = Input::AR_HALF,
|
||||
wchar_t character=0);
|
||||
|
||||
void setPlugged () { m_plugged++; }
|
||||
@@ -106,7 +107,7 @@ public:
|
||||
*/
|
||||
bool getGameAction (Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
int* value, /* inout */
|
||||
PlayerAction* action /* out */);
|
||||
|
||||
/**
|
||||
@@ -117,7 +118,7 @@ public:
|
||||
*/
|
||||
bool getMenuAction (Input::InputType type,
|
||||
const int id,
|
||||
const int value,
|
||||
int* value,
|
||||
PlayerAction* action /* out */);
|
||||
|
||||
Binding& getBinding (int i) {return m_bindings[i];}
|
||||
|
||||
@@ -117,7 +117,7 @@ void STKConfig::load(const std::string &filename)
|
||||
CHECK_NEG(m_anvil_time, "anvil-time" );
|
||||
CHECK_NEG(m_anvil_weight, "anvil-weight" );
|
||||
CHECK_NEG(m_item_switch_time, "item-switch-time" );
|
||||
CHECK_NEG(m_bubble_gum_counter, "bubblegum disappear counter");
|
||||
CHECK_NEG(m_bubblegum_counter, "bubblegum disappear counter");
|
||||
CHECK_NEG(m_explosion_impulse_objects, "explosion-impulse-objects" );
|
||||
CHECK_NEG(m_max_history, "max-history" );
|
||||
CHECK_NEG(m_max_skidmarks, "max-skidmarks" );
|
||||
@@ -158,7 +158,7 @@ void STKConfig::init_defaults()
|
||||
m_near_ground = m_item_switch_time =
|
||||
m_smooth_angle_limit =
|
||||
m_penalty_time = m_explosion_impulse_objects = UNDEFINED;
|
||||
m_bubble_gum_counter = -100;
|
||||
m_bubblegum_counter = -100;
|
||||
m_max_karts = -100;
|
||||
m_max_history = -100;
|
||||
m_max_skidmarks = -100;
|
||||
@@ -333,9 +333,9 @@ void STKConfig::getAllData(const XMLNode * root)
|
||||
switch_node->get("time", &m_item_switch_time);
|
||||
}
|
||||
|
||||
if(const XMLNode *bubble_gum_node= root->getNode("bubble-gum"))
|
||||
if(const XMLNode *bubblegum_node= root->getNode("bubblegum"))
|
||||
{
|
||||
bubble_gum_node->get("disappear-counter", &m_bubble_gum_counter);
|
||||
bubblegum_node->get("disappear-counter", &m_bubblegum_counter);
|
||||
}
|
||||
|
||||
if(const XMLNode *explosion_node= root->getNode("explosion"))
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
passed on. */
|
||||
float m_anvil_time; /**<Time an anvil is active. */
|
||||
float m_item_switch_time; /**< Time items will be switched. */
|
||||
int m_bubble_gum_counter; /**< How many times bananas must be eaten
|
||||
int m_bubblegum_counter; /**< How many times bananas must be eaten
|
||||
before they disappear. */
|
||||
float m_explosion_impulse_objects;/**<Impulse of explosion on moving
|
||||
objects, e.g. road cones, ... */
|
||||
|
||||
@@ -284,7 +284,6 @@ irr::core::stringw TimeUserConfigParam::toString() const
|
||||
// we can't use an irrlicht's stringw directly. Since it's only a
|
||||
// number, we can use std::string, and convert to stringw
|
||||
|
||||
std::string tmp;
|
||||
std::ostringstream o;
|
||||
o<<m_value;
|
||||
return core::stringw(o.str().c_str());
|
||||
|
||||
@@ -487,13 +487,15 @@ namespace UserConfigParams
|
||||
// not saved to file
|
||||
|
||||
// ---- Networking
|
||||
PARAM_PREFIX StringUserConfigParam m_server_address
|
||||
PARAM_DEFAULT( StringUserConfigParam("localhost", "server_adress",
|
||||
"Information about last server used") );
|
||||
PARAM_PREFIX IntUserConfigParam m_server_port
|
||||
PARAM_DEFAULT( IntUserConfigParam(2305, "server_port",
|
||||
"Information about last server used") );
|
||||
|
||||
PARAM_DEFAULT( IntUserConfigParam(7321, "server_port",
|
||||
"Information about the port to listen on.") );
|
||||
|
||||
PARAM_PREFIX IntUserConfigParam m_server_max_players
|
||||
PARAM_DEFAULT( IntUserConfigParam(16, "server_max_players",
|
||||
"Maximum number of players on the server.") );
|
||||
|
||||
|
||||
// ---- Graphic Quality
|
||||
PARAM_PREFIX GroupUserConfigParam m_graphics_quality
|
||||
PARAM_DEFAULT( GroupUserConfigParam("GFX",
|
||||
@@ -603,6 +605,13 @@ namespace UserConfigParams
|
||||
PARAM_DEFAULT( WStringUserConfigParam(L"", "default_player",
|
||||
"Which player to use by default (if empty, will prompt)") );
|
||||
|
||||
// ---- Online multiplayer related
|
||||
|
||||
PARAM_PREFIX StringUserConfigParam m_server_multiplayer
|
||||
PARAM_DEFAULT( StringUserConfigParam("http://api.stkaddons.net/",
|
||||
"server_multiplayer",
|
||||
"The server used for online multiplayer."));
|
||||
|
||||
// ---- Addon server related entries
|
||||
PARAM_PREFIX GroupUserConfigParam m_addon_group
|
||||
PARAM_DEFAULT( GroupUserConfigParam("AddonAndNews",
|
||||
|
||||
@@ -99,7 +99,7 @@ private:
|
||||
* get attached to another kart if a kart is elimiated). */
|
||||
AbstractKart *m_original_kart;
|
||||
|
||||
/** The list of viewports for this cameras. */
|
||||
/** The viewport for this camera (portion of the game window covered by this camera) */
|
||||
core::recti m_viewport;
|
||||
|
||||
/** The scaling necessary for each axis. */
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/particle_emitter.hpp"
|
||||
#include "graphics/particle_kind_manager.hpp"
|
||||
#include "items/projectile_manager.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "utils/vec3.hpp"
|
||||
@@ -32,44 +34,15 @@
|
||||
const float burst_time = 0.1f;
|
||||
|
||||
/** Creates an explosion effect. */
|
||||
Explosion::Explosion(const Vec3& coord, const char* explosion_sound)
|
||||
Explosion::Explosion(const Vec3& coord, const char* explosion_sound, const char * particle_file)
|
||||
: HitSFX(coord, explosion_sound)
|
||||
{
|
||||
// short emision time, explosion, not constant flame
|
||||
m_remaining_time = burst_time;
|
||||
m_node = irr_driver->addParticleNode();
|
||||
m_node->grab();
|
||||
#ifdef DEBUG
|
||||
m_node->setName("explosion");
|
||||
#endif
|
||||
m_node->setPosition(coord.toIrrVector());
|
||||
Material* m = material_manager->getMaterial("explode.png");
|
||||
m_node->setMaterialTexture(0, m->getTexture());
|
||||
m->setMaterialProperties(&(m_node->getMaterial(0)), NULL);
|
||||
m_node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
|
||||
|
||||
scene::IParticleEmitter* em =
|
||||
m_node->createSphereEmitter(core::vector3df(0.0f,0.0f,0.0f), 0.5f,
|
||||
/* velocity in m/ms */core::vector3df(0.0f,0.005f,0.0f),
|
||||
600, 900, // min max particles per sec
|
||||
video::SColor(0, 0, 0, 0), // min colour
|
||||
video::SColor(0, 0, 0, 0), // max colour
|
||||
(int)((burst_time + explosion_time)
|
||||
*1000.0f), // min life ms
|
||||
(int)((burst_time + explosion_time)
|
||||
*1000.0f), // max max life ms
|
||||
90, // max angle
|
||||
// min and max start size
|
||||
core::dimension2df(0.3f, 0.3f),
|
||||
core::dimension2df(0.75f, 0.75f)
|
||||
);
|
||||
m_node->setEmitter(em); // this grabs the emitter
|
||||
em->drop(); // so we can drop it here without deleting it
|
||||
|
||||
scene::IParticleAffector* scale_affector =
|
||||
m_node->createScaleParticleAffector(core::dimension2df(3.0f, 3.0f));
|
||||
m_node->addAffector(scale_affector); // same goes for the affector
|
||||
scale_affector->drop();
|
||||
|
||||
ParticleKindManager* pkm = ParticleKindManager::get();
|
||||
ParticleKind* particles = pkm->getParticles(particle_file);
|
||||
m_emitter = new ParticleEmitter(particles, coord, NULL);
|
||||
} // Explosion
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -77,12 +50,9 @@ Explosion::Explosion(const Vec3& coord, const char* explosion_sound)
|
||||
*/
|
||||
Explosion::~Explosion()
|
||||
{
|
||||
if(m_node)
|
||||
if(m_emitter)
|
||||
{
|
||||
m_node->drop();
|
||||
// Remove from scene node by removing from parent.
|
||||
irr_driver->removeNode(m_node);
|
||||
m_node = NULL;
|
||||
delete m_emitter;
|
||||
}
|
||||
} // ~Explosion
|
||||
|
||||
@@ -101,19 +71,20 @@ bool Explosion::updateAndDelete(float dt)
|
||||
|
||||
if (m_remaining_time < 0.0f && m_remaining_time >= -explosion_time)
|
||||
{
|
||||
|
||||
scene::ISceneNode* node = m_emitter->getNode();
|
||||
|
||||
const int intensity = (int)(255-(m_remaining_time/-explosion_time)*255);
|
||||
m_node->getMaterial(0).AmbientColor.setGreen(intensity);
|
||||
m_node->getMaterial(0).DiffuseColor.setGreen(intensity);
|
||||
m_node->getMaterial(0).EmissiveColor.setGreen(intensity);
|
||||
node->getMaterial(0).AmbientColor.setGreen(intensity);
|
||||
node->getMaterial(0).DiffuseColor.setGreen(intensity);
|
||||
node->getMaterial(0).EmissiveColor.setGreen(intensity);
|
||||
|
||||
m_node->getMaterial(0).AmbientColor.setBlue(intensity);
|
||||
m_node->getMaterial(0).DiffuseColor.setBlue(intensity);
|
||||
m_node->getMaterial(0).EmissiveColor.setBlue(intensity);
|
||||
node->getMaterial(0).AmbientColor.setBlue(intensity);
|
||||
node->getMaterial(0).DiffuseColor.setBlue(intensity);
|
||||
node->getMaterial(0).EmissiveColor.setBlue(intensity);
|
||||
|
||||
m_node->getMaterial(0).AmbientColor.setRed(intensity);
|
||||
m_node->getMaterial(0).DiffuseColor.setRed(intensity);
|
||||
m_node->getMaterial(0).EmissiveColor.setRed(intensity);
|
||||
node->getMaterial(0).AmbientColor.setRed(intensity);
|
||||
node->getMaterial(0).DiffuseColor.setRed(intensity);
|
||||
node->getMaterial(0).EmissiveColor.setRed(intensity);
|
||||
|
||||
}
|
||||
|
||||
@@ -127,8 +98,8 @@ bool Explosion::updateAndDelete(float dt)
|
||||
if (m_remaining_time > -explosion_time)
|
||||
{
|
||||
// Stop the emitter and wait a little while for all particles to have time to fade out
|
||||
m_node->getEmitter()->setMinParticlesPerSecond(0);
|
||||
m_node->getEmitter()->setMaxParticlesPerSecond(0);
|
||||
m_emitter->getNode()->getEmitter()->setMinParticlesPerSecond(0);
|
||||
m_emitter->getNode()->getEmitter()->setMaxParticlesPerSecond(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@ using namespace irr;
|
||||
|
||||
class Vec3;
|
||||
class SFXBase;
|
||||
class ParticleEmitter;
|
||||
|
||||
const float explosion_time = 1.5f;
|
||||
|
||||
@@ -39,11 +40,11 @@ const float explosion_time = 1.5f;
|
||||
class Explosion : public HitSFX
|
||||
{
|
||||
private:
|
||||
float m_remaining_time;
|
||||
scene::IParticleSystemSceneNode *m_node;
|
||||
float m_remaining_time;
|
||||
ParticleEmitter* m_emitter;
|
||||
|
||||
public:
|
||||
Explosion(const Vec3& coord, const char* explosion_sound);
|
||||
Explosion(const Vec3& coord, const char* explosion_sound, const char * particle_file );
|
||||
~Explosion();
|
||||
bool updateAndDelete(float delta_t);
|
||||
bool hasEnded () { return m_remaining_time <= -explosion_time; }
|
||||
|
||||
@@ -384,6 +384,13 @@ void IrrDriver::initDevice()
|
||||
m_glsl = m_video_driver->queryFeature(video::EVDF_ARB_GLSL) &&
|
||||
m_video_driver->queryFeature(video::EVDF_TEXTURE_NPOT);
|
||||
|
||||
// This remaps the window, so it has to be done before the clear to avoid flicker
|
||||
m_device->setResizable(false);
|
||||
|
||||
// Immediate clear to black for a nicer user loading experience
|
||||
m_video_driver->beginScene(/*backBuffer clear*/true, /* Z */ false);
|
||||
m_video_driver->endScene();
|
||||
|
||||
if (m_glsl)
|
||||
{
|
||||
Log::info("irr_driver", "GLSL supported.");
|
||||
@@ -409,7 +416,6 @@ void IrrDriver::initDevice()
|
||||
classhint);
|
||||
XFree(classhint);
|
||||
#endif
|
||||
m_device->setResizable(false);
|
||||
m_device->setWindowCaption(L"SuperTuxKart");
|
||||
m_device->getVideoDriver()
|
||||
->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
|
||||
|
||||
@@ -62,8 +62,6 @@ private:
|
||||
* m_forced_lod is >=0, only this level is be used. */
|
||||
int m_forced_lod;
|
||||
|
||||
int getLevel();
|
||||
|
||||
enum PreviousVisibility
|
||||
{
|
||||
FIRST_PASS,
|
||||
@@ -81,6 +79,8 @@ public:
|
||||
//! returns the axis aligned bounding box of this node
|
||||
virtual const core::aabbox3d<f32>& getBoundingBox() const { return Box; }
|
||||
|
||||
int getLevel();
|
||||
|
||||
/*
|
||||
//! Returns a reference to the current relative transformation matrix.
|
||||
//! This is the matrix, this scene node uses instead of scale, translation
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
#include <IGPUProgrammingServices.h>
|
||||
#include <IMaterialRendererServices.h>
|
||||
@@ -873,9 +874,9 @@ void Material::initParticlesEffect(const XMLNode *node)
|
||||
node->get("base", &base);
|
||||
if (base.size() < 1)
|
||||
{
|
||||
fprintf(stderr, "[Material::initParticlesEffect] WARNING: Invalid "
|
||||
"particle settings for material '%s'\n",
|
||||
m_texname.c_str());
|
||||
Log::warn("Material::initParticlesEffect"
|
||||
"Invalid particle settings for material '%s'\n",
|
||||
m_texname.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -883,12 +884,19 @@ void Material::initParticlesEffect(const XMLNode *node)
|
||||
try
|
||||
{
|
||||
particles = pkm->getParticles(base.c_str());
|
||||
|
||||
if (particles == NULL)
|
||||
{
|
||||
Log::warn("Material::initParticlesEffect",
|
||||
"Error loading particles '%s' for material '%s'\n",
|
||||
base.c_str(), m_texname.c_str());
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
fprintf(stderr, "[Material::initParticlesEffect] WARNING: Cannot find "
|
||||
"particles '%s' for material '%s'\n",
|
||||
base.c_str(), m_texname.c_str());
|
||||
Log::warn("Material::initParticlesEffect",
|
||||
"Cannot find particles '%s' for material '%s'\n",
|
||||
base.c_str(), m_texname.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,8 @@ void MaterialManager::popTempMaterial()
|
||||
Material *MaterialManager::getMaterial(const std::string& fname,
|
||||
bool is_full_path,
|
||||
bool make_permanent,
|
||||
bool complain_if_not_found)
|
||||
bool complain_if_not_found,
|
||||
bool strip_path)
|
||||
{
|
||||
if(fname=="")
|
||||
{
|
||||
@@ -297,8 +298,13 @@ Material *MaterialManager::getMaterial(const std::string& fname,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::string basename=StringUtils::getBasename(fname);
|
||||
|
||||
std::string basename;
|
||||
|
||||
if (strip_path)
|
||||
basename = StringUtils::getBasename(fname);
|
||||
else
|
||||
basename = fname;
|
||||
|
||||
// Search backward so that temporary (track) textures are found first
|
||||
for(int i = (int)m_materials.size()-1; i>=0; i-- )
|
||||
{
|
||||
|
||||
@@ -65,7 +65,8 @@ public:
|
||||
Material *getMaterial (const std::string& t,
|
||||
bool is_full_path=false,
|
||||
bool make_permanent=false,
|
||||
bool complain_if_not_found=true);
|
||||
bool complain_if_not_found=true,
|
||||
bool strip_path=true);
|
||||
void addSharedMaterial(const std::string& filename, bool deprecated = false);
|
||||
bool pushTempMaterial (const std::string& filename, bool deprecated = false);
|
||||
bool pushTempMaterial (const XMLNode *root, const std::string& filename, bool deprecated = false);
|
||||
|
||||
@@ -381,14 +381,16 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
m_node->setMaterialTexture(0, irr_driver->getTexture((file_manager->getDataDir() + "gui/main_help.png").c_str()));
|
||||
}
|
||||
|
||||
// velocity in m/ms
|
||||
core::vector3df velocity(m_particle_type->getVelocityX(),
|
||||
m_particle_type->getVelocityY(),
|
||||
m_particle_type->getVelocityZ());
|
||||
|
||||
switch (type->getShape())
|
||||
{
|
||||
case EMITTER_POINT:
|
||||
{
|
||||
m_emitter = m_node->createPointEmitter(core::vector3df(m_particle_type->getVelocityX(),
|
||||
m_particle_type->getVelocityY(),
|
||||
m_particle_type->getVelocityZ()), // velocity in m/ms
|
||||
m_emitter = m_node->createPointEmitter(velocity,
|
||||
type->getMinRate(), type->getMaxRate(),
|
||||
type->getMinColor(), type->getMaxColor(),
|
||||
lifeTimeMin, lifeTimeMax,
|
||||
@@ -404,13 +406,11 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
|
||||
m_emitter = m_node->createBoxEmitter(core::aabbox3df(-box_size_x, -box_size_y, -0.6f,
|
||||
box_size_x, box_size_y, -0.6f - type->getBoxSizeZ()),
|
||||
core::vector3df(m_particle_type->getVelocityX(),
|
||||
m_particle_type->getVelocityY(),
|
||||
m_particle_type->getVelocityZ()), // velocity in m/ms
|
||||
velocity,
|
||||
type->getMinRate(), type->getMaxRate(),
|
||||
type->getMinColor(), type->getMaxColor(),
|
||||
lifeTimeMin, lifeTimeMax,
|
||||
m_particle_type->getAngleSpread() /* angle */
|
||||
m_particle_type->getAngleSpread()
|
||||
);
|
||||
|
||||
#if VISUALIZE_BOX_EMITTER
|
||||
@@ -435,6 +435,18 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case EMITTER_SPHERE:
|
||||
{
|
||||
m_emitter = m_node->createSphereEmitter(core::vector3df(0.0f,0.0f,0.0f) /* center */,
|
||||
m_particle_type->getSphereRadius(),
|
||||
velocity,
|
||||
type->getMinRate(), type->getMaxRate(),
|
||||
type->getMinColor(), type->getMaxColor(),
|
||||
lifeTimeMin, lifeTimeMax,
|
||||
m_particle_type->getAngleSpread()
|
||||
);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
fprintf(stderr, "[ParticleEmitter] Unknown shape\n");
|
||||
@@ -476,6 +488,16 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
m_node->addAffector(faa);
|
||||
faa->drop();
|
||||
}
|
||||
|
||||
if (type->hasScaleAffector())
|
||||
{
|
||||
core::dimension2df factor = core::dimension2df(type->getScaleAffectorFactorX(),
|
||||
type->getScaleAffectorFactorY());
|
||||
scene::IParticleAffector* scale_affector =
|
||||
m_node->createScaleParticleAffector(factor);
|
||||
m_node->addAffector(scale_affector);
|
||||
scale_affector->drop();
|
||||
}
|
||||
}
|
||||
} // setParticleType
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
@@ -42,6 +41,7 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
|
||||
m_box_x = 0.5f;
|
||||
m_box_y = 0.5f;
|
||||
m_box_z = 0.5f;
|
||||
m_sphere_radius = 0.5f;
|
||||
m_angle_spread = 45;
|
||||
m_velocity_x = 0.001f;
|
||||
m_velocity_y = 0.001f;
|
||||
@@ -51,6 +51,9 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
|
||||
m_fade_away_end = -1.0f;
|
||||
m_force_lost_to_gravity_time = 1000;
|
||||
m_emission_decay_rate = 0;
|
||||
m_has_scale_affector = NULL;
|
||||
m_scale_affector_factor_x = 0.0f;
|
||||
m_scale_affector_factor_y = 0.0f;
|
||||
|
||||
|
||||
// ----- Read XML file
|
||||
@@ -87,6 +90,12 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
|
||||
xml->get("box_y", &m_box_y);
|
||||
xml->get("box_z", &m_box_z);
|
||||
}
|
||||
else if (emitterShape == "sphere")
|
||||
{
|
||||
m_shape = EMITTER_SPHERE;
|
||||
|
||||
xml->get("radius", &m_sphere_radius);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "[ParticleKind] <particles> main node has unknown value for attribute 'emitter'\n");
|
||||
@@ -154,6 +163,10 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
|
||||
size->get("min", &m_min_size);
|
||||
size->get("max", &m_max_size);
|
||||
}
|
||||
|
||||
bool has_x = size->get("x-increase-factor", &m_scale_affector_factor_x)==1;
|
||||
bool has_y = size->get("y-increase-factor", &m_scale_affector_factor_y)==1;
|
||||
m_has_scale_affector = (has_x || has_y);
|
||||
|
||||
//std::cout << "m_particle_size = " << m_particle_size << "\n";
|
||||
//std::cout << "m_min_size = " << m_min_size << "\n";
|
||||
|
||||
@@ -30,6 +30,7 @@ class Material;
|
||||
enum EmitterShape
|
||||
{
|
||||
EMITTER_POINT,
|
||||
EMITTER_SPHERE,
|
||||
EMITTER_BOX
|
||||
};
|
||||
|
||||
@@ -77,6 +78,9 @@ private:
|
||||
/** For box emitters only */
|
||||
float m_box_x, m_box_y, m_box_z;
|
||||
|
||||
/** For sphere emitters only */
|
||||
float m_sphere_radius;
|
||||
|
||||
/** Distance from camera at which particles start fading out, or negative if disabled */
|
||||
float m_fade_away_start, m_fade_away_end;
|
||||
|
||||
@@ -86,6 +90,10 @@ private:
|
||||
|
||||
std::string m_material_file;
|
||||
|
||||
bool m_has_scale_affector;
|
||||
float m_scale_affector_factor_x;
|
||||
float m_scale_affector_factor_y;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@@ -119,6 +127,8 @@ public:
|
||||
float getBoxSizeY () const { return m_box_y; }
|
||||
float getBoxSizeZ () const { return m_box_z; }
|
||||
|
||||
float getSphereRadius() const { return m_sphere_radius; }
|
||||
|
||||
int getAngleSpread () const { return m_angle_spread; }
|
||||
|
||||
float getVelocityX () const { return m_velocity_x; }
|
||||
@@ -138,6 +148,11 @@ public:
|
||||
|
||||
int getEmissionDecayRate() const { return m_emission_decay_rate; }
|
||||
|
||||
|
||||
bool hasScaleAffector() const { return m_has_scale_affector; }
|
||||
float getScaleAffectorFactorX() const { return m_scale_affector_factor_x; }
|
||||
float getScaleAffectorFactorY() const { return m_scale_affector_factor_y; };
|
||||
|
||||
std::string getName() const { return m_name; }
|
||||
};
|
||||
|
||||
|
||||
@@ -108,12 +108,12 @@ void SkidMarks::update(float dt, bool force_skid_marks,
|
||||
// If only one wheel touches the ground, the 2nd one gets the same
|
||||
// raycast result --> delta is 0, which is considered to be not skidding.
|
||||
const Skidding *skid = m_kart.getSkidding();
|
||||
bool is_skidding = force_skid_marks ||
|
||||
( (skid->getSkidState()==Skidding::SKID_ACCUMULATE_LEFT ||
|
||||
skid->getSkidState()==Skidding::SKID_ACCUMULATE_RIGHT )
|
||||
&& m_kart.getSkidding()->getGraphicalJumpOffset()<=0
|
||||
&& raycast_right.m_isInContact
|
||||
&& delta.length2()>=0.0001f );
|
||||
bool is_skidding = raycast_right.m_isInContact &&
|
||||
( force_skid_marks ||
|
||||
( (skid->getSkidState()==Skidding::SKID_ACCUMULATE_LEFT||
|
||||
skid->getSkidState()==Skidding::SKID_ACCUMULATE_RIGHT )
|
||||
&& skid->getGraphicalJumpOffset()<=0
|
||||
&& delta.length2()>=0.0001f ) );
|
||||
|
||||
if(m_skid_marking)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/abstract_top_level_container.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
|
||||
@@ -479,6 +479,13 @@ namespace GUIEngine
|
||||
Currently used for spinners only. Value can be "true" or "false"
|
||||
|
||||
|
||||
\n
|
||||
\subsection prop19 PROP_DIV_PADDING
|
||||
<em> Name in XML files: </em> \c "padding"
|
||||
|
||||
Used on divs, indicate by how many pixels to pad contents
|
||||
|
||||
|
||||
\n
|
||||
<HR>
|
||||
\section code Using the engine in code
|
||||
|
||||
@@ -615,7 +615,9 @@ EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int
|
||||
{
|
||||
if (w->m_deactivated) return EVENT_BLOCK;
|
||||
|
||||
if (ModalDialog::isADialogActive())
|
||||
Widget* parent = w->m_event_handler;
|
||||
|
||||
if (ModalDialog::isADialogActive() && (parent == NULL || parent->m_type != GUIEngine::WTYPE_RIBBON))
|
||||
{
|
||||
if (ModalDialog::getCurrent()->processEvent(w->m_properties[PROP_ID]) == EVENT_BLOCK)
|
||||
{
|
||||
@@ -626,7 +628,6 @@ EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int
|
||||
|
||||
//std::cout << "**** widget activated : " << w->m_properties[PROP_ID].c_str() << " ****" << std::endl;
|
||||
|
||||
Widget* parent = w->m_event_handler;
|
||||
if (w->m_event_handler != NULL)
|
||||
{
|
||||
/* Find all parents. Stop looping if a widget event handler's is itself, to not fall
|
||||
|
||||
@@ -308,7 +308,19 @@ void LayoutManager::applyCoords(Widget* self, AbstractTopLevelContainer* topLeve
|
||||
parent_x = parent->m_x;
|
||||
parent_y = parent->m_y;
|
||||
}
|
||||
|
||||
|
||||
if (parent != NULL && parent->getType() == WTYPE_DIV && parent->m_show_bounding_box)
|
||||
{
|
||||
int padding = 15;
|
||||
if (parent->m_properties[PROP_DIV_PADDING].length() > 0)
|
||||
padding = atoi(parent->m_properties[PROP_DIV_PADDING].c_str());
|
||||
|
||||
parent_x += padding;
|
||||
parent_y += padding;
|
||||
parent_w -= padding*2;
|
||||
parent_h -= padding*2;
|
||||
}
|
||||
|
||||
if (self->m_absolute_x > -1) self->m_x = parent_x + self->m_absolute_x;
|
||||
else if (self->m_absolute_reverse_x > -1) self->m_x = parent_x + (parent_w - self->m_absolute_reverse_x);
|
||||
else if (self->m_relative_x > -1) self->m_x = (int)(parent_x + parent_w*self->m_relative_x/100);
|
||||
@@ -418,8 +430,23 @@ void LayoutManager::doCalculateLayout(PtrVector<Widget>& widgets, AbstractTopLev
|
||||
break;
|
||||
}
|
||||
|
||||
const int w = parent->m_w, h = parent->m_h;
|
||||
int x = parent->m_x;
|
||||
int y = parent->m_y;
|
||||
int w = parent->m_w;
|
||||
int h = parent->m_h;
|
||||
|
||||
if (parent != NULL && parent->getType() == WTYPE_DIV && parent->m_show_bounding_box)
|
||||
{
|
||||
int padding = 15;
|
||||
if (parent->m_properties[PROP_DIV_PADDING].length() > 0)
|
||||
padding = atoi(parent->m_properties[PROP_DIV_PADDING].c_str());
|
||||
|
||||
x += padding;
|
||||
y += padding;
|
||||
w -= padding*2;
|
||||
h -= padding*2;
|
||||
}
|
||||
|
||||
// find space left after placing all absolutely-sized widgets in a row
|
||||
// (the space left will be divided between remaining widgets later)
|
||||
int left_space = (horizontal ? w : h);
|
||||
@@ -445,8 +472,6 @@ void LayoutManager::doCalculateLayout(PtrVector<Widget>& widgets, AbstractTopLev
|
||||
}
|
||||
|
||||
// ---- lay widgets in row
|
||||
int x = parent->m_x;
|
||||
int y = parent->m_y;
|
||||
for (int n=0; n<widgets_amount; n++)
|
||||
{
|
||||
std::string prop = widgets[n].m_properties[ PROP_PROPORTION ];
|
||||
@@ -694,7 +719,10 @@ void LayoutManager::doCalculateLayout(PtrVector<Widget>& widgets, AbstractTopLev
|
||||
// ----- also deal with containers' children
|
||||
for (int n=0; n<widgets_amount; n++)
|
||||
{
|
||||
if (widgets[n].m_type == WTYPE_DIV) doCalculateLayout(widgets[n].m_children, topLevelContainer, &widgets[n]);
|
||||
if (widgets[n].m_type == WTYPE_DIV)
|
||||
{
|
||||
doCalculateLayout(widgets[n].m_children, topLevelContainer, &widgets[n]);
|
||||
}
|
||||
}
|
||||
} // calculateLayout
|
||||
|
||||
|
||||
@@ -187,6 +187,9 @@ void ModalDialog::dismiss()
|
||||
{
|
||||
if(modalWindow != NULL) delete modalWindow;
|
||||
modalWindow = NULL;
|
||||
GUIEngine::Screen* scr = GUIEngine::getCurrentScreen();
|
||||
if (scr)
|
||||
scr->onDialogClose();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -302,6 +302,10 @@ namespace GUIEngine
|
||||
int axisDir,
|
||||
int value) {}
|
||||
|
||||
/** Callback that gets called when a dialog is closed.
|
||||
* Can be used to set focus for instance.
|
||||
*/
|
||||
virtual void onDialogClose() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -175,6 +175,10 @@ void Screen::parseScreenFileDiv(irr::io::IXMLReader* xml, PtrVector<Widget>& app
|
||||
{
|
||||
append_to.push_back(new TextBoxWidget());
|
||||
}
|
||||
else if (wcscmp(L"ratingbar", xml->getNodeName()) == 0)
|
||||
{
|
||||
append_to.push_back(new RatingBarWidget());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "/!\\ Warning /!\\ : unknown tag found in STK GUI file : '"
|
||||
@@ -216,6 +220,7 @@ if(prop_name != NULL) widget.m_properties[prop_flag] = core::stringc(prop_name).
|
||||
READ_PROPERTY(label_location, PROP_LABELS_LOCATION);
|
||||
READ_PROPERTY(max_rows, PROP_MAX_ROWS);
|
||||
READ_PROPERTY(wrap_around, PROP_WRAP_AROUND);
|
||||
READ_PROPERTY(padding, PROP_DIV_PADDING);
|
||||
#undef READ_PROPERTY
|
||||
|
||||
const wchar_t* text = xml->getAttributeValue( L"text" );
|
||||
|
||||
@@ -805,6 +805,60 @@ void Skin::drawProgress(Widget* w, const core::recti &rect,
|
||||
}
|
||||
} // drawProgress
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/**
|
||||
* @param focused whether this element is focus by the master player (focus
|
||||
* for other players is not supported)
|
||||
*/
|
||||
void Skin::drawRatingBar(Widget *w, const core::recti &rect,
|
||||
const bool pressed, const bool focused)
|
||||
{
|
||||
static const int step_number = 3; // Harcoded number of step.
|
||||
|
||||
const ITexture *texture = SkinConfig::m_render_params["rating::neutral"].getImage();
|
||||
const int texture_w = texture->getSize().Width / 4;
|
||||
const int texture_h = texture->getSize().Height;
|
||||
const float aspect_ratio = 1.0f;
|
||||
|
||||
RatingBarWidget *ratingBar = (RatingBarWidget*)w;
|
||||
const int star_number = ratingBar->getStarNumber();
|
||||
|
||||
int star_h = rect.getHeight();
|
||||
int star_w = (int)(aspect_ratio * star_h);
|
||||
|
||||
if (rect.getWidth() < star_w * star_number)
|
||||
{
|
||||
const float scale_factor = rect.getWidth() / (float)(star_w * star_number);
|
||||
star_w = (int)(star_w * scale_factor);
|
||||
star_h = (int)(star_h * scale_factor);
|
||||
}
|
||||
|
||||
// center horizontally and vertically
|
||||
const int x_from = rect.UpperLeftCorner.X + (rect.getWidth() - star_w) / 2;
|
||||
const int y_from = rect.UpperLeftCorner.Y + (rect.getHeight() - star_h) / 2;
|
||||
|
||||
for (int i = 0; i < star_number; i++)
|
||||
{
|
||||
core::recti star_rect = rect;
|
||||
|
||||
star_rect.UpperLeftCorner.X = x_from + i * star_w;
|
||||
star_rect.UpperLeftCorner.Y = y_from;
|
||||
star_rect.LowerRightCorner.X = x_from + (i + 1) * star_w;
|
||||
star_rect.LowerRightCorner.Y = y_from + star_h;
|
||||
|
||||
int step = ratingBar->getStepOfStar(i, step_number);
|
||||
|
||||
const core::recti source_area(texture_w * step, 0,
|
||||
texture_w * (step + 1), texture_h);
|
||||
|
||||
GUIEngine::getDriver()->draw2DImage(texture,
|
||||
star_rect, source_area,
|
||||
0 /* no clipping */, 0,
|
||||
true /* alpha */);
|
||||
}
|
||||
|
||||
} // drawRatingBar
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
SColor Skin::getColor(const std::string &name)
|
||||
{
|
||||
@@ -1467,9 +1521,9 @@ void Skin::drawCheckBox(const core::recti &rect, Widget* widget, bool focused)
|
||||
*/
|
||||
void Skin::drawList(const core::recti &rect, Widget* widget, bool focused)
|
||||
{
|
||||
drawBoxFromStretchableTexture(widget, rect,
|
||||
SkinConfig::m_render_params["list::neutral"],
|
||||
widget->m_deactivated, NULL);
|
||||
//drawBoxFromStretchableTexture(widget, rect,
|
||||
// SkinConfig::m_render_params["list::neutral"],
|
||||
// widget->m_deactivated, NULL);
|
||||
|
||||
} // drawList
|
||||
|
||||
@@ -1556,6 +1610,8 @@ void Skin::renderSections(PtrVector<Widget>* within_vector)
|
||||
drawBoxFromStretchableTexture(&widget, rect,
|
||||
SkinConfig::m_render_params["section::neutral"]);
|
||||
}
|
||||
|
||||
renderSections( &widget.m_children );
|
||||
}
|
||||
else if (widget.isBottomBar())
|
||||
{
|
||||
@@ -1810,6 +1866,10 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect,
|
||||
{
|
||||
drawCheckBox(rect, widget, focused);
|
||||
}
|
||||
else if(type == WTYPE_RATINGBAR)
|
||||
{
|
||||
drawRatingBar(widget, rect, pressed, focused);
|
||||
}
|
||||
|
||||
|
||||
if (ID_DEBUG && id != -1 && Widget::isFocusableId(id))
|
||||
@@ -1954,70 +2014,41 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor,
|
||||
|
||||
if (element->getType()==gui::EGUIET_EDIT_BOX)
|
||||
{
|
||||
SColor& color = SkinConfig::m_colors["text_field::neutral"];
|
||||
SColor& colorFocus = SkinConfig::m_colors["text_field::focused"];
|
||||
SColor& bg_color = SkinConfig::m_colors["text_field::background"];
|
||||
SColor& bg_color_focused = SkinConfig::m_colors["text_field::background_focused"];
|
||||
SColor& border_color = SkinConfig::m_colors["text_field::neutral"];
|
||||
SColor& border_color_focus = SkinConfig::m_colors["text_field::focused"];
|
||||
|
||||
if (focused)
|
||||
core::recti borderArea = rect;
|
||||
borderArea.UpperLeftCorner -= position2d< s32 >( 2, 2 );
|
||||
borderArea.LowerRightCorner += position2d< s32 >( 2, 2 );
|
||||
|
||||
// if within an appearing dialog, grow
|
||||
if (m_dialog && m_dialog_size < 1.0f && widget->m_parent != NULL &&
|
||||
widget->m_parent->getType() == gui::EGUIET_WINDOW)
|
||||
{
|
||||
core::recti borderArea = rect;
|
||||
borderArea.UpperLeftCorner -= position2d< s32 >( 2, 2 );
|
||||
borderArea.LowerRightCorner += position2d< s32 >( 2, 2 );
|
||||
core::position2d<u32> center(irr_driver->getFrameSize()/2);
|
||||
const float texture_size = sin(m_dialog_size*M_PI*0.5f);
|
||||
|
||||
// if within an appearing dialog, grow
|
||||
if (m_dialog && m_dialog_size < 1.0f && widget->m_parent != NULL &&
|
||||
widget->m_parent->getType() == gui::EGUIET_WINDOW)
|
||||
{
|
||||
core::position2d<u32> center(irr_driver->getFrameSize()/2);
|
||||
const float texture_size = sin(m_dialog_size*M_PI*0.5f);
|
||||
|
||||
borderArea.UpperLeftCorner.X =
|
||||
center.X + (int)(((int)rect.UpperLeftCorner.X
|
||||
- (int)center.X)*texture_size);
|
||||
borderArea.UpperLeftCorner.Y =
|
||||
center.Y + (int)(((int)rect.UpperLeftCorner.Y
|
||||
- (int)center.Y)*texture_size);
|
||||
borderArea.LowerRightCorner.X =
|
||||
center.X + (int)(((int)rect.LowerRightCorner.X
|
||||
- (int)center.X)*texture_size);
|
||||
borderArea.LowerRightCorner.Y =
|
||||
center.Y + (int)(((int)rect.LowerRightCorner.Y
|
||||
- (int)center.Y)*texture_size);
|
||||
}
|
||||
GUIEngine::getDriver()->draw2DRectangle( colorFocus, borderArea );
|
||||
|
||||
core::recti innerArea = borderArea;
|
||||
innerArea.UpperLeftCorner += position2d< s32 >( 2, 2 );
|
||||
innerArea.LowerRightCorner -= position2d< s32 >( 2, 2 );
|
||||
GUIEngine::getDriver()->draw2DRectangle( color, innerArea );
|
||||
}
|
||||
else
|
||||
{
|
||||
// if within an appearing dialog, grow
|
||||
if (m_dialog && m_dialog_size < 1.0f && widget->m_parent != NULL &&
|
||||
widget->m_parent->getType() == gui::EGUIET_WINDOW)
|
||||
{
|
||||
core::position2d<u32> center(irr_driver->getFrameSize()/2);
|
||||
const float texture_size = sin(m_dialog_size*M_PI*0.5f);
|
||||
core::recti sizedRect;
|
||||
sizedRect.UpperLeftCorner.X =
|
||||
center.X + (int)(((int)rect.UpperLeftCorner.X
|
||||
- (int)center.X)*texture_size);
|
||||
sizedRect.UpperLeftCorner.Y =
|
||||
center.Y + (int)(((int)rect.UpperLeftCorner.Y
|
||||
- (int)center.Y)*texture_size);
|
||||
sizedRect.LowerRightCorner.X =
|
||||
center.X + (int)(((int)rect.LowerRightCorner.X
|
||||
- (int)center.X)*texture_size);
|
||||
sizedRect.LowerRightCorner.Y =
|
||||
center.Y + (int)(((int)rect.LowerRightCorner.Y
|
||||
- (int)center.Y)*texture_size);
|
||||
GUIEngine::getDriver()->draw2DRectangle( color, sizedRect );
|
||||
}
|
||||
else
|
||||
{
|
||||
GUIEngine::getDriver()->draw2DRectangle( color, rect );
|
||||
}
|
||||
borderArea.UpperLeftCorner.X =
|
||||
center.X + (int)(((int)rect.UpperLeftCorner.X
|
||||
- (int)center.X)*texture_size);
|
||||
borderArea.UpperLeftCorner.Y =
|
||||
center.Y + (int)(((int)rect.UpperLeftCorner.Y
|
||||
- (int)center.Y)*texture_size);
|
||||
borderArea.LowerRightCorner.X =
|
||||
center.X + (int)(((int)rect.LowerRightCorner.X
|
||||
- (int)center.X)*texture_size);
|
||||
borderArea.LowerRightCorner.Y =
|
||||
center.Y + (int)(((int)rect.LowerRightCorner.Y
|
||||
- (int)center.Y)*texture_size);
|
||||
}
|
||||
GUIEngine::getDriver()->draw2DRectangle(focused ? border_color_focus : border_color, borderArea);
|
||||
|
||||
core::recti innerArea = borderArea;
|
||||
innerArea.UpperLeftCorner += position2d< s32 >( 2, 2 );
|
||||
innerArea.LowerRightCorner -= position2d< s32 >( 2, 2 );
|
||||
GUIEngine::getDriver()->draw2DRectangle(focused ? bg_color_focused : bg_color, innerArea);
|
||||
return;
|
||||
}
|
||||
else if (type == WTYPE_LIST)
|
||||
|
||||
@@ -293,6 +293,8 @@ namespace GUIEngine
|
||||
const bool pressed, const bool focused);
|
||||
void drawProgress(Widget* w, const core::rect< s32 > &rect,
|
||||
const bool pressed, const bool focused);
|
||||
void drawRatingBar(Widget* w, const core::rect< s32 > &rect,
|
||||
const bool pressed, const bool focused);
|
||||
void drawRibbon(const core::rect< s32 > &rect, Widget* widget,
|
||||
const bool pressed, bool focused);
|
||||
void drawRibbonChild(const core::rect< s32 > &rect, Widget* widget,
|
||||
|
||||
@@ -28,7 +28,6 @@ using namespace video;
|
||||
using namespace io;
|
||||
using namespace gui;
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
@@ -99,6 +98,7 @@ Widget::Widget(WidgetType type, bool reserve_id)
|
||||
|
||||
m_reserved_id = -1;
|
||||
m_deactivated = false;
|
||||
m_is_visible = true;
|
||||
m_badges = 0;
|
||||
|
||||
// set a default value, derivates can override this as they wish
|
||||
@@ -320,7 +320,9 @@ void Widget::setParent(IGUIElement* parent)
|
||||
|
||||
bool Widget::isVisible() const
|
||||
{
|
||||
return m_element && m_element->isVisible();
|
||||
if (m_element != NULL)
|
||||
assert(m_element->isVisible() == m_is_visible);
|
||||
return m_is_visible;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -331,6 +333,7 @@ void Widget::setVisible(bool visible)
|
||||
{
|
||||
m_element->setVisible(visible);
|
||||
}
|
||||
m_is_visible = visible;
|
||||
m_deactivated = !visible;
|
||||
|
||||
const int childrenCount = m_children.size();
|
||||
|
||||
@@ -52,7 +52,8 @@ namespace GUIEngine
|
||||
WTYPE_MODEL_VIEW,
|
||||
WTYPE_LIST,
|
||||
WTYPE_TEXTBOX,
|
||||
WTYPE_PROGRESS
|
||||
WTYPE_PROGRESS,
|
||||
WTYPE_RATINGBAR
|
||||
};
|
||||
|
||||
enum BadgeType
|
||||
@@ -100,7 +101,8 @@ namespace GUIEngine
|
||||
PROP_EXTEND_LABEL,
|
||||
PROP_LABELS_LOCATION,
|
||||
PROP_MAX_ROWS,
|
||||
PROP_WRAP_AROUND
|
||||
PROP_WRAP_AROUND,
|
||||
PROP_DIV_PADDING
|
||||
};
|
||||
|
||||
bool isWithinATextBox();
|
||||
@@ -232,9 +234,12 @@ namespace GUIEngine
|
||||
/** A bitmask of which badges to show, if any; choices are *_BADGE, defined above */
|
||||
int m_badges;
|
||||
|
||||
/** A simple flag that can be raised to hide this widget */
|
||||
/** A simple flag that can be raised to deactivate this widget */
|
||||
bool m_deactivated;
|
||||
|
||||
/** A flag to indicate whether this widget should be visible or not. */
|
||||
bool m_is_visible;
|
||||
|
||||
/** Set to false if widget is something that should not receive focus */
|
||||
bool m_focusable;
|
||||
|
||||
|
||||
@@ -13,3 +13,4 @@
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/check_box_widget.hpp"
|
||||
#include "guiengine/widgets/rating_bar_widget.hpp"
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/widgets/dynamic_ribbon_widget.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
|
||||
@@ -185,3 +185,13 @@ void LabelWidget::setScrollSpeed(float speed)
|
||||
m_scroll_speed = speed;
|
||||
} // setScrollSpeed
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void LabelWidget::setColor(const irr::video::SColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
m_has_color = true;
|
||||
if (m_element != NULL)
|
||||
((IGUIStaticText*)m_element)->setOverrideColor(m_color);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,7 @@ namespace GUIEngine
|
||||
|
||||
/** Sets the color of the widget.
|
||||
* \param color The color to use for this widget. */
|
||||
void setColor(const irr::video::SColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
m_has_color = true;
|
||||
} // setColor
|
||||
void setColor(const irr::video::SColor& color);
|
||||
|
||||
/** \brief Callback from base class Widget */
|
||||
virtual void update(float dt);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/CGUISpriteBank.h"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/widgets/model_view_widget.hpp"
|
||||
using namespace GUIEngine;
|
||||
|
||||
85
src/guiengine/widgets/rating_bar_widget.cpp
Normal file
85
src/guiengine/widgets/rating_bar_widget.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009 Marianne Gagnon
|
||||
//
|
||||
// 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 "guiengine/engine.hpp"
|
||||
#include "guiengine/widgets/rating_bar_widget.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include <string.h>
|
||||
|
||||
#include <IGUIEnvironment.h>
|
||||
#include <IGUIElement.h>
|
||||
#include <IGUIButton.h>
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr::core;
|
||||
using namespace irr;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
RatingBarWidget::RatingBarWidget() : Widget(WTYPE_RATINGBAR)
|
||||
{
|
||||
m_rating = 0;
|
||||
m_star_number = 0;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void RatingBarWidget::add()
|
||||
{
|
||||
rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
|
||||
m_element = GUIEngine::getGUIEnv()->addButton(widget_size, m_parent, getNewNoFocusID(), NULL, L"");
|
||||
|
||||
m_id = m_element->getID();
|
||||
m_element->setTabStop(false);
|
||||
m_element->setTabGroup(false);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Get the current step of the star
|
||||
*
|
||||
* \param index The index of the star.
|
||||
* \param max_step The number of different steps that a star can display. Two
|
||||
* step are obligatory: full and empty.
|
||||
* \return The current step of the star.
|
||||
*/
|
||||
int RatingBarWidget::getStepOfStar(int index, int max_step)
|
||||
{
|
||||
assert(index >= 0 && index < m_star_number); // Index must be between 0 and m_star_number - 1.
|
||||
assert(max_step >= 2); // The maximun number of step must be superior or equals to 2.
|
||||
|
||||
if (m_rating < index)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_rating > index + 1)
|
||||
{
|
||||
return max_step - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
float step_size = 1 / (float)(max_step - 1);
|
||||
|
||||
for (int i = 0; i < max_step; i++)
|
||||
{
|
||||
if (m_rating > index + step_size * (i - 0.5)
|
||||
&& m_rating < index + step_size * (i + 0.5))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
// TODO: Assert or throws a exception, what type?
|
||||
} // getStepOfStar
|
||||
|
||||
66
src/guiengine/widgets/rating_bar_widget.hpp
Normal file
66
src/guiengine/widgets/rating_bar_widget.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009 Marianne Gagnon
|
||||
//
|
||||
// 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_RATING_BAR_HPP
|
||||
#define HEADER_RATING_BAR_HPP
|
||||
|
||||
#include <irrString.h>
|
||||
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "utils/leak_check.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
/**
|
||||
* \brief A rating bar widget.
|
||||
* \ingroup widgetsgroup
|
||||
*/
|
||||
class RatingBarWidget : public Widget
|
||||
{
|
||||
|
||||
float m_rating;
|
||||
int m_star_number;
|
||||
|
||||
public:
|
||||
|
||||
LEAK_CHECK()
|
||||
|
||||
RatingBarWidget();
|
||||
virtual ~RatingBarWidget() {}
|
||||
|
||||
void add();
|
||||
|
||||
/** Change the rating value of the widget. */
|
||||
void setRating(float rating) { m_rating = rating; };
|
||||
|
||||
/** Get the current value of the widget. */
|
||||
float getRating() {return m_rating; };
|
||||
|
||||
/** Change the number of star of the widget. */
|
||||
void setStarNumber(int star_number) { m_star_number = star_number; };
|
||||
|
||||
/** Get the current number of star of the widget. */
|
||||
int getStarNumber() {return m_star_number; };
|
||||
|
||||
int getStepOfStar(int index, int max_step);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -64,6 +64,13 @@ RibbonWidget::RibbonWidget(const RibbonType type) : Widget(WTYPE_RIBBON)
|
||||
updateSelection();
|
||||
} // RibbonWidget
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
RibbonWidget::~RibbonWidget()
|
||||
{
|
||||
m_active_children.clearWithoutDeleting();
|
||||
} // ~RibbonWidget
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void RibbonWidget::add()
|
||||
{
|
||||
@@ -84,7 +91,15 @@ void RibbonWidget::add()
|
||||
m_parent, id, L"");
|
||||
m_element = btn;
|
||||
|
||||
const int subbuttons_amount = m_children.size();
|
||||
m_active_children.clearWithoutDeleting(); // Is just a copy of m_children without the deactivated children. m_children takes care of memory.
|
||||
for (int i=0; i<m_children.size(); i++)
|
||||
{
|
||||
if (m_children[i].isVisible())
|
||||
{
|
||||
m_active_children.push_back(m_children.get(i));
|
||||
}
|
||||
}
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
// For some ribbon types, we can have unequal sizes depending on whether
|
||||
// items have labels or not
|
||||
@@ -97,11 +112,11 @@ void RibbonWidget::add()
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
// FIXME: why do I manually invoke the Layout Manager here?
|
||||
LayoutManager::readCoords(m_children.get(i));
|
||||
LayoutManager::applyCoords(m_children.get(i), NULL, this);
|
||||
LayoutManager::readCoords(m_active_children.get(i));
|
||||
LayoutManager::applyCoords(m_active_children.get(i), NULL, this);
|
||||
|
||||
if (m_children[i].m_type != WTYPE_ICON_BUTTON &&
|
||||
m_children[i].m_type != WTYPE_BUTTON)
|
||||
if (m_active_children[i].m_type != WTYPE_ICON_BUTTON &&
|
||||
m_active_children[i].m_type != WTYPE_BUTTON)
|
||||
{
|
||||
fprintf(stderr, "/!\\ Warning /!\\ : ribbon widgets can only have "
|
||||
"(icon)button widgets as children\n");
|
||||
@@ -110,15 +125,15 @@ void RibbonWidget::add()
|
||||
|
||||
// ribbon children must not be keyboard navigatable, the parent
|
||||
// ribbon takes care of that
|
||||
if (m_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
if (m_active_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
IconButtonWidget* icon = ((IconButtonWidget*)m_children.get(i));
|
||||
IconButtonWidget* icon = ((IconButtonWidget*)m_active_children.get(i));
|
||||
icon->m_tab_stop = false;
|
||||
}
|
||||
|
||||
|
||||
bool has_label_underneath = m_children[i].m_text.size() > 0;
|
||||
if (m_children[i].m_properties[PROP_LABELS_LOCATION].size() > 0)
|
||||
bool has_label_underneath = m_active_children[i].m_text.size() > 0;
|
||||
if (m_active_children[i].m_properties[PROP_LABELS_LOCATION].size() > 0)
|
||||
{
|
||||
has_label_underneath = false;
|
||||
}
|
||||
@@ -126,7 +141,7 @@ void RibbonWidget::add()
|
||||
if (has_label_underneath) with_label++;
|
||||
else without_label++;
|
||||
|
||||
total_needed_space += m_children[i].m_w;
|
||||
total_needed_space += m_active_children[i].m_w;
|
||||
}
|
||||
|
||||
int free_w_space = m_w - total_needed_space;
|
||||
@@ -155,7 +170,7 @@ void RibbonWidget::add()
|
||||
/ (with_label + without_label/2.0f));
|
||||
const int small_tab = large_tab/2;
|
||||
|
||||
stringw& message = m_children[i].m_text;
|
||||
stringw& message = m_active_children[i].m_text;
|
||||
|
||||
|
||||
if (message.size() == 0)
|
||||
@@ -179,7 +194,7 @@ void RibbonWidget::add()
|
||||
widget_x + small_tab/2-2, m_h);
|
||||
}
|
||||
|
||||
if (m_children[i].m_type == WTYPE_BUTTON)
|
||||
if (m_active_children[i].m_type == WTYPE_BUTTON)
|
||||
{
|
||||
subbtn = GUIEngine::getGUIEnv()
|
||||
->addButton(subsize, btn, getNewNoFocusID(),
|
||||
@@ -197,7 +212,7 @@ void RibbonWidget::add()
|
||||
subbtn->setOverrideFont(GUIEngine::getSmallFont());
|
||||
}
|
||||
}
|
||||
else if (m_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
else if (m_active_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
rect<s32> icon_part = rect<s32>(15,
|
||||
0,
|
||||
@@ -232,7 +247,7 @@ void RibbonWidget::add()
|
||||
same_id, L"");
|
||||
icon->setScaleImage(true);
|
||||
std::string filename = file_manager->getDataDir()
|
||||
+ m_children[i].m_properties[PROP_ICON];
|
||||
+ m_active_children[i].m_properties[PROP_ICON];
|
||||
icon->setImage( irr_driver->getTexture(filename.c_str()) );
|
||||
icon->setUseAlphaChannel(true);
|
||||
icon->setDrawBorder(false);
|
||||
@@ -267,21 +282,21 @@ void RibbonWidget::add()
|
||||
fprintf(stderr, "Invalid tab bar contents\n");
|
||||
}
|
||||
|
||||
m_children[i].m_element = subbtn;
|
||||
m_active_children[i].m_element = subbtn;
|
||||
|
||||
if (message.size() == 0) widget_x += small_tab/2;
|
||||
else widget_x += large_tab/2;
|
||||
}
|
||||
// ---- icon ribbons
|
||||
else if (m_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
else if (m_active_children[i].m_type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
if (widget_x == -1) widget_x = one_button_space/2;
|
||||
|
||||
// find how much space to keep for the label under the button.
|
||||
// consider font size, whether the label is multiline, etc...
|
||||
bool has_label = m_children[i].m_text.size() > 0;
|
||||
bool has_label = m_active_children[i].m_text.size() > 0;
|
||||
|
||||
if (m_children[i].m_properties[PROP_LABELS_LOCATION].size() > 0)
|
||||
if (m_active_children[i].m_properties[PROP_LABELS_LOCATION].size() > 0)
|
||||
{
|
||||
has_label = false;
|
||||
}
|
||||
@@ -291,11 +306,11 @@ void RibbonWidget::add()
|
||||
: 10;
|
||||
|
||||
float imageRatio =
|
||||
(float)m_children[i].m_w / (float)m_children[i].m_h;
|
||||
(float)m_active_children[i].m_w / (float)m_active_children[i].m_h;
|
||||
|
||||
// calculate the size of the image
|
||||
std::string filename = file_manager->getDataDir()
|
||||
+ m_children[i].m_properties[PROP_ICON];
|
||||
+ m_active_children[i].m_properties[PROP_ICON];
|
||||
video::ITexture* image =
|
||||
irr_driver->getTexture((filename).c_str());
|
||||
float image_h = (float)image->getSize().Height;
|
||||
@@ -320,17 +335,17 @@ void RibbonWidget::add()
|
||||
// ---- add bitmap button part
|
||||
// backup and restore position in case the same object is added
|
||||
// multiple times (FIXME: unclean)
|
||||
int old_x = m_children[i].m_x;
|
||||
int old_y = m_children[i].m_y;
|
||||
int old_w = m_children[i].m_w;
|
||||
int old_h = m_children[i].m_h;
|
||||
int old_x = m_active_children[i].m_x;
|
||||
int old_y = m_active_children[i].m_y;
|
||||
int old_w = m_active_children[i].m_w;
|
||||
int old_h = m_active_children[i].m_h;
|
||||
|
||||
m_children[i].m_x = widget_x - (int)(image_w*zoom/2.0f);
|
||||
m_children[i].m_y = button_y;
|
||||
m_children[i].m_w = (int)(image_w*zoom);
|
||||
m_children[i].m_h = (int)(image_h*zoom);
|
||||
m_active_children[i].m_x = widget_x - (int)(image_w*zoom/2.0f);
|
||||
m_active_children[i].m_y = button_y;
|
||||
m_active_children[i].m_w = (int)(image_w*zoom);
|
||||
m_active_children[i].m_h = (int)(image_h*zoom);
|
||||
|
||||
IconButtonWidget* icon = ((IconButtonWidget*)m_children.get(i));
|
||||
IconButtonWidget* icon = ((IconButtonWidget*)m_active_children.get(i));
|
||||
|
||||
if (icon->m_properties[PROP_EXTEND_LABEL].size() == 0)
|
||||
{
|
||||
@@ -338,14 +353,14 @@ void RibbonWidget::add()
|
||||
StringUtils::toString(one_button_space - icon->m_w);
|
||||
}
|
||||
|
||||
m_children.get(i)->m_parent = btn;
|
||||
m_children.get(i)->add();
|
||||
m_active_children.get(i)->m_parent = btn;
|
||||
m_active_children.get(i)->add();
|
||||
|
||||
// restore backuped size and location (see above for more info)
|
||||
m_children[i].m_x = old_x;
|
||||
m_children[i].m_y = old_y;
|
||||
m_children[i].m_w = old_w;
|
||||
m_children[i].m_h = old_h;
|
||||
m_active_children[i].m_x = old_x;
|
||||
m_active_children[i].m_y = old_y;
|
||||
m_active_children[i].m_w = old_w;
|
||||
m_active_children[i].m_h = old_h;
|
||||
|
||||
// the label itself will be added by the icon widget. since it
|
||||
// adds the label outside of the widget area it is assigned to,
|
||||
@@ -361,7 +376,7 @@ void RibbonWidget::add()
|
||||
|
||||
|
||||
//m_children[i].id = subbtn->getID();
|
||||
m_children[i].m_event_handler = this;
|
||||
m_active_children[i].m_event_handler = this;
|
||||
}// next sub-button
|
||||
|
||||
id = m_element->getID();
|
||||
@@ -439,11 +454,11 @@ void RibbonWidget::removeChildNamed(const char* name)
|
||||
|
||||
void RibbonWidget::select(std::string item, const int mousePlayerID)
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
if (m_children[i].m_properties[PROP_ID] == item)
|
||||
if (m_active_children[i].m_properties[PROP_ID] == item)
|
||||
{
|
||||
m_selection[mousePlayerID] = i;
|
||||
updateSelection();
|
||||
@@ -458,15 +473,15 @@ EventPropagation RibbonWidget::rightPressed(const int playerID)
|
||||
{
|
||||
if (m_deactivated) return EVENT_LET;
|
||||
// empty ribbon, or only one item (can't move right)
|
||||
if (m_children.size() < 2) return EVENT_LET;
|
||||
if (m_active_children.size() < 2) return EVENT_LET;
|
||||
|
||||
m_selection[playerID]++;
|
||||
|
||||
if (m_selection[playerID] >= m_children.size())
|
||||
if (m_selection[playerID] >= m_active_children.size())
|
||||
{
|
||||
if (m_listener != NULL) m_listener->onRibbonWidgetScroll(1);
|
||||
|
||||
m_selection[playerID] = m_event_handler ? m_children.size()-1 : 0;
|
||||
m_selection[playerID] = m_event_handler ? m_active_children.size()-1 : 0;
|
||||
}
|
||||
updateSelection();
|
||||
|
||||
@@ -475,14 +490,14 @@ EventPropagation RibbonWidget::rightPressed(const int playerID)
|
||||
const int mousePlayerID = input_manager->getPlayerKeyboardID();
|
||||
if (playerID == mousePlayerID || playerID == PLAYER_ID_GAME_MASTER)
|
||||
{
|
||||
m_mouse_focus = m_children.get(m_selection[playerID]);
|
||||
m_mouse_focus = m_active_children.get(m_selection[playerID]);
|
||||
}
|
||||
}
|
||||
|
||||
// if we reached a filler item, move again (but don't wrap)
|
||||
if (getSelectionIDString(playerID) == RibbonWidget::NO_ITEM_ID)
|
||||
{
|
||||
if (m_selection[playerID] + 1 < m_children.size())
|
||||
if (m_selection[playerID] + 1 < m_active_children.size())
|
||||
{
|
||||
rightPressed(playerID);
|
||||
}
|
||||
@@ -496,7 +511,7 @@ EventPropagation RibbonWidget::leftPressed(const int playerID)
|
||||
{
|
||||
if (m_deactivated) return EVENT_LET;
|
||||
// empty ribbon, or only one item (can't move left)
|
||||
if (m_children.size() < 2) return EVENT_LET;
|
||||
if (m_active_children.size() < 2) return EVENT_LET;
|
||||
|
||||
m_selection[playerID]--;
|
||||
if (m_selection[playerID] < 0)
|
||||
@@ -505,7 +520,7 @@ EventPropagation RibbonWidget::leftPressed(const int playerID)
|
||||
|
||||
m_selection[playerID] = m_event_handler
|
||||
? 0
|
||||
: m_children.size()-1;
|
||||
: m_active_children.size()-1;
|
||||
}
|
||||
|
||||
updateSelection();
|
||||
@@ -515,7 +530,7 @@ EventPropagation RibbonWidget::leftPressed(const int playerID)
|
||||
const int mousePlayerID = input_manager->getPlayerKeyboardID();
|
||||
if (playerID == mousePlayerID || playerID == PLAYER_ID_GAME_MASTER)
|
||||
{
|
||||
m_mouse_focus = m_children.get(m_selection[playerID]);
|
||||
m_mouse_focus = m_active_children.get(m_selection[playerID]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,7 +557,7 @@ EventPropagation RibbonWidget::focused(const int playerID)
|
||||
{
|
||||
Widget::focused(playerID);
|
||||
|
||||
if (m_children.size() < 1) return EVENT_LET; // empty ribbon
|
||||
if (m_active_children.size() < 1) return EVENT_LET; // empty ribbon
|
||||
|
||||
if (m_ribbon_type == RIBBON_COMBO || m_ribbon_type == RIBBON_TABS)
|
||||
{
|
||||
@@ -550,7 +565,7 @@ EventPropagation RibbonWidget::focused(const int playerID)
|
||||
if (m_mouse_focus == NULL && m_selection[playerID] != -1 &&
|
||||
(playerID == mousePlayerID || playerID == PLAYER_ID_GAME_MASTER))
|
||||
{
|
||||
m_mouse_focus = m_children.get(m_selection[playerID]);
|
||||
m_mouse_focus = m_active_children.get(m_selection[playerID]);
|
||||
m_mouse_focus->focused(playerID);
|
||||
}
|
||||
}
|
||||
@@ -558,7 +573,7 @@ EventPropagation RibbonWidget::focused(const int playerID)
|
||||
{
|
||||
if (m_selection[playerID] != -1)
|
||||
{
|
||||
m_children.get(m_selection[playerID])->focused(playerID);
|
||||
m_active_children.get(m_selection[playerID])->focused(playerID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,11 +587,11 @@ EventPropagation RibbonWidget::focused(const int playerID)
|
||||
|
||||
void RibbonWidget::unfocused(const int playerID, Widget* new_focus)
|
||||
{
|
||||
if (new_focus != NULL && new_focus != this && !m_children.contains(new_focus))
|
||||
if (new_focus != NULL && new_focus != this && !m_active_children.contains(new_focus))
|
||||
{
|
||||
if (m_selection[playerID] != -1)
|
||||
{
|
||||
m_children.get(m_selection[playerID])->unfocused(playerID, new_focus);
|
||||
m_active_children.get(m_selection[playerID])->unfocused(playerID, new_focus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +604,7 @@ EventPropagation RibbonWidget::mouseHovered(Widget* child,
|
||||
{
|
||||
if (m_deactivated) return EVENT_LET;
|
||||
|
||||
const int subbuttons_amount = m_children.size();
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
if (m_ribbon_type == RIBBON_COMBO || m_ribbon_type == RIBBON_TABS)
|
||||
{
|
||||
@@ -602,7 +617,7 @@ EventPropagation RibbonWidget::mouseHovered(Widget* child,
|
||||
{
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
if (m_children.get(i) == child)
|
||||
if (m_active_children.get(i) == child)
|
||||
{
|
||||
// Was already selected, don't send another event
|
||||
if (m_selection[mousePlayerID] == i) return EVENT_BLOCK;
|
||||
@@ -623,21 +638,21 @@ const std::string& RibbonWidget::getSelectionIDString(const int playerID)
|
||||
{
|
||||
static std::string empty;
|
||||
if (m_selection[playerID] == -1) return empty;
|
||||
if (m_children.size() == 0) return empty;
|
||||
if (m_active_children.size() == 0) return empty;
|
||||
|
||||
// This can happen if an addon is removed, which causes a tab group
|
||||
// to be removed. If this tab group was previously selected, an
|
||||
// invalid array element would be accessed. In this case just pretend
|
||||
// that the first child was selected previously.
|
||||
if(m_selection[playerID]>=m_children.size())
|
||||
return m_children[0].m_properties[PROP_ID];
|
||||
return m_children[m_selection[playerID]].m_properties[PROP_ID];
|
||||
if(m_selection[playerID]>=m_active_children.size())
|
||||
return m_active_children[0].m_properties[PROP_ID];
|
||||
return m_active_children[m_selection[playerID]].m_properties[PROP_ID];
|
||||
} // getSelectionIDString
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void RibbonWidget::updateSelection()
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
// FIXME: m_selection, m_selected, m_mouse_focus... what a mess...
|
||||
|
||||
@@ -648,12 +663,12 @@ void RibbonWidget::updateSelection()
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
bool new_val = (i == m_selection[p]);
|
||||
if (!new_val && m_children[i].m_selected[p])
|
||||
if (!new_val && m_active_children[i].m_selected[p])
|
||||
{
|
||||
m_children[i].unfocused(PLAYER_ID_GAME_MASTER, NULL);
|
||||
m_active_children[i].unfocused(PLAYER_ID_GAME_MASTER, NULL);
|
||||
}
|
||||
m_children[i].m_selected[p] = new_val;
|
||||
if (new_val) m_children[i].focused(PLAYER_ID_GAME_MASTER);
|
||||
m_active_children[i].m_selected[p] = new_val;
|
||||
if (new_val) m_active_children[i].focused(PLAYER_ID_GAME_MASTER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,11 +685,11 @@ EventPropagation RibbonWidget::transmitEvent(Widget* w,
|
||||
|
||||
if (!m_deactivated)
|
||||
{
|
||||
const int subbuttons_amount = m_children.size();
|
||||
const int subbuttons_amount = m_active_children.size();
|
||||
|
||||
for (int i=0; i<subbuttons_amount; i++)
|
||||
{
|
||||
if (m_children[i].m_properties[PROP_ID] == originator)
|
||||
if (m_active_children[i].m_properties[PROP_ID] == originator)
|
||||
{
|
||||
m_selection[playerID] = i;
|
||||
break;
|
||||
@@ -689,10 +704,10 @@ EventPropagation RibbonWidget::transmitEvent(Widget* w,
|
||||
|
||||
if (m_selection[playerID] != -1)
|
||||
{
|
||||
if (m_children[m_selection[playerID]].m_deactivated)
|
||||
if (m_active_children[m_selection[playerID]].m_deactivated)
|
||||
{
|
||||
GUIEngine::getCurrentScreen()->onDisabledItemClicked(
|
||||
m_children[m_selection[playerID]].m_properties[PROP_ID]);
|
||||
m_active_children[m_selection[playerID]].m_properties[PROP_ID]);
|
||||
|
||||
return EVENT_BLOCK;
|
||||
}
|
||||
@@ -731,3 +746,12 @@ int RibbonWidget::findItemNamed(const char* internalName)
|
||||
}
|
||||
return -1;
|
||||
} // findItemNamed
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
Widget* RibbonWidget::findWidgetNamed(const char* internalName)
|
||||
{
|
||||
int id = findItemNamed(internalName);
|
||||
if (id >= 0)
|
||||
return m_children.get(id);
|
||||
return NULL;
|
||||
} // findItemNamed
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace GUIEngine
|
||||
PtrVector<irr::gui::IGUIStaticText, REF> m_labels;
|
||||
|
||||
IRibbonListener* m_listener;
|
||||
|
||||
PtrVector<Widget> m_active_children;
|
||||
|
||||
public:
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace GUIEngine
|
||||
Widget* m_mouse_focus;
|
||||
|
||||
RibbonWidget(const RibbonType type=RIBBON_COMBO);
|
||||
virtual ~RibbonWidget() {}
|
||||
virtual ~RibbonWidget();
|
||||
|
||||
void add();
|
||||
|
||||
@@ -155,6 +155,9 @@ namespace GUIEngine
|
||||
/** Returns the ID of the item, or -1 if not found */
|
||||
int findItemNamed(const char* internalName);
|
||||
|
||||
/** Returns the the widget, or NULL if not found */
|
||||
GUIEngine::Widget * findWidgetNamed(const char* interalName);
|
||||
|
||||
/** \brief Dynamically (at runtime) add a text item to this ribbon
|
||||
* \pre This must be called before RibbonWidget::add, while the
|
||||
* widget is not yet displayed
|
||||
|
||||
@@ -128,6 +128,15 @@ stringw TextBoxWidget::getText() const
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void TextBoxWidget::setPasswordBox(bool passwordBox, wchar_t passwordChar)
|
||||
{
|
||||
IGUIEditBox* textCtrl = Widget::getIrrlichtElement<IGUIEditBox>();
|
||||
assert(textCtrl != NULL);
|
||||
textCtrl->setPasswordBox(passwordBox, passwordChar);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
EventPropagation TextBoxWidget::focused(const int playerID)
|
||||
{
|
||||
assert(playerID == 0); // No support for multiple players in text areas!
|
||||
@@ -145,6 +154,8 @@ void TextBoxWidget::unfocused(const int playerID, Widget* new_focus)
|
||||
assert(playerID == 0); // No support for multiple players in text areas!
|
||||
|
||||
setWithinATextBox(false);
|
||||
|
||||
GUIEngine::getGUIEnv()->removeFocus(m_element);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace GUIEngine
|
||||
void clearListeners();
|
||||
|
||||
irr::core::stringw getText() const;
|
||||
void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
|
||||
|
||||
virtual void elementRemoved();
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -692,6 +692,10 @@
|
||||
RelativePath="..\..\guiengine\widgets\progress_bar_widget.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\guiengine\widgets\rating_bar_widget.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\guiengine\widgets\ribbon_widget.cpp"
|
||||
>
|
||||
@@ -1138,23 +1142,23 @@
|
||||
Name="network"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\network\connect_message.cpp"
|
||||
RelativePath="..\..\network\client_network_manager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\kart_control_message.cpp"
|
||||
RelativePath="..\..\network\event.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\kart_update_message.cpp"
|
||||
RelativePath="..\..\network\game_setup.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\message.cpp"
|
||||
RelativePath="..\..\network\http_functions.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\network_kart.cpp"
|
||||
RelativePath="..\..\network\network_interface.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@@ -1162,17 +1166,81 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\race_info_message.cpp"
|
||||
RelativePath="..\..\network\network_string.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\race_result_message.cpp"
|
||||
RelativePath="..\..\network\protocol.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\race_state.cpp"
|
||||
RelativePath="..\..\network\protocol_manager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\server_network_manager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\stk_host.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\stk_peer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\types.cpp"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="protocols"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\connect_to_peer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\connect_to_server.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\get_peer_address.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\get_public_address.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\hide_public_address.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\lobby_room_protocol.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\ping_protocol.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\request_connection.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\show_public_address.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\start_server.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\stop_server.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="tracks"
|
||||
@@ -1418,7 +1486,15 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\minimal_race_gui.cpp"
|
||||
RelativePath="..\..\states_screens\networking_lobby.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\networking_lobby_settings.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\online_screen.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@@ -1508,6 +1584,10 @@
|
||||
RelativePath="..\..\states_screens\dialogs\gp_info_dialog.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\dialogs\login_dialog.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\dialogs\message_dialog.cpp"
|
||||
>
|
||||
@@ -1524,6 +1604,10 @@
|
||||
RelativePath="..\..\states_screens\dialogs\race_paused_dialog.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\dialogs\registration_dialog.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\dialogs\select_challenge.cpp"
|
||||
>
|
||||
@@ -1638,6 +1722,22 @@
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="online"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\online\current_online_user.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\online\http_connector.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\online\online_user.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
@@ -1738,6 +1838,10 @@
|
||||
RelativePath="..\..\guiengine\widgets\progress_bar_widget.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\guiengine\widgets\rating_bar_widget.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\guiengine\widgets\ribbon_widget.hpp"
|
||||
>
|
||||
@@ -1776,47 +1880,23 @@
|
||||
Name="network"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\network\character_confirm_message.hpp"
|
||||
RelativePath="..\..\network\client_network_manager.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\character_info_message.hpp"
|
||||
RelativePath="..\..\network\event.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\character_selected_message.hpp"
|
||||
RelativePath="..\..\network\game_setup.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\connect_message.hpp"
|
||||
RelativePath="..\..\network\http_functions.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\flyable_info.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\item_info.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\kart_control_message.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\kart_packet.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\kart_update_message.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\message.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\network_kart.hpp"
|
||||
RelativePath="..\..\network\network_interface.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@@ -1824,23 +1904,15 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\race_info_message.hpp"
|
||||
RelativePath="..\..\network\network_string.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\race_result_ack_message.hpp"
|
||||
RelativePath="..\..\network\protocol.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\race_result_message.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\race_start_message.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\race_state.hpp"
|
||||
RelativePath="..\..\network\protocol_manager.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@@ -1848,9 +1920,73 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\world_loaded_message.hpp"
|
||||
RelativePath="..\..\network\server_network_manager.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\singleton.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\stk_host.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\stk_peer.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\types.hpp"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="protocols"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\connect_to_peer.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\connect_to_server.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\get_peer_address.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\get_public_address.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\hide_public_address.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\lobby_room_protocol.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\ping_protocol.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\request_connection.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\show_public_address.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\start_server.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\network\protocols\stop_server.hpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="utils"
|
||||
@@ -2620,7 +2756,15 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\minimal_race_gui.hpp"
|
||||
RelativePath="..\..\states_screens\networking_lobby.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\networking_lobby_settings.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\online_screen.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@@ -2710,6 +2854,10 @@
|
||||
RelativePath="..\..\states_screens\dialogs\gp_info_dialog.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\dialogs\login_dialog.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\dialogs\message_dialog.hpp"
|
||||
>
|
||||
@@ -2726,6 +2874,10 @@
|
||||
RelativePath="..\..\states_screens\dialogs\race_paused_dialog.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\dialogs\registration_dialog.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\states_screens\dialogs\select_challenge.hpp"
|
||||
>
|
||||
@@ -2828,6 +2980,22 @@
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="online"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\online\current_online_user.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\online\http_connector.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\online\online_user.hpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Ressourcendateien"
|
||||
|
||||
@@ -31,10 +31,11 @@ void Binding::serialize(std::ofstream& stream) const
|
||||
<< "event=\"" << m_type << "\" "
|
||||
<< "character=\"" << m_character << "\" ";
|
||||
|
||||
// Only serialize the direction for stick motions
|
||||
// Only serialize the direction and the range for stick motions
|
||||
if (m_type == Input::IT_STICKMOTION)
|
||||
{
|
||||
stream << "direction=\"" << m_dir << "\" ";
|
||||
stream << "range=\"" << m_range << "\" ";
|
||||
}
|
||||
} // serialize
|
||||
|
||||
@@ -44,6 +45,7 @@ bool Binding::deserialize(irr::io::IrrXMLReader* xml)
|
||||
const char *id_string = xml->getAttributeValue("id");
|
||||
const char *event_string = xml->getAttributeValue("event");
|
||||
const char *dir_string = xml->getAttributeValue("direction");
|
||||
const char *range_string = xml->getAttributeValue("range");
|
||||
const char *character = xml->getAttributeValue("character");
|
||||
|
||||
// Proceed only if neccesary tags were found
|
||||
@@ -67,7 +69,18 @@ bool Binding::deserialize(irr::io::IrrXMLReader* xml)
|
||||
printf("WARNING: IT_STICKMOTION without direction, ignoring.\n");
|
||||
return false;
|
||||
}
|
||||
m_dir = (Input::AxisDirection)atoi(dir_string);
|
||||
|
||||
// If the action is a stick motion & a range is defined
|
||||
if (range_string == NULL)
|
||||
{
|
||||
m_range = Input::AR_HALF;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_range = (Input::AxisRange)atoi(range_string);
|
||||
}
|
||||
|
||||
m_dir = (Input::AxisDirection)atoi(dir_string);
|
||||
|
||||
} // if m_type!=stickmotion
|
||||
return true;
|
||||
@@ -263,7 +276,14 @@ irr::core::stringw Binding::getAsString() const
|
||||
else
|
||||
{
|
||||
//I18N: to appear in input configuration screen, for gamepad axes
|
||||
s = _("Axis %d %s", m_id, (m_dir == Input::AD_NEGATIVE) ? L"-" : L"+");
|
||||
if (m_range == Input::AR_HALF)
|
||||
s = _("Axis %d %s", m_id, (m_dir == Input::AD_NEGATIVE) ? L"-" : L"+");
|
||||
else
|
||||
{
|
||||
irr::core::stringw inv = _("inverted");
|
||||
s = _("Axis %d %s", m_id, (m_dir == Input::AD_NEGATIVE) ? inv : L"");
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case Input::IT_STICKBUTTON:
|
||||
|
||||
@@ -36,6 +36,7 @@ private:
|
||||
Input::InputType m_type;
|
||||
int m_id;
|
||||
Input::AxisDirection m_dir;
|
||||
Input::AxisRange m_range;
|
||||
wchar_t m_character;
|
||||
public:
|
||||
/** Returns the type of device this binding is using. */
|
||||
@@ -47,12 +48,16 @@ public:
|
||||
/** Returns the direction this binding is using. */
|
||||
Input::AxisDirection getDirection() const {return m_dir;}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the range this binding is using. */
|
||||
Input::AxisRange getRange() const {return m_range;}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Defines all values of this binding. */
|
||||
void set(Input::InputType type, int id,
|
||||
Input::AxisDirection dir,
|
||||
Input::AxisRange range,
|
||||
wchar_t character)
|
||||
{
|
||||
m_type = type; m_id=id; m_dir=dir; m_character=character;
|
||||
m_type = type; m_id=id; m_dir=dir; m_range=range; m_character=character;
|
||||
} // set
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -322,7 +322,7 @@ InputDevice *DeviceManager::mapGamepadInput( Input::InputType type,
|
||||
int deviceID,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
int *value /* inout */,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */)
|
||||
@@ -361,14 +361,14 @@ bool DeviceManager::translateInput( Input::InputType type,
|
||||
int deviceID,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
int* value /* inout */,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer** player /* out */,
|
||||
PlayerAction* action /* out */ )
|
||||
{
|
||||
if (GUIEngine::getCurrentScreen() != NULL)
|
||||
{
|
||||
GUIEngine::getCurrentScreen()->filterInput(type, deviceID, btnID, axisDir, value);
|
||||
GUIEngine::getCurrentScreen()->filterInput(type, deviceID, btnID, axisDir, *value);
|
||||
}
|
||||
|
||||
InputDevice *device = NULL;
|
||||
@@ -406,7 +406,7 @@ bool DeviceManager::translateInput( Input::InputType type,
|
||||
|
||||
|
||||
// Return true if input was successfully translated to an action and player
|
||||
if (device != NULL && abs(value) > Input::MAX_VALUE/2)
|
||||
if (device != NULL && abs(*value) > Input::MAX_VALUE/2)
|
||||
{
|
||||
m_latest_used_device = device;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
int deviceID,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
int* value /* inout */,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */);
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
int deviceID,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
int *value /* inout */,
|
||||
InputManager::InputDriverMode mode,
|
||||
StateManager::ActivePlayer** player /* out */,
|
||||
PlayerAction* action /* out */ );
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user