Topic: Делаем команду /stats похожую как на сервере iCCup.
Всем привет, думаю многие досихпор не нашли полноценного ответа как сделать /stats как в ICCup'e.
Так давайте начнем...
Для начала нужно игрового бота GHost One (Ghost ++, BRT) заставить писать данные статистики в таблицу bnet.
Теперь идем к pvpgn
Открываем проект pvpgn
Открываем заголовочный файл account_wrap.h
ищем код
extern int account_set_ll_ip(t_account * account, char const * ip);
после него вставляем это:
extern int account_get_pts(t_account * account);
extern unsigned int account_get_top(t_account * account);
extern int account_get_wins(t_account * account);
extern int account_get_losses(t_account * account);
extern int account_get_winspcnt(t_account * account);
extern int account_get_leavescnt(t_account * account);
extern int account_get_leavespcnt(t_account * account);
extern int account_get_kills(t_account * account);
extern int account_get_deaths(t_account * account);
extern int account_get_assists(t_account * account);
extern char const * account_get_percentsymbols(t_account * account);
extern char const * account_get_rank(t_account * account);
Теперь идем к account_wrap.cpp (в PRO версии .c)
ищем строрчки
extern int account_set_ll_ip(t_account * account, char const * ip)
{
return account_set_strattr(account,"BNET\\acct\\lastlogin_ip",ip);
}
/****************************************************************/
и после вставляем это:
extern int account_get_pts(t_account * account)
{
return account_get_numattr(account, "BNET\\pts");
}
extern char const * account_get_rank(t_account * account)
{
return account_get_strattr(account, "BNET\\rank");
}
extern char const * account_get_percentsymbols(t_account * account)
{
return account_get_strattr(account, "BNET\\percentsymbols");
}
extern int account_get_winspcnt(t_account * account)
{
return account_get_numattr(account, "BNET\\winspcnt");
}
extern int account_get_wins(t_account * account)
{
return account_get_numattr(account, "BNET\\wins");
}
extern int account_get_losses(t_account * account)
{extern int account_set_ll_ip(t_account * account, char const * ip);
return account_get_numattr(account, "BNET\\losses");
}
extern int account_get_leavescnt(t_account * account)
{
return account_get_numattr(account, "BNET\\leavescount");
}
extern int account_get_leavespcnt(t_account * account)
{
return account_get_numattr(account, "BNET\\leavespcnt");
}
extern int account_get_kills(t_account * account)
{
return account_get_numattr(account, "BNET\\kills");
}
extern int account_get_deaths(t_account * account)
{
return account_get_numattr(account, "BNET\\deaths");
}
extern int account_get_assists(t_account * account)
{
return account_get_numattr(account, "BNET\\assists");
}
extern unsigned int account_get_top(t_account * account)
{
return account_get_numattr(account, "BNET\\top");
}
Теперь идем к command.cpp (в PRO версии command.c)
ищем
static int _handle_stats_command(t_connection *c, char const *text)
удаляем всё от { до }
и вставляем
static int _handle_stats_command(t_connection * c, char const *text)
{
text = skip_command(text);
if (text[0] == '\0')
{
t_account * myacc = conn_get_account(c);
char * dotastats = new char[MAX_MESSAGE_LEN];
snprintf(dotastats, MAX_MESSAGE_LEN, "%s DotA(5x5) stats", account_get_name(myacc));
message_send_text(c, message_type_info, c, dotastats);
snprintf(dotastats, MAX_MESSAGE_LEN, "Score: [%s] %d pts", account_get_rank(myacc), account_get_pts(myacc));
message_send_text(c, message_type_info, c, dotastats);
snprintf(dotastats, MAX_MESSAGE_LEN, "Games W/L: %d/%d (Win: %d%s)",
account_get_wins(myacc), account_get_losses(myacc), account_get_winspcnt(myacc), account_get_percentsymbols(myacc));
message_send_text(c, message_type_info, c, dotastats);
snprintf(dotastats, MAX_MESSAGE_LEN, "Hero K/D/A: %d/%d/%d",
account_get_kills(myacc), account_get_deaths(myacc), account_get_assists(myacc));
message_send_text(c, message_type_info, c, dotastats);
snprintf(dotastats, MAX_MESSAGE_LEN, "Leaves: %d(%d%s)",
account_get_leavescnt(myacc), account_get_leavespcnt(myacc), account_get_percentsymbols(myacc));
message_send_text(c, message_type_info, c, dotastats);
delete[]dotastats;
}
else
{
t_account * myacc;
if (!(myacc = accountlist_find_account(text)))
{
message_send_text(c, message_type_error, c, "Неизвестный пользователь!");
}
else
{
char * dotastats = new char[MAX_MESSAGE_LEN];
snprintf(dotastats, MAX_MESSAGE_LEN, "%s DotA(5x5) stats", account_get_name(myacc));
message_send_text(c, message_type_error, c, dotastats);
snprintf(dotastats, MAX_MESSAGE_LEN, "Score: [%s] %d pts",
account_get_rank(myacc), account_get_pts(myacc));
message_send_text(c, message_type_info, c, dotastats);
snprintf(dotastats, MAX_MESSAGE_LEN, "Games W/L: %d/%d (Win: %d%s)",
account_get_wins(myacc), account_get_losses(myacc), account_get_winspcnt(myacc), account_get_percentsymbols(myacc));
message_send_text(c, message_type_info, c, dotastats);
snprintf(dotastats, MAX_MESSAGE_LEN, "Hero K/D/A: %d/%d/%d",
account_get_kills(myacc), account_get_deaths(myacc), account_get_assists(myacc));
message_send_text(c, message_type_info, c, dotastats);
snprintf(dotastats, MAX_MESSAGE_LEN, "Leaves: %d(%d%s)",
account_get_leavescnt(myacc), account_get_leavespcnt(myacc), account_get_percentsymbols(myacc));
message_send_text(c, message_type_info, c, dotastats);
delete[]dotastats;
}
}
return 0;
}
И компилируем.
И теперь идем к запросам базы:
Делаем запрос SQL(Спасибо ув. Serc):
ALTER TABLE Перфикс_bnet ADD games INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD wins INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD winspcnt INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD losses INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD winspcnt INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD kills INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD deaths INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD assists INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD pts INT DEFAULT '1000' NOT NULL;
ALTER TABLE Перфикс_bnet ADD rank varchar(32) DEFAULT 'D' NOT NULL;
ALTER TABLE Перфикс_bnet ADD percentsymbols varchar(32) DEFAULT '%' NOT NULL;
ALTER TABLE Перфикс_bnet ADD leavescount INT DEFAULT '0' NOT NULL;
ALTER TABLE Перфикс_bnet ADD leavespcnt INT DEFAULT '0' NOT NULL;
Запускаем сервер и проверяем статистику командой /stats