コード例 #1
0
        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;
            }));
        }
コード例 #2
0
        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;
                }
            });
        }
コード例 #3
0
        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);
            }));
        }
コード例 #4
0
 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;
     }
 }