Beispiel #1
0
        private void HandleChatEvents()
        {
            //Handle leave event
            if (!leaveEventHandled)
            {
                if (!string.IsNullOrEmpty(selectedChannel) && selectedChannel != consoleIdentifier)
                {
                    using (MessageWriter mw = new MessageWriter())
                    {
                        mw.Write <int>((int)ChatMessageType.LEAVE);
                        mw.Write <string>(dmpSettings.playerName);
                        mw.Write <string>(selectedChannel);
                        networkWorker.SendChatMessage(mw.GetMessageBytes());
                    }

                    if (joinedChannels.Contains(selectedChannel))
                    {
                        joinedChannels.Remove(selectedChannel);
                    }

                    selectedChannel   = null;
                    selectedPMChannel = null;
                }
                if (!string.IsNullOrEmpty(selectedPMChannel))
                {
                    if (joinedPMChannels.Contains(selectedPMChannel))
                    {
                        joinedPMChannels.Remove(selectedPMChannel);
                    }

                    selectedChannel   = null;
                    selectedPMChannel = null;
                }

                leaveEventHandled = true;
            }
            //Handle send event
            if (!sendEventHandled)
            {
                if (sendText != "")
                {
                    HandleChatInput(sendText);
                }
                sendText         = "";
                sendEventHandled = true;
            }
            //Handle join messages
            while (newJoinMessages.Count > 0)
            {
                JoinLeaveMessage jlm = newJoinMessages.Dequeue();
                if (!playerChannels.ContainsKey(jlm.fromPlayer))
                {
                    playerChannels.Add(jlm.fromPlayer, new List <string>());
                }
                if (!playerChannels[jlm.fromPlayer].Contains(jlm.channel))
                {
                    playerChannels[jlm.fromPlayer].Add(jlm.channel);
                }
            }
            //Handle leave messages
            while (newLeaveMessages.Count > 0)
            {
                JoinLeaveMessage jlm = newLeaveMessages.Dequeue();
                if (playerChannels.ContainsKey(jlm.fromPlayer))
                {
                    if (playerChannels[jlm.fromPlayer].Contains(jlm.channel))
                    {
                        playerChannels[jlm.fromPlayer].Remove(jlm.channel);
                    }
                    if (playerChannels[jlm.fromPlayer].Count == 0)
                    {
                        playerChannels.Remove(jlm.fromPlayer);
                    }
                }
            }
            //Handle channel messages
            while (newChannelMessages.Count > 0)
            {
                ChannelEntry ce = newChannelMessages.Dequeue();
                if (!channelMessages.ContainsKey(ce.channel))
                {
                    channelMessages.Add(ce.channel, new List <string>());
                }

                // Write message to screen if chat window is disabled
                if (!display)
                {
                    chatButtonHighlighted = ce.fromPlayer != consoleIdentifier;

                    if (!string.IsNullOrEmpty(ce.channel))
                    {
                        ScreenMessages.PostScreenMessage(ce.fromPlayer + " -> #" + ce.channel + ": " + ce.message, 5f, ScreenMessageStyle.UPPER_LEFT);
                    }
                    else
                    {
                        ScreenMessages.PostScreenMessage(ce.fromPlayer + " -> #Global : " + ce.message, 5f, ScreenMessageStyle.UPPER_LEFT);
                    }
                }

                //Highlight if the channel isn't selected.
                if (!string.IsNullOrEmpty(selectedChannel) && string.IsNullOrEmpty(ce.channel) && ce.fromPlayer != consoleIdentifier)
                {
                    if (!highlightChannel.Contains(ce.channel))
                    {
                        highlightChannel.Add(ce.channel);
                    }
                }

                if (!string.IsNullOrEmpty(ce.channel) && ce.channel != selectedChannel)
                {
                    if (!highlightChannel.Contains(ce.channel))
                    {
                        highlightChannel.Add(ce.channel);
                    }
                }

                //Move the bar to the bottom on a new message
                if (string.IsNullOrEmpty(selectedChannel) && string.IsNullOrEmpty(selectedPMChannel) && string.IsNullOrEmpty(ce.channel))
                {
                    chatScrollPos.y = float.PositiveInfinity;
                    selectTextBox   = chatLocked;
                }

                if (!string.IsNullOrEmpty(selectedChannel) && string.IsNullOrEmpty(selectedPMChannel) && ce.channel == selectedChannel)
                {
                    chatScrollPos.y = float.PositiveInfinity;
                    selectTextBox   = chatLocked;
                }

                channelMessages[ce.channel].Add(ce.fromPlayer + ": " + ce.message);
            }
            //Handle private messages
            while (newPrivateMessages.Count > 0)
            {
                PrivateEntry pe = newPrivateMessages.Dequeue();
                if (pe.fromPlayer != dmpSettings.playerName)
                {
                    if (!privateMessages.ContainsKey(pe.fromPlayer))
                    {
                        privateMessages.Add(pe.fromPlayer, new List <string>());
                    }

                    //Highlight if the player isn't selected
                    if (!joinedPMChannels.Contains(pe.fromPlayer))
                    {
                        joinedPMChannels.Add(pe.fromPlayer);
                    }

                    if (selectedPMChannel != pe.fromPlayer)
                    {
                        if (!highlightPM.Contains(pe.fromPlayer))
                        {
                            highlightPM.Add(pe.fromPlayer);
                        }
                    }
                }

                if (!privateMessages.ContainsKey(pe.toPlayer))
                {
                    privateMessages.Add(pe.toPlayer, new List <string>());
                }

                //Move the bar to the bottom on a new message
                if (!string.IsNullOrEmpty(selectedPMChannel) && string.IsNullOrEmpty(selectedChannel) && (pe.fromPlayer == selectedPMChannel || pe.fromPlayer == dmpSettings.playerName))
                {
                    chatScrollPos.y = float.PositiveInfinity;
                    selectTextBox   = chatLocked;
                }

                if (pe.fromPlayer != dmpSettings.playerName)
                {
                    privateMessages[pe.fromPlayer].Add(pe.fromPlayer + ": " + pe.message);

                    if (!display)
                    {
                        chatButtonHighlighted = true;
                        ScreenMessages.PostScreenMessage(pe.fromPlayer + " -> @" + pe.toPlayer + ": " + pe.message, 5f, ScreenMessageStyle.UPPER_LEFT);
                    }
                }
                else
                {
                    privateMessages[pe.toPlayer].Add(pe.fromPlayer + ": " + pe.message);
                }
            }
            //Handle console messages
            while (newConsoleMessages.Count > 0)
            {
                ConsoleEntry ce = newConsoleMessages.Dequeue();
                //Highlight if the channel isn't selected.
                if (selectedChannel != consoleIdentifier)
                {
                    if (!highlightChannel.Contains(consoleIdentifier))
                    {
                        highlightChannel.Add(consoleIdentifier);
                    }
                }

                //Move the bar to the bottom on a new message
                if (!string.IsNullOrEmpty(selectedChannel) && string.IsNullOrEmpty(selectedPMChannel) && consoleIdentifier == selectedChannel)
                {
                    chatScrollPos.y = float.PositiveInfinity;
                    selectTextBox   = chatLocked;
                }

                consoleMessages.Add(ce.message);
            }
            while (disconnectingPlayers.Count > 0)
            {
                string disconnectingPlayer = disconnectingPlayers.Dequeue();
                if (playerChannels.ContainsKey(disconnectingPlayer))
                {
                    playerChannels.Remove(disconnectingPlayer);
                }
                if (joinedPMChannels.Contains(disconnectingPlayer))
                {
                    joinedPMChannels.Remove(disconnectingPlayer);
                }
                if (highlightPM.Contains(disconnectingPlayer))
                {
                    highlightPM.Remove(disconnectingPlayer);
                }
                if (privateMessages.ContainsKey(disconnectingPlayer))
                {
                    privateMessages.Remove(disconnectingPlayer);
                }
            }
        }
