Пример #1
0
        private void HandleProposal(object sender, EventArgs <Message> e)
        {
            var msg = e.Value;

            if (msg.Type != Communications.MsgType.Notify || !msg.Content.StartsWith(PROPOSE))
            {
                return;
            }
            Log.Debug(_tag, "Received opponent's proposal message.");
            opponentsProposal = msg;
            opponentsProposalSignal.Set();
        }
Пример #2
0
        protected async Task <IChoreographer> InitChoreographer()
        {
            if (!CueClassifiers.ContainsKey(OFFENSE))
            {
                throw new Exception($"{OFFENSE} classifier not found.");
            }
            if (!CueClassifiers.ContainsKey(DEFENSE))
            {
                throw new Exception($"{DEFENSE} classifier not found.");
            }

            // Establish the choreographer - this depends on whether you're connected or not (and on Solipsism mode)
            if (Communications.Bluetooth.BluetoothMessageCenter.TemporaryAddressBook_SingleEntry == null)
            {
                if (!Res.SolipsismMode)
                {
                    return(new SimpleChoreographer(CueClassifiers));
                }
                else
                {
                    return(new SolipsisticChoreographer(CueClassifiers));
                }
            }
            else
            {
                Message myProposal = new Message(MsgType.Notify, PROPOSE);
                Communications.Bluetooth.BluetoothMessageCenter.TemporaryAddressBook_SingleEntry.SendMessage(myProposal);
                Log.Debug(_tag, "Sent proposal message.");
                await opponentsProposalSignal.WaitAsync();

                if (String.Compare(myProposal.ID, opponentsProposal.ID) == 0)
                {
                    Log.Debug(_tag, "Tie GUID encountered - WTF???");
                    return(await InitChoreographer());
                }
                else if (String.Compare(myProposal.ID, opponentsProposal.ID) > 0)
                {
                    Log.Debug(_tag, "My GUID wins - I'm choreographer.");
                    return(new SendingChoreographer(Communications.Bluetooth.BluetoothMessageCenter.TemporaryAddressBook_SingleEntry, CueClassifiers));
                }
                else
                {
                    Log.Debug(_tag, "My GUID loses - the other guy is choreographer this time.");
                    return(new ReceivingChoreographer(Communications.Bluetooth.BluetoothMessageCenter.TemporaryAddressBook_SingleEntry));
                }
            }
        }