添加Visual Studio编译支持
This commit is contained in:
parent
aea49d6b31
commit
a08102fc30
|
@ -2,6 +2,8 @@
|
|||
build/
|
||||
lib/
|
||||
cmake*/
|
||||
out/
|
||||
CMakeSettings.json
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
@ -37,3 +39,14 @@ cmake*/
|
|||
*.app
|
||||
cmake-build-debug
|
||||
.idea
|
||||
.vs
|
||||
|
||||
# Built Dependencies
|
||||
dependencies/Http/out
|
||||
dependencies/Http/lib
|
||||
dependencies/Http/.vs./
|
||||
dependencies/Http/CMakeSettings.json
|
||||
dependencies/Person/out
|
||||
dependencies/Person/lib
|
||||
dependencies/Person/.vs./
|
||||
dependencies/Person/CMakeSettings.json
|
||||
|
|
|
@ -25,6 +25,9 @@ set(SOURCE_HEADER_PATH
|
|||
# 添加src目录下所有源文件(每次新增文件不要修改cmake,只需重新执行cmake命令)
|
||||
file(GLOB PLUGIN_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
||||
|
||||
if (MSVC)
|
||||
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif (MSVC)
|
||||
|
||||
# 添加动态库编译目标
|
||||
add_library(
|
||||
|
@ -38,11 +41,15 @@ target_include_directories(MiraiCPPlugin PUBLIC ${SOURCE_HEADER_PATH})
|
|||
|
||||
# 插件移植性
|
||||
if (WIN32)
|
||||
target_link_libraries(MiraiCPPlugin -static
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/libcurl.dll.a
|
||||
if (MINGW)
|
||||
target_link_libraries(MiraiCPPlugin -static
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/libHttp.dll.a
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/libiconv.dll.a
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/libPerson.dll.a)
|
||||
else (MSVC)
|
||||
target_link_libraries(MiraiCPPlugin -static
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Http.lib
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Person.lib)
|
||||
endif()
|
||||
endif (WIN32)
|
||||
if (UNIX)
|
||||
target_link_libraries(MiraiCPPlugin -static-libstdc++ -static-libgcc)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.24)
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
project(Http)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
|
|
@ -18,10 +18,18 @@
|
|||
#ifndef HTTP_LIBRARY_H
|
||||
#define HTTP_LIBRARY_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef EXPORT_HTTP
|
||||
#define HTTP_LIB __declspec(dllexport)
|
||||
#else
|
||||
#define HTTP_LIB __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Http {
|
||||
class Request {
|
||||
class HTTP_LIB Request {
|
||||
public:
|
||||
Request();
|
||||
~Request();
|
||||
|
@ -42,11 +50,13 @@ namespace Http {
|
|||
static size_t writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata);
|
||||
};
|
||||
|
||||
class FileUtilities {
|
||||
class HTTP_LIB FileUtilities {
|
||||
public:
|
||||
static std::string readFile(const std::string& path);
|
||||
static void writeFile(const std::string& path, const std::string& content);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //HTTP_LIBRARY_H
|
||||
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "library.h"
|
||||
#define EXPORT_HTTP
|
||||
|
||||
#include "http.h"
|
||||
|
||||
#include "curl/curl.h"
|
||||
#include <random>
|
||||
|
@ -23,7 +25,7 @@
|
|||
#include <sstream>
|
||||
|
||||
namespace Http {
|
||||
Request::Request() {
|
||||
HTTP_LIB Request::Request() {
|
||||
this->url = "";
|
||||
this->method = "GET";
|
||||
this->body = "";
|
||||
|
@ -32,33 +34,33 @@ namespace Http {
|
|||
this->verbose = false;
|
||||
}
|
||||
|
||||
Request::~Request() = default;
|
||||
HTTP_LIB Request::~Request() = default;
|
||||
|
||||
void Request::setUrl(const std::string& theUrl) {
|
||||
void HTTP_LIB Request::setUrl(const std::string& theUrl) {
|
||||
this->url = theUrl;
|
||||
}
|
||||
|
||||
void Request::setMethod(const std::string& theMethod) {
|
||||
void HTTP_LIB Request::setMethod(const std::string& theMethod) {
|
||||
this->method = theMethod;
|
||||
}
|
||||
|
||||
void Request::setBody(const std::string& theBody) {
|
||||
void HTTP_LIB Request::setBody(const std::string& theBody) {
|
||||
this->body = theBody;
|
||||
}
|
||||
|
||||
void Request::setHeader(const std::string& theHeader) {
|
||||
void HTTP_LIB Request::setHeader(const std::string& theHeader) {
|
||||
this->header = theHeader;
|
||||
}
|
||||
|
||||
void Request::setVerbose(bool theVerbose) {
|
||||
void HTTP_LIB Request::setVerbose(bool theVerbose) {
|
||||
this->verbose = theVerbose;
|
||||
}
|
||||
|
||||
std::string Request::getResponse() {
|
||||
std::string HTTP_LIB Request::getResponse() {
|
||||
return this->response;
|
||||
}
|
||||
|
||||
void Request::send() {
|
||||
void HTTP_LIB Request::send() {
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
curl = curl_easy_init();
|
||||
|
@ -78,14 +80,14 @@ namespace Http {
|
|||
}
|
||||
}
|
||||
|
||||
size_t Request::writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata) {
|
||||
size_t HTTP_LIB Request::writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata) {
|
||||
auto *response = static_cast<std::string *>(userdata);
|
||||
response->append(ptr, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
|
||||
std::string FileUtilities::readFile(const std::string &path) {
|
||||
std::string HTTP_LIB FileUtilities::readFile(const std::string &path) {
|
||||
std::ifstream file(path, std::ios::in | std::ios::binary | std::ios::ate);
|
||||
std::stringstream buffer;
|
||||
// read binary from path to the string
|
||||
|
@ -93,7 +95,7 @@ namespace Http {
|
|||
return buffer.str();
|
||||
}
|
||||
|
||||
void FileUtilities::writeFile(const std::string &path, const std::string &content) {
|
||||
void HTTP_LIB FileUtilities::writeFile(const std::string &path, const std::string &content) {
|
||||
std::ofstream file(path, std::ios::out | std::ios::binary);
|
||||
// write content to path in binary format
|
||||
file.write(content.c_str(), content.size());
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.24)
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
project(Person)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
|
|
@ -15,10 +15,12 @@
|
|||
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define EXPORT_PERSON
|
||||
|
||||
#include "Person.h"
|
||||
#include <random>
|
||||
|
||||
bool Person::isSignOnToday() const {
|
||||
bool PERSON_LIB Person::isSignOnToday() const {
|
||||
// Get today's 12:00 A.M. time point
|
||||
std::time_t now = std::time(nullptr);
|
||||
std::tm* nowTm = std::localtime(&now);
|
||||
|
@ -34,7 +36,7 @@ bool Person::isSignOnToday() const {
|
|||
return lastSignOnTime >= today;
|
||||
}
|
||||
|
||||
void Person::signOn() {
|
||||
void PERSON_LIB Person::signOn() {
|
||||
if (isSignOnToday()) {
|
||||
return;
|
||||
}
|
||||
|
@ -56,7 +58,7 @@ void Person::signOn() {
|
|||
copperCoin += static_cast<int>(dis(gen));
|
||||
}
|
||||
|
||||
int Person::continuousSignOnDays() const {
|
||||
int PERSON_LIB Person::continuousSignOnDays() const {
|
||||
// Check last sign-on date
|
||||
// If it's not yesterday, return 0
|
||||
// If it is yesterday or today, return signOnDays
|
||||
|
@ -83,36 +85,34 @@ int Person::continuousSignOnDays() const {
|
|||
}
|
||||
}
|
||||
|
||||
bool Person::willBeAttackNextTime() const {
|
||||
bool PERSON_LIB Person::willBeAttackNextTime() const {
|
||||
static std::default_random_engine e(std::time(nullptr));
|
||||
std::uniform_int_distribution<unsigned> u(0, 10000);
|
||||
// u(e) divide 100 is the probability
|
||||
switch (speakCount) {
|
||||
if (speakCount >= 0 && speakCount <= 73)
|
||||
// Case 0-73: the probability is 0.60%
|
||||
case 0 ... 73:
|
||||
return u(e) < 60;
|
||||
// Case 74-90:
|
||||
// The base probability is 6.60%
|
||||
// Increase by 6% for each 1 times
|
||||
// Max probability is 100%
|
||||
case 74 ... 90:
|
||||
return u(e) < 660 + 60 * (speakCount - 74);
|
||||
return u(e) < 60;
|
||||
else if (speakCount >= 74 && speakCount <= 90)
|
||||
// Case 74-90:
|
||||
// The base probability is 6.60%
|
||||
// Increase by 6% for each 1 times
|
||||
// Max probability is 100%
|
||||
return u(e) < 660 + 60 * (speakCount - 74);
|
||||
else
|
||||
// If speakCount > 90, the probability is 100%
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Person::resetAttackCount() {
|
||||
void PERSON_LIB Person::resetAttackCount() {
|
||||
speakCount = 0;
|
||||
}
|
||||
|
||||
void Person::increaseSpeakCount() {
|
||||
void PERSON_LIB Person::increaseSpeakCount() {
|
||||
speakCount++;
|
||||
}
|
||||
|
||||
// Serialize to JSON
|
||||
nlohmann::json Person::serializeToJSON() {
|
||||
nlohmann::json PERSON_LIB Person::serializeToJSON() {
|
||||
nlohmann::json j;
|
||||
j["qqID"] = qqID;
|
||||
j["lastSignOnTime"] = lastSignOnTime;
|
||||
|
@ -123,20 +123,32 @@ nlohmann::json Person::serializeToJSON() {
|
|||
}
|
||||
|
||||
// Deserialize from JSON
|
||||
Person::Person(const nlohmann::json &json) :
|
||||
PERSON_LIB Person::Person(const nlohmann::json &json) :
|
||||
qqID(json["qqID"]),
|
||||
lastSignOnTime(json["lastSignOnTime"]),
|
||||
signOnDays(json["signOnDays"]),
|
||||
speakCount(json["speakCount"]),
|
||||
copperCoin(json["copperCoin"]) {}
|
||||
|
||||
int Person::getCopperCoin() const {
|
||||
PERSON_LIB Person::~Person() = default;
|
||||
|
||||
PERSON_LIB Person::Person(const Person&) = default;
|
||||
|
||||
PERSON_LIB Person& Person::operator=(const Person&) = default;
|
||||
|
||||
PERSON_LIB Person::Person(Person&&) = default;
|
||||
|
||||
PERSON_LIB Person& Person::operator=(Person&&) = default;
|
||||
|
||||
int PERSON_LIB Person::getCopperCoin() const {
|
||||
return copperCoin;
|
||||
}
|
||||
|
||||
MiraiCP::QQID Person::getQQID() const {
|
||||
MiraiCP::QQID PERSON_LIB Person::getQQID() const {
|
||||
return qqID;
|
||||
}
|
||||
|
||||
Person::Person(MiraiCP::QQID id) :
|
||||
PERSON_LIB Person::Person() = default;
|
||||
|
||||
PERSON_LIB Person::Person(MiraiCP::QQID id) :
|
||||
qqID(id), lastSignOnTime(0), signOnDays(0), speakCount(0), copperCoin(0) {}
|
||||
|
|
|
@ -18,12 +18,21 @@
|
|||
#ifndef PERSON_DEMO_PERSON_H
|
||||
#define PERSON_DEMO_PERSON_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef EXPORT_PERSON
|
||||
#define PERSON_LIB __declspec(dllexport)
|
||||
#else
|
||||
#define PERSON_LIB __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <ctime>
|
||||
#include "json.hpp"
|
||||
|
||||
#ifndef MIRAICP_PRO_PLUGINCONFIG_H
|
||||
namespace MiraiCP {
|
||||
using QQID = unsigned long long;
|
||||
}
|
||||
#endif
|
||||
|
||||
class Person {
|
||||
private:
|
||||
|
@ -39,29 +48,29 @@ private:
|
|||
public:
|
||||
// Generate ctors and dtors
|
||||
// assignment operators
|
||||
Person() = default;
|
||||
explicit Person(MiraiCP::QQID id);
|
||||
PERSON_LIB Person();
|
||||
explicit PERSON_LIB Person(MiraiCP::QQID id);
|
||||
|
||||
// Deserialize from JSON
|
||||
explicit Person(const nlohmann::json&);
|
||||
~Person() = default;
|
||||
Person(const Person&) = default;
|
||||
Person& operator=(const Person&) = default;
|
||||
Person(Person&&) = default;
|
||||
Person& operator=(Person&&) = default;
|
||||
explicit PERSON_LIB Person(const nlohmann::json&);
|
||||
PERSON_LIB ~Person();
|
||||
PERSON_LIB Person(const Person&);
|
||||
PERSON_LIB Person& operator=(const Person&);
|
||||
PERSON_LIB Person(Person&&);
|
||||
PERSON_LIB Person& operator=(Person&&);
|
||||
|
||||
[[nodiscard]] bool isSignOnToday() const;
|
||||
void signOn();
|
||||
[[nodiscard]] int continuousSignOnDays() const;
|
||||
[[nodiscard]] bool PERSON_LIB isSignOnToday() const;
|
||||
void PERSON_LIB signOn();
|
||||
[[nodiscard]] int PERSON_LIB continuousSignOnDays() const;
|
||||
|
||||
[[nodiscard]] bool willBeAttackNextTime() const;
|
||||
void resetAttackCount();
|
||||
void increaseSpeakCount();
|
||||
[[nodiscard]] bool PERSON_LIB willBeAttackNextTime() const;
|
||||
void PERSON_LIB resetAttackCount();
|
||||
void PERSON_LIB increaseSpeakCount();
|
||||
|
||||
[[nodiscard]] int getCopperCoin() const;
|
||||
nlohmann::json serializeToJSON();
|
||||
[[nodiscard]] int PERSON_LIB getCopperCoin() const;
|
||||
nlohmann::json PERSON_LIB serializeToJSON();
|
||||
|
||||
[[nodiscard]] MiraiCP::QQID getQQID() const;
|
||||
[[nodiscard]] MiraiCP::QQID PERSON_LIB getQQID() const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
You should have received a copy of the GNU Affero General Public License along
|
||||
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define EXPORT_PERSON
|
||||
|
||||
#include "PersonCollection.h"
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
@ -36,7 +39,7 @@ namespace PersonCollection {
|
|||
// Refactoring:
|
||||
// loadPersonMap and savePersonMap are now using
|
||||
// globally defined localFilePath
|
||||
void loadPersonMap() {
|
||||
PERSON_LIB void loadPersonMap() {
|
||||
// If localFilePath is not defined
|
||||
if (initialized || localFilePath.empty() || !std::filesystem::exists(localFilePath)) {
|
||||
return;
|
||||
|
@ -56,7 +59,7 @@ namespace PersonCollection {
|
|||
initialized = true;
|
||||
}
|
||||
|
||||
void savePersonMap() {
|
||||
PERSON_LIB void savePersonMap() {
|
||||
// If localFilePath is not defined
|
||||
if (localFilePath.empty()) {
|
||||
// Throw an exception
|
||||
|
@ -77,19 +80,19 @@ namespace PersonCollection {
|
|||
ofs << j.dump(4);
|
||||
}
|
||||
|
||||
void addPerson(MiraiCP::QQID id) {
|
||||
PERSON_LIB void addPerson(MiraiCP::QQID id) {
|
||||
// Lock the mutex
|
||||
std::lock_guard<std::mutex> lock(personMapMutex);
|
||||
personMap[id] = Person(id);
|
||||
}
|
||||
|
||||
Person& getPerson(MiraiCP::QQID id) {
|
||||
PERSON_LIB Person& getPerson(MiraiCP::QQID id) {
|
||||
if (personMap.find(id) == personMap.end())
|
||||
personMap.insert({id, Person(id)});
|
||||
return personMap[id];
|
||||
}
|
||||
|
||||
void removePerson(MiraiCP::QQID id) {
|
||||
PERSON_LIB void removePerson(MiraiCP::QQID id) {
|
||||
// Lock the mutex
|
||||
std::lock_guard<std::mutex> lock(personMapMutex);
|
||||
personMap.erase(id);
|
||||
|
@ -107,7 +110,7 @@ namespace PersonCollection {
|
|||
}
|
||||
}
|
||||
|
||||
void registerLocalFile(const std::string &path) {
|
||||
PERSON_LIB void registerLocalFile(const std::string &path) {
|
||||
localFilePath = path;
|
||||
}
|
||||
}
|
|
@ -18,18 +18,25 @@
|
|||
#ifndef PERSON_DEMO_PERSONCOLLECTION_H
|
||||
#define PERSON_DEMO_PERSONCOLLECTION_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef EXPORT_PERSON
|
||||
#define PERSON_LIB __declspec(dllexport)
|
||||
#else
|
||||
#define PERSON_LIB __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <unordered_map>
|
||||
#include "Person.h"
|
||||
#include <string>
|
||||
|
||||
namespace PersonCollection {
|
||||
void loadPersonMap();
|
||||
void savePersonMap();
|
||||
void addPerson(MiraiCP::QQID id);
|
||||
Person& getPerson(MiraiCP::QQID id);
|
||||
void removePerson(MiraiCP::QQID id);
|
||||
void registerLocalFile(const std::string&);
|
||||
PERSON_LIB void loadPersonMap();
|
||||
PERSON_LIB void savePersonMap();
|
||||
PERSON_LIB void addPerson(MiraiCP::QQID id);
|
||||
PERSON_LIB Person& getPerson(MiraiCP::QQID id);
|
||||
PERSON_LIB void removePerson(MiraiCP::QQID id);
|
||||
PERSON_LIB void registerLocalFile(const std::string&);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,6 +17,22 @@
|
|||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#ifndef MIRAICP_PRO_PLUGINCONFIG_H
|
||||
#define MIRAICP_PRO_PLUGINCONFIG_H
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4474)
|
||||
#pragma warning(disable: 4615)
|
||||
#pragma warning(disable: 4819)
|
||||
#pragma warning(disable: 6031)
|
||||
#endif
|
||||
#elif defined(__linux__) || defined(unix) || defined(__unix__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
#elif defined(__APPLE__) || defined(__MACH__)
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
#include <json.hpp>
|
||||
namespace MiraiCP {
|
||||
const std::string MiraiCPVersion = "v2.12.0-RC2";
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <http.h>
|
||||
#include <regex>
|
||||
#include <RandomLibrary.h>
|
||||
#include <windef.h>
|
||||
|
||||
/**
|
||||
* @brief 获取临时文件名
|
||||
|
|
Loading…
Reference in New Issue