#78 new: alter host

This commit is contained in:
lollipopkit
2023-07-28 13:59:32 +08:00
parent ed3201db6d
commit 389d1753c4
18 changed files with 101 additions and 36 deletions

View File

@@ -18,6 +18,8 @@ class ServerPrivateInfo {
String? pubKeyId;
@HiveField(6)
List<String>? tags;
@HiveField(7)
String? alterHost;
late String id;
@@ -29,6 +31,7 @@ class ServerPrivateInfo {
required this.pwd,
this.pubKeyId,
this.tags,
this.alterHost,
}) : id = '$user@$ip:$port';
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
@@ -40,6 +43,7 @@ class ServerPrivateInfo {
pubKeyId = json["pubKeyId"]?.toString();
id = '$user@$ip:$port';
tags = json["tags"]?.cast<String>();
alterHost = json["alterHost"]?.toString();
}
Map<String, dynamic> toJson() {
@@ -51,11 +55,15 @@ class ServerPrivateInfo {
data["authorization"] = pwd;
data["pubKeyId"] = pubKeyId;
data["tags"] = tags;
data["alterHost"] = alterHost;
return data;
}
bool shouldReconnect(ServerPrivateInfo old) {
return id != old.id || pwd != old.pwd || pubKeyId != old.pubKeyId;
return id != old.id ||
pwd != old.pwd ||
pubKeyId != old.pubKeyId ||
alterHost != old.alterHost;
}
@override

View File

@@ -24,13 +24,14 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
pwd: fields[4] as String,
pubKeyId: fields[5] as String?,
tags: (fields[6] as List?)?.cast<String>(),
alterHost: fields[7] as String?,
);
}
@override
void write(BinaryWriter writer, ServerPrivateInfo obj) {
writer
..writeByte(7)
..writeByte(8)
..writeByte(0)
..write(obj.name)
..writeByte(1)
@@ -44,7 +45,9 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
..writeByte(5)
..write(obj.pubKeyId)
..writeByte(6)
..write(obj.tags);
..write(obj.tags)
..writeByte(7)
..write(obj.alterHost);
}
@override