Esempio n. 1
0
        protected override void WriteBoard(PacketWriter stream)
        {
            // players
            byte count    = 0;
            int  countPos = stream.Position++;

            ArenaClient.ForEach(c =>
            {
                if (c.GMTeamID >= TeamIdent.GMPlayer)
                {
                    WritePlayer(c, stream);
                    count++;
                }
            });
            stream.Edit(countPos, count);

            // spectators
            count    = 0;
            countPos = stream.Position++;
            ArenaClient.ForEach(c =>
            {
                if (c.GMTeamID == TeamIdent.GMSpectator)
                {
                    WritePlayer(c, stream);
                    count++;
                }
            });
            stream.Edit(countPos, count);
        }
Esempio n. 2
0
    private AliceClient(
        Guid aliceId,
        RoundState roundState,
        ArenaClient arenaClient,
        SmartCoin coin,
        OwnershipProof ownershipProof,
        IEnumerable <Credential> issuedAmountCredentials,
        IEnumerable <Credential> issuedVsizeCredentials,
        bool isPayingZeroCoordinationFee)
    {
        var roundParameters = roundState.CoinjoinState.Parameters;

        AliceId                     = aliceId;
        RoundId                     = roundState.Id;
        ArenaClient                 = arenaClient;
        SmartCoin                   = coin;
        OwnershipProof              = ownershipProof;
        FeeRate                     = roundParameters.MiningFeeRate;
        CoordinationFeeRate         = roundParameters.CoordinationFeeRate;
        IssuedAmountCredentials     = issuedAmountCredentials;
        IssuedVsizeCredentials      = issuedVsizeCredentials;
        MaxVsizeAllocationPerAlice  = roundParameters.MaxVsizeAllocationPerAlice;
        ConfirmationTimeout         = roundParameters.ConnectionConfirmationTimeout / 2;
        IsPayingZeroCoordinationFee = isPayingZeroCoordinationFee;
    }
Esempio n. 3
0
        public void RespawnClient(ArenaClient client)
        {
            if (Phase < GamePhase.Fight)
            {
                return;
            }

            Vec3f nextStand = Stands[0].Stand.Position;
            // find player closest to next stand
            IEnumerable <Vec3f> positions = StandingPlayers.Select(p => p.Character.GetPosition());

            if (!Vec3f.FindClosest(Stands[0].Stand.Position, positions, out Vec3f best))
            {
                return;
            }

            // two closest respawns to player
            IEnumerable <Vec3f> x = Scenario.Respawns.OrderBy(p => p.GetDistance(best)).Take(2);

            // closest of the two respawns to next stand
            if (!Vec3f.FindClosest(best, x, out Vec3f result))
            {
                return;
            }

            var npc = SpawnCharacter(client, World, result, 100);

            npc.DropUnconscious();
        }
Esempio n. 4
0
        void OnHit(NPCInst attacker, NPCInst target, int damage)
        {
            if (!IsActive || ActiveMode.Phase < GamePhase.Fight)
            {
                return;
            }

            if (attacker.IsPlayer)
            {
                if (target.IsPlayer)
                {
                    return;
                }

                ArenaClient player = (ArenaClient)attacker.Client;
                player.GMScore += damage / 10.0f;
                if (target.HP <= 0)
                {
                    player.GMKills++;
                    player.GMScore += 5;
                }
            }
            else if (target.IsPlayer)
            {
                ArenaClient player = (ArenaClient)target.Client;
                if (target.HP <= 1)
                {
                    player.GMDeaths++;
                    if (players.TrueForAll(p => !p.IsCharacter || p.Character.IsDead || p.Character.IsUnconscious))
                    {
                        HordeFadeOut(false);
                    }
                }
            }
        }
