mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add server info
Former-commit-id: 9e504c821e871d30f8ac7cd4acb7a8022bdb5710
This commit is contained in:
parent
3d21cd7402
commit
c10a43f541
@ -1,6 +1,6 @@
|
||||
use client::{Client, Event};
|
||||
use common::{clock::Clock, comp};
|
||||
use log::info;
|
||||
use log::{error, info};
|
||||
use std::time::Duration;
|
||||
|
||||
const FPS: u64 = 60;
|
||||
@ -18,15 +18,21 @@ fn main() {
|
||||
let mut client =
|
||||
Client::new(([127, 0, 0, 1], 59003), None).expect("Failed to create client instance");
|
||||
|
||||
client.register(comp::Player::new("test".to_string(), None));
|
||||
println!("Server info: {:?}", client.server_info);
|
||||
|
||||
println!("Players online: {:?}",
|
||||
client.get_players()
|
||||
// TODO: Remove or move somewhere else, this doesn't work immediately after connecting
|
||||
println!("Ping: {:?}", client.get_ping_ms());
|
||||
|
||||
println!(
|
||||
"Players online: {:?}",
|
||||
client
|
||||
.get_players()
|
||||
.into_iter()
|
||||
.map(|(e, p)| p)
|
||||
.collect::<Vec<comp::Player>>()
|
||||
);
|
||||
|
||||
client.register(comp::Player::new("test".to_string(), None));
|
||||
client.send_chat("Hello!".to_string());
|
||||
|
||||
loop {
|
||||
|
@ -9,7 +9,7 @@ pub use specs::Entity as EcsEntity;
|
||||
|
||||
use common::{
|
||||
comp,
|
||||
msg::{ClientMsg, ClientState, ServerMsg},
|
||||
msg::{ClientMsg, ClientState, ServerInfo, ServerMsg},
|
||||
net::PostBox,
|
||||
state::State,
|
||||
};
|
||||
@ -32,6 +32,7 @@ pub enum Event {
|
||||
pub struct Client {
|
||||
client_state: ClientState,
|
||||
thread_pool: ThreadPool,
|
||||
pub server_info: ServerInfo,
|
||||
|
||||
postbox: PostBox<ClientMsg, ServerMsg>,
|
||||
|
||||
@ -54,17 +55,18 @@ impl Client {
|
||||
let mut postbox = PostBox::to(addr)?;
|
||||
|
||||
// Wait for initial sync
|
||||
let (mut state, entity) = match postbox.next_message() {
|
||||
let (mut state, entity, server_info) = match postbox.next_message() {
|
||||
Some(ServerMsg::InitialSync {
|
||||
ecs_state,
|
||||
entity_uid,
|
||||
server_info,
|
||||
}) => {
|
||||
let mut state = State::from_state_package(ecs_state);
|
||||
let entity = state
|
||||
.ecs()
|
||||
.entity_from_uid(entity_uid)
|
||||
.ok_or(Error::ServerWentMad)?;
|
||||
(state, entity)
|
||||
(state, entity, server_info)
|
||||
}
|
||||
_ => return Err(Error::ServerWentMad),
|
||||
};
|
||||
@ -76,6 +78,7 @@ impl Client {
|
||||
thread_pool: threadpool::Builder::new()
|
||||
.thread_name("veloren-worker".into())
|
||||
.build(),
|
||||
server_info,
|
||||
|
||||
postbox,
|
||||
|
||||
@ -91,7 +94,7 @@ impl Client {
|
||||
})
|
||||
}
|
||||
|
||||
/// Ask the server to transition the player into the `Registered` state
|
||||
/// Request a state transition to `ClientState::Registered`.
|
||||
pub fn register(&mut self, player: comp::Player) {
|
||||
self.postbox.send_message(ClientMsg::Register { player });
|
||||
self.client_state = ClientState::Pending;
|
||||
@ -432,7 +435,6 @@ impl Client {
|
||||
.map(|(e, p)| (e, p.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Drop for Client {
|
||||
|
@ -5,7 +5,7 @@ pub mod server;
|
||||
// Reexports
|
||||
pub use self::client::ClientMsg;
|
||||
pub use self::ecs_packet::{EcsCompPacket, EcsResPacket};
|
||||
pub use self::server::{RequestStateError, ServerMsg};
|
||||
pub use self::server::{RequestStateError, ServerInfo, ServerMsg};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ClientState {
|
||||
|
@ -10,11 +10,18 @@ pub enum RequestStateError {
|
||||
WrongMessage,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ServerInfo {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ServerMsg {
|
||||
InitialSync {
|
||||
ecs_state: sphynx::StatePackage<EcsCompPacket, EcsResPacket>,
|
||||
entity_uid: u64,
|
||||
server_info: ServerInfo,
|
||||
},
|
||||
StateAnswer(Result<ClientState, (RequestStateError, ClientState)>),
|
||||
ForceState(ClientState),
|
||||
|
@ -14,7 +14,7 @@ use crate::{
|
||||
};
|
||||
use common::{
|
||||
comp,
|
||||
msg::{ClientMsg, ClientState, RequestStateError, ServerMsg},
|
||||
msg::{ClientMsg, ClientState, RequestStateError, ServerInfo, ServerMsg},
|
||||
net::PostOffice,
|
||||
state::{State, Uid},
|
||||
terrain::TerrainChunk,
|
||||
@ -65,6 +65,8 @@ pub struct Server {
|
||||
chunk_tx: mpsc::Sender<(Vec2<i32>, TerrainChunk)>,
|
||||
chunk_rx: mpsc::Receiver<(Vec2<i32>, TerrainChunk)>,
|
||||
pending_chunks: HashSet<Vec2<i32>>,
|
||||
|
||||
server_info: ServerInfo,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
@ -97,6 +99,11 @@ impl Server {
|
||||
chunk_tx,
|
||||
chunk_rx,
|
||||
pending_chunks: HashSet::new(),
|
||||
|
||||
server_info: ServerInfo {
|
||||
name: "Server name".to_owned(),
|
||||
description: "This is the best Veloren server.".to_owned(),
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
@ -377,6 +384,7 @@ impl Server {
|
||||
client.notify(ServerMsg::InitialSync {
|
||||
ecs_state: self.state.ecs().gen_state_package(),
|
||||
entity_uid: self.state.ecs().uid_from_entity(entity).unwrap().into(), // Can't fail.
|
||||
server_info: self.server_info.clone(),
|
||||
});
|
||||
|
||||
self.clients.add(entity, client);
|
||||
|
Loading…
Reference in New Issue
Block a user