예제 #1
0
파일: wi-wired.c 프로젝트: asvitkine/phxd
void wi_parse_wire_command(wi_string_t *buffer, wi_string_t **out_command, wi_string_t **out_arguments) {
	wi_uinteger_t	index;
	
	index = wi_string_index_of_string(buffer, WI_STR(" "), 0);
	
	if(index != WI_NOT_FOUND) {
		*out_command	= wi_string_substring_to_index(buffer, index);
		*out_arguments	= wi_string_substring_from_index(buffer, index + 1);
	} else {
		*out_command	= wi_autorelease(wi_copy(buffer));
		*out_arguments	= wi_string();
	}
	
	if(wi_string_has_prefix(*out_command, WI_STR("/")))
		*out_command = wi_string_by_deleting_characters_to_index(*out_command, 1);
}
예제 #2
0
static void wd_cmd_info(wi_array_t *arguments) {
	wd_client_t			*client = wd_client();
	wi_list_node_t		*node;
	wi_string_t			*info, *login, *idle, *downloads, *uploads;
	wd_client_t			*peer;
	wd_transfer_t		*transfer;
	wd_uid_t			uid;

	if(!client->account->get_user_info) {
		wd_reply(516, WI_STR("Permission Denied"));
		
		return;
	}

	uid = wi_string_uint32(WI_ARRAY(arguments, 0));
	peer = wd_client_with_uid(uid);

	if(!peer) {
		wd_reply(512, WI_STR("Client Not Found"));

		return;
	}
	
	downloads	= wi_string();
	uploads		= wi_string();

	wi_list_rdlock(wd_transfers);
	WI_LIST_FOREACH(wd_transfers, node, transfer) {
		if(transfer->client == peer && transfer->state == WD_TRANSFER_RUNNING) {
			if(!client->account->view_dropboxes) {
				if(wd_files_path_is_dropbox(transfer->path))
					continue;
			}
			
			info = wi_string_with_format(WI_STR("%#@%c%llu%c%llu%c%u"),
										 transfer->path,		WD_RECORD_SEPARATOR,
										 transfer->transferred,	WD_RECORD_SEPARATOR,
										 transfer->size,		WD_RECORD_SEPARATOR,
										 transfer->speed);
			
			if(transfer->type == WD_TRANSFER_DOWNLOAD) {
				if(wi_string_length(downloads) > 0)
					wi_string_append_format(downloads, WI_STR("%c"), WD_GROUP_SEPARATOR);

				wi_string_append_string(downloads, info);
			} else {
				if(wi_string_length(uploads) > 0)
					wi_string_append_format(uploads, WI_STR("%c"), WD_GROUP_SEPARATOR);

				wi_string_append_string(uploads, info);
			}
		}
	}
	wi_list_unlock(wd_transfers);
	
	login	= wi_date_iso8601_string(wi_date_with_time_interval(peer->login_time));
	idle	= wi_date_iso8601_string(wi_date_with_time_interval(peer->idle_time));

	wd_reply(308, WI_STR("%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"),
			 peer->uid,								WD_FIELD_SEPARATOR,
			 peer->idle,							WD_FIELD_SEPARATOR,
			 peer->admin,							WD_FIELD_SEPARATOR,
			 peer->icon,							WD_FIELD_SEPARATOR,
			 peer->nick,							WD_FIELD_SEPARATOR,
			 peer->login,							WD_FIELD_SEPARATOR,
			 peer->ip,								WD_FIELD_SEPARATOR,
			 peer->host,							WD_FIELD_SEPARATOR,
			 peer->version,							WD_FIELD_SEPARATOR,
			 wi_socket_cipher_name(peer->socket),	WD_FIELD_SEPARATOR,
			 wi_socket_cipher_bits(peer->socket),	WD_FIELD_SEPARATOR,
			 login,									WD_FIELD_SEPARATOR,
			 idle,									WD_FIELD_SEPARATOR,
			 downloads,								WD_FIELD_SEPARATOR,
			 uploads,								WD_FIELD_SEPARATOR,
			 peer->status,							WD_FIELD_SEPARATOR,
			 peer->image);
}
예제 #3
0
파일: windows.c 프로젝트: ProfDrLuigi/zanka
void wr_draw_divider(void) {
	wi_enumerator_t		*enumerator;
	wi_string_t			*string, *action, *position;
	wr_window_t			*window;
	wi_size_t			size;
	wi_range_t			scroll;
	wi_point_t			location;
	const char			*color;
	wi_uinteger_t		users, line, lines, windows;
	
	string = wi_string_with_format(WI_STR("%s%@"), WR_PREFIX, wr_nick);
	
	if(wr_connected && wr_server) {
		users = wi_array_count(wr_chat_users(wr_console_window->chat));
		
		wi_string_append_format(string, WI_STR(" - %@ - %u %@"),
								wr_server->name,
								users,
								users == 1
									? WI_STR("user")
									: WI_STR("users"));
	}
	
	action = wi_string();
	windows = 0;
	
	enumerator = wi_array_data_enumerator(wr_windows);
	
	while((window = wi_enumerator_next_data(enumerator))) {
		switch(window->status) {
			case WR_WINDOW_STATUS_ACTION:
				color = WR_INTERFACE_COLOR;
				break;

			case WR_WINDOW_STATUS_CHAT:
				color = WR_STATUS_COLOR;
				break;

			case WR_WINDOW_STATUS_HIGHLIGHT:
				color = WR_HIGHLIGHT_COLOR;
				break;
				
			default:
				color = NULL;
				break;
		}
		
		if(color) {
			if(windows > 0)
				wi_string_append_string(action, WI_STR(","));
			
			wi_string_append_format(action, WI_STR("%s%s%s%u%s%s"),
				WR_END_COLOR,
				WR_INTERFACE_COLOR,
				color,
				window->wid,
				WR_END_COLOR,
				WR_INTERFACE_COLOR);
			
			windows++;
		}
	}

	if(windows > 0)
		wi_string_append_format(string, WI_STR(" [%@]"), action);
	
	line = wi_terminal_buffer_current_line(wr_current_window->buffer);
	lines = wi_terminal_buffer_lines(wr_current_window->buffer);
	scroll = wi_terminal_scroll(wr_terminal);
	
	if(lines == 0 || line == lines)
		position = NULL;
	else if(line <= scroll.length)
		position = wi_string_with_cstring("TOP");
	else
		position = wi_string_with_format(WI_STR("%.0f%%"), 100 * ((double) (line - scroll.length)  / (double) lines));
	
	wi_terminal_adjust_string_to_fit_width(wr_terminal, string);
	
	if(position) {
		wi_string_delete_characters_from_index(string, wi_string_length(string) - wi_string_length(position));
		wi_string_append_string(string, position);
	}

	size = wi_terminal_size(wr_terminal);

	location = wi_terminal_location(wr_terminal);
	wi_terminal_move_printf(wr_terminal, wi_make_point(0, size.height - 2), WI_STR("%s%@%s"),
		WR_INTERFACE_COLOR,
		string,
		WR_END_COLOR);
	wi_terminal_move(wr_terminal, location);
}