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