public async Task SendInfo()
    {
        if (PermissionManager.GetPerms(Context.Message.Author.Id) < PermissionConfig.User)
        {
            await Context.Channel.SendMessageAsync("Not authorised to run this command."); return;
        }

        try
        {
            QueryMaster.Server     server1 = ServerQuery.GetServerInstance(EngineType.Source, "54.36.229.194", 27015);
            QueryMaster.ServerInfo s1Info  = server1.GetInfo();
            QueryMaster.Server     server3 = ServerQuery.GetServerInstance(EngineType.Source, "51.81.120.22", 27015);
            QueryMaster.ServerInfo s3Info  = server3.GetInfo();

            EmbedBuilder       eb = new EmbedBuilder();
            EmbedFooterBuilder fb = new EmbedFooterBuilder();


            fb.WithText($"Called by {Context.Message.Author.Username}");
            fb.WithIconUrl(Context.Message.Author.GetAvatarUrl());

            eb.WithTitle($"Server Info");
            eb.AddField("Server 1", $"[{s1Info.Players}/{s1Info.MaxPlayers}](http://s1.nickgor.com)", true);
            eb.AddField("Server 3", $"[{s3Info.Players}/{s3Info.MaxPlayers}](http://s3.nickgor.com)", true);

            eb.WithColor(Color.Blue);
            eb.WithFooter(fb);

            await ReplyAsync("", false, eb.Build());

            await Utilities.StatusMessage("online", Context);
        }
        catch (Exception)
        {
            await ReplyAsync("A connection could not be made to one or more ZARP servers. Please try again later.");

            await Utilities.StatusMessage("online", Context);

            return;
        }
    }
Beispiel #2
0
 private ServerInfo Obsolete(byte[] data)
 {
     var parser = new Parser(data);
       if (parser.ReadByte() != (byte) ResponseMsgHeader.A2S_INFO_Obsolete)
     throw new InvalidHeaderException("A2S_INFO(obsolete) message header is not valid");
       var server = new ServerInfo();
       server.IsObsolete = true;
       server.Address = parser.ReadString();
       server.Name = parser.ReadString();
       server.Map = parser.ReadString();
       server.Directory = parser.ReadString();
       server.Id = Util.GetGameId(parser.ReadString());
       server.Players = parser.ReadByte();
       server.MaxPlayers = parser.ReadByte();
       server.Protocol = parser.ReadByte();
       server.ServerType = (new Func<string>(() =>
       {
     switch ((char) parser.ReadByte())
     {
       case 'L': return "non-dedicated server";
       case 'D': return "dedicated";
       case 'P': return "HLTV server";
     }
     return "";
       }))();
       server.Environment = (new Func<string>(() =>
       {
     switch ((char) parser.ReadByte())
     {
       case 'L': return "Linux";
       case 'W': return "Windows";
     }
     return "";
       }))();
       server.IsPrivate = Convert.ToBoolean(parser.ReadByte());
       var mod = parser.ReadByte();
       server.IsModded = mod > 0;
       if (server.IsModded)
       {
     var modinfo = new Mod();
     modinfo.Link = parser.ReadString();
     modinfo.DownloadLink = parser.ReadString();
     parser.ReadByte(); //0x00
     modinfo.Version = parser.ReadInt();
     modinfo.Size = parser.ReadInt();
     modinfo.IsOnlyMultiPlayer = parser.ReadByte() > 0;
     modinfo.IsHalfLifeDll = parser.ReadByte() == 0;
     server.ModInfo = modinfo;
       }
       server.IsSecure = Convert.ToBoolean(parser.ReadByte());
       server.Bots = parser.ReadByte();
       server.GameVersion = "server is obsolete,does not provide this information";
       server.Ping = Latency;
       return server;
 }
