Skip to content

Commit

Permalink
Add KRPC.GetClientId (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
djungelorm committed Feb 19, 2017
1 parent a906b63 commit 5170dbb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client/python/krpc/test/test_client.py
Expand Up @@ -317,8 +317,8 @@ def test_client_members(self):

def test_krpc_service_members(self):
self.assertSetEqual(
set(['get_services', 'get_status', 'add_stream', 'remove_stream',
'current_game_scene', 'GameScene', 'clients',
set(['get_client_id', 'get_services', 'get_status', 'add_stream',
'remove_stream', 'current_game_scene', 'GameScene', 'clients',
'InvalidOperationException', 'ArgumentException',
'ArgumentNullException', 'ArgumentOutOfRangeException']),
set(x for x in dir(self.conn.krpc) if not x.startswith('_')))
Expand Down
1 change: 1 addition & 0 deletions doc/order.txt
@@ -1,4 +1,5 @@
KRPC
KRPC.GetClientID
KRPC.GetStatus
KRPC.GetServices
KRPC.Clients
Expand Down
1 change: 1 addition & 0 deletions server/CHANGES.txt
Expand Up @@ -8,6 +8,7 @@ v0.4.0
* Significantly reduced the size of the message returned by GetServices
* More compact encoding of signed integers
* Added ability for RPCs to throw custom exception types in the calling client
* Add KRPC.GetClientID
* Update to Protocol Buffers v3.1.0

v0.3.8
Expand Down
8 changes: 8 additions & 0 deletions server/src/Service/KRPC.cs
Expand Up @@ -13,6 +13,14 @@ namespace KRPC.Service
[KRPCService]
public static class KRPC
{
/// <summary>
/// Returns the identifier for the current client.
/// </summary>
[KRPCProcedure]
public static byte[] GetClientID() {
return CallContext.Client.Guid.ToByteArray ();
}

/// <summary>
/// Returns some information about the server, such as the version.
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions server/test/Service/KRPCTest.cs
Expand Up @@ -25,13 +25,17 @@ public void GetServices ()
Assert.AreEqual (4, services.ServicesList.Count);

var service = services.ServicesList.First (x => x.Name == "KRPC");
Assert.AreEqual (6, service.Procedures.Count);
Assert.AreEqual (7, service.Procedures.Count);
Assert.AreEqual (0, service.Classes.Count);
Assert.AreEqual (1, service.Enumerations.Count);

int foundProcedures = 0;
foreach (var proc in service.Procedures) {
if (proc.Name == "GetStatus") {
if (proc.Name == "GetClientID") {
MessageAssert.HasReturnType (proc, typeof(byte[]));
MessageAssert.HasNoParameters (proc);
MessageAssert.HasDocumentation (proc);
} else if (proc.Name == "GetStatus") {
MessageAssert.HasReturnType (proc, typeof(KRPC.Service.Messages.Status));
MessageAssert.HasNoParameters (proc);
MessageAssert.HasDocumentation (proc);
Expand Down Expand Up @@ -62,7 +66,7 @@ public void GetServices ()
}
foundProcedures++;
}
Assert.AreEqual (6, foundProcedures);
Assert.AreEqual (7, foundProcedures);

bool foundEnumeration = false;
foreach (var enumeration in service.Enumerations) {
Expand Down

0 comments on commit 5170dbb

Please sign in to comment.