• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ packet_create函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中packet_create函数的典型用法代码示例。如果您正苦于以下问题:C++ packet_create函数的具体用法?C++ packet_create怎么用?C++ packet_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了packet_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: net_game_thread

void net_game_thread(net_client_descr_t *clients) {
    Field *net_field = malloc(sizeof(Field));
    char* field_buffer = malloc(512);

    game_init(net_field);

    for(int i = 0; i < MAX_CONNECTIONS; i++) {
        // sending packet 2 (game start)
        Packet *p = (Packet*) packet_create(2, 1, "1");
        queue_push(clients[i].send, p);
        clients[i].field = net_field;
    }
    
    while(net_server_status != SHUTDOWN) {
        game_update(net_field);

        int game_over = 1;
        for(int i = 0; i < MAX_CONNECTIONS; i++) {
            if (!net_field->players[i].is_dead) game_over = 0;
        }
        if (game_over) {
            Packet* p = (Packet *) packet_create(8, 1, "1");
            for(int i = 0; i < MAX_CONNECTIONS; i++) queue_push(clients[i].send, p);
            net_server_status = SHUTDOWN;
            break;
        }

        packer_pack_field(field_buffer, net_field);
        Packet* p = (Packet*) packet_create(3, strlen(field_buffer), field_buffer);
        for(int i = 0; i < MAX_CONNECTIONS; i++) queue_push(clients[i].send, p);
        usleep(30000);
    }
}
开发者ID:dekamaru,项目名称:space_invaders,代码行数:33,代码来源:net.c


示例2: irc_send_ping

extern int irc_send_ping(t_connection * conn)
{
    t_packet * p;
    char data[MAX_IRC_MESSAGE_LEN];
    
    if (!conn) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
	return -1;
    }
    if (!(p = packet_create(packet_class_raw))) {
	eventlog(eventlog_level_error,__FUNCTION__,"could not create packet");
	return -1;
    }

    if((conn_get_wol(conn) == 1))
        return 0;

    conn_set_ircping(conn,get_ticks());
    if (conn_get_state(conn)==conn_state_bot_username)
    	sprintf(data,"PING :%u\r\n",conn_get_ircping(conn)); /* Undernet doesn't reveal the servername yet ... neither do we */
    else if ((6+strlen(server_get_hostname())+2+1)<=MAX_IRC_MESSAGE_LEN)
    	sprintf(data,"PING :%s\r\n",server_get_hostname());
    else
    	eventlog(eventlog_level_error,__FUNCTION__,"maximum message length exceeded");
    eventlog(eventlog_level_debug,__FUNCTION__,"[%d] sent \"%s\"",conn_get_socket(conn),data);
    packet_set_size(p,0);
    packet_append_data(p,data,strlen(data));
    conn_push_outqueue(conn,p);
    packet_del_ref(p);
    return 0;
}
开发者ID:91D2,项目名称:pvpgn,代码行数:31,代码来源:irc.c


示例3: send_d2cs_gameinforeq

extern int send_d2cs_gameinforeq(t_connection * c)
{
	t_packet	* packet;
	t_game		* game;
	t_realm		* realm;

	if (!(c))
	{
		eventlog(eventlog_level_error,__FUNCTION__,"got NULL conn");
		return -1;
	}
	
	if (!(game = conn_get_game(c)))
	{
		eventlog(eventlog_level_error,__FUNCTION__,"conn had NULL game");
		return -1;
	}

	if (!(realm = conn_get_realm(c)))
	{
		eventlog(eventlog_level_error,__FUNCTION__,"conn had NULL realm");
		return -1;
	}


	if ((packet=packet_create(packet_class_d2cs_bnetd))) {
		packet_set_size(packet,sizeof(t_bnetd_d2cs_gameinforeq));
		packet_set_type(packet,BNETD_D2CS_GAMEINFOREQ);
		bn_int_set(&packet->u.bnetd_d2cs_gameinforeq.h.seqno,0);
		packet_append_string(packet,game_get_name(game));
		conn_push_outqueue(realm_get_conn(realm),packet);
		packet_del_ref(packet);
	}
	return 0;
}
开发者ID:BackupTheBerlios,项目名称:pvpgn,代码行数:35,代码来源:handle_d2cs.c


