BACKENDS: ENET: Now compiles and works on MSVC.

This commit is contained in:
Little Cat 2023-01-12 04:53:34 -04:00 committed by Eugene Sandulenko
parent 747b28504a
commit 1a50e10a83
5 changed files with 23 additions and 16 deletions

View File

@ -29,14 +29,16 @@ namespace Networking {
Host::Host(ENetHost *host) {
_host = host;
_serverPeer = nullptr;
_recentEvent = nullptr;
_recentHost = "";
_recentPort = 0;
_recentPacket = nullptr;
}
Host::Host(ENetHost *host, ENetPeer *serverPeer) {
_host = host;
_serverPeer = serverPeer;
_recentEvent = nullptr;
_recentHost = "";
_recentPort = 0;
_recentPacket = nullptr;
}
@ -49,7 +51,14 @@ Host::~Host() {
uint8 Host::service(int timeout) {
ENetEvent event;
enet_host_service(_host, &event, timeout);
_recentEvent = &event;
if (event.type > ENET_EVENT_TYPE_NONE) {
char hostName[50];
if (enet_address_get_host_ip(&event.peer->address, hostName, 50) == 0)
_recentHost = Common::String(hostName);
_recentPort = event.peer->address.port;
}
if (event.type == ENET_EVENT_TYPE_RECEIVE) {
if (_recentPacket)
destroyPacket();
@ -82,19 +91,11 @@ void Host::disconnectPeer(int peerIndex) {
}
Common::String Host::getHost() {
if (!_recentEvent)
return "";
char _hostName[50];
if (enet_address_get_host_ip(&_recentEvent->peer->address, _hostName, 50) == 0)
return Common::String(_hostName);
return "";
return _recentHost;
}
int Host::getPort() {
if (!_recentEvent || !_recentEvent->peer)
return 0;
return _recentEvent->peer->address.port;
return _recentPort;
}
int Host::getPeerIndexFromHost(Common::String host, int port) {

View File

@ -64,7 +64,8 @@ public:
private:
ENetHost *_host;
ENetPeer *_serverPeer; // Only used for clients.
ENetEvent *_recentEvent;
Common::String _recentHost;
int _recentPort;
ENetPacket *_recentPacket;

View File

@ -23,8 +23,11 @@
#define BACKENDS_NETWORKING_ENET_SOCKET_H
#ifdef WIN32
// TODO: Test me.
#include <winsock2.h>
// Including winsock2.h will result in errors, we have to define
// SOCKET ourselves.
#include <basetsd.h>
typedef UINT_PTR SOCKET;
typedef SOCKET ENetSocket;
#else
typedef int ENetSocket;

View File

@ -1078,6 +1078,7 @@ const Feature s_features[] = {
{ "fluidlite", "USE_FLUIDLITE", true, false, "FluidLite support" },
{ "libcurl", "USE_LIBCURL", true, true, "libcurl support" },
{ "sdlnet", "USE_SDL_NET", true, true, "SDL_net support" },
{ "enet", "USE_ENET", true, true, "ENet support" },
{ "discord", "USE_DISCORD", true, false, "Discord support" },
{ "retrowave", "USE_RETROWAVE", true, false, "RetroWave OPL3 support" },

View File

@ -74,6 +74,7 @@ std::string MSVCProvider::getLibraryFromFeature(const char *feature, const Build
{ "libcurl", "libcurl.lib", "libcurl-d.lib", "ws2_32.lib wldap32.lib crypt32.lib normaliz.lib", nullptr },
{ "sdlnet", "SDL_net.lib", nullptr, "iphlpapi.lib", nullptr },
{ "sdl2net", "SDL2_net.lib", nullptr, "iphlpapi.lib", "SDL_net.lib" },
{ "enet", "enet.lib", nullptr, "winmm.lib ws2_32.lib", nullptr },
{ "discord", "discord-rpc.lib", nullptr, nullptr, nullptr },
{ "retrowave", "retrowave.lib", nullptr, nullptr, nullptr },
// Feature flags with library dependencies