Example #1
0
/**
 *  (Lobby-)RankingInfo: Rankinginfo eines bestimmten Benutzers empfangen
 */
void dskHostGame::LC_RankingInfo(const LobbyPlayerInfo& player)
{
    for(unsigned int i = 0; i < GAMECLIENT.GetPlayerCount(); ++i)
    {
        if(GAMECLIENT.GetPlayer(i).name == player.getName())
            GAMECLIENT.GetPlayer(i).rating = player.getPunkte();
    }
}
/**
 *  Lobby-Ranking-Info Nachricht.
 *
 *  @param[in] email Die PlayerInfo des angefragten Spielers.
 *
 *  @author FloSoft
 */
void LobbyServer::OnNMSLobbyRankingInfo(unsigned int id, const LobbyPlayerInfo& player)
{
    LobbyPlayerInfo p = player;

    if(!MYSQLCLIENT.GetRankingInfo(p))
        LOG.write("Failed to lookup Ranking of player %s!\n") % p.getName();

    SendToAll(LobbyMessage_Lobby_Ranking_Info(p));
}
Example #3
0
/**
 *
 *
 *
 *  @author FloSoft
 */
bool MySQL::GetRankingInfo(LobbyPlayerInfo& player)
{
    MYSQL_RES*   pResult;
    MYSQL_ROW   Row;
    char query[1024];

    char name[256];
    mysql_real_escape_string(m_pMySQL, name, player.getName().c_str(), (unsigned long)player.getName().length());

    //snprintf(query, 1024, "SELECT username, win, lose FROM `tb_user` WHERE `username` = '%s' LIMIT 1;", name);
    snprintf(query, 1024, "SELECT user, win, lose FROM `users` WHERE `user` = '%s' LIMIT 1;", name);

    if(!DoQuery(query))
        return false;

    pResult = mysql_store_result(m_pMySQL);

    if(mysql_num_rows(pResult) == 0)
    {
        mysql_free_result(pResult);
        return true;
    }

    Row = mysql_fetch_row(pResult);

    int punkte = atoi(Row[1]) * 100 - atoi(Row[2]) * 70;
    if(punkte < 0)
        punkte = 0;

    //player.setId(0);
    player.setName(Row[0]);
    player.setGewonnen(atoi(Row[1]));
    player.setVerloren(atoi(Row[2]));
    player.setPunkte(punkte);

    mysql_free_result(pResult);

    return true;
}
Example #4
0
bool MySQL::GetRankingList(LobbyPlayerList* List)
{
    MYSQL_RES*   pResult;
    MYSQL_ROW   Row;

    char query[1024];
    //snprintf(query, 1024, "SELECT username, win, lose FROM `tb_user` WHERE `useremail` IS NOT NULL AND (`win` > 0 OR `lose` > 0) ORDER BY `win` DESC, `lose` ASC LIMIT 10;");
    snprintf(query, 1024, "SELECT user, win, lose FROM `users` WHERE `mail` IS NOT NULL AND (`win` > 0 OR `lose` > 0) ORDER BY `win` DESC, `lose` ASC LIMIT 10;");

    if(!DoQuery(query))
        return false;

    pResult = mysql_store_result(m_pMySQL);

    unsigned int count = (unsigned int)mysql_num_rows(pResult);

    if(count == 0)
    {
        mysql_free_result(pResult);
        return true;
    }

    for(unsigned int i = 0; i < count; i++)
    {
        Row = mysql_fetch_row(pResult);

        int punkte = atoi(Row[1]) * 100 - atoi(Row[2]) * 70;
        if(punkte < 0)
            punkte = 0;

        LobbyPlayerInfo player;
        player.setId(i + 1);
        player.setName(Row[0]);
        player.setGewonnen(atoi(Row[1]));
        player.setVerloren(atoi(Row[2]));
        player.setPunkte(punkte);

        List->push_back(player);
    }

    mysql_free_result(pResult);

    return true;
}