|
|
|
@ -22,6 +22,7 @@ mod message_handler; |
|
|
|
mod room;
|
|
|
|
mod user;
|
|
|
|
|
|
|
|
use config::Config;
|
|
|
|
use context::ContextBundle;
|
|
|
|
use dispatcher::Dispatcher;
|
|
|
|
use executor::Executor;
|
|
|
|
@ -30,35 +31,26 @@ fn old_main() { |
|
|
|
let (request_tx, _request_rx) = crossbeam_channel::bounded(100);
|
|
|
|
let (_response_tx, response_rx) = crossbeam_channel::bounded(100);
|
|
|
|
|
|
|
|
let mut client = client::Client::new(request_tx, response_rx);
|
|
|
|
let mut client =
|
|
|
|
client::Client::new(request_tx, response_rx, Config::default());
|
|
|
|
|
|
|
|
client.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn run_client(
|
|
|
|
config: Config,
|
|
|
|
request_rx: mpsc::Receiver<solstice_proto::ServerRequest>,
|
|
|
|
dispatcher_tx: mpsc::Sender<dispatcher::Message>,
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
let address = format!(
|
|
|
|
"{}:{}",
|
|
|
|
config::SERVER_HOST,
|
|
|
|
config::SERVER_PORT
|
|
|
|
);
|
|
|
|
info!("Connecting to server at {}.", address);
|
|
|
|
let stream = TcpStream::connect(address)
|
|
|
|
info!("Connecting to server at {}.", config.server_address);
|
|
|
|
let stream = TcpStream::connect(&config.server_address)
|
|
|
|
.await
|
|
|
|
.context("connecting to server")?;
|
|
|
|
info!("Connection successful.");
|
|
|
|
|
|
|
|
let credentials = solstice_proto::server::Credentials::new(
|
|
|
|
config::USERNAME.to_string(),
|
|
|
|
config::PASSWORD.to_string(),
|
|
|
|
)
|
|
|
|
.context("validating credentials")?;
|
|
|
|
|
|
|
|
info!("Logging in to server.");
|
|
|
|
let (_info, mut worker) = solstice_proto::server::Client::new(stream)
|
|
|
|
.login(credentials)
|
|
|
|
.login(config.credentials)
|
|
|
|
.await
|
|
|
|
.context("logging in")?;
|
|
|
|
info!("Login successful.");
|
|
|
|
@ -94,17 +86,21 @@ async fn async_main() -> anyhow::Result<()> { |
|
|
|
// TODO: Define a constant for this, or something.
|
|
|
|
let (dispatcher_tx, mut dispatcher_rx) = mpsc::channel(100);
|
|
|
|
|
|
|
|
let client_task =
|
|
|
|
tokio::spawn(run_client(bundle.server_request_rx, dispatcher_tx.clone()));
|
|
|
|
let config = Config::default();
|
|
|
|
|
|
|
|
let mut control_listener =
|
|
|
|
control::Listener::bind(&config.control_listen_address)
|
|
|
|
.await
|
|
|
|
.context("binding control listener")?;
|
|
|
|
|
|
|
|
let client_task = tokio::spawn(run_client(
|
|
|
|
config,
|
|
|
|
bundle.server_request_rx,
|
|
|
|
dispatcher_tx.clone(),
|
|
|
|
));
|
|
|
|
|
|
|
|
let dispatcher = Dispatcher::new();
|
|
|
|
let executor = Executor::new(bundle.context);
|
|
|
|
|
|
|
|
let control_address =
|
|
|
|
format!("{}:{}", config::CONTROL_HOST, config::CONTROL_PORT);
|
|
|
|
let mut control_listener = control::Listener::bind(&control_address)
|
|
|
|
.await
|
|
|
|
.context("binding control listener")?;
|
|
|
|
let control_task =
|
|
|
|
control_listener.run(dispatcher_tx, bundle.control_response_rx);
|
|
|
|
|
|
|
|
|