public override Task Join(MultiplayerGame game) { return(Task.Factory.StartNew(() => { if (!Started) { throw new InvalidOperationException("Chord is not started!"); } _channel = _manager.JoinChannel(game.Id, this); _game = game; })); }
public void OnStarted(string name, int reason) { _publicChannel = _manager.JoinChannel(ChordManager.PublicChannel, this); //I have no idea why we need a delay here, but the first request fails otherwise Task.Delay(3000).ContinueWith(t => { if (_startSource != null) { Started = true; _startSource.SetResult(true); _startSource = null; } }); }
public override Task Host(MultiplayerGame game) { game.Id = Guid.NewGuid().ToString("N"); return(Start().ContinueWith(t => { if (t.IsFaulted) { throw t.Exception.InnerExceptions.First(); } _game = game; _channel = _manager.JoinChannel(game.Id, this); })); }
public override void Stop() { if (_manager != null) { _manager.Stop(); if (_publicChannel != null) { _manager.LeaveChannel(_publicChannel.Name); _publicChannel.Dispose(); _publicChannel = null; } if (_channel != null) { _manager.LeaveChannel(_channel.Name); _channel.Dispose(); _channel = null; } _game = null; Started = false; } }