Beispiel #1
0
        public byte[] QueryFull()
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(stream))
                {
                    IEnumerable <Player> players = elementRepository.GetByType <Player>(ElementType.Player);

                    string aseVersion = GetVersion();

                    bw.Write("EYE1".AsSpan());
                    bw.WriteWithLength("mta");
                    bw.WriteWithLength(configuration.Port);
                    bw.WriteWithLength(configuration.ServerName);
                    bw.WriteWithLength(mtaServer.GameType);
                    bw.WriteWithLength(mtaServer.MapName);
                    bw.WriteWithLength(aseVersion);
                    bw.WriteWithLength(mtaServer.HasPassword);
                    bw.WriteWithLength(players.Count().ToString());
                    bw.WriteWithLength(configuration.MaxPlayerCount.ToString());
                    foreach (var item in rules)
                    {
                        bw.WriteWithLength(item.Key);
                        bw.WriteWithLength(item.Value);
                    }
                    bw.Write((byte)1);

                    byte flags = 0;
                    flags |= (byte)PlayerFlags.Nick;
                    flags |= (byte)PlayerFlags.Team;
                    flags |= (byte)PlayerFlags.Skin;
                    flags |= (byte)PlayerFlags.Score;
                    flags |= (byte)PlayerFlags.Ping;
                    flags |= (byte)PlayerFlags.Time;

                    foreach (Player player in players)
                    {
                        bw.Write(flags);
                        bw.WriteWithLength(player.Name.StripColorCode());
                        bw.Write((byte)1);     // team, skip
                        bw.Write((byte)1);     // skin, skip
                        bw.WriteWithLength(1); // score
                        bw.WriteWithLength(1); // ping, skip right now
                        bw.Write((byte)1);     // time, skip
                    }

                    bw.Flush();
                    return(stream.ToArray());
                }
            }
        }
Beispiel #2
0
    public MarkerBehaviour(MtaServer server, IElementRepository elementRepository)
    {
        this.server = server;
        foreach (var marker in elementRepository.GetByType <Marker>(ElementType.Marker))
        {
            AddMarker(marker);
        }

        server.ElementCreated += OnElementCreate;
    }
    public BlipBehaviour(MtaServer server, IElementRepository elementRepository)
    {
        this.server = server;
        this.blips  = new HashSet <Blip>();
        foreach (var blip in elementRepository.GetByType <Blip>(ElementType.Blip))
        {
            AddBlip(blip);
        }

        server.ElementCreated += OnElementCreate;
    }
    public CollisionShapeBehaviour(MtaServer server, IElementRepository elementRepository)
    {
        this.collisionShapes = new HashSet <CollisionShape>();
        foreach (var collisionShape in elementRepository.GetByType <CollisionShape>(ElementType.Colshape))
        {
            this.AddCollisionShape(collisionShape);
        }

        server.ElementCreated += OnElementCreate;
        this.server            = server;
    }
    public RadarAreaBehaviour(MtaServer server, IElementRepository elementRepository)
    {
        this.server     = server;
        this.radarAreas = new HashSet <RadarArea>();
        foreach (var radarArea in elementRepository.GetByType <RadarArea>(ElementType.RadarArea))
        {
            AddRadarArea(radarArea);
        }

        server.ElementCreated += OnElementCreate;
    }
Beispiel #6
0
    public TypeFilteredCollisionShapeBehaviour(MtaServer server, IElementRepository elementRepository, IEnumerable <Type> types)
    {
        this.types = new HashSet <Type>(types);

        this.collisionShapes = new HashSet <CollisionShape>();
        foreach (var collisionShape in elementRepository.GetByType <CollisionShape>(ElementType.Colshape))
        {
            this.AddCollisionShape(collisionShape);
        }

        server.ElementCreated += OnElementCreate;
    }
    public VoiceBehaviour(MtaServer server, IElementRepository elementRepository)
    {
        server.PlayerJoined += (player) =>
        {
            player.VoiceDataReceived += (sender, args) =>
            {
                var packet       = new VoiceDataPacket(player.Id, args.DataBuffer);
                var otherPlayers = elementRepository.GetByType <Player>(ElementType.Player)
                                   .Where(p => p.Client != player.Client).ToArray();

                packet.SendTo(otherPlayers);
            };

            player.VoiceDataEnded += (sender, args) =>
            {
                var packet       = new VoiceEndPacket(player.Id);
                var otherPlayers = elementRepository.GetByType <Player>(ElementType.Player)
                                   .Where(p => p.Client != player.Client).ToArray();

                packet.SendTo(otherPlayers);
            };
        };
    }
Beispiel #8
0
 public DefaultChatBehaviour(IElementRepository elementRepository, ILogger?logger)
 {
     Player.OnJoin += (player) =>
     {
         player.OnCommand += (command, arguments) =>
         {
             if (command == "say")
             {
                 string message = $"{player.Name}: {string.Join(' ', arguments)}";
                 var    packet  = new ChatEchoPacket(player.Id, message, Color.White);
                 foreach (var _player in elementRepository.GetByType <Player>(ElementType.Player))
                 {
                     _player.Client.SendPacket(packet);
                     logger?.LogInformation(message);
                 }
             }
         };
     };
 }