From ba228a4de8b7996fd4a33cc9c316bc7cc37c7cab Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Sat, 7 Nov 2020 07:41:52 +0200 Subject: [PATCH 1/4] PacketGuard: Add allow for Event Update (String Update) (0x060) --- src/map/packet_guard.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/map/packet_guard.cpp b/src/map/packet_guard.cpp index ab8f2a0f26b..0b64e9047be 100644 --- a/src/map/packet_guard.cpp +++ b/src/map/packet_guard.cpp @@ -39,6 +39,7 @@ void Init() allowList[SUBSTATE_IN_CS][0x05A] = true; // Map Update (Conquest, Besieged, Campaign) allowList[SUBSTATE_IN_CS][0x05B] = true; // Event Update (Completion or Update) allowList[SUBSTATE_IN_CS][0x05C] = true; // Event Update (Update Player Position) + allowList[SUBSTATE_IN_CS][0x060] = true; // Event Update (String Update) allowList[SUBSTATE_IN_CS][0x061] = true; // Full Char Update allowList[SUBSTATE_IN_CS][0x0B5] = true; // Chat Message allowList[SUBSTATE_IN_CS][0x0B6] = true; // Tell Message From b15a382f286143303f4237f19017f2d52c34c9b5 Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Sun, 8 Nov 2020 10:55:54 +0200 Subject: [PATCH 2/4] Add GetRandomElement helpers and cleanup tpzrand --- src/common/tpzrand.h | 48 +++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/common/tpzrand.h b/src/common/tpzrand.h index 24faac67c0e..165e193639d 100644 --- a/src/common/tpzrand.h +++ b/src/common/tpzrand.h @@ -18,14 +18,13 @@ class tpzrand mt().seed(seq); } - /*Generates a random number in the half-open interval [min, max) - @param min - @param max - @returns result - */ + // Generates a random number in the half-open interval [min, max] + // @param min + // @param max + // @returns result template static inline typename std::enable_if::value, T>::type - GetRandomNumber(T min, T max) + GetRandomNumber(T min, T max) { if (min == max - 1 || max == min) { @@ -37,7 +36,7 @@ class tpzrand template static inline typename std::enable_if::value, T>::type - GetRandomNumber(T min, T max) + GetRandomNumber(T min, T max) { if (min == max) { @@ -47,14 +46,39 @@ class tpzrand return dist(mt()); } - /*Generates a random number in the half-open interval [0, max) - @param min - @param max - @returns result - */ + // Generates a random number in the half-open interval [0, max) + // @param min + // @param max + // @returns result template static inline T GetRandomNumber(T max) { return GetRandomNumber(0, max); } + + // Gets a random element from the given stl-like container (container must have members: at() and size()). + // @param container + // @returns result + template static inline typename T::value_type GetRandomElement(T* container) + { + // NOTE: the specialisation for integral types uses: dist(min, max - 1), so no need to offset container->size() + return container->at(GetRandomNumber(0U, container->size())); + } + + // Gets a random element from the given stl-like container (container must have members: at() and size()). + // @param container + // @returns result + template static inline typename T::value_type GetRandomElement(T& container) + { + return GetRandomElement(&container); + } + + // Gets a random element from the given initializer_list. + // @param initializer_list + // @returns result + template static inline T GetRandomElement(std::initializer_list list) + { + std::vector container(list); + return GetRandomElement(container); + } }; From 36c07763bfadc1d8721a1d814a7d36904ead4b9a Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Sun, 8 Nov 2020 11:31:28 +0200 Subject: [PATCH 3/4] CI: Update Full_Startup_Checks (mariadb) --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d391f4a6ecf..f4f07122761 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -125,10 +125,10 @@ jobs: fi Full_Startup_Checks: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 services: mysql: - image: mariadb:10.1 + image: mariadb env: MYSQL_DATABASE: tpzdb MYSQL_ROOT_PASSWORD: root @@ -142,7 +142,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get update - sudo apt-get install -y software-properties-common cmake mariadb-server libmariadb-dev-compat libluajit-5.1-dev libzmq3-dev zlib1g-dev libssl-dev luarocks python3.7 + sudo apt-get install -y software-properties-common cmake mariadb-server-10.3 mariadb-client-10.3 libmariadb-dev-compat libluajit-5.1-dev libzmq3-dev zlib1g-dev libssl-dev luarocks python3.7 - name: Configure CMake run: | cmake . From b40d15087b68ec1281ec443025e099fd6a8635ba Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Sun, 8 Nov 2020 11:53:34 +0200 Subject: [PATCH 4/4] Trust: replace GetRandomNumber with GetRandomElement --- src/map/ai/helpers/gambits_container.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/ai/helpers/gambits_container.cpp b/src/map/ai/helpers/gambits_container.cpp index 76491d3df36..a1a49272404 100644 --- a/src/map/ai/helpers/gambits_container.cpp +++ b/src/map/ai/helpers/gambits_container.cpp @@ -558,7 +558,7 @@ bool CGambitsContainer::TryTrustSkill() { case G_SELECT::RANDOM: { - chosen_skill = tp_skills.at(tpzrand::GetRandomNumber(tp_skills.size())); + chosen_skill = tpzrand::GetRandomElement(tp_skills); break; } case G_SELECT::HIGHEST: // Form the best possible skillchain