Ejemplo n.º 1
0
 internal static void LoadCustom()
 {
     CustomTokens.Clear();
     if (File.Exists("text/custom$s.txt"))
     {
         using (CP437Reader r = new CP437Reader("text/custom$s.txt")) {
             string line;
             while ((line = r.ReadLine()) != null)
             {
                 if (line.StartsWith("//"))
                 {
                     continue;
                 }
                 string[] split = line.Split(new[] { ':' }, 2);
                 if (split.Length == 2 && !String.IsNullOrEmpty(split[0]))
                 {
                     CustomTokens.Add(split[0], split[1]);
                 }
             }
         }
     }
     else
     {
         Server.s.Log("custom$s.txt does not exist, creating");
         using (CP437Writer w = new CP437Writer("text/custom$s.txt")) {
             w.WriteLine("// This is used to create custom $s");
             w.WriteLine("// If you start the line with a // it wont be used");
             w.WriteLine("// It should be formatted like this:");
             w.WriteLine("// $website:http://example.org");
             w.WriteLine("// That would replace '$website' in any message to 'http://example.org'");
             w.WriteLine("// It must not start with a // and it must not have a space between the 2 sides and the colon (:)");
         }
     }
 }
Ejemplo n.º 2
0
        void Listener_OnPrivate(UserInfo user, string message)
        {
            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts   = message.SplitSpaces(2);
            string   cmdName = parts[0].ToLower();
            string   cmdArgs = parts.Length > 1 ? parts[1] : "";

            if (HandleWhoCommand(user.Nick, cmdName, false))
            {
                return;
            }
            Command.Search(ref cmdName, ref cmdArgs);

            string error;
            string chan = String.IsNullOrEmpty(channel) ? opchannel : channel;

            if (!CheckIRCCommand(user, cmdName, chan, out error))
            {
                if (error != null)
                {
                    Pm(user.Nick, error);
                }
                return;
            }
            HandleIRCCommand(user.Nick, user.Nick, cmdName, cmdArgs);
        }
Ejemplo n.º 3
0
        static void LoadBadWords()
        {
            if (!File.Exists("text/badwords.txt"))
            {
                // No file exists yet, so let's create one
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("# This file contains a list of bad words to remove via the profanity filter");
                sb.AppendLine("# Each bad word should be on a new line all by itself");
                File.WriteAllText("text/badwords.txt", sb.ToString());
            }

            List <string> lines = CP437Reader.ReadAllLines("text/badwords.txt");

            // Run the badwords through the reducer to ensure things like Ls become Is and everything is lowercase
            filters = new List <string>();
            foreach (string line in lines)
            {
                if (line.StartsWith("#") || line.Trim().Length == 0)
                {
                    continue;
                }
                string word = Reduce(line.ToLower());
                filters.Add(word);
            }
        }
Ejemplo n.º 4
0
 void LoginTimerElapsed(object sender, ElapsedEventArgs e)
 {
     if (!Loading)
     {
         loginTimer.Stop();
         if (File.Exists("text/welcome.txt"))
         {
             try {
                 List <string> welcome = CP437Reader.ReadAllLines("text/welcome.txt");
                 foreach (string w in welcome)
                 {
                     SendMessage(w);
                 }
             } catch {
             }
         }
         else
         {
             Server.s.Log("Could not find Welcome.txt. Using default.");
             CP437Writer.WriteAllText("text/welcome.txt", "Welcome to my server!");
             SendMessage("Welcome to my server!");
         }
         loginTimer.Dispose();
         extraTimer.Start();
     }
 }
