示例#1
0
        private static void CMInvoke()
        {
            if (VoteSites.Count != 0)
            {
                return;
            }

            var sites = new List <IVoteSite>();

            SiteTypes.ForEach(
                type =>
            {
                var site = type.CreateInstanceSafe <IVoteSite>();

                if (site == null)
                {
                    return;
                }

                if (site.Name == "Vita-Nex")
                {
                    site.Enabled = true;
                }

                sites.Add(site);
                CMOptions.ToConsole(
                    "Created site ({0}) '{1}', '{2}'", site.GetType().Name, site.Name, site.Enabled ? "Enabled" : "Disabled");
            });

            sites.ForEach(s => VoteSites.AddOrReplace(s.UID, s));

            InternalSiteSort();
        }
示例#2
0
        private static void EquipItem6017(NetState state, PacketReader reader, ref byte[] buffer, ref int length)
        {
            var pos = reader.Seek(0, SeekOrigin.Current);

            reader.Seek(1, SeekOrigin.Begin);

            var item = World.FindItem(reader.ReadInt32());

            reader.Seek(pos, SeekOrigin.Begin);

            if (EquipItemParent6017 != null)
            {
                EquipItemParent6017(state, reader, ref buffer, ref length);
            }

            if (!CMOptions.ModuleEnabled || item == null || item.Deleted || !item.Layer.IsEquip())
            {
                return;
            }

            if (CMOptions.ModuleDebug)
            {
                CMOptions.ToConsole("EquipItem6017: {0} equiped {1}", state.Mobile, item);
            }

            Timer.DelayCall(Invalidate, state.Mobile);
        }
示例#3
0
        public static void LoadProfiles()
        {
            DataStoreResult result = Profiles.Import();

            CMOptions.ToConsole("Result: {0}", result.ToString());

            switch (result)
            {
            case DataStoreResult.Null:
            case DataStoreResult.Busy:
            case DataStoreResult.Error:
            {
                if (Profiles.HasErrors)
                {
                    CMOptions.ToConsole("Profiles database has errors...");

                    Profiles.Errors.ForEach(CMOptions.ToConsole);
                }
            }
            break;

            case DataStoreResult.OK:
            {
                CMOptions.ToConsole("Profile count: {0:#,0}", Profiles.Count);
                CMOptions.ToConsole("State count: {0:#,0}", Profiles.Values.Sum(p => p.Count));
            }
            break;
            }
        }
        public static void LoadHueRegistry()
        {
            DataStoreResult result = HueRegistry.Import();

            CMOptions.ToConsole("Result: {0}", result.ToString());

            switch (result)
            {
            case DataStoreResult.Null:
            case DataStoreResult.Busy:
            case DataStoreResult.Error:
            {
                if (HueRegistry.HasErrors)
                {
                    CMOptions.ToConsole("Hues database has errors...");

                    HueRegistry.Errors.ForEach(CMOptions.ToConsole);
                }
            }
            break;

            case DataStoreResult.OK:
                CMOptions.ToConsole("Hues count: {0:#,0}", HueRegistry.Count);
                break;
            }
        }
示例#5
0
        public static void SaveConquestRegistry()
        {
            DataStoreResult result = ConquestRegistry.Export();

            CMOptions.ToConsole("Result: {0}", result.ToString());

            switch (result)
            {
            case DataStoreResult.Null:
            case DataStoreResult.Busy:
            case DataStoreResult.Error:
            {
                if (ConquestRegistry.HasErrors)
                {
                    CMOptions.ToConsole("Conquest database has errors...");

                    ConquestRegistry.Errors.ForEach(CMOptions.ToConsole);
                }
            }
            break;

            case DataStoreResult.OK:
                CMOptions.ToConsole("Conquest count: {0:#,0}", ConquestRegistry.Count);
                break;
            }
        }
示例#6
0
        public static void SaveSeasons()
        {
            DataStoreResult result = Seasons.Export();

            CMOptions.ToConsole("Result: {0}", result.ToString());

            switch (result)
            {
            case DataStoreResult.Null:
            case DataStoreResult.Busy:
            case DataStoreResult.Error:
            {
                if (Seasons.HasErrors)
                {
                    CMOptions.ToConsole("Seasons database has errors...");

                    Seasons.Errors.ForEach(CMOptions.ToConsole);
                }
            }
            break;

            case DataStoreResult.OK:
                CMOptions.ToConsole("Season count: {0:#,0}", Seasons.Count);
                break;
            }
        }
