Exemplo n.º 1
0
        public void WhitelistPlayers(ArenaStars.Models.Game _game)
        {
            try
            {
                ArenaStarsContext db = new ArenaStarsContext();
                var findGame         = from x in db.Games
                                       where x.Id == _game.Id
                                       select x;
                Models.Game g = findGame.FirstOrDefault();

                User playerA = g.Participants.FirstOrDefault();
                User playerB = g.Participants.LastOrDefault();
                //Add players to the whitelist
                string playerAID = "\"" + playerA.SteamId + "\"";
                string playerBID = "\"" + playerB.SteamId + "\"";

                QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(EngineType.Source, "217.78.24.8", 28892);

                if (server.GetControl("lol"))
                {
                    server.Rcon.SendCommand("sm_whitelist_add " + playerAID);
                    server.Rcon.SendCommand("sm_whitelist_add " + playerBID);
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter writer = new StreamWriter(errorsPath, true))
                {
                    writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + Environment.NewLine + "Innerexception :" + ex.InnerException +
                                     "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
            }
        }
Exemplo n.º 2
0
        public static Server QueryServer(string ip, string rconPwd = null, int rconPort = 0)
        {
            string[] formattedIP = ip.Split(':'); //split IP into IP and port

            //Get server instance
            QueryMaster.GameServer.Server server = GetServerInstance(ip, rconPwd);
            ServerInfo info = server.GetInfo();

            //If RCON password has been submitted, check to see if it's correct.
            //If not, then set RCON password back to null because it's incorrect
            if (rconPwd != null)
            {
                if (!server.GetControl(rconPwd))
                {
                    rconPwd = null;
                }
            }

            return(new Server()
            {
                Address = info.Address,
                Map = info.Map,
                MaxPlayers = info.MaxPlayers,
                Name = info.Name,
                Players = info.Players,
                RconPwd = rconPwd,
                RconPort = rconPort
            });
        }
Exemplo n.º 3
0
 public void StartGame()
 {
     QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(EngineType.Source, "217.78.24.8", 28892);
     if (server.GetControl("lol"))
     {
         server.Rcon.SendCommand("1on1");
     }
 }
Exemplo n.º 4
0
        public static QueryMaster.GameServer.Server GetServerInstance(string ip, string rconPwd = null)
        {
            string[] formattedIP = ip.Split(':');
            var      ipEndpoint  = new IPEndPoint(IPAddress.Parse(formattedIP[0]), int.Parse(formattedIP[1]));

            //Get server instance
            QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(Game.Rust, ipEndpoint, sendTimeout: 500, receiveTimeout: 500, throwExceptions: true);

            //If rconPwd is not null, check if we can get control of RCON
            if (rconPwd != null)
            {
                if (!server.GetControl(rconPwd))
                {
                    return(null);
                }
            }

            return(server);
        }
Exemplo n.º 5
0
        public void SaveStatsAndGame(ArenaStars.Models.Game _game)
        {
            try
            {
                using (ArenaStarsContext db = new ArenaStarsContext())
                {
                    var findGame = from x in db.Games
                                   where x.Id == _game.Id
                                   select x;
                    ArenaStars.Models.Game g = findGame.FirstOrDefault();
                    User playerA             = g.Participants.FirstOrDefault();
                    User playerB             = g.Participants.LastOrDefault();

                    QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(EngineType.Source, "217.78.24.8", 28892);
                    ServerInfo info = server.GetInfo();


                    string playerAName    = "\"" + playerA.Username;
                    string playerASteamID = playerA.SteamId;
                    int    playerAKills   = 0;
                    int    playerADeaths  = 0;
                    int    playerAHSCount = 0;

                    string playerBName    = "\"" + playerB.Username;
                    string playerBSteamID = playerB.SteamId;
                    int    playerBKills   = 0;
                    int    playerBDeaths  = 0;
                    int    playerBHSCount = 0;

                    //Spagetthi for getting kills,deaths etc..
                    //Reads every line in Logs.txt and calculates
                    foreach (var line in File.ReadAllLines(logsPath))
                    {
                        if (line.StartsWith(playerAName) && line.Contains("killed"))
                        {
                            playerAKills++;
                            if (line.Contains("headshot"))
                            {
                                playerAHSCount++;
                            }
                        }
                        if (line.StartsWith(playerBName) && line.Contains("killed"))
                        {
                            playerBKills++;
                            if (line.Contains("headshot"))
                            {
                                playerBHSCount++;
                            }
                        }
                    }
                    playerADeaths = playerBKills;
                    playerBDeaths = playerAKills;


                    GameStats gameStatsA = new GameStats();
                    gameStatsA.SteamId = playerASteamID;
                    gameStatsA.Kills   = playerAKills;
                    gameStatsA.Deaths  = playerADeaths;
                    gameStatsA.HsRatio = headShotRatioConverter(playerAHSCount, playerAKills);
                    gameStatsA.Score   = 0;
                    gameStatsA.Game    = g;


                    GameStats gameStatsB = new GameStats();
                    gameStatsB.SteamId = playerBSteamID;
                    gameStatsB.Kills   = playerBKills;
                    gameStatsB.Deaths  = playerBDeaths;
                    gameStatsB.HsRatio = headShotRatioConverter(playerBHSCount, playerBKills); //ISSUES
                    gameStatsB.Score   = 0;
                    gameStatsB.Game    = g;

                    g.Winner   = getWinner(gameStatsA, gameStatsB, playerA, playerB, g);
                    g.HasEnded = true;


                    db.GameStats.Add(gameStatsA);
                    db.GameStats.Add(gameStatsB);


                    db.SaveChanges();

                    //Match has finished so we remove players from the whitelist and restart map.
                    string playerAID = "\"" + playerA.SteamId + "\"";
                    string playerBID = "\"" + playerB.SteamId + "\"";


                    if (server.GetControl("lol"))
                    {
                        server.Rcon.SendCommand("sm_whitelist_remove " + playerAID);
                        server.Rcon.SendCommand("sm_whitelist_remove " + playerBID);
                        server.Rcon.SendCommand("sm_kick @all");
                        server.Rcon.SendCommand("changelevel aim_map");
                        server.Rcon.SendCommand("warmup");
                    }
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter writer = new StreamWriter(errorsPath, true))
                {
                    writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + Environment.NewLine + "Innerexception :" + ex.InnerException +
                                     "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
            }
        }