Пример #1
0
    private void HandleIngameNotice(IClient client)
    {
        var players = this.elementCollection.GetByType <Elements.Player>(ElementType.Player);

        var isVersionValid = Version.TryParse(string.Join(".", client.Version !.Replace("-", ".").Split(".").Take(4)), out Version? result);

        if (!isVersionValid)
        {
            client.Player.Kick(PlayerDisconnectType.BAD_VERSION);
            return;
        }

        if (result < this.configuration.MinVersion)
        {
            client.SendPacket(PlayerPacketFactory.CreateUpdateInfoPacket(this.configuration.MinVersion));
            client.Player.Kick($"Disconnected: Minimum mta version required: {this.configuration.MinVersion}");
            return;
        }

        client.SendPacket(new JoinedGamePacket(
                              client.Player.Id,
                              players.Count() + 1,
                              this.root.Id,
                              this.configuration.HttpUrl != null ? HttpDownloadType.HTTP_DOWNLOAD_ENABLED_URL : HttpDownloadType.HTTP_DOWNLOAD_ENABLED_PORT,
                              this.configuration.HttpPort,
                              this.configuration.HttpUrl ?? "",
                              this.configuration.HttpConnectionsPerClient,
                              1,
                              isVoiceEnabled: this.configuration.IsVoiceEnabled
                              ));

        var otherPlayers = players
                           .Except(new Elements.Player[] { client.Player })
                           .ToArray();

        var existingPlayersListPacket = PlayerPacketFactory.CreatePlayerListPacket(otherPlayers, true);

        client.SendPacket(existingPlayersListPacket);

        var newPlayerListPacket = PlayerPacketFactory.CreatePlayerListPacket(new Elements.Player[] { client.Player }, false);

        newPlayerListPacket.SendTo(otherPlayers);

        SyncPacketFactory.CreateSyncSettingsPacket(this.configuration).SendTo(client.Player);
        SyncPacketFactory.CreateSyncIntervalPacket(this.configuration).SendTo(client.Player);

        foreach (var player in otherPlayers)
        {
            if (player.GetAllStats().Count > 0)
            {
                PedPacketFactory.CreatePlayerStatsPacket(player).SendTo(client.Player);
            }

            if (player.GetAllStats().Count > 0)
            {
                PedPacketFactory.CreateFullClothesPacket(player).SendTo(client.Player);
            }
        }

        this.server.HandlePlayerJoin(client.Player);
    }
Пример #2
0
    private void RelayStatChanged(Ped sender, PedStatChangedEventArgs e)
    {
        var packet = PedPacketFactory.CreatePlayerStatsPacket(sender);

        this.server.BroadcastPacket(packet);
    }