示例4: cyberspace_transmit

/**
 *  \brief Cyberspace data transmission.
 *
 *         This function sends data between the cyberspace server and
 *         clients.
 *
 * @param fd            communication socket to use
 * @param tag           tag for data
 * @param data          data to transmit
 * @param len           length of data to transmit
 * @return              the result of the packet_send() function
 */
int cyberspace_transmit(int fd, int tag, unsigned char * data, int len)
{
        unsigned char packet[MAX_PACKET_SIZE] = {0};

        packet_create(tag, data, len, packet);
        return packet_send(fd, packet);
}
开发者ID:tnemeth,项目名称:Cyberspace-cybercomms,代码行数:19,代码来源:cybercomms.c


示例5: rx_source_adv

void rx_source_adv(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct source_adv_p *source = (struct source_adv_p *) (packet->data + nodedata->overhead);
    struct sensor_adv_p *sensor;
    packet_t *packet0;
    destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}};
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    /* check adv sequence */
    if (source->s_seq <= nodedata->s_seq[source->source]) {
        /* old request */
        packet_dealloc(packet);
        return;
    }
    nodedata->s_seq[source->source] = source->s_seq;
    
    /* reply */
    packet0 = packet_create(c, nodedata->overhead + sizeof(struct sensor_adv_p), -1);
    sensor = (struct sensor_adv_p *) (packet0->data + nodedata->overhead);
    if (SET_HEADER(&c0, packet0, &dst) == -1) {
        packet_dealloc(packet);
        packet_dealloc(packet0);
        return;
    }
    sensor->type = SENSOR_ADV_TYPE;
    sensor->sensor = c->node;
    sensor->source = source->source;
    sensor->s_seq = source->s_seq;
    TX(&c0, packet0);
    packet_dealloc(packet);

    return;
}
开发者ID:gabrielleLQX,项目名称:wsnet,代码行数:33,代码来源:gossip_sensor.c


示例6: probe_create

probe_t * probe_create()
{
    probe_t * probe;

    // We calloc probe to set *_time and caller members to 0
    if (!(probe = calloc(1, sizeof(probe_t))))   goto ERR_PROBE;
    if (!(probe->packet = packet_create())) {
        fprintf(stderr, "Cannot create packet\n");
        goto ERR_PACKET;
    }
    if (!(probe->layers = dynarray_create()))    goto ERR_LAYERS;
//    if (!(probe->bitfield = bitfield_create(0))) goto ERR_BITFIELD;
    probe_set_left_to_send(probe, 1);
    return probe;

    /*
ERR_BITFIELD:
    probe_layers_free(probe);
    */
ERR_LAYERS:
    packet_free(probe->packet);
ERR_PACKET:
    free(probe);
ERR_PROBE:
    return NULL;
}
开发者ID:drt24,项目名称:libparistraceroute,代码行数:26,代码来源:probe.c


示例7: network_open_tcp_channel

/*
 * Open a TCP channel with the remote endpoint
 */
DWORD network_open_tcp_channel(Remote *remote, LPCSTR remoteHost, 
		USHORT remotePort, PacketRequestCompletion *complete)
{
	Packet *request = packet_create(PACKET_TLV_TYPE_REQUEST,
			"network_open_tcp_channel");
	DWORD res = ERROR_SUCCESS;

	do
	{
		// Verify that the packet was allocated
		if (!request)
		{
			res = ERROR_NOT_ENOUGH_MEMORY;
			break;
		}

		// Add the host/port combination
		packet_add_tlv_string(request, TLV_TYPE_NETWORK_GENERAL_REMOTE_HOST,
				remoteHost);
		packet_add_tlv_uint(request, TLV_TYPE_NETWORK_GENERAL_REMOTE_PORT,
				remotePort);

		// Transmit the request
		res = packet_transmit(remote, request, complete);

	} while (0);

	return res;
}
开发者ID:hdm,项目名称:framework2,代码行数:32,代码来源:util.c


示例8: send_bits_gamelist_del

