void RemoveNetPlayer(NetConnection connection) { NetworkPlayer netPlayer; if (netPlayers.TryGetValue(connection, out netPlayer)) { netPlayers.Remove(connection); // Remove netplayer from every players world snapshot foreach (NetConnectionSnapshotState state in snapshotComponent.ConnectionStates.Values) { state.WorldSnapshot.NetworkPlayerListSnapshot.RemoveNetPlayer(netPlayer); } // Tell each client this player has left channel.FireEventForAllConnections("Client_RemoveNetPlayer", netPlayer.Id); if (OnClientLeave != null) { OnClientLeave(connection, netPlayer); } } }
public override PlayerRaycastResult RaycastPlayers(Ray ray, float maxDist = float.MaxValue, params Player[] ignore) { bool sv_impacts = DashCMD.GetCVar <bool>("sv_impacts"); bool sv_hitboxes = DashCMD.GetCVar <bool>("sv_hitboxes"); ServerMPPlayer hitPlayer = null; float? hitPlayerAt = null; foreach (ServerMPPlayer otherPlayer in players.Values) { // Make sure we aren't ignoring this player if (ignore.Length == 0 || !Array.Exists(ignore, (x => x == otherPlayer))) { Vector3 otherPlayerPosition; float otherPlayerCamYaw; if (rollbackTime.HasValue) { // We are applying rollback, so find the players old transform int otherPlayerPing = DashCMD.GetCVar <bool>("rp_usetargetping") ? otherPlayer.StateInfo.Owner.Stats.Ping : 0; int rollbackFrame = MathHelper.Clamp(otherPlayerPing + rollbackTime.Value, 0, 1000); if (sv_hitboxes) { DashCMD.WriteLine("[RB] Rolling back bullet-player transform by {0}ms [target ping: {1}ms]", ConsoleColor.Green, rollbackTime, otherPlayerPing); } PlayerTransform otherPlayerTransform = otherPlayer.RollbackTransform(Environment.TickCount - rollbackFrame); otherPlayerPosition = otherPlayerTransform.Position; otherPlayerCamYaw = otherPlayerTransform.CameraYaw; } else { // No rollback currently, use current transform otherPlayerPosition = otherPlayer.Transform.Position; otherPlayerCamYaw = otherPlayer.GetCamera().Yaw; } if (sv_hitboxes) { channel.FireEventForAllConnections("Client_RolledBackServerPlayer", otherPlayerPosition.X, otherPlayerPosition.Y, otherPlayerPosition.Z, (byte)otherPlayer.Team); } Ray newRay = new Ray(ray.Origin - otherPlayerPosition, ray.Direction); float?dist; // Check for intersection if (newRay.Intersects(otherPlayer.GetOrientatedBoundingBox(otherPlayerCamYaw), out dist)) { // If the distance is out of bounds, ignore if (dist.Value > maxDist) { continue; } // Only update the intersected player if it was closer than the last if (!hitPlayerAt.HasValue || dist.Value < hitPlayerAt.Value) { hitPlayer = otherPlayer; hitPlayerAt = dist.Value; } } } } if (hitPlayer != null) { return(new PlayerRaycastResult(ray, true, ray.Origin + ray.Direction * hitPlayerAt.Value, hitPlayerAt, hitPlayer)); } else { return(new PlayerRaycastResult(ray)); } }