Skip to content

Commit 27dc5f9

Browse files
blackspherefollowerqdot
authored andcommitted
WS client support for MessageAttributes
This also includes the change that declares the message version of the client to the server.
1 parent 36edcb5 commit 27dc5f9

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

Buttplug.Client/ButtplugClientDevice.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ public class ButtplugClientDevice
1313
public readonly string Name;
1414

1515
[NotNull]
16-
public readonly List<string> AllowedMessages;
16+
public readonly Dictionary<string, MessageAttributes> AllowedMessages;
1717

1818
public ButtplugClientDevice(DeviceMessageInfo aDevInfo)
1919
{
2020
Index = aDevInfo.DeviceIndex;
2121
Name = aDevInfo.DeviceName;
22-
AllowedMessages = new List<string>(aDevInfo.DeviceMessages);
22+
AllowedMessages = new Dictionary<string, MessageAttributes>(aDevInfo.DeviceMessages);
2323
}
2424

25-
public ButtplugClientDevice(uint aIndex, string aName, string[] aMessages)
25+
public ButtplugClientDevice(uint aIndex, string aName, Dictionary<string, MessageAttributes> aMessages)
2626
{
2727
Index = aIndex;
2828
Name = aName;
29-
AllowedMessages = new List<string>(aMessages);
29+
AllowedMessages = new Dictionary<string, MessageAttributes>(aMessages);
3030
}
3131

3232
public ButtplugClientDevice(DeviceAdded aDevInfo)
3333
{
3434
Index = aDevInfo.DeviceIndex;
3535
Name = aDevInfo.DeviceName;
36-
AllowedMessages = new List<string>(aDevInfo.DeviceMessages);
36+
AllowedMessages = new Dictionary<string, MessageAttributes>(aDevInfo.DeviceMessages);
3737
}
3838

3939
public ButtplugClientDevice(DeviceRemoved aDevInfo)
4040
{
4141
Index = aDevInfo.DeviceIndex;
4242
Name = string.Empty;
43-
AllowedMessages = new List<string>();
43+
AllowedMessages = new Dictionary<string, MessageAttributes>();
4444
}
4545
}
4646
}

Buttplug.Client/ButtplugWSClient.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class ButtplugWSClient
2929
[NotNull]
3030
private readonly string _clientName;
3131

32+
[NotNull]
33+
private uint _messageSchemaVersion;
34+
3235
[NotNull]
3336
private ConcurrentDictionary<uint, TaskCompletionSource<ButtplugMessage>> _waitingMsgs = new ConcurrentDictionary<uint, TaskCompletionSource<ButtplugMessage>>();
3437

@@ -150,6 +153,14 @@ public async Task Connect(Uri aURL, bool aIgnoreSSLErrors = false)
150153
_pingTimer = new Timer(onPingTimer, null, 0, Convert.ToInt32(Math.Round(((double)si.MaxPingTime) / 2, 0)));
151154
}
152155

156+
_messageSchemaVersion = si.MessageVersion;
157+
if (_messageSchemaVersion < ButtplugMessage.CurrentMessageVersion)
158+
{
159+
throw new Exception("Buttplug Server's schema version (" + _messageSchemaVersion +
160+
") is less than the client's (" + ButtplugMessage.CurrentMessageVersion +
161+
"). A newer server is required!");
162+
}
163+
153164
break;
154165

155166
case Error e:
@@ -382,7 +393,7 @@ public async Task<ButtplugMessage> SendDeviceMessage(ButtplugClientDevice aDevic
382393
{
383394
if (_devices.TryGetValue(aDevice.Index, out ButtplugClientDevice dev))
384395
{
385-
if (!dev.AllowedMessages.Contains(aDeviceMsg.GetType().Name))
396+
if (!dev.AllowedMessages.ContainsKey(aDeviceMsg.GetType().Name))
386397
{
387398
return new Error("Device does not accept message type: " + aDeviceMsg.GetType().Name, Error.ErrorClass.ERROR_DEVICE, ButtplugConsts.SystemMsgId);
388399
}
@@ -436,12 +447,12 @@ protected async Task<ButtplugMessage> SendMessage(ButtplugMessage aMsg)
436447

437448
protected string Serialize(ButtplugMessage aMsg)
438449
{
439-
return _parser.Serialize(aMsg);
450+
return _parser.Serialize(aMsg, ButtplugMessage.CurrentMessageVersion);
440451
}
441452

442453
protected string Serialize(ButtplugMessage[] aMsgs)
443454
{
444-
return _parser.Serialize(aMsgs);
455+
return _parser.Serialize(aMsgs, ButtplugMessage.CurrentMessageVersion);
445456
}
446457

447458
protected ButtplugMessage[] Deserialize(string aMsg)

0 commit comments

Comments
 (0)