| 186 | }; |
| 187 | |
| 188 | static bool HandleHandshakeClient(ActiveClient &activeClient, ClientThread *threadData) |
| 189 | { |
| 190 | uint32_t ip = threadData->socket->GetRemoteIP(); |
| 191 | |
| 192 | uint32_t version = 0; |
| 193 | |
| 194 | bool activeConnectionDesired = false; |
| 195 | bool activeConnectionEstablished = false; |
| 196 | |
| 197 | { |
| 198 | ReadSerialiser ser(new StreamReader(threadData->socket, Ownership::Nothing), Ownership::Stream); |
| 199 | |
| 200 | ser.SetStreamingMode(true); |
| 201 | |
| 202 | // this thread just handles receiving the handshake and sending a busy signal without blocking |
| 203 | // the server thread |
| 204 | RemoteServerPacket type = ser.ReadChunk<RemoteServerPacket>(); |
| 205 | |
| 206 | if(ser.IsErrored() || type != RemoteServerPacket::Handshake) |
| 207 | { |
| 208 | RDCWARN("Didn't receive proper handshake"); |
| 209 | return activeConnectionEstablished; |
| 210 | } |
| 211 | |
| 212 | SERIALISE_ELEMENT(version); |
| 213 | SERIALISE_ELEMENT(activeConnectionDesired); |
| 214 | |
| 215 | ser.EndChunk(); |
| 216 | } |
| 217 | |
| 218 | { |
| 219 | WriteSerialiser ser(new StreamWriter(threadData->socket, Ownership::Nothing), Ownership::Stream); |
| 220 | |
| 221 | ser.SetStreamingMode(true); |
| 222 | |
| 223 | if(version != RemoteServerProtocolVersion) |
| 224 | { |
| 225 | RDCLOG("Connection using protocol %u, but we are running %u", version, |
| 226 | RemoteServerProtocolVersion); |
| 227 | |
| 228 | // as of 1.23 we started serialising our version so the other end knows what it's talking |
| 229 | // to. |
| 230 | if(version >= MAKE_REMOTE_SERVER_VERSION(1, 23)) |
| 231 | { |
| 232 | SCOPED_SERIALISE_CHUNK(RemoteServerPacket::VersionMismatch2); |
| 233 | |
| 234 | SERIALISE_ELEMENT(RemoteServerProtocolVersion); |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | SCOPED_SERIALISE_CHUNK(RemoteServerPacket::VersionMismatch); |
| 239 | } |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | bool busy = false; |
| 244 | |
| 245 | { |
no test coverage detected