public void PrintText(string text)
        {
            if (this.rtb.InvokeRequired)
            {
                this.rtb.BeginInvoke((MethodInvoker) delegate { PrintText(text); });
            }
            else
            {
                // bkcolour = config.CurrentConfig.HeaderBackColour;

                if (text == null)
                {
                    return;
                }

                //rtb.SelectionFont = new Font(textfont, textfontsize, fontst);
                ////rtb.SelectionBackColor = rtb.BackColor = bgcolour;

                if (text.Contains("secondlife:///"))
                {
                    if (!text.Contains("http://secondlife:///"))
                    {
                        text = instance.CleanReplace("secondlife:///", "http://secondlife:///", text);
                    }
                }

                if (text.Contains("secondlife://"))
                {
                    if (!text.Contains("http://secondlife://"))
                    {
                        text = instance.CleanReplace("secondlife://", "http://secondlife:///", text);
                    }
                }

                //rtb.Text += Environment.NewLine;

                AppendNStext(text + Environment.NewLine);

                rtb.SelectionFont = new Font(rtb.SelectionFont.Name, textfontsize, rtb.SelectionFont.Style);

                //rtb.AppendTextAsRtf(text, new Font(textfont, textfontsize, fontst));

                CheckBufferSize();

                int _findex = rtb.Text.Length - text.Length; // To be SAFE this has to be done after 'append' like this due to the buffer or we will get index out of range error when trying to replace

                PutSmiley(_findex);
            }
        }
        private void SendIM(string message)
        {
            if (message.Length == 0)
            {
                return;
            }

            message = message.TrimEnd();

            message = instance.CleanReplace("http://*****:*****@"[^a-zA-Z0-9]", "");
                //string[] swords = cword.Split(' ');
                string[] swords     = message.Split(' ');
                bool     hasmistake = false;
                bool     correct    = true;

                foreach (string word in swords)
                {
                    string cword = Regex.Replace(word, @"[^a-zA-Z0-9]", "");

                    try
                    {
                        correct = hunspell.Spell(cword);
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "Dictionary is not loaded")
                        {
                            instance.Config.ApplyCurrentConfig();
                            //correct = hunspell.Spell(cword);
                        }
                        else
                        {
                            Logger.Log("Spellcheck error Group IM: " + ex.Message, Helpers.LogLevel.Error);
                        }
                    }

                    if (!correct)
                    {
                        hasmistake = true;
                        break;
                    }
                }

                if (hasmistake)
                {
                    (new frmSpelling(instance, message, swords, true, target, session)).Show();

                    ClearIMInput();
                    hasmistake = false;
                    return;
                }
            }

            string message1 = string.Empty;
            string message2 = string.Empty;

            if (message.Length > 1023)
            {
                message1 = message.Substring(0, 1022);
                netcom.SendInstantMessageGroup(message1, target, session);

                if (message.Length > 2046)
                {
                    message2 = message.Substring(1023, 2045);
                    netcom.SendInstantMessageGroup(message2, target, session);
                }
            }
            else
            {
                netcom.SendInstantMessageGroup(message, target, session);;
            }

            this.ClearIMInput();
        }
Exemple #3
0
        private void LogMessage(DateTime timestamp, string uuid, string fromName, string msg, bool group, string groupname)
        {
            if (!instance.Config.CurrentConfig.SaveIMs)
            {
                return;
            }

            string folder = instance.Config.CurrentConfig.LogDir;

            if (!folder.EndsWith("\\", StringComparison.CurrentCultureIgnoreCase))
            {
                folder += "\\";
            }

            // Log the message
            string filename = string.Empty;

            if (group)
            {
                string cleangrpname = instance.RemoveReservedCharacters(groupname);

                filename = "IM-" + timestamp.Date.ToString() + "-" + client.Self.Name + "-GROUP-" + cleangrpname + ".txt";
            }
            else
            {
                filename = "IM-" + timestamp.Date.ToString() + "-" + client.Self.Name + "-" + sessionAVname + ".txt";
            }

            //filename = filename.Replace("/", "-");
            ////filename = filename.Replace(" ", "_");
            //filename = filename.Replace(":", "-");

            filename = instance.CleanReplace("/", "-", filename);    //filename.Replace("/", "-");
            //filename = filename.Replace(" ", "_");
            filename = instance.CleanReplace(":", "-", filename);    //filename.Replace(":", "-");

            string path = folder + filename;
            string line = "[" + timestamp.ToShortTimeString() + "] " + fromName + ": " + msg;

            bool exists = false;

            // Check if the file exists
            try
            {
                exists = File.Exists(@path);
            }
            catch
            {
                ;
            }

            if (exists)
            {
                StreamWriter SW = File.AppendText(@path);

                try
                {
                    SW.WriteLine(@line);
                    SW.Dispose();
                }
                catch
                {
                    SW.Dispose();
                }
            }
            else
            {
                StreamWriter SW = File.CreateText(@path);

                try
                {
                    SW.WriteLine(@line);
                    SW.Dispose();
                }
                catch
                {
                    //string exp = ex.Message;
                    SW.Dispose();
                }
            }
        }