Ejemplo n.º 1
0
        private static bool LoadMessage()
        {
            string str = "";

            try
            {
                if (File.Exists(Path.Combine(_path, "message.txt")))
                {
                    using (StreamReader reader = new StreamReader(Path.Combine(_path, "message.txt")))
                    {
                        str = reader.ReadToEnd();
                        reader.Close();
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("MessageOfTheDay.cs", e);
            }
            finally
            {
                _msgCache = (str == "" ? DefaultBody : str);
            }

            return(!(_msgCache == DefaultBody));
        }
Ejemplo n.º 2
0
        private static Dictionary <string, uint> LoadRegionColors()
        {
            Dictionary <string, uint> table = new Dictionary <string, uint>();

            if (File.Exists(RegionColorDescriptor))
            {
                XmlDocument doc = new XmlDocument();
                XmlElement  root;

                try
                {
                    doc.Load(RegionColorDescriptor);
                    root = doc[DescriptorRootElementName];

                    table.Add("default", UInt32.Parse(root.GetAttribute("defaultColor"), NumberStyles.HexNumber));

                    foreach (XmlElement node in root.GetElementsByTagName(DescriptorChildTagName))
                    {
                        table.Add(node.GetAttribute("name"), UInt32.Parse(node.GetAttribute("color"), NumberStyles.HexNumber));
                    }
                }
                catch (Exception e)
                {
                    ExceptionManager.LogException("StatusServer", e);
                }
            }

            return(table);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Cleans up the instruction file and, optionally, the local copy of the uploaded file.
        /// </summary>
        private void CleanUp()
        {
            try
            {
                if (_ftpProc != null && !_ftpProc.HasExited)
                {
                    _ftpProc.Kill();
                }

                if (File.Exists(_instructionFile))
                {
                    File.Delete(_instructionFile);
                }

                _processLocked = false;

                if (_currentRequest.DeleteAfterUpload && File.Exists(_currentRequest.FileName))
                {
                    File.Delete(_currentRequest.FileName);
                }
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("FTPManager.CleanUp(): Unable to upload file \"" + _currentRequest.FileName + "\":\n", e);
            }

            ProcessQueue();
        }
Ejemplo n.º 4
0
        private static void HandleOnLogout(LogoutEventArgs args)
        {
            Mobile m = args.Mobile;

            try
            {
                StaticTile[] tiles  = m.Map.Tiles.GetStaticTiles(m.X, m.Y, true);
                NetState     state  = (NetState)m.NetState;
                int          tileID = 0;
                bool         safe   = false;

                int[] bedID = new int[]
                {
                    2651, 2653, 2654, 2656,
                    2659, 2660, 2662, 2663,
                    2665, 2666, 2682, 2684,
                    2688, 2690, 2692, 2696,
                    2702, 2704
                };

                foreach (Item item in m.GetItemsInRange(6))
                {
                    for (int i = 0; !safe && i < bedID.Length; i++)
                    {
                        for (int j = 0; !safe && j < tiles.Length; j++)
                        {
                            tileID = tiles[j].ID;

                            if (tiles[j].Z == m.Z)
                            {
                                safe = (tileID == bedID[i]) || (item.ItemID == bedID[i]);
                            }
                        }
                    }
                }

                if (safe)
                {
                    ((PlayerMobile)m).BedrollLogout = true;

                    if (state != null)
                    {
                        state.Dispose();
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("StartupSettings.cs", e);
            }
        }
        protected override void OnTick()
        {
            List <NetState>     users = new List <NetState>(NetState.Instances);
            Mobile              m;
            Region              reg;
            RegionWatcherObject obj;

            for (int i = 0; i < users.Count; i++)
            {
                reg = null;
                obj = null;

                m = users[i].Mobile;

                if (m == null || IgnoreMap(m.Map))
                {
                    continue;
                }

                reg = FindRegion(m.Location, m.Map);

                if (reg == null)
                {
                    continue;
                }

                _totalRegionChecks++;

                if (RegionCollected(reg, out obj))
                {
                    obj.Count++;
                }
                else
                {
                    obj = new RegionWatcherObject(reg.Name, reg.Map, 1);
                    _regions.Add(obj);
                }
            }

            CalculatePopularity();

            try
            {
                SortStats(_regions);
                SaveStats(_regions, _totalRegionChecks);
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("RegionPopularityWatcher", e);
            }
        }
        public static List <RegionWatcherObject> Load(bool autoStart)
        {
            RegionPopularityWatcher watcher = new RegionPopularityWatcher();

            watcher.Regions     = new List <RegionWatcherObject>();
            watcher.TotalChecks = 0;

            if (File.Exists(PersistancePath))
            {
                XmlDocument         doc = new XmlDocument();
                XmlElement          root;
                RegionWatcherObject obj;

                try
                {
                    doc.Load(PersistancePath);
                    root = doc[RootElementName];

                    watcher.TotalChecks = Convert.ToInt32(root.GetAttribute("totalChecks"));

                    foreach (XmlElement node in root.GetElementsByTagName(ChildElementName))
                    {
                        obj                   = new RegionWatcherObject(node["name"].InnerText, Util.GetMapByName(node["map"].InnerText));
                        obj.Count             = Convert.ToInt32(node["count"].InnerText);
                        obj.PopularityPercent = Convert.ToInt32(node["popularityPercentage"].InnerText);

                        if (IgnoreMap(obj.Map))
                        {
                            watcher.TotalChecks -= obj.Count;
                        }
                        else
                        {
                            watcher.Regions.Add(obj);
                        }
                    }
                }
                catch (Exception e)
                {
                    ExceptionManager.LogException("RegionPopularityWatcher", e);
                }
            }

            SortStats(watcher.Regions);

            if (autoStart)
            {
                watcher.Start();
            }

            return(watcher.Regions);
        }
Ejemplo n.º 7
0
        private static void ReloadMotD()
        {
            bool showMsg = true;

            _mutex.WaitOne();

            try
            {
                showMsg = LoadMessage();
                RetrieveArchives();
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("MessageOfTheDay.cs", e);
            }
            finally
            {
                _mutex.ReleaseMutex();
            }

            Account acct;

            foreach (Mobile m in World.Mobiles.Values)
            {
                if (m == null || !(m is PlayerMobile))
                {
                    continue;
                }
                else if ((acct = ((Account)m.Account)) == null)
                {
                    continue;
                }

                if (acct.GetTag("MotD") != null)
                {
                    acct.RemoveTag("MotD");
                }

                acct.SetTag("MotD", showMsg.ToString());
            }

            World.Broadcast(0x482, false, "Notice: the message of the day has been updated. Type \"[MotD\" to view this message.");
        }
Ejemplo n.º 8
0
        private static void ArchiveMotD()
        {
            bool showMsg = true;

            _mutex.WaitOne();

            try
            {
                PerformArchive();
                showMsg = LoadMessage();
                RetrieveArchives();
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("MessageOfTheDay.cs", e);
            }
            finally
            {
                _mutex.ReleaseMutex();
            }

            Account acct;

            foreach (Mobile m in World.Mobiles.Values)
            {
                if (m == null || !(m is PlayerMobile))
                {
                    continue;
                }
                else if ((acct = ((Account)m.Account)) == null)
                {
                    continue;
                }

                if (acct.GetTag("MotD") != null)
                {
                    acct.RemoveTag("MotD");
                }

                acct.SetTag("MotD", showMsg.ToString());
            }
        }
Ejemplo n.º 9
0
        public static void Initialize()
        {
            try
            {
                if (!Directory.Exists(_archives))
                {
                    Directory.CreateDirectory(_archives);
                }

                LoadMessage();
                RetrieveArchives();
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("MessageOfTheDay.cs", e);
            }

            EventSink.Login += new LoginEventHandler(OnLogin);
            CommandSystem.Register("MotD", AccessLevel.Player, new CommandEventHandler(MOTD_OnCommand));
        }
Ejemplo n.º 10
0
        private static void SendGump(Mobile m)
        {
            MessageOfTheDay gump = null;

            _mutex.WaitOne();

            try
            {
                int size = _archiveNameCache.Length >= _maxArchives ? _maxArchives : _archiveNameCache.Length;

                gump = new MessageOfTheDay(m, _msgCache, _archiveNameCache, size);
            }
            catch (Exception e)
            {
                ExceptionManager.LogException("MessageOfTheDay.cs", e);
            }
            finally
            {
                _mutex.ReleaseMutex();
            }

            if (gump != null && (Account)m.Account != null)
            {
                Account acct = (Account)m.Account;

                gump.BuildGump();
                m.SendGump(gump);

                if (acct.GetTag("MotD") != null)
                {
                    acct.RemoveTag("MotD");
                }

                acct.SetTag("MotD", "false");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Uploads the specified file to the shard website
        /// </summary>
        /// <param name="fileName">the absolute or relative path of the file to be uploaded</param>
        /// <param name="uploadPath">the relative path on the web server to upload the file to</param>
        /// <param name="asciiFormat">if true, upload in ASCII format; if false, upload in binary format</param>
        /// <param name="deleteAfterUpload">if true, deletes the given file after uploading</param>
        public void UploadFile(string fileName, string uploadPath, bool asciiFormat, bool deleteAfterUpload)
        {
            if (!CollectRegistrySettings(out _ftpHost, out _ftpUsername, out _ftpPassword))
            {
                ExceptionManager.LogException("FTPManager", new Exception("Unable to collect the necessary registry settings to upload " + fileName));
            }
            else if (!File.Exists(fileName))
            {
                ExceptionManager.LogException("FTPManager", new FileNotFoundException("The specified file was not found.", fileName));
            }
            else
            {
                _currentRequest  = new UploadRequest(fileName, uploadPath, asciiFormat, deleteAfterUpload);
                _instructionFile = DateTime.Now.Ticks.ToString() + ".ftp";

                if (_processLocked || File.Exists(_instructionFile))
                {
                    _requestQueue.Enqueue(_currentRequest);
                }
                else
                {
                    try
                    {
                        using (StreamWriter writer = new StreamWriter(_instructionFile))
                        {
                            writer.AutoFlush = true;

                            writer.WriteLine("open {0}", _ftpHost);
                            writer.WriteLine(_ftpUsername);
                            writer.WriteLine(_ftpPassword);
                            writer.WriteLine("cd {0}", _currentRequest.UploadPath);
                            writer.WriteLine(_currentRequest.ASCIIFormat ? "ascii" : "binary");
                            writer.WriteLine("put \"{0}\"", _currentRequest.FileName);
                            writer.WriteLine("close");
                            writer.Write("quit");

                            writer.Close();
                        }

                        _timeoutDelay = (IsArchivePackage(fileName) ? 180 : 60);

                        _ftpProc = new Process();
                        _ftpProc.EnableRaisingEvents = true;
                        _ftpProc.Exited               += new EventHandler(delegate(object sender, EventArgs args) { CleanUp(); });
                        _ftpProc.StartInfo             = new ProcessStartInfo("ftp", String.Format("-v -i -s:\"{0}\"", _instructionFile));
                        _ftpProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                        _processLocked = true;
                        _ftpProc.Start();

                        int elapsedTime = 0;
                        while (_processLocked)
                        {
                            elapsedTime += 100;

                            if (elapsedTime >= (_timeoutDelay * 1000))
                            {
                                CleanUp();
                                break;
                            }

                            Thread.Sleep(100);
                        }
                    }
                    catch (IOException ioe)
                    {
                        ExceptionManager.LogException("FTPManager.UploadFile(): Unable to upload file \"" + fileName + "\":\n", ioe);
                        CleanUp();
                    }
                    catch (Exception e)
                    {
                        ExceptionManager.LogException("FTPManager.UploadFile(): Unable to upload file \"" + fileName + "\":\n", e);
                        CleanUp();
                    }
                }
            }
        }
Ejemplo n.º 12
0
 private static void InitialThread()
 {
     try { DoCommand(Console.ReadLine(), true); }
     catch (Exception e) { ExceptionManager.LogException("ConsoleControl.cs", e); }
 }