Ejemplo n.º 1
0
        public static void Start()
        {
            serverConfig = ConfigElement.GetAll(typeof(ServerConfig));
            levelConfig  = ConfigElement.GetAll(typeof(LevelConfig));
            zoneConfig   = ConfigElement.GetAll(typeof(ZoneConfig));

            #pragma warning disable 0618
            Player.players = PlayerInfo.Online.list;
            Server.levels  = LevelInfo.Loaded.list;
            #pragma warning restore 0618

            StartTime    = DateTime.UtcNow;
            shuttingDown = false;
            Logger.Log(LogType.SystemActivity, "Starting Server");
            ServicePointManager.Expect100Continue = false;

            CheckFile("MySql.Data.dll");
            CheckFile("sqlite3_x32.dll");
            CheckFile("sqlite3_x64.dll");
            CheckFile("LibNoise.dll");

            EnsureFilesExist();
            MoveSqliteDll();
            MoveOutdatedFiles();

            LoadAllSettings();
            SrvProperties.GenerateSalt();

            InitDatabase();
            Economy.LoadDatabase();

            Background.QueueOnce(UpgradeTasks.CombineEnvFiles);
            Background.QueueOnce(LoadMainLevel);
            Plugin.LoadAll();
            Background.QueueOnce(LoadAutoloadMaps);
            Background.QueueOnce(UpgradeTasks.MovePreviousLevelFiles);
            Background.QueueOnce(UpgradeTasks.UpgradeOldTempranks);
            Background.QueueOnce(UpgradeTasks.UpgradeDBTimeSpent);
            Background.QueueOnce(InitPlayerLists);
            Background.QueueOnce(UpgradeTasks.UpgradeBots);

            Background.QueueOnce(SetupSocket);
            Background.QueueOnce(InitTimers);
            Background.QueueOnce(InitRest);
            Background.QueueOnce(InitHeartbeat);

            Devs.Clear();
            Mods.Clear();
            Background.QueueOnce(InitTasks.UpdateStaffList);

            ServerTasks.QueueTasks();
            Background.QueueRepeat(ThreadSafeCache.DBCache.CleanupTask,
                                   null, TimeSpan.FromMinutes(5));
        }
Ejemplo n.º 2
0
 public Dev CreateDev(string name)
 {
     if (Devs.Count == 0 || Devs.Count(d => d != null && d.Name == name) == 0)
     {
         Dev dev = new Dev(Devs.Count + 1, name, _salary, _hiringCost);
         dev.Skills     = this.GenerateListOfSkill(SkillDevLevel);
         dev.HiringCost = HiringCost + (dev.Skills.Where(s => s.Level > SkillDevLevel).Sum(s => s.Level) * MultiHiring);
         dev.Salary     = Salary + (dev.Skills.Sum(s => s.Level) * MultiSalary);
         return(dev);
     }
     return(null);
 }
