@@ -50,12 +50,11 @@ public Client(Server server, Socket socket)
50
50
51
51
this . _server = server ;
52
52
this . _socket = socket ;
53
- this . Services = new Dictionary < uint , uint >
54
- {
55
- { 0x0 , 0x0 } // base service.
56
- } ;
53
+ this . Services = new Dictionary < uint , uint > ( ) ;
57
54
}
58
55
56
+ private static uint _importedServiceCounter = 99 ;
57
+
59
58
public void Process ( PacketIn packet )
60
59
{
61
60
Console . WriteLine ( packet ) ;
@@ -67,32 +66,25 @@ public void Process(PacketIn packet)
67
66
Console . WriteLine ( response ) ;
68
67
}
69
68
else if ( packet is BindRequest )
70
- {
71
- var importedServicesIDs = new List < uint > ( ) ;
72
- foreach ( var service in packet . Request . ExportedServiceList ) // add list of imported services supplied by client.
69
+ {
70
+ var requestedServiceIDs = new List < uint > ( ) ;
71
+
72
+ foreach ( var serviceHash in packet . Request . ImportedServiceHashList ) // supply service id's requested by client using service-hashes.
73
73
{
74
- importedServicesIDs . Add ( service . Id ) ;
75
- if ( ! this . Services . ContainsKey ( service . Id ) ) this . Services . Add ( service . Id , service . Hash ) ;
74
+ requestedServiceIDs . Add ( Server . Services . ContainsValue ( serviceHash ) ? Server . Services . Where ( pair => pair . Value == serviceHash ) . FirstOrDefault ( ) . Key : _importedServiceCounter ++ ) ;
76
75
}
77
76
78
- if ( importedServicesIDs . Count > 0 )
77
+ if ( requestedServiceIDs . Count > 0 )
79
78
{
80
- var response = new BindResponse ( packet . Header . RequestID , importedServicesIDs ) ;
79
+ var response = new BindResponse ( packet . Header . RequestID , requestedServiceIDs ) ;
81
80
this . Send ( response . GetRawPacketData ( ) ) ;
82
81
Console . WriteLine ( response ) ;
83
82
}
84
-
85
- var requestedServices = new Dictionary < uint , uint > ( ) ;
86
- if ( requestedServices . Count > 0 )
83
+
84
+ foreach ( var service in packet . Request . ExportedServiceList ) // add list of imported services supplied by client.
87
85
{
88
- foreach ( var serviceHash in packet . Request . ImportedServiceHashList ) // supply service id's requested by client using service-hashes.
89
- {
90
- requestedServices . Add ( Server . Services . ContainsKey ( serviceHash ) ? Server . Services [ serviceHash ] : ( uint ) 255 , serviceHash ) ;
91
- // probably we should reply with a BoundService.
92
- }
86
+ if ( ! this . Services . ContainsKey ( service . Id ) ) this . Services . Add ( service . Id , service . Hash ) ;
93
87
}
94
-
95
-
96
88
}
97
89
98
90
else if ( packet is LogonRequest )
0 commit comments