mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Rename enums to allow a super enum in the future, but i am not yet sure if we want to introduce this yet
``` //This is a helper structure, containing all possible data send over pub enum ClientMsg { Initial(ClientType), General(ClientGeneralMsg), InGame(ClientInGameMsg), NotInGame(ClientNotInGameMsg), Register(ClientRegisterMsg), Ping(PingMsg) } ```
This commit is contained in:
parent
d7a74c0cf1
commit
017e004309
@ -25,10 +25,10 @@ use common::{
|
||||
},
|
||||
event::{EventBus, LocalEvent},
|
||||
msg::{
|
||||
validate_chat_msg, ChatMsgValidationError, ClientInGameMsg, ClientIngame, ClientMsg,
|
||||
validate_chat_msg, ChatMsgValidationError, ClientInGameMsg, ClientIngame, ClientGeneralMsg,
|
||||
ClientNotInGameMsg, ClientRegisterMsg, ClientType, DisconnectReason, InviteAnswer,
|
||||
Notification, PingMsg, PlayerInfo, PlayerListUpdate, RegisterError, ServerInGameMsg,
|
||||
ServerInfo, ServerInitMsg, ServerMsg, ServerNotInGameMsg, ServerRegisterAnswerMsg,
|
||||
ServerInfo, ServerInitMsg, ServerGeneralMsg, ServerNotInGameMsg, ServerRegisterAnswerMsg,
|
||||
MAX_BYTES_CHAT_MSG,
|
||||
},
|
||||
outcome::Outcome,
|
||||
@ -502,7 +502,7 @@ impl Client {
|
||||
/// Send disconnect message to the server
|
||||
pub fn request_logout(&mut self) {
|
||||
debug!("Requesting logout from server");
|
||||
if let Err(e) = self.singleton_stream.send(ClientMsg::Disconnect) {
|
||||
if let Err(e) = self.singleton_stream.send(ClientGeneralMsg::Disconnect) {
|
||||
error!(
|
||||
?e,
|
||||
"Couldn't send disconnect package to server, did server close already?"
|
||||
@ -844,7 +844,7 @@ impl Client {
|
||||
match validate_chat_msg(&message) {
|
||||
Ok(()) => self
|
||||
.singleton_stream
|
||||
.send(ClientMsg::ChatMsg(message))
|
||||
.send(ClientGeneralMsg::ChatMsg(message))
|
||||
.unwrap(),
|
||||
Err(ChatMsgValidationError::TooLong) => tracing::warn!(
|
||||
"Attempted to send a message that's too long (Over {} bytes)",
|
||||
@ -1111,24 +1111,24 @@ impl Client {
|
||||
fn handle_server_msg(
|
||||
&mut self,
|
||||
frontend_events: &mut Vec<Event>,
|
||||
msg: ServerMsg,
|
||||
msg: ServerGeneralMsg,
|
||||
) -> Result<(), Error> {
|
||||
match msg {
|
||||
ServerMsg::Disconnect(reason) => match reason {
|
||||
ServerGeneralMsg::Disconnect(reason) => match reason {
|
||||
DisconnectReason::Shutdown => return Err(Error::ServerShutdown),
|
||||
DisconnectReason::Requested => {
|
||||
debug!("finally sending ClientMsg::Terminate");
|
||||
frontend_events.push(Event::Disconnect);
|
||||
self.singleton_stream.send(ClientMsg::Terminate)?;
|
||||
self.singleton_stream.send(ClientGeneralMsg::Terminate)?;
|
||||
},
|
||||
DisconnectReason::Kicked(reason) => {
|
||||
debug!("sending ClientMsg::Terminate because we got kicked");
|
||||
frontend_events.push(Event::Kicked(reason.clone()));
|
||||
self.singleton_stream.send(ClientMsg::Terminate)?;
|
||||
self.singleton_stream.send(ClientGeneralMsg::Terminate)?;
|
||||
},
|
||||
},
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::Init(list)) => self.player_list = list,
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::Add(uid, player_info)) => {
|
||||
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Init(list)) => self.player_list = list,
|
||||
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Add(uid, player_info)) => {
|
||||
if let Some(old_player_info) = self.player_list.insert(uid, player_info.clone()) {
|
||||
warn!(
|
||||
"Received msg to insert {} with uid {} into the player list but there was \
|
||||
@ -1137,7 +1137,7 @@ impl Client {
|
||||
);
|
||||
}
|
||||
},
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::Admin(uid, admin)) => {
|
||||
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Admin(uid, admin)) => {
|
||||
if let Some(player_info) = self.player_list.get_mut(&uid) {
|
||||
player_info.is_admin = admin;
|
||||
} else {
|
||||
@ -1148,7 +1148,7 @@ impl Client {
|
||||
);
|
||||
}
|
||||
},
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::SelectedCharacter(uid, char_info)) => {
|
||||
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::SelectedCharacter(uid, char_info)) => {
|
||||
if let Some(player_info) = self.player_list.get_mut(&uid) {
|
||||
player_info.character = Some(char_info);
|
||||
} else {
|
||||
@ -1159,7 +1159,7 @@ impl Client {
|
||||
);
|
||||
}
|
||||
},
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::LevelChange(uid, next_level)) => {
|
||||
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::LevelChange(uid, next_level)) => {
|
||||
if let Some(player_info) = self.player_list.get_mut(&uid) {
|
||||
player_info.character = match &player_info.character {
|
||||
Some(character) => Some(common::msg::CharacterInfo {
|
||||
@ -1178,7 +1178,7 @@ impl Client {
|
||||
};
|
||||
}
|
||||
},
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::Remove(uid)) => {
|
||||
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Remove(uid)) => {
|
||||
// Instead of removing players, mark them as offline because we need to
|
||||
// remember the names of disconnected players in chat.
|
||||
//
|
||||
@ -1203,7 +1203,7 @@ impl Client {
|
||||
);
|
||||
}
|
||||
},
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::Alias(uid, new_name)) => {
|
||||
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Alias(uid, new_name)) => {
|
||||
if let Some(player_info) = self.player_list.get_mut(&uid) {
|
||||
player_info.player_alias = new_name;
|
||||
} else {
|
||||
@ -1214,38 +1214,38 @@ impl Client {
|
||||
);
|
||||
}
|
||||
},
|
||||
ServerMsg::ChatMsg(m) => frontend_events.push(Event::Chat(m)),
|
||||
ServerMsg::SetPlayerEntity(uid) => {
|
||||
ServerGeneralMsg::ChatMsg(m) => frontend_events.push(Event::Chat(m)),
|
||||
ServerGeneralMsg::SetPlayerEntity(uid) => {
|
||||
if let Some(entity) = self.state.ecs().entity_from_uid(uid.0) {
|
||||
self.entity = entity;
|
||||
} else {
|
||||
return Err(Error::Other("Failed to find entity from uid.".to_owned()));
|
||||
}
|
||||
},
|
||||
ServerMsg::TimeOfDay(time_of_day) => {
|
||||
ServerGeneralMsg::TimeOfDay(time_of_day) => {
|
||||
*self.state.ecs_mut().write_resource() = time_of_day;
|
||||
},
|
||||
ServerMsg::EntitySync(entity_sync_package) => {
|
||||
ServerGeneralMsg::EntitySync(entity_sync_package) => {
|
||||
self.state
|
||||
.ecs_mut()
|
||||
.apply_entity_sync_package(entity_sync_package);
|
||||
},
|
||||
ServerMsg::CompSync(comp_sync_package) => {
|
||||
ServerGeneralMsg::CompSync(comp_sync_package) => {
|
||||
self.state
|
||||
.ecs_mut()
|
||||
.apply_comp_sync_package(comp_sync_package);
|
||||
},
|
||||
ServerMsg::CreateEntity(entity_package) => {
|
||||
ServerGeneralMsg::CreateEntity(entity_package) => {
|
||||
self.state.ecs_mut().apply_entity_package(entity_package);
|
||||
},
|
||||
ServerMsg::DeleteEntity(entity) => {
|
||||
ServerGeneralMsg::DeleteEntity(entity) => {
|
||||
if self.uid() != Some(entity) {
|
||||
self.state
|
||||
.ecs_mut()
|
||||
.delete_entity_and_clear_from_uid_allocator(entity.0);
|
||||
}
|
||||
},
|
||||
ServerMsg::Notification(n) => {
|
||||
ServerGeneralMsg::Notification(n) => {
|
||||
frontend_events.push(Event::Notification(n));
|
||||
},
|
||||
}
|
||||
@ -1802,7 +1802,7 @@ impl Client {
|
||||
impl Drop for Client {
|
||||
fn drop(&mut self) {
|
||||
trace!("Dropping client");
|
||||
if let Err(e) = self.singleton_stream.send(ClientMsg::Disconnect) {
|
||||
if let Err(e) = self.singleton_stream.send(ClientGeneralMsg::Disconnect) {
|
||||
warn!(
|
||||
?e,
|
||||
"Error during drop of client, couldn't send disconnect package, is the connection \
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{comp::group::Group, msg::ServerMsg, sync::Uid};
|
||||
use crate::{comp::group::Group, msg::ServerGeneralMsg, sync::Uid};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specs::Component;
|
||||
use specs_idvs::IdvStorage;
|
||||
@ -118,11 +118,11 @@ impl<G> ChatType<G> {
|
||||
}
|
||||
}
|
||||
impl ChatType<String> {
|
||||
pub fn server_msg<S>(self, msg: S) -> ServerMsg
|
||||
pub fn server_msg<S>(self, msg: S) -> ServerGeneralMsg
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
ServerMsg::ChatMsg(self.chat_msg(msg))
|
||||
ServerGeneralMsg::ChatMsg(self.chat_msg(msg))
|
||||
}
|
||||
}
|
||||
// Stores chat text, type
|
||||
|
@ -63,7 +63,7 @@ pub enum ClientInGameMsg {
|
||||
|
||||
/// Messages sent from the client to the server
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ClientMsg {
|
||||
pub enum ClientGeneralMsg {
|
||||
ChatMsg(String),
|
||||
Command(String),
|
||||
Disconnect,
|
||||
|
@ -4,11 +4,11 @@ pub mod server;
|
||||
|
||||
// Reexports
|
||||
pub use self::{
|
||||
client::{ClientInGameMsg, ClientMsg, ClientNotInGameMsg, ClientRegisterMsg, ClientType},
|
||||
client::{ClientInGameMsg, ClientGeneralMsg, ClientNotInGameMsg, ClientRegisterMsg, ClientType},
|
||||
ecs_packet::EcsCompPacket,
|
||||
server::{
|
||||
CharacterInfo, DisconnectReason, InviteAnswer, Notification, PlayerInfo, PlayerListUpdate,
|
||||
RegisterError, ServerInGameMsg, ServerInfo, ServerInitMsg, ServerMsg, ServerNotInGameMsg,
|
||||
RegisterError, ServerInGameMsg, ServerInfo, ServerInitMsg, ServerGeneralMsg, ServerNotInGameMsg,
|
||||
ServerRegisterAnswerMsg,
|
||||
},
|
||||
};
|
||||
|
@ -255,7 +255,7 @@ pub enum ServerInGameMsg {
|
||||
|
||||
/// Messages sent from the server to the client
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ServerMsg {
|
||||
pub enum ServerGeneralMsg {
|
||||
PlayerListUpdate(PlayerListUpdate),
|
||||
/// A message to go into the client chat box. The client is responsible for
|
||||
/// formatting the message and turning it into a speech bubble.
|
||||
@ -285,6 +285,6 @@ impl From<AuthClientError> for RegisterError {
|
||||
fn from(err: AuthClientError) -> Self { Self::AuthError(err.to_string()) }
|
||||
}
|
||||
|
||||
impl From<comp::ChatMsg> for ServerMsg {
|
||||
fn from(v: comp::ChatMsg) -> Self { ServerMsg::ChatMsg(v) }
|
||||
impl From<comp::ChatMsg> for ServerGeneralMsg {
|
||||
fn from(v: comp::ChatMsg) -> Self { ServerGeneralMsg::ChatMsg(v) }
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::error::Error;
|
||||
use common::msg::{
|
||||
ClientInGameMsg, ClientIngame, ClientMsg, ClientNotInGameMsg, ClientType, PingMsg,
|
||||
ServerInGameMsg, ServerInitMsg, ServerMsg, ServerNotInGameMsg,
|
||||
ClientInGameMsg, ClientIngame, ClientGeneralMsg, ClientNotInGameMsg, ClientType, PingMsg,
|
||||
ServerInGameMsg, ServerInitMsg, ServerGeneralMsg, ServerNotInGameMsg,
|
||||
};
|
||||
use hashbrown::HashSet;
|
||||
use network::{MessageBuffer, Participant, Stream};
|
||||
@ -57,7 +57,7 @@ impl Client {
|
||||
Self::internal_send(&self.network_error, &mut self.register_stream, msg);
|
||||
}
|
||||
|
||||
pub fn send_msg(&mut self, msg: ServerMsg) {
|
||||
pub fn send_msg(&mut self, msg: ServerGeneralMsg) {
|
||||
Self::internal_send(&self.network_error, &mut self.singleton_stream, msg);
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn recv_msg(&mut self) -> Result<ClientMsg, Error> {
|
||||
pub async fn recv_msg(&mut self) -> Result<ClientGeneralMsg, Error> {
|
||||
Self::internal_recv(&self.network_error, &mut self.singleton_stream).await
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ use common::{
|
||||
cmd::{ChatCommand, CHAT_COMMANDS, CHAT_SHORTCUTS},
|
||||
comp::{self, ChatType, Item, LightEmitter, WaypointArea},
|
||||
event::{EventBus, ServerEvent},
|
||||
msg::{DisconnectReason, Notification, PlayerListUpdate, ServerInGameMsg, ServerMsg},
|
||||
msg::{DisconnectReason, Notification, PlayerListUpdate, ServerInGameMsg, ServerGeneralMsg},
|
||||
npc::{self, get_npc_name},
|
||||
state::TimeOfDay,
|
||||
sync::{Uid, WorldSyncExt},
|
||||
@ -505,7 +505,7 @@ fn handle_alias(
|
||||
old_alias_optional,
|
||||
) {
|
||||
let msg =
|
||||
ServerMsg::PlayerListUpdate(PlayerListUpdate::Alias(*uid, player.alias.clone()));
|
||||
ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Alias(*uid, player.alias.clone()));
|
||||
server.state.notify_registered_clients(msg);
|
||||
|
||||
// Announce alias change if target has a Body.
|
||||
@ -1157,7 +1157,7 @@ fn handle_waypoint(
|
||||
.write_storage::<comp::Waypoint>()
|
||||
.insert(target, comp::Waypoint::new(pos.0, *time));
|
||||
server.notify_client(client, ChatType::CommandInfo.server_msg("Waypoint saved!"));
|
||||
server.notify_client(client, ServerMsg::Notification(Notification::WaypointSaved));
|
||||
server.notify_client(client, ServerGeneralMsg::Notification(Notification::WaypointSaved));
|
||||
},
|
||||
None => server.notify_client(
|
||||
client,
|
||||
@ -1193,7 +1193,7 @@ fn handle_adminify(
|
||||
ecs.write_storage().insert(player, comp::Admin).is_ok()
|
||||
};
|
||||
// Update player list so the player shows up as admin in client chat.
|
||||
let msg = ServerMsg::PlayerListUpdate(PlayerListUpdate::Admin(
|
||||
let msg = ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Admin(
|
||||
*ecs.read_storage::<Uid>()
|
||||
.get(player)
|
||||
.expect("Player should have uid"),
|
||||
@ -1586,7 +1586,7 @@ fn find_target(
|
||||
ecs: &specs::World,
|
||||
opt_alias: Option<String>,
|
||||
fallback: EcsEntity,
|
||||
) -> Result<EcsEntity, ServerMsg> {
|
||||
) -> Result<EcsEntity, ServerGeneralMsg> {
|
||||
if let Some(alias) = opt_alias {
|
||||
(&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
||||
.join()
|
||||
@ -1658,7 +1658,7 @@ fn handle_set_level(
|
||||
.expect("Failed to get uid for player");
|
||||
server
|
||||
.state
|
||||
.notify_registered_clients(ServerMsg::PlayerListUpdate(
|
||||
.notify_registered_clients(ServerGeneralMsg::PlayerListUpdate(
|
||||
PlayerListUpdate::LevelChange(uid, lvl),
|
||||
));
|
||||
|
||||
@ -1898,7 +1898,7 @@ fn kick_player(server: &mut Server, target_player: EcsEntity, reason: &str) {
|
||||
.emit_now(ServerEvent::ClientDisconnect(target_player));
|
||||
server.notify_client(
|
||||
target_player,
|
||||
ServerMsg::Disconnect(DisconnectReason::Kicked(reason.to_string())),
|
||||
ServerGeneralMsg::Disconnect(DisconnectReason::Kicked(reason.to_string())),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ use common::{
|
||||
Player, Pos, Stats,
|
||||
},
|
||||
lottery::Lottery,
|
||||
msg::{PlayerListUpdate, ServerInGameMsg, ServerMsg},
|
||||
msg::{PlayerListUpdate, ServerInGameMsg, ServerGeneralMsg},
|
||||
outcome::Outcome,
|
||||
state::BlockChange,
|
||||
sync::{Uid, UidAllocator, WorldSyncExt},
|
||||
@ -656,7 +656,7 @@ pub fn handle_level_up(server: &mut Server, entity: EcsEntity, new_level: u32) {
|
||||
|
||||
server
|
||||
.state
|
||||
.notify_registered_clients(ServerMsg::PlayerListUpdate(PlayerListUpdate::LevelChange(
|
||||
.notify_registered_clients(ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::LevelChange(
|
||||
*uid, new_level,
|
||||
)));
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
};
|
||||
use common::{
|
||||
comp::{self, item},
|
||||
msg::ServerMsg,
|
||||
msg::ServerGeneralMsg,
|
||||
sync::{Uid, WorldSyncExt},
|
||||
};
|
||||
use specs::{world::WorldExt, Entity as EcsEntity};
|
||||
@ -116,7 +116,7 @@ pub fn handle_possess(server: &Server, possessor_uid: Uid, possesse_uid: Uid) {
|
||||
let mut clients = ecs.write_storage::<Client>();
|
||||
if clients.get_mut(possesse).is_none() {
|
||||
if let Some(mut client) = clients.remove(possessor) {
|
||||
client.send_msg(ServerMsg::SetPlayerEntity(possesse_uid));
|
||||
client.send_msg(ServerGeneralMsg::SetPlayerEntity(possesse_uid));
|
||||
clients
|
||||
.insert(possesse, client)
|
||||
.err()
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
use common::{
|
||||
comp,
|
||||
comp::{group, Player},
|
||||
msg::{PlayerListUpdate, ServerInGameMsg, ServerMsg},
|
||||
msg::{PlayerListUpdate, ServerInGameMsg, ServerGeneralMsg},
|
||||
span,
|
||||
sync::{Uid, UidAllocator},
|
||||
};
|
||||
@ -131,7 +131,7 @@ pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event
|
||||
state.notify_registered_clients(comp::ChatType::Offline(*uid).server_msg(""));
|
||||
|
||||
state
|
||||
.notify_registered_clients(ServerMsg::PlayerListUpdate(PlayerListUpdate::Remove(*uid)));
|
||||
.notify_registered_clients(ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Remove(*uid)));
|
||||
}
|
||||
|
||||
// Make sure to remove the player from the logged in list. (See LoginProvider)
|
||||
|
@ -46,7 +46,7 @@ use common::{
|
||||
event::{EventBus, ServerEvent},
|
||||
msg::{
|
||||
server::WorldMapMsg, ClientType, DisconnectReason, ServerInGameMsg, ServerInfo,
|
||||
ServerInitMsg, ServerMsg, ServerNotInGameMsg,
|
||||
ServerInitMsg, ServerGeneralMsg, ServerNotInGameMsg,
|
||||
},
|
||||
outcome::Outcome,
|
||||
recipe::default_recipe_book,
|
||||
@ -885,7 +885,7 @@ impl Server {
|
||||
|
||||
pub fn notify_client<S>(&self, entity: EcsEntity, msg: S)
|
||||
where
|
||||
S: Into<ServerMsg>,
|
||||
S: Into<ServerGeneralMsg>,
|
||||
{
|
||||
if let Some(client) = self.state.ecs().write_storage::<Client>().get_mut(entity) {
|
||||
client.send_msg(msg.into())
|
||||
@ -910,7 +910,7 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn notify_registered_clients(&mut self, msg: ServerMsg) {
|
||||
pub fn notify_registered_clients(&mut self, msg: ServerGeneralMsg) {
|
||||
self.state.notify_registered_clients(msg);
|
||||
}
|
||||
|
||||
@ -990,7 +990,7 @@ impl Server {
|
||||
impl Drop for Server {
|
||||
fn drop(&mut self) {
|
||||
self.state
|
||||
.notify_registered_clients(ServerMsg::Disconnect(DisconnectReason::Shutdown));
|
||||
.notify_registered_clients(ServerGeneralMsg::Disconnect(DisconnectReason::Shutdown));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use common::{
|
||||
comp,
|
||||
effect::Effect,
|
||||
msg::{
|
||||
CharacterInfo, ClientIngame, PlayerListUpdate, ServerInGameMsg, ServerMsg,
|
||||
CharacterInfo, ClientIngame, PlayerListUpdate, ServerInGameMsg, ServerGeneralMsg,
|
||||
ServerNotInGameMsg,
|
||||
},
|
||||
state::State,
|
||||
@ -62,7 +62,7 @@ pub trait StateExt {
|
||||
fn update_character_data(&mut self, entity: EcsEntity, components: PersistedComponents);
|
||||
/// Iterates over registered clients and send each `ServerMsg`
|
||||
fn send_chat(&self, msg: comp::UnresolvedChatMsg);
|
||||
fn notify_registered_clients(&self, msg: ServerMsg);
|
||||
fn notify_registered_clients(&self, msg: ServerGeneralMsg);
|
||||
/// Delete an entity, recording the deletion in [`DeletedEntities`]
|
||||
fn delete_entity_recorded(
|
||||
&mut self,
|
||||
@ -229,7 +229,7 @@ impl StateExt for State {
|
||||
|
||||
if let Some(player_uid) = self.read_component_copied::<Uid>(entity) {
|
||||
// Notify clients of a player list update
|
||||
self.notify_registered_clients(ServerMsg::PlayerListUpdate(
|
||||
self.notify_registered_clients(ServerGeneralMsg::PlayerListUpdate(
|
||||
PlayerListUpdate::SelectedCharacter(player_uid, CharacterInfo {
|
||||
name: String::from(&stats.name),
|
||||
level: stats.level.level(),
|
||||
@ -276,7 +276,7 @@ impl StateExt for State {
|
||||
| comp::ChatType::Kill(_, _)
|
||||
| comp::ChatType::Meta
|
||||
| comp::ChatType::World(_) => {
|
||||
self.notify_registered_clients(ServerMsg::ChatMsg(resolved_msg))
|
||||
self.notify_registered_clients(ServerGeneralMsg::ChatMsg(resolved_msg))
|
||||
},
|
||||
comp::ChatType::Tell(u, t) => {
|
||||
for (client, uid) in (
|
||||
@ -286,7 +286,7 @@ impl StateExt for State {
|
||||
.join()
|
||||
{
|
||||
if uid == u || uid == t {
|
||||
client.send_msg(ServerMsg::ChatMsg(resolved_msg.clone()));
|
||||
client.send_msg(ServerGeneralMsg::ChatMsg(resolved_msg.clone()));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -298,7 +298,7 @@ impl StateExt for State {
|
||||
if let Some(speaker_pos) = entity_opt.and_then(|e| positions.get(e)) {
|
||||
for (client, pos) in (&mut ecs.write_storage::<Client>(), &positions).join() {
|
||||
if is_within(comp::ChatMsg::SAY_DISTANCE, pos, speaker_pos) {
|
||||
client.send_msg(ServerMsg::ChatMsg(resolved_msg.clone()));
|
||||
client.send_msg(ServerGeneralMsg::ChatMsg(resolved_msg.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -310,7 +310,7 @@ impl StateExt for State {
|
||||
if let Some(speaker_pos) = entity_opt.and_then(|e| positions.get(e)) {
|
||||
for (client, pos) in (&mut ecs.write_storage::<Client>(), &positions).join() {
|
||||
if is_within(comp::ChatMsg::REGION_DISTANCE, pos, speaker_pos) {
|
||||
client.send_msg(ServerMsg::ChatMsg(resolved_msg.clone()));
|
||||
client.send_msg(ServerGeneralMsg::ChatMsg(resolved_msg.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -322,7 +322,7 @@ impl StateExt for State {
|
||||
if let Some(speaker_pos) = entity_opt.and_then(|e| positions.get(e)) {
|
||||
for (client, pos) in (&mut ecs.write_storage::<Client>(), &positions).join() {
|
||||
if is_within(comp::ChatMsg::NPC_DISTANCE, pos, speaker_pos) {
|
||||
client.send_msg(ServerMsg::ChatMsg(resolved_msg.clone()));
|
||||
client.send_msg(ServerGeneralMsg::ChatMsg(resolved_msg.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -336,7 +336,7 @@ impl StateExt for State {
|
||||
.join()
|
||||
{
|
||||
if s == &faction.0 {
|
||||
client.send_msg(ServerMsg::ChatMsg(resolved_msg.clone()));
|
||||
client.send_msg(ServerGeneralMsg::ChatMsg(resolved_msg.clone()));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -348,7 +348,7 @@ impl StateExt for State {
|
||||
.join()
|
||||
{
|
||||
if g == group {
|
||||
client.send_msg(ServerMsg::ChatMsg(resolved_msg.clone()));
|
||||
client.send_msg(ServerGeneralMsg::ChatMsg(resolved_msg.clone()));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -356,7 +356,7 @@ impl StateExt for State {
|
||||
}
|
||||
|
||||
/// Sends the message to all connected clients
|
||||
fn notify_registered_clients(&self, msg: ServerMsg) {
|
||||
fn notify_registered_clients(&self, msg: ServerGeneralMsg) {
|
||||
for client in (&mut self.ecs().write_storage::<Client>())
|
||||
.join()
|
||||
.filter(|c| c.registered)
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||
};
|
||||
use common::{
|
||||
comp::{ForceUpdate, Inventory, InventoryUpdate, Last, Ori, Player, Pos, Vel},
|
||||
msg::{ServerInGameMsg, ServerMsg},
|
||||
msg::{ServerInGameMsg, ServerGeneralMsg},
|
||||
outcome::Outcome,
|
||||
region::{Event as RegionEvent, RegionMap},
|
||||
span,
|
||||
@ -129,7 +129,7 @@ impl<'a> System<'a> for Sys {
|
||||
})
|
||||
}) {
|
||||
let create_msg =
|
||||
ServerMsg::CreateEntity(tracked_comps.create_entity_package(
|
||||
ServerGeneralMsg::CreateEntity(tracked_comps.create_entity_package(
|
||||
entity,
|
||||
Some(*pos),
|
||||
vel.copied(),
|
||||
@ -157,7 +157,7 @@ impl<'a> System<'a> for Sys {
|
||||
.map(|key| !regions.contains(key))
|
||||
.unwrap_or(true)
|
||||
{
|
||||
client.send_msg(ServerMsg::DeleteEntity(uid));
|
||||
client.send_msg(ServerGeneralMsg::DeleteEntity(uid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,14 +174,14 @@ impl<'a> System<'a> for Sys {
|
||||
.take_deleted_in_region(key)
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let entity_sync_msg = ServerMsg::EntitySync(entity_sync_package);
|
||||
let comp_sync_msg = ServerMsg::CompSync(comp_sync_package);
|
||||
let entity_sync_msg = ServerGeneralMsg::EntitySync(entity_sync_package);
|
||||
let comp_sync_msg = ServerGeneralMsg::CompSync(comp_sync_package);
|
||||
subscribers.iter_mut().for_each(move |(client, _, _, _)| {
|
||||
client.send_msg(entity_sync_msg.clone());
|
||||
client.send_msg(comp_sync_msg.clone());
|
||||
});
|
||||
|
||||
let mut send_msg = |msg: ServerMsg,
|
||||
let mut send_msg = |msg: ServerGeneralMsg,
|
||||
entity: EcsEntity,
|
||||
pos: Pos,
|
||||
force_update: Option<&ForceUpdate>,
|
||||
@ -287,7 +287,7 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
|
||||
send_msg(
|
||||
ServerMsg::CompSync(comp_sync_package),
|
||||
ServerGeneralMsg::CompSync(comp_sync_package),
|
||||
entity,
|
||||
pos,
|
||||
force_update,
|
||||
@ -311,7 +311,7 @@ impl<'a> System<'a> for Sys {
|
||||
})
|
||||
{
|
||||
for uid in &deleted {
|
||||
client.send_msg(ServerMsg::DeleteEntity(Uid(*uid)));
|
||||
client.send_msg(ServerGeneralMsg::DeleteEntity(Uid(*uid)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -353,7 +353,7 @@ impl<'a> System<'a> for Sys {
|
||||
// Sync resources
|
||||
// TODO: doesn't really belong in this system (rename system or create another
|
||||
// system?)
|
||||
let tof_msg = ServerMsg::TimeOfDay(*time_of_day);
|
||||
let tof_msg = ServerGeneralMsg::TimeOfDay(*time_of_day);
|
||||
for client in (&mut clients).join() {
|
||||
client.send_msg(tof_msg.clone());
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ use common::{
|
||||
event::{EventBus, ServerEvent},
|
||||
msg::{
|
||||
validate_chat_msg, CharacterInfo, ChatMsgValidationError, ClientInGameMsg, ClientIngame,
|
||||
ClientMsg, ClientNotInGameMsg, ClientRegisterMsg, DisconnectReason, PingMsg, PlayerInfo,
|
||||
PlayerListUpdate, RegisterError, ServerInGameMsg, ServerMsg, ServerNotInGameMsg,
|
||||
ClientGeneralMsg, ClientNotInGameMsg, ClientRegisterMsg, DisconnectReason, PingMsg, PlayerInfo,
|
||||
PlayerListUpdate, RegisterError, ServerInGameMsg, ServerGeneralMsg, ServerNotInGameMsg,
|
||||
ServerRegisterAnswerMsg, MAX_BYTES_CHAT_MSG,
|
||||
},
|
||||
span,
|
||||
@ -45,10 +45,10 @@ impl Sys {
|
||||
player_metrics: &ReadExpect<'_, PlayerMetrics>,
|
||||
uids: &ReadStorage<'_, Uid>,
|
||||
chat_modes: &ReadStorage<'_, ChatMode>,
|
||||
msg: ClientMsg,
|
||||
msg: ClientGeneralMsg,
|
||||
) -> Result<(), crate::error::Error> {
|
||||
match msg {
|
||||
ClientMsg::ChatMsg(message) => {
|
||||
ClientGeneralMsg::ChatMsg(message) => {
|
||||
if client.registered {
|
||||
match validate_chat_msg(&message) {
|
||||
Ok(()) => {
|
||||
@ -68,7 +68,7 @@ impl Sys {
|
||||
}
|
||||
}
|
||||
},
|
||||
ClientMsg::Command(message) => {
|
||||
ClientGeneralMsg::Command(message) => {
|
||||
if client.registered {
|
||||
match validate_chat_msg(&message) {
|
||||
Ok(()) => {
|
||||
@ -88,10 +88,10 @@ impl Sys {
|
||||
}
|
||||
}
|
||||
},
|
||||
ClientMsg::Disconnect => {
|
||||
client.send_msg(ServerMsg::Disconnect(DisconnectReason::Requested));
|
||||
ClientGeneralMsg::Disconnect => {
|
||||
client.send_msg(ServerGeneralMsg::Disconnect(DisconnectReason::Requested));
|
||||
},
|
||||
ClientMsg::Terminate => {
|
||||
ClientGeneralMsg::Terminate => {
|
||||
debug!(?entity, "Client send message to termitate session");
|
||||
player_metrics
|
||||
.clients_disconnected
|
||||
@ -435,7 +435,7 @@ impl Sys {
|
||||
.send(ServerRegisterAnswerMsg::Ok(()))?;
|
||||
|
||||
// Send initial player list
|
||||
client.send_msg(ServerMsg::PlayerListUpdate(PlayerListUpdate::Init(
|
||||
client.send_msg(ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Init(
|
||||
player_list.clone(),
|
||||
)));
|
||||
|
||||
@ -734,7 +734,7 @@ impl<'a> System<'a> for Sys {
|
||||
// Tell all clients to add them to the player list.
|
||||
for entity in new_players {
|
||||
if let (Some(uid), Some(player)) = (uids.get(entity), players.get(entity)) {
|
||||
let msg = ServerMsg::PlayerListUpdate(PlayerListUpdate::Add(*uid, PlayerInfo {
|
||||
let msg = ServerGeneralMsg::PlayerListUpdate(PlayerListUpdate::Add(*uid, PlayerInfo {
|
||||
player_alias: player.alias.clone(),
|
||||
is_online: true,
|
||||
is_admin: admins.get(entity).is_some(),
|
||||
|
@ -5,7 +5,7 @@ use super::{
|
||||
use crate::client::{self, Client, RegionSubscription};
|
||||
use common::{
|
||||
comp::{Ori, Player, Pos, Vel},
|
||||
msg::ServerMsg,
|
||||
msg::ServerGeneralMsg,
|
||||
region::{region_in_vd, regions_in_vd, Event as RegionEvent, RegionMap},
|
||||
span,
|
||||
sync::Uid,
|
||||
@ -153,7 +153,7 @@ impl<'a> System<'a> for Sys {
|
||||
.map(|key| subscription.regions.contains(key))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
client.send_msg(ServerMsg::DeleteEntity(uid));
|
||||
client.send_msg(ServerGeneralMsg::DeleteEntity(uid));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -161,7 +161,7 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
// Tell client to delete entities in the region
|
||||
for (&uid, _) in (&uids, region.entities()).join() {
|
||||
client.send_msg(ServerMsg::DeleteEntity(uid));
|
||||
client.send_msg(ServerGeneralMsg::DeleteEntity(uid));
|
||||
}
|
||||
}
|
||||
// Send deleted entities since they won't be processed for this client in entity
|
||||
@ -171,7 +171,7 @@ impl<'a> System<'a> for Sys {
|
||||
.iter()
|
||||
.flat_map(|v| v.iter())
|
||||
{
|
||||
client.send_msg(ServerMsg::DeleteEntity(Uid(*uid)));
|
||||
client.send_msg(ServerGeneralMsg::DeleteEntity(Uid(*uid)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ impl<'a> System<'a> for Sys {
|
||||
{
|
||||
// Send message to create entity and tracked components and physics
|
||||
// components
|
||||
client.send_msg(ServerMsg::CreateEntity(
|
||||
client.send_msg(ServerGeneralMsg::CreateEntity(
|
||||
tracked_comps.create_entity_package(
|
||||
entity,
|
||||
Some(*pos),
|
||||
@ -249,7 +249,7 @@ pub fn initialize_region_subscription(world: &World, entity: specs::Entity) {
|
||||
.join()
|
||||
{
|
||||
// Send message to create entity and tracked components and physics components
|
||||
client.send_msg(ServerMsg::CreateEntity(
|
||||
client.send_msg(ServerGeneralMsg::CreateEntity(
|
||||
tracked_comps.create_entity_package(
|
||||
entity,
|
||||
Some(*pos),
|
||||
|
@ -2,7 +2,7 @@ use super::SysTimer;
|
||||
use crate::client::Client;
|
||||
use common::{
|
||||
comp::{Player, Pos, Waypoint, WaypointArea},
|
||||
msg::{Notification, ServerMsg},
|
||||
msg::{Notification, ServerGeneralMsg},
|
||||
span,
|
||||
state::Time,
|
||||
};
|
||||
@ -42,7 +42,7 @@ impl<'a> System<'a> for Sys {
|
||||
if let Ok(wp_old) = waypoints.insert(entity, Waypoint::new(player_pos.0, *time))
|
||||
{
|
||||
if wp_old.map_or(true, |w| w.elapsed(*time) > NOTIFY_TIME) {
|
||||
client.send_msg(ServerMsg::Notification(Notification::WaypointSaved));
|
||||
client.send_msg(ServerGeneralMsg::Notification(Notification::WaypointSaved));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user