public void CreateExplosionFor_SendsPacketsToChosenClients()
    {
        var mtaServer = new TestingServer();
        var players   = new TestingPlayer[] {
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
        };
        var additionalPlayers = new TestingPlayer[]
        {
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
        };

        var service = new ExplosionService(mtaServer);

        service.CreateExplosionFor(players, Vector3.Zero, Enums.ExplosionType.WeakRocket);

        foreach (var player in players)
        {
            mtaServer.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_EXPLOSION, player);
        }
        foreach (var player in additionalPlayers)
        {
            mtaServer.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_EXPLOSION, player, count: 0);
        }
    }
Ejemplo n.º 2
0
    public void CreateFireFor_SendsPacketsToChosenClients()
    {
        var mtaServer = new TestingServer();
        var players   = new TestingPlayer[] {
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
        };
        var additionalPlayers = new TestingPlayer[]
        {
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
        };

        var service = new FireService(mtaServer);

        service.CreateFireFor(players, Vector3.Zero);

        foreach (var player in players)
        {
            mtaServer.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_FIRE, player);
        }
        foreach (var player in additionalPlayers)
        {
            mtaServer.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_FIRE, player, count: 0);
        }
    }
Ejemplo n.º 3
0
    public void BroadcastPacket_SendsPacketToAllPlayers()
    {
        var server = new TestingServer();

        var player  = server.AddFakePlayer();
        var player2 = server.AddFakePlayer();

        server.BroadcastPacket(new SetElementModelRpcPacket(player.Id, 0));

        server.VerifyPacketSent(PacketId.PACKET_ID_LUA_ELEMENT_RPC, player);
        server.VerifyPacketSent(PacketId.PACKET_ID_LUA_ELEMENT_RPC, player2);
    }
Ejemplo n.º 4
0
    public void HandlePacketRelaysPureSyncPacket()
    {
        var server       = new TestingServer();
        var sourcePlayer = server.AddFakePlayer();
        var otherPlayers = new TestingPlayer[] { server.AddFakePlayer(), server.AddFakePlayer(), server.AddFakePlayer() };

        Mock <ILogger> loggerMock = new();

        Mock <ISyncHandlerMiddleware <PlayerPureSyncPacket> > middlewareMock = new();

        middlewareMock.Setup(x => x.GetPlayersToSyncTo(sourcePlayer, It.IsAny <PlayerPureSyncPacket>())).Returns(otherPlayers);

        Mock <IElementCollection> elementCollectionMock = new();

        var handler = new PlayerPureSyncPacketHandler(loggerMock.Object, middlewareMock.Object, elementCollectionMock.Object);

        handler.HandlePacket(sourcePlayer.Client, new PlayerPureSyncPacket()
        {
        });

        foreach (var player in otherPlayers)
        {
            server.VerifyPacketSent(PacketId.PACKET_ID_PLAYER_PURESYNC, player);
        }
    }
    public void ClientOutOfScope_DoesNotSendPacket()
    {
        var server = new TestingServer();

        var player = server.AddFakePlayer();

        using var scope = new ClientPacketScope(Array.Empty <IClient>());
        player.Client.SendPacket(new SetElementModelRpcPacket(player.Id, 0));

        server.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_LUA_ELEMENT_RPC, player, count: 0);
    }
    public void ClientInScope_SendsPacket()
    {
        var server = new TestingServer();

        var player = server.AddFakePlayer();

        using var scope = new ClientPacketScope(new IClient[] { player.Client });
        player.Client.SendPacket(new SetElementModelRpcPacket(player.Id, 0));

        server.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_LUA_ELEMENT_RPC, player);
    }
Ejemplo n.º 7
0
    public void CreateFire_SendsExpectedPacket()
    {
        var mtaServer = new TestingServer();
        var player    = mtaServer.AddFakePlayer();

        var service = new FireService(mtaServer);

        service.CreateFire(Vector3.Zero, 2);

        var expectedPacket = new FirePacket(Vector3.Zero, 2);

        mtaServer.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_FIRE, player, expectedPacket.Write());
    }
    public void CreateExplosion_SendsExpectedPacket()
    {
        var mtaServer = new TestingServer();
        var player    = mtaServer.AddFakePlayer();

        var service = new ExplosionService(mtaServer);

        service.CreateExplosion(Vector3.Zero, Enums.ExplosionType.WeakRocket);

        var expectedPacket = new ExplosionPacket(null, null, Vector3.Zero, (byte)Enums.ExplosionType.WeakRocket, 0);

        mtaServer.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_EXPLOSION, player, expectedPacket.Write());
    }
Ejemplo n.º 9
0
    public void CreateFire_BroadcastsFirePacket()
    {
        var mtaServer = new TestingServer();
        var players   = new TestingPlayer[] {
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
        };

        var service = new FireService(mtaServer);

        service.CreateFire(Vector3.Zero);

        foreach (var player in players)
        {
            mtaServer.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_FIRE, player);
        }
    }
Ejemplo n.º 10
0
    public void CreateExplosion_BroadcastsExplosionPacket()
    {
        var mtaServer = new TestingServer();
        var players   = new TestingPlayer[] {
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
            mtaServer.AddFakePlayer(),
        };

        var service = new ExplosionService(mtaServer);

        service.CreateExplosion(Vector3.Zero, Enums.ExplosionType.WeakRocket);

        foreach (var player in players)
        {
            mtaServer.VerifyPacketSent(Packets.Enums.PacketId.PACKET_ID_EXPLOSION, player);
        }
    }