extern int send_bits_gamelist_del(t_connection * c, t_game const * game)
{
    t_packet * p;

    if (!game) {
        eventlog(eventlog_level_error,"send_bits_gamelist_del","got NULL game");
        return -1;
    }
    p = packet_create(packet_class_bits);
    if (!p) {
        eventlog(eventlog_level_error,"send_bits_gamelist_del","could not create packet");
        return -1;
    }
    packet_set_size(p,sizeof(t_bits_gamelist_del));
    packet_set_type(p,BITS_GAMELIST_DEL);
    /***/
    bn_int_set(&p->u.bits_gamelist_del.id,game_get_id(game));
    /***/
    if (c) {
        /* send the packet on the connection */
        bits_packet_generic(p,BITS_ADDR_PEER);
        send_bits_packet_on(p,c);
    } else {
        /* broadcast the packet */
        bits_packet_generic(p,BITS_ADDR_BCAST);
        handle_bits_packet(bits_loopback_connection,p); /* also remove the game from this server */
        send_bits_packet(p);
    }
    packet_del_ref(p);
    return 0;
}
开发者ID:cooljeanius,项目名称:bnetd,代码行数:31,代码来源:bits_game.c


示例9: irc_send_pong

extern int irc_send_pong(t_connection * conn, char const * params)
{
    t_packet * p;
    char data[MAX_IRC_MESSAGE_LEN];
    
    if (!conn) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
	return -1;
    }
    if ((1+strlen(server_get_hostname())+1+4+1+strlen(server_get_hostname())+((params)?(2+strlen(params)):(0))+2+1) > MAX_IRC_MESSAGE_LEN) {
	eventlog(eventlog_level_error,__FUNCTION__,"max message length exceeded");
	return -1;
    }
    if (!(p = packet_create(packet_class_raw))) {
	eventlog(eventlog_level_error,__FUNCTION__,"could not create packet");
	return -1;
    }
    
    if (params)
    	sprintf(data,":%s PONG %s :%s\r\n",server_get_hostname(),server_get_hostname(),params);
    else
    	sprintf(data,":%s PONG %s\r\n",server_get_hostname(),server_get_hostname());
    eventlog(eventlog_level_debug,__FUNCTION__,"[%d] sent \"%s\"",conn_get_socket(conn),data);
    packet_set_size(p,0);
    packet_append_data(p,data,strlen(data));
    conn_push_outqueue(conn,p);
    packet_del_ref(p);
    return 0;
}
开发者ID:91D2,项目名称:pvpgn,代码行数:29,代码来源:irc.c


示例10: on_d2cs_authreply

static int on_d2cs_authreply(t_connection * c, t_packet const * packet)
{
	t_packet	* rpacket;
	unsigned int	version;
	unsigned int	try_version;
	unsigned int	reply;
	char const	* realmname;
	t_realm		* realm;

	if (packet_get_size(packet)<sizeof(t_d2cs_bnetd_authreply)) {
		eventlog(eventlog_level_error,__FUNCTION__,"got bad packet size");
		return -1;
	}
	if (!(realmname=packet_get_str_const(packet,sizeof(t_d2cs_bnetd_authreply),REALM_NAME_LEN))) {
		eventlog(eventlog_level_error,__FUNCTION__,"got bad realmname");
		return -1;
	}
        if (!(realm=realmlist_find_realm(realmname))) {
		realm=realmlist_find_realm_by_ip(conn_get_addr(c)); /* should not fail - checked in handle_init_packet() handle_init.c */
		eventlog(eventlog_level_warn,__FUNCTION__, "warn: realm name mismatch %s %s", realm_get_name(realm), realmname);
		if (!(prefs_allow_d2cs_setname())) { /* fail if allow_d2cs_setname = false */
			eventlog(eventlog_level_error,__FUNCTION__, "d2cs not allowed to set realm name");
			return -1;
		}
		if (realm_get_active(realm)) { /* fail if realm already active */
			eventlog(eventlog_level_error,__FUNCTION__, "cannot set realm name to %s (realm already active)",realmname);
			return -1;
		}
		realm_set_name(realm,realmname);
        }
	version=prefs_get_d2cs_version();
	try_version=bn_int_get(packet->u.d2cs_bnetd_authreply.version);
	if (version && version != try_version) {
		eventlog(eventlog_level_error,__FUNCTION__,"d2cs version mismatch 0x%X - 0x%X",
			try_version,version);
		reply=BNETD_D2CS_AUTHREPLY_BAD_VERSION;
	} else {
		reply=BNETD_D2CS_AUTHREPLY_SUCCEED;
	}

	if (reply==BNETD_D2CS_AUTHREPLY_SUCCEED) {
		eventlog(eventlog_level_info,__FUNCTION__,"d2cs %s authed",
			addr_num_to_ip_str(conn_get_addr(c)));
		conn_set_state(c,conn_state_loggedin);
		realm_active(realm,c);
	} else {
		eventlog(eventlog_level_error,__FUNCTION__,"failed to auth d2cs %s",
			addr_num_to_ip_str(conn_get_addr(c)));
	}
	if ((rpacket=packet_create(packet_class_d2cs_bnetd))) {
		packet_set_size(rpacket,sizeof(t_bnetd_d2cs_authreply));
		packet_set_type(rpacket,BNETD_D2CS_AUTHREPLY);
		bn_int_set(&rpacket->u.bnetd_d2cs_authreply.h.seqno,1);
		bn_int_set(&rpacket->u.bnetd_d2cs_authreply.reply,reply);
		conn_push_outqueue(c,rpacket);
		packet_del_ref(rpacket);
	}
	return 0;
}
开发者ID:BackupTheBerlios,项目名称:pvpgn,代码行数:59,代码来源:handle_d2cs.c


