-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
133 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#pragma once | ||
|
||
using namespace geode::prelude; | ||
|
||
#ifdef GEODE_IS_WINDOWS | ||
#ifdef KM7DEV_SERVER_API_EXPORTING | ||
#define SERVER_API_DLL __declspec(dllexport) | ||
#else | ||
#define SERVER_API_DLL __declspec(dllimport) | ||
#endif | ||
#else | ||
#define SERVER_API_DLL __attribute__((visibility("default"))) | ||
#endif | ||
|
||
// thx prevter for the help | ||
|
||
struct GetCurrentServerEvent : geode::Event { | ||
GetCurrentServerEvent() {} | ||
|
||
int m_id = 0; | ||
std::string m_url = ""; | ||
int m_prio = 0; | ||
}; | ||
|
||
struct GetServerByIdEvent : geode::Event { | ||
GetServerByIdEvent(int id) : m_id(std::move(id)) {} | ||
|
||
int m_id = 0; | ||
std::string m_url = ""; | ||
int m_prio = 0; | ||
}; | ||
|
||
struct RegisterServerEvent : geode::Event { | ||
RegisterServerEvent(std::string url, int priority) : m_url(std::move(url)), m_priority(std::move(priority)) {} | ||
|
||
int m_id; | ||
std::string m_url = ""; | ||
int m_priority = 0; | ||
}; | ||
|
||
struct UpdateServerEvent : geode::Event { | ||
UpdateServerEvent(int id, std::string url , int priority) : m_id(std::move(id)), m_url(std::move(url)), m_priority(std::move(priority)) {} | ||
UpdateServerEvent(int id, std::string url) : m_id(std::move(id)), m_url(std::move(url)) {} | ||
UpdateServerEvent(int id, int priority) : m_id(std::move(id)), m_priority(std::move(priority)) {} | ||
|
||
int m_id = 0; | ||
std::string m_url = ""; | ||
int m_priority = 0; | ||
}; | ||
|
||
struct RemoveServerEvent : geode::Event { | ||
RemoveServerEvent(int id) : m_id(std::move(id)) {} | ||
|
||
int m_id = 0; | ||
}; | ||
|
||
struct GetBaseUrlEvent : geode::Event { | ||
GetBaseUrlEvent() {} | ||
|
||
std::string m_url = ""; | ||
}; | ||
|
||
struct GetRegisteredServersEvent : geode::Event { | ||
GetRegisteredServersEvent() {} | ||
|
||
std::map<int, std::pair<std::string, int>> m_servers = {}; | ||
}; | ||
|
||
namespace ServerAPIEvents { | ||
struct Server { | ||
int id; | ||
std::string url; | ||
int priority; | ||
}; | ||
|
||
inline Server getCurrentServer() { | ||
auto event = GetCurrentServerEvent(); | ||
event.post(); | ||
return {event.m_id, event.m_url, event.m_prio}; | ||
} | ||
|
||
inline Server getServerById(int id) { | ||
auto event = GetServerByIdEvent(id); | ||
event.post(); | ||
return {event.m_id, event.m_url, event.m_prio}; | ||
} | ||
|
||
inline Server registerServer(std::string url, int priority = 0) { | ||
auto event = RegisterServerEvent(url, priority); | ||
event.post(); | ||
return {event.m_id, event.m_url, event.m_priority}; | ||
} | ||
|
||
inline void updateServer(Server server) { | ||
auto event = UpdateServerEvent(server.id, server.url, server.priority); | ||
event.post(); | ||
} | ||
|
||
inline void updateServer(int id, std::string url, int priority) { | ||
auto event = UpdateServerEvent(id, url, priority); | ||
event.post(); | ||
} | ||
|
||
inline void updateServer(int id, std::string url) { | ||
auto event = UpdateServerEvent(id, url); | ||
event.post(); | ||
} | ||
|
||
inline void updateServer(int id, int priority) { | ||
auto event = UpdateServerEvent(id, priority); | ||
event.post(); | ||
} | ||
|
||
inline void removeServer(int id) { | ||
auto event = RemoveServerEvent(id); | ||
event.post(); | ||
} | ||
|
||
inline std::string getBaseUrl() { | ||
auto event = GetBaseUrlEvent(); | ||
event.post(); | ||
return event.m_url; | ||
} | ||
|
||
inline std::map<int, std::pair<std::string, int>> getRegisteredServers() { | ||
auto event = GetRegisteredServersEvent(); | ||
event.post(); | ||
return event.m_servers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters