veloren/chat-cli/src/main.rs

54 lines
1.5 KiB
Rust
Raw Normal View History

use client::{Client, Event};
use common::{clock::Clock, comp};
use log::{error, info};
use std::time::Duration;
2019-06-06 19:11:39 +00:00
const TICK_RATE: u64 = 10; // Low value is okay, just reading messages.
fn main() {
// Initialize logging.
pretty_env_logger::init();
info!("Starting chat-cli...");
// Set up an fps clock.
let mut clock = Clock::new();
// Create a client.
let mut client =
Client::new(([127, 0, 0, 1], 59003), None).expect("Failed to create client instance");
println!("Server info: {:?}", client.server_info);
// TODO: Remove or move somewhere else, this doesn't work immediately after connecting
println!("Ping: {:?}", client.get_ping_ms());
2019-06-02 14:35:21 +00:00
println!("Players online: {:?}", client.get_players());
client.register(comp::Player::new("test".to_string(), None));
client.send_chat("Hello!".to_string());
loop {
let events = match client.tick(comp::Control::default(), clock.get_last_delta()) {
Ok(events) => events,
Err(err) => {
error!("Error: {:?}", err);
break;
}
};
for event in events {
match event {
Event::Chat(msg) => println!("[chat] {}", msg),
Event::Disconnect => {} // TODO
}
}
// Clean up the server after a tick.
client.cleanup();
// Wait for the next tick.
2019-06-06 19:11:39 +00:00
clock.tick(Duration::from_millis(1000 / TICK_RATE));
}
}