quantum-space-buddies/QuantumUNET/QULocalConnectionToServer.cs
2021-06-18 22:39:21 +01:00

59 lines
1.6 KiB
C#

using QuantumUNET.Messages;
using QuantumUNET.Transport;
using UnityEngine;
namespace QuantumUNET
{
internal class QULocalConnectionToServer : QNetworkConnection
{
public QULocalConnectionToServer(QNetworkServer localServer)
{
address = "localServer";
m_LocalServer = localServer;
}
public override bool Send(short msgType, QMessageBase msg) =>
m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, 0);
public override bool SendUnreliable(short msgType, QMessageBase msg) =>
m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, 1);
public override bool SendByChannel(short msgType, QMessageBase msg, int channelId) =>
m_LocalServer.InvokeHandlerOnServer(this, msgType, msg, channelId);
public override bool SendBytes(byte[] bytes, int numBytes, int channelId)
{
bool result;
if (numBytes <= 0)
{
Debug.LogError("LocalConnection:SendBytes cannot send zero bytes");
result = false;
}
else
{
result = m_LocalServer.InvokeBytes(this, bytes, numBytes, channelId);
}
return result;
}
public override bool SendWriter(QNetworkWriter writer, int channelId) =>
m_LocalServer.InvokeBytes(this, writer.AsArray(), (short)writer.AsArray().Length, channelId);
public override void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
{
numMsgs = 0;
numBufferedMsgs = 0;
numBytes = 0;
lastBufferedPerSecond = 0;
}
public override void GetStatsIn(out int numMsgs, out int numBytes)
{
numMsgs = 0;
numBytes = 0;
}
private readonly QNetworkServer m_LocalServer;
}
}