From 7e6711e163830239a84053437897673ecd03c97a Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 11 Feb 2016 09:03:51 +1100 Subject: [PATCH] Renamged NetworkWorld to RaceEventManager (since this class is not a 'world' in the sense our game modes are). --- sources.cmake | 2 +- src/items/item_manager.cpp | 6 +-- .../controller/local_player_controller.cpp | 6 +-- src/karts/kart.cpp | 4 +- src/main_loop.cpp | 7 +-- src/network/network_config.hpp | 8 +--- .../protocols/client_lobby_room_protocol.cpp | 29 +++++++----- .../protocols/controller_events_protocol.cpp | 1 - .../protocols/kart_update_protocol.cpp | 1 - .../protocols/server_lobby_room_protocol.cpp | 22 +++++---- src/network/protocols/start_game_protocol.cpp | 4 +- ...twork_world.cpp => race_event_manager.cpp} | 27 +++++------ ...twork_world.hpp => race_event_manager.hpp} | 8 ++-- src/network/stk_host.cpp | 28 ++++------- src/network/stk_host.hpp | 1 - src/network/stk_peer.cpp | 1 + src/network/stk_peer.hpp | 13 ++++++ src/race/race_manager.cpp | 46 ++++++++++++------- src/states_screens/main_menu_screen.cpp | 6 +-- 19 files changed, 119 insertions(+), 101 deletions(-) rename src/network/{network_world.cpp => race_event_manager.cpp} (83%) rename src/network/{network_world.hpp => race_event_manager.hpp} (90%) mode change 100644 => 100755 diff --git a/sources.cmake b/sources.cmake index ddc029d4f..f484b15d5 100644 --- a/sources.cmake +++ b/sources.cmake @@ -1,5 +1,5 @@ # Modify this file to change the last-modified date when you add/remove a file. -# This will then trigger a new cmake run automatically. +# This will then trigger a new cmake run automatically. file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp") file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp") file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*") diff --git a/src/items/item_manager.cpp b/src/items/item_manager.cpp index 782a408e6..b1bf53516 100644 --- a/src/items/item_manager.cpp +++ b/src/items/item_manager.cpp @@ -30,7 +30,7 @@ #include "karts/abstract_kart.hpp" #include "modes/linear_world.hpp" #include "network/network_config.hpp" -#include "network/network_world.hpp" +#include "network/race_event_manager.hpp" #include "tracks/quad_graph.hpp" #include "tracks/track.hpp" #include "utils/string_utils.hpp" @@ -320,7 +320,7 @@ void ItemManager::checkItemHit(AbstractKart* kart) if((*i)->hitKart(kart->getXYZ(), kart)) { // if we're not playing online, pick the item. - if (!NetworkWorld::getInstance()->isRunning()) + if (!RaceEventManager::getInstance()->isRunning()) collectedItem(*i, kart); else if (NetworkConfig::get()->isServer()) { @@ -328,7 +328,7 @@ void ItemManager::checkItemHit(AbstractKart* kart) // A client does the collection upon receiving the // event from the server! collectedItem(*i, kart); - NetworkWorld::getInstance()->collectedItem(*i, kart); + RaceEventManager::getInstance()->collectedItem(*i, kart); } } // if hit } // for m_all_items diff --git a/src/karts/controller/local_player_controller.cpp b/src/karts/controller/local_player_controller.cpp index 3d885bd65..b48a3622d 100644 --- a/src/karts/controller/local_player_controller.cpp +++ b/src/karts/controller/local_player_controller.cpp @@ -37,7 +37,7 @@ #include "karts/rescue_animation.hpp" #include "modes/world.hpp" #include "network/network_config.hpp" -#include "network/network_world.hpp" +#include "network/race_event_manager.hpp" #include "race/history.hpp" #include "states_screens/race_gui_base.hpp" #include "utils/constants.hpp" @@ -121,9 +121,9 @@ void LocalPlayerController::action(PlayerAction action, int value) // If this is a client, send the action to the server if (World::getWorld()->isNetworkWorld() && NetworkConfig::get()->isClient() && - NetworkWorld::getInstance()->isRunning() ) + RaceEventManager::getInstance()->isRunning() ) { - NetworkWorld::getInstance()->controllerAction(this, action, value); + RaceEventManager::getInstance()->controllerAction(this, action, value); } } // action diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 0723d37ae..363c1d311 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -58,7 +58,7 @@ #include "karts/skidding.hpp" #include "modes/linear_world.hpp" #include "network/network_config.hpp" -#include "network/network_world.hpp" +#include "network/race_event_manager.hpp" #include "physics/btKart.hpp" #include "physics/btKartRaycast.hpp" #include "physics/physics.hpp" @@ -1393,7 +1393,7 @@ void Kart::update(float dt) // Check if any item was hit. // check it if we're not in a network world, or if we're on the server // (when network mode is on) - if (!NetworkWorld::getInstance()->isRunning() || + if (!RaceEventManager::getInstance()->isRunning() || NetworkConfig::get()->isServer()) ItemManager::get()->checkItemHit(this); diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 07d04e584..6c6459755 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -32,7 +32,7 @@ #include "modes/world.hpp" #include "network/network_config.hpp" #include "network/protocol_manager.hpp" -#include "network/network_world.hpp" +#include "network/race_event_manager.hpp" #include "network/stk_host.hpp" #include "online/request_manager.hpp" #include "race/race_manager.hpp" @@ -121,8 +121,9 @@ void MainLoop::updateRace(float dt) { if(ProfileWorld::isProfileMode()) dt=1.0f/60.0f; - if (NetworkWorld::getInstance()->isRunning()) - NetworkWorld::getInstance()->update(dt); + // The race event manager will update world in case of an online race + if (RaceEventManager::getInstance()->isRunning()) + RaceEventManager::getInstance()->update(dt); else World::getWorld()->updateWorld(dt); } // updateRace diff --git a/src/network/network_config.hpp b/src/network/network_config.hpp index 86d69559c..f09b93d5e 100644 --- a/src/network/network_config.hpp +++ b/src/network/network_config.hpp @@ -90,12 +90,8 @@ public: /** Sets the password for a server. */ void setPassword(const std::string &password) { m_password = password; } // ------------------------------------------------------------------------ - /** Returns if the specified password is the correct password for this - * server. */ - bool checkPassword(const std::string &password) - { - return m_password == password; - } + /** Returns the password. */ + const std::string& getPassword() const { return m_password; } // ------------------------------------------------------------------------ /** Return if a network setting is happening. A network setting is active * if a host (server or client) exists. */ diff --git a/src/network/protocols/client_lobby_room_protocol.cpp b/src/network/protocols/client_lobby_room_protocol.cpp index 9545dd6c8..15c9d20a7 100644 --- a/src/network/protocols/client_lobby_room_protocol.cpp +++ b/src/network/protocols/client_lobby_room_protocol.cpp @@ -21,10 +21,11 @@ #include "config/player_manager.hpp" #include "modes/world_with_rank.hpp" #include "network/event.hpp" +#include "network/network_config.hpp" #include "network/network_player_profile.hpp" -#include "network/network_world.hpp" #include "network/protocols/start_game_protocol.hpp" #include "network/protocol_manager.hpp" +#include "network/race_event_manager.hpp" #include "network/stk_host.hpp" #include "network/stk_peer.hpp" #include "online/online_profile.hpp" @@ -242,9 +243,11 @@ void ClientLobbyRoomProtocol::update() name = PlayerManager::getCurrentPlayer()->getName(); std::string name_u8 = StringUtils::wideToUtf8(name); - NetworkString ns(6+1+name_u8.size()); + const std::string &password = NetworkConfig::get()->getPassword(); + NetworkString ns(6+1+name_u8.size()+1+password.size()); // 4 (size of id), global id - ns.ai8(LE_CONNECTION_REQUESTED).encodeString(name); + ns.ai8(LE_CONNECTION_REQUESTED).encodeString(name) + .encodeString(NetworkConfig::get()->getPassword()); sendMessage(ns); m_state = REQUESTING_CONNECTION; } @@ -266,7 +269,7 @@ void ClientLobbyRoomProtocol::update() case PLAYING: { // race is now over, kill race protocols and return to connected state - if (NetworkWorld::getInstance()->isRaceOver()) + if (RaceEventManager::getInstance()->isRaceOver()) { Log::info("ClientLobbyRoomProtocol", "Game finished."); m_state = RACE_FINISHED; @@ -372,17 +375,17 @@ void ClientLobbyRoomProtocol::disconnectedPlayer(Event* event) * \param event : Event providing the information. * * Format of the data : - * Byte 0 1 2 3 7 8 - * ------------------------------------------------------------------ - * Size | 1 | 1 | 1 | 4 | 1 | | - * Data | 1 | 0 <= race id < 16 | 4 | priv token | hostid | playernames* | - * ------------------------------------------------------------------ + * Byte 0 1 2 3 7 8 9 + * ----------------------------------------------------------------------------- + * Size | 1 | 1 | 1 | 4 | 1 | 1 | | + * Data | 1 | 0 <= race id < 16 | 4 | priv token | hostid | authorised |playernames* | + * ------------------------------------------------------------------------------ */ void ClientLobbyRoomProtocol::connectionAccepted(Event* event) { NetworkString &data = event->data(); // At least 12 bytes should remain now - if (data.size() < 8|| data[0] != 1 || data[2] != 4) + if (data.size() < 9|| data[0] != 1 || data[2] != 4) { Log::error("ClientLobbyRoomProtocol", "A message notifying an accepted connection wasn't " @@ -404,6 +407,10 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event) name = PlayerManager::getCurrentPlayer()->getName(); uint8_t my_player_id = data.getUInt8(1); uint8_t my_host_id = data.getUInt8(7); + uint8_t authorised = data.getUInt8(8); + // Store this client's authorisation status in the peer information + // for the server. + event->getPeer()->setAuthorised(authorised!=0); STKHost::get()->setMyHostId(my_host_id); NetworkPlayerProfile* profile = new NetworkPlayerProfile(my_player_id, name); @@ -416,7 +423,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event) // Add all players // =============== - int n = 8; + int n = 9; while (n < data.size()) { if (data[n] != 1 ) diff --git a/src/network/protocols/controller_events_protocol.cpp b/src/network/protocols/controller_events_protocol.cpp index c7188fb1a..e71c72f74 100644 --- a/src/network/protocols/controller_events_protocol.cpp +++ b/src/network/protocols/controller_events_protocol.cpp @@ -25,7 +25,6 @@ #include "network/network_player_profile.hpp" #include "network/game_setup.hpp" #include "network/network_config.hpp" -#include "network/network_world.hpp" #include "network/protocol_manager.hpp" #include "network/stk_host.hpp" #include "network/stk_peer.hpp" diff --git a/src/network/protocols/kart_update_protocol.cpp b/src/network/protocols/kart_update_protocol.cpp index 9ed79d03a..1b1b965b5 100644 --- a/src/network/protocols/kart_update_protocol.cpp +++ b/src/network/protocols/kart_update_protocol.cpp @@ -5,7 +5,6 @@ #include "modes/world.hpp" #include "network/event.hpp" #include "network/network_config.hpp" -#include "network/network_world.hpp" #include "network/protocol_manager.hpp" #include "utils/time.hpp" diff --git a/src/network/protocols/server_lobby_room_protocol.cpp b/src/network/protocols/server_lobby_room_protocol.cpp index ba92a03fb..9bb3e4ea4 100644 --- a/src/network/protocols/server_lobby_room_protocol.cpp +++ b/src/network/protocols/server_lobby_room_protocol.cpp @@ -23,12 +23,12 @@ #include "modes/world.hpp" #include "network/event.hpp" #include "network/network_config.hpp" -#include "network/network_world.hpp" #include "network/network_player_profile.hpp" #include "network/protocols/get_public_address.hpp" #include "network/protocols/connect_to_peer.hpp" #include "network/protocols/start_game_protocol.hpp" #include "network/protocol_manager.hpp" +#include "network/race_event_manager.hpp" #include "network/stk_host.hpp" #include "network/stk_peer.hpp" #include "online/online_profile.hpp" @@ -146,7 +146,7 @@ void ServerLobbyRoomProtocol::update() if(NetworkConfig::get()->isWAN()) checkIncomingConnectionRequests(); if (m_in_race && World::getWorld() && - NetworkWorld::getInstance()->isRunning()) + RaceEventManager::getInstance()->isRunning()) { checkRaceFinished(); } @@ -241,7 +241,7 @@ void ServerLobbyRoomProtocol::startGame() */ void ServerLobbyRoomProtocol::startSelection(const Event *event) { - if(event && !STKHost::get()->isAuthorisedToControl(event->getPeer())) + if(event && !event->getPeer()->isAuthorised()) { Log::warn("ServerLobby", "Client %lx is not authorised to start selection.", @@ -313,10 +313,10 @@ void ServerLobbyRoomProtocol::checkIncomingConnectionRequests() void ServerLobbyRoomProtocol::checkRaceFinished() { - assert(NetworkWorld::getInstance()->isRunning()); + assert(RaceEventManager::getInstance()->isRunning()); assert(World::getWorld()); // if race is over, give the final score to everybody - if (NetworkWorld::getInstance()->isRaceOver()) + if (RaceEventManager::getInstance()->isRaceOver()) { // calculate karts ranks : int num_players = race_manager->getNumberOfKarts(); @@ -381,7 +381,7 @@ void ServerLobbyRoomProtocol::checkRaceFinished() "No game events protocol registered."); // notify the network world that it is stopped - NetworkWorld::getInstance()->stop(); + RaceEventManager::getInstance()->stop(); // exit the race now race_manager->exitRace(); race_manager->setAIKartOverride(""); @@ -445,8 +445,11 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event) // Connection accepted. // ==================== std::string name_u8; - data.decodeString(0, &name_u8); + int len = data.decodeString(0, &name_u8); core::stringw name = StringUtils::utf8ToWide(name_u8); + std::string password; + data.decodeString(len, &password); + bool is_authorised = (password==NetworkConfig::get()->getPassword()); // Get the unique global ID for this player. m_next_player_id.lock(); @@ -480,10 +483,10 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event) const std::vector &players = m_setup->getPlayers(); // send a message to the one that asked to connect // Size is overestimated, probably one player's data will not be sent - NetworkString message_ack(13 + players.size() * 7); + NetworkString message_ack(14 + players.size() * 7); // connection success -- size of token -- token message_ack.ai8(LE_CONNECTION_ACCEPTED).ai8(1).ai8(new_player_id).ai8(4) - .ai32(token).addUInt8(new_host_id); + .ai32(token).addUInt8(new_host_id).addUInt8(is_authorised); // Add all players so that this user knows (this new player is only added // to the list of players later, so the new player's info is not included) for (unsigned int i = 0; i < players.size(); i++) @@ -499,6 +502,7 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event) m_setup->addPlayer(profile); peer->setPlayerProfile(profile); peer->setClientServerToken(token); + peer->setAuthorised(is_authorised); peer->setHostId(new_host_id); Log::verbose("ServerLobbyRoomProtocol", "New player."); diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index 7beddc625..16a4cdc2b 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -10,7 +10,7 @@ #include "network/game_setup.hpp" #include "network/network_config.hpp" #include "network/network_player_profile.hpp" -#include "network/network_world.hpp" +#include "network/race_event_manager.hpp" #include "network/protocol_manager.hpp" #include "network/protocols/synchronization_protocol.hpp" #include "network/stk_host.hpp" @@ -58,7 +58,7 @@ void StartGameProtocol::setup() // Race startup sequence // --------------------- // This creates the network world. - NetworkWorld::getInstance()->start(); + RaceEventManager::getInstance()->start(); // The number of karts includes the AI karts, which are not supported atn race_manager->setNumKarts(m_game_setup->getPlayerCount()); diff --git a/src/network/network_world.cpp b/src/network/race_event_manager.cpp similarity index 83% rename from src/network/network_world.cpp rename to src/network/race_event_manager.cpp index e957d6209..24eb18eaf 100644 --- a/src/network/network_world.cpp +++ b/src/network/race_event_manager.cpp @@ -1,4 +1,5 @@ -#include "network/network_world.hpp" + +#include "network/race_event_manager.hpp" #include "network/network_config.hpp" #include "network/protocol_manager.hpp" @@ -8,19 +9,19 @@ #include "modes/world.hpp" -NetworkWorld::NetworkWorld() +RaceEventManager::RaceEventManager() { m_running = false; -} // NetworkWorld +} // RaceEventManager // ---------------------------------------------------------------------------- #include "karts/controller/controller.hpp" -NetworkWorld::~NetworkWorld() +RaceEventManager::~RaceEventManager() { -} // ~NetworkWorld +} // ~RaceEventManager // ---------------------------------------------------------------------------- -void NetworkWorld::update(float dt) +void RaceEventManager::update(float dt) { // This can happen in case of disconnects - protocol manager is // shut down, but still events to process. @@ -31,7 +32,7 @@ void NetworkWorld::update(float dt) ProtocolManager::getInstance()->getProtocol(PROTOCOL_SYNCHRONIZATION)); if (protocol) // if this protocol exists, that's that we play online { - Log::debug("NetworkWorld", "Coutdown value is %f", + Log::debug("RaceEventManager", "Coutdown value is %f", protocol->getCountdown()); if (protocol->getCountdown() > 0.0) { @@ -46,24 +47,24 @@ void NetworkWorld::update(float dt) { // consider the world finished. stop(); - Log::info("NetworkWorld", "The game is considered finish."); + Log::info("RaceEventManager", "The game is considered finish."); } } // update // ---------------------------------------------------------------------------- -void NetworkWorld::start() +void RaceEventManager::start() { m_running = true; } // start // ---------------------------------------------------------------------------- -void NetworkWorld::stop() +void RaceEventManager::stop() { m_running = false; } // stop // ---------------------------------------------------------------------------- -bool NetworkWorld::isRaceOver() +bool RaceEventManager::isRaceOver() { if(!World::getWorld()) return false; @@ -76,7 +77,7 @@ bool NetworkWorld::isRaceOver() * \param item The item that was collected. * \param kart The kart that collected the item. */ -void NetworkWorld::collectedItem(Item *item, AbstractKart *kart) +void RaceEventManager::collectedItem(Item *item, AbstractKart *kart) { // this is only called in the server assert(NetworkConfig::get()->isServer()); @@ -87,7 +88,7 @@ void NetworkWorld::collectedItem(Item *item, AbstractKart *kart) } // collectedItem // ---------------------------------------------------------------------------- -void NetworkWorld::controllerAction(Controller* controller, +void RaceEventManager::controllerAction(Controller* controller, PlayerAction action, int value) { ControllerEventsProtocol* protocol = static_cast( diff --git a/src/network/network_world.hpp b/src/network/race_event_manager.hpp old mode 100644 new mode 100755 similarity index 90% rename from src/network/network_world.hpp rename to src/network/race_event_manager.hpp index 07209f6eb..408367a76 --- a/src/network/network_world.hpp +++ b/src/network/race_event_manager.hpp @@ -34,16 +34,16 @@ class Item; /*! \brief Manages the world updates during an online game * This function's update is to be called instead of the normal World update */ -class NetworkWorld : public AbstractSingleton +class RaceEventManager : public AbstractSingleton { private: bool m_running; float m_race_time; - friend class AbstractSingleton; + friend class AbstractSingleton; - NetworkWorld(); - virtual ~NetworkWorld(); + RaceEventManager(); + virtual ~RaceEventManager(); public: void update(float dt); diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index 1c2e3969a..eee521197 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -492,33 +492,21 @@ int STKHost::mustStopListening() return 1; } // mustStopListening -// -------------------------------------------------------------------- -/** Returns true if this instance is allowed to control the server. - * Only the first connected client (i.e. the one with host id 1) is - * allowed to control the server. Only called from a client. +// ---------------------------------------------------------------------------- +/** Returns true if this client instance is allowed to control the server. + * A client can authorise itself by providing the server's password. It is + * then allowed to control the server (e.g. start kart selection). + * The information if this client was authorised by the server is actually + * stored in the peer (which is the server peer on a client). */ bool STKHost::isAuthorisedToControl() const { + assert(NetworkConfig::get()->isClient()); // If we are not properly connected (i.e. only enet connection, but not // stk logic), no peer is authorised. if(m_peers.size()==0) return false; - return m_host_id == 1; -} // isAuthorisedToControl - -// ---------------------------------------------------------------------------- -/** Server-side check if the client sending a command is really authorised - * to do so. Only the first connected client (i.e. host id = 1) is allowed - * to control the server. - * \param peer Peer sending the command. - */ -bool STKHost::isAuthorisedToControl(const STKPeer *peer) const -{ - // If we are not properly connected (i.e. only enet connection, but not - // stk logic), no peer is authorised. - if(m_peers.size()==0) - return false; - return peer->getHostId()==1; + return m_peers[0]->isAuthorised(); } // isAuthorisedToControl // ---------------------------------------------------------------------------- diff --git a/src/network/stk_host.hpp b/src/network/stk_host.hpp index fdd4a4268..2a0c3b31e 100644 --- a/src/network/stk_host.hpp +++ b/src/network/stk_host.hpp @@ -162,7 +162,6 @@ public: uint16_t getPort() const; void setErrorMessage(const irr::core::stringw &message); bool isAuthorisedToControl() const; - bool isAuthorisedToControl(const STKPeer *peer) const; const irr::core::stringw& getErrorMessage() const; diff --git a/src/network/stk_peer.cpp b/src/network/stk_peer.cpp index 190b7ca17..eed96862f 100644 --- a/src/network/stk_peer.cpp +++ b/src/network/stk_peer.cpp @@ -30,6 +30,7 @@ STKPeer::STKPeer(ENetPeer *enet_peer) { m_enet_peer = enet_peer; + m_is_authorised = false; m_player_profile = NULL; m_client_server_token = 0; m_host_id = 0; diff --git a/src/network/stk_peer.hpp b/src/network/stk_peer.hpp index 923e73cff..49ebe7b25 100644 --- a/src/network/stk_peer.hpp +++ b/src/network/stk_peer.hpp @@ -52,6 +52,9 @@ protected: /** Host id of this peer. */ int m_host_id; + + /** True if this peer is authorised to control a server. */ + bool m_is_authorised; public: STKPeer(ENetPeer *enet_peer); virtual ~STKPeer(); @@ -97,6 +100,16 @@ public: // ------------------------------------------------------------------------ /** Returns the host id of this peer. */ int getHostId() const { return m_host_id; } + // ------------------------------------------------------------------------ + /** Sets if this peer is authorised to control the server. */ + void setAuthorised(bool authorised) { m_is_authorised = authorised; } + // ------------------------------------------------------------------------ + /** Returns if this peer is authorised to control the server. The server + * uses this to check if a peer is allowed certain commands; and a client + * uses this function (in which case this peer is actually the server + * peer) to see if this client is allowed certain command (i.e. to + * display additional GUI elements). */ + bool isAuthorised() const { return m_is_authorised; } }; // STKPeer #endif // STK_PEER_HPP diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index 40a55b47a..26318bc5f 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -45,8 +45,8 @@ #include "modes/soccer_world.hpp" #include "network/protocol_manager.hpp" #include "network/network_config.hpp" -#include "network/network_world.hpp" #include "network/protocols/start_game_protocol.hpp" +#include "network/race_event_manager.hpp" #include "scriptengine/property_animator.hpp" #include "states_screens/grand_prix_cutscene.hpp" #include "states_screens/grand_prix_lose.hpp" @@ -318,7 +318,7 @@ void RaceManager::startNew(bool from_overworld) m_num_laps = m_grand_prix.getLaps(); m_reverse_track = m_grand_prix.getReverse(); - if (!NetworkWorld::getInstance()->isRunning()) + if (!RaceEventManager::getInstance()->isRunning()) { // We look if Player 1 has a saved version of this GP. m_saved_gp = SavedGrandPrix::getSavedGP( @@ -362,7 +362,8 @@ void RaceManager::startNew(bool from_overworld) Log::verbose("RaceManager", "Nb of karts=%u, ai:%lu players:%lu\n", (unsigned int) m_num_karts, m_ai_kart_list.size(), m_player_karts.size()); - assert((unsigned int)m_num_karts == m_ai_kart_list.size()+m_player_karts.size()); + assert((unsigned int)m_num_karts == m_ai_kart_list.size() + + m_player_karts.size() ); // First add the AI karts (randomly chosen) // ---------------------------------------- @@ -441,8 +442,8 @@ void RaceManager::startNextRace() IrrlichtDevice* device = irr_driver->getDevice(); GUIEngine::renderLoading(); device->getVideoDriver()->endScene(); - device->getVideoDriver()->beginScene(true, true, video::SColor(255,100,101,140)); - + device->getVideoDriver()->beginScene(true, true, + video::SColor(255,100,101,140)); m_num_finished_karts = 0; m_num_finished_players = 0; @@ -556,7 +557,8 @@ void RaceManager::next() m_track_number++; if(m_track_number<(int)m_tracks.size()) { - if(m_major_mode==MAJOR_MODE_GRAND_PRIX && !NetworkWorld::getInstance()->isRunning()) + if( m_major_mode==MAJOR_MODE_GRAND_PRIX && + !RaceEventManager::getInstance()->isRunning() ) { // Saving GP state saveGP(); @@ -601,7 +603,8 @@ void RaceManager::saveGP() { // Delete other save files (and random GP, which should never // have been saved in the first place) - const SavedGrandPrix &sgp = UserConfigParams::m_saved_grand_prix_list[i]; + const SavedGrandPrix &sgp = + UserConfigParams::m_saved_grand_prix_list[i]; if (sgp.getGPID() == "random" || (sgp.getGPID() == m_saved_gp->getGPID() && sgp.getDifficulty() == m_saved_gp->getDifficulty()) ) @@ -679,9 +682,10 @@ void RaceManager::computeGPRanks() sort_data.push_back(sd); if(UserConfigParams::m_ftl_debug) { - Log::debug("Race Manager","[ftl] kart '%s' has position %d score %d.", - World::getWorld()->getKart(kart_id)->getIdent().c_str(), - sd->m_position, sd->m_score); + Log::debug("Race Manager", + "[ftl] kart '%s' has position %d score %d.", + World::getWorld()->getKart(kart_id)->getIdent().c_str(), + sd->m_position, sd->m_score); } } @@ -710,10 +714,12 @@ void RaceManager::exitRace(bool delete_world) { // Only display the grand prix result screen if all tracks // were finished, and not when a race is aborted. - if (m_major_mode==MAJOR_MODE_GRAND_PRIX && m_track_number==(int)m_tracks.size()) + if ( m_major_mode==MAJOR_MODE_GRAND_PRIX && + m_track_number==(int)m_tracks.size() ) { PlayerManager::getCurrentPlayer()->grandPrixFinished(); - if(m_major_mode==MAJOR_MODE_GRAND_PRIX&& !NetworkWorld::getInstance()->isRunning()) + if( m_major_mode==MAJOR_MODE_GRAND_PRIX && + !RaceEventManager::getInstance()->isRunning() ) { if(m_saved_gp != NULL) m_saved_gp->remove(); @@ -726,7 +732,8 @@ void RaceManager::exitRace(bool delete_world) const int loserThreshold = 3; std::string winners[3]; - std::vector humanLosers; // because we don't care about AIs that lost + // because we don't care about AIs that lost + std::vector humanLosers; for (unsigned int i=0; i < kart_status_count; ++i) { if(UserConfigParams::logMisc()) @@ -769,14 +776,16 @@ void RaceManager::exitRace(bool delete_world) if (some_human_player_won) { - race_manager->startSingleRace("gpwin", 999, race_manager->raceWasStartedFromOverworld()); + race_manager->startSingleRace("gpwin", 999, + race_manager->raceWasStartedFromOverworld()); GrandPrixWin* scene = GrandPrixWin::getInstance(); scene->push(); scene->setKarts(winners); } else { - race_manager->startSingleRace("gplose", 999, race_manager->raceWasStartedFromOverworld()); + race_manager->startSingleRace("gplose", 999, + race_manager->raceWasStartedFromOverworld()); GrandPrixLose* scene = GrandPrixLose::getInstance(); scene->push(); @@ -830,7 +839,8 @@ void RaceManager::kartFinishedRace(const AbstractKart *kart, float time) m_kart_status[id].m_score += wwr->getScoreForPosition(pos); else { - Log::error("RaceManager", "World with scores that is not a WorldWithRank??"); + Log::error("RaceManager", + "World with scores that is not a WorldWithRank??"); } m_kart_status[id].m_overall_time += time; @@ -891,7 +901,9 @@ void RaceManager::startSingleRace(const std::string &track_ident, setMajorMode(RaceManager::MAJOR_MODE_SINGLE); setCoinTarget( 0 ); // Might still be set from a previous challenge - if (!NetworkWorld::getInstance()->isRunning()) // if not in a network world + + // if not in a network world, setup player karts + if (!RaceEventManager::getInstance()->isRunning()) race_manager->setupPlayerKartInfo(); // do this setup player kart startNew(from_overworld); diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 0d9198b64..0bc4f0e9b 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -490,12 +490,10 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, "\"Connect to the Internet\".")); return; } - if(1) -// if (PlayerManager::getCurrentOnlineId()) + if (PlayerManager::getCurrentOnlineId()) { // For 0.8.2 disable the server menu, instead go to online profile -#define ENABLE_NETWORK_MULTIPLAYER_SCREEN -#ifdef ENABLE_NETWORK_MULTIPLAYER_SCREEN + #ifdef ENABLE_NETWORK_MULTIPLAYER_SCREEN OnlineScreen::getInstance()->push(); #else ProfileManager::get()->setVisiting(PlayerManager::getCurrentOnlineId());