Ejemplo n.º 1
0
        public void ReInstall(int serverId)
        {
            new Thread(new ThreadStart(() =>
            {
                try
                {
                    log.Info(String.Format("Reinstalling server #{0}.", serverId));

                    Server server = null;

                    lock (_context)
                    {
                        server             = _context.Servers.Single(p => p.Id == serverId);
                        server.IsInstalled = false;

                        _context.SubmitChanges();
                    }

                    Directory.Delete(ServerUtils.GetServerDirectory(server.Game.Abbreviation, server.Id), true);

                    new DirectoryInfo(ServerUtils.GetOrginalGameDirectory(server.Game.Abbreviation))
                    .CopyTo(ServerUtils.GetServerDirectory(server.Game.Abbreviation, server.Id), true);

                    server.IsInstalled = true;

                    if (server.ConfigurationType == "Minecraft")
                    {
                        var minecraftServer = (MinecraftServer)server;

                        File.WriteAllText(
                            Path.Combine(ServerUtils.GetServerDirectory(server.Game.Abbreviation, server.Id), "server.properties"),
                            ServerUtils.BuildMinecraftConfiguration(new Dictionary <string, object>()
                        {
                            { "level-name", string.IsNullOrEmpty(minecraftServer.World) ? "world" : minecraftServer.World },
                            { "allow-nether", minecraftServer.AllowNether.GetValueOrDefault(true) },
                            { "view-distance", minecraftServer.ViewDistance.GetValueOrDefault(10) },
                            { "spawn-monsters", minecraftServer.SpawnMonsters.GetValueOrDefault(true) },
                            { "online-mode", minecraftServer.OnlineMode.GetValueOrDefault(true) },
                            { "max-players", minecraftServer.MaxPlayers },
                            { "server-ip", minecraftServer.IP },
                            { "pvp", minecraftServer.Pvp.GetValueOrDefault(false) },
                            { "level-seed", string.Empty },
                            { "server-port", minecraftServer.Port },
                            { "allow-flight", minecraftServer.AllowFlight.GetValueOrDefault(false) },
                            { "white-list", minecraftServer.WhiteList.GetValueOrDefault(true) }
                        })
                            );
                    }

                    lock (_context)
                    {
                        _context.SubmitChanges();
                    }
                }
                catch (Exception e)
                {
                    log.Warn(String.Format("Failed to reinstall server #{0}.", serverId), e);
                }
            })).Start();
        }
Ejemplo n.º 2
0
        public void Install(int serverId)
        {
            new Thread(new ThreadStart(() =>
            {
                try
                {
                    log.Info(String.Format("Installing server #{0}.", serverId));

                    Server server = null;

                    lock (_context)
                    {
                        server = _context.Servers.Single(p => p.Id == serverId);
                    }

                    var serverDirectory = ServerUtils.GetServerDirectory(server.Game.Abbreviation, server.Id);

                    new DirectoryInfo(ServerUtils.GetOrginalGameDirectory(server.Game.Abbreviation))
                    .CopyTo(serverDirectory, true);

                    server.IsInstalled = true;

                    if (server.ConfigurationType == "Minecraft")
                    {
                        var minecraftServer = (MinecraftServer)server;

                        File.WriteAllText(
                            Path.Combine(serverDirectory, "server.properties"),
                            ServerUtils.BuildMinecraftConfiguration(new Dictionary <string, object>()
                        {
                            { "level-name", string.IsNullOrEmpty(minecraftServer.World) ? "world" : minecraftServer.World },
                            { "allow-nether", minecraftServer.AllowNether.GetValueOrDefault(true) },
                            { "view-distance", minecraftServer.ViewDistance.GetValueOrDefault(10) },
                            { "spawn-monsters", minecraftServer.SpawnMonsters.GetValueOrDefault(true) },
                            { "online-mode", minecraftServer.OnlineMode.GetValueOrDefault(true) },
                            { "max-players", minecraftServer.MaxPlayers },
                            { "server-ip", minecraftServer.IP },
                            { "pvp", minecraftServer.Pvp.GetValueOrDefault(false) },
                            { "level-seed", string.Empty },
                            { "server-port", minecraftServer.Port },
                            { "allow-flight", minecraftServer.AllowFlight.GetValueOrDefault(false) },
                            { "white-list", minecraftServer.WhiteList.GetValueOrDefault(true) }
                        })
                            );
                    }

                    var password = Guid.NewGuid().ToString().Substring(0, 8);

                    FtpManager.CreateFtpUser(
                        "GamePanelFTP",
                        ServerUtils.GetServerIdentifier(server.Game.Abbreviation, server.Id),
                        password);

                    server.FtpAddress  = "www.mpsite-serv.com";
                    server.FtpPassword = password;

                    lock (_context)
                    {
                        _context.SubmitChanges();
                    }
                }
                catch (Exception e)
                {
                    log.Warn(String.Format("Failed to install server #{0}.", serverId), e);
                }
            })).Start();
        }