Esempio n. 5
0
        protected virtual NPCInst SpawnCharacter(ArenaClient client, WorldInst world, PosAng spawnPoint)
        {
            // only spawn if player has joined the game mode and chosen a class
            if (client == null || !client.GMJoined || client.GMClass == null)
            {
                return(null);
            }

            // get rid of old character if there is one
            client.KillCharacter();

            NPCInst npc = CreateNPC(client.GMClass, (int)client.GMTeamID, client.CharInfo);

            npc.Spawn(world, spawnPoint.Position, spawnPoint.Angles);
            client.SetControl(npc);

            // start the warm up phase as soon as the first player joins
            if (Phase == GamePhase.None && players.Count(p => p.IsCharacter) == 1)
            {
                SetPhase(GamePhase.WarmUp);
                phaseTimer.SetInterval(Scenario.WarmUpDuration);
                phaseTimer.SetCallback(Fight);
                phaseTimer.Restart();
            }
            return(npc);
        }
Esempio n. 6
0
        public void JoinTeam(ArenaClient client, int index)
        {
            if (Phase == GamePhase.FadeOut)
            {
                return;
            }

            if (index < 0 || index >= teams.Count)
            {
                return;
            }

            var team = teams[index];

            if (client.TDMTeam == team)
            {
                return;
            }

            if (client.TDMTeam != null)
            {
                client.KillCharacter();
                client.TDMTeam.Players.Remove(client);
                client.GMClass = null;
            }

            client.TDMTeam = team;
            team.Players.Add(client);
            client.SetTeamID((TeamIdent)index);
        }
Esempio n. 7
0
        void SelectClass(int index)
        {
            if (!HordeMode.IsActive || PlayerInfo.HeroInfo.TeamID < TeamIdent.GMSpectator || GameMode.ActiveMode.Phase == GamePhase.FadeOut)
            {
                Close();
                return;
            }

            if (!HordeMode.ActiveMode.Scenario.PlayerClasses.TryGet(index, out NPCClass classDef))
            {
                return;
            }

            if (classDef == NPCClass.Hero)
            {
                Close();
                return;
            }

            if (!lockTimer.IsReady)
            {
                return;
            }

            var stream = ArenaClient.GetStream(ScriptMessages.ModeClassSelect);

            stream.Write((byte)index);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);

            NPCClass.Hero = classDef;

            Close();
        }
Esempio n. 8
0
        public static void DuelWin(ArenaClient winner)
        {
            if (!winner.IsDueling)
            {
                return;
            }

            var stream = ArenaClient.GetStream(ScriptMessages.DuelWin);

            stream.Write((ushort)winner.Character.ID);
            winner.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered);
            if (winner.DuelEnemy.IsConnected)
            {
                winner.DuelEnemy.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered);
            }

            winner.DuelEnemy.DuelDeaths++;
            winner.DuelEnemy.DuelScore--;

            winner.DuelKills++;
            winner.DuelScore += 2;

            winner.DuelEnemy.DuelEnemy = null;
            winner.DuelEnemy           = null;
        }
Esempio n. 9
0
        void SelectTeam(int index)
        {
            if (!TDMMode.IsActive)
            {
                return;
            }

            var teams = TDMMode.ActiveMode.Scenario.Teams;

            if (index < 0 || index >= teams.Length)
            {
                return;
            }

            if ((int)PlayerInfo.HeroInfo.TeamID == index)
            {
                MenuClassSelect.Instance.Open();
                Close();
                return;
            }

            if (!lockTimer.IsReady)
            {
                return;
            }

            var stream = ArenaClient.GetStream(ScriptMessages.TDMTeamSelect);

            stream.Write((byte)index);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
        }
Esempio n. 10
0
        void Spectate()
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.SpectateTeam);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
            Close();
        }
Esempio n. 11
0
 void Join()
 {
     if (PlayerInfo.HeroInfo.TeamID != GameModes.TeamIdent.FFAPlayer)
     {
         ArenaClient.SendJoinGameMessage();
     }
     Close();
 }
Esempio n. 12
0
 void Spectate()
 {
     if (PlayerInfo.HeroInfo.TeamID != GameModes.TeamIdent.FFASpectator)
     {
         ArenaClient.SendSpectateMessage();
     }
     Close();
 }
Esempio n. 13
0
        protected override NPCInst SpawnCharacter(ArenaClient client, WorldInst world, PosAng spawnPoint)
        {
            NPCInst pc = base.SpawnCharacter(client, world, spawnPoint);

            pc.AllowHitTarget.Add(OnAllowHit);
            pc.DropUnconsciousOnDeath = true;
            pc.UnconsciousDuration    = -1;
            return(pc);
        }
