-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for mutual connections [WIP] #117
Conversation
use super::packet::Packet; | ||
use std::sync::mpsc::Sender; | ||
use uuid::Uuid; | ||
|
||
pub trait PatchworkState { | ||
fn new_map(&self, peer: Peer); | ||
fn route_player_packet(&self, packet: Packet, conn_id: Uuid); | ||
fn connect_map(&self, map_index: usize, conn_id: PeerConnection); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this index thing blows, will be fixed with #118
@@ -58,63 +61,56 @@ impl Map { | |||
pub fn connect< | |||
M: 'static + Messenger + Clone + Send, | |||
PP: 'static + PacketProcessor + Clone + Send, | |||
PA: 'static + PatchworkState + Clone + Send, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Establishing a new pattern here for async stuff- basically throw a copy of your own sender so they can call you back once it's done. There might be better ways of doing this, not really sure about the adoption of callbacks here
pub fn start<M: Messenger>(receiver: Receiver<BlockStateOperations>, messenger: M) { | ||
pub fn start<M: Messenger>( | ||
receiver: Receiver<BlockStateOperations>, | ||
_sender: Sender<BlockStateOperations>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all the services are called by the same macro they all now take a sender (unused, hence the underscore). I think it's reasonable to give them all the ability to send messages to themselves. We'll see how this pattern turns out
) | ||
} | ||
PatchworkStateOperations::ConnectMap(msg) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the callback once the peer actually connects
messenger.broadcast_packet( | ||
msg.packet, | ||
entity_conn_ids.get(&msg.entity_id).copied(), | ||
true, | ||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug that was revealed when mutual connections started working. Certainly events from anchored players are not local events that should be broadcast to every peer
messenger: M, | ||
) { | ||
match msg { | ||
PlayerStateOperations::New(msg) => { | ||
let mut player = msg.player; | ||
if player.entity_id == 0 { | ||
player.entity_id = players.len().try_into().expect("too many players"); | ||
player.entity_id = *entity_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we started deleting players when they disconnect we can't use length of the player map as an id anymore
Issue: #116
Why
What
Checks