Ejemplo n.º 5
0
        public static bool Read <T>(string path, ref T state, LineProcessor <T> processor,
                                    char separator = '=', bool trimValue = true)
        {
            if (!File.Exists(path))
            {
                return(false);
            }

            using (CP437Reader reader = new CP437Reader(path)) {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    int index = ParseLine(line, path, separator);
                    if (index == -1)
                    {
                        continue;
                    }

                    string key = line.Substring(0, index), value = line.Substring(index + 1);
                    if (trimValue)
                    {
                        value = value.Trim();
                    }

                    try {
                        processor(key.Trim(), value, ref state);
                    } catch (Exception ex) {
                        Server.ErrorLog(ex);
                        Server.s.Log("Line \"" + line + "\" in " + path + " caused an error");
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
 public static List<string> ReadAllLines(string file) {
     using (CP437Reader reader = new CP437Reader(file)) {
         List<string> lines = new List<string>();
         string line = null;
         
         while ((line = reader.ReadLine()) != null)
             lines.Add(line);
         return lines;
     }
 }
Ejemplo n.º 7
0
        public static List <string> GetInfectMessages(Player p)
        {
            if (p.name == null || !Directory.Exists("text/infect"))
            {
                return(null);
            }
            string path = InfectPath(p.name);

            return(File.Exists(path) ? CP437Reader.ReadAllLines(path) : null);
        }
Ejemplo n.º 8
0
        public static void InitAll()
        {
            List <string> lines = CP437Reader.ReadAllLines(filename);
            Group         grp   = null;

            PropertiesFile.Read(filename, ref grp, ParseProperty, '=', false);
            if (grp != null)
            {
                AddGroup(ref grp);
            }
        }
Ejemplo n.º 9
0
        public static List <string> ReadAllLines(string file)
        {
            using (CP437Reader reader = new CP437Reader(file)) {
                List <string> lines = new List <string>();
                string        line  = null;

                while ((line = reader.ReadLine()) != null)
                {
                    lines.Add(line);
                }
                return(lines);
            }
        }
Ejemplo n.º 10
0
        public static string GetLoginMessage(Player p)
        {
            if (!Directory.Exists("text/login"))
            {
                Directory.CreateDirectory("text/login");
            }
            string path = "text/login/" + p.name.ToLower() + ".txt";

            if (File.Exists(path))
            {
                return(CP437Reader.ReadAllText(path));
            }
            // Unix is case sensitive (older files used correct casing of name)
            path = "text/login/" + p.name + ".txt";
            return(File.Exists(path) ? CP437Reader.ReadAllText(path) : "joined the game.");
        }
Ejemplo n.º 11
0
        void Listener_OnPrivate(UserInfo user, string message)
        {
            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts  = message.Split(trimChars, 2);
            string   ircCmd = parts[0].ToLower();

            if (ircCmd == ".who" || ircCmd == ".players")
            {
                try {
                    CmdPlayers.DisplayPlayers(null, "", text => Pm(user.Nick, text), false, false);
                } catch (Exception e) {
                    Server.ErrorLog(e);
                }
                return;
            }

            string error;

            if (!CheckUserAndCommand(user, ircCmd, message, out error))
            {
                if (error != null)
                {
                    Pm(user.Nick, error);
                }
                return;
            }

            Command cmd = Command.all.Find(ircCmd);

            if (cmd != null)
            {
                Server.s.Log("IRC Command: /" + message + " (by " + user.Nick + ")");
                usedCmd = user.Nick;
                string args = parts.Length > 1 ? parts[1] : "";
                try {
                    cmd.Use(new Player("IRC"), args);
                } catch (Exception e) {
                    Pm(user.Nick, "CMD Error: " + e.ToString());
                }
                usedCmd = "";
            }
            else
            {
                Pm(user.Nick, "Unknown command!");
            }
        }
Ejemplo n.º 12
0
        /// <summary> Gives info about the ban of user, as a string array of
        /// {banned by, ban reason, date and time, previous rank, stealth},
        /// or null if no ban data was found. </summary>
        public static string[] GetBanData(string who)
        {
            who = who.ToLower();
            foreach (string line in File.ReadAllLines("text/bans.txt"))
            {
                string[] parts = line.Split(' ');
                if (parts.Length <= 5 || parts[1] != who)
                {
                    continue;
                }

                parts[2] = CP437Reader.ConvertToRaw(parts[2]).Replace("%20", " ");
                parts[4] = parts[4].Replace("%20", " ");
                return(new[] { parts[0], parts[2], parts[4], parts[5], parts[3] });
            }
            return(null);
        }
Ejemplo n.º 13
0
        void InitTimers()
        {
            updateTimer.Elapsed += delegate {
                Entities.GlobalUpdate();
                PlayerBot.GlobalUpdatePosition();
            };
            updateTimer.Start();

            if (File.Exists("text/messages.txt"))
            {
                messages = CP437Reader.ReadAllLines("text/messages.txt");
            }
            else
            {
                using (File.Create("text/messages.txt")) {}
            }
            Server.MainScheduler.QueueRepeat(RandomMessage, null, TimeSpan.FromMinutes(5));
        }
Ejemplo n.º 14
0
        public static string GetLogoutMessage(Player p)
        {
            if (p.name == null)
            {
                return("Disconnected");
            }
            if (!Directory.Exists("text/logout"))
            {
                Directory.CreateDirectory("text/logout");
            }
            string path = "text/logout/" + p.name.ToLower() + ".txt";

            if (File.Exists(path))
            {
                return(CP437Reader.ReadAllText(path));
            }

            path = "text/logout/" + p.name + ".txt";
            return(File.Exists(path) ? CP437Reader.ReadAllText(path) : "Disconnected");
        }
Ejemplo n.º 15
0
        void Listener_OnPublic(UserInfo user, string channel, string message)
        {
            message = message.TrimEnd();
            if (message.Length == 0)
            {
                return;
            }
            bool opchat = channel.CaselessEq(opchannel);

            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts  = message.SplitSpaces(3);
            string   ircCmd = parts[0].ToLower();

            string nick = opchat ? "#@private@#" : "#@public@#";

            if (HandleWhoCommand(nick, ircCmd, opchat))
            {
                return;
            }

            if (ircCmd == ".x" && !HandlePublicCommand(user, channel, message, parts, opchat))
            {
                return;
            }

            if (channel.CaselessEq(opchannel))
            {
                Server.s.Log(String.Format("(OPs): [IRC] {0}: {1}", user.Nick, message));
                Chat.MessageOps(String.Format("To Ops &f-%I[IRC] {0}&f- {1}", user.Nick,
                                              Server.profanityFilter ? ProfanityFilter.Parse(message) : message));
            }
            else
            {
                Server.s.Log(String.Format("[IRC] {0}: {1}", user.Nick, message));
                Player.GlobalIRCMessage(String.Format("%I[IRC] {0}: &f{1}", user.Nick,
                                                      Server.profanityFilter ? ProfanityFilter.Parse(message) : message));
            }
        }
Ejemplo n.º 16
0
 public static string ReadAllText(string file)
 {
     using (CP437Reader reader = new CP437Reader(file)) {
         return(reader.ReadToEnd());
     }
 }
Ejemplo n.º 17
0
        void Listener_OnPublic(UserInfo user, string channel, string message)
        {
            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts  = message.Split(trimChars, 3);
            string   ircCmd = parts[0].ToLower();

            if (ircCmd == ".who" || ircCmd == ".players")
            {
                try {
                    CmdPlayers.DisplayPlayers(null, "", text => Say(text, false, true), false, false);
                } catch (Exception e) {
                    Server.ErrorLog(e);
                }
            }

            if (ircCmd == ".x")
            {
                string cmdName = parts.Length > 1 ? parts[1].ToLower() : "";
                string error;
                if (!CheckUserAndCommand(user, cmdName, message, out error))
                {
                    if (error != null)
                    {
                        Server.IRC.Say(error);
                    }
                    return;
                }

                Command cmd = Command.all.Find(cmdName);
                if (cmdName != "" && cmd != null)
                {
                    Server.s.Log("IRC Command: /" + message.Replace(".x ", "") + " (by " + user.Nick + ")");
                    usedCmd = "";
                    string args = parts.Length > 2 ? parts[2] : "";
                    try {
                        cmd.Use(new Player("IRC"), args);
                    } catch (Exception e) {
                        Server.IRC.Say("CMD Error: " + e.ToString());
                    }
                    usedCmd = "";
                }
                else
                {
                    Server.IRC.Say("Unknown command!");
                }
            }

            if (String.IsNullOrEmpty(message.Trim()))
            {
                message = ".";
            }

            if (channel.CaselessEq(opchannel))
            {
                Server.s.Log(String.Format("(OPs): [IRC] {0}: {1}", user.Nick, message));
                Chat.GlobalMessageOps(String.Format("To Ops &f-%I[IRC] {0}&f- {1}", user.Nick, Server.profanityFilter ? ProfanityFilter.Parse(message) : message));
            }
            else
            {
                Server.s.Log(String.Format("[IRC] {0}: {1}", user.Nick, message));
                Player.GlobalIRCMessage(String.Format("%I[IRC] {0}: &f{1}", user.Nick, Server.profanityFilter ? ProfanityFilter.Parse(message) : message));
            }
        }
Ejemplo n.º 18
0
 public static string ReadAllText(string file) {
     using (CP437Reader reader = new CP437Reader(file)) {
         return reader.ReadToEnd();
     }
 }
Ejemplo n.º 19
0
        void Listener_OnPublic(UserInfo user, string channel, string message)
        {
            message = CP437Reader.ConvertToRaw(message);
            //string allowedchars = "1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./!@#$%^*()_+QWERTYUIOPASDFGHJKL:\"ZXCVBNM<>? ";
            //string msg = message;
            RemoveVariables(ref message);
            RemoveWhitespace(ref message);

            //if (message.Contains("^UGCS"))
            //{
            //    Server.UpdateGlobalSettings();
            //    return;
            //}
            if (message.Contains("^IPGET "))
            {
                Player[] players = PlayerInfo.Online.Items;
                foreach (Player p in players)
                {
                    if (p.name == message.Split(' ')[1])
                    {
                        if (Server.UseGlobalChat && IsConnected())
                        {
                            if (Player.IsLocalIpAddress(p.ip))
                            {
                                connection.Sender.PublicMessage(channel, "^IP " + p.name + ": " + Server.IP);
                                connection.Sender.PublicMessage(channel, "^PLAYER IS CONNECTING THROUGH A LOCAL IP.");
                            }
                            else
                            {
                                connection.Sender.PublicMessage(channel, "^IP " + p.name + ": " + p.ip);
                            }
                        }
                    }
                }
            }
            if (message.Contains("^SENDRULES "))
            {
                Player who = PlayerInfo.Find(message.Split(' ')[1]);
                if (who != null)
                {
                    Command.all.Find("gcrules").Use(who, "");
                }
            }
            if (message.Contains("^GETINFO "))
            {
                if (message.Split(' ')[1] == Server.GlobalChatNick())
                {
                    if (Server.UseGlobalChat && IsConnected())
                    {
                        connection.Sender.PublicMessage(channel, "^NAME: " + Server.name);
                        connection.Sender.PublicMessage(channel, "^MOTD: " + Server.motd);
                        connection.Sender.PublicMessage(channel, "^VERSION: " + Server.VersionString);
                        connection.Sender.PublicMessage(channel, "^URL: " + Server.URL);
                        connection.Sender.PublicMessage(channel, "^PLAYERS: " + PlayerInfo.Online.Count + "/" + Server.players);
                    }
                }
            }

            //for RoboDash's anti advertise/swear in #globalchat
            if (message.Contains("^ISASERVER "))
            {
                if (Server.GlobalChatNick() == message.Split(' ')[1])
                {
                    connection.Sender.PublicMessage(channel, "^IMASERVER");
                }
            }

            if (message.StartsWith("^"))
            {
                return;
            }

            message = message.MCCharFilter();

            if (String.IsNullOrEmpty(message))
            {
                return;
            }

            if (OnNewRecieveGlobalMessage != null)
            {
                OnNewRecieveGlobalMessage(user.Nick, message);
            }

            if (Server.Devs.CaselessContains(message.Split(':')[0]) && !message.StartsWith("[Dev]") && !message.StartsWith("[Developer]"))
            {
                message = "[Dev]" + message;
            }
            else if (Server.Mods.CaselessContains(message.Split(':')[0]) && !message.StartsWith("[Mod]") && !message.StartsWith("[Moderator]"))
            {
                message = "[Mod]" + message;
            }

            /*try {
             *  if(GUI.GuiEvent != null)
             *  GUI.GuiEvents.GlobalChatEvent(this, "> " + user.Nick + ": " + message); }
             * catch { Server.s.Log(">[Global] " + user.Nick + ": " + message); }*/
            Player.GlobalMessage(String.Format("%G>[Global] {0}: &f{1}", user.Nick, Server.profanityFilter ? ProfanityFilter.Parse(message) : message), true);
        }