extern int account_set_normal_last_time(t_account * account, char const * clienttag, t_bnettime t) { char key[256]; if (!clienttag || strlen(clienttag)!=4) { eventlog(eventlog_level_error,"account_set_normal_last_time","got bad clienttag"); return -1; } sprintf(key,"Record\\%s\\0\\last game",clienttag); return account_set_strattr(account,key,bnettime_get_str(t)); }
extern int account_set_ladder_last_result(t_account * account, char const * clienttag, t_ladder_id id, char const * result) { char key[256]; if (!clienttag || strlen(clienttag)!=4) { eventlog(eventlog_level_error,"account_set_ladder_last_result","got bad clienttag"); return -1; } sprintf(key,"Record\\%s\\%d\\last game result",clienttag,(int)id); return account_set_strattr(account,key,result); }
extern int account_set_boolattr(t_account * account, char const * key, int val) { if (!account) { eventlog(eventlog_level_error,"account_set_boolattr","got NULL account"); return -1; } if (!key) { eventlog(eventlog_level_error,"account_set_boolattr","got NULL key"); return -1; } return account_set_strattr(account,key,val?"true":"false"); }
extern t_account * create_vaccount(const char *username, unsigned int uid) { /* this is a modified(?) version of account_create */ t_account * account; account = malloc(sizeof(t_account)); if (!account) { eventlog(eventlog_level_error,"create_vaccount","could not allocate memory for account"); return NULL; } account->attrs = NULL; account->age = 0; CLEAR_FLAGS(account); account->namehash = 0; /* hash it later */ account->uid = 0; account->filename = NULL; /* there is no local account file */ account->bits_state = account_state_unknown; if (username) { if (username[0]!='#') { if (strchr(username,' ')) { eventlog(eventlog_level_error,"create_vaccount","username contains spaces"); account_destroy(account); return NULL; } if (strlen(username)>=MAX_USER_NAME) { eventlog(eventlog_level_error,"create_vaccount","username \"%s\" is too long (%u chars)",username,strlen(username)); account_destroy(account); return NULL; } account_set_strattr(account,"BNET\\acct\\username",username); account->namehash = account_hash(username); } else { if (str_to_uint(&username[1],&account->uid)<0) { eventlog(eventlog_level_warn,"create_vaccount","invalid username \"%s\"",username); } } } account_set_numattr(account,"BNET\\acct\\userid",account->uid); return account; }
extern int account_set_numattr(t_account * account, char const * key, unsigned int val) { char temp[32]; /* should be more than enough room */ if (!account) { eventlog(eventlog_level_error,"account_set_numattr","got NULL account"); return -1; } if (!key) { eventlog(eventlog_level_error,"account_set_numattr","got NULL key"); return -1; } sprintf(temp,"%u",val); return account_set_strattr(account,key,temp); }
extern int account_set_ll_cdkey(t_account * account, char const * cdkey) { return account_set_strattr(account,"BNET\\acct\\lastlogin_cdkey",cdkey); }
extern int account_set_ll_owner(t_account * account, char const * owner) { return account_set_strattr(account,"BNET\\acct\\lastlogin_owner",owner); }
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_set_ll_host(t_account * account, char const * host) { return account_set_strattr(account,"BNET\\acct\\lastlogin_host",host); }
extern int account_set_ll_clientver(t_account * account, char const * version) { return account_set_strattr(account,"BNET\\acct\\lastlogin_clientver",version); }
extern int account_set_ll_clientexe(t_account * account, char const * exefile) { return account_set_strattr(account,"BNET\\acct\\lastlogin_clientexe",exefile); }
extern int account_set_fl_user(t_account * account, char const * user) { return account_set_strattr(account,"BNET\\acct\\firstlogin_user",user); }
extern int account_set_pass(t_account * account, char const * passhash1) { return account_set_strattr(account,"BNET\\acct\\passhash1",passhash1); }
BOOL CALLBACK KickDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { case WM_INITDIALOG: if (selected_item[0] != 0) { SetDlgItemText(hwnd, IDC_EDITKICK, selected_item); } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_KICK_EXECUTE: { t_connection * conngui; t_account * accountgui; BOOL messageq; BOOL kickq; char temp[60]; char ipadr[110]; messageq = FALSE; kickq = FALSE; GetDlgItemText(hwnd, IDC_EDITKICK, selected_item, 32); conngui = connlist_find_connection_by_accountname(selected_item); accountgui = accountlist_find_account(selected_item); if (conngui == NULL) { strcat(selected_item, " could not be found in Userlist!"); MessageBox(hwnd, selected_item, "ERROR", MB_OK); } else { HWND hButton = GetDlgItem(hwnd, IDC_CHECKBAN); HWND hButton1 = GetDlgItem(hwnd, IDC_CHECKKICK); HWND hButton2 = GetDlgItem(hwnd, IDC_CHECKADMIN); HWND hButton3 = GetDlgItem(hwnd, IDC_CHECKMOD); HWND hButton4 = GetDlgItem(hwnd, IDC_CHECKANN); if (SendMessage(hButton2, BM_GETCHECK, 0, 0) == BST_CHECKED) { account_set_admin(accountgui); account_set_command_groups(accountgui, 255); messageq = TRUE; } if (SendMessage(hButton3, BM_GETCHECK, 0, 0) == BST_CHECKED) { account_set_auth_operator(accountgui, NULL, 1); messageq = TRUE; } if (SendMessage(hButton4, BM_GETCHECK, 0, 0) == BST_CHECKED) { account_set_strattr(accountgui, "BNET\\auth\\announce", "true"); messageq = TRUE; } if (SendMessage(hButton, BM_GETCHECK, 0, 0) == BST_CHECKED) { unsigned int i_GUI; strcpy(temp, addr_num_to_addr_str(conn_get_addr(conngui), 0)); for (i_GUI = 0; temp[i_GUI] != ':'; i_GUI++) ipadr[i_GUI] = temp[i_GUI]; ipadr[i_GUI] = 0; strcpy(temp, " a "); strcat(temp, ipadr); handle_ipban_command(NULL, temp); temp[0] = 0; strcpy(temp, " has been added to IpBanList"); strcat(ipadr, temp); if (messageq == TRUE) { strcat(ipadr, " and UserStatus changed"); MessageBox(hwnd, ipadr, "ipBan & StatusChange", MB_OK); messageq = FALSE; kickq = FALSE; } else MessageBox(hwnd, ipadr, "ipBan", MB_OK); } if (SendMessage(hButton1, BM_GETCHECK, 0, 0) == BST_CHECKED) { conn_set_state(conngui, conn_state_destroy); kickq = TRUE; } if ((messageq == TRUE) && (kickq == TRUE)) { strcat(selected_item, "has been kicked and Status has changed"); MessageBox(hwnd, selected_item, "UserKick & StatusChange", MB_OK); } if ((kickq == TRUE) && (messageq == FALSE)) { strcat(selected_item, " has been kicked from the server"); MessageBox(hwnd, selected_item, "UserKick", MB_OK); } if ((kickq == FALSE) && (messageq == TRUE)) { strcat(selected_item, "'s Status has been changed"); MessageBox(hwnd, selected_item, "StatusChange", MB_OK); } selected_item[0] = 0; } break; } } break; case WM_CLOSE: EndDialog(hwnd, IDC_EDITKICK); break; default: return FALSE; } return TRUE; }
/* Set account attribute value * (Return 0 if attribute is not set, and 1 if set) */ extern int __account_set_attr(lua_State* L) { const char *username, *attrkey; int attrtype; std::map<std::string, std::string> o_account; int result = 0; try { lua::stack st(L); // get args st.at(1, username); st.at(2, attrkey); st.at(3, attrtype); if (t_account *account = accountlist_find_account(username)) { switch ((t_attr_type)attrtype) { case attr_type_str: const char * strvalue; st.at(4, strvalue); if (account_set_strattr(account, attrkey, strvalue) >= 0) result = 1; break; case attr_type_num: int numvalue; st.at(4, numvalue); if (account_set_numattr(account, attrkey, numvalue) >= 0) result = 1; break; case attr_type_bool: bool boolvalue; st.at(4, boolvalue); if (account_set_boolattr(account, attrkey, boolvalue ? 1 : 0) >= 0) result = 1; break; case attr_type_raw: const char * rawvalue; int length; st.at(4, rawvalue); st.at(5, length); if (account_set_rawattr(account, attrkey, rawvalue, length) >= 0) result = 1; break; } } st.push(result); } catch (const std::exception& e) { eventlog(eventlog_level_error, __FUNCTION__, e.what()); } catch (...) { eventlog(eventlog_level_error, __FUNCTION__, "lua exception\n"); } return 1; }
extern int account_set_ll_clienttag(t_account * account, char const * clienttag) { return account_set_strattr(account,"BNET\\acct\\lastlogin_clienttag",clienttag); }
static t_account * account_create3(char const * username, char const * passhash1, char const * email) { t_account * account; if (username && !passhash1) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL passhash1"); return NULL; } if (username && account_check_name(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; } if (account_set_strattr(account,"BNET\\acct\\email",email)<0) { eventlog(eventlog_level_error,__FUNCTION__,"could not set email"); goto err; } if (account_set_numattr(account,"BNET\\auth\\vip_expire",(unsigned int)now+prefs_get_vip_experience())) { eventlog(eventlog_level_error,__FUNCTION__,"could not set vip_expire"); goto err; } } return account; err: account_destroy(account); return NULL; }
extern t_account * account_create(char const * username, char const * passhash1) { t_account * account; if (username && account_check_name(username)<0) { eventlog(eventlog_level_error,"account_create","got bad account name"); return NULL; } if (!(account = malloc(sizeof(t_account)))) { eventlog(eventlog_level_error,"account_create","could not allocate memory for account"); return NULL; } account->filename = NULL; account->attrs = NULL; account->age = 0; CLEAR_FLAGS(account); account->namehash = 0; /* hash it later before inserting */ #ifndef ACCT_DYN_LOAD account->uid = 0; #endif /* !ACCT_DYN_LOAD */ #ifdef ACCT_DYN_UNLOAD account->ref = 0; #endif /* ACCT_DYN_UNLOAD */ if (username) /* actually making a new account */ { char * temp; if (account_check_name(username)<0) { eventlog(eventlog_level_error,"account_create","invalid account name \"%s\"",username); account_destroy(account); return NULL; } if (!passhash1) { eventlog(eventlog_level_error,"account_create","got NULL passhash1"); account_destroy(account); return NULL; } #ifdef WITH_STORAGE_DB /* In DB (MySQL) storage i always use the real login name as id */ if (!(temp = malloc(strlen(username)+1))) /* name + NUL */ { eventlog(eventlog_level_error,"account_create","could not allocate memory for temp"); account_destroy(account); return NULL; } sprintf(temp,"%s",username); #else # ifndef ACCT_DYN_LOAD if (prefs_get_savebyname()==0) { if (!(temp = malloc(strlen(prefs_get_userdir())+1+8+1))) /* dir + / + uid + NUL */ { eventlog(eventlog_level_error,"account_create","could not allocate memory for temp"); account_destroy(account); return NULL; } sprintf(temp,"%s/%06u",prefs_get_userdir(),maxuserid+1); /* FIXME: hmm, maybe up the %06 to %08... */ } else # endif /* ! ACCT_DYN_LOAD */ { char const * safename; char * filename; if (!(filename = strdup(username))) { eventlog(eventlog_level_error,"account_create","could not allocate memory for filename"); account_destroy(account); return NULL; } str_to_lower(filename); if (!(safename = escape_fs_chars(filename,strlen(filename)))) { eventlog(eventlog_level_error,"account_create","could not escape username"); account_destroy(account); free(filename); return NULL; } free(filename); if (!(temp = malloc(strlen(prefs_get_userdir())+1+strlen(safename)+1))) /* dir + / + name + NUL */ { eventlog(eventlog_level_error,"account_create","could not allocate memory for temp"); account_destroy(account); return NULL; } sprintf(temp,"%s/%s",prefs_get_userdir(),safename); free((void *)safename); /* avoid warning */ } #endif /* WITH_DB_STORAGE */ account->filename = temp; SET_FLAG(account,account_flag_loaded); if (account_set_strattr(account,"BNET\\acct\\username",username)<0) { eventlog(eventlog_level_error,"account_create","could not set username"); account_destroy(account); return NULL; } #ifndef ACCT_DYN_LOAD if (account_set_numattr(account,"BNET\\acct\\userid",maxuserid+1)<0) { eventlog(eventlog_level_error,"account_create","could not set userid"); account_destroy(account); return NULL; } #endif /* !ACCT_DYN_LOAD */ if (account_set_strattr(account,"BNET\\acct\\passhash1",passhash1)<0) { eventlog(eventlog_level_error,"account_create","could not set passhash1"); account_destroy(account); return NULL; } #ifdef WITH_BITS account_set_bits_state(account,account_state_valid); if (!bits_master) { eventlog(eventlog_level_warn,"account_create","account_create should not be called on BITS clients"); } #endif /* WITH_BITS */ } #ifdef WITH_BITS else /* empty account to be filled in later */ account_set_bits_state(account,account_state_valid); #endif /* WITH_BITS */ return account; }