示例#7
0
        private static void HandleHttpRequest(WebSocketsClient client, Dictionary <string, string> headers)
        {
            //var uri = headers["GET"];
            //var origin = headers["Origin"];

            var key = client.ResolveKey(headers["Sec-WebSocket-Key"]);

            var answer = Convert.ToBase64String(Encoding.ASCII.GetBytes(key.Value));

            var sendHeaders = new List <string>
            {
                "HTTP/1.1 101 Switching Protocols",  //
                "Connection: Upgrade",               //
                "Sec-WebSocket-Accept: " + answer,   //
                "Upgrade: websocket"                 //
            };

            Send(client, String.Join("\r\n", sendHeaders) + "\r\n\r\n", false, false, (c, d) => client.Start());

            if (!CMOptions.ModuleDebug)
            {
                return;
            }

            CMOptions.ToConsole("HEADERS>>>\n");
            CMOptions.ToConsole(sendHeaders.ToArray());
        }
示例#8
0
        private static void Connected(WebSocketsClient client)
        {
            lock (Clients)
            {
                if (!Clients.Contains(client))
                {
                    Clients.Add(client);
                }
            }

            CMOptions.ToConsole("[{0}] Client connected: {1}", Clients.Count, client.Address);

            if (OnConnected != null)
            {
                VitaNexCore.TryCatch(
                    () => OnConnected(client),
                    e =>
                {
                    CMOptions.ToConsole(e);

                    client.Dispose();
                    Disconnected(client);
                });
            }
        }
示例#9
0
        private static void CastBarRequestHandler(CastBarRequestEventArgs e)
        {
            if (!CMOptions.ModuleEnabled || e.User == null || !e.User.IsOnline() || e.Gump != null)
            {
                return;
            }

            SpellCastBar cb;

            if (!Instances.TryGetValue(e.User, out cb) || cb.IsDisposed)
            {
                Instances[e.User] = cb = new SpellCastBar(e.User, e.Location.X, e.Location.Y);
            }
            else
            {
                cb.X = e.Location.X;
                cb.Y = e.Location.Y;
            }

            cb.Preview = false;

            e.Gump = cb;

            if (CMOptions.ModuleDebug)
            {
                CMOptions.ToConsole(
                    "Request: {0} casting {1}, using {2} ({3}) at {4}",
                    e.User,
                    e.User.Spell,
                    cb,
                    cb.Preview ? "Prv" : "Std",
                    e.Location);
            }
        }
示例#10
0
        public static void Invalidate(Mobile owner, Item item)
        {
            if (!CMOptions.ModuleEnabled || owner == null || item == null || item.Deleted || !item.Layer.IsEquip())
            {
                return;
            }

            if (!CMOptions.ModuleDebug)
            {
                foreach (var set in FindSetsFor(item))
                {
                    set.Invalidate(owner, item);
                }
            }
            else
            {
                var sets = GetSetsFor(item);

                CMOptions.ToConsole("Found {0} sets for '{1}'", sets.Count, item);

                if (sets.Count > 0)
                {
                    CMOptions.ToConsole("'{0}'", String.Join("', '", sets.Select(s => s.Name)));

                    sets.ForEach(set => set.Invalidate(owner, item));
                }

                sets.Free(true);
            }
        }
示例#11
0
        private static void CMLoad()
        {
            DataStoreResult result = Profiles.Import();

            CMOptions.ToConsole("Result: {0}", result.ToString());

            switch (result)
            {
            case DataStoreResult.Null:
            case DataStoreResult.Busy:
            case DataStoreResult.Error:
            {
                if (Profiles.HasErrors)
                {
                    CMOptions.ToConsole("Profiles database has errors...");

                    Profiles.Errors.ForEach(e => e.ToConsole(CMOptions.ModuleQuietMode, CMOptions.ModuleDebug));
                }
            }
            break;

            case DataStoreResult.OK:
                CMOptions.ToConsole("Profile count: {0:#,0}", Profiles.Count);
                break;
            }

            Sync();
        }
