Skip to content
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

Merged
merged 1 commit into from
Jan 6, 2020
Merged

Conversation

DuncanUszkay1
Copy link
Owner

Issue: #116

Why

What

Checks

  • I have performed the manual integration test
  • The output of cargo clippy is empty
  • I have run cargo fmt on my most recent changes
  • I haven't read the PR template

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);
Copy link
Owner Author

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,
Copy link
Owner Author

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>,
Copy link
Owner Author

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) => {
Copy link
Owner Author

@DuncanUszkay1 DuncanUszkay1 Jan 3, 2020

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,
Copy link
Owner Author

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;
Copy link
Owner Author

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

@DuncanUszkay1 DuncanUszkay1 merged commit 275e855 into master Jan 6, 2020
@DuncanUszkay1 DuncanUszkay1 deleted the mutual-connection branch January 6, 2020 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant