Skip to content

Commit f83fe2f

Browse files
authored
Merge pull request #55 from Jouca/mqtt
update(mqtt): Implemented MQTT support for notifications
2 parents 9761324 + 644852f commit f83fe2f

File tree

16 files changed

+1317
-308
lines changed

16 files changed

+1317
-308
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
push:
66
branches:
7-
- main
7+
- '**'
88
jobs:
99
build:
1010
strategy:
@@ -33,6 +33,10 @@ jobs:
3333
- uses: actions/checkout@v4
3434
with:
3535
submodules: 'recursive'
36+
37+
- name: Update Submodule
38+
run: |
39+
git submodule update --init --recursive
3640
3741
- name: Build the mod
3842
uses: geode-sdk/build-geode-mod@main

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "libs/socket.io-client-cpp"]
2-
path = libs/socket.io-client-cpp
3-
url = https://github.com/socketio/socket.io-client-cpp
41
[submodule "libs/pl_mpeg"]
52
path = libs/pl_mpeg
63
url = https://github.com/phoboslab/pl_mpeg

CMakeLists.txt

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(CMAKE_CXX_STANDARD 20)
33
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
55
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
6+
include(cmake/CPM.cmake)
67

78
if(NOT DEFINED GEODE_TARGET_PLATFORM)
89
set(GEODE_TARGET_PLATFORM "Win64")
@@ -41,12 +42,42 @@ file(GLOB SOURCES
4142
# Set up the mod binary
4243
add_library(${PROJECT_NAME} SHARED ${SOURCES})
4344

45+
set(PAHO_BUILD_SHARED OFF CACHE INTERNAL "")
46+
set(PAHO_BUILD_STATIC ON CACHE INTERNAL "")
47+
set(PAHO_ENABLE_TESTING OFF CACHE INTERNAL "")
48+
set(PAHO_BUILD_TESTS OFF CACHE INTERNAL "")
49+
set(PAHO_WITH_MQTT_C ON CACHE INTERNAL "")
50+
set(PAHO_WITH_SSL OFF CACHE INTERNAL "")
51+
52+
FetchContent_Declare(
53+
paho-mqttpp3-static
54+
GIT_REPOSITORY https://github.com/eclipse-paho/paho.mqtt.cpp.git
55+
GIT_TAG 71f78aafc3246c05d624098b8438129f5e0a70e5
56+
)
57+
58+
#FetchContent_MakeAvailable(paho-mqttpp3-static)
59+
FetchContent_GetProperties(paho-mqttpp3-static)
60+
# patch it because apparently stl doesnt like basic_string
61+
if(NOT paho-mqttpp3-static_POPULATED)
62+
FetchContent_Populate(paho-mqttpp3-static)
63+
configure_file(
64+
${CMAKE_CURRENT_SOURCE_DIR}/patch/ssl_options.h
65+
${paho-mqttpp3-static_SOURCE_DIR}/include/mqtt/ssl_options.h
66+
COPYONLY
67+
)
68+
configure_file(
69+
${CMAKE_CURRENT_SOURCE_DIR}/patch/ssl_options.cpp
70+
${paho-mqttpp3-static_SOURCE_DIR}/src/ssl_options.cpp
71+
COPYONLY
72+
)
73+
add_subdirectory(${paho-mqttpp3-static_SOURCE_DIR} ${paho-mqttpp3-static_BINARY_DIR})
74+
endif()
75+
4476
target_include_directories(${PROJECT_NAME} PRIVATE
45-
libs/socket.io-client-cpp
4677
libs/filesystem
4778
libs/pl_mpeg/
4879
libs/glew/
49-
libs/socket.io-client-cpp/src
80+
${paho-mqttpp3-static_SOURCE_DIR}/src
5081
)
5182

5283
if (NOT DEFINED ENV{GEODE_SDK})
@@ -57,12 +88,10 @@ endif()
5788

5889
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
5990

60-
add_subdirectory(libs/socket.io-client-cpp EXCLUDE_FROM_ALL)
61-
add_dependencies(${PROJECT_NAME} sioclient)
6291
if (APPLE) # AND NOT (${GEODE_TARGET_PLATFORM} STREQUAL "iOS" OR IOS)
63-
target_link_libraries(${PROJECT_NAME} sioclient "-framework OpenGL")
92+
target_link_libraries(${PROJECT_NAME} paho-mqttpp3-static "-framework OpenGL")
6493
else()
65-
target_link_libraries(${PROJECT_NAME} sioclient)
94+
target_link_libraries(${PROJECT_NAME} paho-mqttpp3-static)
6695
endif()
6796
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND WIN32)
6897
message("compiling on linux!!")

