breaking: Eliminates RemovePlayerMessage As Security Risk (#1835)

* fix: Deprecate RemovePlayerMessage As Security Risk

* Updated PreprocessorDefine

* Updating for changes in master

* Updating for changes in master

* Removed the error flag so tests could still pass
This commit is contained in:
MrGadget 2020-05-03 10:45:53 -04:00 committed by GitHub
parent 2a08aac7cb
commit 75f3975041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 63 deletions

View File

@ -26,7 +26,8 @@ public static void AddDefineSymbols()
"MIRROR_9_0_OR_NEWER",
"MIRROR_10_0_OR_NEWER",
"MIRROR_11_0_OR_NEWER",
"MIRROR_12_0_OR_NEWER"
"MIRROR_12_0_OR_NEWER",
"MIRROR_13_0_OR_NEWER"
};
// only touch PlayerSettings if we actually modified it.

View File

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using UnityEngine;
using Guid = System.Guid;
@ -121,27 +123,12 @@ public static bool AddPlayer(NetworkConnection readyConn)
return true;
}
// Deprecated 5/2/2020
/// <summary>
/// Removes the player from the game.
/// Obsolete: Removed as a security risk. Use <see cref="NetworkServer.RemovePlayerForConnection(NetworkConnection, GameObject, bool)"/> instead.
/// </summary>
/// <returns>True if succcessful</returns>
public static bool RemovePlayer()
{
if (logger.LogEnabled()) logger.Log("ClientScene.RemovePlayer() called with connection [" + readyConnection + "]");
if (readyConnection.identity != null)
{
readyConnection.Send(new RemovePlayerMessage());
Object.Destroy(readyConnection.identity.gameObject);
readyConnection.identity = null;
localPlayer = null;
return true;
}
return false;
}
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Removed as a security risk. Use NetworkServer.RemovePlayerForConnection(NetworkConnection conn, GameObject player, bool keepAuthority = false) instead", true)]
public static bool RemovePlayer() { return false; }
/// <summary>
/// Signal that the client connection is ready to enter the game.

View File

@ -61,6 +61,11 @@ public void Deserialize(NetworkReader reader) { }
public void Serialize(NetworkWriter writer) { }
}
// Deprecated 5/2/2020
/// <summary>
/// Obsolete: Removed as a security risk. Use <see cref="NetworkServer.RemovePlayerForConnection(NetworkConnection, GameObject, bool)"/> instead.
/// </summary>
[Obsolete("Removed as a security risk. Use NetworkServer.RemovePlayerForConnection(NetworkConnection conn, GameObject player, bool keepAuthority = false) instead")]
public struct RemovePlayerMessage : IMessageBase
{
public void Deserialize(NetworkReader reader) { }

View File

@ -736,7 +736,6 @@ void RegisterServerMessages()
// Network Server initially registers it's own handlers for these, so we replace them here.
NetworkServer.ReplaceHandler<ReadyMessage>(OnServerReadyMessageInternal);
NetworkServer.ReplaceHandler<RemovePlayerMessage>(OnServerRemovePlayerMessageInternal);
}
void RegisterClientMessages()
@ -1186,16 +1185,12 @@ void OnServerAddPlayerInternal(NetworkConnection conn, AddPlayerMessage msg)
OnServerAddPlayer(conn);
}
void OnServerRemovePlayerMessageInternal(NetworkConnection conn, RemovePlayerMessage msg)
{
if (LogFilter.Debug) Debug.Log("NetworkManager.OnServerRemovePlayerMessageInternal");
if (conn.identity != null)
{
OnServerRemovePlayer(conn, conn.identity);
conn.identity = null;
}
}
// Deprecated 5/2/2020
/// <summary>
/// Obsolete: Removed as a security risk. Use <see cref="NetworkServer.RemovePlayerForConnection(NetworkConnection, GameObject, bool)"/> instead.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Removed as a security risk. Use NetworkServer.RemovePlayerForConnection(NetworkConnection conn, GameObject player, bool keepAuthority = false) instead", true)]
void OnServerRemovePlayerMessageInternal(NetworkConnection conn, RemovePlayerMessage msg) { }
void OnServerErrorInternal(NetworkConnection conn, ErrorMessage msg)
{
@ -1354,19 +1349,12 @@ public Transform GetStartPosition()
}
}
// Deprecated 5/2/2020
/// <summary>
/// Called on the server when a client removes a player.
/// <para>The default implementation of this function destroys the corresponding player object.</para>
/// Obsolete: Removed as a security risk. Use <see cref="NetworkServer.RemovePlayerForConnection(NetworkConnection, GameObject, bool)"/> instead.
/// </summary>
/// <param name="conn">The connection to remove the player from.</param>
/// <param name="player">The player identity to remove.</param>
public virtual void OnServerRemovePlayer(NetworkConnection conn, NetworkIdentity player)
{
if (player.gameObject != null)
{
NetworkServer.Destroy(player.gameObject);
}
}
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Removed as a security risk. Use NetworkServer.RemovePlayerForConnection(NetworkConnection conn, GameObject player, bool keepAuthority = false) instead", true)]
public virtual void OnServerRemovePlayer(NetworkConnection conn, NetworkIdentity player) { }
/// <summary>
/// Called on the server when a network error occurs for a client connection.

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
namespace Mirror
@ -138,7 +139,6 @@ internal static void RegisterMessageHandlers()
{
RegisterHandler<ReadyMessage>(OnClientReadyMessage);
RegisterHandler<CommandMessage>(OnCommandMessage);
RegisterHandler<RemovePlayerMessage>(OnRemovePlayerMessage);
RegisterHandler<NetworkPingMessage>(NetworkTime.OnServerPing, false);
}
@ -924,15 +924,12 @@ static void OnClientReadyMessage(NetworkConnection conn, ReadyMessage msg)
SetClientReady(conn);
}
// default remove player handler
static void OnRemovePlayerMessage(NetworkConnection conn, RemovePlayerMessage msg)
{
if (conn.identity != null)
{
Destroy(conn.identity.gameObject);
conn.identity = null;
}
}
// Deprecated 5/2/2020
/// <summary>
/// Obsolete: Removed as a security risk. Use <see cref="NetworkServer.RemovePlayerForConnection(NetworkConnection, GameObject, bool)"/> instead.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("Removed as a security risk. Use NetworkServer.RemovePlayerForConnection(NetworkConnection conn, GameObject player, bool keepAuthority = false) instead", true)]
static void OnRemovePlayerMessage(NetworkConnection conn, RemovePlayerMessage msg) { }
/// <summary>
/// Removes the player object from the connection

View File

@ -148,17 +148,6 @@ public class #SCRIPTNAME# : NetworkManager
base.OnServerAddPlayer(conn);
}
/// <summary>
/// Called on the server when a client removes a player.
/// <para>The default implementation of this function destroys the corresponding player object.</para>
/// </summary>
/// <param name="conn">The connection to remove the player from.</param>
/// <param name="player">The player identity to remove.</param>
public override void OnServerRemovePlayer(NetworkConnection conn, NetworkIdentity player)
{
base.OnServerRemovePlayer(conn, player);
}
/// <summary>
/// Called on the server when a client disconnects.
/// <para>This is called on the Server when a Client disconnects from the Server. Use an override to decide what should happen when a disconnection is detected.</para>