public void FoundPeer(MCNearbyServiceBrowser browser, MCPeerID peerID, NSDictionary info) { if (peerID != this.myself.PeerId) { var appIdentifier = info?[XamarinShotGameAttribute.AppIdentifier]; if (appIdentifier?.ToString() == NSBundle.MainBundle.BundleIdentifier) { DispatchQueue.MainQueue.DispatchAsync(() => { var player = new Player(peerID); var gameName = info?[XamarinShotGameAttribute.Name] as NSString; GameTableLocation location = null; var locationIdString = info?[XamarinShotGameAttribute.Location] as NSString; if (!string.IsNullOrEmpty(locationIdString) && int.TryParse(locationIdString, out int locationId)) { location = GameTableLocation.GetLocation(locationId); } var game = new NetworkGame(player, gameName, location?.Identifier ?? 0); this.games.Add(game); this.Delegate?.SawGames(this, new List <NetworkGame>(this.games)); }); } } }
public static GameTableLocation GetLocation(int identifier) { if (!Locations.TryGetValue(identifier, out GameTableLocation location)) { location = new GameTableLocation(identifier); Locations[identifier] = location; } return(location); }
public NetworkSession(Player myself, bool asServer, GameTableLocation location, Player host) : base() { this.myself = myself; this.Session = new MCSession(this.myself.PeerId, null, MCEncryptionPreference.Required); this.IsServer = asServer; this.location = location; this.Host = host; this.appIdentifier = NSBundle.MainBundle.BundleIdentifier; this.Session.Delegate = this; }
public override void DidRangeBeacons(CLLocationManager manager, CLBeacon[] beacons, CLBeaconRegion region) { // we want to filter out beacons that have unknown proximity var knownBeacon = beacons.FirstOrDefault(beacon => beacon.Proximity != CLProximity.Unknown); if (knownBeacon != null) { GameTableLocation location = null; if (knownBeacon.Proximity == CLProximity.Near || knownBeacon.Proximity == CLProximity.Immediate) { location = GameTableLocation.GetLocation(knownBeacon.Minor.Int32Value); } if (this.ClosestLocation != location) { // Closest location changed this.ClosestLocation = location; this.Delegate?.LocationChanged(this, location); } } }
/// <summary> /// for beacon use /// </summary> /// <param name="newLocation">New location.</param> public void UpdateLocation(GameTableLocation newLocation) { this.location = newLocation; }