cmake/CPM.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: MIT
2+
#
3+
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
4+
5+
set(CPM_DOWNLOAD_VERSION 0.38.7)
6+
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5")
7+
8+
if(CPM_SOURCE_CACHE)
9+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
10+
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
11+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
12+
else()
13+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
14+
endif()
15+
16+
# Expand relative path. This is important if the provided path contains a tilde (~)
17+
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
18+
19+
file(DOWNLOAD
20+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
21+
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
22+
)
23+
24+
include(${CPM_DOWNLOAD_LOCATION})

include/Types.hpp

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
32
#include <Geode/Geode.hpp>
43
enum EventType {
54
Rate,
@@ -13,17 +12,95 @@ enum EventType {
1312
};
1413

1514
struct EventData {
16-
bool demon;
17-
uint8_t starsum;
18-
uint8_t stars;
19-
uint8_t rate;
20-
EventType type;
15+
bool demon = false;
16+
uint16_t starsum = 0;
17+
uint16_t stars = 0;
18+
uint16_t rate = 0;
19+
EventType type = EventType::Rate;
2120
std::string title;
22-
std::string sprite;
21+
std::string sprite = "GJ_square01.png";
2322
std::string level_name;
2423
std::string level_creator;
25-
uint8_t coins;
26-
bool verified_coins;
27-
bool platformer;
24+
uint8_t coins = 0;
25+
uint8_t verified_coins = 0;
26+
bool platformer = false;
2827
int level_id = -1;
28+
std::string levels_list;
29+
int maxToCompleteList = 0;
30+
};
31+
32+
template<>
33+
struct matjson::Serialize<EventData> {
34+
static geode::Result<EventData> fromJson(matjson::Value const& value) {
35+
EventData data;
36+
if (value.contains("demon")) {
37+
if (value["demon"].asUInt().isErr()) {
38+
GEODE_UNWRAP_INTO(data.demon, value["demon"].asBool());
39+
} else {
40+
GEODE_UNWRAP_INTO(auto demon, value["demon"].asUInt());
41+
data.demon = demon == 1;
42+
}
43+
}
44+
GEODE_UNWRAP_INTO(data.starsum, value["starsum"].asUInt());
45+
GEODE_UNWRAP_INTO(data.stars, value["stars"].asUInt());
46+
GEODE_UNWRAP_INTO(data.rate, value["rate"].asUInt());
47+
GEODE_UNWRAP_INTO(auto type, value["type"].asUInt());
48+
// yeahhhh im getting linker errors ok
49+
switch (type) {
50+
default:
51+
data.type = EventType::NA;
52+
break;
53+
case 0: // Rate
54+
data.type = EventType::Rate;
55+
break;
56+
case 1: // Daily
57+
data.type = EventType::Daily;
58+
break;
59+
case 2: // Weekly
60+
data.type = EventType::Weekly;
61+
break;
62+
case 3: // Small chest
63+
data.type = EventType::smallChest;
64+
break;
65+
case 4: // Large chest
66+
data.type = EventType::largeChest;
67+
break;
68+
case 5: // List
69+
data.type = EventType::List;
70+
break;
71+
case 6: // Event
72+
data.type = EventType::Event;
73+
break;
74+
}
75+
GEODE_UNWRAP_INTO(data.title, value["title"].asString());
76+
GEODE_UNWRAP_INTO(data.sprite, value["sprite"].asString());
77+
GEODE_UNWRAP_INTO(data.level_name, value["level_name"].asString());
78+
GEODE_UNWRAP_INTO(data.level_creator, value["level_creator"].asString());
79+
GEODE_UNWRAP_INTO(data.rate, value["rate"].asUInt());
80+
GEODE_UNWRAP_INTO(data.coins, value["coins"].asUInt());
81+
GEODE_UNWRAP_INTO(data.verified_coins, value["verified_coins"].asUInt());
82+
if (value.contains("platformer")) {
83+
if (value["platformer"].asUInt().isErr()) {
84+
GEODE_UNWRAP_INTO(data.platformer, value["platformer"].asBool());
85+
} else {
86+
GEODE_UNWRAP_INTO(auto platformer, value["platformer"].asUInt());
87+
data.platformer = platformer == 1;
88+
}
89+
}
90+
if (value.contains("level_id")) {
91+
if (value["level_id"].asString().isErr()) {
92+
GEODE_UNWRAP_INTO(data.level_id, value["level_id"].asInt());
93+
} else {
94+
GEODE_UNWRAP_INTO(auto level_id, value["level_id"].asString());
95+
data.level_id = geode::utils::numFromString<int>(level_id).unwrapOrDefault();
96+
}
97+
}
98+
if (value.contains("levels_list")) {
99+
GEODE_UNWRAP_INTO(data.levels_list, value["levels_list"].asString());
100+
}
101+
if (value.contains("maxToCompleteList")) {
102+
GEODE_UNWRAP_INTO(data.maxToCompleteList, value["maxToCompleteList"].asInt());
103+
}
104+
return geode::Ok(data);
105+
}
29106
};

libs/socket.io-client-cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)