示例#12
0
        public static void Sync()
        {
            VitaNexCore.TryCatch(
                () =>
            {
                int added = 0;

                foreach (var t in TypeOfEquipmentSet.GetConstructableChildren())
                {
                    Sets.AddOrReplace(
                        t,
                        set =>
                    {
                        if (set == null)
                        {
                            set = t.CreateInstanceSafe <EquipmentSet>();

                            if (set != null)
                            {
                                ++added;
                            }
                        }

                        return(set);
                    });
                }

                if (added > 0)
                {
                    CMOptions.ToConsole("{0:#,0} new sets added.", added);
                }
            },
                CMOptions.ToConsole);
        }
        void Test2()
        {
            var map = new List <(string Key, string Value)>();

            map.Add(("V", "VA"));
            map.Add(("V", "VO"));

            var matcher = new ConfusableMatcher(map, null);
            var res     = matcher.IndexOf("VV", "VAVOVAVO", CMOptions.Default);

            AssertNoMatch(res);
            res = matcher.IndexOf("VAVOVAVO", "VV", CMOptions.Default);
            AssertMatchMulti(res, new[] { 0, 0 }, new[] { 3, 4 });
            CMOptions opts = CMOptions.Default;

            opts.StartIndex = 4;
            res             = matcher.IndexOf("VAVOVAVO", "VV", opts);
            AssertMatchMulti(res, new[] { 4, 4 }, new[] { 3, 4 });
            opts.StartIndex = 2;
            res             = matcher.IndexOf("VAVOVAVO", "VV", opts);
            AssertMatchMulti(res, new[] { 2, 2 }, new[] { 3, 4 });
            opts.StartIndex = 3;
            res             = matcher.IndexOf("VAVOVAVO", "VV", opts);
            AssertMatchMulti(res, new[] { 4, 4 }, new[] { 3, 4 });
        }
示例#14
0
        private static void OnAbort()
        {
            ExportQueue.Clear();

            if (ExportThread != null)
            {
                if (ExportThread.IsAlive || ExportThread.ThreadState == ThreadState.Running)
                {
                    ExportThread.Abort();
                    ExportThread.Join(3000);
                }

                ExportThread = null;
            }

            if (_Connection != null && _Connection.Connected)
            {
                _Connection.Close();
                _Connection = null;
            }

            CMOptions.ToConsole("Update aborted.");

            _Updating = false;
        }
示例#15
0
        private static void OnSpellRequest(CastSpellRequestEventArgs e)
        {
            if (!CMOptions.ModuleEnabled)
            {
                return;
            }

            var user = e.Mobile as PlayerMobile;

            if (user == null)
            {
                return;
            }

            var o = EnsureState(user);

            if (o != null && o.Enabled)
            {
                if (CMOptions.ModuleDebug)
                {
                    CMOptions.ToConsole("{0} casting {1} ({2})", user, e.SpellID, user.Spell);
                }

                if (user.Spell != null && SpellRegistry.GetRegistryNumber(user.Spell) == e.SpellID)
                {
                    SendCastBarGump(user);
                }
                else
                {
                    _CastBarQueue.Enqueue(user);
                }
            }
        }
示例#16
0
文件: WebStats.cs 项目: LordEnigma/UO
        private static void ListenAsync()
        {
            AcquireListener();

            if (Listener == null)
            {
                return;
            }

            VitaNexCore.TryCatch(
                () => Listener.BeginAcceptTcpClient(
                    r =>
            {
                var client = VitaNexCore.TryCatchGet(() => Listener.EndAcceptTcpClient(r), CMOptions.ToConsole);

                ListenAsync();

                if (client != null && client.Connected)
                {
                    VitaNexCore.TryCatch(() => Connected(client), CMOptions.ToConsole);
                }
            },
                    null),
                e =>
            {
                _Listening = false;
                CMOptions.ToConsole(e);
            });
        }
示例#17
0
文件: WebStats.cs 项目: LordEnigma/UO
        public static void Connected(WebStatsClient client)
        {
            lock (Clients)
            {
                if (!Clients.Contains(client))
                {
                    Clients.Add(client);
                }
            }

            CMOptions.ToConsole("[{0}] Client connected: {1}", Clients.Count, client.Client.Client.RemoteEndPoint);

            if (OnConnected != null)
            {
                VitaNexCore.TryCatch(
                    () => OnConnected(client),
                    e =>
                {
                    lock (Clients)
                    {
                        Clients.Remove(client);
                    }

                    CMOptions.ToConsole(e);
                });
            }
        }
