Skip to content

Commit

Permalink
Improvements for commands:
Browse files Browse the repository at this point in the history
/lock <player> [hours] [reason]
/mute <player> [hours] [reason]

#3
  • Loading branch information
HarpyWar committed Apr 27, 2014
1 parent 50e8531 commit 8638b17
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 25 deletions.
82 changes: 74 additions & 8 deletions src/bnetd/account_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,28 +361,94 @@ namespace pvpgn

extern int account_get_auth_lock(t_account * account)
{
return account_get_boolattr(account, "BNET\\auth\\lockk");
// check for unlock
if (unsigned int locktime = account_get_auth_locktime(account))
{
if ((locktime - std::time(NULL)) < 0)
{
account_set_auth_lock(account, 0);
account_set_auth_locktime(account, 0);
account_set_auth_lockreason(account, "");
account_set_auth_lockby(account, "");
}
}
return account_get_boolattr(account, "BNET\\auth\\lock");
}
extern unsigned int account_get_auth_locktime(t_account * account)
{
return account_get_numattr(account, "BNET\\auth\\locktime");
}
extern char const * account_get_auth_lockreason(t_account * account)
{
return account_get_strattr(account, "BNET\\auth\\lockreason");
}
extern char const * account_get_auth_lockby(t_account * account)
{
return account_get_strattr(account, "BNET\\auth\\lockby");
}


extern int account_set_auth_lock(t_account * account, int val)
{
return account_set_boolattr(account, "BNET\\auth\\lockk", val);
return account_set_boolattr(account, "BNET\\auth\\lock", val);
}


extern int account_set_auth_mute(t_account * account, int val)
extern int account_set_auth_locktime(t_account * account, unsigned int val)
{
return account_set_boolattr(account, "BNET\\auth\\mute", val);
return account_set_numattr(account, "BNET\\auth\\locktime", val);
}
extern int account_set_auth_lockreason(t_account * account, char const * val)
{
return account_set_strattr(account, "BNET\\auth\\lockreason", val);
}
extern int account_set_auth_lockby(t_account * account, char const * val)
{
return account_set_strattr(account, "BNET\\auth\\lockby", val);
}


extern int account_get_auth_mute(t_account * account)
{
// check for unmute
if (unsigned int locktime = account_get_auth_mutetime(account))
{
if ((locktime - std::time(NULL)) < 0)
{
account_set_auth_mute(account, 0);
account_set_auth_mutetime(account, 0);
account_set_auth_mutereason(account, "");
account_set_auth_muteby(account, "");
}
}
return account_get_boolattr(account, "BNET\\auth\\mute");
}
extern unsigned int account_get_auth_mutetime(t_account * account)
{
return account_get_numattr(account, "BNET\\auth\\mutetime");
}
extern char const * account_get_auth_mutereason(t_account * account)
{
return account_get_strattr(account, "BNET\\auth\\mutereason");
}
extern char const * account_get_auth_muteby(t_account * account)
{
return account_get_strattr(account, "BNET\\auth\\muteby");
}


extern int account_set_auth_mute(t_account * account, int val)
{
return account_set_boolattr(account, "BNET\\auth\\mute", val);
}
extern int account_set_auth_mutetime(t_account * account, unsigned int val)
{
return account_set_numattr(account, "BNET\\auth\\mutetime", val);
}
extern int account_set_auth_mutereason(t_account * account, char const * val)
{
return account_set_strattr(account, "BNET\\auth\\mutereason", val);
}
extern int account_set_auth_muteby(t_account * account, char const * val)
{
return account_set_strattr(account, "BNET\\auth\\muteby", val);
}

/****************************************************************/

Expand Down
14 changes: 13 additions & 1 deletion src/bnetd/account_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,21 @@ namespace pvpgn
extern int account_get_auth_createladdergame(t_account * account);
extern int account_get_auth_joinladdergame(t_account * account);
extern int account_get_auth_lock(t_account * account);
extern unsigned int account_get_auth_locktime(t_account * account);
extern char const * account_get_auth_lockreason(t_account * account);
extern char const * account_get_auth_lockby(t_account * account);
extern int account_set_auth_lock(t_account * account, int val);
extern int account_set_auth_mute(t_account * account, int val);
extern int account_set_auth_locktime(t_account * account, unsigned int val);
extern int account_set_auth_lockreason(t_account * account, char const * val);
extern int account_set_auth_lockby(t_account * account, char const * val);
extern int account_get_auth_mute(t_account * account);
extern unsigned int account_get_auth_mutetime(t_account * account);
extern char const * account_get_auth_mutereason(t_account * account);
extern char const * account_get_auth_muteby(t_account * account);
extern int account_set_auth_mute(t_account * account, int val);
extern int account_set_auth_mutetime(t_account * account, unsigned int val);
extern int account_set_auth_mutereason(t_account * account, char const * val);
extern int account_set_auth_muteby(t_account * account, char const * val);