示例11: main

/**
 * Programma per generare codice C (array) di pacchetti di vari protocolli,
 * 	anche concatenati
 */
int main(int argc,  char *argv[])
{
	if(argc < 3)
	{
		printf("use:\n\t%s ... eth ip tcp data", argv[0]);
		return 0;
	}
	
	int i;
	packet_t *p = packet_create(argv[argc-1], strlen(argv[argc-1]));
	

	for(i = (argc - 2); i > 0; i--)
	{
		if(add_proto(p, argv[i]))
			printf("%s added\n", argv[i]);
		else
		{
			printf("unknow protocol %s\n", argv[i]);
			return 0;
		}
	}
	
	printf("%d\n\n", p->size);
	
	char *c_data = (char *) malloc(p->size * 6 + 30);
	
	strcpy(c_data, "char test_packet[] = {\t");
	
	for(i = 0; i < p->size; i++)
	{
		char t_data[8];
		sprintf(t_data, "0x%.2X", p->data[i]);
		strcat(c_data, t_data);
		
		if(i < p->size -1) 
		{
			if(((i % 7) == 0) && i > 3)
				strcat(c_data, ",\n\t\t\t\t\t\t");
			else
				strcat(c_data, ", ");
		}
	}
	
	strcat(c_data, " };\n");
	
	char t_data[8];
	sprintf(t_data, "%d", p->size);
	strcat(c_data, "packet_t *pack = packet_create(test_packet, ");
	strcat(c_data, t_data);
	strcat(c_data, ");\n\n");
	
	printf("\n%s\n", c_data);
	
	
	return 0;
}
开发者ID:dakk,项目名称:spiderpig-os,代码行数:61,代码来源:main.c


示例12: channel_write

/*
 * Write to the remote end of the channel
 */
