Topic: ghost rating
Привет хэрпивару! Вопрос: как правильно настроить это?
{
t_account * acc;
char query[2048];
t_sql_engine *sql = NULL;
t_sql_res * result = NULL;
t_sql_row * Row = NULL;
text = skip_command(text); // Extract command. (Parameters, etc.)
acc = accountlist_find_account(text); // Get account according to the name parameter.
sql = &sql_mysql; // The SQL connection.
if (!sql) // Check if the SQL connection exists.
{
eventlog(eventlog_level_error, __FUNCTION__, "sql layer not initilized"); // The SQL connection does not exist.
return -1;
}
if ( acc != NULL ) // Check if the account is NULL or not.
{
// Run some bad-ass SQL query.
snprintf(query,sizeof(query),"select totgames,wins,losses,killstotal,deathstotal,creepkillstotal,creepdeniestotal,assiststotal,neutralkillstotal,towerkillstotal,raxkillstotal,courierkillstotal,kills,deaths,creepkills,creepdenies,assists,neutralkills,towerkills,raxkills,courierkills, server from(select *, (kills/deaths) as killdeathratio, (totgames-wins) as losses from (select gp.name as name,ga.server as server,gp.gameid as gameid, gp.colour as colour, avg(dp.courierkills) as courierkills, sum(dp.raxkills) as raxkillstotal, sum(dp.towerkills) as towerkillstotal, sum(dp.assists) as assiststotal,sum(dp.courierkills) as courierkillstotal, sum(dp.creepdenies) as creepdeniestotal, sum(dp.creepkills) as creepkillstotal,sum(dp.neutralkills) as neutralkillstotal, sum(dp.deaths) as deathstotal, sum(dp.kills) as killstotal,avg(dp.raxkills) as raxkills,avg(dp.towerkills) as towerkills, avg(dp.assists) as assists, avg(dp.creepdenies) as creepdenies, avg(dp.creepkills) as creepkills,avg(dp.neutralkills) as neutralkills, avg(dp.deaths) as deaths, avg(dp.kills) as kills,count(*) as totgames, SUM(case when((dg.winner = 1 and dp.newcolour < 6) or (dg.winner = 2 and dp.newcolour > 6)) then 1 else 0 end) as wins from gameplayers as gp, dotagames as dg, games as ga,dotaplayers as dp where dg.winner <> 0 and dp.gameid = gp.gameid and dg.gameid = dp.gameid and dp.gameid = ga.id and gp.gameid = dg.gameid and gp.colour = dp.colour and gp.name='%s' group by gp.name) as h) as i", account_get_name(acc));
result = sql->query_res(query); // Copy the result of the query.
eventlog(eventlog_level_error,__FUNCTION__,query); // Log the query, as an error(?)
if (result != NULL) // Check if the query didn't return NULL or is NULL.
{
if (sql->num_rows(result) < 1) // Check if the user has played any games on linked bots.
{
message_send_text(c,message_type_error,c,"Rating Doesnt exist"); // No entries found.
sql->free_result(result);
return 0;
}
while ((Row = sql->fetch_row(result)) != NULL) // Now we run through all rows found in the result of the query.
{
uint32_t TotalGames = std::atoi( Row[0] );
if( TotalGames > 0 ) // Make sure the row has at least a total amount of games played higher than zero.
{
// Parsing is done here. No comments needed.
uint32_t TotalWins = std::atoi( Row[1] );
uint32_t TotalLosses = std::atoi( Row[2] );
uint32_t TotalKills = std::atoi( Row[3] );
uint32_t TotalDeaths = std::atoi( Row[4] );
uint32_t TotalCreepKills = std::atoi( Row[5] );
uint32_t TotalCreepDenies = std::atoi( Row[6] );
uint32_t TotalAssists = std::atoi( Row[7] );
uint32_t TotalNeutralKills = std::atoi( Row[8] );
uint32_t TotalTowerKills = std::atoi( Row[9] );
uint32_t TotalRaxKills = std::atoi( Row[10] );
uint32_t TotalCourierKills = std::atoi( Row[11] );
double wpg = 0;
double lpg = 0;
double kpg = (double)TotalKills/TotalGames;
double dpg = (double)TotalDeaths/TotalGames;
double ckpg = (double)TotalCreepKills/TotalGames;
double cdpg = (double)TotalCreepDenies/TotalGames;
double apg = (double)TotalAssists/TotalGames;
double nkpg = (double)TotalNeutralKills/TotalGames;
double tkpg = (double)TotalTowerKills/TotalGames;
double rkpg = (double)TotalRaxKills/TotalGames;
double coukpg = (double)TotalCourierKills/TotalGames;
double Score = std::atoi( Row[21] );
uint32_t Rank = 0;
wpg = (double)TotalWins/TotalGames;
lpg = (double)TotalLosses/TotalGames;
wpg = wpg * 100;
lpg = lpg * 100;
uint32_t leavecount = 0;
// Make the sendable text and send it.
snprintf(msgtemp, sizeof(msgtemp), "Rating >> S/W/L/K/D/CK/CD/A/NK/TK/RK/CK %d/%u/%u/%u/%u/%u/%u/%u/%u/%u/%u/%u",Score,TotalWins,TotalLosses,TotalKills,TotalDeaths,TotalCreepKills,TotalCreepDenies,TotalAssists,TotalNeutralKills,TotalTowerKills,TotalRaxKills,TotalCourierKills);
message_send_text(c,message_type_info,c,msgtemp);
return 0;
}
else
{
// Return this when there are no games found for this user.
message_send_text(c,message_type_error,c,"No Game");
return 0;
}
}
}
}
else
{
snprintf(msgtemp, sizeof(msgtemp), "User was not found : %s",text);
message_send_text(c,message_type_error,c,msgtemp);
return 0;
}
message_send_text(c,message_type_error,c,"User was not found : %s",text);
return 0;
}
При компиляции следующие ошибки:
1>..\..\..\src\bnetd\command.cpp(2244) : error C2065: t_sql_engine: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2244) : error C2065: sql: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2245) : error C2065: t_sql_res: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2245) : error C2065: result: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2246) : error C2065: t_sql_row: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2246) : error C2065: Row: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2251) : error C2065: sql: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2251) : error C2065: sql_mysql: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2252) : error C2065: sql: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2261) : error C2065: result: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2261) : error C2065: sql: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2261) : error C2227: выражение слева от "->query_res" должно указывать на тип класса, структуры или объединения либо на универсальный тип
1> тип: 'unknown-type'
1>..\..\..\src\bnetd\command.cpp(2263) : error C2065: result: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2265) : error C2065: sql: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2265) : error C2227: выражение слева от "->num_rows" должно указывать на тип класса, структуры или объединения либо на универсальный тип
1> тип: 'unknown-type'
1>..\..\..\src\bnetd\command.cpp(2265) : error C2065: result: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2268) : error C2065: sql: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2268) : error C2227: выражение слева от "->free_result" должно указывать на тип класса, структуры или объединения либо на универсальный тип
1> тип: 'unknown-type'
1>..\..\..\src\bnetd\command.cpp(2268) : error C2065: result: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2271) : error C2065: Row: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2271) : error C2065: sql: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2271) : error C2227: выражение слева от "->fetch_row" должно указывать на тип класса, структуры или объединения либо на универсальный тип
1> тип: 'unknown-type'
1>..\..\..\src\bnetd\command.cpp(2271) : error C2065: result: необъявленный идентификатор
1>..\..\..\src\bnetd\command.cpp(2271) : fatal error C1903: не удается восстановить после предыдущих ошибок; остановка компиляции
1>Журнал построения был сохранен в "file://c:\Games\pvpgn\pvpgn\builder\src\bnetd\bnetd.dir\Release\BuildLog.htm"
1>bnetd - ошибок 24, предупреждений 1
========== Построение: успешно: 0, с ошибками: 1, без изменений: 23, пропущено: 0 ==========