Skip to content

Commit 974c47e

Browse files
committed
AlloPlace does semantic version compatibility check
1 parent f737d6c commit 974c47e

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Sources/allonet2/AlloClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ open class AlloClient : AlloSessionDelegate, ObservableObject, Identifiable
216216
type: .request,
217217
senderEntityId: "",
218218
receiverEntityId: Interaction.PlaceEntity,
219-
body: .announce(version: "2.0", identity: identity, avatar: avatarDesc)
219+
body: .announce(version: Allonet.version().description, identity: identity, avatar: avatarDesc)
220220
))
221221
guard case .announceResponse(let avatarId, let placeName) = response.body else
222222
{

Sources/allonet2/PlaceServer.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Foundation
99
import FlyingFox
10+
import Version
1011

1112
public struct AppDescription
1213
{
@@ -365,9 +366,11 @@ public class PlaceServer : AlloSessionDelegate
365366
}
366367

367368
case .announce(let version, let identity, let avatarDescription):
368-
// TODO: Since we added authentication, should the version go up?
369-
guard version == "2.0" else {
370-
print("Client \(client.cid) has incompatible version, disconnecting.")
369+
guard
370+
let semantic = Version(version),
371+
Allonet.version().serverIsCompatibleWith(clientVersion: semantic)
372+
else {
373+
print("Client \(client.cid) has incompatible version (server \(Allonet.version()), client \(version)), disconnecting.")
371374
client.session.disconnect()
372375
return
373376
}

Sources/allonet2/allonet2.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,13 @@ extension PackageBuild
4949

5050
}
5151
}
52+
53+
extension Version
54+
{
55+
func serverIsCompatibleWith(clientVersion: Version) -> Bool
56+
{
57+
return
58+
major == clientVersion.major &&
59+
minor == clientVersion.minor
60+
}
61+
}

0 commit comments

Comments
 (0)