Beispiel #1
0
 public Message CreateChatMessageMessage(ChatRoom room, string messageText)
 {
     Message p = new Message(network, MessageType.ChatroomMessage);
     ChatMessage c = new ChatMessage();
     c.RoomId = room.Id;
     c.RoomName = room.Name;
     c.Message = messageText;
     //		p.To = "";
     p.Content = c;
     return p;
 }
        internal void ProcessChatMessage(Node messageFrom, ChatMessage message)
        {
            ChatRoom c = network.GetChatRoom(message.RoomId);

            if (messageFrom != null) {

                if (c == null) {
                    c = new ChatRoom (network, message.RoomId, message.RoomName);
                    network.AddChatRoom(c);
                    LoggingService.LogWarning("MessageProcessor: Assuming chat room {0} exists and that somebody will be joining it in a moment...", c.Name);
                }

                if (!c.Users.ContainsKey(messageFrom.NodeID)) {
                    LoggingService.LogWarning("MessageProcessor: Assuming {0} is in {1}...", messageFrom.NickName, c.Name);
                    c.AddUser(messageFrom);

                    network.RaiseJoinedChat (messageFrom, c);
                }
                if (c.InRoom == true) {
                    string messageText = message.Message;
                    if (c.HasPassword) {
                        try {
                            byte[] saltBytes = System.Text.Encoding.UTF8.GetBytes(c.Id);
                            messageText = Security.Encryption.PasswordDecrypt(c.Password, messageText, saltBytes);
                        } catch (Exception) {
                            messageText = "<UNABLE TO DECRYPT MESSAGE>";
                        }
                    }
                    network.RaiseChatMessage (c, messageFrom, messageText);
                }
            } else {
                throw new Exception("A chat message was Received from a non existing user! (NodeID: " + messageFrom + ")");
            }
        }