/* profile */
extern char const * account_get_sex(t_account * account); /* the profile attributes are updated directly in bnetd.c */
Expand Down
31 changes: 30 additions & 1 deletion src/bnetd/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "compat/strdup.h"
#include "compat/strcasecmp.h"
#include "compat/snprintf.h"
#include "common/eventlog.h"
#include "common/list.h"
#include "common/util.h"
Expand Down Expand Up @@ -669,9 +670,37 @@ namespace pvpgn
if (type != message_type_join && type != message_type_part)
return;

// if user muted
if (account_get_auth_mute(acc) == 1)
{
message_send_text(me, message_type_error, me, "Your account has been muted, you can't talk on the channel.");
char msgtemp[MAX_MESSAGE_LEN], msgtemp2[MAX_MESSAGE_LEN];

snprintf(msgtemp, sizeof(msgtemp), "You can't talk on the channel. Your account has been muted");

// append author of ban
char const * author = account_get_auth_muteby(acc);
if (author && author[0] != '\0')
{
snprintf(msgtemp2, sizeof(msgtemp2), " by %s", author);
std::strcat(msgtemp, msgtemp2);
}

// append remaining time
if (unsigned int locktime = account_get_auth_mutetime(acc))
snprintf(msgtemp2, sizeof(msgtemp2), " for %.48s", seconds_to_timestr(locktime - std::time(NULL)));
else
snprintf(msgtemp2, sizeof(msgtemp2), " permanently");
std::strcat(msgtemp, msgtemp2);

// append reason
char const * reason = account_get_auth_mutereason(acc);
if (reason && reason[0] != '\0')
{
snprintf(msgtemp2, sizeof(msgtemp2), " with a reason \"%s\"", reason);
std::strcat(msgtemp, msgtemp2);
}

message_send_text(me, message_type_error, me, msgtemp);
return;
}

Expand Down
92 changes: 80 additions & 12 deletions src/bnetd/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4204,25 +4204,59 @@ namespace pvpgn
{
t_connection * user;
t_account * account;
char const * username, *reason = "", *hours = "24"; // default time 24 hours
unsigned int sectime;
char msgtemp3[MAX_MESSAGE_LEN];

std::vector<std::string> args = split_command(text, 1);
std::vector<std::string> args = split_command(text, 3);
if (args[1].empty())
{
describe_command(c, args[0].c_str());
return -1;
}
text = args[1].c_str(); // username
username = args[1].c_str(); // username
if (!args[2].empty())
hours = args[2].c_str(); // hours
if (!args[3].empty())
reason = args[3].c_str(); // reason

if (!(account = accountlist_find_account(text)))
if (!(account = accountlist_find_account(username)))
{
message_send_text(c, message_type_error, c, "Invalid user.");
return 0;
}
if ((user = connlist_find_connection_by_accountname(text)))
message_send_text(user, message_type_info, user, "Your account has just been locked by an admin.");

account_set_auth_lock(account, 1);
message_send_text(c, message_type_error, c, "That user's account is now locked.");
sectime = (atoi(hours) == 0) ? 0 : (atoi(hours) * 60 * 60) + now; // get unlock time in the future
account_set_auth_locktime(account, sectime);
account_set_auth_lockreason(account, reason);
account_set_auth_lockby(account, conn_get_username(c));


// append remaining time
if (sectime == 0)
snprintf(msgtemp3, sizeof(msgtemp3), " permanently");
else
snprintf(msgtemp3, sizeof(msgtemp3), " for %.48s", seconds_to_timestr(sectime - now));

// append reason
if (reason[0] != '\0')
{
snprintf(msgtemp2, sizeof(msgtemp2), " with a reason \"%s\"", reason);
std::strcat(msgtemp3, msgtemp2);
}

// send message to author
snprintf(msgtemp, sizeof(msgtemp), "Account %s is now locked%s", account_get_name(account), msgtemp3);
message_send_text(c, message_type_error, c, msgtemp);

// send message to locked user
if ((user = connlist_find_connection_by_accountname(username)))
{
snprintf(msgtemp, sizeof(msgtemp), "Your account has just been locked by %s%s", conn_get_username(c), msgtemp3);
message_send_text(user, message_type_info, user, msgtemp);
}

return 0;
}

