コード例 #1
0
ファイル: Database.cs プロジェクト: xuesong/ModernMUD
        /// <summary>
        /// Loads the ban file from disk.
        /// </summary>
        public static void LoadBans()
        {
            BanData ban;
            string  fileLocation      = FileLocation.SystemDirectory + FileLocation.BanFile;
            string  blankFileLocation = FileLocation.BlankSystemFileDirectory + FileLocation.BanFile;

            try
            {
                FileStream fp = null;
                try
                {
                    fp = File.OpenRead(fileLocation);
                }
                catch (FileNotFoundException)
                {
                    Log.Info("Ban file not found, using blank file.");
                    File.Copy(blankFileLocation, fileLocation);
                    fp = File.OpenRead(fileLocation);
                }
                StreamReader sr = new StreamReader(fp);
                while (!sr.EndOfStream)
                {
                    string name = sr.ReadLine();

                    if (name[0] == '$')
                    {
                        break;
                    }

                    ban      = new BanData();
                    ban.Name = name;
                    BanList.Add(ban);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception in Database.LoadBans(): " + ex);
            }
        }
コード例 #2
0
ファイル: Command.cs プロジェクト: ramseur/ModernMUD
        /// <summary>
        /// Immortal command to ban a site from the game.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="str"></param>
        public static void Ban(CharData ch, string[] str)
        {
            if( ch == null ) return;

            BanData ban;

            if (ch.IsNPC())
            {
                return;
            }

            CharData realChar = ch.GetChar();

            if (!realChar.Authorized("ban"))
            {
                return;
            }

            if (str.Length == 0)
            {
                string text = "Banned sites:\r\n";
                foreach (BanData it in Database.BanList)
                {
                    ban = it;
                    text += ban.Name;
                    text += "\r\n";
                }
                ch.SendText(text);
                return;
            }

            foreach (BanData it in Database.BanList)
            {
                ban = it;

                if (!MUDString.StringsNotEqual(str[0], ban.Name))
                {
                    ch.SendText("That site is already banned!\r\n");
                    return;
                }
            }

            ban = new BanData();

            ban.Name = str[0];
            Database.BanList.Add(ban);
            ch.SendText("Done.\r\n");
            Event.UpdateBans();
            return;
        }
コード例 #3
0
ファイル: Database.cs プロジェクト: ramseur/ModernMUD
        /// <summary>
        /// Loads the ban file from disk.
        /// </summary>
        public static void LoadBans()
        {
            BanData ban;
            string fileLocation = FileLocation.SystemDirectory + FileLocation.BanFile;
            string blankFileLocation = FileLocation.BlankSystemFileDirectory + FileLocation.BanFile;

            try
            {
                FileStream fp = null;
                try
                {
                    fp = File.OpenRead(fileLocation);
                }
                catch (FileNotFoundException)
                {
                    Log.Info("Ban file not found, using blank file.");
                    File.Copy(blankFileLocation, fileLocation);
                    fp = File.OpenRead(fileLocation);
                }
                StreamReader sr = new StreamReader(fp);
                while (!sr.EndOfStream)
                {
                    string name = sr.ReadLine();

                    if (name[0] == '$')
                        break;

                    ban = new BanData();
                    ban.Name = name;
                    BanList.Add(ban);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception in Database.LoadBans(): " + ex);
            }
        }