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
This commit is contained in:
parent
39a0e7a67e
commit
ff1ef8b0b6
@ -179,6 +179,162 @@ void GroupUserConfigParam::addChild(UserConfigParam* child)
|
||||
} // addChild
|
||||
|
||||
|
||||
// ============================================================================
|
||||
template<typename T>
|
||||
ListUserConfigParam<T>::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<typename T>
|
||||
ListUserConfigParam<T>::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<typename T>
|
||||
ListUserConfigParam<T>::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<typename T>
|
||||
ListUserConfigParam<T>::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<typename T>
|
||||
void ListUserConfigParam<T>::write(XMLWriter& stream) const
|
||||
{
|
||||
const int elts_amount = m_elements.size();
|
||||
|
||||
// comment
|
||||
if(m_comment.size() > 0) stream << " <!-- " << m_comment.c_str();
|
||||
stream << L" -->\n <" << m_param_name.c_str() << "\n";
|
||||
|
||||
stream << L" Size=\"" << elts_amount << "\"\n";
|
||||
// actual elements
|
||||
for (int n=0; n<elts_amount; n++)
|
||||
{
|
||||
stream << L" " << n << "=\"" << m_elements[n] << "\"\n";
|
||||
}
|
||||
stream << L" >\n";
|
||||
stream << L" </" << m_param_name.c_str() << ">\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<typename T>
|
||||
void ListUserConfigParam<T>::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; n<attr_count; n++)
|
||||
{
|
||||
T elt;
|
||||
std::ostringstream oss;
|
||||
oss << n;
|
||||
std::string str;
|
||||
child->get( 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<typename T>
|
||||
void ListUserConfigParam<T>::findYourDataInAnAttributeOf(const XMLNode* node)
|
||||
{
|
||||
} // findYourDataInAnAttributeOf
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void ListUserConfigParam<T>::addElement(T element)
|
||||
{
|
||||
m_elements.push_back(element);
|
||||
} // findYourDataInAnAttributeOf
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
irr::core::stringw ListUserConfigParam<T>::toString() const
|
||||
{
|
||||
return "";
|
||||
} // toString
|
||||
|
||||
|
||||
|
||||
// ============================================================================
|
||||
IntUserConfigParam::IntUserConfigParam(int default_value,
|
||||
const char* param_name,
|
||||
|
@ -101,6 +101,45 @@ public:
|
||||
irr::core::stringw toString() const;
|
||||
}; // GroupUserConfigParam
|
||||
|
||||
// ============================================================================
|
||||
template<typename T>
|
||||
class ListUserConfigParam : public UserConfigParam
|
||||
{
|
||||
std::vector<T> 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<T>() const
|
||||
{ return m_elements; }
|
||||
float& operator=(const std::vector<T>& v)
|
||||
{ m_elements = std::vector<T>(v); return m_elements; }
|
||||
float& operator=(const ListUserConfigParam& v)
|
||||
{ m_elements = std::vector<T>(v); return m_elements; }
|
||||
}; // ListUserConfigParam
|
||||
typedef ListUserConfigParam<char*> 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",
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -94,7 +94,6 @@ void StartGameProtocol::update()
|
||||
m_listener->requestStart(new SynchronizationProtocol());
|
||||
Log::info("StartGameProtocol", "SynchronizationProtocol started.");
|
||||
// race startup sequence
|
||||
|
||||
NetworkWorld::getInstance<NetworkWorld>()->start(); // builds it and starts
|
||||
race_manager->setNumKarts(m_game_setup->getPlayerCount());
|
||||
race_manager->setNumPlayers(m_game_setup->getPlayerCount());
|
||||
|
Loading…
Reference in New Issue
Block a user