Skip to content

Commit

Permalink
Add RUDP transport option. Merge #45
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Oct 31, 2017
1 parent 5077f91 commit 74a9902
Show file tree
Hide file tree
Showing 28 changed files with 547 additions and 7,975 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/).

## [Unreleased]
### Added
- RUDP transport option.

## [0.9.0] - 2017-10-17
### Added
Expand Down
6 changes: 3 additions & 3 deletions Nakama.Tests/MatchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void SendDataMatch()
d = matchData;
evt2.Set();
};
client1.Send(NMatchDataSendMessage.Default(m.Id, opCode, data), (bool completed) =>
client1.Send(NMatchDataSendMessage.Default(m.Id, opCode, data), false, (bool completed) =>
{
// No action.
}, (INError err) => {
Expand Down Expand Up @@ -314,7 +314,7 @@ public void SendDataNoEchoMatch()
d = data;
evt2.Set();
};
client1.Send(NMatchDataSendMessage.Default(m.Id, 9, Encoding.ASCII.GetBytes("test-data")), (bool completed) =>
client1.Send(NMatchDataSendMessage.Default(m.Id, 9, Encoding.ASCII.GetBytes("test-data")), false, (bool completed) =>
{
// No action.
}, (INError err) => {
Expand Down Expand Up @@ -374,7 +374,7 @@ public void SendDataSubsetMatch()
evt2.Set();
};
var msg = new NMatchDataSendMessage.Builder(m.Id, opCode, data).Presences(new INUserPresence[]{p}).Build();
client2.Send(msg, (bool completed) =>
client2.Send(msg, false, (bool completed) =>
{
// No action.
}, (INError err) => {
Expand Down
2 changes: 1 addition & 1 deletion Nakama.Tests/Nakama.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
2 changes: 2 additions & 0 deletions Nakama/INClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public interface INClient

void Send<T>(INCollatedMessage<T> message, Action<T> callback, Action<INError> errback);

void Send(INUncollatedMessage message, bool reliable, Action<bool> callback, Action<INError> errback);

void Send(INUncollatedMessage message, Action<bool> callback, Action<INError> errback);
}
}
5 changes: 4 additions & 1 deletion Nakama/INCollatedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
* limitations under the License.
*/

using Google.Protobuf;

namespace Nakama
{
public interface INCollatedMessage<T> : INMessage
public interface INCollatedMessage<T>
{
IMessage Payload { get; }
void SetCollationId(string id);
}
}
25 changes: 0 additions & 25 deletions Nakama/INMessage.cs

This file was deleted.

2 changes: 2 additions & 0 deletions Nakama/INSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface INSession
byte[] Id { get; }

string Token { get; }

byte[] UdpToken { get; }

bool HasExpired(DateTime dateTime);
}
Expand Down
52 changes: 38 additions & 14 deletions Nakama/INTransport.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
using System;
/**
* Copyright 2017 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;

namespace Nakama
{
public enum TransportType : int
{
// WebSocket transport default.
WebSocket = 0,
// UDP transport.
Udp = 1
}

internal interface INTransport
{
bool Trace { get; set; }
Expand All @@ -16,46 +40,46 @@ void Post(string uri,
Action<byte[]> successAction,
Action<Exception> errorAction);

void Connect(string uri, bool noDelay);
void ConnectAsync(string uri, bool noDelay, Action<bool> callback);
void Connect(string uri, byte[] token);
void ConnectAsync(string uri, byte[] token, Action<bool> callback);
void Close();
void CloseAsync(Action callback);
void Send(byte[] data);
void SendAsync(byte[] data, Action<bool> completed);
void Send(byte[] data, bool reliable);
void SendAsync(byte[] data, bool reliable, Action<bool> completed);

event EventHandler<WebSocketCloseEventArgs> OnClose;
event EventHandler<WebSocketErrorEventArgs> OnError;
event EventHandler<WebSocketMessageEventArgs> OnMessage;
event EventHandler<SocketCloseEventArgs> OnClose;
event EventHandler<SocketErrorEventArgs> OnError;
event EventHandler<SocketMessageEventArgs> OnMessage;
event EventHandler OnOpen;
}

public class WebSocketMessageEventArgs : EventArgs
public class SocketMessageEventArgs : EventArgs
{
public byte[] Data { get ; private set; }

internal WebSocketMessageEventArgs(byte[] data)
internal SocketMessageEventArgs(byte[] data)
{
Data = data;
}
}

public class WebSocketCloseEventArgs : EventArgs
public class SocketCloseEventArgs : EventArgs
{
public int Code { get; private set; }
public string Reason{ get; private set; }

internal WebSocketCloseEventArgs(int code, string reason)
internal SocketCloseEventArgs(int code, string reason)
{
Code = code;
Reason = reason;
}
}

public class WebSocketErrorEventArgs : EventArgs
public class SocketErrorEventArgs : EventArgs
{
public Exception Error { get ; private set; }

internal WebSocketErrorEventArgs(Exception error)
internal SocketErrorEventArgs(Exception error)
{
Error = error;
}
Expand Down
5 changes: 4 additions & 1 deletion Nakama/INUncollatedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
* limitations under the License.
*/

using Google.Protobuf;

namespace Nakama
{
public interface INUncollatedMessage : INMessage
public interface INUncollatedMessage
{
IMessage Payload { get; }
}
}
Loading

0 comments on commit 74a9902

Please sign in to comment.