Esempio n. 14
0
 void Spectate()
 {
     if (PlayerInfo.HeroInfo.TeamID != TeamIdent.GMSpectator)
     {
         var stream = ArenaClient.GetStream(ScriptMessages.ModeSpectate);
         ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered);
     }
     Close();
 }
Esempio n. 15
0
 void Join()
 {
     if (PlayerInfo.HeroInfo.TeamID < TeamIdent.GMPlayer)
     {
         var stream = ArenaClient.GetStream(ScriptMessages.BRJoin);
         ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
     }
     Close();
 }
Esempio n. 16
0
        static void SendRequest(ArenaClient requester, ArenaClient target)
        {
            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.DuelRequest);
            stream.Write((ushort)requester.Character.ID);
            stream.Write((ushort)target.Character.ID);
            requester.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
            target.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);
        }
Esempio n. 17
0
        protected void SetPhase(GamePhase phase)
        {
            this.Phase = phase;
            Log.Logger.Log("Set Phase " + phase);

            // send phase update to clients
            var stream = ArenaClient.GetStream(ScriptMessages.ModePhase);

            stream.Write((byte)Phase);
            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));
        }
Esempio n. 18
0
        void FFAStart()
        {
            if (ArenaClient.FFAJoined)
            {
                FreeModeMenu.Instance.Open();
                return;
            }

            ArenaClient.SendSpectateMessage();
            Close();
        }
Esempio n. 19
0
        public override void OnSuicide(ArenaClient client)
        {
            if (Phase < GamePhase.Fight)
            {
                return;
            }

            client.GMScore--;
            client.GMDeaths++;
            client.TDMTeam.Score--;
        }
Esempio n. 20
0
        public async Task SignTransactionAsync()
        {
            WabiSabiConfig config = new();
            Round          round  = WabiSabiFactory.CreateRound(config);

            using Key key1 = new();
            Alice alice1 = WabiSabiFactory.CreateAlice(key: key1);

            round.Alices.Add(alice1);

            using Key key2 = new();
            Alice alice2 = WabiSabiFactory.CreateAlice(key: key2);

            round.Alices.Add(alice2);

            var coinjoin = round.Coinjoin;

            using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(config, round);

            var mockRpc = new Mock <IRPCClient>();

            await using var coordinator = new ArenaRequestHandler(config, new Prison(), arena, mockRpc.Object);

            var rnd          = new InsecureRandom();
            var amountClient = new WabiSabiClient(round.AmountCredentialIssuerParameters, 2, rnd, 4300000000000ul);
            var weightClient = new WabiSabiClient(round.WeightCredentialIssuerParameters, 2, rnd, 2000ul);
            var apiClient    = new ArenaClient(amountClient, weightClient, coordinator);

            round.SetPhase(Phase.TransactionSigning);

            // No inputs in the CoinJoin.
            await Assert.ThrowsAsync <ArgumentException>(async() => await apiClient.SignTransactionAsync(round.Id, alice1.Coins.ToArray(), new BitcoinSecret(key1, Network.Main), coinjoin));

            coinjoin.Inputs.Add(alice1.Coins.First().Outpoint);

            // Trying to sign coins those are not in the CoinJoin.
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await apiClient.SignTransactionAsync(round.Id, alice2.Coins.ToArray(), new BitcoinSecret(key2, Network.Main), coinjoin));

            coinjoin.Inputs.Add(alice2.Coins.First().Outpoint);

            // Trying to sign coins with the wrong secret.
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await apiClient.SignTransactionAsync(round.Id, alice1.Coins.ToArray(), new BitcoinSecret(key2, Network.Main), coinjoin));

            Assert.False(round.Coinjoin.HasWitness);

            await apiClient.SignTransactionAsync(round.Id, alice1.Coins.ToArray(), new BitcoinSecret(key1, Network.Main), coinjoin);

            Assert.True(round.Coinjoin.Inputs.Where(i => alice1.Coins.Select(c => c.Outpoint).Contains(i.PrevOut)).All(i => i.HasWitScript()));

            await apiClient.SignTransactionAsync(round.Id, alice2.Coins.ToArray(), new BitcoinSecret(key2, Network.Main), coinjoin);

            Assert.True(round.Coinjoin.Inputs.Where(i => alice2.Coins.Select(c => c.Outpoint).Contains(i.PrevOut)).All(i => i.HasWitScript()));
        }