DWORD channel_write(Channel *channel, Remote *remote, Tlv *addend,
                    DWORD addendLength, PUCHAR buffer, ULONG length,
                    ChannelCompletionRoutine *completionRoutine)
{
    PacketRequestCompletion requestCompletion, *realRequestCompletion = NULL;
    ChannelCompletionRoutine *dupe = NULL;
    DWORD res = ERROR_SUCCESS;
    LPCSTR method = "core_channel_write";
    Packet *request;
    Tlv methodTlv;

    do
    {
        // Allocate a request packet
        if (!(request = packet_create(PACKET_TLV_TYPE_REQUEST, NULL)))
        {
            res = ERROR_NOT_ENOUGH_MEMORY;
            break;
        }

        // Add the supplied TLVs
        packet_add_tlvs(request, addend, addendLength);

        // If no method TLV as added, add the default one.
        if (packet_get_tlv(request, TLV_TYPE_METHOD, &methodTlv) != ERROR_SUCCESS)
            packet_add_tlv_string(request, TLV_TYPE_METHOD, method);

        // Add the channel identifier and the length to write
        packet_add_tlv_uint(request, TLV_TYPE_CHANNEL_ID, channel_get_id(channel));

        // if the channel data is ment to be compressed, compress it!
        if( channel_is_flag( channel, CHANNEL_FLAG_COMPRESS ) )
            packet_add_tlv_raw(request, TLV_TYPE_CHANNEL_DATA|TLV_META_TYPE_COMPRESSED, buffer, length);
        else
            packet_add_tlv_raw(request, TLV_TYPE_CHANNEL_DATA, buffer, length);

        packet_add_tlv_uint(request, TLV_TYPE_LENGTH, channel_get_id(channel));

        // Initialize the packet completion routine
        if (completionRoutine)
        {
            // Duplicate the completion routine
            dupe = channel_duplicate_completion_routine(completionRoutine);

            requestCompletion.context = dupe;
            requestCompletion.routine = _channel_packet_completion_routine;
            realRequestCompletion     = &requestCompletion;
        }

        // Transmit the packet with the supplied completion routine, if any.
        res = packet_transmit(remote, request, realRequestCompletion);

    } while (0);

    return res;
}
开发者ID:C40,项目名称:metasploit-framework,代码行数:59,代码来源:channel.c


示例13: packet_create

packet_t *packet_new(enum packet_id type, ...)
{
	packet_constructor_t pc = packet_create(type);

	/* build the fields */

	va_list ap;
	va_start(ap, type);

	unsigned nfields = packet_format[type].nfields;
	for (unsigned field = 0; field < nfields; field++)
	{
		switch (packet_format[type].ftype[field])
		{
		case FIELD_BYTE:
			packet_add_jbyte(&pc, va_arg(ap, int));
			break;

		case FIELD_UBYTE:
			packet_add_jubyte(&pc, va_arg(ap, int));
			break;

		case FIELD_SHORT:
			packet_add_jshort(&pc, va_arg(ap, int));
			break;

		case FIELD_INT:
			packet_add_jint(&pc, va_arg(ap, long));
			break;

		case FIELD_LONG:		
			packet_add_jlong(&pc, va_arg(ap, long long));
			break;

		case FIELD_FLOAT:
			packet_add_jfloat(&pc, va_arg(ap, double));
			break;

		case FIELD_DOUBLE:
			packet_add_jdouble(&pc, va_arg(ap, double));
			break;

		case FIELD_STRING:
			packet_add_string(&pc, va_arg(ap, unsigned char *));
			break;

		default:
			dief("unhandled field type %d (packet 0x%02x, field %u)",
			     packet_format[type].ftype[field], type, field);
		}
	}

	va_end(ap);

	return packet_construct(&pc);
}
开发者ID:fis,项目名称:mcmap,代码行数:56,代码来源:protocol.c


示例14: on_d2cs_authreply

