Пример #1
0
 public void ChatMessageTest_Constructor_NullParams()
 {
     var msg = new ChatMessageEntity(new DateTime(), null, null, null);
     Assert.AreEqual(msg.Speaker, "");
     Assert.AreEqual(msg.Text, "");
     Assert.AreEqual(msg.MessageTimeStamp, new DateTime());
 }
Пример #2
0
 public void ChatMessageTest_Constructor_Default()
 {
     var msg = new ChatMessageEntity();
     Assert.AreEqual(msg.Speaker, "");
     Assert.AreEqual(msg.Text, "");
     Assert.AreEqual(msg.MessageTimeStamp, new DateTime());
 }
Пример #3
0
        public static ChatMessageEntity CleanPlayerTargets(ChatMessageEntity input)
        {
            var targets = input.MessageType;
            if (!targets.Contains("squad"))
            {
                return input;
            }
            //Extract the single digit squad id after the word squad.
            var teamId = targets.Substring(5, 1);
            //Extract the squad id (from teamId to end of string).
            var squadId = targets.Substring(6);

            input.MessageType = String.Format("team{0}squad{1}", teamId, squadId);
            return input;
        }
Пример #4
0
 /// <summary>
 ///     Constructs a new ChatEventArgs object with a predefined ChatMessage
 /// </summary>
 /// <param name="msg">ChatMessage to pass along</param>
 public ChatEventArgs(ChatMessageEntity msg)
 {
     ServerMessage = msg;
 }
Пример #5
0
 public void ChatMessageTest_ToString()
 {
     var msg = new ChatMessageEntity(new DateTime(2012, 12, 11, 10, 9, 8), "TestSpeaker", "This is a test string", "all");
     Assert.AreEqual(msg.ToString(), "[12/11/2012 10:09:08 AM] [all] TestSpeaker: This is a test string");
 }
Пример #6
0
 /// <summary>
 /// Enqueues a message into both Table Store and the current cached queue
 /// </summary>
 /// <param name="msg"></param>
 private void EnqueueMessage(ChatMessageEntity msg)
 {
     try
     {
         var insertOp = TableOperation.Insert(msg);
         MessageTable.Execute(insertOp);
         MessageQueue.Enqueue(msg);
         if (MessageQueue.Count > 100)
         {
             MessageQueue.Dequeue();
         }
     }
     catch (Exception e)
     {
         LogUtility.Log(GetType().Name, MethodBase.GetCurrentMethod().Name, e.Message);
     }
 }
Пример #7
0
        // Implements ICore
        public void MessageHandler(object sender, Dictionary<string, string> packet)
        {
            // Filter for server messages here - do not want the spam
            if (packet != null)
            {
                ChatMessageEntity msg = new ChatMessageEntity(DateTime.UtcNow, packet["source soldier name"], packet["text"], packet["target players"]);
                msg = ChatMessageCleaner.CleanPlayerTargets(msg);
                if (msg.Speaker == "Server")
                {
                    if (ServerMessages.ContainsKey(msg.Text))
                    {
                        DateTime lastShown = ServerMessages[msg.Text];
                        DateTime now = DateTime.UtcNow;
                        TimeSpan ts = now - lastShown;
                        double diff = ts.TotalMinutes;

                        if (diff > 30)
                        {
                            // Message needs to be displayed again
                            EnqueueMessage(msg);

                            // Timestamp in Dictionary also needs to be updated
                            ServerMessages[msg.Text] = now;
                        }
                    }
                    else
                    {
                        // Message needs to be displayed, as it has not been seen
                        EnqueueMessage(msg);

                        // Also need to add it to the Dictionary
                        DateTime now = DateTime.UtcNow;
                        ServerMessages.Add(msg.Text, now);
                    }
                }
                else
                {
                    EnqueueMessage(msg);
                }
            }
        }