Esempio n. 21
0
    public async Task <ArenaClient> CreateArenaClientAsync(WabiSabiHttpApiClient wabiSabiHttpApiClient)
    {
        var rounds         = (await wabiSabiHttpApiClient.GetStatusAsync(RoundStateRequest.Empty, CancellationToken.None)).RoundStates;
        var round          = rounds.First(x => x.CoinjoinState is ConstructionState);
        var insecureRandom = new InsecureRandom();
        var arenaClient    = new ArenaClient(
            round.CreateAmountCredentialClient(insecureRandom),
            round.CreateVsizeCredentialClient(insecureRandom),
            wabiSabiHttpApiClient);

        return(arenaClient);
    }
Esempio n. 22
0
        public void Join(ArenaClient client)
        {
            if (Phase != GamePhase.WarmUp)
            {
                return;
            }

            players.Add(client);

            client.GMClass = BRScenario.StartClass;
            SpawnCharacter(client, World, Randomizer.Get(Scenario.Spawnpoints));
        }
Esempio n. 23
0
        public override void Close()
        {
            base.Close();
            arrow.Hide();

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.TOTeamCount);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Reliable);

            TeamMode.OnPhaseChange -= TOPhaseChanged;
        }
Esempio n. 24
0
        protected virtual void Start(GameScenario scenario)
        {
            this.Scenario = scenario;

            var stream = ArenaClient.GetStream(ScriptMessages.ModeStart);

            stream.Write(scenario.Name);
            ArenaClient.ForEach(c => c.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered));
            Phase = GamePhase.None;

            phaseTimer.Stop();
        }
Esempio n. 25
0
        public static void SendRequest(NPCInst target)
        {
            if (!requestTime.IsReady)
            {
                return;
            }

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.DuelRequest);
            stream.Write((ushort)target.ID);
            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.Unreliable);
        }
Esempio n. 26
0
        void GameModeStart()
        {
            if (ArenaClient.GMJoined)
            {
                GameMode.ActiveMode.OpenJoinMenu();
                return;
            }

            var stream = ArenaClient.GetStream(ScriptMessages.ModeSpectate);

            ArenaClient.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered);
            Close();
        }
Esempio n. 27
0
        public override void OnSuicide(ArenaClient client)
        {
            if (Phase < GamePhase.Fight)
            {
                return;
            }

            client.GMDeaths++;
            if (players.TrueForAll(p => !p.IsCharacter || p.Character.IsDead || p.Character.IsUnconscious))
            {
                HordeFadeOut(false);
            }
        }
Esempio n. 28
0
        public override bool Leave(ArenaClient client)
        {
            if (!base.Leave(client))
            {
                return(false);
            }

            if (client.TDMTeam != null)
            {
                client.TDMTeam.Players.Remove(client);
                client.TDMTeam = null;
            }
            return(true);
        }
Esempio n. 29
0
        protected virtual NPCInst InitialSpawnClient(ArenaClient client, bool inSpawnWorld)
        {
            NPCInst npc;

            if (inSpawnWorld && SpawnWorld != null)
            {
                npc = SpawnCharacter(client, SpawnWorld, Scenario.SpawnWorldPos, Scenario.SpawnWorldRange);
            }
            else
            {
                npc = SpawnCharacter(client, World, Scenario.SpawnPos, Scenario.SpawnRange);
            }
            return(npc);
        }
Esempio n. 30
0
        static void DuelEnd(ArenaClient client)
        {
            if (!client.IsDueling)
            {
                return;
            }

            var stream = ArenaClient.GetScriptMessageStream();

            stream.Write((byte)ScriptMessages.DuelEnd);
            client.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered);
            client.DuelEnemy.SendScriptMessage(stream, NetPriority.Low, NetReliability.ReliableOrdered);

            client.DuelEnemy.DuelEnemy = null;
            client.DuelEnemy           = null;
        }