static int on_d2cs_authreply(t_connection * c, t_packet const * packet)
{
	t_packet	* rpacket;
	unsigned int	version;
	unsigned int	try_version;
	unsigned int	reply;
	char const	* realmname;
	t_realm		* realm;

	if (packet_get_size(packet)<sizeof(t_d2cs_bnetd_authreply)) {
		eventlog(eventlog_level_error,"on_d2cs_authreply","got bad packet size");
		return -1;
	}
	if (!(realmname=packet_get_str_const(packet,sizeof(t_d2cs_bnetd_authreply),REALM_NAME_LEN))) {
		eventlog(eventlog_level_error,"on_d2cs_authreply","got bad realmname");
		return -1;
	}
        if (!(realm=realmlist_find_realm_by_ip(conn_get_addr(c)))) {
                eventlog(eventlog_level_error,"handle_init_packet", "realm not found");
                return -1;
        }
	if (realm_get_name(realm) && strcasecmp(realmname,realm_get_name(realm))) {
                eventlog(eventlog_level_error,"handle_init_packet", "warn: realm name mismatch %s %s",
			realm_get_name(realm),realmname);
	}

	version=prefs_get_d2cs_version();
	try_version=bn_int_get(packet->u.d2cs_bnetd_authreply.version);
	if (version && version != try_version) {
		eventlog(eventlog_level_error,"on_d2cs_authreply","d2cs version mismatch 0x%X - 0x%X",
			try_version,version);
		reply=BNETD_D2CS_AUTHREPLY_BAD_VERSION;
	} else {
		reply=BNETD_D2CS_AUTHREPLY_SUCCEED;
	}

	if (reply==BNETD_D2CS_AUTHREPLY_SUCCEED) {
		eventlog(eventlog_level_error,"on_d2cs_authreply","d2cs %s authed",
			addr_num_to_ip_str(conn_get_addr(c)));
		conn_set_state(c,conn_state_loggedin);
		if (prefs_allow_d2cs_setname()) realm_set_name(realm,realmname);
		realm_active(realm,c);
	} else {
		eventlog(eventlog_level_error,"on_d2cs_authreply","failed to auth d2cs %s",
			addr_num_to_ip_str(conn_get_addr(c)));
	}
	if ((rpacket=packet_create(packet_class_d2cs_bnetd))) {
		packet_set_size(rpacket,sizeof(t_bnetd_d2cs_authreply));
		packet_set_type(rpacket,BNETD_D2CS_AUTHREPLY);
		bn_int_set(&rpacket->u.bnetd_d2cs_authreply.reply,reply);
		queue_push_packet(conn_get_out_queue(c),rpacket);
		packet_del_ref(rpacket);
	}
	return 0;
}
开发者ID:Danteoriginal,项目名称:bnetd,代码行数:55,代码来源:handle_d2cs.c


示例15: channel_interact

/*
 * Interact with a given channel such that data on the remote end is
 * forwarded in real time rather than being polled.
 */
DWORD channel_interact(Channel *channel, Remote *remote, Tlv *addend,
                       DWORD addendLength, BOOL enable,
                       ChannelCompletionRoutine *completionRoutine)
{
    PacketRequestCompletion requestCompletion, *realRequestCompletion = NULL;
    ChannelCompletionRoutine *dupe = NULL;
    LPCSTR method = "core_channel_interact";
    DWORD res = ERROR_SUCCESS;
    Packet *request;
    Tlv methodTlv;

    do
    {
        if (!(request = packet_create(PACKET_TLV_TYPE_REQUEST,
                                      NULL)))
        {
            res = ERROR_NOT_ENOUGH_MEMORY;
            break;
        }

        // Add the supplied TLVs
        packet_add_tlvs(request, addend, addendLength);

        // If no method TLV as added, add the default one.
        if (packet_get_tlv(request, TLV_TYPE_METHOD,
                           &methodTlv) != ERROR_SUCCESS)
            packet_add_tlv_string(request, TLV_TYPE_METHOD,
                                  method);

        // Add the channel identifier
        packet_add_tlv_uint(request, TLV_TYPE_CHANNEL_ID,
                            channel_get_id(channel));

        // Add the enable/disable boolean
        packet_add_tlv_bool(request, TLV_TYPE_BOOL, enable);

        // Initialize the packet completion routine
        if (completionRoutine)
        {
            // Duplicate the completion routine
            dupe = channel_duplicate_completion_routine(completionRoutine);

            requestCompletion.context = dupe;
            requestCompletion.routine = _channel_packet_completion_routine;
            realRequestCompletion     = &requestCompletion;
        }

        // Transmit the packet with the supplied completion routine, if any.
        res = packet_transmit(remote, request, realRequestCompletion);

    } while (0);

    return res;
}
开发者ID:C40,项目名称:metasploit-framework,代码行数:58,代码来源:channel.c


示例16: on_client_gameinforeq

