private void AddTextRecieved(ChatLogEventArgs args)
        {
            var message = new ChatMessage
            {
                PrevSide = _curside,
                SenderName = args.Sender,
                Text = args.Message,
                Side = MessageSide.You
            };

            if (ChatSettings.IsTimestampingEnabled)
                message.Timestamp = args.Timestamp;

            ChatMessages.Add(message);
            _curside = MessageSide.You;
            if (ChatSettings.IsAutoScrollEnabled)
            {
                View.ScrollConversationToEnd();
            }

            try
            {
                if (!ChatSettings.IsNotificationsEnabled || ChatSettings.NotificationString == null) return;

                if (ChatSettings.NotificationWords.Any(s => message.Text.Contains(s)))
                {
                    ShowCustomBalloon($"{message.SenderName}: {message.Text}");
                }

                if (ChatSettings.IsFlashWindowNotificationEnabled)
                    Application.Current.MainWindow.FlashWindow();

                if (!ChatSettings.IsNotificationSoundFileEnabled || ChatSettings.NotificationSoundFile == null) return;
                    SoundManager.PlayFile(ChatSettings.NotificationSoundFile);
            }
            catch (Exception ex)
            {
                App.LogErrorMessage(ex);
            }
        }
        private static void SendMessageParts(byte[] byteData, MessageSide side, ulong receiver = 0)
        {
            EconomyScript.Instance.ServerLogger.WriteVerbose("SendMessageParts {0} {1} {2}.", byteData.Length, side, receiver);

            var byteList = byteData.ToList();

            while (byteList.Count > 0)
            {
                // we create an empty message part
                var messagePart = new MessageIncomingMessageParts()
                {
                    Side = side,
                    SenderSteamId = side == MessageSide.ServerSide ? MyAPIGateway.Session.Player.SteamUserId : MyAPIGateway.Multiplayer.ServerId, // The 'side' indicates where it's going to, so the SenderId is the reverse of that.
                    SenderDisplayName = side == MessageSide.ServerSide ? MyAPIGateway.Session.Player.DisplayName : "",
                    SenderLanguage = side == MessageSide.ServerSide ? (int)MyAPIGateway.Session.Config.Language : 0,
                    LastPart = false,
                };

                try
                {
                    // let's check how much we could store in the message
                    int freeBytes = GetFreeByteElementCount(messagePart);

                    int count = freeBytes;

                    // we check if that might be the last message
                    if (freeBytes > byteList.Count)
                    {
                        messagePart.LastPart = true;

                        // since we changed LastPart, we should make sure that we are still able to send all the stuff
                        if (GetFreeByteElementCount(messagePart) > byteList.Count)
                        {
                            count = byteList.Count;
                        }
                        else
                            throw new Exception("Failed to send message parts. The leftover could not be sent!");
                    }

                    // fill the message with content
                    messagePart.Content = byteList.GetRange(0, count).ToArray();
                    var xmlPart = MyAPIGateway.Utilities.SerializeToXML<MessageContainer>(new MessageContainer() { Content = messagePart });
                    var bytes = System.Text.Encoding.Unicode.GetBytes(xmlPart);

                    // and finally send the message
                    switch (side)
                    {
                        case MessageSide.ClientSide:
                            if (MyAPIGateway.Multiplayer.SendMessageTo(EconomyConsts.ConnectionId, bytes, receiver))
                                byteList.RemoveRange(0, count);
                            else
                                throw new Exception("Failed to send message parts to client.");
                            break;
                        case MessageSide.ServerSide:
                            if (MyAPIGateway.Multiplayer.SendMessageToServer(EconomyConsts.ConnectionId, bytes))
                                byteList.RemoveRange(0, count);
                            else
                                throw new Exception("Failed to send message parts to server.");
                            break;
                    }

                }
                catch (Exception ex)
                {
                    EconomyScript.Instance.ServerLogger.WriteException(ex);
                    EconomyScript.Instance.ClientLogger.WriteException(ex);
                    return;
                }
            }
        }
 private void AddTextSend(ChatLogEventArgs args)
 {
     var message = new ChatMessage { PrevSide = _curside };
     if (ChatSettings.IsCustomServerConsoleNameEnabled)
         message.SenderName = string.IsNullOrWhiteSpace(ChatSettings.CustomServerConsoleName) ? "Server Admin" : ChatSettings.CustomServerConsoleName;
     else
         message.SenderName = "Server Admin";
     message.Text = args.Message;
     message.Side = MessageSide.Me;
     if (ChatSettings.IsTimestampingEnabled)
         message.Timestamp = args.Timestamp;
     ChatMessages.Add(message);
     _curside = MessageSide.Me;
     if (ChatSettings.IsAutoScrollEnabled)
     {
         View.ScrollConversationToEnd();
     }
 }
        private void addTextRecieved(ChatLogEventArgs args)
        {
            var message = new ChatMessage();
            message.PrevSide = curside;
            message.SenderName = args.Sender;
            message.Text = args.Message;
            message.Side = MessageSide.You;

            if (ChatSettings.IsTimestampingEnabled)
                message.Timestamp = args.Timestamp;

            ChatMessages.Add(message);
            curside = MessageSide.You;
            if (ChatSettings.IsAutoScrollEnabled)
            {
                View.ScrollConversationToEnd();
            }
        }