From 293e53bbd1e744ed750c24cf681b709224c75747 Mon Sep 17 00:00:00 2001 From: hilnius Date: Mon, 8 Jul 2013 15:03:36 +0000 Subject: [PATCH] supposedly working server-client connection git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/networking@13122 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/network/protocols/lobby_room_protocol.cpp | 28 ++++++++++++++++++- src/network/protocols/lobby_room_protocol.hpp | 7 ++++- src/network/server_network_manager.cpp | 4 +++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/network/protocols/lobby_room_protocol.cpp b/src/network/protocols/lobby_room_protocol.cpp index 1442fde56..e62cef88c 100644 --- a/src/network/protocols/lobby_room_protocol.cpp +++ b/src/network/protocols/lobby_room_protocol.cpp @@ -19,7 +19,10 @@ #include "network/protocols/lobby_room_protocol.hpp" #include "network/network_manager.hpp" +#include "network/protocol_manager.hpp" #include "network/client_network_manager.hpp" +#include "network/protocols/get_public_address.hpp" +#include "network/protocols/show_public_address.hpp" #include "online/current_online_user.hpp" #include "online/http_connector.hpp" #include "config/user_config.hpp" @@ -54,7 +57,10 @@ void ServerLobbyRoomProtocol::setup() { m_setup = NetworkManager::getInstance()->setupNewGame(); // create a new setup m_next_id = 0; - m_state = WORKING; + m_state = NONE; + m_public_address.ip = 0; + m_public_address.port = 0; + Log::info("ServerLobbyRoomProtocol", "Starting the protocol."); } //----------------------------------------------------------------------------- @@ -238,6 +244,26 @@ void ServerLobbyRoomProtocol::update() { switch (m_state) { + case NONE: + m_current_protocol_id = ProtocolManager::getInstance()->requestStart(new GetPublicAddress(&m_public_address)); + m_state = GETTING_PUBLIC_ADDRESS; + break; + case GETTING_PUBLIC_ADDRESS: + if (ProtocolManager::getInstance()->getProtocolState(m_current_protocol_id) == PROTOCOL_STATE_TERMINATED) + { + NetworkManager::getInstance()->setPublicAddress(m_public_address); + m_current_protocol_id = ProtocolManager::getInstance()->requestStart(new ShowPublicAddress()); + m_state = SHOWING_PUBLIC_ADDRESS; + Log::info("ServerLobbyRoomProtocol", "Public address known."); + } + break; + case SHOWING_PUBLIC_ADDRESS: + if (ProtocolManager::getInstance()->getProtocolState(m_current_protocol_id) == PROTOCOL_STATE_TERMINATED) + { + m_state = WORKING; + Log::info("ServerLobbyRoomProtocol", "Public address visible."); + } + break; case WORKING: // first poll every 5 seconds static double last_poll_time = 0; diff --git a/src/network/protocols/lobby_room_protocol.hpp b/src/network/protocols/lobby_room_protocol.hpp index 51c038217..f04b4e894 100644 --- a/src/network/protocols/lobby_room_protocol.hpp +++ b/src/network/protocols/lobby_room_protocol.hpp @@ -82,9 +82,14 @@ class ServerLobbyRoomProtocol : public LobbyRoomProtocol uint8_t m_next_id; //!< Next id to assign to a peer. std::vector m_peers; std::vector m_incoming_peers_ids; - + uint32_t m_current_protocol_id; + TransportAddress m_public_address; + enum STATE { + NONE, + GETTING_PUBLIC_ADDRESS, + SHOWING_PUBLIC_ADDRESS, WORKING, DONE }; diff --git a/src/network/server_network_manager.cpp b/src/network/server_network_manager.cpp index ee5524780..095036456 100644 --- a/src/network/server_network_manager.cpp +++ b/src/network/server_network_manager.cpp @@ -45,6 +45,10 @@ void ServerNetworkManager::run() Log::error("ServerNetworkManager", "Could not initialize enet.\n"); return; } + m_localhost = new STKHost(); + m_localhost->setupServer(STKHost::HOST_ANY, 7321, 16, 2, 0, 0); + m_localhost->startListening(); + NetworkManager::run(); }