static int on_client_gameinforeq(t_connection * c, t_packet * packet)
{
	t_game_charinfo	* info;
	t_packet	* rpacket;
	char const	* gamename;
	t_game		* game;
	unsigned int	seqno, n;

	if (!(gamename=packet_get_str_const(packet,sizeof(t_client_d2cs_gameinforeq),MAX_GAMENAME_LEN))) {
		eventlog(eventlog_level_error,__FUNCTION__,"got bad game name");
		return -1;
	}
	if (!(game=d2cs_gamelist_find_game(gamename))) {
		eventlog(eventlog_level_error,__FUNCTION__,"game %s not found",gamename);
		return 0;
	}
	seqno=bn_short_get(packet->u.client_d2cs_gameinforeq.seqno);
	if ((rpacket=packet_create(packet_class_d2cs))) {
		packet_set_size(rpacket,sizeof(t_d2cs_client_gameinforeply));
		packet_set_type(rpacket,D2CS_CLIENT_GAMEINFOREPLY);
		bn_short_set(&rpacket->u.d2cs_client_gameinforeply.seqno,seqno);
		bn_int_set(&rpacket->u.d2cs_client_gameinforeply.gameflag,game_get_gameflag(game));
		bn_int_set(&rpacket->u.d2cs_client_gameinforeply.etime,std::time(NULL)-d2cs_game_get_create_time(game));
		bn_byte_set(&rpacket->u.d2cs_client_gameinforeply.charlevel,game_get_charlevel(game));
		bn_byte_set(&rpacket->u.d2cs_client_gameinforeply.leveldiff,game_get_leveldiff(game));
		bn_byte_set(&rpacket->u.d2cs_client_gameinforeply.maxchar,game_get_maxchar(game));
		packet_append_string(rpacket, game_get_desc(game) ? game_get_desc(game) : NULL);

		n=0;
		BEGIN_LIST_TRAVERSE_DATA_CONST(game_get_charlist(game),info,t_game_charinfo)
		{
			if (!info->charname) {
				eventlog(eventlog_level_error,__FUNCTION__,"got NULL charname in game %s char list",gamename);
				continue;
			}
			packet_append_string(rpacket,info->charname);
			bn_byte_set(&rpacket->u.d2cs_client_gameinforeply.chclass[n],info->chclass);
			/* GUI is limited to a max level of 255 */
			if (info->level < 255) {
			bn_byte_set(&rpacket->u.d2cs_client_gameinforeply.level[n],info->level);
			} else {
				bn_byte_set(&rpacket->u.d2cs_client_gameinforeply.level[n], 255);
			}
			n++;
		}
		END_LIST_TRAVERSE_DATA_CONST()

		bn_byte_set(&rpacket->u.d2cs_client_gameinforeply.currchar,n);
		if (n!=game_get_currchar(game)) {
			eventlog(eventlog_level_error,__FUNCTION__,"game %s character list corrupted",gamename);
		}
		conn_push_outqueue(c,rpacket);
		packet_del_ref(rpacket);
	}
开发者ID:BackupTheBerlios,项目名称:pvpgn-svn,代码行数:54,代码来源:handle_d2cs.cpp


示例17: irc_send_cmd2

extern int irc_send_cmd2(t_connection * conn, char const * prefix, char const * command, char const * postfix, char const * comment)
{
    t_packet * p;
    char data[MAX_IRC_MESSAGE_LEN+1];
    int len;
    
    if (!conn) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
	return -1;
    }
    if (!prefix)
    {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL prefix");
	return -1;
    }
    if (!command) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL command");
	return -1;
    }
    if (!postfix)
    {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL postfix");
	return -1;
    }
    
    if (!(p = packet_create(packet_class_raw))) {
	eventlog(eventlog_level_error,__FUNCTION__,"could not create packet");
	return -1;
    }

    if (comment) {
        len = 1+strlen(prefix)+1+strlen(command)+1+strlen(postfix)+2+strlen(comment)+1+2;
    	if (len > MAX_IRC_MESSAGE_LEN) {
	    eventlog(eventlog_level_error,__FUNCTION__,"message to send is too large (%d bytes)",len);
	    return -1;
	}
	else
	    sprintf(data,":%s %s %s :%s\r\n",prefix,command,postfix,comment);
    } else {
        len = 1+strlen(prefix)+1+strlen(command)+1+strlen(postfix)+1+2;
    	if (len > MAX_IRC_MESSAGE_LEN) {
	    eventlog(eventlog_level_error,__FUNCTION__,"message to send is too large (%d bytes)",len);
	    return -1;
	}
	else
	sprintf(data,":%s %s %s\r\n",prefix,command,postfix);
    }
    packet_set_size(p,0);
    packet_append_data(p,data,len);
    // eventlog(eventlog_level_debug,__FUNCTION__,"[%d] sent \"%s\"",conn_get_socket(conn),data);
    conn_push_outqueue(conn,p);
    packet_del_ref(p);
    return 0;
}
开发者ID:91D2,项目名称:pvpgn,代码行数:54,代码来源:irc.c