Beispiel #2
0
 public void QueueSystemMessage(string message)
 {
     ConsoleEntry ce = new ConsoleEntry();
     ce.message = message;
     newConsoleMessages.Enqueue(ce);
 }
Beispiel #3
0
 private void HandleChatEvents()
 {
     //Handle leave event
     if (!leaveEventHandled)
     {
         if (selectedChannel != null && selectedChannel != consoleIdentifier)
         {
             using (MessageWriter mw = new MessageWriter())
             {
                 mw.Write <int>((int)ChatMessageType.LEAVE);
                 mw.Write <string>(Settings.fetch.playerName);
                 mw.Write <string>(selectedChannel);
                 NetworkWorker.fetch.SendChatMessage(mw.GetMessageBytes());
             }
             if (joinedChannels.Contains(selectedChannel))
             {
                 joinedChannels.Remove(selectedChannel);
             }
             selectedChannel   = null;
             selectedPMChannel = null;
         }
         if (selectedPMChannel != null)
         {
             if (joinedPMChannels.Contains(selectedPMChannel))
             {
                 joinedPMChannels.Remove(selectedPMChannel);
             }
             selectedChannel   = null;
             selectedPMChannel = null;
         }
         leaveEventHandled = true;
     }
     //Handle send event
     if (!sendEventHandled)
     {
         if (sendText != "")
         {
             HandleChatInput(sendText);
         }
         sendText         = "";
         sendEventHandled = true;
     }
     //Handle join messages
     while (newJoinMessages.Count > 0)
     {
         JoinLeaveMessage jlm = newJoinMessages.Dequeue();
         if (!playerChannels.ContainsKey(jlm.fromPlayer))
         {
             playerChannels.Add(jlm.fromPlayer, new List <string>());
         }
         if (!playerChannels[jlm.fromPlayer].Contains(jlm.channel))
         {
             playerChannels[jlm.fromPlayer].Add(jlm.channel);
         }
     }
     //Handle leave messages
     while (newLeaveMessages.Count > 0)
     {
         JoinLeaveMessage jlm = newLeaveMessages.Dequeue();
         if (playerChannels.ContainsKey(jlm.fromPlayer))
         {
             if (playerChannels[jlm.fromPlayer].Contains(jlm.channel))
             {
                 playerChannels[jlm.fromPlayer].Remove(jlm.channel);
             }
             if (playerChannels[jlm.fromPlayer].Count == 0)
             {
                 playerChannels.Remove(jlm.fromPlayer);
             }
         }
     }
     //Handle channel messages
     while (newChannelMessages.Count > 0)
     {
         ChannelEntry ce = newChannelMessages.Dequeue();
         if (!channelMessages.ContainsKey(ce.channel))
         {
             channelMessages.Add(ce.channel, new List <string>());
         }
         //Highlight if the channel isn't selected.
         if (selectedChannel != null && ce.channel == "" && ce.fromPlayer != consoleIdentifier)
         {
             if (!highlightChannel.Contains(ce.channel))
             {
                 highlightChannel.Add(ce.channel);
             }
         }
         if (ce.channel != selectedChannel && ce.channel != "")
         {
             if (!highlightChannel.Contains(ce.channel))
             {
                 highlightChannel.Add(ce.channel);
             }
         }
         //Move the bar to the bottom on a new message
         if (selectedChannel == null && selectedPMChannel == null && ce.channel == "")
         {
             chatScrollPos.y = float.PositiveInfinity;
             if (chatLocked)
             {
                 selectTextBox = true;
             }
         }
         if (selectedChannel != null && selectedPMChannel == null && ce.channel == selectedChannel)
         {
             chatScrollPos.y = float.PositiveInfinity;
             if (chatLocked)
             {
                 selectTextBox = true;
             }
         }
         channelMessages[ce.channel].Add(ce.fromPlayer + ": " + ce.message);
     }
     //Handle private messages
     while (newPrivateMessages.Count > 0)
     {
         PrivateEntry pe = newPrivateMessages.Dequeue();
         if (pe.fromPlayer != Settings.fetch.playerName)
         {
             if (!privateMessages.ContainsKey(pe.fromPlayer))
             {
                 privateMessages.Add(pe.fromPlayer, new List <string>());
             }
             //Highlight if the player isn't selected
             if (!joinedPMChannels.Contains(pe.fromPlayer))
             {
                 joinedPMChannels.Add(pe.fromPlayer);
             }
             if (selectedPMChannel != pe.fromPlayer)
             {
                 if (!highlightPM.Contains(pe.fromPlayer))
                 {
                     highlightPM.Add(pe.fromPlayer);
                 }
             }
         }
         if (!privateMessages.ContainsKey(pe.toPlayer))
         {
             privateMessages.Add(pe.toPlayer, new List <string>());
         }
         //Move the bar to the bottom on a new message
         if (selectedPMChannel != null && selectedChannel == null && (pe.fromPlayer == selectedPMChannel || pe.fromPlayer == Settings.fetch.playerName))
         {
             chatScrollPos.y = float.PositiveInfinity;
             if (chatLocked)
             {
                 selectTextBox = true;
             }
         }
         if (pe.fromPlayer != Settings.fetch.playerName)
         {
             privateMessages[pe.fromPlayer].Add(pe.fromPlayer + ": " + pe.message);
         }
         else
         {
             privateMessages[pe.toPlayer].Add(pe.fromPlayer + ": " + pe.message);
         }
     }
     //Handle console messages
     while (newConsoleMessages.Count > 0)
     {
         ConsoleEntry ce = newConsoleMessages.Dequeue();
         //Highlight if the channel isn't selected.
         if (selectedChannel != consoleIdentifier)
         {
             if (!highlightChannel.Contains(consoleIdentifier))
             {
                 highlightChannel.Add(consoleIdentifier);
             }
         }
         //Move the bar to the bottom on a new message
         if (selectedChannel != null && selectedPMChannel == null && consoleIdentifier == selectedChannel)
         {
             chatScrollPos.y = float.PositiveInfinity;
             if (chatLocked)
             {
                 selectTextBox = true;
             }
         }
         consoleMessages.Add(ce.message);
     }
     while (disconnectingPlayers.Count > 0)
     {
         string disconnectingPlayer = disconnectingPlayers.Dequeue();
         if (playerChannels.ContainsKey(disconnectingPlayer))
         {
             playerChannels.Remove(disconnectingPlayer);
         }
         if (joinedPMChannels.Contains(disconnectingPlayer))
         {
             joinedPMChannels.Remove(disconnectingPlayer);
         }
         if (highlightPM.Contains(disconnectingPlayer))
         {
             highlightPM.Remove(disconnectingPlayer);
         }
         if (privateMessages.ContainsKey(disconnectingPlayer))
         {
             privateMessages.Remove(disconnectingPlayer);
         }
     }
 }