Ejemplo n.º 3
0
        //public IActionResult SeeTasksByUser(int id)
        //{
        //    List<Task> tasks = _capstone.Devs.Where(x => x.UserId == id).ToList();
        //    Task tasks =
        //}

        public IActionResult UpdateTask(int id)
        {
            //find the whold task we're looking to update
            Devs updatedTask = _capstone.Devs.Find(id);

            if (updatedTask == null)
            {
                return(RedirectToAction("ViewTasksToDo"));
            }
            else
            {
                return(View(updatedTask));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddTask(Devs newTask)
        {
            if (ModelState.IsValid)
            {
                string id = User.FindFirst(ClaimTypes.NameIdentifier).Value;

                var taskIndex = _capstone.Devs.Where(x => x.UserId == id).ToList();
                newTask.UserId = id;

                _capstone.Devs.Add(newTask);
                await _capstone.SaveChangesAsync();
            }
            return(RedirectToAction("ViewTasksToDo"));
        }
Ejemplo n.º 5
0
        // Check the existence of any combination of XenBus devices.
        // If 'strict' == true, all the devices queried need to exist
        // (bitwise AND). Else, at least one of the devices queried
        // needs to exist (bitwise OR).
        public static bool IsPresent(Devs xenBusDevQuery, bool strict)
        {
            bool result = strict ? true : false;

            for (int i = 0; i < hwIDs.Length; ++i)
            {
                if (((uint)xenBusDevQuery & (1 << i)) != 0)
                {
                    if (strict)
                    {
                        result &= !String.IsNullOrEmpty(hwIDs[i]);
                    }
                    else if (!String.IsNullOrEmpty(hwIDs[i]))
                    {
                        return(true);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        public IActionResult SaveChanges(Devs updatedTask)
        {
            Devs capstone = _capstone.Devs.Find(updatedTask.Id);

            //merging the capstone database on SQL  with the updatedTasks one property ata a time
            //This is to to prevent losing information in the capstone that might not
            //but in the updatedTasks

            capstone.ItemDescription = updatedTask.ItemDescription;
            capstone.DueDate         = updatedTask.DueDate;
            capstone.Complete        = updatedTask.Complete;
            capstone.TaskName        = updatedTask.TaskName;


            //creates a log og changes for this entry. A way to track our work
            _capstone.Entry(capstone).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _capstone.Update(capstone);
            _capstone.SaveChanges();

            return(RedirectToAction("ViewTasksToDo"));
        }
Ejemplo n.º 7
0
        public static void ListCommands(Message msg, string[] args)
        {
            var bu = Methods.GetUser(msg, args);

            var res = $"<b>User commands:</b>{Environment.NewLine}" +
                      $"{string.Join(Environment.NewLine, Bot.Commands.Where(x => !x.AdminOnly & !x.DevOnly).Select(x => x.Trigger))}";

            if (Admins.Contains(bu.Telegramid))
            {
                res += $"{Environment.NewLine}{Environment.NewLine}<b>Bot admin commands:</b>" +
                       $"{Environment.NewLine}{string.Join(Environment.NewLine, Bot.Commands.Where(x => x.AdminOnly).Select(x => x.Trigger))}";
            }

            if (Devs.ToList().Contains((int)bu.Telegramid))
            {
                res += $"{Environment.NewLine}{Environment.NewLine}<b>Bot Dev Commands:</b>" +
                       $"{Environment.NewLine}{string.Join(Environment.NewLine, Bot.Commands.Where(x => x.DevOnly).Select(x => x.Trigger))}";
            }

            Bot.Reply(res, msg);
        }
Ejemplo n.º 8
0
 void UpdateStaffListTask()
 {
     try {
         using (WebClient web = new WebClient()) {
             string[] result = web.DownloadString(staffUrl).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
             foreach (string line in result)
             {
                 string        type      = line.Split(':')[0].ToLower();
                 List <string> staffList = type.Equals("devs") ? Devs : type.Equals("mods") ? Mods : null;
                 foreach (string name in line.Split(':')[1].Split())
                 {
                     staffList.Add(name);
                 }
             }
         }
     } catch (Exception e) {
         ErrorLog(e);
         s.Log("Failed to update MCGalaxy staff list.");
         Devs.Clear();
         Mods.Clear();
     }
 }
Ejemplo n.º 9
0
        public static bool HasChildren(Devs xenBusDev)
        {
            CfgMgr32.CR err;

            string xenBusHwId = XenBus.hwIDs[
                Helpers.BitIdxFromFlag((uint)xenBusDev)
                                ];

            int xenBusNode = Device.GetDevNode(xenBusHwId);
            int xenBusChild;

            if (xenBusNode == -1)
            {
                Trace.WriteLine("Could not get XenBus DevNode");
                return(false);
            }

            err = CfgMgr32.CM_Get_Child(
                out xenBusChild, xenBusNode, 0
                );

            if (err == CfgMgr32.CR.NO_SUCH_DEVNODE)
            {
                Trace.WriteLine("XenBus device has no children");
                return(false);
            }
            else if (err != CfgMgr32.CR.SUCCESS)
            {
                Win32Error.SetCR("CM_Get_Child", err);
                throw new Exception(Win32Error.GetFullErrMsg());
            }

            Trace.WriteLine("XenBus device has at least one child");

            return(true);
        }
        private void CreateInputDeviceInstance(String DeviceName)
        {
            DirectInputEnumDevices8    Devs;    //DirectInput device enumeration.
            DirectInputDeviceInstance8 DevInst; //A single device instance.
            Int32 Counter;                      //Loop counter

            //Create a list of devices for this machine.
            Devs = DI8.GetDIDevices(CONST_DI8DEVICETYPE.DI8DEVCLASS_ALL,
                                    CONST_DIENUMDEVICESFLAGS.DIEDFL_ATTACHEDONLY);

            //Search for the correct GUID. Remember to start the
            //Counter at 1 for VB.
            for (Counter = 1; Counter <= Devs.GetCount(); Counter++)
            {
                //Get a device instance.
                DevInst = Devs.GetItem(Counter);

                if (DevInst.GetProductName().ToUpper() == DeviceName.ToUpper())
                {
                    DIDI8 = DevInst;
                    break;
                }
            }
        }
Ejemplo n.º 11
0
        public static void MessageHandler(Message msg)
        {
            try
            {
                if (!Groups.Any(x => x.Id == msg.Chat.Id) && msg.Chat.Type != ChatType.Private)
                {
                    Bot.Reply("Hey there! This bot isn't for every group! If you want to farm achievements with me, join a group in @WWAchievement! <b>Bye.</b>", msg);
                    Bot.Api.LeaveChatAsync(msg.Chat.Id);
                    Bot.Send($"<b>{msg.From.FirstName} {msg.From.LastName}</b> (@{msg.From.Username}) (<code>{msg.From.Id}</code>) just interacted me with me in <b>{msg.Chat.Title}</b> (<code>{msg.Chat.Id}</code>), which I left because it isn't an allowed group.", testgroup.Id);
                    return;
                }
                if (DateTime.UtcNow.AddSeconds(-5) > msg.Date.ToUniversalTime())
                {
                    return;
                }

                if (msg.Chat.Type == ChatType.Supergroup)
                {
                    var grp = Groups.First(x => x.Id == msg.Chat.Id);
                    if (msg.Chat.Title.FormatHTML() != grp.Name)
                    {
                        grp.Name = msg.Chat.Title.FormatHTML();
                        SQL.ChangeGroup(grp);
                    }
                    if (Games.Any(x => x.GroupId == grp.Id))
                    {
                        Games.First(x => x.GroupId == grp.Id).LastUpdate = DateTime.UtcNow;
                    }
                }

                var text = msg.Text;
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                var args = text.Contains(' ')
                    ? new[] { text.Split(' ')[0], text.Remove(0, text.IndexOf(' ') + 1) }
                    : new[] { text, null };

                if (!args[0].StartsWith("!") & !args[0].StartsWith("/") & args[0].ToLower() != "#ping")
                {
                    return;
                }

                var cmd = args[0].StartsWith("/") | args[0].StartsWith("!")
                    ? args[0].ToLower().Remove(0, 1).Replace('@' + Bot.Me.Username.ToLower(), "").Replace("@werewolfbot", "")
                    : args[0].ToLower().Replace('@' + Bot.Me.Username.ToLower(), "").Replace("@werewolfbot", "");

                var command = Bot.Commands.FirstOrDefault(x => String.Equals(x.Trigger, cmd, StringComparison.CurrentCultureIgnoreCase));
                if (command == null)
                {
                    return;
                }

                if (msg.Chat.Id == TranslationGroup && !Admins.Contains(msg.From.Id))
                {
                    Bot.Reply("You may not use commands in here!", msg);
                    return;
                }

                if (command.DevOnly & !Devs.Contains(msg.From.Id))
                {
                    Bot.Reply(Methods.GetString(msg, "NotDev"), msg);
                    return;
                }

                if (command.AdminOnly & !Admins.Contains(msg.From.Id))
                {
                    Bot.Reply(Methods.GetString(msg, "NotAdmin"), msg);
                    return;
                }

                if (command.InGroupOnly & msg.Chat.Type != ChatType.Supergroup)
                {
                    Bot.Reply(Methods.GetString(msg, "MustUseInGroup"), msg);
                    return;
                }

                if (command.InGameOnly)
                {
                    if (msg.Chat.Type != ChatType.Supergroup)
                    {
                        Bot.Reply(Methods.GetString(msg, "MustUseInGroup"), msg);
                        return;
                    }

                    var g = Games.FirstOrDefault(x => x.GroupId == msg.Chat.Id);

                    if (g == null)
                    {
                        Bot.Reply(Methods.GetString(msg, "MustUseInGame"), msg);
                        return;
                    }
                }

                command.Method.Invoke(msg, args);
            }
            catch (Exception e)
            {
                e.Log(true);
                return;
            }
        }
Ejemplo n.º 12
0
        public static void CallbackHandler(CallbackQuery call)
        {
            try
            {
                if (call.Message.Date.ToUniversalTime() < StartTime)
                {
                    Bot.AnswerCallback(call, Methods.GetString(call.Message, "OutdatedQuery"));
                    Bot.Edit(call.Message, call.Message.Text);
                    return;
                }

                var text = call.Data;
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                var args = text.Contains('|')
                    ? new[] { text.Split('|')[0], text.Remove(0, text.IndexOf('|') + 1) }
                    : new[] { text, null };

                var callback = Bot.Callbacks.FirstOrDefault(x => String.Equals(x.Trigger, args[0], StringComparison.CurrentCultureIgnoreCase));
                if (callback == null)
                {
                    return;
                }

                if (callback.DevOnly & !Devs.Contains(call.From.Id))
                {
                    Bot.AnswerCallback(call, "You aren't a bot dev!");
                    return;
                }

                if (callback.AdminOnly & !Admins.Contains(call.From.Id))
                {
                    Bot.AnswerCallback(call, "You aren't a bot admin!");
                    return;
                }

                if (callback.RequiresConfirm)
                {
                    var bu = call.From.GetOrMakeBotUser();
                    if (bu.CallbackChoice == call.Data)
                    {
                        bu.CallbackChoice = "";
                    }
                    else
                    {
                        bu.CallbackChoice = call.Data;
                        Timer t = new Timer(new TimerCallback(delegate { if (bu.CallbackChoice == call.Data)
                                                                         {
                                                                             bu.CallbackChoice = "";
                                                                         }
                                                              }), null, 10000, Timeout.Infinite);
                        Bot.AnswerCallback(call, Methods.GetString(call.Message, "ClickAgainConfirm"), true);
                        return;
                    }
                }

                callback.Method.Invoke(call, args);
            }
            catch (Exception e)
            {
                e.Log(true);
                return;
            }
        }
Ejemplo n.º 13
0
        public void Start()
        {
            serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGameProps));
            levelConfig  = ConfigElement.GetAll(typeof(Level));

            #pragma warning disable 0618
            Player.players       = PlayerInfo.Online.list;
            PlayerInfo.players   = PlayerInfo.Online.list;
            Server.levels        = LevelInfo.Loaded.list;
            PlayerBot.playerbots = PlayerBot.Bots.list;
            #pragma warning restore 0618

            StartTime      = DateTime.UtcNow;
            StartTimeLocal = StartTime.ToLocalTime();
            shuttingDown   = false;
            Log("Starting Server");
            try {
                if (File.Exists("Restarter.exe"))
                {
                    File.Delete("Restarter.exe");
                }
            } catch { }
            try {
                if (File.Exists("Restarter.pdb"))
                {
                    File.Delete("Restarter.pdb");
                }
            } catch { }

            CheckFile("MySql.Data.dll");
            CheckFile("System.Data.SQLite.dll");
            CheckFile("sqlite3.dll");
            CheckFile("Newtonsoft.Json.dll");
            CheckFile("LibNoise.dll");

            EnsureFilesExist();
            MoveOutdatedFiles();

            lava      = new LavaSurvival();
            zombie    = new ZombieGame();
            Countdown = new CountdownGame();
            LoadAllSettings();

            InitDatabase();
            Economy.LoadDatabase();
            Server.zombie.CheckTableExists();

            Level[] loaded = LevelInfo.Loaded.Items;
            foreach (Level l in loaded)
            {
                l.Unload();
            }

            Background.QueueOnce(UpgradeTasks.CombineEnvFiles);
            Background.QueueOnce(LoadMainLevel);
            Plugin.Load();
            Background.QueueOnce(UpgradeTasks.UpgradeOldBlacklist);
            Background.QueueOnce(LoadPlayerLists);
            Background.QueueOnce(LoadAutoloadCommands);
            Background.QueueOnce(UpgradeTasks.MovePreviousLevelFiles);
            Background.QueueOnce(UpgradeTasks.UpgradeOldLockdown);

            Background.QueueOnce(SetupSocket);
            Background.QueueOnce(InitTimers);
            Background.QueueOnce(InitRest);
            Background.QueueOnce(InitHeartbeat);

            Devs.Clear();
            Mods.Clear();
            Background.QueueOnce(InitTasks.UpdateStaffList);

            MainScheduler.QueueRepeat(ServerTasks.TemprankExpiry,
                                      null, TimeSpan.FromMinutes(1));
            Background.QueueRepeat(ServerTasks.AutoSave,
                                   1, TimeSpan.FromSeconds(Server.backupInterval));
            Background.QueueRepeat(ServerTasks.BlockUpdates,
                                   null, TimeSpan.FromSeconds(Server.blockInterval));
            Background.QueueRepeat(ThreadSafeCache.DBCache.CleanupTask,
                                   null, TimeSpan.FromMinutes(5));
        }
Ejemplo n.º 14
0
        // Static constructor
        static XenBus()
        {
            Trace.WriteLine("===> PVDevice.XenBus cctor");

            hwIDs = new string[
                Enum.GetNames(typeof(Devs)).Length // == # of devs
                    ];

            const string XENBUS_DEV_PREFIX = @"PCI\VEN_5853&";

            using (SetupApi.DeviceInfoSet devInfoSet =
                       new SetupApi.DeviceInfoSet(
                           IntPtr.Zero,
                           "PCI",
                           IntPtr.Zero,
                           SetupApi.DiGetClassFlags.DIGCF_ALLCLASSES |
                           SetupApi.DiGetClassFlags.DIGCF_PRESENT))
            {
                for (int i = 0; i < hwIDs.Length; ++i)
                {
                    SetupApi.SP_DEVINFO_DATA xenBusDevInfoData;

                    xenBusDevInfoData = Device.FindInSystem(
                        XENBUS_DEV_PREFIX +
                        Enum.GetName(typeof(Devs), 1 << i),     // == Dev name
                        devInfoSet,
                        false
                        );

                    if (xenBusDevInfoData != null)
                    {
                        // Just get the first string returned.
                        // Should be the most explicit.
                        hwIDs[i] = Device.GetDevRegPropertyMultiStr(
                            devInfoSet,
                            xenBusDevInfoData,
                            SetupApi.SPDRP.HARDWAREID
                            )[0];
                    }
                    else
                    {
                        hwIDs[i] = "";
                    }
                }

                // In descending order of preference
                if (IsPresent(Devs.DEV_C000, true))
                {
                    preferredXenBus = Devs.DEV_C000;
                }
                else if (IsPresent(Devs.DEV_0001, true))
                {
                    preferredXenBus = Devs.DEV_0001;
                }
                else if (IsPresent(Devs.DEV_0002, true))
                {
                    preferredXenBus = Devs.DEV_0002;
                }
            }

            Trace.WriteLine("<=== PVDevice.XenBus cctor");
        }
Ejemplo n.º 15
0
 void UpdateStaffList()
 {
     Devs.Clear();
     Mods.Clear();
     ml.Queue(UpdateStaffListTask);
 }