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

📄 client_connect.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 2 页
字号:
    if ((sd = psock_socket(PSOCK_PF_INET,PSOCK_SOCK_STREAM,PSOCK_IPPROTO_TCP))<0)    {	fprintf(stderr,"%s: could not create socket (psock_socket: %s)\n",progname,pstrerror(psock_errno()));	return -1;    }        memset(saddr,0,sizeof(*saddr));    saddr->sin_family = PSOCK_AF_INET;    saddr->sin_port   = htons(servport);    memcpy(&saddr->sin_addr.s_addr,host->h_addr_list[0],host->h_length);    if (psock_connect(sd,(struct sockaddr *)saddr,sizeof(*saddr))<0)    {	fprintf(stderr,"%s: could not connect to server \"%s\" port %hu (psock_connect: %s)\n",progname,servname,servport,pstrerror(psock_errno()));	goto error_sd;    }        printf("Connected to %s:%hu.\n",inet_ntoa(saddr->sin_addr),servport);    #ifdef CLIENTDEBUG    eventlog_set(stderr);#endif            if ((lsock = client_udptest_setup(progname,&lsock_port))>=0)	dprintf("Got UDP data on port %hu\n",lsock_port);        if (!(packet = packet_create(packet_class_init)))    {	fprintf(stderr,"%s: could not create packet\n",progname);	goto error_lsock;    }    bn_byte_set(&packet->u.client_initconn.class,CLIENT_INITCONN_CLASS_BNET);    client_blocksend_packet(sd,packet);    packet_del_ref(packet);        /* reuse this same packet over and over */    if (!(rpacket = packet_create(packet_class_bnet)))    {	fprintf(stderr,"%s: could not create packet\n",progname);	goto error_lsock;    }        get_defversioninfo(progname,clienttag,&versionid,&gameversion,&exeinfo,&checksum);    if (strcmp(clienttag,CLIENTTAG_DIABLOSHR)==0 ||        strcmp(clienttag,CLIENTTAG_DIABLORTL)==0)    {	if (!(packet = packet_create(packet_class_bnet)))	{	    fprintf(stderr,"%s: could not create packet\n",progname);	    goto error_rpacket;	}	packet_set_size(packet,sizeof(t_client_unknown_1b));	packet_set_type(packet,CLIENT_UNKNOWN_1B);	bn_short_set(&packet->u.client_unknown_1b.unknown1,CLIENT_UNKNOWN_1B_UNKNOWN3);	bn_short_nset(&packet->u.client_unknown_1b.port,lsock_port);	bn_int_nset(&packet->u.client_unknown_1b.ip,0); /* FIXME */	bn_int_set(&packet->u.client_unknown_1b.unknown2,CLIENT_UNKNOWN_1B_UNKNOWN3);	bn_int_set(&packet->u.client_unknown_1b.unknown3,CLIENT_UNKNOWN_1B_UNKNOWN3);	client_blocksend_packet(sd,packet);	packet_del_ref(packet);    }        if (!(packet = packet_create(packet_class_bnet)))    {	fprintf(stderr,"%s: could not create packet\n",progname);	goto error_rpacket;    }    packet_set_size(packet,sizeof(t_client_countryinfo_109));    packet_set_type(packet,CLIENT_COUNTRYINFO_109);    bn_int_set(&packet->u.client_countryinfo_109.protocol,CLIENT_COUNTRYINFO_109_PROTOCOL);    bn_int_tag_set(&packet->u.client_countryinfo_109.archtag,archtag);    bn_int_tag_set(&packet->u.client_countryinfo_109.clienttag,clienttag);	   //AARON     bn_int_set(&packet->u.client_countryinfo_109.versionid,versionid);    bn_int_tag_set(&packet->u.client_countryinfo_109.gamelang,gamelang);    bn_int_set(&packet->u.client_countryinfo_109.localip,CLIENT_COUNTRYINFO_109_LOCALIP);    {	int bias;	        bias = local_tzbias();        	bn_int_set(&packet->u.client_countryinfo_109.bias,(unsigned int)bias); /* rely on 2's complement */	dprintf("my tzbias = %d (0x%08hx)\n",bias,(unsigned int)bias);    }    /* FIXME: determine from locale */    bn_int_set(&packet->u.client_countryinfo_109.lcid,CLIENT_COUNTRYINFO_109_LANGID_USENGLISH);    bn_int_set(&packet->u.client_countryinfo_109.langid,CLIENT_COUNTRYINFO_109_LANGID_USENGLISH);    packet_append_string(packet,CLIENT_COUNTRYINFO_109_LANGSTR_USENGLISH);    /* FIXME: determine from locale+timezone... from domain name... nothing really would       work.  Maybe add some command-line options */    packet_append_string(packet,CLIENT_COUNTRYINFO_109_COUNTRYNAME_USA);    client_blocksend_packet(sd,packet);    packet_del_ref(packet);       do        if (client_blockrecv_packet(sd,rpacket)<0)	{	    fprintf(stderr,"%s: server closed connection\n",progname);	    goto error_rpacket;	}    while (packet_get_type(rpacket)!=SERVER_AUTHREQ_109 &&	   packet_get_type(rpacket)!=SERVER_AUTHREPLY_109);        if (packet_get_type(rpacket)==SERVER_AUTHREQ_109) /* hmm... server wants to check the version number */    {	dprintf("Got AUTHREQ_109\n");	*sessionkey = bn_int_get(rpacket->u.server_authreq_109.sessionkey);	*sessionnum = bn_int_get(rpacket->u.server_authreq_109.sessionnum);	/* FIXME: also get filename and equation */	if (!(packet = packet_create(packet_class_bnet)))	{	    fprintf(stderr,"%s: could not create packet\n",progname);	    goto error_rpacket;	}	packet_set_size(packet,sizeof(t_client_authreq_109));	packet_set_type(packet,CLIENT_AUTHREQ_109);	bn_int_set(&packet->u.client_authreq_109.ticks,time(NULL));		{            t_cdkey_info cdkey_info;	    	    bn_int_set(&packet->u.client_authreq_109.gameversion,gameversion);	    bn_int_set(&packet->u.client_authreq_109.cdkey_number,1); /* only one */	    memset(&cdkey_info,'0',sizeof(cdkey_info));	    /* FIXME: put the input cdkey here */	    packet_append_data(packet,&cdkey_info,sizeof(cdkey_info));	    packet_append_string(packet,exeinfo);	    packet_append_string(packet,cdowner);	}	bn_int_set(&packet->u.client_authreq_109.spawn,0x0000);		bn_int_set(&packet->u.client_authreq_109.checksum,checksum);	client_blocksend_packet(sd,packet);	packet_del_ref(packet);		/* now wait for reply */	do	    if (client_blockrecv_packet(sd,rpacket)<0)	    {		fprintf(stderr,"%s: server closed connection\n",progname);		goto error_rpacket;	    }	while (packet_get_type(rpacket)!=SERVER_AUTHREPLY_109);      //FIXME: check if AUTHREPLY_109 is success or fail      if (bn_int_get(rpacket->u.server_authreply_109.message)!=SERVER_AUTHREPLY_109_MESSAGE_OK)      {         fprintf(stderr,"AUTHREPLY_109 failed - closing connection\n");         goto error_rpacket;      }    }    else	fprintf(stderr,"We didn't get a sessionkey, don't expect login to work!");    dprintf("Got AUTHREPLY_109\n");        if (!(packet = packet_create(packet_class_bnet)))    {	fprintf(stderr,"%s: could not create packet\n",progname);	goto error_rpacket;    }    packet_set_size(packet,sizeof(t_client_iconreq));    packet_set_type(packet,CLIENT_ICONREQ);    client_blocksend_packet(sd,packet);    packet_del_ref(packet);        do        if (client_blockrecv_packet(sd,rpacket)<0)	{	    fprintf(stderr,"%s: server closed connection\n",progname);	    goto error_rpacket;	}    while (packet_get_type(rpacket)!=SERVER_ICONREPLY);    dprintf("Got ICONREPLY\n");        if (strcmp(clienttag,CLIENTTAG_STARCRAFT)==0 ||	strcmp(clienttag,CLIENTTAG_BROODWARS)==0 ||	strcmp(clienttag,CLIENTTAG_WARCIIBNE)==0)    {	if (!(packet = packet_create(packet_class_bnet)))	{	    fprintf(stderr,"%s: could not create packet\n",progname);	    goto error_rpacket;	}        {            struct            {                bn_int sessionkey;                bn_int ticks;                bn_int productid;                bn_int keyvalue1;                bn_int keyvalue2;            }            temp;            t_hash       key_hash;            unsigned int ticks;            unsigned int keyvalue1,keyvalue2,productid;                        if (key_interpret(cdkey,&productid,&keyvalue1,&keyvalue2)<0)	    {                fprintf(stderr,"%s: specified key is not valid, sending junk\n",progname);                productid = 0;                keyvalue1 = 0;                keyvalue2 = 0;	    }	    	    ticks = 0; /* FIXME: what to use here? */	    bn_int_set(&temp.ticks,ticks);	    bn_int_set(&temp.sessionkey,*sessionkey);	    bn_int_set(&temp.productid,productid);	    bn_int_set(&temp.keyvalue1,keyvalue1);	    bn_int_set(&temp.keyvalue2,keyvalue2);	    bnet_hash(&key_hash,sizeof(temp),&temp);	    	    packet_set_size(packet,sizeof(t_client_cdkey2));	    packet_set_type(packet,CLIENT_CDKEY2);	    bn_int_set(&packet->u.client_cdkey2.spawn,CLIENT_CDKEY2_SPAWN_FALSE); /* FIXME: add option */	    bn_int_set(&packet->u.client_cdkey2.keylen,strlen(cdkey));	    bn_int_set(&packet->u.client_cdkey2.productid,productid);	    bn_int_set(&packet->u.client_cdkey2.keyvalue1,keyvalue1);	    bn_int_set(&packet->u.client_cdkey2.sessionkey,*sessionkey);	    bn_int_set(&packet->u.client_cdkey2.ticks,ticks);	    hash_to_bnhash((t_hash const *)&key_hash,packet->u.client_cdkey2.key_hash); /* avoid warning */	    packet_append_string(packet,cdowner);	    client_blocksend_packet(sd,packet);	    packet_del_ref(packet);	}        do            if (client_blockrecv_packet(sd,rpacket)<0)            {                fprintf(stderr,"%s: server closed connection\n",progname);		goto error_rpacket;            }        while (packet_get_type(rpacket)!=SERVER_CDKEYREPLY2);        dprintf("Got CDKEYREPLY2 (%u)\n",bn_int_get(rpacket->u.server_cdkeyreply2.message));    }        packet_destroy(rpacket);    return sd;        /* error cleanup */        error_rpacket:    	packet_destroy(rpacket);        error_lsock:    	if (lsock>=0)	    psock_close(lsock);        error_sd:    	psock_close(sd);        return -1;}

⌨️ 快捷键说明

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