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

📄 bnchat.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 5 页
字号:
            bn_int_set(&temp.ticks,ticks);            bn_int_set(&temp.sessionkey,client.sessionkey);            bnet_hash(&passhash1,strlen(password),password); /* do the single hash */            hash_to_bnhash((t_hash const *)&passhash1,temp.passhash1); /* avoid warning */            bnet_hash(&passhash2,sizeof(temp),&temp); /* do the double hash */	    	    if (!(packet = packet_create(packet_class_bnet)))	    {		fprintf(stderr,"%s: could not create packet\n",argv[0]);		psock_close(client.sd);		if (client.changed_in)		    tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old);		return STATUS_FAILURE;	    }	    packet_set_size(packet,sizeof(t_client_loginreq1));	    packet_set_type(packet,CLIENT_LOGINREQ1);	    bn_int_set(&packet->u.client_loginreq1.ticks,ticks);	    bn_int_set(&packet->u.client_loginreq1.sessionkey,client.sessionkey);	    hash_to_bnhash((t_hash const *)&passhash2,packet->u.client_loginreq1.password_hash2); /* avoid warning */	    packet_append_string(packet,user.player);            client_blocksend_packet(client.sd,packet);	    packet_del_ref(packet);	}	        do            if (client_blockrecv_packet(client.sd,rpacket)<0)	    {	       fprintf(stderr,"%s: server closed connection\n",argv[0]);	       psock_close(client.sd);	       if (client.changed_in)	           tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old);	       return STATUS_FAILURE;	    }        while (packet_get_type(rpacket)!=SERVER_LOGINREPLY1);	if (bn_int_get(rpacket->u.server_loginreply1.message)==SERVER_LOGINREPLY1_MESSAGE_SUCCESS)	    break;	fprintf(stderr,"Login incorrect.\n");    }        fprintf(stderr,"Logged in.\n");    printf("----\n");        if (newacct && (strcmp(user.clienttag,CLIENTTAG_DIABLORTL)==0 ||		    strcmp(user.clienttag,CLIENTTAG_DIABLOSHR)==0))    {	if (!(packet = packet_create(packet_class_bnet)))	{	    fprintf(stderr,"%s: could not create packet\n",argv[0]);	    if (client.changed_in)		tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old);	}	else	{	    packet_set_size(packet,sizeof(t_client_playerinforeq));	    packet_set_type(packet,CLIENT_PLAYERINFOREQ);	    packet_append_string(packet,user.player);	    packet_append_string(packet,"LTRD 1 2 0 20 25 15 20 100 0"); /* FIXME: don't hardcode */	    client_blocksend_packet(client.sd,packet);	    packet_del_ref(packet);	}    }        if (!(packet = packet_create(packet_class_bnet)))    {	fprintf(stderr,"%s: could not create packet\n",argv[0]);	psock_close(client.sd);	if (client.changed_in)	    tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old);	return STATUS_FAILURE;    }    packet_set_size(packet,sizeof(t_client_progident2));    packet_set_type(packet,CLIENT_PROGIDENT2);    bn_int_tag_set(&packet->u.client_progident2.clienttag,user.clienttag);    client_blocksend_packet(client.sd,packet);    packet_del_ref(packet);        do        if (client_blockrecv_packet(client.sd,rpacket)<0)	{	    fprintf(stderr,"%s: server closed connection\n",argv[0]);	    psock_close(client.sd);	    if (client.changed_in)		tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old);	    return STATUS_FAILURE;	}    while (packet_get_type(rpacket)!=SERVER_CHANNELLIST);        {	unsigned int i;	unsigned int chann_off;	char const * chann;		channellist = xmalloc(sizeof(char const *)*1);	for (i=0,chann_off=sizeof(t_server_channellist);	     (chann = packet_get_str_const(rpacket,chann_off,128));	     i++,chann_off+=strlen(chann)+1)        {	    if (chann[0] == '\0') break;  /* channel list ends with a "" */	    channellist = xrealloc(channellist,sizeof(char const *)*(i+2));	    channellist[i] = xstrdup(chann);	}	channellist[i] = NULL;    }        if (!(packet = packet_create(packet_class_bnet)))    {	fprintf(stderr,"%s: could not create packet\n",argv[0]);	psock_close(client.sd);	if (client.changed_in)	    tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old);	return STATUS_FAILURE;    }    packet_set_size(packet,sizeof(t_client_joinchannel));    packet_set_type(packet,CLIENT_JOINCHANNEL);    bn_int_set(&packet->u.client_joinchannel.channelflag,CLIENT_JOINCHANNEL_GENERIC);    packet_append_string(packet,user.channel);    client_blocksend_packet(client.sd,packet);    packet_del_ref(packet);        if (psock_ctl(client.sd,PSOCK_NONBLOCK)<0)	fprintf(stderr,"%s: could not set TCP socket to non-blocking mode (psock_ctl: %s)\n",argv[0],pstrerror(psock_errno()));        client.mode = mode_chat;        {	unsigned int   i;	int            highest_fd;	t_psock_fd_set rfds;#ifdef WIN32    static struct timeval tv;	tv.tv_sec  = 50 / 1000;	tv.tv_usec = 50 % 1000;#endif		PSOCK_FD_ZERO(&rfds);#ifndef WIN32	highest_fd = client.fd_stdin;	if (client.sd>highest_fd)#endif	    highest_fd = client.sd;		client.currsize = 0;		client.munged = 1; /* == need to draw prompt */	client.commpos = 0;	client.text[0] = '\0';		for (;;)	{	    if (handle_winch)	    {		client_get_termsize(client.fd_stdin,&client.screen_width,&client.screen_height);		handle_winch = 0;		printf(" \r");		client.munged = 1;	    }	    	    if (client.munged)	    {		printf("%s%s",mode_get_prompt(client.mode),client.text + ((client.screen_width <= strlen(mode_get_prompt(client.mode)) + client.commpos ) ? strlen(mode_get_prompt(client.mode)) + client.commpos + 1 - client.screen_width : 0));		fflush(stdout);		client.munged = 0;	    }	    	PSOCK_FD_ZERO(&rfds);#ifndef WIN32	    PSOCK_FD_SET(client.fd_stdin,&rfds);#endif	    PSOCK_FD_SET(client.sd,&rfds);		errno = 0;	    #ifndef WIN32	    if (psock_select(highest_fd+1,&rfds,NULL,NULL,NULL)<0)#else	    if (psock_select(highest_fd+1,&rfds,NULL,NULL,&tv)<0)#endif	    {			if (psock_errno()!=PSOCK_EINTR)			{				munge(&client);				printf("Select failed (select: %s)\n",pstrerror(psock_errno()));			}			continue;	    }#ifndef WIN32	    if (PSOCK_FD_ISSET(client.fd_stdin,&rfds)) /* got keyboard data */#else		if (kbhit())#endif	    {		client.munged = 0;		switch (client_get_comm(mode_get_prompt(client.mode),client.text,MAX_MESSAGE_LEN,&client.commpos,1,		                        0,client.screen_width))		{		case -1: /* cancel */		    munge(&client);		    if (client.mode==mode_command)			client.mode = mode_chat;		    else			client.mode = mode_command;		    client.commpos = 0;		    client.text[0] = '\0';		    break;		    		case 0: /* timeout */		    break;		    		case 1:		    switch (client.mode)		    {		    case mode_claninvite:			    		        printf("\n");			client.munged = 1;			if ((client.text[0]!='\0') && strcasecmp(client.text,"yes") && strcasecmp(client.text,"no"))			{			    printf("Do you want to accept invitation (yes/no) ? [yes] ");			    break;			}						if (!(packet = packet_create(packet_class_bnet)))			{			    printf("Packet creation failed.\n");			}			else			{			    char result;						    packet_set_size(packet,sizeof(t_client_w3xp_clan_invitereply));			    packet_set_type(packet,CLIENT_W3XP_CLAN_INVITEREPLY);			    bn_int_set(&packet->u.client_w3xp_clan_invitereply.count,user.count);			    bn_int_set(&packet->u.client_w3xp_clan_invitereply.clantag,user.clantag);			    packet_append_string(packet,user.inviter);			    if (!strcasecmp(client.text,"no"))			        result = W3XP_CLAN_INVITEREPLY_DECLINE;			    else			        result = W3XP_CLAN_INVITEREPLY_ACCEPT;							    packet_append_data(packet,&result,1);			    			    client_blocksend_packet(client.sd,packet);			    packet_del_ref(packet);			    if (user.inviter)			        xfree((void *)user.inviter);			    user.inviter = NULL;							}						client.mode = mode_chat;		        break;		    case mode_gamename:			if (client.text[0]=='\0')			{		            munge(&client);			    printf("Games must have a name.\n");			    break;			}			printf("\n");			client.munged = 1;			strncpy(user.curr_gamename,client.text,sizeof(user.curr_gamename));			user.curr_gamename[sizeof(user.curr_gamename)-1] = '\0';			client.mode = mode_gamepass;			break;		    case mode_gamepass:			printf("\n");			client.munged = 1;			strncpy(user.curr_gamepass,client.text,sizeof(user.curr_gamepass));			user.curr_gamepass[sizeof(user.curr_gamepass)-1] = '\0';						if (!(packet = packet_create(packet_class_bnet)))			{			    printf("Packet creation failed.\n");			    client.mode = mode_command;			}			else			{			    packet_set_size(packet,sizeof(t_client_startgame4));			    packet_set_type(packet,CLIENT_STARTGAME4);			    bn_short_set(&packet->u.client_startgame4.status,CLIENT_STARTGAME4_STATUS_INIT);			    bn_short_set(&packet->u.client_startgame4.flag,0x0000);			    bn_int_set(&packet->u.client_startgame4.unknown2,CLIENT_STARTGAME4_UNKNOWN2);			    bn_short_set(&packet->u.client_startgame4.gametype,CLIENT_GAMELISTREQ_MELEE);			    bn_short_set(&packet->u.client_startgame4.option,CLIENT_STARTGAME4_OPTION_MELEE_NORMAL);			    bn_int_set(&packet->u.client_startgame4.unknown4,CLIENT_STARTGAME4_UNKNOWN4);			    bn_int_set(&packet->u.client_startgame4.unknown5,CLIENT_STARTGAME4_UNKNOWN5);			    packet_append_string(packet,user.curr_gamename);			    packet_append_string(packet,user.curr_gamepass);			    packet_append_string(packet,",,,,1,3,1,3e37a84c,7,Player\rAshrigo\r");			    client_blocksend_packet(client.sd,packet);			    packet_del_ref(packet);			    client.mode = mode_gamewait;			}			break;		    case mode_gamestop:			printf("\n");			client.munged = 1;						if (!(packet = packet_create(packet_class_bnet)))			    printf("Packet creation failed.\n");			else			{			    packet_set_size(packet,sizeof(t_client_closegame));			    packet_set_type(packet,CLIENT_CLOSEGAME);			    client_blocksend_packet(client.sd,packet);			    packet_del_ref(packet);			    printf("Game closed.\n");			    client.mode = mode_command;			}			break;		    case mode_command:			if (client.text[0]=='\0')			    break;			printf("\n");			client.munged = 1;			if (strstart(client.text,"channel")==0)			{			    printf("Available channels:\n");			    if (client.useansi)				ansi_text_color_fore(ansi_text_color_yellow);			    for (i=0; channellist[i]; i++)				printf(" %s\n",channellist[i]);			    if (client.useansi)				ansi_text_reset();			}			else if (strstart(client.text,"create")==0)			{			    printf("Enter new game information\n");			    client.mode = mode_gamename;			}			else if (strstart(client.text,"join")==0)			{			    printf("Not implemented yet.\n");			}			else if (strstart(client.text,"ladder")==0)			{			    printf("Not implemented yet.\n");			}			else if (strstart(client.text,"stats")==0)			{			    printf("Not implemented yet.\n");			}			else if (strstart(client.text,"help")==0 || strcmp(client.text,"?")==0)			{			    printf("Available commands:\n"				   " channel        - join or create a channel\n"				   " create         - create a new game\n"				   " join           - list current games\n"				   " ladder         - list ladder rankings\n"				   " help           - show this text\n"				   " info <PLAYER>  - print a player's profile\n"				   " chinfo         - modify your profile\n"				   " quit           - exit bnchat\n"				   " stats <PLAYER> - print a player's game record\n"				   "Use the escape key to toggle between chat and command modes.\n");			}			else if (strstart(client.text,"info")==0)			{			    for (i=4; client.text[i]==' ' || client.text[i]=='\t'; i++);			    if (client.text[i]=='\0')			    {			        ansi_printf(&client,ansi_text_color_red,"You must specify the player.\n");			    }			    else			    {				if (!(packet = packet_create(packet_class_bnet)))				    fprintf(stderr,"%s: could not create packet\n",argv[0]);				else				{				    printf("Profile info for %s:\n",&client.text[i]);				    packet_set_size(packet,sizeof(t_client_statsreq));				    packet_set_type(packet,CLIENT_STATSREQ);				    bn_int_set(&packet->u.client_statsreq.name_count,1);				    bn_int_set(&packet->u.client_statsreq.key_count,4);				    statsmatch = (unsigned int)time(NULL);				    bn_int_set(&packet->u.client_statsreq.requestid,statsmatch);				    packet_append_string(packet,&client.text[i]);#if 0				    packet_append_string(packet,"BNET\\acct\\username");				    packet_append_string(packet,"BNET\\acct\\userid");#endif				    packet_append_string(packet,"profile\\sex");				    packet_append_string(packet,"profile\\age");				    packet_append_string(packet,"profile\\location");				    packet_append_string(packet,"profile\\description");				    client_blocksend_packet(client.sd,packet);				    packet_del_ref(packet);				    				    client.mode = mode_waitstat;				}			    }			}			else if (strstart(client.text,"chinfo")==0)			{			    printf("Not implemented yet.\n");			}			else if (strstart(client.text,"quit")==0)			{			    psock_close(client.sd);			    if (client.changed_in)				tcsetattr(client.fd_stdin,TCSAFLUSH,&client.in_attr_old);			    return STATUS_SUCCESS;			}			else			{			    ansi_printf(&client,ansi_text_color_red,"Unknown local command \"%s\".\n",client.text);			}			break;			

⌨️ 快捷键说明

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