コード例 #1
0
        public bool Matches(NetPlayer player)
        {
            switch (Type)
            {
            case IdentityType.Ip:
                return(player.Peer.RemoteEndPoint.Address.ToUint32() == Ip);

            case IdentityType.SteamId:
                return(player.SteamId == SteamId);
            }

            throw new NotImplementedException("Unimplemented IdentityType");
        }
コード例 #2
0
        public void Spectate(NetPlayer target)
        {
            if (SpectateTarget == target)
            {
                return;
            }

            bool wasSpectating = SpectateTarget != null;

            SpectateTarget = target;

            // Send message to connection to start/stop spectating target
            var netMessage = server.CreateMessage();

            netMessage.Write(MessageType.SpectateTarget);
            netMessage.Write(target?.Id ?? 0);

            Peer.SendMessage(netMessage, NetDeliveryMethod.ReliableOrdered, 0);

            netMessage = server.CreateMessage();

            if (target != null && !wasSpectating) // Started spectating
            {
                // Stop people from spectating this player
                foreach (var netPlayer in server.Players.Values)
                {
                    if (netPlayer.SpectateTarget == this)
                    {
                        netPlayer.Spectate(null);
                    }
                }

                // Broadcast message to all other peers to remove this peers player (if he wasn't spectating already, otherwise he would already be despawned)
                netMessage.Write(MessageType.RemovePlayer);
                netMessage.Write(Id);

                server.Broadcast(netMessage, NetDeliveryMethod.ReliableOrdered, 0, Peer);
            }
            else if (target == null) // Stopped spectating
            {
                // Broadcast message to all other peers to add this peers player
                netMessage.Write(MessageType.CreatePlayer);
                netMessage.Write(Id);
                netMessage.Write(Name);
                netMessage.Write(Movement);
                netMessage.Write(Wins);
                netMessage.Write(Goldness);
                netMessage.WriteRgbaColor(PotColor);
                server.Broadcast(netMessage, NetDeliveryMethod.ReliableOrdered, 0, Peer);
            }
        }