Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Ported to MirrorNG 49.0.0
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Ported the transport to MirrorNG 49
paulpach committed Oct 14, 2020
1 parent 76c83cd commit 3cb88fd
Showing 5 changed files with 15 additions and 15 deletions.
9 changes: 4 additions & 5 deletions Assets/KCP/KcpConnection.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using UnityEngine;

@@ -103,18 +102,18 @@ internal void RawInput(byte[] buffer, int msgLength)

protected abstract void RawSend(byte[] data, int length);

public Task SendAsync(ArraySegment<byte> data)
public UniTask SendAsync(ArraySegment<byte> data)
{
kcp.Send(data.Array, data.Offset, data.Count);
return Task.CompletedTask;
return UniTask.CompletedTask;
}

/// <summary>
/// reads a message from connection
/// </summary>
/// <param name="buffer">buffer where the message will be written</param>
/// <returns>true if we got a message, false if we got disconnected</returns>
public async Task<bool> ReceiveAsync(MemoryStream buffer)
public async UniTask<bool> ReceiveAsync(MemoryStream buffer)
{
int msgSize = kcp.PeekSize();

@@ -151,7 +150,7 @@ public async Task<bool> ReceiveAsync(MemoryStream buffer)
return true;
}

internal async Task Handshake()
internal async UniTask Handshake()
{
// send a greeting and see if the server replies
await SendAsync(Hello);
9 changes: 4 additions & 5 deletions Assets/KCP/KcpTransport.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using UnityEngine;

@@ -29,12 +28,12 @@ public class KcpTransport : Transport
/// </summary>
/// <exception>If we cannot start the transport</exception>
/// <returns></returns>
public override Task ListenAsync()
public override UniTask ListenAsync()
{
socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
socket.DualMode = true;
socket.Bind(new IPEndPoint(IPAddress.IPv6Any, Port));
return Task.CompletedTask;
return UniTask.CompletedTask;
}

EndPoint newClientEP = new IPEndPoint(IPAddress.IPv6Any, 0);
@@ -79,7 +78,7 @@ public override void Disconnect()
/// then you get the connection to the client
/// </summary>
/// <returns>The connection to a client</returns>
public override async Task<IConnection> AcceptAsync()
public override async UniTask<IConnection> AcceptAsync()
{
KcpServerConnection connection = await acceptedConnections.Reader.ReadAsync();

@@ -116,7 +115,7 @@ public override IEnumerable<Uri> ServerUri()
/// <param name="uri">address of the server to connect to</param>
/// <returns>The connection to the server</returns>
/// <exception>If connection cannot be established</exception>
public override async Task<IConnection> ConnectAsync(Uri uri)
public override async UniTask<IConnection> ConnectAsync(Uri uri)
{
var client = new KcpClientConnection();

Original file line number Diff line number Diff line change
@@ -8,7 +8,8 @@
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"Mirror.10kBenchmark",
"Mirror.10BenchmarkLight"
"Mirror.10BenchmarkLight",
"UniTask"
],
"includePlatforms": [],
"excludePlatforms": [],
4 changes: 2 additions & 2 deletions Assets/Tests/Play/ConnectionTest.cs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public IEnumerator Setup() => UniTask.ToCoroutine(async () =>

await transport.ListenAsync();

Task<IConnection> acceptTask = transport.AcceptAsync();
UniTask<IConnection> acceptTask = transport.AcceptAsync();
var uriBuilder = new UriBuilder()
{
Host = "localhost",
@@ -48,7 +48,7 @@ public IEnumerator Setup() => UniTask.ToCoroutine(async () =>

testUri = uriBuilder.Uri;

Task<IConnection> connectTask = transport.ConnectAsync(uriBuilder.Uri);
UniTask<IConnection> connectTask = transport.ConnectAsync(uriBuilder.Uri);

serverConnection = await acceptTask;
clientConnection = await connectTask;
5 changes: 3 additions & 2 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -12,9 +12,10 @@
"depth": 0,
"source": "git",
"dependencies": {
"nuget.mono-cecil": "0.1.6-preview"
"nuget.mono-cecil": "0.1.6-preview",
"com.cysharp.unitask": "2.0.36"
},
"hash": "bc17d19a543535c5d326df3098812db7a4686fd4"
"hash": "4a0628ab15ec894d5a813b5c04c7396cd008c767"
},
"com.unity.ext.nunit": {
"version": "1.0.0",

0 comments on commit 3cb88fd

Please sign in to comment.