mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
LocalConnections: removed redundant functions. no need to overwrite SendByChannel, as NetworkConnection.SendByChannel calls SendBytes anyway. Also removed NetworkServer.InvokeHandler since it's not needed anymore. InvokeBytes is the way to go.
This commit is contained in:
parent
8f44c9aabb
commit
9fb8b071c6
@ -5,8 +5,7 @@
|
||||
namespace UnityEngine.Networking
|
||||
{
|
||||
// a server's connection TO a LocalClient.
|
||||
// sending messages on this connection causes the client's
|
||||
// handler function to be invoked directly
|
||||
// sending messages on this connection causes the client's handler function to be invoked directly
|
||||
class ULocalConnectionToClient : NetworkConnection
|
||||
{
|
||||
LocalClient m_LocalClient;
|
||||
@ -19,14 +18,6 @@ public ULocalConnectionToClient(LocalClient localClient)
|
||||
m_LocalClient = localClient;
|
||||
}
|
||||
|
||||
public override bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
||||
{
|
||||
m_LocalClient.InvokeHandlerOnClient(msgType, msg, channelId);
|
||||
return true;
|
||||
}
|
||||
public override bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); }
|
||||
public override bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); }
|
||||
|
||||
protected override bool SendBytes(byte[] bytes, int channelId)
|
||||
{
|
||||
m_LocalClient.InvokeBytesOnClient(bytes, channelId);
|
||||
@ -35,9 +26,7 @@ protected override bool SendBytes(byte[] bytes, int channelId)
|
||||
}
|
||||
|
||||
// a localClient's connection TO a server.
|
||||
// send messages on this connection causes the server's
|
||||
// handler function to be invoked directly.
|
||||
|
||||
// send messages on this connection causes the server's handler function to be invoked directly.
|
||||
internal class ULocalConnectionToServer : NetworkConnection
|
||||
{
|
||||
public ULocalConnectionToServer()
|
||||
@ -45,13 +34,6 @@ public ULocalConnectionToServer()
|
||||
address = "localServer";
|
||||
}
|
||||
|
||||
public override bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
||||
{
|
||||
return NetworkServer.InvokeHandlerOnServer(this, msgType, msg, channelId);
|
||||
}
|
||||
public override bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); }
|
||||
public override bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); }
|
||||
|
||||
protected override bool SendBytes(byte[] bytes, int channelId)
|
||||
{
|
||||
if (bytes.Length == 0)
|
||||
|
@ -1393,26 +1393,6 @@ static internal bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer, i
|
||||
return false;
|
||||
}
|
||||
|
||||
// invoked for local clients
|
||||
static internal bool InvokeHandlerOnServer(ULocalConnectionToServer conn, short msgType, MessageBase msg, int channelId)
|
||||
{
|
||||
if (handlers.ContainsKey(msgType) && s_LocalConnection != null)
|
||||
{
|
||||
// write the message to a local buffer
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
msg.Serialize(writer);
|
||||
|
||||
// pass a reader (attached to local buffer) to handler
|
||||
NetworkReader reader = new NetworkReader(writer.ToArray());
|
||||
|
||||
// this must be invoked with the connection to the client, not the client's connection to the server
|
||||
s_LocalConnection.InvokeHandler(msgType, reader, channelId);
|
||||
return true;
|
||||
}
|
||||
if (LogFilter.logError) { Debug.LogError("Local invoke: Failed to find local connection to invoke handler on [connectionId=" + conn.connectionId + "] for MsgId:" + msgType); }
|
||||
return false;
|
||||
}
|
||||
|
||||
static public GameObject FindLocalObject(NetworkInstanceId netId)
|
||||
{
|
||||
return s_NetworkScene.FindLocalObject(netId);
|
||||
|
Loading…
Reference in New Issue
Block a user