Start to remove ClientNetworkManager.
This commit is contained in:
parent
a58f408a99
commit
90b8db9993
14
src/main.cpp
14
src/main.cpp
@ -174,11 +174,9 @@
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "modes/demo_world.hpp"
|
||||
#include "modes/profile_world.hpp"
|
||||
#include "network/client_network_manager.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/server_lobby_room_protocol.hpp"
|
||||
#include "network/client_network_manager.hpp"
|
||||
#include "network/server_console.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/protocols/server_lobby_room_protocol.hpp"
|
||||
@ -782,6 +780,7 @@ int handleCmdLine()
|
||||
// Networking command lines
|
||||
if(CommandLine::has("--server") )
|
||||
{
|
||||
STKHost::setMaxPlayers(UserConfigParams::m_server_max_players);
|
||||
STKHost::create(/*is_Server*/true);
|
||||
Log::info("main", "Creating a server.");
|
||||
}
|
||||
@ -790,7 +789,6 @@ int handleCmdLine()
|
||||
STKHost::create(/*is_server*/false);
|
||||
Log::info("main", "Creating a client.");
|
||||
}
|
||||
NetworkManager::getInstance<ClientNetworkManager>();
|
||||
|
||||
if(CommandLine::has("--max-players", &n))
|
||||
UserConfigParams::m_server_max_players=n;
|
||||
@ -1348,16 +1346,6 @@ int main(int argc, char *argv[] )
|
||||
//handleCmdLine() needs InitTuxkart() so it can't be called first
|
||||
if(!handleCmdLine()) exit(0);
|
||||
|
||||
// load the network manager
|
||||
if (STKHost::isServer())
|
||||
{
|
||||
STKHost::setMaxPlayers(UserConfigParams::m_server_max_players);
|
||||
(new ServerLobbyRoomProtocol())->requestStart();
|
||||
}
|
||||
else // is client
|
||||
{
|
||||
}
|
||||
|
||||
addons_manager->checkInstalledAddons();
|
||||
|
||||
// Load addons.xml to get info about addons even when not
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "network/protocols/connect_to_server.hpp"
|
||||
#include "network/protocols/client_lobby_room_protocol.hpp"
|
||||
#include "network/protocols/synchronization_protocol.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
|
||||
#include "utils/log.hpp"
|
||||
|
||||
@ -44,68 +45,6 @@ void* waitInput(void* data)
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
else if (str == "select")
|
||||
{
|
||||
std::string str2;
|
||||
getline(std::cin, str2);
|
||||
Protocol* protocol = ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM);
|
||||
ClientLobbyRoomProtocol* clrp = static_cast<ClientLobbyRoomProtocol*>(protocol);
|
||||
clrp->requestKartSelection(str2);
|
||||
}
|
||||
else if (str == "vote")
|
||||
{
|
||||
std::cout << "Vote for ? (track/laps/reversed/major/minor/race#) :";
|
||||
std::string str2;
|
||||
getline(std::cin, str2);
|
||||
Protocol* protocol = ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM);
|
||||
ClientLobbyRoomProtocol* clrp = static_cast<ClientLobbyRoomProtocol*>(protocol);
|
||||
if (str2 == "track")
|
||||
{
|
||||
std::cin >> str2;
|
||||
clrp->voteTrack(str2);
|
||||
}
|
||||
else if (str2 == "laps")
|
||||
{
|
||||
int cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteLaps(cnt);
|
||||
}
|
||||
else if (str2 == "reversed")
|
||||
{
|
||||
bool cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteReversed(cnt);
|
||||
}
|
||||
else if (str2 == "major")
|
||||
{
|
||||
int cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteMajor(cnt);
|
||||
}
|
||||
else if (str2 == "minor")
|
||||
{
|
||||
int cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteMinor(cnt);
|
||||
}
|
||||
else if (str2 == "race#")
|
||||
{
|
||||
int cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteRaceCount(cnt);
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
// If STK shuts down, but should receive an input after the network
|
||||
// manager was deleted, the getInstance call will return NULL.
|
||||
else if (NetworkManager::getInstance() &&
|
||||
STKHost::get()->getPeerCount() > 0)
|
||||
{
|
||||
NetworkString msg(1+str.size());
|
||||
msg.ai8(0);
|
||||
msg += str;
|
||||
STKHost::get()->getPeers()[0]->sendPacket(msg);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
@ -173,8 +112,3 @@ void ClientNetworkManager::reset()
|
||||
STKHost::get()->startListening();
|
||||
|
||||
}
|
||||
|
||||
STKPeer* ClientNetworkManager::getPeer()
|
||||
{
|
||||
return STKHost::get()->getPeers()[0];
|
||||
}
|
||||
|
@ -23,24 +23,16 @@
|
||||
#ifndef CLIENT_NETWORK_MANAGER_HPP
|
||||
#define CLIENT_NETWORK_MANAGER_HPP
|
||||
|
||||
#include "network/network_manager.hpp"
|
||||
#include "pthread.h"
|
||||
|
||||
class STKPeer;
|
||||
|
||||
/*! \class ClientNetworkManager
|
||||
* \ingroup network
|
||||
*/
|
||||
class ClientNetworkManager : public NetworkManager
|
||||
class ClientNetworkManager
|
||||
{
|
||||
friend class AbstractSingleton<NetworkManager>;
|
||||
public:
|
||||
/*! \brief Get the instance.
|
||||
* This is a utility function to avoid passing templates parameters
|
||||
* to the getInstance singleton method.
|
||||
*/
|
||||
static ClientNetworkManager* getInstance()
|
||||
{
|
||||
return AbstractSingleton<NetworkManager>::getInstance<ClientNetworkManager>();
|
||||
}
|
||||
|
||||
/*! \brief Initializes network.
|
||||
* This starts the threads and initializes network libraries.
|
||||
*/
|
||||
|
@ -388,7 +388,7 @@ void ProtocolManager::protocolTerminated(Protocol *protocol)
|
||||
{
|
||||
if (m_protocols.getData()[i-offset] == protocol)
|
||||
{
|
||||
delete protocol;
|
||||
// FIXME check for memory leak delete protocol;
|
||||
m_protocols.getData().erase(m_protocols.getData().begin()+(i-offset),
|
||||
m_protocols.getData().begin()+(i-offset)+1);
|
||||
offset++;
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "network/protocols/hide_public_address.hpp"
|
||||
#include "network/protocols/request_connection.hpp"
|
||||
#include "network/protocols/ping_protocol.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "network/protocols/ping_protocol.hpp"
|
||||
#include "network/protocols/quick_join_protocol.hpp"
|
||||
#include "network/protocols/client_lobby_room_protocol.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "network/stk_peer.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
@ -202,7 +204,8 @@ void ConnectToServer::asynchronousUpdate()
|
||||
|
||||
m_current_protocol = new HidePublicAddress();
|
||||
m_current_protocol->requestStart();
|
||||
ClientNetworkManager::getInstance()->setConnected(true);
|
||||
// FIXME - is that necessary? ClientNetworkManager::getInstance()->setConnected(true);
|
||||
// FIXME We can test if the peer is connected, which is handled by ENet
|
||||
m_state = HIDING_ADDRESS;
|
||||
break;
|
||||
}
|
||||
@ -213,7 +216,7 @@ void ConnectToServer::asynchronousUpdate()
|
||||
Log::info("ConnectToServer", "Address hidden");
|
||||
m_state = DONE;
|
||||
// lobby room protocol if we're connected only
|
||||
if (ClientNetworkManager::getInstance()->isConnected())
|
||||
if(STKHost::get()->getPeers()[0]->isConnected())
|
||||
{
|
||||
Protocol *p = new ClientLobbyRoomProtocol(m_server_address);
|
||||
p->requestStart();
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "network/network_manager.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "network/protocols/client_lobby_room_protocol.hpp"
|
||||
#include "network/protocols/server_lobby_room_protocol.hpp"
|
||||
#include "network/protocols/stop_server.hpp"
|
||||
#include "utils/log.hpp"
|
||||
@ -79,40 +80,110 @@ void* ServerConsole::mainLoop(void* data)
|
||||
ServerConsole *me = static_cast<ServerConsole*>(data);
|
||||
std::string str = "";
|
||||
bool stop = false;
|
||||
while(!stop)
|
||||
while (!stop)
|
||||
{
|
||||
getline(std::cin, str);
|
||||
if (str == "quit")
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
else if (str == "kickall")
|
||||
else if (str == "kickall" && STKHost::isServer())
|
||||
{
|
||||
me->kickAllPlayers();
|
||||
}
|
||||
else if (str == "start")
|
||||
else if (str == "start" && STKHost::isServer())
|
||||
{
|
||||
ServerLobbyRoomProtocol* protocol = static_cast<ServerLobbyRoomProtocol*>(ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM));
|
||||
ServerLobbyRoomProtocol* protocol =
|
||||
static_cast<ServerLobbyRoomProtocol*>
|
||||
(ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM));
|
||||
assert(protocol);
|
||||
protocol->startGame();
|
||||
}
|
||||
else if (str == "selection")
|
||||
else if (str == "selection" && STKHost::isServer())
|
||||
{
|
||||
ServerLobbyRoomProtocol* protocol = static_cast<ServerLobbyRoomProtocol*>(ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM));
|
||||
ServerLobbyRoomProtocol* protocol =
|
||||
static_cast<ServerLobbyRoomProtocol*>
|
||||
(ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM));
|
||||
assert(protocol);
|
||||
protocol->startSelection();
|
||||
}
|
||||
else if (str == "compute_race")
|
||||
else if (str == "compute_race"&& STKHost::isServer())
|
||||
{
|
||||
GameSetup* setup = STKHost::get()->getGameSetup();
|
||||
setup->getRaceConfig()->computeRaceMode();
|
||||
}
|
||||
else if (str == "compute_track")
|
||||
else if (str == "compute_track" && STKHost::isServer())
|
||||
{
|
||||
GameSetup* setup = STKHost::get()->getGameSetup();
|
||||
setup->getRaceConfig()->computeNextTrack();
|
||||
}
|
||||
}
|
||||
else if (str == "select" && STKHost::isclient())
|
||||
{
|
||||
std::string str2;
|
||||
getline(std::cin, str2);
|
||||
Protocol* protocol =
|
||||
ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM);
|
||||
ClientLobbyRoomProtocol* clrp = static_cast<ClientLobbyRoomProtocol*>(protocol);
|
||||
clrp->requestKartSelection(str2);
|
||||
}
|
||||
else if (str == "vote" && STKHost::isclient())
|
||||
{
|
||||
std::cout << "Vote for ? (track/laps/reversed/major/minor/race#) :";
|
||||
std::string str2;
|
||||
getline(std::cin, str2);
|
||||
Protocol* protocol = ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM);
|
||||
ClientLobbyRoomProtocol* clrp = static_cast<ClientLobbyRoomProtocol*>(protocol);
|
||||
if (str2 == "track")
|
||||
{
|
||||
std::cin >> str2;
|
||||
clrp->voteTrack(str2);
|
||||
}
|
||||
else if (str2 == "laps")
|
||||
{
|
||||
int cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteLaps(cnt);
|
||||
}
|
||||
else if (str2 == "reversed")
|
||||
{
|
||||
bool cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteReversed(cnt);
|
||||
}
|
||||
else if (str2 == "major")
|
||||
{
|
||||
int cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteMajor(cnt);
|
||||
}
|
||||
else if (str2 == "minor")
|
||||
{
|
||||
int cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteMinor(cnt);
|
||||
}
|
||||
else if (str2 == "race#")
|
||||
{
|
||||
int cnt;
|
||||
std::cin >> cnt;
|
||||
clrp->voteRaceCount(cnt);
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
// If STK shuts down, but should receive an input after the network
|
||||
// manager was deleted, the getInstance call will return NULL.
|
||||
else if (NetworkManager::getInstance() && STKHost::isclient() &&
|
||||
STKHost::get()->getPeerCount() > 0)
|
||||
{
|
||||
NetworkString msg(1 + str.size());
|
||||
msg.ai8(0);
|
||||
msg += str;
|
||||
STKHost::get()->getPeers()[0]->sendPacket(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // while !stop
|
||||
|
||||
uint32_t id = ProtocolManager::getInstance()->requestStart(new StopServer());
|
||||
while(ProtocolManager::getInstance()->getProtocolState(id) != PROTOCOL_STATE_TERMINATED)
|
||||
|
Loading…
Reference in New Issue
Block a user