Beispiel #3
0
        private ServerInfo Current(byte[] data)
        {
            var parser = new Parser(data);
              if (parser.ReadByte() != (byte) ResponseMsgHeader.A2S_INFO)
            throw new InvalidHeaderException("A2S_INFO message header is not valid");
              var server = new ServerInfo();
              server.IsObsolete = false;
              server.Protocol = parser.ReadByte();
              server.Name = parser.ReadString();
              server.Map = parser.ReadString();
              server.Directory = parser.ReadString();
              server.Description = parser.ReadString();
              server.Id = parser.ReadShort();
              server.Players = parser.ReadByte();
              server.MaxPlayers = parser.ReadByte();
              server.Bots = parser.ReadByte();
              server.ServerType = (new Func<string>(() =>
              {
            switch ((char) parser.ReadByte())
            {
              case 'l': return "Listen";
              case 'd': return "Dedicated";
              case 'p': return "SourceTV";
            }
            return "";
              }))();
              server.Environment = (new Func<string>(() =>
              {
            switch ((char) parser.ReadByte())
            {
              case 'l': return "Linux";
              case 'w': return "Windows";
              case 'm': return "Mac";
            }
            return "";
              }))();
              server.IsPrivate = Convert.ToBoolean(parser.ReadByte());
              server.IsSecure = Convert.ToBoolean(parser.ReadByte());
              if (server.Id >= 2400 && server.Id <= 2412)
              {
            var ship = new TheShip();
            switch (parser.ReadByte())
            {
              case 0: ship.Mode = "Hunt"; break;
              case 1: ship.Mode = "Elimination"; break;
              case 2: ship.Mode = "Duel"; break;
              case 3: ship.Mode = "Deathmatch"; break;
              case 4: ship.Mode = "VIP Team"; break;
              case 5: ship.Mode = "Team Elimination"; break;
              default: ship.Mode = ""; break;
            }
            ship.Witnesses = parser.ReadByte();
            ship.Duration = parser.ReadByte();
            server.ShipInfo = ship;
              }

              server.GameVersion = parser.ReadString();
              if (parser.HasMore)
              {
            var edf = parser.ReadByte();
            var info = new ExtraInfo();
            info.Port = (edf & 0x80) > 0 ? parser.ReadShort() : (ushort)0;
            info.SteamID = (edf & 0x10) > 0 ? parser.ReadLong() : 0;
            if ((edf & 0x40) > 0)
              info.SpecInfo = new SourceTVInfo {Port = parser.ReadShort(), Name = parser.ReadString()};
            info.Keywords = (edf & 0x20) > 0 ? parser.ReadString() : string.Empty;
            info.GameId = (edf & 0x01) > 0 ? parser.ReadLong() : 0;
            server.Extra = info;
              }
              server.Address = socket.Address.Address + ":" + socket.Address.Port;
              server.Ping = Latency;
              return server;
        }
        private ServerInfo Current(byte[] data)
        {
            Parser parser = new Parser(data);

            if (parser.ReadByte() != (byte)ResponseMsgHeader.A2S_INFO)
            {
                throw new InvalidHeaderException("A2S_INFO message header is not valid");
            }
            ServerInfo server = new ServerInfo();

            server.IsObsolete  = false;
            server.Protocol    = parser.ReadByte();
            server.Name        = parser.ReadString();
            server.Map         = parser.ReadString();
            server.Directory   = parser.ReadString();
            server.Description = parser.ReadString();
            server.Id          = parser.ReadShort();
            server.Players     = parser.ReadByte();
            server.MaxPlayers  = parser.ReadByte();
            server.Bots        = parser.ReadByte();
            server.ServerType  = (new Func <string>(() => { switch ((char)parser.ReadByte())
                                                            {
                                                            case 'l': return("Listen");

                                                            case 'd': return("Dedicated");

                                                            case 'p': return("SourceTV");
                                                            }
                                                            return(""); }))();
            server.Environment = (new Func <string>(() => { switch ((char)parser.ReadByte())
                                                            {
                                                            case 'l': return("Linux");

                                                            case 'w': return("Windows");

                                                            case 'm': return("Mac");
                                                            }
                                                            return(""); }))();
            server.IsPrivate   = Convert.ToBoolean(parser.ReadByte());
            server.IsSecure    = Convert.ToBoolean(parser.ReadByte());
            if (server.Id >= 2400 && server.Id <= 2412)
            {
                TheShip ship = new TheShip();
                switch (parser.ReadByte())
                {
                case 0: ship.Mode = "Hunt"; break;

                case 1: ship.Mode = "Elimination"; break;

                case 2: ship.Mode = "Duel"; break;

                case 3: ship.Mode = "Deathmatch"; break;

                case 4: ship.Mode = "VIP Team"; break;

                case 5: ship.Mode = "Team Elimination"; break;

                default: ship.Mode = ""; break;
                }
                ship.Witnesses  = parser.ReadByte();
                ship.Duration   = parser.ReadByte();
                server.ShipInfo = ship;
            }

            server.GameVersion = parser.ReadString();
            byte      edf  = parser.ReadByte();
            ExtraInfo info = new ExtraInfo();

            info.Port    = (edf & 0x80) > 0 ? parser.ReadShort() : (short)0;
            info.SteamID = (edf & 0x10) > 0 ? parser.ReadInt() : 0;
            if ((edf & 0x40) > 0)
            {
                info.SpecInfo = new SourceTVInfo()
                {
                    Port = parser.ReadShort(), Name = parser.ReadString()
                }
            }
            ;
            info.Keywords  = (edf & 0x20) > 0 ? parser.ReadString() : string.Empty;
            info.GameId    = (edf & 0x10) > 0 ? parser.ReadInt() : 0;
            server.Extra   = info;
            server.Address = socket.Address.Address + ":" + socket.Address.Port;
            server.Ping    = Latency;
            server.Address = socket.Address.Address + ":" + socket.Address.Port;
            server.Ping    = Latency;
            return(server);
        }