2018-06-07 13:41:08 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
#if ENABLE_UNET
|
|
|
|
|
|
|
|
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
|
|
|
|
class ULocalConnectionToClient : NetworkConnection
|
|
|
|
{
|
|
|
|
LocalClient m_LocalClient;
|
|
|
|
|
|
|
|
public LocalClient localClient { get { return m_LocalClient; } }
|
|
|
|
|
|
|
|
public ULocalConnectionToClient(LocalClient localClient)
|
|
|
|
{
|
|
|
|
address = "localClient";
|
|
|
|
m_LocalClient = localClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
|
|
|
{
|
|
|
|
m_LocalClient.InvokeHandlerOnClient(msgType, msg, channelId);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-20 09:35:20 +00:00
|
|
|
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); }
|
2018-06-07 13:41:08 +00:00
|
|
|
|
2018-07-20 10:29:51 +00:00
|
|
|
public override bool SendBytes(byte[] bytes, int channelId)
|
2018-06-07 13:41:08 +00:00
|
|
|
{
|
|
|
|
m_LocalClient.InvokeBytesOnClient(bytes, channelId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// a localClient's connection TO a server.
|
|
|
|
// send messages on this connection causes the server's
|
|
|
|
// handler function to be invoked directly.
|
|
|
|
|
|
|
|
internal class ULocalConnectionToServer : NetworkConnection
|
|
|
|
{
|
2018-06-22 18:34:35 +00:00
|
|
|
public ULocalConnectionToServer()
|
2018-06-07 13:41:08 +00:00
|
|
|
{
|
|
|
|
address = "localServer";
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
|
|
|
{
|
2018-06-22 18:34:35 +00:00
|
|
|
return NetworkServer.InvokeHandlerOnServer(this, msgType, msg, channelId);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
2018-07-20 09:35:20 +00:00
|
|
|
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); }
|
2018-06-07 13:41:08 +00:00
|
|
|
|
2018-07-20 10:29:51 +00:00
|
|
|
public override bool SendBytes(byte[] bytes, int channelId)
|
2018-06-07 13:41:08 +00:00
|
|
|
{
|
2018-07-20 10:29:51 +00:00
|
|
|
if (bytes.Length == 0)
|
2018-06-07 13:41:08 +00:00
|
|
|
{
|
|
|
|
if (LogFilter.logError) { Debug.LogError("LocalConnection:SendBytes cannot send zero bytes"); }
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-20 10:29:51 +00:00
|
|
|
return NetworkServer.InvokeBytes(this, bytes, channelId);
|
2018-06-07 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //ENABLE_UNET
|