mirror of https://github.com/OpenTTD/OpenTTD
Linux loader attempt
parent
0bf94569e3
commit
0a035d48f3
|
@ -846,7 +846,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
|
||||||
SetLocalCompany(_network_join.company);
|
SetLocalCompany(_network_join.company);
|
||||||
}
|
}
|
||||||
|
|
||||||
JoinData data = {
|
OTTD_Social_Event_Server_Joined_Data data = {
|
||||||
"Unknown", // TODO: fix this
|
"Unknown", // TODO: fix this
|
||||||
this->connection_string.c_str()
|
this->connection_string.c_str()
|
||||||
};
|
};
|
||||||
|
|
|
@ -195,7 +195,7 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(Packet *p)
|
||||||
* attempt to re-use when registering again. */
|
* attempt to re-use when registering again. */
|
||||||
_network_server_invite_code = _settings_client.network.server_invite_code;
|
_network_server_invite_code = _settings_client.network.server_invite_code;
|
||||||
|
|
||||||
JoinData data = {
|
OTTD_Social_Event_Server_Joined_Data data = {
|
||||||
_settings_client.network.server_name.c_str(),
|
_settings_client.network.server_name.c_str(),
|
||||||
_network_server_invite_code.c_str()
|
_network_server_invite_code.c_str()
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,9 @@ void callback(const char* serverName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SocialPlatformLoader::SocialPlatformLoader() {
|
SocialPlatformLoader::SocialPlatformLoader() {
|
||||||
|
#if !defined(__EMSCRIPTEN__)
|
||||||
LoadSocialPlatforms(this->plugins);
|
LoadSocialPlatforms(this->plugins);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (SocialPlatformPlugin plugin : plugins) {
|
for (SocialPlatformPlugin plugin : plugins) {
|
||||||
plugin.initialize(callback, &plugin.userdata);
|
plugin.initialize(callback, &plugin.userdata);
|
||||||
|
@ -35,7 +37,7 @@ void SocialPlatformLoader::RunDispatch() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocialPlatformLoader::NewState(eventCode event, void* parameter) {
|
void SocialPlatformLoader::NewState(OTTD_Social_Event event, void* parameter) {
|
||||||
for (SocialPlatformPlugin plugin : plugins) {
|
for (SocialPlatformPlugin plugin : plugins) {
|
||||||
plugin.newState(event, parameter, plugin.userdata);
|
plugin.newState(event, parameter, plugin.userdata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class SocialPlatformLoader {
|
||||||
public:
|
public:
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
void RunDispatch();
|
void RunDispatch();
|
||||||
void NewState(eventCode event, void* parameter);
|
void NewState(OTTD_Social_Event event, void* parameter);
|
||||||
|
|
||||||
static SocialPlatformLoader* GetInstance();
|
static SocialPlatformLoader* GetInstance();
|
||||||
|
|
||||||
|
@ -37,7 +37,9 @@ private:
|
||||||
std::vector<SocialPlatformPlugin> plugins;
|
std::vector<SocialPlatformPlugin> plugins;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !defined(__EMSCRIPTEN__)
|
||||||
/* Defined in os/<os>/social_<os>.cpp. */
|
/* Defined in os/<os>/social_<os>.cpp. */
|
||||||
void LoadSocialPlatforms(std::vector<SocialPlatformPlugin>& plugins);
|
void LoadSocialPlatforms(std::vector<SocialPlatformPlugin>& plugins);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct JoinData {
|
struct OTTD_Social_Event_Server_Joined_Data {
|
||||||
// Name of the server as shown to players.
|
// Name of the server as shown to players.
|
||||||
const char* server_name;
|
const char* server_name;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ struct JoinData {
|
||||||
const char* connection_string;
|
const char* connection_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum eventCode {
|
enum OTTD_Social_Event {
|
||||||
// Called when the player has entered the main menu.
|
// Called when the player has entered the main menu.
|
||||||
// Parameter: N/A
|
// Parameter: N/A
|
||||||
OTTD_SOCIAL_EVENT_MENU,
|
OTTD_SOCIAL_EVENT_MENU,
|
||||||
|
@ -46,7 +46,9 @@ typedef void (* OTTD_Social_JoinCallback)(const char* serverName);
|
||||||
|
|
||||||
// Initializes the plugin.
|
// Initializes the plugin.
|
||||||
// The plugin is free to initialize the memory pointed to at the given address with any structure it needs to keep data around.
|
// The plugin is free to initialize the memory pointed to at the given address with any structure it needs to keep data around.
|
||||||
// The plugin loader will keep track of this memory for the plugin.
|
// The plugin loader will keep track of this memory for the plugin. It remains valid until the shutdown function is called.
|
||||||
|
//
|
||||||
|
// The callback function is a static reference to a function, however, the plugin should leverage its user data to keep track of it.
|
||||||
typedef bool (* OTTD_Social_Initialize)(OTTD_Social_JoinCallback callback, void **userdata);
|
typedef bool (* OTTD_Social_Initialize)(OTTD_Social_JoinCallback callback, void **userdata);
|
||||||
|
|
||||||
// Called by the plugin loader to indicate that OpenTTD is currently shutting down.
|
// Called by the plugin loader to indicate that OpenTTD is currently shutting down.
|
||||||
|
@ -57,7 +59,9 @@ typedef void (* OTTD_Social_Shutdown)(void *userdata);
|
||||||
typedef void (* OTTD_Social_Dispatch)(void *userdata);
|
typedef void (* OTTD_Social_Dispatch)(void *userdata);
|
||||||
|
|
||||||
// Called when the game's state changes.
|
// Called when the game's state changes.
|
||||||
typedef void (* OTTD_Social_NewState)(eventCode event, void* parameter, void *userdata);
|
//
|
||||||
|
// The data pointed to by parameter is only valid during the duration of this function.
|
||||||
|
typedef void (* OTTD_Social_NewState)(OTTD_Social_Event event, void* parameter, void *userdata);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ add_files(
|
||||||
|
|
||||||
add_files(
|
add_files(
|
||||||
unix.cpp
|
unix.cpp
|
||||||
|
social_unix.cpp
|
||||||
CONDITION UNIX
|
CONDITION UNIX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file social_unix.cpp Unix like backing implementation for social plugin loading. */
|
||||||
|
|
||||||
|
#include "../../stdafx.h"
|
||||||
|
#include "../../fileio_func.h"
|
||||||
|
#include "../../string_func.h"
|
||||||
|
#include "../../network/social/loader.h"
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../../safeguards.h"
|
||||||
|
|
||||||
|
void LoadSocialPlatforms(std::vector<SocialPlatformPlugin>& plugins) {
|
||||||
|
std::string search_dir = FioGetDirectory(SP_BINARY_DIR, BASE_DIR);
|
||||||
|
|
||||||
|
DIR* directory = opendir(OTTD2FS(search_dir).c_str());
|
||||||
|
if (directory == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
struct dirent* entry = readdir(directory);
|
||||||
|
if (entry == nullptr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StrEndsWith(FS2OTTD(entry->d_name), ".ots")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string library_path = search_dir + FS2OTTD(entry->d_name);
|
||||||
|
void* library = dlopen(library_path.c_str(), 0);
|
||||||
|
if (library == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SocialPlatformPlugin plugin = {
|
||||||
|
library,
|
||||||
|
|
||||||
|
(OTTD_Social_Initialize)dlsym(library, "OTTD_Social_Initialize"),
|
||||||
|
(OTTD_Social_Shutdown)dlsym(library, "OTTD_Social_Shutdown"),
|
||||||
|
(OTTD_Social_Dispatch)dlsym(library, "OTTD_Social_Dispatch"),
|
||||||
|
(OTTD_Social_NewState)dlsym(library, "OTTD_Social_NewState"),
|
||||||
|
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
if (plugin.initialize == nullptr || plugin.shutdown == nullptr || plugin.dispatch == nullptr || plugin.newState == nullptr) {
|
||||||
|
dlclose(library);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.push_back(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(directory);
|
||||||
|
}
|
|
@ -8,11 +8,9 @@
|
||||||
/** @file social_win.cpp Win32 backing implementation for social plugin loading. */
|
/** @file social_win.cpp Win32 backing implementation for social plugin loading. */
|
||||||
|
|
||||||
#include "../../stdafx.h"
|
#include "../../stdafx.h"
|
||||||
|
|
||||||
#include "../../network/social/loader.h"
|
|
||||||
#include "../../fileio_func.h"
|
#include "../../fileio_func.h"
|
||||||
|
#include "../../network/social/loader.h"
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include "../../safeguards.h"
|
#include "../../safeguards.h"
|
||||||
|
@ -20,35 +18,38 @@
|
||||||
void LoadSocialPlatforms(std::vector<SocialPlatformPlugin>& plugins) {
|
void LoadSocialPlatforms(std::vector<SocialPlatformPlugin>& plugins) {
|
||||||
std::string search_dir = FioGetDirectory(SP_BINARY_DIR, BASE_DIR);
|
std::string search_dir = FioGetDirectory(SP_BINARY_DIR, BASE_DIR);
|
||||||
|
|
||||||
WIN32_FIND_DATAW find_data = {};
|
WIN32_FIND_DATAW find_data = { };
|
||||||
HANDLE find_handle = FindFirstFileW(OTTD2FS(search_dir + "*.ots").c_str(), &find_data);
|
HANDLE find_handle = FindFirstFileW(OTTD2FS(search_dir + "*.ots").c_str(), &find_data);
|
||||||
if (find_handle != INVALID_HANDLE_VALUE) {
|
if (find_handle == INVALID_HANDLE_VALUE) {
|
||||||
do {
|
return;
|
||||||
std::string library_path = search_dir + FS2OTTD(find_data.cFileName);
|
|
||||||
HMODULE library = LoadLibraryW(OTTD2FS(library_path).c_str());
|
|
||||||
if (library == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SocialPlatformPlugin plugin = {
|
|
||||||
library,
|
|
||||||
|
|
||||||
(OTTD_Social_Initialize)GetProcAddress(library, "OTTD_Social_Initialize"),
|
|
||||||
(OTTD_Social_Shutdown)GetProcAddress(library, "OTTD_Social_Shutdown"),
|
|
||||||
(OTTD_Social_Dispatch)GetProcAddress(library, "OTTD_Social_Dispatch"),
|
|
||||||
(OTTD_Social_NewState)GetProcAddress(library, "OTTD_Social_NewState"),
|
|
||||||
|
|
||||||
nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
if (plugin.initialize == nullptr || plugin.shutdown == nullptr || plugin.dispatch == nullptr || plugin.newState == nullptr) {
|
|
||||||
FreeLibrary(library);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.push_back(plugin);
|
|
||||||
} while (FindNextFileW(find_handle, &find_data));
|
|
||||||
|
|
||||||
FindClose(find_handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
std::string library_path = search_dir + FS2OTTD(find_data.cFileName);
|
||||||
|
HMODULE library = LoadLibraryW(OTTD2FS(library_path).c_str());
|
||||||
|
if (library == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SocialPlatformPlugin plugin = {
|
||||||
|
library,
|
||||||
|
|
||||||
|
(OTTD_Social_Initialize)GetProcAddress(library, "OTTD_Social_Initialize"),
|
||||||
|
(OTTD_Social_Shutdown)GetProcAddress(library, "OTTD_Social_Shutdown"),
|
||||||
|
(OTTD_Social_Dispatch)GetProcAddress(library, "OTTD_Social_Dispatch"),
|
||||||
|
(OTTD_Social_NewState)GetProcAddress(library, "OTTD_Social_NewState"),
|
||||||
|
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
if (plugin.initialize == nullptr || plugin.shutdown == nullptr || plugin.dispatch == nullptr || plugin.newState == nullptr) {
|
||||||
|
FreeLibrary(library);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.push_back(plugin);
|
||||||
|
} while (FindNextFileW(find_handle, &find_data) == TRUE);
|
||||||
|
|
||||||
|
FindClose(find_handle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue