Пример #1
0
 public ServerInfo GetServerData()
 {
     using (QueryMaster.GameServer.Server s = ServerQuery.GetServerInstance(EngineType.Source, new IPEndPoint(this.serverConnectionInfo.ServerIP, this.serverConnectionInfo.ServerQueryPort)))
     {
         return(s.GetInfo());
     }
 }
Пример #2
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);
                }
            }
        }
Пример #3
0
 public void WaitForPlayers()
 {
     try
     {
         QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(EngineType.Source, "217.78.24.8", 28892);
         server.ReceiveTimeout = 200;
         bool stop = false;
         while (!stop)
         {
             ServerInfo info = server.GetInfo();
             if (info.Players == 2)
             {
                 stop = true;
             }
             Thread.Sleep(10000);
         }
     }
     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);
         }
     }
 }
Пример #4
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
            });
        }
Пример #5
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");
     }
 }
Пример #6
0
 public void Disconnect()
 {
     if (squadServer != null)
     {
         this.squadServer.Dispose();
         squadServer = null;
     }
 }
Пример #7
0
        public bool Connect(ServerConnectionInfo connectionInfo)
        {
            if (!connectionInfo.IsValid)
            {
                return(false);
            }

            this.serverConnectionInfo = connectionInfo;
            this.squadServer          = ServerQuery.GetServerInstance(EngineType.Source,
                                                                      new IPEndPoint(this.serverConnectionInfo.ServerIP, this.serverConnectionInfo.ServerRconPort));
            return(this.squadServer.GetControl(this.serverConnectionInfo.RCONPassword));
        }
Пример #8
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);
        }
Пример #9
0
        public void ReadServerLogs()
        {
            // Create textfile locally to save all logs comming from server
            using (StreamWriter writer = new StreamWriter(logsPath, true))
            {
                //Connect to gameserver
                QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(EngineType.Source, "217.78.24.8", 28892);
                //Get logs from server. To get these,
                //Type in server console: logaddress_add YOURIP:9871
                //Port 9871 is default for logs
                Logs logs = server.GetLogs(9871);

                //Start listen to logs
                var event1 = logs.GetEventsInstance();
                //Copy logs to your txt file
                event1.LogReceived += (o, e) => writer.Write(e.Message + Environment.NewLine);
                logs.Start();
                StopGame(event1, logs);
                logs.Stop();
            }
        }
Пример #10
0
        public async Task QueryServerData(Server dayZServer)
        {
            ReadOnlyCollection <QueryMaster.GameServer.PlayerInfo> players;
            ServerInfo info;

            if (dayZServer.QueryPort == 0)
            {
                byte[] data;

                try
                {
                    WebClient webClient = new WebClient();
                    data = await webClient.DownloadDataTaskAsync(new Uri("http://api.steampowered.com/ISteamApps/GetServersAtAddress/v1?addr=" + dayZServer.IP_Address + "&format=json", UriKind.Absolute));

                    string     result     = System.Text.Encoding.UTF8.GetString(data);
                    RootObject rootObject = JsonConvert.DeserializeObject <RootObject>(result);
                    Console.WriteLine(rootObject.response.servers);
                    List <SteamServer> steamservers = rootObject.response.servers;

                    if (steamservers != null && Servers != null)
                    {
                        foreach (SteamServer steamServer in steamservers)
                        {
                            string serverip      = steamServer.addr.Substring(0, steamServer.addr.IndexOf(":", StringComparison.Ordinal));
                            string queryport     = steamServer.addr.Substring(steamServer.addr.LastIndexOf(':') + 1);
                            string steamgameport = steamServer.gameport.ToString();
                            ushort queryportnum  = ushort.Parse(queryport);
                            if (queryportnum == 0)
                            {
                                continue;
                            }
                            try
                            {
                                if (Servers == null)
                                {
                                    continue;
                                }
                                Server matchCurrent = Servers.FirstOrDefault(p => p.IP_Address == serverip && p.Game_Port == steamgameport);

                                if (matchCurrent != null)
                                {
                                    QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(EngineType.Source, serverip, queryportnum);
                                    players = server.GetPlayers();
                                    info    = server.GetInfo();
                                    matchCurrent.QueryPort = queryportnum;
                                    UpdateServerData(matchCurrent, players, info);
                                }
                            }
                            catch (ArgumentException e)
                            {
                                Console.WriteLine("Failed to query the DayZ server for data" + e);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to query steam server for data" + e);
                }
            }
            else
            {
                try
                {
                    QueryMaster.GameServer.Server server = ServerQuery.GetServerInstance(EngineType.Source, dayZServer.IP_Address, dayZServer.QueryPort);
                    players = server.GetPlayers();
                    info    = server.GetInfo();
                    UpdateServerData(dayZServer, players, info);
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine("Failed to query the DayZ server for data" + e);
                }
            }
        }
Пример #11
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);
                }
            }
        }