gravestar wrote:can you help me ? i have a problem with std::time
it comes out : There was an error in std::time.
and 1 more question..
how to disable create new account with 3 character ? i want to change it to at least 4 character to create an ID
Change system create account min 4 character via bnet, and 1 character via command: /addacct
change USER_NAME_MIN in field_sizes.h
add new code in account.h
extern int account_check_name2(char const * name);
add new code in account.cpp
extern int account_check_name2(char const * name)
{
unsigned int i;
char ch;
if (!name) {
eventlog(eventlog_level_error, __FUNCTION__,"got NULL name");
return -1;
}
for (i=0; i<strlen(name); i++)
{
/* These are the Battle.net rules but they are too strict.
* We want to allow any characters that wouldn't cause
* problems so this should test for what is _not_ allowed
* instead of what is.
*/
ch = name[i];
/* hardcoded safety checks */
if (ch == '/' || ch == '\\') return -1;
if (isalnum((int)ch)) continue;
if (strchr(prefs_get_account_allowed_symbols(),ch)) continue;
return -1;
}
if (i>=USER_NAME_MAX)
return -1;
return 0;
}
search account_create in account.cpp and change to
static t_account * account_create(char const * username, char const * passhash1)
{
t_account * account;
if (username && !passhash1) {
eventlog(eventlog_level_error,__FUNCTION__,"got NULL passhash1");
return NULL;
}
if (username && account_check_name2(username)) {
eventlog(eventlog_level_error,__FUNCTION__,"got invalid chars in username");
return NULL;
}
account = xmalloc(sizeof(t_account));
account->name = NULL;
account->clanmember = NULL;
account->attrgroup = NULL;
account->friends = NULL;
account->teams = NULL;
account->conn = NULL;
FLAG_ZERO(&account->flags);
account->namehash = 0; /* hash it later before inserting */
account->uid = 0; /* hash it later before inserting */
if (username) { /* actually making a new account */
/* first check if such a username already owns an account.
* we search in the memory hash mainly for non-indexed storage types.
* indexed storage types check themselves if the username exists already
* in the storage (see storage_sql.c) */
if (accountlist_find_account(username)) {
eventlog(eventlog_level_debug,__FUNCTION__,"user \"%s\" already has an account",username);
goto err;
}
account->attrgroup = attrgroup_create_newuser(username);
if(!account->attrgroup) {
eventlog(eventlog_level_error,__FUNCTION__,"failed to add user");
goto err;
}
account->name = xstrdup(username);
if (account_set_strattr(account,"BNET\\acct\\username",username)<0) {
eventlog(eventlog_level_error,__FUNCTION__,"could not set username");
goto err;
}
if (account_set_numattr(account,"BNET\\acct\\userid",maxuserid+1)<0) {
eventlog(eventlog_level_error,__FUNCTION__,"could not set userid");
goto err;
}
if (account_set_strattr(account,"BNET\\acct\\passhash1",passhash1)<0) {
eventlog(eventlog_level_error,__FUNCTION__,"could not set passhash1");
goto err;
}
if (account_set_numattr(account,"BNET\\acct\\ctime",(unsigned int)now)) {
eventlog(eventlog_level_error,__FUNCTION__,"could not set ctime");
goto err;
}
}
return account;
err:
account_destroy(account);
return NULL;
}
search account_load_new in account.cpp and change to
static t_account * account_load_new(char const * name, unsigned uid)
{
t_account *account;
t_attrgroup *attrgroup;
if (name && account_check_name2(name)) return NULL;
force_account_add = 1; /* disable the protection */
attrgroup = attrgroup_create_nameuid(name, uid);
if (!attrgroup) {
force_account_add = 0;
return NULL;
}
if (!(account = account_load(attrgroup))) {
eventlog(eventlog_level_error, __FUNCTION__,"could not load account");
attrgroup_destroy(attrgroup);
force_account_add = 0;
return NULL;
}
if (!accountlist_add_account(account)) {
eventlog(eventlog_level_error, __FUNCTION__,"could not add account to list");
account_destroy(account);
force_account_add = 0;
return NULL;
}
force_account_add = 0;
return account;
}
change code in command.cpp
static int _handle_addacct_command(t_connection * c, char const *text)
{
unsigned int i,j;
t_account * temp;
t_hash passhash;
char username[USER_NAME_MAX];
char pass[256];
for (i=0; text[i]!=' ' && text[i]!='\0'; i++);
for (; text[i]==' '; i++);
for (j=0; text[i]!=' ' && text[i]!='\0'; i++) /* get username */
if (j<sizeof(username)-1) username[j++] = text[i];
username[j] = '\0';
for (; text[i]==' '; i++); /* skip spaces */
for (j=0; text[i]!='\0'; i++) /* get pass (spaces are allowed) */
if (j<sizeof(pass)-1) pass[j++] = text[i];
pass[j] = '\0';
if (username[0]=='\0' || pass[0]=='\0') {
message_send_text(c,message_type_info,c,"Create new account must be at least 1 character long");
message_send_text(c,message_type_info,c,"usage: /addacct <username> <password>");
return 0;
}
if (account_check_name2(username)<0) {
message_send_text(c,message_type_error,c,"Account name contains some invalid symbol!");
return 0;
}
/* FIXME: truncate or err on too long password */
for (i=0; i<strlen(pass); i++)
if (isupper((int)pass[i])) pass[i] = tolower((int)pass[i]);
bnet_hash(&passhash,strlen(pass),pass);
snprintf(msgtemp, sizeof(msgtemp), "Trying to add account \"%.64s\" with password \"%.64s\"",username,pass);
message_send_text(c,message_type_info,c,msgtemp);
snprintf(msgtemp, sizeof(msgtemp), "Hash is: %.128s",hash_get_str(passhash));
message_send_text(c,message_type_info,c,msgtemp);
temp = accountlist_create_account(username,hash_get_str(passhash));
if (!temp) {
message_send_text(c,message_type_error,c,"Failed to create account!");
eventlog(eventlog_level_debug,__FUNCTION__,"[%d] account \"%s\" not created (failed)",conn_get_socket(c),username);
return 0;
}
snprintf(msgtemp, sizeof(msgtemp), "Number account \"%.64s\" is: "UID_FORMAT"",username,account_get_uid(temp));
message_send_text(c,message_type_info,c,msgtemp);
eventlog(eventlog_level_debug,__FUNCTION__,"[%d] account \"%s\" created",conn_get_socket(c),username);
return 0;
}
Finish change system create account min 4 character via bnet, and 1 character via command: /addacct