/// <summary>
        /// Process chat messages from the server
        /// </summary>
        public override void GetText(string text)
        {
            string message  = "";
            string username = "";

            text = GetVerbatim(text);

            if (IsPrivateMessage(text, ref message, ref username) || (Settings.Mailer_PublicInteractions && IsChatMessage(text, ref message, ref username)))
            {
                string usernameLower = username.ToLower();
                if (!ignoreList.Contains(usernameLower))
                {
                    string command = message.Split(' ')[0].ToLower();
                    switch (command)
                    {
                    case "mail":
                    case "tellonym":
                        if (usernameLower != GetUsername().ToLower() &&
                            mailDatabase.Count < Settings.Mailer_MaxDatabaseSize &&
                            mailDatabase.Where(mail => mail.SenderLowercase == usernameLower).Count() < Settings.Mailer_MaxMailsPerPlayer)
                        {
                            Queue <string> args = new Queue <string>(Command.getArgs(message));
                            if (args.Count >= 2)
                            {
                                bool   anonymous = (command == "tellonym");
                                string recipient = args.Dequeue();
                                message = string.Join(" ", args);

                                if (IsValidName(recipient))
                                {
                                    if (message.Length <= maxMessageLength)
                                    {
                                        Mail mail = new Mail(username, recipient, message, anonymous, DateTime.Now);
                                        LogToConsole("Saving message: " + mail.ToString());
                                        lock (readWriteLock)
                                        {
                                            mailDatabase.Add(mail);
                                            mailDatabase.SaveToFile(Settings.Mailer_DatabaseFile);
                                        }
                                        SendPrivateMessage(username, "信息已保存!");
                                    }
                                    else
                                    {
                                        SendPrivateMessage(username, "你的信息长度不能大于 " + maxMessageLength + " 字节.");
                                    }
                                }
                                else
                                {
                                    SendPrivateMessage(username, "'" + recipient + "' 不是一个有效的玩家名.");
                                }
                            }
                            else
                            {
                                SendPrivateMessage(username, "使用方法: " + command + " <玩家名> <信息>");
                            }
                        }
                        else
                        {
                            SendPrivateMessage(username, "数据库达到上线,无法保存!");
                        }
                        break;
                    }
                }
                else
                {
                    LogDebugToConsole(username + " 已经被忽略!");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Process chat messages from the server
        /// </summary>
        public override void GetText(string text)
        {
            string message  = "";
            string username = "";

            text = GetVerbatim(text);

            if (IsPrivateMessage(text, ref message, ref username) || (Settings.Mailer_PublicInteractions && IsChatMessage(text, ref message, ref username)))
            {
                string usernameLower = username.ToLower();
                if (!ignoreList.Contains(usernameLower))
                {
                    string command = message.Split(' ')[0].ToLower();
                    switch (command)
                    {
                    case "mail":
                    case "tellonym":
                        if (usernameLower != GetUsername().ToLower() &&
                            mailDatabase.Count < Settings.Mailer_MaxDatabaseSize &&
                            mailDatabase.Where(mail => mail.SenderLowercase == usernameLower).Count() < Settings.Mailer_MaxMailsPerPlayer)
                        {
                            Queue <string> args = new Queue <string>(Command.getArgs(message));
                            if (args.Count >= 2)
                            {
                                bool   anonymous = (command == "tellonym");
                                string recipient = args.Dequeue();
                                message = string.Join(" ", args);

                                if (IsValidName(recipient))
                                {
                                    if (message.Length <= maxMessageLength)
                                    {
                                        Mail mail = new Mail(username, recipient, message, anonymous, DateTime.Now);
                                        LogToConsoleTranslated("bot.mailer.saving", mail.ToString());
                                        lock (readWriteLock)
                                        {
                                            mailDatabase.Add(mail);
                                            mailDatabase.SaveToFile(Settings.Mailer_DatabaseFile);
                                        }
                                        SendPrivateMessage(username, "Message saved!");
                                    }
                                    else
                                    {
                                        SendPrivateMessage(username, "Your message cannot be longer than " + maxMessageLength + " characters.");
                                    }
                                }
                                else
                                {
                                    SendPrivateMessage(username, "Recipient '" + recipient + "' is not a valid player name.");
                                }
                            }
                            else
                            {
                                SendPrivateMessage(username, "Usage: " + command + " <recipient> <message>");
                            }
                        }
                        else
                        {
                            SendPrivateMessage(username, "Couldn't save Message. Limit reached!");
                        }
                        break;
                    }
                }
                else
                {
                    LogDebugToConsoleTranslated("bot.mailer.user_ignored", username);
                }
            }
        }