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

📄 connection.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 5 页
字号:
    {	xfree((void *)c->protocol.client.owner); /* avoid warning */	c->protocol.client.owner = NULL;    }    if (c->protocol.client.cdkey)    {	xfree((void *)c->protocol.client.cdkey); /* avoid warning */	c->protocol.client.cdkey = NULL;    }        clanmember_set_online(c);    totalcount++;        watchlist_notify_event(c->protocol.account,NULL,c->protocol.client.clienttag,watch_event_login);        return;}extern void conn_login(t_connection *c, t_account *a, const char *loggeduser){    assert(c != NULL);    assert(a != NULL);    assert(loggeduser != NULL);    conn_set_account(c,a);    if (strcmp(conn_get_loggeduser(c),loggeduser))	conn_set_loggeduser(c,loggeduser);}extern t_account * conn_get_account(t_connection const * c){    if (!c)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");	return NULL;    }        return c->protocol.account;}extern int conn_set_loggeduser(t_connection * c, char const * username){    const char * temp;    assert(c != NULL);    assert(username != NULL);    temp = xstrdup(username);    if (c->protocol.loggeduser) xfree((void*)c->protocol.loggeduser);    c->protocol.loggeduser = temp;    return 0;}extern char const * conn_get_loggeduser(t_connection const * c){    assert(c != NULL);    if (!c->protocol.loggeduser && c->protocol.account)	return account_get_name(c->protocol.account);    return c->protocol.loggeduser;}extern unsigned int conn_get_flags(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }    return c->protocol.flags;}extern int conn_set_flags(t_connection * c, unsigned int flags){    if (!c) {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }    if (flags!=c->protocol.flags) {	c->protocol.flags = flags;	if (c->protocol.chat.channel) channel_update_userflags(c);    }    return 0;}extern void conn_add_flags(t_connection * c, unsigned int flags){    unsigned int oldflags;        if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return;    }    oldflags = c->protocol.flags;    c->protocol.flags |= flags;        if (oldflags!=c->protocol.flags && c->protocol.chat.channel)	channel_update_userflags(c);}extern void conn_del_flags(t_connection * c, unsigned int flags){    unsigned int oldflags;        if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return;    }    oldflags = c->protocol.flags;    c->protocol.flags &= ~flags;        if (oldflags!=c->protocol.flags && c->protocol.chat.channel)	channel_update_userflags(c);}extern unsigned int conn_get_latency(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }    return c->protocol.latency;}extern void conn_set_latency(t_connection * c, unsigned int ms){    if (!c)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");	return;    }    if (c->protocol.latency != ms)    {        c->protocol.latency = ms;            if (c->protocol.chat.channel)	    channel_update_latency(c);    }}extern char const * conn_get_awaystr(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return NULL;    }    return c->protocol.chat.away;}extern int conn_set_awaystr(t_connection * c, char const * away){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }        if (c->protocol.chat.away)	xfree((void *)c->protocol.chat.away); /* avoid warning */    if (!away)        c->protocol.chat.away = NULL;    else        c->protocol.chat.away = xstrdup(away);        return 0;}extern char const * conn_get_dndstr(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return NULL;    }        return c->protocol.chat.dnd;}extern int conn_set_dndstr(t_connection * c, char const * dnd){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }        if (c->protocol.chat.dnd)	xfree((void *)c->protocol.chat.dnd); /* avoid warning */    if (!dnd)        c->protocol.chat.dnd = NULL;    else        c->protocol.chat.dnd = xstrdup(dnd);        return 0;}extern int conn_add_ignore(t_connection * c, t_account * account){    t_account * * newlist;    t_connection *dest_c;    if (!c) {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }    if (!account) {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");        return -1;    }    newlist = xrealloc(c->protocol.chat.ignore_list,sizeof(t_account const *)*(c->protocol.chat.ignore_count+1));    newlist[c->protocol.chat.ignore_count++] = account;    c->protocol.chat.ignore_list = newlist;    dest_c = account_get_conn(account);    if (dest_c) {	t_message *message;	message = message_create(message_type_userflags,dest_c,NULL,NULL);	if (!message) return 0;	message_send(message,c);	message_destroy(message);    }    return 0;}extern int conn_del_ignore(t_connection * c, t_account const * account){    t_account * * newlist;    t_account *   temp;    unsigned int  i;        if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }    if (!account)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");        return -1;    }        for (i=0; i<c->protocol.chat.ignore_count; i++)	if (c->protocol.chat.ignore_list[i]==account)	    break;    if (i==c->protocol.chat.ignore_count)	return -1; /* not in list */        /* swap entry to be deleted with last entry */    temp = c->protocol.chat.ignore_list[c->protocol.chat.ignore_count-1];    c->protocol.chat.ignore_list[c->protocol.chat.ignore_count-1] = c->protocol.chat.ignore_list[i];    c->protocol.chat.ignore_list[i] = temp;        if (c->protocol.chat.ignore_count==1) /* some realloc()s are buggy */    {	xfree(c->protocol.chat.ignore_list);	newlist = NULL;    }    else	newlist = xrealloc(c->protocol.chat.ignore_list,sizeof(t_account const *)*(c->protocol.chat.ignore_count-1));    c->protocol.chat.ignore_count--;    c->protocol.chat.ignore_list = newlist;    return 0;}extern int conn_add_watch(t_connection * c, t_account * account, t_clienttag clienttag){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }        if (watchlist_add_events(c,account,clienttag,watch_event_login|watch_event_logout|watch_event_joingame|watch_event_leavegame)<0)	return -1;    return 0;}extern int conn_del_watch(t_connection * c, t_account * account, t_clienttag clienttag){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }        if (watchlist_del_events(c,account,clienttag,watch_event_login|watch_event_logout|watch_event_joingame|watch_event_leavegame)<0)	return -1;    return 0;}extern int conn_check_ignoring(t_connection const * c, char const * me){    unsigned int i;    t_account *  temp;        if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }        if (!me || !(temp = accountlist_find_account(me)))	return -1;        if (c->protocol.chat.ignore_list)	for (i=0; i<c->protocol.chat.ignore_count; i++)	    if (c->protocol.chat.ignore_list[i]==temp)		return 1;        return 0;}extern t_channel * conn_get_channel(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return NULL;    }        return c->protocol.chat.channel;}extern int conn_set_channel_var(t_connection * c, t_channel * channel){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }    c->protocol.chat.channel = channel;    return 0;}extern int conn_set_channel(t_connection * c, char const * channelname){    t_channel * channel;    t_channel * oldchannel;    t_account * acc;    t_elem * curr;    int clantag=0;    t_clan * clan = NULL;    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }    acc = c->protocol.account;    if (!acc)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");        return -1;    }    if (channelname)    {	unsigned int created;	oldchannel=c->protocol.chat.channel;	channel = channellist_find_channel_by_name(channelname,conn_get_country(c),realm_get_name(conn_get_realm(c)));	if(channel && (channel == oldchannel))		return 0;	if((strncasecmp(channelname, "clan ", 5)==0)&&(strlen(channelname)<10))		clantag = str_to_clantag(&channelname[5]);    if(clantag && ((!(clan = account_get_clan(acc))) || (clan_get_clantag(clan) != clantag)))    {        if (!channel)        {            char msgtemp[MAX_MESSAGE_LEN];            sprintf(msgtemp, "Unable to join channel %s, there is no member of that clan in the channel!", channelname);            message_send_text(c, message_type_error, c, msgtemp);            return 0;        }        else        {            t_clan * ch_clan;            if((ch_clan=clanlist_find_clan_by_clantag(clantag))&&(clan_get_channel_type(ch_clan)==1))            {                message_send_text(c, message_type_error, c, "This is a private clan channel, unable to join!");                return 0;            }        }    }    if (c->protocol.chat.channel)    {	channel_del_connection(c->protocol.chat.channel, c);	c->protocol.chat.channel = NULL;    }    if (channel)	{	    if (channel_check_banning(channel,c))	    {		message_send_text(c,message_type_error,c,"You are banned from that channel.");		return -1;	    }	    if ((account_get_auth_admin(acc,NULL)!=1) && (account_get_auth_admin(acc,channelname)!=1) &&		(account_get_auth_operator(acc,NULL)!=1) && (account_get_auth_operator(acc,channelname)!=1) &&		(channel_get_max(channel) == 0))	    {		message_send_text(c,message_type_error,c,"That channel is for Admins/Operators only.");		return -1;	    }	    if ((account_get_auth_admin(acc,NULL)!=1) && (account_get_auth_admin(acc,channelname)!=1) &&		(account_get_auth_operator(acc,NULL)!=1) && (account_get_auth_operator(acc,channelname)!=1) &&		(channel_get_max(channel) != -1) && (channel_get_curr(channel)>=channel_get_max(channel)))	    {		message_send_text(c,message_type_error,c,"The channel is currently full.");		return -1;	    }	}        if(conn_set_joingamewhisper_ack(c,0)<0)	eventlog(eventlog_level_error,__FUNCTION__,"Unable to reset conn_set_joingamewhisper_ack flag");    if(conn_set_leavegamewhisper_ack(c,0)<0)	eventlog(eventlog_level_error,__FUNCTION__,"Unable to reset conn_set_leavegamewhisper_ack flag");    	/* if you're entering a channel, make sure they didn't exit a game without telling us */	if (c->protocol.game)	{            game_del_player(conn_get_game(c),c);	    c->protocol.game = NULL;	}	created = 0;    if (!channel)	{	    if(clantag)		channel = channel_create(channelname,channelname,NULL,0,1,1,prefs_get_chanlog(), NULL, NULL, (prefs_get_maxusers_per_channel() > 0) ? prefs_get_maxusers_per_channel() : -1, 0, 1,0);	    else		channel = channel_create(channelname,channelname,NULL,0,1,1,prefs_get_chanlog(), NULL, NULL, (prefs_get_maxusers_per_channel() > 0) ? prefs_get_maxusers_per_channel() : -1, 0, 0,0);	    if (!channel)	    {		eventlog(eventlog_level_error,__FUNCTION__,"[%d] could not create channel on join \"%s\"",conn_get_socket(c),channelname);		return -1;	    }	    created = 1;	}

⌨️ 快捷键说明

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