Skip to content

Commit f885ca8

Browse files
authored
Allow multiple features (#337)
1 parent f481781 commit f885ca8

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

protonvpn_cli/connection.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def show_dialog(headline, choices, stop=False):
5757

5858
pull_server_data()
5959

60-
features = {0: "Normal", 1: "Secure-Core", 2: "Tor", 4: "P2P"}
60+
features = {
61+
1: "Secure-Core",
62+
2: "Tor",
63+
4: "P2P",
64+
8: "Streaming",
65+
}
6166
server_tiers = {0: "F", 1: "B", 2: "P"}
6267

6368
servers = get_servers()
@@ -76,8 +81,14 @@ def show_dialog(headline, choices, stop=False):
7681
country_features = []
7782
for server in countries[country]:
7883
feat = int(get_server_value(server, "Features", servers))
79-
if not features[feat] in country_features:
80-
country_features.append(features[feat])
84+
for bit_flag in features:
85+
if (feat & bit_flag) != 0:
86+
if not features[bit_flag] in country_features:
87+
country_features.append(features[bit_flag])
88+
89+
if len(country_features) == 0:
90+
country_features.append("Normal")
91+
8192
choices.append((country, " | ".join(sorted(country_features))))
8293

8394
country = show_dialog("Choose a country:", choices)
@@ -96,16 +107,21 @@ def show_dialog(headline, choices, stop=False):
96107
get_server_value(servername, "Load", servers)
97108
).rjust(3, " ")
98109

99-
feature = features[
100-
get_server_value(servername, 'Features', servers)
101-
]
110+
servers_features = []
111+
feat = int(get_server_value(servername, 'Features', servers))
112+
for bit_flag in features:
113+
if (feat & bit_flag) != 0:
114+
servers_features.append(features[bit_flag])
115+
116+
if len(servers_features) == 0:
117+
servers_features.append("Normal")
102118

103119
tier = server_tiers[
104120
get_server_value(servername, "Tier", servers)
105121
]
106122

107123
choices.append((servername, "Load: {0}% | {1} | {2}".format(
108-
load, tier, feature
124+
load, tier, ", ".join(servers_features)
109125
)))
110126

111127
server_result = show_dialog("Choose the server to connect:", choices)

0 commit comments

Comments
 (0)