Expand Down Expand Up @@ -4258,25 +4292,59 @@ namespace pvpgn
{
t_connection * user;
t_account * account;
char const * username, *reason = "", *hours = "1"; // default time 1 hour
unsigned int sectime;
char msgtemp3[MAX_MESSAGE_LEN];

std::vector<std::string> args = split_command(text, 1);
std::vector<std::string> args = split_command(text, 3);
if (args[1].empty())
{
describe_command(c, args[0].c_str());
return -1;
}
text = args[1].c_str(); // username
username = args[1].c_str(); // username
if (!args[2].empty())
hours = args[2].c_str(); // hours
if (!args[3].empty())
reason = args[3].c_str(); // reason

if (!(account = accountlist_find_account(text)))
if (!(account = accountlist_find_account(username)))
{
message_send_text(c, message_type_error, c, "Invalid user.");
return 0;
}
if ((user = connlist_find_connection_by_accountname(text)))
message_send_text(user, message_type_info, user, "Your account has just been muted by an admin.");

account_set_auth_mute(account, 1);
message_send_text(c, message_type_error, c, "That user's account is now muted.");
// get unlock time in the future
sectime = (atoi(hours) == 0) ? 0 : (atoi(hours) * 60 * 60) + now;
account_set_auth_mutetime(account, sectime);
account_set_auth_mutereason(account, reason);
account_set_auth_muteby(account, conn_get_username(c));

// append remaining time
if (sectime == 0)
snprintf(msgtemp3, sizeof(msgtemp3), " permanently");
else
snprintf(msgtemp3, sizeof(msgtemp3), " for %.48s", seconds_to_timestr(sectime - now));

// append reason
if (reason[0] != '\0')
{
snprintf(msgtemp2, sizeof(msgtemp2), " with a reason \"%s\"", reason);
std::strcat(msgtemp3, msgtemp2);
}

// send message to author
snprintf(msgtemp, sizeof(msgtemp), "Account %s is now muted%s", account_get_name(account), msgtemp3);
message_send_text(c, message_type_error, c, msgtemp);

// send message to muted user
if ((user = connlist_find_connection_by_accountname(username)))
{
snprintf(msgtemp, sizeof(msgtemp), "Your account has just been muted by %s%s", conn_get_username(c), msgtemp3);
message_send_text(user, message_type_info, user, msgtemp);
}

return 0;
}

Expand Down
38 changes: 35 additions & 3 deletions src/bnetd/handle_bnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,11 @@ namespace pvpgn
char supports_locked_reply = 0;
t_clienttag clienttag = conn_get_clienttag(c);

if (clienttag == CLIENTTAG_DIABLO2XP_UINT || clienttag == CLIENTTAG_DIABLO2DV_UINT){
if (clienttag == CLIENTTAG_STARCRAFT_UINT || clienttag == CLIENTTAG_BROODWARS_UINT || clienttag == CLIENTTAG_SHAREWARE_UINT ||
clienttag == CLIENTTAG_DIABLORTL_UINT || clienttag == CLIENTTAG_DIABLOSHR_UINT || clienttag == CLIENTTAG_WARCIIBNE_UINT ||
clienttag == CLIENTTAG_DIABLO2DV_UINT || clienttag == CLIENTTAG_STARJAPAN_UINT || clienttag == CLIENTTAG_DIABLO2ST_UINT ||
clienttag == CLIENTTAG_DIABLO2XP_UINT || clienttag == CLIENTTAG_WARCRAFT3_UINT || clienttag == CLIENTTAG_WAR3XP_UINT )
{
if (conn_get_versionid(c) >= 0x0000000b)
supports_locked_reply = 1;
}
Expand Down Expand Up @@ -1679,9 +1683,37 @@ namespace pvpgn
}
else if (account_get_auth_lock(account) == 1) { /* default to false */
eventlog(eventlog_level_info, __FUNCTION__, "[%d] login for \"%s\" refused (this account is locked)", conn_get_socket(c), username);
if (supports_locked_reply) {
if (supports_locked_reply)
{
char msgtemp[MAX_MESSAGE_LEN], msgtemp2[MAX_MESSAGE_LEN];
snprintf(msgtemp, sizeof(msgtemp), "This account has been locked");

// append author of ban
if (char const * author = account_get_auth_lockby(account))
if (author && author[0] != '\0')
{
snprintf(msgtemp2, sizeof(msgtemp2), " by %s", author);
std::strcat(msgtemp, msgtemp2);
}

// append remaining time
if (unsigned int locktime = account_get_auth_locktime(account))
snprintf(msgtemp2, sizeof(msgtemp2), " for %.48s", seconds_to_timestr(locktime - now));
else
snprintf(msgtemp2, sizeof(msgtemp2), " permanently");
std::strcat(msgtemp, msgtemp2);

// append reason
char const * reason = account_get_auth_lockreason(account);
if (reason && reason[0] != '\0')
{
snprintf(msgtemp2, sizeof(msgtemp2), " with a reason \"%s\"", reason);
std::strcat(msgtemp, msgtemp2);
}


bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY2_MESSAGE_LOCKED);
packet_append_string(rpacket, "This account has been locked.");
packet_append_string(rpacket, msgtemp);
}
else {
bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY2_MESSAGE_BADPASS);
Expand Down

1 comment on commit 8638b17

@esenbek
Copy link

@esenbek esenbek commented on 8638b17 Aug 4, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не получается скомпилировать
мой pvpgn 1.99SVN

Please sign in to comment.