@@ -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