Exemple #1
0
void serverlist_frame() {
    int i;
    for (i = 0; i < server_count; i++) {
        msg_t *msg = sock_recv(&serverlist[i].sock);
        if (msg) {
            serverlist[i].ping_end = millis();
            skip_data(msg, strlen("info\n"));
            read_server(serverlist + i, read_string(msg));
            if (partial_match(filter, serverlist[i].name) || partial_match(filter, serverlist[i].map)
                    || partial_match(filter, serverlist[i].mod) || partial_match(filter, serverlist[i].gametype))
                ui_output(output_client, "^5%i ^7(%i) %s %s ^5[^7%s^5] [^7%s:%s^5]\n", i, serverlist[i].ping_end - serverlist[i].ping_start,
                        serverlist[i].players, serverlist[i].name, serverlist[i].map, serverlist[i].mod, serverlist[i].gametype);
            serverlist[i].received = qtrue;
        }
        if (serverlist[i].ping_retries > 0
                && !serverlist[i].received && millis() >= serverlist[i].ping_start + PING_TIMEOUT)
            ping_server(serverlist + i);
    }

    master_t *master;
    for (master = masters; master->address; master++) {
        msg_t *msg = sock_recv(&master->sock);
        if (!msg)
            continue;

        char address_string[32];
        qbyte address[4];
        unsigned short port;

        skip_data(msg, strlen("getserversResponse"));
        while (msg->readcount + 7 <= msg->cursize) {
            char prefix = read_char(msg);
            port = 0;

            if (prefix == '\\') {
                read_data(msg, address, 4);
                port = ShortSwap(read_short(msg));
                sprintf(address_string, "%u.%u.%u.%u", address[0], address[1], address[2], address[3]);
            }

            if (port != 0) {
                server_t *server = find_server(address_string, port);
                if (server != NULL)
                    continue;
                server = serverlist + server_count++;
                sock_init(&server->sock);
                strcpy(server->address, address_string);
                server->port = port;
                server->received = qfalse;
                server->ping_retries = MAX_PING_RETRIES + 1;
                ping_server(server);
            }
        }
    }
}
Exemple #2
0
void serverlist_query() {
    output_client = cmd_client();
    strcpy(filter, cmd_argv(1));
    int i;
    for (i = 0; i < server_count; i++) {
        serverlist[i].received = qfalse;
        serverlist[i].ping_retries = MAX_PING_RETRIES + 1;
        ping_server(serverlist + i);
    }

    master_t *master;
    for (master = masters; master->address; master++) {
        msg_t *msg = sock_init_send(&master->sock, qfalse);
        write_string(msg, "getservers %s %d full empty", GAME, PROTOCOL);
        sock_send(&master->sock);
    }
}
Exemple #3
0
/* Send commands requested in params to the server. */
static void server_command (struct parameters *params, lists_t_strs *args)
{
	int sock;

	if ((sock = server_connect()) == -1)
		fatal ("The server is not running!");

	xsignal (SIGPIPE, SIG_IGN);
	if (!ping_server (sock))
		fatal ("Can't connect to the server!");

	if (params->playit)
		interface_cmdline_playit (sock, args);
	if (params->clear)
		interface_cmdline_clear_plist (sock);
	if (params->append)
		interface_cmdline_append (sock, args);
	if (params->enqueue)
		interface_cmdline_enqueue (sock, args);
	if (params->play)
		interface_cmdline_play_first (sock);
	if (params->get_file_info)
		interface_cmdline_file_info (sock);
	if (params->seek_by)
		interface_cmdline_seek_by (sock, params->seek_by);
	if (params->jump_type=='%')
		interface_cmdline_jump_to_percent (sock,params->jump_to);
	if (params->jump_type=='s')
		interface_cmdline_jump_to (sock,params->jump_to);
	if (params->get_formatted_info)
		interface_cmdline_formatted_info (sock, params->formatted_info_param);
	if (params->adj_volume)
		interface_cmdline_adj_volume (sock, params->adj_volume);
	if (params->toggle)
		interface_cmdline_set (sock, params->toggle, 2);
	if (params->on)
		interface_cmdline_set (sock, params->on, 1);
	if (params->off)
		interface_cmdline_set (sock, params->off, 0);
	if (params->exit) {
		if (!send_int(sock, CMD_QUIT))
			fatal ("Can't send command!");
	}
	else if (params->stop) {
		if (!send_int(sock, CMD_STOP) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->pause) {
		if (!send_int(sock, CMD_PAUSE) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->next) {
		if (!send_int(sock, CMD_NEXT) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->previous) {
		if (!send_int(sock, CMD_PREV) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->unpause) {
		if (!send_int(sock, CMD_UNPAUSE) || !send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}
	else if (params->toggle_pause) {
		int state, ev, cmd = -1;

		if (!send_int(sock, CMD_GET_STATE))
			fatal ("Can't send commands!");
		if (!get_int(sock, &ev) || ev != EV_DATA || !get_int(sock, &state))
			fatal ("Can't get data from the server!");

		if (state == STATE_PAUSE)
			cmd = CMD_UNPAUSE;
		else if (state == STATE_PLAY)
			cmd = CMD_PAUSE;

		if (cmd != -1 && !send_int(sock, cmd))
			fatal ("Can't send commands!");
		if (!send_int(sock, CMD_DISCONNECT))
			fatal ("Can't send commands!");
	}

	close (sock);
}
Exemple #4
0
/* Run client and the server if needed. */
static void start_moc (const struct parameters *params, lists_t_strs *args)
{
	int server_sock;

	if (params->foreground) {
		set_me_server ();
		server_init (params->debug, params->foreground);
		server_loop ();
		return;
	}

	server_sock = server_connect ();

	if (server_sock != -1 && params->only_server)
		fatal ("Server is already running!");

	if (server_sock == -1) {
		int i = 0;
		int notify_pipe[2];
		ssize_t rc;

		printf ("Running the server...\n");

		/* To notify the client that the server socket is ready */
		if (pipe(notify_pipe))
			fatal ("pipe() failed: %s", xstrerror (errno));

		switch (fork()) {
		case 0: /* child - start server */
			set_me_server ();
			server_init (params->debug, params->foreground);
			rc = write (notify_pipe[1], &i, sizeof(i));
			if (rc < 0)
				fatal ("write() to notify pipe failed: %s", xstrerror (errno));
			close (notify_pipe[0]);
			close (notify_pipe[1]);
			server_loop ();
			options_free ();
			decoder_cleanup ();
			io_cleanup ();
			files_cleanup ();
			rcc_cleanup ();
			common_cleanup ();
			exit (EXIT_SUCCESS);
		case -1:
			fatal ("fork() failed: %s", xstrerror (errno));
		default:
			close (notify_pipe[1]);
			if (read(notify_pipe[0], &i, sizeof(i)) != sizeof(i))
				fatal ("Server exited!");
			close (notify_pipe[0]);
			server_sock = server_connect ();
			if (server_sock == -1) {
				perror ("server_connect()");
				fatal ("Can't connect to the server!");
			}
		}
	}

	if (params->only_server)
		send_int (server_sock, CMD_DISCONNECT);
	else {
		xsignal (SIGPIPE, SIG_IGN);
		if (!ping_server (server_sock))
			fatal ("Can't connect to the server!");

		init_interface (server_sock, params->debug, args);
		interface_loop ();
		interface_end ();
	}

	close (server_sock);
}
Exemple #5
0
enum conflate_mgmt_cb_result on_conflate_ping_test(void *userdata,
                                                   conflate_handle_t *handle,
                                                   const char *cmd,
                                                   bool direct,
                                                   kvpair_t *form,
                                                   conflate_form_result *r)
{
    (void)userdata;
    (void)handle;
    (void)cmd;
    (void)direct;
    assert(userdata);

    // The form key-multivalues looks roughly like...
    //
    //  servers
    //    svrname1
    //    svrname2
    //  svr-svrname1
    //    host=mc1.foo.net
    //    port=11211
    //    bucket=buck1
    //    usr=test1
    //    pwd=password
    //  svr-svrname2
    //    host=mc2.foo.net
    //    port=11211
    //    bucket=buck1
    //    usr=test1
    //    pwd=password
    //  tests
    //    test1
    //    test2
    //  def-test1
    //    ksize=16
    //    vsize=16
    //    iterations=500
    //  def-test2
    //    ksize=64
    //    vsize=524288
    //    iterations=50
    //
    if (!form) {
        return RV_BADARG;
    }

    char detail_key[200];

    // Discover test configuration.
    char **tests = get_key_values(form, "tests");
    int nrecipes = charlistlen(tests);
    struct ping_test_recipe recipes[nrecipes+1];
    memset(recipes, 0x00, sizeof(struct ping_test_recipe) * (nrecipes+1));
    for (int j = 0; j < nrecipes; j++) {
        snprintf(detail_key, sizeof(detail_key), "def-%s", tests[j]);
        recipes[j].name = strdup(detail_key);
        assert(recipes[j].name);
        load_ping_recipe(get_key_values(form, detail_key), &recipes[j]);
    }

    // Initialize each server and run the tests
    char **servers = get_key_values(form, "servers");
    for (int j = 0; servers != NULL && servers[j]; j++) {
        snprintf(detail_key, sizeof(detail_key),
                 "svr-%s", servers[j]);

        if (settings.verbose > 1) {
            moxi_log_write("ping_test %s\n", detail_key);
        }

        proxy_behavior behavior;

        memset(&behavior, 0, sizeof(behavior));

        char **props = get_key_values(form, detail_key);
        for (int k = 0; props && props[k]; k++) {
            cproxy_parse_behavior_key_val_str(props[k], &behavior);
        }

        ping_server(servers[j], recipes, &behavior, r);
    }

    /* The recipe memory allocations */
    for (int j = 0; j < nrecipes; j++) {
        free(recipes[j].name);
    }

    return RV_OK;
}