From ff1ef8b0b6df00a8ee2c0e3bdbe8fea95dc4b5e4 Mon Sep 17 00:00:00 2001 From: hilnius Date: Sat, 24 Aug 2013 16:47:56 +0000 Subject: [PATCH] addded a List UserConfigParam and a StringListUserConfigParam that contains a list of STUN servers (to avoid hard-coding the STUN server domain name.) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13560 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/config/user_config.cpp | 156 ++++++++++++++++++ src/config/user_config.hpp | 73 +++++++- .../protocols/server_lobby_room_protocol.cpp | 3 + src/network/protocols/start_game_protocol.cpp | 1 - 4 files changed, 229 insertions(+), 4 deletions(-) diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index d4f11a16a..5b508ff7c 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -179,6 +179,162 @@ void GroupUserConfigParam::addChild(UserConfigParam* child) } // addChild +// ============================================================================ +template +ListUserConfigParam::ListUserConfigParam(const char* param_name, + const char* comment) +{ + m_param_name = param_name; + all_params.push_back(this); + if(comment != NULL) m_comment = comment; +} // ListUserConfigParam + +// ============================================================================ +template +ListUserConfigParam::ListUserConfigParam(const char* param_name, + const char* comment, + int nb_elements, + ...) +{ + m_param_name = param_name; + all_params.push_back(this); + if(comment != NULL) m_comment = comment; + + // add the default list + va_list arguments; + va_start ( arguments, nb_elements ); + for ( int i = 0; i < nb_elements; i++ ) + m_elements.push_back(va_arg ( arguments, T )); + va_end ( arguments ); // Cleans up the list +} // ListUserConfigParam + +// ============================================================================ +template +ListUserConfigParam::ListUserConfigParam(const char* param_name, + GroupUserConfigParam* group, + const char* comment) +{ + m_param_name = param_name; + group->addChild(this); + if(comment != NULL) m_comment = comment; +} // ListUserConfigParam + +// ============================================================================ +template +ListUserConfigParam::ListUserConfigParam(const char* param_name, + GroupUserConfigParam* group, + const char* comment, + int nb_elements, + ...) +{ + m_param_name = param_name; + group->addChild(this); + if(comment != NULL) m_comment = comment; + + // add the default list + va_list arguments; + va_start ( arguments, nb_elements ); + for ( int i = 0; i < nb_elements; i++ ) + m_elements.push_back(va_arg ( arguments, T )); + va_end ( arguments ); // Cleans up the list +} // ListUserConfigParam + +// ---------------------------------------------------------------------------- +template +void ListUserConfigParam::write(XMLWriter& stream) const +{ + const int elts_amount = m_elements.size(); + + // comment + if(m_comment.size() > 0) stream << " \n <" << m_param_name.c_str() << "\n"; + + stream << L" Size=\"" << elts_amount << "\"\n"; + // actual elements + for (int n=0; n\n"; + stream << L" \n\n"; +} // write + +// ---------------------------------------------------------------------------- + +// Write your own convert function depending on the type of list you use. +void convert(std::string str, char** str2) +{ + *str2 = (char*)(malloc(str.size()+1)); + strcpy(*str2, str.c_str()); +} +// Write your own equals function depending on the type of list you use. +bool equals(char* str1, char* str2) +{ + return (strcmp(str1, str2) == 0); +} + +template +void ListUserConfigParam::findYourDataInAChildOf(const XMLNode* node) +{ + const XMLNode* child = node->getNode( m_param_name ); + if (child == NULL) + { + //std::cerr << "/!\\ User Config : Couldn't find parameter group " + // << paramName << std::endl; + return; + } + + int attr_count = 0; + child->get( "Size", &attr_count); + for (int n=0; nget( oss.str(), &str); + convert(str, &elt); + // check if the element is already there : + bool there = false; + for (unsigned int i = 0; i < m_elements.size(); i++) + { + if (equals(m_elements[i], elt)) + { + there = true; + break; + } + } + if (!there) + { + Log::info("ListUserConfigParam", "New data : %s, \"%s\"", str.c_str(), elt); + m_elements.push_back(elt); + } + } + +} // findYourDataInAChildOf + +// ---------------------------------------------------------------------------- +template +void ListUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node) +{ +} // findYourDataInAnAttributeOf + +// ---------------------------------------------------------------------------- +template +void ListUserConfigParam::addElement(T element) +{ + m_elements.push_back(element); +} // findYourDataInAnAttributeOf + +// ---------------------------------------------------------------------------- +template +irr::core::stringw ListUserConfigParam::toString() const +{ + return ""; +} // toString + + + // ============================================================================ IntUserConfigParam::IntUserConfigParam(int default_value, const char* param_name, diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index fb2485c55..d99c72844 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -101,6 +101,45 @@ public: irr::core::stringw toString() const; }; // GroupUserConfigParam +// ============================================================================ +template +class ListUserConfigParam : public UserConfigParam +{ + std::vector m_elements; + +public: + ListUserConfigParam(const char* param_name, + const char* comment = NULL); + ListUserConfigParam(const char* param_name, + const char* comment, + int nb_elts, + ...); + ListUserConfigParam(const char* param_name, + GroupUserConfigParam* group, + const char* comment = NULL); + ListUserConfigParam(const char* param_name, + GroupUserConfigParam* group, + const char* comment, + int nb_elts, + ...); + + void write(XMLWriter& stream) const; + void findYourDataInAChildOf(const XMLNode* node); + void findYourDataInAnAttributeOf(const XMLNode* node); + + void addElement(T element); + + irr::core::stringw toString() const; + + operator std::vector() const + { return m_elements; } + float& operator=(const std::vector& v) + { m_elements = std::vector(v); return m_elements; } + float& operator=(const ListUserConfigParam& v) + { m_elements = std::vector(v); return m_elements; } +}; // ListUserConfigParam +typedef ListUserConfigParam StringListUserConfigParam; + // ============================================================================ class IntUserConfigParam : public UserConfigParam { @@ -490,12 +529,40 @@ namespace UserConfigParams PARAM_PREFIX IntUserConfigParam m_server_port 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.") ); - - + + PARAM_PREFIX StringListUserConfigParam m_stun_servers + PARAM_DEFAULT( StringListUserConfigParam("Stun_servers", "The stun servers" + " that will be used to know the public address.", + 24, + "provserver.televolution.net", + "sip1.lakedestiny.cordiaip.com", + "stun1.voiceeclipse.net", + "stun01.sipphone.com", + "stun.callwithus.com", + "stun.counterpath.net", + "stun.endigovoip.com", + "stun.ekiga.net", + "stun.ideasip.com" , + "stun.internetcalls.com", + "stun.ipns.com", + "stun.noc.ams-ix.net", + "stun.phonepower.com", + "stun.phoneserve.com", + "stun.rnktel.com", + "stun.softjoys.com", + "stunserver.org", + "stun.sipgate.net", + "stun.stunprotocol.org", + "stun.voip.aebc.com", + "stun.voipbuster.com", + "stun.voxalot.com", + "stun.voxgratia.org", + "stun.xten.com") ); + // ---- Graphic Quality PARAM_PREFIX GroupUserConfigParam m_graphics_quality PARAM_DEFAULT( GroupUserConfigParam("GFX", diff --git a/src/network/protocols/server_lobby_room_protocol.cpp b/src/network/protocols/server_lobby_room_protocol.cpp index 7fa5f9dd7..c51303d4c 100644 --- a/src/network/protocols/server_lobby_room_protocol.cpp +++ b/src/network/protocols/server_lobby_room_protocol.cpp @@ -281,6 +281,9 @@ void ServerLobbyRoomProtocol::checkRaceFinished() // notify the network world that it is stopped NetworkWorld::getInstance()->stop(); + // exit the race now + race_manager->exitRace(); + race_manager->setAIKartOverride(""); } else { diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index 9b06ff90f..f05d30f42 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -94,7 +94,6 @@ void StartGameProtocol::update() m_listener->requestStart(new SynchronizationProtocol()); Log::info("StartGameProtocol", "SynchronizationProtocol started."); // race startup sequence - NetworkWorld::getInstance()->start(); // builds it and starts race_manager->setNumKarts(m_game_setup->getPlayerCount()); race_manager->setNumPlayers(m_game_setup->getPlayerCount());