public int Price(int gameId, int maxPlayers, int months)
        {
            var game = _context.Games.SingleOrDefault(p => p.Id == gameId);
            var x    = game.CreditsPerMonth;

            if (game == null)
            {
                return(-1);
            }

            return(ServerUtils.CalculatePrice(game.BaseCredits.GetValueOrDefault(0), game.Price, maxPlayers, months, game.CreditsPerMonth.GetValueOrDefault(1)));
        }
        public ActionResult Create(int id, string name, byte maxPlayers, int months)
        {
            Server server = null;

            var game = _context.Games.Single(p => p.Id == id);
            var user = _context.Users.Single(p => p.Id == (Guid)Membership.GetUser().ProviderUserKey);

            var credits = ServerUtils.CalculatePrice(game.BaseCredits.GetValueOrDefault(0), game.Price, maxPlayers, months, 0);

            if (credits > user.Credits)
            {
                throw new Exception();
            }

            user.Credits -= credits;

            switch (game.ConfigurationType)
            {
            case "Valve":
                // TODO: Dynamic Configuration Here
                // Hardcoded config

                server = new ValveServer()
                {
                    Map          = game.DefaultMap,
                    MaximumFPS   = 300,
                    AutoUpdate   = false,
                    RconPassword = "******"
                };

                break;

            case "Samp":
                server = new SampServer()
                {
                    HostName = name
                };

                break;

            case "Minecraft":
                server = new MinecraftServer();
                break;
            }

            var ips = XDocument.Load(ServerUtils.GetIPsFile()).Element("IPs").Elements("IP").ToList();
            var ip  = ips[new Random().Next(0, ips.Count())].Value;

            server.IP              = ip;
            server.Port            = 20000 + server.Id;
            server.PublicIPAddress = ip + ":" + server.Port;
            server.Name            = name;
            server.StartDateTime   = DateTime.Now;
            server.EndDateTime     = DateTime.Now.AddMonths(months);
            server.MaxPlayers      = maxPlayers;
            server.Game            = game;
            server.User            = user;
            server.IsInstalled     = false;

            _context.Servers.InsertOnSubmit(server);
            _context.SubmitChanges();

            server.Port = 20000 + server.Id;
            _context.SubmitChanges();

            _queueService.Install(server.Id);

            return(RedirectToAction("Index"));
        }