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
This commit is contained in:
parent
f56f1ec3b1
commit
293e53bbd1
@ -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;
|
||||
|
@ -82,9 +82,14 @@ class ServerLobbyRoomProtocol : public LobbyRoomProtocol
|
||||
uint8_t m_next_id; //!< Next id to assign to a peer.
|
||||
std::vector<TransportAddress> m_peers;
|
||||
std::vector<uint32_t> 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
|
||||
};
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user