示例#18
0
        private static void Update()
        {
            if (ActionsToExport.Count > 0 && PlayersToExport.Count > 0 && HandsToExport.Count > 0)
            {
                if (ExportThread != null)
                {
                    if (ExportThread.IsAlive || ExportThread.ThreadState == ThreadState.Running)
                    {
                        ExportThread.Abort();
                        ExportThread.Join(3000);
                    }

                    ExportThread = null;
                }

                VitaNexCore.TryCatch <Action>(
                    ConnectAsync,
                    () =>
                {
                    ExportThread = new Thread(UpdateCallback)
                    {
                        Name     = CMOptions.ModuleName,
                        Priority = ThreadPriority.BelowNormal
                    };

                    ExportThread.Start();
                },
                    x =>
                {
                    CMOptions.ToConsole(x);
                    Cancel();
                });
            }
        }
示例#19
0
        public static void LoadBattles()
        {
            DataStoreResult result = Battles.Import();

            CMOptions.ToConsole("Result: {0}", result.ToString());

            switch (result)
            {
            case DataStoreResult.Null:
            case DataStoreResult.Busy:
            case DataStoreResult.Error:
            {
                if (Battles.HasErrors)
                {
                    CMOptions.ToConsole("Battles database has errors...");

                    Battles.Errors.ForEach(CMOptions.ToConsole);
                }
            }
            break;

            case DataStoreResult.OK:
                CMOptions.ToConsole("Battle count: {0:#,0}", Battles.Count);
                break;
            }
        }
示例#20
0
        public static void SaveProfiles()
        {
            var result = Profiles.Export();

            CMOptions.ToConsole("Result: {0}", result.ToString());

            switch (result)
            {
            case DataStoreResult.Null:
            case DataStoreResult.Busy:
            case DataStoreResult.Error:
            {
                if (Profiles.HasErrors)
                {
                    CMOptions.ToConsole("Profiles database has errors...");

                    Profiles.Errors.ForEach(CMOptions.ToConsole);
                }
            }
            break;

            case DataStoreResult.OK:
                CMOptions.ToConsole("Profile count: {0:#,0}", Profiles.Count);
                break;
            }
        }
示例#21
0
        private static void CMSave()
        {
            Messages.Import();
            var result = Messages.Export();

            CMOptions.ToConsole("{0} messages saved, {1}.", Messages.Count > 0 ? Messages.Count.ToString("#,#") : "0", result);
        }
示例#22
0
        private static void CMLoad()
        {
            var result = Registry.Import();

            CMOptions.ToConsole("{0} entries loaded, {1}.", Registry.Count > 0 ? Registry.Count.ToString("#,#") : "0", result);

            SpawnBraziers();
        }
示例#23
0
        private static void CMLoad()
        {
            DataStoreResult result = Sets.Import();

            CMOptions.ToConsole("{0:#,0} sets loaded, {1}.", Sets.Count, result);

            Sync();
        }
示例#24
0
        private static void CMInvoke()
        {
            PvPBattle.Bind();
            BattleNotoriety.Enable();

            var scenarios = new List <PvPScenario>();

            foreach (var type in BattleTypes.Where(t => t != null))
            {
                VitaNexCore.TryCatch(
                    () =>
                {
                    var battle = type.CreateInstanceSafe <PvPBattle>();

                    if (battle == null)
                    {
                        throw new Exception("PvPBattle Type could not be constructed, requires a constructor with 0 arguments.");
                    }

                    PvPScenario scenario = battle;
                    scenarios.Add(scenario);
                    battle.Delete();

                    CMOptions.ToConsole("Created scenario ({0}) '{1}'", scenario.TypeOf.Name, scenario.Name);
                },
                    CMOptions.ToConsole);
            }

            Scenarios = scenarios.ToArray();
            scenarios.Clear();

            foreach (var battle in Battles.Values.Where(b => b != null && !b.Deleted).ToArray())
            {
                VitaNexCore.TryCatch(
                    battle.Init,
                    ex =>
                {
                    VitaNexCore.TryCatch(battle.Delete);

                    CMOptions.ToConsole("Failed to initialize battle #{0} '{1}'", battle.Serial, battle.Name);
                    CMOptions.ToConsole(ex);
                });
            }

            foreach (var profile in Profiles.Values.Where(p => p != null && !p.Deleted).ToArray())
            {
                VitaNexCore.TryCatch(
                    profile.Init,
                    ex =>
                {
                    VitaNexCore.TryCatch(profile.Delete);

                    CMOptions.ToConsole("Failed to initialize profile #{0} '{1}'", profile.Owner.Serial.Value, profile.Owner.RawName);
                    CMOptions.ToConsole(ex);
                });
            }
        }
