Ejemplo n.º 1
0
            public async Task SetGameNameAsync(string name, string newName)
            {
                if (name is null || newName is null)
                {
                    await ReplyAsync("Incorrect command structure, use: db port \"[Game]\" \"[NewPort]\"");

                    return;
                }

                Data.Game game = db.Games.Where(x => x.Name == name).FirstOrDefault();
                if (game is null)
                {
                    await ReplyAsync($"Sorry, {name} not found in the database");

                    return;
                }
                try
                {
                    game.Name = newName;
                    await db.SaveChangesAsync();
                    await ReplyAsync($"Changed {game.Name}'s name to {newName} successfully");
                }
                catch (Exception ex)
                {
                    await ReplyAsync($"Nope, something went wrong. " +
                                     $"Please let the knobhead who programmed this know about it, thanks");

                    Console.WriteLine(ex.Message);
                    throw;
                }
            }
Ejemplo n.º 2
0
        public async Task AddGameAsync(string name, string port = "?", string version = "?")
        {
            if (name is null)
            {
                await ReplyAsync($"Incorrect struncture, use: \"[game]\" \"[port]\" \"[version]\"");

                return;
            }
            else
            {
                Game game = new Game {
                    Name = name, Port = port, Version = version
                };
                await db.AddAsync(game);

                await db.SaveChangesAsync();
                await ReplyAsync(InfoMessage.SuccessfullyAdded(game));
            }
        }
Ejemplo n.º 3
0
        public async Task StartGameAsync(string name)
        {
            Data.Game game = db.Games.Where(x => x.Name == name).FirstOrDefault();
            if (game is null)
            {
                await ReplyAsync(ErrorMessage.GameNotFound(game.Name));

                return;
            }

            try
            {
                if (ProcessDictionary.Instance.TryGetValue(game.Name, out Process temp))
                {
                    await ReplyAsync(ErrorMessage.GameAlreadyRunning(Context.User.Mention, game.Name, game.Version, game.Port));

                    return;
                }

                Process p = new Process();
                p.StartInfo.FileName  = Path + game.ExeDir;
                p.StartInfo.Arguments = game.Args;
                p.Start();

                ProcessDictionary.Instance.Add(game.Name, p);

                game.IsOnline = true;
                await db.SaveChangesAsync();

                await ReplyAsync(InfoMessage.GameStartingUp(Context.User.Mention, game.Name, game.Version, game.Port));
            }
            catch (Exception ex)
            {
                await ReplyAsync(ErrorMessage.UnableToStartGameServer(game.Name));

                Console.WriteLine(ex.Message);
                throw;
            }
        }
Ejemplo n.º 4
0
        private async Task PopulateDbAsync()
        {
            List <Data.Game> Games = new List <Data.Game>
            {
                new Data.Game {
                    Name = "Space Engineers", Port = "3080", Version = "?"
                },
                new Data.Game {
                    Name = "StarMade", Port = "3070", Version = ".654"
                },
                new Data.Game {
                    Name = "Project Zomboid", Port = "3050", Version = "37.14"
                },
                new Data.Game {
                    Name = "Starbound", Port = "3040", Version = "1.2.2"
                },
                new Data.Game {
                    Name = "Terraria", Port = "3030", Version = "1.3.5.3"
                },
                new Data.Game {
                    Name = "Factorio", Port = "3020", Version = "15.18"
                },
                new Data.Game {
                    Name = "7 Days to die", Port = "3010", Version = "16 b138"
                },
                new Data.Game {
                    Name = "GMod - Sandbox", Port = "3003", Version = "?"
                },
                new Data.Game {
                    Name = "GMod - Murder", Port = "3000", Version = "?"
                }
            };

            InquisitionContext db = new InquisitionContext();
            await db.Games.AddRangeAsync(Games);

            await db.SaveChangesAsync();
        }
Ejemplo n.º 5
0
        public async Task DeleteGameAsync(string name)
        {
            Data.Game game = db.Games.Where(x => x.Name == name).FirstOrDefault();
            if (game is null)
            {
                await ReplyAsync(ErrorMessage.GameNotFound(game.Name));

                return;
            }
            try
            {
                db.Remove(game);
                await db.SaveChangesAsync();
                await ReplyAsync(InfoMessage.SuccessfullyRemoved(game));
            }
            catch (Exception ex)
            {
                await ReplyAsync(ErrorMessage.DatabaseAccess());

                Console.WriteLine(ex.Message);
                throw;
            }
        }
Ejemplo n.º 6
0
        public async Task StopGameAsync(string name)
        {
            Data.Game game = db.Games.Where(x => x.Name == name).FirstOrDefault();
            if (game is null)
            {
                await ReplyAsync(ErrorMessage.GameNotFound(game.Name));

                return;
            }

            try
            {
                if (ProcessDictionary.Instance.TryGetValue(game.Name, out Process p))
                {
                    p.CloseMainWindow();
                    p.Close();
                    ProcessDictionary.Instance.Remove(game.Name);

                    game.IsOnline = false;
                    await db.SaveChangesAsync();

                    await ReplyAsync(InfoMessage.GameShuttingDown(game.Name));

                    return;
                }

                await ReplyAsync(ErrorMessage.GameNotRunning(Context.User.Mention, game.Name));
            }
            catch (Exception ex)
            {
                await ReplyAsync(ErrorMessage.UnableToStopGameServer(game.Name));

                Console.WriteLine(ex.Message);
                throw;
            }
        }