示例18: START_TEST

END_TEST

START_TEST(test_packet_decode_with_null_data_pointer)
{
    Packet *packet = packet_create( );

    int err = packet_decode(packet, NULL, sizeof pkt10);

    fail_unless((err != 0), "packet_decode returned OK expected ERROR");

    packet_destroy(packet);
}
开发者ID:wtfbbqhax,项目名称:LibPacket,代码行数:12,代码来源:check_packet_decode.c


示例19: transmit

int transmit(size_t *sent)
{
	void *packet = NULL;
	size_t bytes = 0;

	if (packet_create(&packet, &bytes))
		return -1;
	if (!packet)
		return 0;

	return network_packet(packet, bytes, sent);
}
开发者ID:castl,项目名称:pmu_sync_sampler,代码行数:12,代码来源:network.cpp


示例20: udptest_send

extern int udptest_send(t_connection const * c)
{
    t_packet *         upacket;
    struct sockaddr_in caddr;
    unsigned int       tries,successes;

    memset(&caddr,0,sizeof(caddr));
    caddr.sin_family = PSOCK_AF_INET;
    caddr.sin_port = htons(conn_get_game_port(c));
    caddr.sin_addr.s_addr = htonl(conn_get_game_addr(c));

    for (tries=successes=0; successes!=2 && tries<5; tries++)
    {
        if (!(upacket = packet_create(packet_class_udp)))
        {
            eventlog(eventlog_level_error,"udptest_send","[%d] could not allocate memory for packet",conn_get_socket(c));
            continue;
        }
        packet_set_size(upacket,sizeof(t_server_udptest));
        packet_set_type(upacket,SERVER_UDPTEST);
        bn_int_tag_set(&upacket->u.server_udptest.bnettag,BNETTAG);

        if (hexstrm)
        {
            fprintf(hexstrm,"%d: send class=%s[0x%02hx] type=%s[0x%04hx] ",
                    conn_get_game_socket(c),
                    packet_get_class_str(upacket),(unsigned int)packet_get_class(upacket),
                    packet_get_type_str(upacket,packet_dir_from_server),packet_get_type(upacket));
            fprintf(hexstrm,"from=%s ",
                    addr_num_to_addr_str(conn_get_game_addr(c),conn_get_game_port(c)));
            fprintf(hexstrm,"to=%s ",
                    addr_num_to_addr_str(ntohl(caddr.sin_addr.s_addr),ntohs(caddr.sin_port)));
            fprintf(hexstrm,"length=%u\n",
                    packet_get_size(upacket));
            hexdump(hexstrm,packet_get_raw_data(upacket,0),packet_get_size(upacket));
        }

        if (psock_sendto(conn_get_game_socket(c),
                         packet_get_raw_data_const(upacket,0),packet_get_size(upacket),
                         0,(struct sockaddr *)&caddr,(psock_t_socklen)sizeof(caddr))!=(int)packet_get_size(upacket))
            eventlog(eventlog_level_error,"udptest_send","[%d] failed to send UDPTEST to %s (attempt %u) (psock_sendto: %s)",conn_get_socket(c),addr_num_to_addr_str(ntohl(caddr.sin_addr.s_addr),conn_get_game_port(c)),tries+1,strerror(psock_errno()));
        else
            successes++;

        packet_del_ref(upacket);
    }

    if (successes!=2)
        return -1;

    return 0;
}
开发者ID:Danteoriginal,项目名称:bnetd-1,代码行数:52,代码来源:udptest_send.c



注:本文中的packet_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ packet_disconnect函数代码示例发布时间:2022-05-30
下一篇:
C++ packet_check_eom函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap