示例#1
0
        private void _listener_OnReceiveMessage(object sender, ReceiveMessageEventArgs e)
        {
            LogBroker.Log(string.Format("RX {0} from {1}",
                                        e.Message.Type,
                                        e.Message.SourceID));

            switch (e.Message.Type)
            {
            case MessageType.KeyDistribute:
                AddKeys((e.Message as KeyDistributeMessage).Keys);
                _actualResponses++;
                break;
            }

            if (_actualResponses == _joinAck.ExpectedResponses)
            {
                var joinAckAckMsg = new JoinAckAckMessage()
                {
                    SourceID      = _config.ID,
                    DestinationID = _joinAck.SourceID
                };

                SendMessage(joinAckAckMsg, _group);
            }
        }
示例#2
0
        private void _group_OnReceiveMessage(object sender, ReceiveMessageEventArgs e)
        {
            if (e.Message.Type != MessageType.JoinAck &&
                e.Message.Type != MessageType.JoinEnd)
            {
                return; // Only care about these messages
            }
            LogBroker.Log(string.Format("RX {0} from {1}",
                                        e.Message.Type,
                                        e.Message.SourceID));

            if (e.Message.DestinationID != _config.ID && e.Message.DestinationID != Constants.NULL_DESTINATION)
            {
                return;
            }

            switch (e.Message.Type)
            {
            case MessageType.JoinAck:
                _joinAck = e.Message as JoinAckMessage;
                break;

            case MessageType.JoinEnd:
                _t.Stop();
                _nodeCount     = (e.Message as JoinEndMessage).NodeCount;
                _joinSucceeded = true;
                _joinFinished  = true;
                break;
            }
        }
示例#3
0
        private void OnReceiveMessage(object sender, ReceiveMessageEventArgs args)
        {
            if (args.Type != MessageType.File)
            {
                return;
            }

            using (var client = Model.Get())
            {
                var room = client.Chat.GetRoom(args.RoomName);
                var file = room.TryGetFile(args.FileId);

                var downaladDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "downloads");
                if (!Directory.Exists(downaladDirectory))
                {
                    Directory.CreateDirectory(downaladDirectory);
                }

                var path = Path.Combine(downaladDirectory, file.Name);
                if (NeedDownload(file.Name))
                {
                    RemoveFile(file.Name);
                    Model.Api.Perform(new ClientDownloadFileAction(ServerChat.MainRoomName, args.FileId, path));
                }
            }
        }
 private void OnReceivePeerMessage(object sender, ReceiveMessageEventArgs e)
 {
     if (onReceiveMessage != null)
     {
         onReceiveMessage.Invoke(sender, e);
     }
 }
示例#5
0
        protected override void OnRun(MessageContent content, CommandArgs args)
        {
            if (content.Message == null)
            {
                throw new ArgumentException("content.Message");
            }

            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentException("ontent.RoomName");
            }

            using (var client = ClientModel.Get())
            {
                var room = client.Chat.GetRoom(content.RoomName);
                room.AddMessage(new Message(content.Message));

                var receiveMessageArgs = new ReceiveMessageEventArgs
                {
                    Type      = MessageType.Common,
                    RoomName  = content.RoomName,
                    MessageId = content.Message.Id,
                    Time      = content.Message.Time,
                    Message   = content.Message.Text,
                    Sender    = content.Message.Owner,
                };

                ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
            }
        }
示例#6
0
        private void ClientReceiveMessage(object sender, ReceiveMessageEventArgs e)
        {
            if (e.Type != MessageType.System && e.Type != MessageType.Private)
            {
                return;
            }

            Dispatcher.BeginInvoke(new Action <ReceiveMessageEventArgs>(args =>
            {
                switch (args.Type)
                {
                case MessageType.Private:
                    using (var client = ClientModel.Get())
                    {
                        UserViewModel senderUser   = AllUsers.Single(uvm => string.Equals(uvm.Info.Nick, args.Sender));
                        UserViewModel receiverUser = AllUsers.Single(uvm => string.Equals(uvm.Info.Nick, client.User.Nick));
                        SelectedRoom.AddPrivateMessage(senderUser, receiverUser, args.Message);
                    }
                    break;

                case MessageType.System:
                    SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(args.SystemMessage, args.SystemMessageFormat));
                    break;
                }

                Alert();
            }), e);
        }
示例#7
0
        private void ClientReceiveMessage(ReceiveMessageEventArgs e)
        {
            if (e.RoomName != Name)
            {
                return;
            }

            switch (e.Type)
            {
            case MessageType.Common:
                AddMessage(e.MessageId, e.Time, e.Sender, e.Message);
                break;

            case MessageType.File:
                AddFileMessage(e.Time, e.Sender, e.FileId);
                break;
            }

            if (Name != mainViewModel.SelectedRoom.Name)
            {
                Updated = true;
            }

            mainViewModel.Alert();
        }
示例#8
0
        private void TryReconnect()
        {
            if (!reconnecting)
            {
                return;
            }

            var interval = (DateTime.Now - lastReconnect).TotalMilliseconds;

            if (interval < ReconnectTimeInterval)
            {
                return;
            }

            var args = new ReceiveMessageEventArgs
            {
                SystemMessage = SystemMessageId.ConnectionRetryAttempt,
                Time          = DateTime.UtcNow,
                Type          = MessageType.System
            };

            ClientModel.Notifier.ReceiveMessage(args);

            Clean();
            Connect(hostAddress);

            reconnecting  = false;
            lastReconnect = DateTime.Now;
        }
示例#9
0
 protected virtual void OnReceiveMessage(ReceiveMessageEventArgs e)
 {
     if (ReceiveMessage != null)
     {
         ReceiveMessage(this, e);
     }
 }
示例#10
0
        private void TryReconnect()
        {
            if (!_reconnecting)
            {
                return;
            }

            var interval = (DateTime.UtcNow - _lastReconnect).TotalMilliseconds;

            if (interval < ReconnectInterval)
            {
                return;
            }

            var args = new ReceiveMessageEventArgs
            {
                SystemMessage = SystemMessageId.ConnectionRetryAttempt,
                Time          = DateTime.UtcNow,
                Type          = MessageType.System
            };

            _notifier.ReceiveMessage(args);

            Clean();
            Connect(_serverUri);

            _reconnecting  = false;
            _lastReconnect = DateTime.UtcNow;
        }
示例#11
0
        private void ClientReceiveMessage(object sender, ReceiveMessageEventArgs e)
        {
            if (e.RoomName != Name)
            {
                return;
            }

            Dispatcher.BeginInvoke(new Action <ReceiveMessageEventArgs>(args =>
            {
                var senderUser = MainViewModel.AllUsers.Single(uvm => uvm.Info.Nick == args.Sender);

                switch (args.Type)
                {
                case MessageType.Common:
                    AddMessage(args.MessageId, senderUser, args.Message);
                    break;

                case MessageType.File:
                    AddFileMessage(senderUser, (FileDescription)args.State);
                    break;
                }

                if (Name != MainViewModel.SelectedRoom.Name)
                {
                    Updated = true;
                }

                MainViewModel.Alert();
            }), e);
        }
示例#12
0
        public void Run(ClientCommandArgs args)
        {
            var receivedContent = Serializer.Deserialize <MessageContent>(args.Message);

            if (receivedContent.File == null)
            {
                throw new ArgumentNullException("file");
            }

            if (string.IsNullOrEmpty(receivedContent.RoomName))
            {
                throw new ArgumentException("roomName");
            }

            var receiveMessageArgs = new ReceiveMessageEventArgs
            {
                Type      = MessageType.File,
                MessageId = Room.SpecificMessageId,
                Message   = receivedContent.File.Name,
                Sender    = receivedContent.File.Owner.Nick,
                RoomName  = receivedContent.RoomName,
                State     = receivedContent.File,
            };

            ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
        }
示例#13
0
        protected override void OnRun(MessageContent content, ClientCommandArgs args)
        {
            if (string.IsNullOrEmpty(content.Sender))
            {
                throw new ArgumentException("sender");
            }

            if (string.IsNullOrEmpty(content.Message))
            {
                throw new ArgumentException("message");
            }

            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentException("roomName");
            }

            using (var client = ClientModel.Get())
            {
                var room = client.Rooms[content.RoomName];
                room.AddMessage(content.Sender, content.MessageId, content.Message);
            }

            var receiveMessageArgs = new ReceiveMessageEventArgs
            {
                Type      = MessageType.Common,
                Message   = content.Message,
                Sender    = content.Sender,
                RoomName  = content.RoomName,
                MessageId = content.MessageId,
            };

            ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
        }
示例#14
0
        private void tmUpdate_Tick(object sender, EventArgs e)
        {
            labStatus.Text = MeditationLogic.MeditationEnabled;
            labExp.Text    = String.Format("Опыт: {0}/{1}({2}%)", RoleInfo.Experience, RoleInfo.MaxExperience,
                                           RoleInfo.ExpPercent.ToString("0.0"));
            pbExp.Value   = (int)RoleInfo.ExpPercent;
            labLevel.Text = "Лвл: " + RoleInfo.Level;


            labAllMeditationTime.Text  = String.Format("Сегодня: {0}", TimeToNormal(MeditationLogic.MeditationTotal));
            labDeepMeditationTime.Text = String.Format("Гл. медитация: {0}", TimeToNormal(MeditationLogic.MeditationDeep));
            labMeditationTime.Text     = String.Format("Медитация: {0}", TimeToNormal(MeditationLogic.MeditationNormal));


            if (MeditationLogic.Enabled)
            {
                if (MeditationLogic.PrivateMessages.Count != 0)
                {
                    ReceiveMessageEventArgs message = MeditationLogic.PrivateMessages[0];
                    MeditationLogic.PrivateMessages.RemoveAt(0);
                    AddMessage(message.Name, message.Message);
                }

                nIcon.Text = String.Format("PWMeditation - {0}\r\n  {1}\r\n  Опыт: {2}%", MeditationLogic.Settings.PlayerName,
                                           labLevel.Text, RoleInfo.ExpPercent.ToString("0.0"));


                if (MeditationLogic.ExpDelta != 0)
                {
                    //labExp.Text += String.Format(" (в минуту {0})",MeditationLogic.ExpDelta);

                    //Считаем время до апа в медитации
                    var ExpNeeded        = RoleInfo.MaxExperience - RoleInfo.Experience;
                    var MinutesRemaining = ExpNeeded / MeditationLogic.ExpDelta;
                    labLevel.Text += ". До апа: " + TimeToNormal(MinutesRemaining * 60);


                    if (MeditationLogic.oog != null)
                    {
                        //Считаем сколько опыта будет после медитации
                        var MeditationTime = MeditationLogic.oog.Meditation.UsedType == 0
                                               ? MeditationLogic.MeditationNormal
                                               : MeditationLogic.MeditationDeep;
                        var time = (MeditationTime < MeditationLogic.MeditationTotal
                                      ? MeditationTime
                                      : MeditationLogic.MeditationTotal) / 60;

                        double EstExp = RoleInfo.Experience + time * MeditationLogic.ExpDelta;
                        lblEstimatedExp.Text = String.Format("Будет: {0}/{1}({2}%)", EstExp, RoleInfo.MaxExperience,
                                                             (100 * EstExp / RoleInfo.MaxExperience).ToString("0.0"));
                    }
                }
            }
            else
            {
                nIcon.Text = "PWMeditation";
            }
        }
示例#15
0
 public override void OnReceivePlayerMessage(object sender, ReceiveMessageEventArgs args)
 {
     /*if (args.Message.Type == MessageType.TurnAsk) {
      *  ///Player p = sender as Player;
      *  //ProcessFast(p);
      * }
      * else*/
     base.OnReceivePlayerMessage(sender, args);
 }
示例#16
0
        private void EventReceiveMessage(string iMessage, uint iArgb = 0xFFBBBBBB, bool iBold = false)
        {
            //返すデータの設定
            ReceiveMessageEventArgs e = new ReceiveMessageEventArgs();

            e.Message = iMessage;
            e.Color   = Color.FromArgb((int)iArgb);
            e.Bold    = iBold;
            //イベントの発生
            OnReceiveMessage(e);
        }
示例#17
0
        public virtual void MessageHandler_OnReceiveMessage(IMessageHandler sender, ReceiveMessageEventArgs e)
        {
            var msg = e.Message as ItemChangedMessage;

            if (msg != null && BusinessObjectPreviewList != null &&
                msg.PreviewItemType == BusinessObjectPreviewList.ItemType)
            {
                var wasDeleted = (msg.Mode == ItemChangedMode.Delete);
                RefreshPreviewItem(msg.BusinessObjectId, wasDeleted);
            }
        }
示例#18
0
        private void UpdateConvo(object sender, ReceiveMessageEventArgs e)
        {
            if (convoTxtBox.InvokeRequired)
            {
                MethodInvoker mi = new MethodInvoker(
                    delegate()
                {
                    convoTxtBox.AppendText("\n" + e.Message);
                }
                    );

                convoTxtBox.BeginInvoke(mi);
            }
        }
示例#19
0
        protected override void OnRun(MessageContent content, ClientCommandArgs args)
        {
            if (content.Message == null)
            {
                throw new ArgumentNullException("message");
            }

            var receiveMessageArgs = new ReceiveMessageEventArgs
            {
                Type    = MessageType.Private,
                Message = content.Message,
                Sender  = args.PeerConnectionId,
            };

            ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
        }
        protected override void OnRun(MessageContent content, CommandArgs args)
        {
            if (content.Text == null)
            {
                throw new ArgumentNullException(nameof(content.Text));
            }

            var receiveMessageArgs = new ReceiveMessageEventArgs
            {
                Type    = MessageType.Private,
                Time    = DateTime.UtcNow,
                Message = content.Text,
                Sender  = args.ConnectionId,
            };

            ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
        }
示例#21
0
        public void Run(ClientCommandArgs args)
        {
            var receivedContent = Serializer.Deserialize <MessageContent>(args.Message);

            if (receivedContent.Key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (receivedContent.Message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (string.IsNullOrEmpty(receivedContent.Sender))
            {
                throw new ArgumentException("sender");
            }

            var decryptedSymmetricKey = ClientModel.Client.KeyCryptor.Decrypt(receivedContent.Key, true);

            using (MemoryStream messageStream = new MemoryStream(),
                   encryptedMessageStream = new MemoryStream(receivedContent.Message))
            {
                var provider = new AesCryptoServiceProvider
                {
                    Padding = PaddingMode.Zeros,
                    Mode    = CipherMode.CBC
                };

                using (Crypter messageCrypter = new Crypter(provider))
                    messageCrypter.DecryptStream(encryptedMessageStream, messageStream, decryptedSymmetricKey);

                var receiveMessageArgs = new ReceiveMessageEventArgs
                {
                    Type    = MessageType.Private,
                    Message = Encoding.Unicode.GetString(messageStream.ToArray()),
                    Sender  = receivedContent.Sender,
                };

                ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
            }
        }
示例#22
0
        private void ClientReceiveMessage(ReceiveMessageEventArgs e)
        {
            if (e.Type != MessageType.System && e.Type != MessageType.Private)
            {
                return;
            }

            switch (e.Type)
            {
            case MessageType.Private:
                SelectedRoom.AddPrivateMessage(e.Sender, ClientModel.Client.Id, e.Message);
                break;

            case MessageType.System:
                SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(e.SystemMessage, e.SystemMessageFormat));
                break;
            }

            Alert();
        }
示例#23
0
        private void _group_OnReceiveMessage(object sender, ReceiveMessageEventArgs e)
        {
            if (e.Message.Type != MessageType.KeyInstruct)
            {
                return; // Only care about these messages
            }
            LogBroker.Log(string.Format("RX {0} from {1}",
                                        e.Message.Type,
                                        e.Message.SourceID));

            if (e.Message.DestinationID != _config.ID)
            {
                return;
            }

            switch (e.Message.Type)
            {
            case MessageType.KeyInstruct:
                HandleKeyInstruct(e.Message as KeyInstructMessage);
                break;
            }
        }
示例#24
0
        private void _tcpServer_OnReceiveMessage(object sender, ReceiveMessageEventArgs e)
        {
            LogBroker.Log(string.Format("RX {0} from {1}",
                                        e.Message.Type,
                                        e.Message.SourceID));

            switch (e.Message.Type)
            {
            case MessageType.KeyDistribute:
                var msg = e.Message as KeyDistributeMessage;
                _processor.Add(msg.Keys);

                var leaveAck = new LeaveAckMessage()
                {
                    SourceID      = _config.ID,
                    DestinationID = Constants.NULL_DESTINATION
                };

                SendMessage(leaveAck, _group);
                break;
            }
        }
示例#25
0
        protected override void OnRun(MessageContent content, ClientCommandArgs args)
        {
            if (content.File == null)
            {
                throw new ArgumentNullException("file");
            }

            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentException("roomName");
            }

            using (var client = ClientModel.Get())
            {
                Room room;
                if (!client.Rooms.TryGetValue(content.RoomName, out room))
                {
                    return;
                }

                room.Files.RemoveAll(f => f.Id == content.File.Id);
                room.Files.Add(content.File);
            }

            var receiveMessageArgs = new ReceiveMessageEventArgs
            {
                Type      = MessageType.File,
                MessageId = Room.SpecificMessageId,
                Time      = DateTime.UtcNow,
                Message   = content.File.Name,
                Sender    = content.File.Id.Owner,
                RoomName  = content.RoomName,
                FileId    = content.File.Id,
            };

            ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
        }
        public void Run(ClientCommandArgs args)
        {
            var receivedContent = Serializer.Deserialize <MessageContent>(args.Message);

            if (string.IsNullOrEmpty(receivedContent.Sender))
            {
                throw new ArgumentException("sender");
            }

            if (string.IsNullOrEmpty(receivedContent.Message))
            {
                throw new ArgumentException("message");
            }

            if (string.IsNullOrEmpty(receivedContent.RoomName))
            {
                throw new ArgumentException("roomName");
            }

            using (var client = ClientModel.Get())
            {
                var room = client.Rooms[receivedContent.RoomName];
                room.AddMessage(receivedContent.Sender, receivedContent.MessageId, receivedContent.Message);
            }

            var receiveMessageArgs = new ReceiveMessageEventArgs
            {
                Type      = MessageType.Common,
                Message   = receivedContent.Message,
                Sender    = receivedContent.Sender,
                RoomName  = receivedContent.RoomName,
                MessageId = receivedContent.MessageId,
            };

            ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
        }
示例#27
0
        protected override void OnRun(MessageContent content, ClientCommandArgs args)
        {
            if (content.File == null)
            {
                throw new ArgumentNullException("file");
            }

            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentException("roomName");
            }

            var receiveMessageArgs = new ReceiveMessageEventArgs
            {
                Type      = MessageType.File,
                MessageId = Room.SpecificMessageId,
                Message   = content.File.Name,
                Sender    = content.File.Owner.Nick,
                RoomName  = content.RoomName,
                State     = content.File,
            };

            ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
        }
示例#28
0
        private void _group_OnReceiveMessage(object sender, ReceiveMessageEventArgs e)
        {
            if (e.Message.Type != MessageType.ElectionProposal &&
                e.Message.Type != MessageType.ElectionAck &&
                e.Message.Type != MessageType.ElectionEnd)
            {
                return; // Only care about these messages
            }
            LogBroker.Log(string.Format("RX {0} from {1}",
                                        e.Message.Type,
                                        e.Message.SourceID));

            if (e.Message.DestinationID != _config.ID && e.Message.DestinationID != Constants.NULL_DESTINATION)
            {
                return;
            }

            Debug.WriteLine(string.Format("RX {0} from {1}", e.Message.Type, e.Message.SourceID));
            switch (e.Message.Type)
            {
            case MessageType.ElectionProposal:
                if (e.Message.SourceID != _config.ID)     // Don't handle loopback proposals
                {
                    HandleElectionProposal(e.Message as ElectionProposalMessage);
                }
                break;

            case MessageType.ElectionAck:
                HandleElectionAck(e.Message as ElectionAckMessage);
                break;

            case MessageType.ElectionEnd:
                HandleElectionEnd(e.Message as ElectionEndMessage);
                break;
            }
        }
示例#29
0
        protected override void OnRun(MessageContent content, CommandArgs args)
        {
            if (content.File == null)
            {
                throw new ArgumentNullException("content.File");
            }

            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentException("content.RoomName");
            }

            using (var client = ClientModel.Get())
            {
                var room = client.Chat.GetRoom(content.RoomName);

                // File may be posted twice, it's allowed
                if (!room.IsFileExist(content.File.Id))
                {
                    room.AddFile(new FileDescription(content.File));
                }
            }

            var receiveMessageArgs = new ReceiveMessageEventArgs
            {
                Type      = MessageType.File,
                MessageId = Room.SpecificMessageId,
                Time      = DateTime.UtcNow,
                Message   = content.File.Name,
                Sender    = content.File.Id.Owner,
                RoomName  = content.RoomName,
                FileId    = content.File.Id,
            };

            ClientModel.Notifier.ReceiveMessage(receiveMessageArgs);
        }
示例#30
0
        private void TryReconnect()
        {
            if (!reconnecting)
            return;

              var interval = (DateTime.Now - lastReconnect).TotalMilliseconds;
              if (interval < ReconnectTimeInterval)
            return;

              var args = new ReceiveMessageEventArgs
              {
            SystemMessage = SystemMessageId.ConnectionRetryAttempt,
            Time = DateTime.UtcNow,
            Type = MessageType.System
              };

              ClientModel.Notifier.ReceiveMessage(args);

              Clean();
              Connect(hostAddress);

              reconnecting = false;
              lastReconnect = DateTime.Now;
        }
示例#31
0
 static void AutoMessage_OnMessageReceived(object sender, ReceiveMessageEventArgs e)
 {
     PrivateMessages.Add(e);
 }
 private void _Server_ReceiveMessage(object sender, ReceiveMessageEventArgs e)
 {
     _Messages.Add(e.Message);
 }