public void QueueChannelMessage(string fromPlayer, string channelName, string channelMessage) { // Check if any of these is null before doing anything else if (!string.IsNullOrEmpty(fromPlayer) && !string.IsNullOrEmpty(channelMessage)) { ChannelEntry ce = new ChannelEntry(); ce.fromPlayer = fromPlayer; ce.channel = channelName; ce.message = channelMessage; newChannelMessages.Enqueue(ce); } }
public void QueueChannelMessage(string fromPlayer, string channelName, string channelMessage) { ChannelEntry ce = new ChannelEntry(); ce.fromPlayer = fromPlayer; ce.channel = channelName; ce.message = channelMessage; newChannelMessages.Enqueue(ce); if (!display) { chatButtonHighlighted = true; if (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); } } }
public void QueueChannelMessage(string fromPlayer, string channelName, string channelMessage) { ChannelEntry ce = new ChannelEntry(); ce.fromPlayer = fromPlayer; ce.channel = channelName; ce.message = channelMessage; newChannelMessages.Enqueue(ce); if (!display) { chatButtonHighlighted = true; if (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); } } }
public void QueueChannelMessage(string fromPlayer, string channelName, string channelMessage) { ChannelEntry ce = new ChannelEntry(); ce.fromPlayer = fromPlayer; ce.channel = channelName; ce.message = channelMessage; newChannelMessages.Enqueue(ce); }
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); } } }
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); } } }
private void Update() { safeDisplay = display; ignoreChatInput = false; if (chatButtonHighlighted && display) { chatButtonHighlighted = false; } if (chatLocked && !display) { chatLocked = false; InputLockManager.RemoveControlLock(DMP_CHAT_LOCK); } if (workerEnabled) { //Handle leave event if (!leaveEventHandled) { if (selectedChannel != null) { 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 != "") { if (!sendText.StartsWith("/") || sendText.StartsWith("//")) { if (sendText.StartsWith("//")) { sendText = sendText.Substring(1); } if (selectedChannel == null && selectedPMChannel == null) { //Sending a global chat message using (MessageWriter mw = new MessageWriter()) { mw.Write <int>((int)ChatMessageType.CHANNEL_MESSAGE); mw.Write <string>(Settings.fetch.playerName); //Global channel name is empty string. mw.Write <string>(""); mw.Write <string>(sendText); NetworkWorker.fetch.SendChatMessage(mw.GetMessageBytes()); } } if (selectedChannel != null) { using (MessageWriter mw = new MessageWriter()) { mw.Write <int>((int)ChatMessageType.CHANNEL_MESSAGE); mw.Write <string>(Settings.fetch.playerName); mw.Write <string>(selectedChannel); mw.Write <string>(sendText); NetworkWorker.fetch.SendChatMessage(mw.GetMessageBytes()); } } if (selectedPMChannel != null) { using (MessageWriter mw = new MessageWriter()) { mw.Write <int>((int)ChatMessageType.PRIVATE_MESSAGE); mw.Write <string>(Settings.fetch.playerName); mw.Write <string>(selectedPMChannel); mw.Write <string>(sendText); NetworkWorker.fetch.SendChatMessage(mw.GetMessageBytes()); } } } else { //Handle command if (sendText.StartsWith("/join ") && sendText.Length > 7) { string channelName = sendText.Substring(6); if (channelName != "" || channelName != "Global") { DarkLog.Debug("Joining channel " + channelName); joinedChannels.Add(channelName); selectedChannel = channelName; selectedPMChannel = null; using (MessageWriter mw = new MessageWriter()) { mw.Write <int>((int)ChatMessageType.JOIN); mw.Write <string>(Settings.fetch.playerName); mw.Write <string>(channelName); NetworkWorker.fetch.SendChatMessage(mw.GetMessageBytes()); } } else { ScreenMessages.PostScreenMessage("Couln't join '" + channelName + "', channel name not valid!", 5f, ScreenMessageStyle.UPPER_CENTER); } } if (sendText.StartsWith("/query ") && sendText.Length > 8) { string playerName = sendText.Substring(7); bool playerFound = false; if (playerName != consoleIdentifier) { foreach (PlayerStatus ps in PlayerStatusWorker.fetch.playerStatusList) { if (ps.playerName == playerName) { playerFound = true; } } } else { //Make sure we can always query the server. playerFound = true; } if (playerFound) { DarkLog.Debug("Starting query with " + playerName); joinedPMChannels.Add(playerName); selectedChannel = null; selectedPMChannel = playerName; } else { DarkLog.Debug("Couln't start query with '" + playerName + "', player not found!"); ScreenMessages.PostScreenMessage("Couln't start query with '" + playerName + "', player not found!", 5f, ScreenMessageStyle.UPPER_CENTER); } } if (sendText == "/part" || sendText == "/leave") { leaveEventHandled = false; } if (sendText == "/ping") { NetworkWorker.fetch.SendPingRequest(); } if (sendText == "/motd") { NetworkWorker.fetch.SendMotdRequest(); } } } 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 == "") { 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 (selectedChannel != null && selectedPMChannel == null && ce.channel == selectedChannel) { chatScrollPos.y = float.PositiveInfinity; } 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); } } } //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 (pe.fromPlayer != Settings.fetch.playerName) { privateMessages[pe.fromPlayer].Add(pe.fromPlayer + ": " + pe.message); } else { privateMessages[pe.toPlayer].Add(pe.fromPlayer + ": " + pe.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); } } } }
public void QueueChannelMessage(string fromPlayer, string channelName, string channelMessage) { // Check if any of these is null before doing anything else if (!string.IsNullOrEmpty(fromPlayer) && !string.IsNullOrEmpty(channelMessage)) { ChannelEntry ce = new ChannelEntry(); ce.fromPlayer = fromPlayer; ce.channel = channelName; ce.message = channelMessage; newChannelMessages.Enqueue(ce); } }