Пример #1
0
void prot_qun_send_msg( struct qqclient* qq, uint number, char* msg_content )
{
	qqpacket* p = packetmgr_new_send( qq, QQ_CMD_QUN_CMD );
	if( !p ) return;
	ushort len = strlen( msg_content );
	bytebuffer *buf = p->buf;
	put_byte( buf, 0x2A );
	put_int( buf, number );
	bytebuffer* content_buf;
	NEW( content_buf, sizeof(bytebuffer) ,bytebuffer);
	if( !content_buf ) {
		packetmgr_del_packet( &qq->packetmgr, p );
		return;
	}
	content_buf->size = PACKET_SIZE;
	
	put_word( content_buf, 0x0001 );	//text type
	put_byte( content_buf, 0x01 );		//slice_count
	put_byte( content_buf, 0x00 );		//slice_no
	put_word( content_buf, 0 );		//id??
	put_int( content_buf, 0 );		//zeros

	put_int( content_buf, 0x4D534700 ); //"MSG"
	put_int( content_buf, 0x00000000 );
	put_int( content_buf, p->time_create );
	put_int( content_buf, rand() );
	put_int( content_buf, 0x00000000 );
	put_int( content_buf, 0x09008600 );
	char font_name[] = "宋体";	//must be in UTF8
	put_word( content_buf, strlen(font_name) );
	put_data( content_buf, (uchar*)font_name, strlen( font_name) );
	put_word( content_buf, 0x0000 );
	put_byte( content_buf, 0x01 );
	put_word( content_buf, len+3 );
	put_byte( content_buf, 1 );			//unknown, keep 1
	put_word( content_buf, len );
	put_data( content_buf, (uchar*)msg_content, len );
	
	put_word( buf, content_buf->pos );
	put_data( buf, content_buf->data, content_buf->pos );
	DEL( content_buf );
	post_packet( qq, p, SESSION_KEY );
}
Пример #2
0
void* packetmgr_recv( void* data )
{
	int ret;
	qqpacket* p;
	qqclient* qq = (qqclient*)data;
	qqpacketmgr* mgr = &qq->packetmgr;
	uchar* recv_buf;
	int pos;
	NEW( recv_buf, PACKET_SIZE );
	p = packetmgr_new_packet( qq );
	if( !p || !recv_buf ){
		DBG("error: p=%x  buf=%x", p, recv_buf );
		DEL( p ); DEL( recv_buf );
		return NULL;
	}
	pos = 0;
	while( qq->process != P_INIT ){
		ret = qqsocket_recv( qq->socket, recv_buf, PACKET_SIZE-pos );
		if( ret <= 0 ){
			if( qq->process != P_INIT ){
			//	DBG("ret=%d", ret );
				SLEEP(1);
				continue;
			}else{
				break;
			}
		}
		pos += ret;
		//TCP only
		if( qq->network == TCP || qq->network == PROXY_HTTP ){
			if ( pos > 2 ){
				if( !qq->proxy_established && qq->network == PROXY_HTTP ){
					if( strstr( (char*)recv_buf, "200" )!=NULL ){
						DBG("proxy server reply ok!");
						qq->proxy_established = 1;
						prot_login_touch( qq );
						//手动添加到发送队列。
						qqpacket* t;
						while( (t = loop_pop_from_tail( &mgr->temp_loop )) )
							loop_push_to_head( &mgr->ready_loop, t );
						//检查待发送包
						check_ready_packets( qq );
					}else{
						DBG("proxy server reply failure!");
						recv_buf[ret]=0;
						DBG( "%s", recv_buf );
						qqclient_set_process( qq, P_ERROR );
					}
				}else{
					int len = ntohs(*(ushort*)recv_buf);
					if( pos >= len )	//a packet is O.K.
					{
						if( handle_packet( qq, p, recv_buf, len ) < 0 ) {
							pos = 0;
							continue;
						}
						pos -= len;
						//copy data to buf
						if( pos > 0 ){
							memmove( recv_buf, recv_buf+len, pos );
						}
					}else if( pos == PACKET_SIZE ){
						DBG("error: pos: 0x%x ", pos );
						pos = 0;
					}
				}
			}
		}else{	//UDP
			handle_packet( qq, p, recv_buf, ret );
			pos = 0;
		}
	}
	DEL( recv_buf );
	packetmgr_del_packet( mgr, p );
	DBG("end.");
	return NULL;
}
Пример #3
0
void prot_login_verify( struct qqclient* qq )
{
    qqpacket* p = packetmgr_new_send( qq, QQ_CMD_LOGIN_VERIFY );
    if( !p ) return;
    bytebuffer *buf = p->buf;
    bytebuffer *verify_data;
    NEW( verify_data, sizeof(bytebuffer) );
    if( !verify_data ) {
        packetmgr_del_packet( &qq->packetmgr, p );
        return;
    }
    verify_data->size = PACKET_SIZE;
    put_int( verify_data, rand2() );	//random??
    put_word( verify_data, 0x0001 );
    put_int( verify_data, qq->number );
    put_data( verify_data, qq->data.version_spec, sizeof(qq->data.version_spec) );
    put_byte( verify_data, 00 );
    put_word( verify_data, 00 );	//0x0001 什么来的?
    put_data( verify_data, qq->md5_pass1, 16 );
    put_int( verify_data, qq->server_time );
    verify_data->pos += 13;
    put_int( verify_data, qq->server_ip );
    put_int( verify_data, 0 );
    put_int( verify_data, 0 );
    put_word( verify_data, 0x0010 );
    put_data( verify_data, qq->data.verify_key1, 0x10 );
    put_data( verify_data, qq->data.verify_key2, 0x10 );
    //
    put_word( buf, 0x00CA );	//sub cmd??
    put_word( buf, 0x0001 );
    put_data( buf, qq->data.locale, sizeof(qq->data.locale) );
    put_data( buf, qq->data.version_spec, sizeof(qq->data.version_spec) );
    put_word( buf, qq->data.token_c.len );
    put_data( buf, qq->data.token_c.data, qq->data.token_c.len );
    if( verify_data->pos != 104 ) {
        DBG("wrong pos!!!");
    }

    int out_len = 120;
    uchar encrypted[120+10];
    qqencrypt( verify_data->data, verify_data->pos, qq->md5_pass2, encrypted, &out_len );
    put_word( buf, out_len );
    put_data( buf, encrypted, out_len );

    put_word( buf, 0x0000 );
    put_word( buf, 0x018B );
    put_byte( buf, 0x2E );	//length of the following info
    static uchar unknown6[] = {0xE9,0xC4,0xD6,0x5C,0x4D,0x9D,
                               0xA0,0x17,0xE5,0x24,0x6B,0x55,0x57,0xD3,0xAB,0xF1
                              };
    static uchar unknown7[] = {0xCB,0x8D,0xA4,0xE2,0x61,0xC2,
                               0xDD,0x27,0x39,0xEC,0x8A,0xCA,0xA6,0x98,0xF8,0x9B
                              };
    randkey( unknown6 );
    randkey( unknown7 );
    put_byte( buf, 0x01 );
    put_int( buf, rand2()  );
//	put_int( buf, 0x0741E9748  );
    put_word( buf, sizeof(unknown6) );
    put_data( buf, unknown6, sizeof(unknown6) );
    put_byte( buf, 0x02 );
    put_int( buf, rand2()  );
//	put_int( buf, 0x8BED382E  );
    put_word( buf, sizeof(unknown7) );
    put_data( buf, unknown7, sizeof(unknown7) );
    buf->pos += 0x015C;	//395 zeros?  348

    DEL( verify_data );
    post_packet( qq, p, RANDOM_KEY );
}