示例#25
0
        private static void CMSave()
        {
            DataStoreResult result = VitaNexCore.TryCatchGet(VoteSites.Export, CMOptions.ToConsole);

            CMOptions.ToConsole("{0} sites saved, {1}", VoteSites.Count.ToString("#,0"), result);

            result = VitaNexCore.TryCatchGet(Profiles.Export, CMOptions.ToConsole);
            CMOptions.ToConsole("{0} profiles saved, {1}", Profiles.Count.ToString("#,0"), result);
        }
示例#26
0
        private static void UpdateCallback()
        {
            if (_Updating || !Connection.Connected)
            {
                return;
            }

            _Updating = true;

            LastUpdate = DateTime.Now;

            Connection.NonQuery(
                @"CREATE DATABASE IF NOT EXISTS `{0}` DEFAULT CHARSET `utf8` DEFAULT COLLATE `utf8_bin`",
                CMOptions.MySQL.Database);

            Connection.UseDatabase(CMOptions.MySQL.Database);

            var watch = new Stopwatch();

            watch.Start();

            VitaNexCore.TryCatch(
                () =>
            {
                Process();
                Flush();
            },
                x =>
            {
                CMOptions.ToConsole(x);
                OnAbort();
            });

            watch.Stop();

            CMOptions.ToConsole("Updated {0:#,0} objects in {1:F2} seconds.", _UpdateCount, watch.Elapsed.TotalSeconds);

            if (UpdateTimes.Count >= 10)
            {
                UpdateTimes.Dequeue();
            }

            UpdateTimes.Enqueue(watch.Elapsed);

            ExportQueue.Clear();

            if (_Connection != null)
            {
                _Connection.Close();
                _Connection = null;
            }

            //GC.Collect();

            _UpdateCount = 0;
            _Updating    = false;
        }
示例#27
0
        public static void Process <T>(string opName, ParallelQuery <T> opQueue)
        {
            if (!_Updating)
            {
                OnAbort();
                return;
            }

            CMOptions.ToConsole("Processing {0}...", opName);


            int c = opQueue.Count();

            List <T> list = VitaNexCore.TryCatchGet(opQueue.Take(c).ToList);

            while (list.Count > 0)
            {
                if (World.Loading)
                {
                    Thread.Sleep(10);
                    continue;
                }

                if (World.Saving)
                {
                    World.WaitForWriteCompletion();
                    Thread.Sleep(10);
                    continue;
                }

                if (!_Updating)
                {
                    OnAbort();
                    break;
                }

                int cur   = ExportQueue.Values.Sum(l => l.Count);
                int count = Math.Max(0, Math.Min(CMOptions.QueueCapacity - cur, list.Count));

                Parallel.ForEach(list.Take(count), Enqueue);

                list.RemoveRange(0, count);
                list.TrimExcess();

                cur += count;

                if (cur >= CMOptions.QueueCapacity)
                {
                    Flush();
                }

                Thread.Sleep(0);
            }

            list.Clear();
            list.TrimExcess();
        }
示例#28
0
        private static void CMSave()
        {
            var result = Handlers.Export();

            CMOptions.ToConsole("{0:#,0} handlers saved, {1}", Handlers.Count, result);

            result = Profiles.Export();
            CMOptions.ToConsole("{0:#,0} profiles saved, {1}", Profiles.Count, result);
        }
示例#29
0
        private static void CMLoad()
        {
            var result = Handlers.Import();

            CMOptions.ToConsole("{0:#,0} handlers loaded, {1}.", Handlers.Count, result);

            result = Profiles.Import();
            CMOptions.ToConsole("{0:#,0} profiles loaded, {1}.", Profiles.Count, result);
        }
示例#30
0
 private static void CMLoad()
 {
     VitaNexCore.TryCatch(
         () =>
     {
         DataStoreResult result = Profiles.Import();
         CMOptions.ToConsole("{0} profiles loaded, {1}.", Profiles.Count > 0 ? Profiles.Count.ToString("#,#") : "0", result);
     },
         CMOptions.ToConsole);
 }