Skip to content

Commit

Permalink
Command /find <substr to search for inside username>
Browse files Browse the repository at this point in the history
  • Loading branch information
HarpyWar committed Mar 25, 2014
1 parent 8762667 commit c229c66
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
7 changes: 7 additions & 0 deletions conf/bnhelp.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,12 @@ Disband your clan
/clearstats - used to clear game statistics of a given user/clienttag
Syntax: /clearstats <user> <clienttag>
<clienttag> can be one of DSHR,DRTL,SSHR,STAR,SEXP,W2BNE,WAR3,W3XP,ALL
%find
/find - used to find users with similar name
Syntax: /find <substring to find>
<substring to find> needs to be in lower case
%save
/save - used to force save accounts changes from a cache into database
Syntax: /save
# #
##############################################################################
2 changes: 1 addition & 1 deletion conf/command_groups.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@

7 /set /commandgroups /cg /clearstats

8 /shutdown /rehash /save
8 /shutdown /rehash /find /save

# //////////////////////////////////////
# ///// End of Command Groups File /////
Expand Down
32 changes: 32 additions & 0 deletions src/bnetd/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,38 @@ namespace pvpgn
}


extern char const *accountlist_find_vague_account(t_account * account, char const *vague_username)
{
char const *tname;
int i;

if (!vague_username) {
eventlog(eventlog_level_error, __FUNCTION__, "got NULL vague_username");
return NULL;
}
if (!account) {
eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");
return NULL;
}


if (tname = account_get_name(account)) {
char temp[MAX_USERNAME_LEN];
for (i = 0; i < std::strlen(tname); i++) {
temp[i] = tname[i];
if (isupper((int)temp[i])) {
temp[i] = tolower((int)temp[i]);
}
}
if (strstr(temp, vague_username)) {
return tname;
}
return NULL;
}
return NULL;
}


extern int accountlist_allow_add(void)
{
if (force_account_add)
Expand Down
1 change: 1 addition & 0 deletions src/bnetd/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace pvpgn
extern int accountlist_flush(unsigned flags);
extern t_account * accountlist_find_account(char const * username);
extern t_account * accountlist_find_account_by_uid(unsigned int uid);
extern char const *accountlist_find_vague_account(t_account * account, char const *vague_username);
extern int accountlist_allow_add(void);
extern t_account * accountlist_create_account(const char *username, const char *passhash1);
extern void accounts_get_attr(char const *);
Expand Down
45 changes: 45 additions & 0 deletions src/bnetd/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "common/xstr.h"
#include "common/trans.h"
#include "common/lstr.h"
#include "common/hashtable.h"

#include "connection.h"
#include "message.h"
Expand Down Expand Up @@ -333,6 +334,7 @@ namespace pvpgn
static int _handle_gameinfo_command(t_connection * c, char const * text);
static int _handle_ladderactivate_command(t_connection * c, char const * text);
static int _handle_rehash_command(t_connection * c, char const * text);
static int _handle_find_command(t_connection * c, char const *text);
static int _handle_save_command(t_connection * c, char const * text);

//static int _handle_rank_all_accounts_command(t_connection * c, char const * text);
Expand Down Expand Up @@ -445,6 +447,7 @@ namespace pvpgn
{ "/gameinfo", _handle_gameinfo_command },
{ "/ladderactivate", _handle_ladderactivate_command },
{ "/rehash", _handle_rehash_command },
{ "/find", _handle_find_command },
{ "/save", _handle_save_command },
// { "/rank_all_accounts" , _handle_rank_all_accounts_command },
{ "/shutdown", _handle_shutdown_command },
Expand Down Expand Up @@ -3877,6 +3880,48 @@ namespace pvpgn
return 0;
}

/**
* /find <substr to search for inside username>
*/
static int _handle_find_command(t_connection * c, char const *text)
{
unsigned int i = 0;
t_account *account;
char const *tname;
t_entry *curr;
t_hashtable *accountlist_head = accountlist();

text = skip_command(text);

if (text[0] == '\0') {
/* In need of a better description */
message_send_text(c, message_type_info, c, "Usage: /find <substring to search in acct name>");
message_send_text(c, message_type_info, c, " <substring> has to be in lower case");
return -1;
}

std::sprintf(msgtemp, " -- name -- similar to %s", text);
message_send_text(c, message_type_info, c, msgtemp);


HASHTABLE_TRAVERSE(accountlist_head, curr)
{
if (!curr)
{
eventlog(eventlog_level_error, __FUNCTION__, "found NULL account in list");
}
else
{
account = (t_account *)entry_get_data(curr);
if ((tname = accountlist_find_vague_account(account, text)) != NULL) {
message_send_text(c, message_type_info, c, tname);
return 0;
}
}
}
return 0;
}

/**
* Save changes of accounts and clans from the cache to a storage
*/
Expand Down

0 comments on commit c229c66

Please sign in to comment.