int CCP_run(void) { console_draw_empty_board(text_mode); console_exit(); CCP_exit(NORMAL_EXIT); return 0; }
static void console_client_write(evutil_socket_t fd, short bedrock_attribute_unused events, void *data) { struct console_client *client = data; bedrock_node *node; const char *out_str; int out_str_len, i; if (client->out_buffer.count == 0) { io_disable(&client->fd.event_write); if (io_is_pending(&client->fd.event_read, EV_READ) == false) console_exit(client); return; } node = client->out_buffer.head; out_str = node->data; out_str_len = strlen(out_str); i = send(fd, out_str, out_str_len, 0); if (i <= 0) { if (bedrock_list_has_data(&exiting_client_list, client) == false) bedrock_log(LEVEL_INFO, "Lost connection from console client"); io_disable(&client->fd.event_read); io_disable(&client->fd.event_write); console_exit(client); return; } bedrock_list_del_node(&client->out_buffer, node); bedrock_free(node); if (client->out_buffer.count == 0) { io_disable(&client->fd.event_write); if (io_is_pending(&client->fd.event_read, EV_READ) == false) console_exit(client); } }
static void console_client_read(evutil_socket_t fd, short bedrock_attribute_unused events, void *data) { struct console_client *client = data; int i; struct command_source source; if (client->in_buffer_len == sizeof(client->in_buffer)) { bedrock_log(LEVEL_INFO, "Receive queue exceeded for console client - dropping client"); io_disable(&client->fd.event_read); io_disable(&client->fd.event_write); return; } i = recv(fd, client->in_buffer + client->in_buffer_len, sizeof(client->in_buffer) - client->in_buffer_len, 0); if (i <= 0) { if (bedrock_list_has_data(&exiting_client_list, client) == false) bedrock_log(LEVEL_INFO, "Lost connection from console client"); io_disable(&client->fd.event_read); io_disable(&client->fd.event_write); console_exit(client); return; } client->in_buffer_len += i; source.user = NULL; source.console = client; while (io_is_pending(&client->fd.event_read, EV_READ) && (i = mem_find(client->in_buffer, client->in_buffer_len, '\n')) > 0) { client->in_buffer[i] = 0; if (client->in_buffer[i - 1] == '\r') client->in_buffer[i - 1] = 0; command_run(&source, (char *) client->in_buffer); memmove(client->in_buffer, client->in_buffer + i + 1, client->in_buffer_len - i - 1); client->in_buffer_len -= i + 1; } }