Skip to content

Commit 0caa9ea

Browse files
committed
Added support for RPC return values
1 parent 051af85 commit 0caa9ea

File tree

10 files changed

+3537
-2153
lines changed

10 files changed

+3537
-2153
lines changed

MLAPI/Data/AttributeMessageMode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public ReflectionMehtod(MethodInfo methodInfo)
3939
}
4040
}
4141

42-
public void Invoke(object instance, Stream stream)
42+
public object Invoke(object instance, Stream stream)
4343
{
4444
using (PooledBitReader reader = PooledBitReader.Get(stream))
4545
{
@@ -48,7 +48,7 @@ public void Invoke(object instance, Stream stream)
4848
parameterRefs[i] = reader.ReadObjectPacked(parameterTypes[i]);
4949
}
5050

51-
method.Invoke(instance, parameterRefs);
51+
return method.Invoke(instance, parameterRefs);
5252
}
5353
}
5454
}

MLAPI/Data/MLAPIConstants.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ public static class MLAPIConstants
2626
public const byte MLAPI_NETWORKED_VAR_DELTA = 15;
2727
public const byte MLAPI_NETWORKED_VAR_UPDATE = 16;
2828
public const byte MLAPI_SERVER_RPC = 17;
29-
public const byte MLAPI_CLIENT_RPC = 18;
30-
public const byte MLAPI_CUSTOM_MESSAGE = 19;
29+
public const byte MLAPI_SERVER_RPC_REQUEST = 18;
30+
public const byte MLAPI_SERVER_RPC_RESPONSE = 19;
31+
public const byte MLAPI_CLIENT_RPC = 20;
32+
public const byte MLAPI_CLIENT_RPC_REQUEST = 21;
33+
public const byte MLAPI_CLIENT_RPC_RESPONSE = 22;
34+
public const byte MLAPI_CUSTOM_MESSAGE = 23;
3135
public const byte INVALID = 32;
3236

3337
public static readonly string[] MESSAGE_NAMES = {
@@ -47,9 +51,13 @@ public static class MLAPIConstants
4751
"MLAPI_ADD_OBJECTS",
4852
"MLAPI_TIME_SYNC",
4953
"MLAPI_NETWORKED_VAR_DELTA",
50-
"MLAPI_NETWORKED_VAR_UPDATE",
51-
"MLAPI_SERVER_RPC", // 16
54+
"MLAPI_NETWORKED_VAR_UPDATE", // 16
55+
"MLAPI_SERVER_RPC",
56+
"MLAPI_SERVER_RPC_REQUEST",
57+
"MLAPI_SERVER_RPC_RESPONSE",
5258
"MLAPI_CLIENT_RPC",
59+
"MLAPI_CLIENT_RPC_REQUEST",
60+
"MLAPI_CLIENT_RPC_RESPONSE",
5361
"MLAPI_CUSTOM_MESSAGE",
5462
"",
5563
"",
@@ -60,10 +68,6 @@ public static class MLAPIConstants
6068
"",
6169
"",
6270
"",
63-
"",
64-
"",
65-
"",
66-
"",
6771
"INVALID" // 32
6872
};
6973
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

MLAPI/Data/RpcResponse.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
3+
namespace MLAPI
4+
{
5+
/// <summary>
6+
/// The RpcResponse class exposed by the API. Represents a network Request/Response operation with a result
7+
/// </summary>
8+
/// <typeparam name="T">The result type</typeparam>
9+
public class RpcResponse<T> : RpcResponseBase
10+
{
11+
/// <summary>
12+
/// Gets the value from the operation.
13+
/// Note that this is an expensive operation, grab and cache
14+
/// </summary>
15+
public T Value => Result == null ? default(T) : (T) Result;
16+
}
17+
18+
/// <summary>
19+
/// Abstract base class for RpcResponse
20+
/// </summary>
21+
public abstract class RpcResponseBase
22+
{
23+
/// <summary>
24+
/// Unique ID for the Rpc Request & Response pair
25+
/// </summary>
26+
public ulong Id { get; internal set; }
27+
/// <summary>
28+
/// Whether or not a result has been received
29+
/// </summary>
30+
public bool IsDone { get; internal set; }
31+
/// <summary>
32+
/// The clientId which the Request/Response was done wit
33+
/// </summary>
34+
public uint ClientId { get; internal set; }
35+
internal object Result { get; set; }
36+
internal Type Type { get; set; }
37+
}
38+
}

MLAPI/MLAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<ItemGroup>
8181
<Compile Include="Data\Channel.cs" />
8282
<Compile Include="Data\AttributeMessageMode.cs" />
83+
<Compile Include="Data\RpcResponse.cs" />
8384
<Compile Include="Data\UnsignedIntegerArrayExtensions.cs" />
8485
<Compile Include="Data\MLAPIConstants.cs" />
8586
<Compile Include="Data\NetworkedCollections\NetworkedDictionary.cs" />

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.RpcOverloads.cs

Lines changed: 3155 additions & 2113 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)