// ----------------------------------------------------------------------------
void CreateServerScreen::serverCreationRequest()
{
    const irr::core::stringw name = m_name_widget->getText().trim();
    const int max_players = m_max_players_widget->getValue();
    m_info_widget->setErrorColor();
    if (name.size() < 4 || name.size() > 30)
    {
        m_info_widget->setText(_("Name has to be between 4 and 30 characters long!"), false);
    }
    else if (max_players < 2 || max_players > 12)
    {
        m_info_widget->setText(_("The maxinum number of players has to be between 2 and 12."), false);
    }
    else
    {

        m_server_creation_request = new ServerCreationRequest();
        CurrentUser::setUserDetails(m_server_creation_request);
        m_server_creation_request->addParameter("action", "create_server");
        m_server_creation_request->addParameter("name", name);
        m_server_creation_request->addParameter("max_players", max_players);
        m_server_creation_request->queue();

        return;
    }
    sfx_manager->quickSound("anvil");
}
/** In case of WAN it adds the server to the list of servers. In case of LAN
 *  networking, it registers this game server with the stk server.
 */
void CreateServerScreen::createServer()
{
    const irr::core::stringw name = m_name_widget->getText().trim();
    const int max_players = m_max_players_widget->getValue();
    m_info_widget->setErrorColor();
    if (name.size() < 4 || name.size() > 30)
    {
        m_info_widget->setText(
            _("Name has to be between 4 and 30 characters long!"), false);
        SFXManager::get()->quickSound("anvil");
        return;
    }
    else if (max_players < 2 || max_players > 12)
    {
        m_info_widget->setText(
            _("The maxinum number of players has to be between 2 and 12."),
            false);
        SFXManager::get()->quickSound("anvil");
        return;
    }

    // In case of a LAN game, we can create the new server object now
    if (NetworkConfig::get()->isLAN())
    {
        // FIXME Is this actually necessary?? Only in case of WAN, or LAN and WAN?
        TransportAddress address(0x7f000001,0);  // 127.0.0.1
        Server *server = new Server(name, /*lan*/true, max_players,
                                    /*current_player*/1, address);
        ServersManager::get()->addServer(server);
    }

    // In case of a WAN game, we register this server with the
    // stk server, and will get the server's id when this 
    // request is finished.
    NetworkConfig::get()->setMaxPlayers(max_players);
    NetworkConfig::get()->setServerName(name);

    // FIXME: Add the following fields to the create server screen
    // FIXME: Long term we might add a 'vote' option (e.g. GP vs single race,
    // and normal vs FTL vs time trial could be voted about).
    race_manager->setDifficulty(RaceManager::convertDifficulty("hard"));
    race_manager->setMajorMode(RaceManager::MAJOR_MODE_SINGLE);
    race_manager->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE);
    race_manager->setReverseTrack(false);
    STKHost::create();

}   // createServer
    /** Splits a string into substrings separated by a certain character, and
     *  returns a std::vector of all those substring. E.g.:
     *  split("a b=c d=e",' ')  --> ["a", "b=c", "d=e"]
     *  This is the version for wide strings.
     *  \param s The string to split.
     *  \param c The character  by which the string is split.
     */
    std::vector<irr::core::stringw> split(const irr::core::stringw& s, char c,
                                           bool keepSplitChar)
    {
        try
        {
            std::vector<irr::core::stringw> result;

            irr::s32 start = 0;
            while (start < (irr::s32)s.size())
            {
                irr::s32 i = s.findNext(c, start);
                if (i != -1)
                {
                    if (keepSplitChar)
                    {
                        int from = start-1;
                        if (from < 0) from = 0;
                        result.push_back( s.subString(from, i-from) );
                    }
                    else result.push_back( s.subString(start, i-start) );
                    start = i+1;
                }
                else
                {
                    if (keepSplitChar)
                        result.push_back( s.subString(start - 1,
                                                      s.size()-start + 1) );
                    else
                        result.push_back( s.subString(start, s.size()-start) );

                    return result;
                    //start = i+1;
                }
            }
            return result;
        }
        catch (std::exception& e)
        {
            (void)e;  // avoid warning about unused variable
            Log::fatal("StringUtils",
                       "Fatal error in split(stringw) : %s @ line %i : '%s'.",
                       __FILE__, __LINE__, e.what());
            exit(1);
        }
    }   // split
Example #4
0
/** Checks if the input string is not empty. ( = has characters different
 *  from a space).
 */
bool notEmpty(const irr::core::stringw& input)
{
    const int size = input.size();
    int nonEmptyChars = 0;
    for (int n=0; n<size; n++)
    {
        if (input[n] != L' ')
        {
            nonEmptyChars++;
        }
    }
    return (nonEmptyChars > 0);
}   // getExtension
Example #5
0
/** Converts a unicode string to plain ASCII using XML entites (e.g. &x00;)
 *  \param s The input string which should be encoded.
 *  \return A std:;string with ASCII characters.
 */
std::string xmlEncode(const irr::core::stringw &s)
{
    std::ostringstream output;
    for(unsigned int i=0; i<s.size(); i++)
    {
        if (s[i] >= 128 || s[i] == '&' || s[i] == '<' || s[i] == '>' || s[i] == '\"')
        {
            output << "&#x" << std::hex << std::uppercase << s[i] << ";";
        }
        else
        {
            irr::c8 c = (char)(s[i]);
            output << c;
        }
    }
    return output.str();
}   // xmlEncode
 /** Converts a unicode string to plain ASCII using html-like & codes.
  *  \param s The input string which should be encoded.
  *  \return A std:;string with ASCII characters.
  */
 std::string encodeToHtmlEntities(const irr::core::stringw &s)
 {
     std::ostringstream output;
     for(unsigned int i=0; i<s.size(); i++)
     {
         if(s[i]=='&')
             output<<"&amp;";
         else
         {
             if(s[i]<128)
             {
                 irr::c8 c=(char)(s[i]);
                 output<<c;
             }
             else
             {
                 output <<"&#x" << std::hex <<std::uppercase<< s[i]<<";";
             }
         }
     }
     return output.str();
 }   // encodeToHtmlEntities