Topic: /shop /money /lt /stats
новые команды для сервера (кроме /stats)
/shop - магазин покупок
/money - счет игрока
/lt - лотарея
/stats - статистика игрока
В command.cpp добавим
static int _handle_money_command( t_connection * c , char const * text );
static int _handle_shop_command( t_connection * c , char const * text );
static int _handle_lt_command( t_connection * c , char const * text );
{ "/money" , _handle_money_command },
{ "/shop" , _handle_shop_command },
{ "/lt" , _handle_lt_command },
static int _handle_money_command(t_connection * c, char const * text)
{
text = skip_command( text );
if ( text[ 0 ] == '\0' )
{
t_account * myacc = conn_get_account( c );
char * bnetmoney = new char[ MAX_MESSAGE_LEN ];
snprintf( bnetmoney , MAX_MESSAGE_LEN , "Ваш счет: %d золота", account_get_money(myacc));
message_send_text( c , message_type_info , c , bnetmoney );
delete[ ]bnetmoney;
}
else
{
t_account * myacc;
if ( !( myacc = accountlist_find_account( text ) ) )
{
message_send_text( c , message_type_info , c , "Неизвестный пользователь!" );
}
else
{
char * bnetmoney = new char[ MAX_MESSAGE_LEN ];
snprintf(bnetmoney, MAX_MESSAGE_LEN, "Счет игрока %s: %d золота", account_get_name(myacc),account_get_money(myacc));
message_send_text(c, message_type_info, c, bnetmoney);
delete[ ]bnetmoney;
}
}
return 0;
}
static int _handle_shop_command(t_connection * c, char const *text)
{
t_account * account;
account = conn_get_account(c);
char const * username, *hours = "240";
unsigned int sectime;
char * command;
char * code;
char * pts;
char t[MAX_MESSAGE_LEN];
unsigned int i,j;
char arg1[256];
char arg2[256];
char arg3[256];
std::strncpy(t, text, MAX_MESSAGE_LEN - 1);
for (i=0; t[i]!=' ' && t[i]!='\0'; i++); /* skip command /groups */
for (; t[i]==' '; i++); /* skip spaces */
for (j=0; t[i]!=' ' && t[i]!='\0'; i++) /* get command */
if (j<sizeof(arg1)-1) arg1[j++] = t[i];
arg1[j] = '\0';
for (; t[i]==' '; i++); /* skip spaces */
for (j=0; t[i]!=' ' && t[i]!='\0'; i++) /* get username */
if (j<sizeof(arg2)-1) arg2[j++] = t[i];
arg2[j] = '\0';
for (; t[i]==' '; i++); /* skip spaces */
for (j=0; t[i]!=' ' && t[i]!='\0'; i++) /* get username */
if (j<sizeof(arg3)-1) arg3[j++] = t[i];
arg3[j] = '\0';
command = arg1;
code = arg2;
pts = arg3;
if (arg1[0] =='\0') {
message_send_text(c,message_type_info,c,"используйте: /shop <купить> <вещь>");
message_send_text(c,message_type_info,c,"используйте: /shop list - список вещей для покупки");
return 0;
}
if (!std::strcmp(command,"list") || !std::strcmp(command,"l")) {
message_send_text(c,message_type_info,c,"Вещи для покупки:");
message_send_text(c,message_type_info,c,"Про аккаунт ( 50 золота на 10 дней )(код: pro)");
message_send_text(c,message_type_info,c,"Птс ( 5 золота = 50 птс )(код: pts)");
message_send_text(c,message_type_info,c,"Очистка статистики ( 5 золота )(код: clearstats)");
message_send_text(c,message_type_info,c,"Лотерейный билет(/lt) ( 5 золота )(код: lbilet)");
return 0;
}
if (arg2[0] =='\0') {
message_send_text(c,message_type_info,c,"usage: /shop <купить> <вещь>");
return 0;
}
if (account_get_money(account)<=4)
{
message_send_text(c,message_type_info,c,"У вас не хватает золота!");
}
else if (!std::strcmp(code,"clearstats") || !std::strcmp(code,"очистка") || !std::strcmp(code,"очистка статистики")) {
account_set_pts(account,1000);
account_set_money(account,account_get_money(account) - 5);
message_send_text(c,message_type_info,c,"Вы успешно очистили свою статистику");
}
else if (!std::strcmp(code,"pts") || !std::strcmp(code,"птс")) {
account_set_money(account,account_get_money(account) - 5);
account_set_pts(account,account_get_pts(account) + 50);
message_send_text(c,message_type_info,c,"Вы получили 50 птс. Блогадарим за покупку.");
}
else if (account_get_money(account)<=9)
{
message_send_text(c,message_type_info,c,"У вас не хватает золота!");
}
else if (!std::strcmp(code,"lbilet") || !std::strcmp(code,"лбилет")) {
account_set_money(account,account_get_money(account) - 10);
account_set_auth_lbilet(account,NULL,1);
message_send_text(c,message_type_info,c,"Вы получили лотарейный билет. Блогадарим за покупку.");
}
else if (account_get_money(account)<=49)
{
message_send_text(c,message_type_info,c,"У вас не хватает золота!");
}
else if (!std::strcmp(code,"pro") || !std::strcmp(code,"про") || !std::strcmp(code,"про аккаунт")) {
account_set_money(account,account_get_money(account) - 50);
account_set_auth_pro(account,NULL,1);
sectime = (atoi(hours) == 0) ? 0 : (atoi(hours) * 60 * 60) + now; // get unlock time in the future
account_set_auth_protime(account, sectime);
account_set_auth_proby(account, conn_get_username(c));
message_send_text(c,message_type_info,c,"Вы получили про аккаунта на 10 дней. Блогадарим за покупку.");
}
else
{
message_send_text(c,message_type_error,c,"Вы не правильно ввели код.");
}
}
static int _handle_lt_command(t_connection * c, char const *text)
{
t_account * account;
account = conn_get_account(c);
char const * username, *hours = "72";
unsigned int sectime;
unsigned int i;
int rnd = rand() % 4;
for (i=0; text[i]!=' ' && text[i]!='\0'; i++); /* skip command */
for (; text[i]==' '; i++);
if (text[i]=='\0')
{
message_send_text(c,message_type_info,c,"используйте: /lt yes - играть лотарею");
return 0;
}
if (account_get_auth_lbilet(account,NULL)==0)
{
message_send_text(c,message_type_info,c,"У вас нету лотарейного билета.");
}
else if (account_get_auth_lbilet(account,NULL)==NULL)
{
message_send_text(c,message_type_info,c,"У тебя нету лотарейного билета.");
}
else if (( rnd == 0 ) && (account_get_auth_lbilet(account,NULL)==1))
{
message_send_text(c,message_type_info,c,"Вы выйграли очистка статистики(clearstats)");
account_set_pts(account,1000);
account_set_auth_lbilet(account,NULL,0);
}
else if (( rnd == 1 ) && (account_get_auth_lbilet(account,NULL)==1))
{
message_send_text(c,message_type_info,c,"Вы выйграли 30 золота");
account_set_money(account,account_get_money(account) + 30);
account_set_auth_lbilet(account,NULL,0);
}
else if (( rnd == 2 ) && (account_get_auth_lbilet(account,NULL)==1))
{
message_send_text(c,message_type_info,c,"Вы выйграли 200 птс");
account_set_pts(account,account_get_pts(account) + 200);
account_set_auth_lbilet(account,NULL,0);
}
else if (( rnd == 3 ) && (account_get_auth_lbilet(account,NULL)==1))
{
account_set_auth_pro(account,NULL,1);
sectime = (atoi(hours) == 0) ? 0 : (atoi(hours) * 60 * 60) + now; // get unlock time in the future
account_set_auth_protime(account, sectime);
account_set_auth_proby(account, conn_get_username(c));
message_send_text(c,message_type_info,c,"Вы выйграли про аккаунта на 3 дней");
account_set_auth_lbilet(account,NULL,0);
}
return 0;
}
В account_wrap.cpp добавим
extern int account_get_auth_lbilet(t_account * account, char const * channelname)
{
char temp[256];
if (!channelname)
return account_get_boolattr(account, "BNET\\auth\\lbilet");
std::sprintf(temp, "BNET\\auth\\lbilet\\%.100s", channelname);
return account_get_boolattr(account, temp);
}
extern int account_set_auth_lbilet(t_account * account, char const * channelname, int val)
{
char temp[256];
if (!channelname)
return account_set_boolattr(account, "BNET\\auth\\lbilet", val);
std::sprintf(temp, "BNET\\auth\\lbilet\\%.100s", channelname);
return account_set_boolattr(account, temp, val);
}
extern int account_set_money(t_account * account, unsigned int val)
{
return account_set_numattr(account, "BNET\\money", val);
}
extern unsigned int account_get_money(t_account * account)
{
return account_get_numattr(account,"BNET\\money");
}
В account_wrap.h
extern int account_set_money(t_account * account, unsigned int val);
extern unsigned int account_get_money(t_account * account);
extern int account_get_auth_lbilet(t_account * account, char const * channelname);
extern int account_set_auth_lbilet(t_account * account, char const * channelname, int val);
далее команда /stats
в account_wrap.cpp добавим
extern unsigned int account_get_wins(t_account * account)
{
return account_get_numattr(account,"stats\\wins");
}
extern unsigned int account_get_looses(t_account * account)
{
return account_get_numattr(account,"stats\\looses");
}
extern unsigned int account_get_pts(t_account * account)
{
return account_get_numattr(account,"stats\\pts");
}
//
extern int account_set_wins(t_account * account, unsigned int val)
{
return account_set_numattr(account, "stats\\wins", val);
}
extern int account_set_looses(t_account * account, unsigned int val)
{
return account_set_numattr(account, "stats\\looses", val);
}
extern int account_set_pts(t_account * account, unsigned int val)
{
return account_set_numattr(account, "stats\\pts", val);
}
В account_wrap.h добавим
extern unsigned int account_get_wins(t_account * account);
extern unsigned int account_get_looses(t_account * account);
extern unsigned int account_get_pts(t_account * account);
extern int account_set_wins(t_account * account, unsigned int val);
extern int account_set_looses(t_account * account, unsigned int val);
extern int account_set_pts(t_account * account, unsigned int val);
В command.cpp добавим
static int _handle_stats_command(t_connection * c, char const * text)
{
unsigned int i;
text = skip_command( text );
t_connection * user;
t_game * game;
if ( text[ 0 ] == '\0' )
{
t_account * myacc = conn_get_account( c );
char * dotastats = new char[ MAX_MESSAGE_LEN ];
snprintf( dotastats , MAX_MESSAGE_LEN , "DotA 5x5: [Wins: %u / Looses: %u] %d pts" ,
account_get_wins(myacc), account_get_looses(myacc) , account_get_pts(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_info , c , "Неизвестный пользователь!" );
}
else
{
char * dotastats = new char[ MAX_MESSAGE_LEN ];
snprintf(dotastats, MAX_MESSAGE_LEN, "%s's DotA 5x5: [Wins: %u / Looses: %u] %d pts", account_get_name(myacc),
account_get_wins(myacc), account_get_looses(myacc), account_get_pts(myacc));
message_send_text(c, message_type_info, c, dotastats);
delete[ ]dotastats;
}
}
return 0;
}