From 92a3faaed76e5f32e81eff403664874c63d738dc Mon Sep 17 00:00:00 2001
From: WolverinDEV <git@did.science>
Date: Sun, 7 Mar 2021 21:25:55 +0100
Subject: [PATCH] Some small bug fixes

---
 git-teaspeak                          |  2 +-
 rtclib                                |  2 +-
 server/CMakeLists.txt                 |  2 +-
 server/src/Configuration.cpp          | 17 +++++++++++------
 server/src/client/ConnectedClient.cpp |  2 --
 server/src/rtc/lib.cpp                | 21 +++++++++++++++++++++
 shared                                |  2 +-
 7 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/git-teaspeak b/git-teaspeak
index 883a2f1..d0babbc 160000
--- a/git-teaspeak
+++ b/git-teaspeak
@@ -1 +1 @@
-Subproject commit 883a2f1433576c75d5731d80681886795fb5c41b
+Subproject commit d0babbc62fb657783a04737a1265ab1c36636bf6
diff --git a/rtclib b/rtclib
index 06262ed..cdf42fc 160000
--- a/rtclib
+++ b/rtclib
@@ -1 +1 @@
-Subproject commit 06262edcdbfedc0836fe70fb21c90b384898d22b
+Subproject commit cdf42fccd34c769fabfef7208f829c3f4b62a595
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
index d47cb89..6415ffc 100644
--- a/server/CMakeLists.txt
+++ b/server/CMakeLists.txt
@@ -217,7 +217,7 @@ target_link_libraries(PermMapHelper
 
 SET(CPACK_PACKAGE_VERSION_MAJOR "1")
 SET(CPACK_PACKAGE_VERSION_MINOR "5")
-SET(CPACK_PACKAGE_VERSION_PATCH "1")
+SET(CPACK_PACKAGE_VERSION_PATCH "2")
 if (BUILD_TYPE_NAME EQUAL OFF)
     SET(CPACK_PACKAGE_VERSION_DATA "beta")
 elseif (BUILD_TYPE_NAME STREQUAL "")
diff --git a/server/src/Configuration.cpp b/server/src/Configuration.cpp
index b089e44..8720f45 100644
--- a/server/src/Configuration.cpp
+++ b/server/src/Configuration.cpp
@@ -348,7 +348,7 @@ void read_bindings(YAML::Node& root, const std::deque<std::shared_ptr<EntryBindi
 inline string apply_comments(stringstream &in, map<string, deque<string>>& comments);
 std::deque<std::shared_ptr<EntryBinding>> create_local_bindings(int& version, std::string& license);
 
-#define CURRENT_CONFIG_VERSION 15
+#define CURRENT_CONFIG_VERSION 16
 static std::string _config_path;
 vector<string> config::parseConfig(const std::string& path) {
     _config_path = path;
@@ -463,6 +463,13 @@ vector<string> config::parseConfig(const std::string& path) {
                                 nodes_key = "2";
                         }
                     }
+                    case 15: {
+                        auto nodes_key = resolveNode(config, "web.webrtc.stun.ip").back();
+                        if(nodes_key.IsDefined() && nodes_key.as<std::string>() == "127.0.0.1") {
+                            nodes_key.reset();
+                            resolveNode(config, "web.webrtc.stun.enabled").back() = "1";
+                        }
+                    }
                     default:
                         break;
                 }
@@ -1542,16 +1549,14 @@ std::deque<std::shared_ptr<EntryBinding>> config::create_bindings() {
         }
         {
             CREATE_BINDING("webrtc.stun.enabled", 0);
-            BIND_INTEGRAL(config::web::stun_enabled, false, false, true);
+            BIND_INTEGRAL(config::web::stun_enabled, true, false, true);
             ADD_DESCRIPTION("Whatever to use a STUN server");
             ADD_NOTE_RELOADABLE();
         }
         {
-            CREATE_BINDING("webrtc.stun.ip", 0);
-            BIND_STRING(config::web::stun_host, "127.0.0.1");
+            CREATE_BINDING("webrtc.stun.host", 0);
+            BIND_STRING(config::web::stun_host, "stun.l.google.com");
             ADD_DESCRIPTION("The address of the stun server to use.");
-            ADD_DESCRIPTION("Attention: This must be an IP address!");
-            ADD_DESCRIPTION("Example whise you could use the resolved IP address of 'stun.l.google.com' as the stun server address.");
             ADD_NOTE_RELOADABLE();
         }
         {
diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp
index 0cce013..724864d 100644
--- a/server/src/client/ConnectedClient.cpp
+++ b/server/src/client/ConnectedClient.cpp
@@ -119,8 +119,6 @@ void ConnectedClient::updateChannelClientProperties(bool lock_channel_tree, bool
             permission::b_client_ignore_antiflood,
             permission::i_channel_view_power,
             permission::b_channel_ignore_view_power,
-            permission::i_icon_id,
-            permission::b_client_is_priority_speaker,
     }, channel ? channel->channelId() : 0);
 
     permission::v2::PermissionFlaggedValue
diff --git a/server/src/rtc/lib.cpp b/server/src/rtc/lib.cpp
index ea88f15..dd92469 100644
--- a/server/src/rtc/lib.cpp
+++ b/server/src/rtc/lib.cpp
@@ -79,6 +79,27 @@ uint32_t librtc_callback_rtc_configure(const void* callback_data_ptr, void* conf
     options.max_port = config::web::webrtc_port_max;
 
     std::string stun_host{config::web::stun_host};
+    if(!net::is_ipv4(stun_host) && !net::is_ipv6(stun_host)) {
+        auto timestamp_begin = std::chrono::system_clock::now();
+        auto result = gethostbyname(stun_host.c_str());
+        auto timestamp_end = std::chrono::system_clock::now();
+
+        if(!result) {
+            logError(target_client->getServerId(), "{} Failed to resolve stun hostname {}: {}", target_client->getLoggingPrefix(), stun_host, strerror(errno));
+            return 1;
+        }
+
+        auto addresses = (struct in_addr **) result->h_addr_list;
+        if(!*addresses) {
+            logError(target_client->getServerId(), "{} Failed to resolve stun hostname {}: Empty result", target_client->getLoggingPrefix(), stun_host);
+            return 1;
+        }
+
+        stun_host = inet_ntoa(**addresses);
+        logTrace(target_client->getServerId(), "{} Resolved stun host {} to {} within {}ms", target_client->getLoggingPrefix(), config::web::stun_host, stun_host,
+            std::chrono::duration_cast<std::chrono::milliseconds>(timestamp_end - timestamp_begin).count()
+        );
+    }
     options.stun_host = stun_host.c_str();
     options.stun_port = config::web::stun_port;
     if(!config::web::stun_enabled) {
diff --git a/shared b/shared
index 26981b9..eef0144 160000
--- a/shared
+++ b/shared
@@ -1 +1 @@
-Subproject commit 26981b95f70ed4418be0a0e1720eaa7c7fc0a76a
+Subproject commit eef0144e77ee87fc7fe275beb743bd85e6e37f19