2020-12-07 21:19:16 +00:00
|
|
|
|
using QuantumUNET.Messages;
|
2020-12-16 09:08:38 +00:00
|
|
|
|
using QuantumUNET.Transport;
|
2020-12-07 21:19:16 +00:00
|
|
|
|
using UnityEngine;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
|
2020-12-04 22:14:53 +00:00
|
|
|
|
namespace QuantumUNET
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2020-12-23 12:58:45 +00:00
|
|
|
|
internal class QULocalConnectionToServer : QNetworkConnection
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2020-12-23 12:58:45 +00:00
|
|
|
|
public QULocalConnectionToServer(QNetworkServer localServer)
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
|
|
|
|
address = "localServer";
|
|
|
|
|
m_LocalServer = localServer;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 15:42:20 +00:00
|
|
|
|
public override bool Send(short msgType, QMessageBase msg)
|
|
|
|
|
=> m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, 0);
|
2020-12-02 18:40:38 +00:00
|
|
|
|
|
2021-08-29 15:42:20 +00:00
|
|
|
|
public override bool SendUnreliable(short msgType, QMessageBase msg)
|
|
|
|
|
=> m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, 1);
|
2020-12-02 18:40:38 +00:00
|
|
|
|
|
2021-08-29 15:42:20 +00:00
|
|
|
|
public override bool SendByChannel(short msgType, QMessageBase msg, int channelId)
|
|
|
|
|
=> m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, channelId);
|
2020-12-02 18:40:38 +00:00
|
|
|
|
|
|
|
|
|
public override bool SendBytes(byte[] bytes, int numBytes, int channelId)
|
|
|
|
|
{
|
|
|
|
|
bool result;
|
|
|
|
|
if (numBytes <= 0)
|
|
|
|
|
{
|
2020-12-18 20:20:54 +00:00
|
|
|
|
Debug.LogError("LocalConnection:SendBytes cannot send zero bytes");
|
2020-12-02 18:40:38 +00:00
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = m_LocalServer.InvokeBytes(this, bytes, numBytes, channelId);
|
|
|
|
|
}
|
2021-06-18 21:39:21 +00:00
|
|
|
|
|
2020-12-02 18:40:38 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 15:42:20 +00:00
|
|
|
|
public override bool SendWriter(QNetworkWriter writer, int channelId)
|
|
|
|
|
=> m_LocalServer.InvokeBytes(this, writer.AsArray(), (short)writer.AsArray().Length, channelId);
|
2020-12-02 18:40:38 +00:00
|
|
|
|
|
2020-12-23 12:58:45 +00:00
|
|
|
|
private readonly QNetworkServer m_LocalServer;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|