Skip to content

Commit ae26f3f

Browse files
authored
Merge pull request #277 from yourWaifu/boost-v1_87_0
Support for Boost 1.87.0 or ASIO 1.32.0
2 parents 3d9b62f + 91215ef commit ae26f3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1481
-781
lines changed

CMakeLists.txt

Lines changed: 42 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ if (NOT ONLY_SLEEPY_DISCORD)
99
option(AUTO_DOWNLOAD_LIBRARY "Automatically download sleepy discord standard config dependencies" ON )
1010
option(SLEEPY_VCPKG "VCPKG with Sleepy Discord" OFF)
1111
option(USE_CPR "Use CPR http library" ON )
12-
option(USE_WEBSOCKETPP "Use websocketpp websockets library" ON )
13-
option(USE_UWEBSOCKETS "Use uWebsockets websockets library" OFF)
14-
option(USE_ASIO "Use ASIO network and I/O library (Used for UDP)" OFF)
12+
option(USE_ASIO "Use ASIO network and I/O library (Used for UDP and TCP)" ON)
1513
option(USE_BOOST_ASIO "Same as USE_ASIO but for boost library" OFF)
1614
option(USE_LIBOPUS "Use Opus audio codec library" OFF)
1715
option(USE_LIBSODIUM "Use libsodium cryptography library" OFF)
1816
option(USE_ZLIB_NG "Use zlib-ng for data compression" OFF)
1917
option(USE_ZLIB "Use zlib for data compression" OFF)
18+
#option(USE_Boost_BEAST "Use Boost Beast for http library" OFF)
19+
#option(USE_IXWEBSOCKET "Use IXWebSocket for websockets" OFF)
2020
endif()
2121

2222
#Define a variable to use to check if this file has been executed
@@ -32,14 +32,6 @@ if(ENABLE_VOICE)
3232
set(USE_LIBSODIUM ON)
3333
endif()
3434

35-
if(USE_WEBSOCKETPP OR USE_UWEBSOCKETS)
36-
if(Boost_FOUND OR USE_BOOST_ASIO) #checks if already defined
37-
set(USE_BOOST_ASIO ON)
38-
else()
39-
set(USE_ASIO ON)
40-
endif()
41-
endif()
42-
4335
if(USE_ZLIB_NG AND USE_ZLIB)
4436
message(FATAL_ERROR "can't use zlib and zlib-ng at the same time")
4537
endif()
@@ -116,8 +108,6 @@ if(USE_ASIO)
116108
find_package(asio CONFIG REQUIRED)
117109
else()
118110
if(AUTO_DOWNLOAD_LIBRARY)
119-
# Note websocketpp doesn't work with the latest version of asio
120-
# Remember to go back to the master version after they are fixed
121111
download_project(
122112
PROJ asio
123113
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
@@ -133,54 +123,6 @@ if(USE_ASIO)
133123
endif()
134124
endif()
135125

136-
if(USE_WEBSOCKETPP)
137-
if (SLEEPY_VCPKG)
138-
find_package(websocketpp CONFIG REQUIRED)
139-
else()
140-
if(AUTO_DOWNLOAD_LIBRARY)
141-
download_project(
142-
PROJ websocketpp
143-
GIT_REPOSITORY https://github.com/zaphoyd/websocketpp.git
144-
GIT_TAG master
145-
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/websocketpp
146-
UPDATE_DISCONNECTED 1
147-
)
148-
endif()
149-
150-
set(THREADS_PREFER_PTHREAD_FLAG ON)
151-
find_package(Threads REQUIRED)
152-
add_subdirectory(deps/websocketpp)
153-
154-
if(NOT DEFINED websocketpp_SOURCE_DIR)
155-
set(websocketpp_SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/websocketpp)
156-
endif()
157-
endif()
158-
endif()
159-
160-
if(USE_UWEBSOCKETS)
161-
if(SLEEPY_VCPKG)
162-
find_path(UWEBSOCKETS_INCLUDE_DIRS "uwebsockets/App.h")
163-
set(uwebsockets_SOURCE_DIR "${UWEBSOCKETS_INCLUDE_DIRS}/..")
164-
else()
165-
if(AUTO_DOWNLOAD_LIBRARY)
166-
#to do install zlib
167-
download_project(
168-
PROJ uwebsockets
169-
GIT_REPOSITORY https://github.com/uNetworking/uWebSockets.git
170-
GIT_TAG master
171-
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/uwebsockets
172-
UPDATE_DISCONNECTED 1
173-
BUILD_COMMAND ${MAKE}
174-
)
175-
set(UWEBSOCKETS_INCLUDE_DIRS "${uwebsockets_SOURCE_DIR}/include")
176-
endif()
177-
178-
if(NOT DEFINED uwebsockets_SOURCE_DIR)
179-
set(uwebsockets_SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/uwebsockets)
180-
endif()
181-
endif()
182-
endif()
183-
184126
if(USE_LIBOPUS)
185127
if(SLEEPY_VCPKG)
186128
find_package(Opus CONFIG REQUIRED)
@@ -248,6 +190,45 @@ if(USE_ZLIB)
248190
#to do add auto download
249191
endif()
250192

193+
if (USE_BEAST)
194+
if(SLEEPY_VCPKG)
195+
find_package(Boost REQUIRED COMPONENTS beast)
196+
else()
197+
if(AUTO_DOWNLOAD_LIBRARY)
198+
download_project(
199+
PROJ beast
200+
GIT_REPOSITORY https://github.com/boostorg/beast.git
201+
GIT_TAG master
202+
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/beast
203+
UPDATE_DISCONNECTED 1
204+
)
205+
endif()
206+
endif()
207+
208+
add_subdirectory(deps/beast)
209+
endif()
210+
211+
if (USE_IXWEBSOCKET)
212+
if (SLEEPY_VCPKG)
213+
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket/IXWebSocket.h)
214+
find_library(IXWEBSOCKET_LIBRARY ixwebsocket)
215+
else()
216+
if (AUTO_DOWNLOAD_LIBRARY)
217+
download_project(
218+
PROJ IXWebSocket
219+
GIT_REPOSITORY https://github.com/machinezone/IXWebSocket.git
220+
GIT_TAG master
221+
SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/ixwebsocket
222+
UPDATE_DISCONNECTED 1
223+
)
224+
endif()
225+
226+
add_subdirectory(deps/ixwebsocket)
227+
set(IXWEBSOCKET_LIBRARY ixwebsocket)
228+
set(IXWEBSOCKET_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/deps/ixwebsocket/ixwebsocket)
229+
endif()
230+
endif ()
231+
251232
# Get Version Info
252233
# Not needed for vcpkg
253234
if(NOT SLEEPY_VCPKG)

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ Sleepy Discord doesn't require you to use any libraries, so that you can use any
5858
5959
* [OpenSSL](https://www.openssl.org/)
6060
* [cpr](https://github.com/whoshuu/cpr)
61-
* [Websocket++](https://github.com/zaphoyd/websocketpp)
62-
or
63-
[uWebSockets](https://github.com/uWebSockets/uWebSockets)
61+
* [ASIO](https://think-async.com/Asio/)
6462
6563
# Develop Branch
6664
For the cutting edge of Sleepy Discord, check out the develop branch. Please use the develop branch with caution because it may not even be able to compile or it is 100% not tested at all. Other then that, the branch is used for code that may not work. Also check to see if it's not behind the master branch, unless you want to use an older version of Sleepy Discord.

azure-pipelines.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
55

66
pool:
7-
vmImage: 'VS2017-Win2016'
7+
vmImage: 'windows-2022'
88

99
variables:
1010
solution: 'build/*.sln'
11-
buildPlatform: Win32
11+
buildPlatform: 'x86'
1212
buildConfiguration: 'Release'
1313

1414
steps:
@@ -24,15 +24,13 @@ steps:
2424

2525
- script: |
2626
cd vcpkg
27-
.\vcpkg install openssl-windows:x86-windows-static
27+
.\vcpkg install openssl:x86-windows-static
2828
displayName: 'OpenSSL Install'
2929

3030
- task: CMake@1
3131
inputs:
32-
CMakeArgs: .. -DBUILD_SLEEPY_DISCORD_EXAMPLES=1 -DCMAKE_TOOLCHAIN_FILE=D:\a\1\s\vcpkg\scripts\buildsystems\vcpkg.cmake -DOPENSSL_USE_STATIC_LIBS=TRUE -DOPENSSL_ROOT_DIR="D:\a\1\s\vcpkg\installed\x86-windows-static" -DBUILD_CPR_TESTS=OFF
32+
CMakeArgs: .. -A Win32 -DBUILD_SLEEPY_DISCORD_EXAMPLES=1 -DCMAKE_TOOLCHAIN_FILE=D:\a\1\s\vcpkg\scripts\buildsystems\vcpkg.cmake -DOPENSSL_USE_STATIC_LIBS=TRUE -DOPENSSL_ROOT_DIR="D:\a\1\s\vcpkg\installed\x86-windows-static" -DBUILD_CPR_TESTS=OFF
3333

34-
- task: VSBuild@1
34+
- task: CMake@1
3535
inputs:
36-
solution: '$(solution)'
37-
platform: '$(buildPlatform)'
38-
configuration: '$(buildConfiguration)'
36+
CMakeArgs: --build . --config Release

examples/hello/example0.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ class MyClientClass : public SleepyDiscord::DiscordClient {
1111

1212
int main() {
1313
MyClientClass client("token", SleepyDiscord::USER_CONTROLED_THREADS);
14-
client.setIntents(SleepyDiscord::Intent::SERVER_MESSAGES);
14+
client.setIntents(SleepyDiscord::Intent::SERVER_MESSAGES, SleepyDiscord::Intent::MESSAGE_CONTENT);
1515
client.run();
1616
}

examples/rock-paper-scissors/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ int main() {
139139
GameClient client("Your Token Goes Here", SleepyDiscord::USER_CONTROLED_THREADS);
140140
client.setIntents(
141141
SleepyDiscord::Intent::SERVER_MESSAGES,
142-
SleepyDiscord::Intent::DIRECT_MESSAGES);
142+
SleepyDiscord::Intent::DIRECT_MESSAGES,
143+
SleepyDiscord::Intent::MESSAGE_CONTENT);
143144
client.run();
144145
}

examples/sound-player/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <random> //For noise
2+
#include <queue>
23
#include "sleepy_discord/sleepy_discord.h"
34
#include "IO_file.h" //For music
45

@@ -319,6 +320,7 @@ int main()
319320
auto intentsList = {
320321
SleepyDiscord::Intent::SERVER_MESSAGES, //required for commands via messages
321322
SleepyDiscord::Intent::SERVER_VOICE_STATES, //required for connecting to voice
323+
SleepyDiscord::Intent::MESSAGE_CONTENT,
322324
};
323325
client.setIntents(intentsList);
324326
client.run();

include/sleepy_discord/IncludeNonexistent/uWS/uWS.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

include/sleepy_discord/IncludeNonexistent/websocketpp/config/asio_client.hpp

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
#pragma once
22

3-
#ifdef _WIN32
4-
#include <winsock2.h>
5-
#elif defined(unix) || defined(__unix__) || defined(__unix)
6-
#include <netinet/in.h>
7-
#endif
3+
#if !defined(NONEXISTENT_ASIO)
4+
#ifdef _WIN32
5+
#include <winsock2.h>
6+
#elif defined(unix) || defined(__unix__) || defined(__unix)
7+
#include <netinet/in.h>
8+
#endif
89

9-
#if !defined(SLEEPY_USE_BOOST) && !defined(EXISTENT_BOOST_ASIO)
10-
#define ASIO_STANDALONE
11-
#include "websocketpp_common.h"
12-
#ifdef NONEXISTENT_WEBSOCKETPP
10+
#if !defined(SLEEPY_USE_BOOST) && !defined(EXISTENT_BOOST_ASIO)
11+
#define ASIO_STANDALONE
1312
#include <asio.hpp>
1413
#ifdef NONEXISTENT_ASIO
1514
#undef ASIO_STANDALONE
1615
#define SLEEPY_USE_BOOST
1716
#endif
18-
#else
19-
namespace asio {
20-
using namespace websocketpp::lib::asio;
21-
}
2217
#endif
23-
#endif
2418

25-
#if defined(SLEEPY_USE_BOOST) || defined(EXISTENT_BOOST_ASIO)
26-
#include <boost/asio.hpp>
27-
#ifndef NONEXISTENT_BOOST_ASIO
28-
#undef NONEXISTENT_ASIO
29-
namespace asio {
30-
using namespace boost::asio;
31-
using boost::system::error_code;
19+
# if defined(ASIO_STANDALONE)
20+
# include <asio.hpp>
21+
namespace SleepyDiscord {
22+
using namespace ::asio;
3223
}
33-
#ifdef ASIO_STANDALONE
34-
#undef ASIO_STANDALONE
24+
#elif defined(SLEEPY_USE_BOOST) || defined(EXISTENT_BOOST_ASIO)
25+
#include <boost/asio.hpp>
26+
#ifndef NONEXISTENT_BOOST_ASIO
27+
#undef NONEXISTENT_ASIO
28+
#define SLEEPY_USE_BOOST_ASIO
29+
namespace SleepyDiscord {
30+
namespace asio {
31+
using namespace boost::asio;
32+
using boost::system::error_code;
33+
}
34+
}
35+
#ifdef ASIO_STANDALONE
36+
#undef ASIO_STANDALONE
37+
#endif
3538
#endif
3639
#endif
3740
#endif

include/sleepy_discord/asio_schedule.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ namespace SleepyDiscord {
1414
class ASIOBasedScheduleHandler : public GenericScheduleHandler {
1515
public:
1616
virtual ~ASIOBasedScheduleHandler() = default;
17-
virtual asio::io_service& getIOService() = 0;
17+
virtual asio::io_context& getIOContext() = 0;
1818
};
1919

2020
class ASIOScheduleHandler : public ASIOBasedScheduleHandler {
2121
public:
22-
ASIOScheduleHandler() {}
22+
ASIOScheduleHandler(std::shared_ptr<asio::io_context> _io):
23+
io(_io) {}
2324
virtual ~ASIOScheduleHandler() = default;
2425

25-
inline asio::io_service& getIOService() override {
26-
return io;
26+
inline asio::io_context& getIOContext() override {
27+
return *io;
2728
}
2829

2930
static void handleTimer(const asio::error_code &ec, std::function<void()>& code) {
@@ -32,20 +33,24 @@ namespace SleepyDiscord {
3233
}
3334
}
3435

35-
inline Timer schedule(TimedTask code, const time_t milliseconds) override {
36+
inline static Timer schedule(asio::io_context& io, TimedTask code, const time_t milliseconds) {
3637
auto timer = std::make_shared<asio::steady_timer>(io, asio::chrono::milliseconds(milliseconds));
3738
timer->async_wait(std::bind(&handleTimer, std::placeholders::_1, code));
3839
return Timer([timer]() {
3940
timer->cancel();
4041
});
4142
}
4243

44+
inline Timer schedule(TimedTask code, const time_t milliseconds) override {
45+
return ASIOScheduleHandler::schedule(*io, std::move(code), std::move(milliseconds));
46+
}
47+
4348
inline void run() {
44-
io.run();
49+
io->run();
4550
}
4651

4752
private:
48-
asio::io_service io;
53+
std::shared_ptr<asio::io_context> io;
4954
};
5055
#endif
5156
}

0 commit comments

Comments
 (0)