HostServer, Systems and Schedules #922
-
|
I want to approach very basic usage first, before I get into the advanced features you already implement, and just tried to play around with directly sending a message. I tried to implement message sending with the current official 0.19 release (I saw that the code will change for all that) and I registered a system, that sends out messages typed into a box (this code works fine and emits one event) fn handle_send_chat_message(
mut send_chat_messages: EventReader<SendChatMessage>, // local event emitted by the textbox
mut client: ResMut<ClientConnectionManager>,
) {
for event in send_chat_messages.read() {
let message = &event.0;
info!("Send message: {:?}", message);
client
.send_message_to_target::<MainChannel, ChatMessage>(&message, NetworkTarget::All)
.unwrap_or_else(|e| {
error!("Failed to send message: {:?}", e);
});
}
}now i wanted the server to handle incoming messages, and saw similar examples also here fn server_handle_chat_messages(
mut input_reader: EventReader<MessageEvent<ChatMessage>>,
entity_map: Res<ClientEntityMap>,
mut commands: Commands,
) {
for input in input_reader.read() {
let client_id = input.from();
let message = input.message.clone();
info!("Received a message!");
}
}I used HostServer Setup. But I would be still interested, what about systems that are not behind a compiler flag, would it suffice to only react to messages that are Client(0), if I want to have server only logic, or could I bind my system in some kind of ServerFixedUpdate Scheduler? If I want to write systems, that work the same in a single player with networking enabled, I therefore have to ignore myself or all but myself in ::All messages? If there are no such schedules yet, would that not also be some nice idea to make it easier to write server and client code? Sorry for my stupid questions. I love your library. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I think it might be a bug? |
Beta Was this translation helpful? Give feedback.
I think it might be a bug?
When the client sends a message to the server with
NetworkTarget::All, the server should redirect the message to all other clients (including the local client), so only the local client should receive the message viaMessageEventand not the server.I think this might be fixed in the
mainbranch. (which also makes the distinction betweenClientMessageandServerMessagemore explicit so that you cannot confuse the two)