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

📄 connection.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 5 页
字号:
    temp->handle	= 0;    temp->addr		= 0;    temp->loaded	= 0;    temp->joined	= 0;    temp->map_prefs	= 0xffffffff;    temp->type		= 0;    temp->gametype	= 0;    temp->queue		= 0;    temp->info		= NULL;    c->protocol.w3.anongame = temp;    return temp;}extern t_anongame * conn_get_anongame(t_connection *c){    if(!c) {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");	return NULL;    }    return c->protocol.w3.anongame;}extern void conn_destroy_anongame(t_connection *c){    t_anongame * a;    if (!c)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");	return;    }    if (!(a = c->protocol.w3.anongame))    {	eventlog(eventlog_level_error,__FUNCTION__,"NULL anongame");	return;    }    // delete reference to this connection    if(a->info) {    	a->info->player[a->playernum-1] = NULL;	if(--(a->info->currentplayers) == 0)	    anongameinfo_destroy(a->info);    }		// [quetzal] 20020824     // unqueue from anongame search list,	// if we got AT game, unqueue entire team.	if (anongame_arranged(a->queue)) {		anongame_unqueue(a->tc[0], a->queue);	} else {		anongame_unqueue(c, a->queue);	}    xfree(c->protocol.w3.anongame);    c->protocol.w3.anongame = NULL;}extern void conn_destroy(t_connection * c, t_elem ** elem, int conn_or_dead_list){    char const * classstr;    t_elem * curr;            if (c == NULL) {	eventlog(eventlog_level_error, "conn_destroy", "got NULL connection");	return;    }    classstr = conn_class_get_str(c->protocol.class);    if (list_remove_data(conn_head,c,(conn_or_dead_list)?&curr:elem)<0)    {	eventlog(eventlog_level_error,__FUNCTION__,"could not remove item from list");	return;    }    if (c->protocol.class==conn_class_d2cs_bnetd)    {        t_realm * realm;        realm=conn_get_realm(c);        if (realm)             realm_deactive(realm);        else        {             eventlog(eventlog_level_error,__FUNCTION__,"could not find realm for d2cs connection");        }    }    else if (c->protocol.class == conn_class_w3route && c->protocol.w3.routeconn && c->protocol.w3.routeconn->protocol.w3.anongame)    {	anongame_stats(c);	conn_destroy_anongame(c->protocol.w3.routeconn);  // [zap-zero] destroy anongame too when game connection is invalid    }    if (c->protocol.d2.realm) {        realm_add_player_number(c->protocol.d2.realm,-1);	realm_put(c->protocol.d2.realm,&c->protocol.d2.realm_regref);    }        /* free the memory with user quota */    {	t_qline * qline;		LIST_TRAVERSE(c->protocol.chat.quota.list,curr)	{	    qline = elem_get_data(curr);	    xfree(qline);	    list_remove_elem(c->protocol.chat.quota.list,&curr);	}	list_destroy(c->protocol.chat.quota.list);    }    /* if this user in a channel, notify everyone that the user has left */    if (c->protocol.chat.channel)	channel_del_connection(c->protocol.chat.channel,c);   if ((c->protocol.game) && (c->protocol.account))   {   	if (game_get_status(c->protocol.game)==game_status_started)	{            game_set_self_report(c->protocol.game,c->protocol.account,game_result_disconnect);            game_set_report(c->protocol.game,c->protocol.account,"disconnect","disconnect");	}   }    conn_set_game(c,NULL,NULL,NULL,game_type_none,0);    c->protocol.state = conn_state_empty;    watchlist_del_all_events(c);    timerlist_del_all_timers(c);    clanmember_set_offline(c);    if(c->protocol.account)	watchlist_notify_event(c->protocol.account,NULL,c->protocol.client.clienttag,watch_event_logout);    if (c->protocol.client.versioncheck)	versioncheck_destroy((void *)c->protocol.client.versioncheck); /* avoid warning */    if (c->protocol.chat.lastsender)	xfree((void *)c->protocol.chat.lastsender); /* avoid warning */        if (c->protocol.chat.away)	xfree((void *)c->protocol.chat.away); /* avoid warning */    if (c->protocol.chat.dnd)	xfree((void *)c->protocol.chat.dnd); /* avoid warning */    if (c->protocol.chat.tmpOP_channel)	xfree((void *)c->protocol.chat.tmpOP_channel); /* avoid warning */    if (c->protocol.chat.tmpVOICE_channel)	xfree((void *)c->protocol.chat.tmpVOICE_channel); /* avoid warning */        if (c->protocol.client.clientver)	xfree((void *)c->protocol.client.clientver); /* avoid warning */    if (c->protocol.client.country)	xfree((void *)c->protocol.client.country); /* avoid warning */    if (c->protocol.client.host)	xfree((void *)c->protocol.client.host); /* avoid warning */    if (c->protocol.client.user)	xfree((void *)c->protocol.client.user); /* avoid warning */    if (c->protocol.client.clientexe)	xfree((void *)c->protocol.client.clientexe); /* avoid warning */    if (c->protocol.client.owner)	xfree((void *)c->protocol.client.owner); /* avoid warning */    if (c->protocol.client.cdkey)	xfree((void *)c->protocol.client.cdkey); /* avoid warning */    if (c->protocol.d2.realminfo)	xfree((void *)c->protocol.d2.realminfo); /* avoid warning */    if (c->protocol.d2.charname)	xfree((void *)c->protocol.d2.charname); /* avoid warning */    if (c->protocol.chat.irc.ircline)	xfree((void *)c->protocol.chat.irc.ircline); /* avoid warning */    if (c->protocol.chat.irc.ircpass)	xfree((void *)c->protocol.chat.irc.ircpass); /* avoid warning */    /* ADDED BY UNDYING SOULZZ 4/8/02 */    if (c->protocol.w3.w3_playerinfo)	xfree((void *)c->protocol.w3.w3_playerinfo); /* avoid warning */     if (c->protocol.bound)	c->protocol.bound->protocol.bound = NULL;        if (c->protocol.chat.ignore_count>0)    {	if (!c->protocol.chat.ignore_list)	  { eventlog(eventlog_level_error,__FUNCTION__,"found NULL ignore_list with ignore_count=%u",c->protocol.chat.ignore_count); }	else	  { xfree(c->protocol.chat.ignore_list); }    }    if (c->protocol.account)    {	eventlog(eventlog_level_info,__FUNCTION__,"[%d] \"%s\" logged out",c->socket.tcp_sock,conn_get_loggeduser(c));	//amadeo#ifdef WIN32_GUI						guiOnUpdateUserList();#endif	if (prefs_get_sync_on_logoff()) {	    if (account_save(conn_get_account(c),FS_FORCE) < 0)		eventlog(eventlog_level_error,__FUNCTION__,"cannot sync account (sync_on_logoff)");	}	if (account_get_conn(c->protocol.account)==c)  /* make sure you don't set this when allready on new conn (relogin with same account) */	    account_set_conn(c->protocol.account,NULL);	c->protocol.account = NULL; /* the account code will free the memory later */    }    /* logged user is no longer only for logged in users */    if (c->protocol.loggeduser) xfree((void*)c->protocol.loggeduser);    /* make sure the connection is closed */    if (c->socket.tcp_sock!=-1) { /* -1 means that the socket was already closed by conn_close() */	fdwatch_del_fd(c->socket.fdw_idx);	psock_shutdown(c->socket.tcp_sock,PSOCK_SHUT_RDWR);	psock_close(c->socket.tcp_sock);    }    /* clear out the packet queues */    if (c->protocol.queues.inqueue) packet_del_ref(c->protocol.queues.inqueue);    queue_clear(&c->protocol.queues.outqueue);    // [zap-zero] 20020601    if (c->protocol.w3.routeconn) {	c->protocol.w3.routeconn->protocol.w3.routeconn = NULL;	if(c->protocol.w3.routeconn->protocol.class == conn_class_w3route)	    conn_set_state(c->protocol.w3.routeconn, conn_state_destroy);    }    if(c->protocol.w3.anongame)	conn_destroy_anongame(c);    /* delete the conn from the dead list if its there, we dont check for error     * because connections may be destroyed without first setting state to destroy */    if (conn_dead) list_remove_data(conn_dead, c, (conn_or_dead_list)?elem:&curr);    connarray_del_conn(c->protocol.sessionnum);    eventlog(eventlog_level_info,__FUNCTION__,"[%d] closed %s connection",c->socket.tcp_sock,classstr);        xfree(c);}extern int conn_match(t_connection const * c, char const * username){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return -1;    }    if (!username)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL username");        return -1;    }        if (!c->protocol.account)	return 0;        return account_match(c->protocol.account,username);}extern t_conn_class conn_get_class(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return conn_class_none;    }        return c->protocol.class;}extern void conn_set_class(t_connection * c, t_conn_class class){    t_timer_data  data;    unsigned long delta;    t_conn_class oldclass;        if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return;    }        if (c->protocol.class==class)	return;        oldclass = c->protocol.class;    c->protocol.class = class;    switch(class) {	case conn_class_bnet:	    if (prefs_get_udptest_port()!=0)		conn_set_game_port(c,(unsigned short)prefs_get_udptest_port());	    udptest_send(c);	    /* remove any init timers */	    if (oldclass == conn_class_init) timerlist_del_all_timers(c);	    delta = prefs_get_latency();	    data.n = delta;	    if (timerlist_add_timer(c,now+(time_t)delta,conn_test_latency,data)<0)		eventlog(eventlog_level_error,__FUNCTION__,"could not add timer");    	    eventlog(eventlog_level_debug,__FUNCTION__,"added latency check timer");	    break;	case conn_class_w3route:	    delta = prefs_get_latency();	    data.n = delta;	    if (timerlist_add_timer(c,now+(time_t)delta,conn_test_latency,data)<0)		eventlog(eventlog_level_error,__FUNCTION__,"could not add timer");	    break;	case conn_class_bot:	case conn_class_telnet:	{	    t_packet * rpacket;	    if (class==conn_class_bot) {		if ((delta = prefs_get_nullmsg())>0) {		    data.n = delta;		    if (timerlist_add_timer(c,now+(time_t)delta,conn_send_nullmsg,data)<0)		    eventlog(eventlog_level_error,__FUNCTION__,"could not add timer");		}	    }	    /* remove any init timers */	    if (oldclass == conn_class_init) timerlist_del_all_timers(c);	    conn_send_issue(c);	    if (!(rpacket = packet_create(packet_class_raw)))		eventlog(eventlog_level_error,__FUNCTION__,"could not create rpacket");	    else {		packet_append_ntstring(rpacket,"Username: ");		conn_push_outqueue(c,rpacket);		packet_del_ref(rpacket);	    }	    break;	}	default:	    /* remove any init timers */	    if (oldclass == conn_class_init) 		timerlist_del_all_timers(c);	    break;    }}extern t_conn_state conn_get_state(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return conn_state_empty;    }        return c->protocol.state;}extern void conn_set_state(t_connection * c, t_conn_state state){    t_elem * elem;    if (!c)    {        eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection");        return;    }    /* special case for destroying connections, add them to conn_dead list */    if (state == conn_state_destroy && c->protocol.state != conn_state_destroy) {	if (!conn_dead)	    conn_dead = list_create();	list_append_data(conn_dead, c);    }    else if (state != conn_state_destroy && c->protocol.state == conn_state_destroy)	if (list_remove_data(conn_dead, c, &elem)) {	    eventlog(eventlog_level_error, __FUNCTION__, "could not remove dead connection");	    return;	}    c->protocol.state = state;}extern unsigned int conn_get_sessionkey(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }        return c->protocol.sessionkey;}extern unsigned int conn_get_sessionnum(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }    return c->protocol.sessionnum;}extern unsigned int conn_get_secret(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }    return c->protocol.secret;}extern unsigned int conn_get_addr(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }        return c->socket.tcp_addr;}extern unsigned short conn_get_port(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }        return c->socket.tcp_port;}extern unsigned int conn_get_local_addr(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }        return c->socket.local_addr;}extern unsigned short conn_get_local_port(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }        return c->socket.local_port;}extern unsigned int conn_get_real_local_addr(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;    }        return c->socket.real_local_addr;}extern unsigned short conn_get_real_local_port(t_connection const * c){    if (!c)    {        eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");        return 0;

⌨️ 快捷键说明

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