Esempio n. 1
0
/* Client requested we send the queue so we get it from audio.c and
 * send it to the client. */
static int req_send_queue (struct client *cli)
{
	int i;
	struct plist *queue;

	logit ("Client with fd %d wants queue... sending it", cli->socket);

	if (!send_int(cli->socket, EV_DATA)) {
		logit ("Error while sending response; disconnecting the client");
		close (cli->socket);
		del_client (cli);
		return 0;
	}

	queue = audio_queue_get_contents ();

	for (i = 0; i < queue->num; i++)
		if (!plist_deleted(queue, i)) {
			if(!send_item(cli->socket, &queue->items[i])){
				logit ("Error sending queue; disconnecting the client");
				close (cli->socket);
				del_client (cli);
				free (queue);
				return 0;
			}
		}

	plist_free (queue);
	free (queue);

	if (!send_item (cli->socket, NULL)) {
		logit ("Error while sending end of playlist mark; "
		       "disconnecting the client");
		close (cli->socket);
		del_client (cli);
		return 0;
	}

	logit ("Queue sent");
	return 1;
}
Esempio n. 2
0
void KClient::ingameSender()
{
    tick++;

    int dx = -1 + ( random() % 3 );
    int dy = -1 + ( random() % 3 );
    send_move( myCoord.x + dx,
               myCoord.y + dy );
    sendCounter[FUNCTION_MOVE]++;

    // 自分以外のmovableに興味を持つ。
    std::map<vce::VUint32,TestMovable*>::iterator it;
    int cnt=0;
    for(it=movmap.begin(); it != movmap.end(); ++it ){
        TestMovable *m = (*it).second;
        assert(m);
        if( m->typeID == k_proto::MOVABLE_GOBLIN ){
            send_attack( m->id );
            sendCounter[ FUNCTION_ATTACK]++;
            cnt++;
            if( cnt == 15) break; // 一度にあまりたくさん攻撃しない
        }
    }

    // 地形取得
    if( recvCounter[FUNCTION_LANDSCAPERESULT] == 0 ){
        // 全部一気に取得
        send_landscape( 0, 0,0, 32,32 );
        sendCounter[FUNCTION_LANDSCAPE]++;
        send_landscape( 0, 32,0, 64,32 );
        sendCounter[FUNCTION_LANDSCAPE]++;
        send_landscape( 1, 0,0, 32,32 );
        sendCounter[FUNCTION_LANDSCAPE]++;
        send_landscape( 1, 32,0, 64,32 );
        sendCounter[FUNCTION_LANDSCAPE]++;
        send_landscape( 1, 0,0, 32,32 );
        sendCounter[FUNCTION_LANDSCAPE]++;
        send_landscape( 1, 32,0, 64,32 );
        sendCounter[FUNCTION_LANDSCAPE]++;
    }
    if( recvCounter[FUNCTION_ITEMNOTIFY] == 0 ){
        send_item();
        sendCounter[FUNCTION_ITEM]++;
    }
    
}
Esempio n. 3
0
/* Handle CMD_SEND_PLIST. Some client requested to get the playlist, so we asked
 * another client to send it (EV_SEND_PLIST). */
static int req_send_plist (struct client *cli)
{
	int requesting = find_cli_requesting_plist ();
	int send_fd;
	struct plist_item *item;
	int serial;

	debug ("Client with fd %d wants to send its playlists", cli->socket);

	if (requesting == -1) {
		logit ("No clients are requesting the playlist");
		send_fd = -1;
	}
	else {
		send_fd = clients[requesting].socket;
		if (!send_int(send_fd, EV_DATA)) {
			logit ("Error while sending response; disconnecting the client");
			close (send_fd);
			del_client (&clients[requesting]);
			send_fd = -1;
		}
	}

	if (!get_int(cli->socket, &serial)) {
		logit ("Error while getting serial");
		return 0;
	}

	if (send_fd != -1 && !send_int(send_fd, serial)) {
		error ("Error while sending serial; disconnecting the client");
		close (send_fd);
		del_client (&clients[requesting]);
		send_fd = -1;
	}

	/* Even if no clients are requesting the playlist, we must read it,
	 * because there is no way to say that we don't need it. */
	while ((item = recv_item(cli->socket)) && item->file[0]) {
		if (send_fd != -1 && !send_item(send_fd, item)) {
			logit ("Error while sending item; disconnecting the client");
			close (send_fd);
			del_client (&clients[requesting]);
			send_fd = -1;
		}
		plist_free_item_fields (item);
		free (item);
	}

	if (item) {
		plist_free_item_fields (item);
		free (item);
		logit ("Playlist sent");
	}
	else
		logit ("Error while receiving item");

	if (send_fd != -1 && !send_item (send_fd, NULL)) {
		logit ("Error while sending end of playlist mark; "
		       "disconnecting the client");
		close (send_fd);
		del_client (&clients[requesting]);
		return 0;
	}

	if (requesting != -1)
		clients[requesting].requests_plist = 0;

	return item ? 1 : 0;
}