⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 account.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 2 页
字号:
}extern t_account * accountlist_find_account(char const * username){    unsigned int userid=0;    t_entry *    curr;    t_account *  account;        if (!username)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL username");	return NULL;    }        if (username[0]=='#') {        if (str_to_uint(&username[1],&userid)<0)            userid = 0;    } else if (!(prefs_get_savebyname()))	if (str_to_uint(username,&userid)<0)	    userid = 0;    /* all accounts in list must be hashed already, no need to check */        if (userid) {        account=accountlist_find_account_by_uid(userid);        if (account) return account;    }    if ((!(userid)) || (userid && ((username[0]=='#') || (isdigit((int)username[0])))))    {	unsigned int namehash;	char const * tname;		namehash = account_hash(username);	HASHTABLE_TRAVERSE_MATCHING(accountlist_head,curr,namehash)	{	    account = entry_get_data(curr);            if ((tname = account_get_name(account)))	    {		if (strcasecmp(tname,username)==0)		{		    hashtable_entry_release(curr);		    return account;		}	    }	}    }        return account_load_new(username,0);}extern t_account * accountlist_find_account_by_uid(unsigned int uid){    t_entry *    curr;    t_account *  account;        if (uid) {	HASHTABLE_TRAVERSE_MATCHING(accountlist_uid_head,curr,uid)	{	    account = entry_get_data(curr);	    if (account->uid==uid) {		hashtable_entry_release(curr);		return account;	    }	}    }    return account_load_new(NULL,uid);}extern int accountlist_allow_add(void){    if (force_account_add)	return 1; /* the permission was forced */    if (prefs_get_max_accounts()==0)	return 1; /* allow infinite accounts */    if (prefs_get_max_accounts()<=hashtable_get_length(accountlist_head))    	return 0; /* maximum account limit reached */    return 1; /* otherwise let them proceed */}static t_account * accountlist_add_account(t_account * account){    unsigned int uid;    char const * username;    if (!account) {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");        return NULL;    }    username = account_get_name(account);    uid = account_get_numattr(account,"BNET\\acct\\userid");    if (!username || strlen(username)<1) {        eventlog(eventlog_level_error,__FUNCTION__,"got bad account (empty username)");        return NULL;    }    if (uid<1) {	eventlog(eventlog_level_error,__FUNCTION__,"got bad account (bad uid), fix it!");	uid = maxuserid + 1;    }    /* check whether the account limit was reached */    if (!accountlist_allow_add()) {	eventlog(eventlog_level_warn,__FUNCTION__,"account limit reached (current is %u, storing %u)",prefs_get_max_accounts(),hashtable_get_length(accountlist_head));	return NULL;    }    /* delayed hash, do it before inserting account into the list */    account->namehash = account_hash(username);    account->uid = uid;    /* FIXME: this check actually (with the new attr system) happens too late     * we already have created the attrgroup here which is "dirty" and refusing      * an account here will trigger attrgroup_destroy which will "sync" the      * bad data to the storage! The codes should make sure we don't fail here */    /* mini version of accountlist_find_account(username) || accountlist_find_account(uid)  */    {	t_entry *    curr;	t_account *  curraccount;	char const * tname;	if(uid <= maxuserid)	HASHTABLE_TRAVERSE_MATCHING(accountlist_uid_head,curr,uid)	{	    curraccount = entry_get_data(curr);	    if (curraccount->uid==uid)	    {		eventlog(eventlog_level_debug,__FUNCTION__,"BUG: user \"%s\":"UID_FORMAT" already has an account (\"%s\":"UID_FORMAT")",username,uid,account_get_name(curraccount),curraccount->uid);		hashtable_entry_release(curr);		return NULL;	    }        }	HASHTABLE_TRAVERSE_MATCHING(accountlist_head,curr,account->namehash)	{	    curraccount = entry_get_data(curr);	    if ((tname = account_get_name(curraccount)))	    {		    if (strcasecmp(tname,username)==0)		    {		        eventlog(eventlog_level_debug,__FUNCTION__,"BUG: user \"%s\":"UID_FORMAT" already has an account (\"%s\":"UID_FORMAT")",username,uid,tname,curraccount->uid);		        hashtable_entry_release(curr);		        return NULL;		    }	    }	}    }    if (hashtable_insert_data(accountlist_head,account,account->namehash)<0) {	eventlog(eventlog_level_error,__FUNCTION__,"could not add account to list");	return NULL;    }    if (hashtable_insert_data(accountlist_uid_head,account,uid)<0) {	eventlog(eventlog_level_error,__FUNCTION__,"could not add account to list");	return NULL;    }/*    hashtable_stats(accountlist_head); */    if (uid>maxuserid)        maxuserid = uid;    return account;}extern t_account * accountlist_create_account(const char *username, const char *passhash1){    t_account *res;    assert(username != NULL);    assert(passhash1 != NULL);    res = account_create(username,passhash1);    if (!res) return NULL; /* eventlog reported ealier */    if (!accountlist_add_account(res)) {	account_destroy(res);	return NULL; /* eventlog reported earlier */    }    account_save(res,FS_FORCE); /* sync new account to storage */    return res;}extern int account_check_name(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_MIN || i>=USER_NAME_MAX)	return -1;    return 0;}extern char const * account_get_name_real(t_account * account, char const * fn, unsigned int ln){    char const * temp;    if (!account)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL account (from %s:%u)",fn,ln);	return NULL; /* FIXME: places assume this can't fail */    }    if (account->name) /* we have a cached username so return it */       return account->name;    /* we dont have a cached username so lets get it from attributes */    if (!(temp = account_get_strattr(account,"BNET\\acct\\username")))	eventlog(eventlog_level_error,__FUNCTION__,"account has no username");    else	account->name = xstrdup(temp);    return account->name;}extern int account_check_mutual( t_account * account, int myuserid){    if (account == NULL) {	eventlog(eventlog_level_error, __FUNCTION__, "got NULL account");	return -1;    }    if(!myuserid) {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL userid");	return -1;    }    if(account->friends!=NULL)    {        t_friend * fr;        if((fr=friendlist_find_uid(account->friends, myuserid))!=NULL)        {            friend_set_mutual(fr, 1);            return 0;        }    }    else    {	int i;	int n = account_get_friendcount(account);	int friend;	for(i=0; i<n; i++) 	{	    friend = account_get_friend(account,i);	    if(!friend)  {		eventlog(eventlog_level_error,__FUNCTION__,"got NULL friend");		continue;	    }	    if(myuserid==friend)		return 0;	}    }    // If friend isnt in list return -1 to tell func NO    return -1;}extern t_list * account_get_friends(t_account * account){    if (!account)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");	return NULL;    }    if(!FLAG_ISSET(account->flags,ACCOUNT_FLAG_FLOADED))	if(account_load_friends(account)<0)        {    	    eventlog(eventlog_level_error,__FUNCTION__,"could not load friend list");            return NULL;        }    return account->friends;}static int account_load_friends(t_account * account){    int i;    int n;    int friend;    t_account * acc;    t_friend * fr;    int newlist=0;    if (!account)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");	return -1;    }    if(FLAG_ISSET(account->flags,ACCOUNT_FLAG_FLOADED))        return 0;    if(account->friends==NULL)    {        account->friends=list_create();        newlist=1;    }    n = account_get_friendcount(account);    for(i=0; i<n; i++)    {	friend = account_get_friend(account,i);        if(!friend)  {            account_remove_friend(account, i);            continue;        }        fr=NULL;        if(newlist || (fr=friendlist_find_uid(account->friends, friend))==NULL)        {            if((acc = accountlist_find_account_by_uid(friend))==NULL)            {                if(account_remove_friend(account, i) == 0)		{		    i--;		    n--;		}                continue;            }            if(account_check_mutual(acc, account_get_uid(account))==0)                friendlist_add_account(account->friends, acc, 1);            else                friendlist_add_account(account->friends, acc, 0);        }        else {            if((acc=friend_get_account(fr))==NULL)            {                account_remove_friend(account, i);                continue;            }            if(account_check_mutual(acc, account_get_uid(account))==0)                friend_set_mutual(fr, 1);            else                friend_set_mutual(fr, 0);        }    }    if(!newlist)        friendlist_purge(account->friends);    FLAG_SET(&account->flags,ACCOUNT_FLAG_FLOADED);    return 0;}static int account_unload_friends(t_account * account){    if(friendlist_unload(account->friends)<0)        return -1;    FLAG_CLEAR(&account->flags,ACCOUNT_FLAG_FLOADED);    return 0;}extern int account_set_clanmember(t_account * account, t_clanmember * clanmember){    if(account==NULL)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");	return -1;    }    account->clanmember = clanmember;    return 0;}extern t_clanmember * account_get_clanmember(t_account * account){    t_clanmember * member;        if(account==NULL)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");	return NULL;    }    if ((member = account->clanmember)&&(clanmember_get_clan(member))&&(clan_get_created(clanmember_get_clan(member)) > 0))	return member;    else	return NULL;}extern t_clanmember * account_get_clanmember_forced(t_account * account){    if(account==NULL)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");	return NULL;    }    return  account->clanmember;}extern t_clan * account_get_clan(t_account * account){    if(account==NULL)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");	return NULL;    }    if(account->clanmember && (clanmember_get_clan(account->clanmember) != NULL) && (clan_get_created(clanmember_get_clan(account->clanmember)) > 0))	return clanmember_get_clan(account->clanmember);    else	return NULL;}extern t_clan * account_get_creating_clan(t_account * account){    if(account==NULL)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");	return NULL;    }    if(account->clanmember && (clanmember_get_clan(account->clanmember) != NULL) && (clan_get_created(clanmember_get_clan(account->clanmember)) <= 0))	return clanmember_get_clan(account->clanmember);    else	return NULL;}int account_set_conn(t_account * account, t_connection * conn){  if (!(account))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");    return -1;  }  account->conn = conn;    return 0;}t_connection * account_get_conn(t_account * account){  if (!(account))  {    eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");    return NULL;  }  return account->conn;}void account_add_team(t_account * account,t_team * team){  assert(account);  assert(team);  if (!(account->teams))    account->teams = list_create();    list_append_data(account->teams,team);}t_team * account_find_team_by_accounts(t_account * account, t_account **accounts, t_clienttag clienttag){    if ((account->teams))      return _list_find_team_by_accounts(accounts,clienttag,account->teams);    else       return NULL;}t_team * account_find_team_by_teamid(t_account * account, unsigned int teamid){    if ((account->teams))      return _list_find_team_by_teamid(teamid,account->teams);    else      return NULL;}t_list * account_get_teams(t_account * account){  assert(account);  return account->teams;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -