diff --git a/CMakeLists.txt b/CMakeLists.txt index 85a98e4c16..a32aa40fa3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -534,6 +534,8 @@ include_directories(Source/Core) # add_subdirectory(Externals/Bochs_disasm) include_directories(Externals/Bochs_disasm) +include_directories(Externals) +add_subdirectory(Externals/enet) if(NOT XXHASH_FOUND) message("Using static xxhash from Externals") diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 95ff8b99b3..e4054d286e 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -24,6 +24,7 @@ set(SRCS BreakPoints.cpp SysConf.cpp Thread.cpp Timer.cpp + TraversalClient.cpp Version.cpp x64ABI.cpp x64Analyzer.cpp @@ -33,7 +34,7 @@ set(SRCS BreakPoints.cpp Logging/ConsoleListener.cpp Logging/LogManager.cpp) - +set(LIBS enet) if(_M_ARM) if (_M_ARM_32) #ARMv7 set(SRCS ${SRCS} diff --git a/Source/Core/Common/TraversalClient.cpp b/Source/Core/Common/TraversalClient.cpp index 9ac5eca238..17e77780c6 100644 --- a/Source/Core/Common/TraversalClient.cpp +++ b/Source/Core/Common/TraversalClient.cpp @@ -1,8 +1,7 @@ // This file is public domain, in case it's useful to anyone. -comex -#include "Common/TraversalClient.h" -#include "enet/enet.h" #include "Timer.h" +#include "Common/TraversalClient.h" static void GetRandomishBytes(u8* buf, size_t size) { @@ -15,11 +14,11 @@ static void GetRandomishBytes(u8* buf, size_t size) TraversalClient::TraversalClient(ENetHost* netHost, const std::string& server) : m_NetHost(netHost) - , m_Server(server) , m_Client(nullptr) , m_FailureReason(0) , m_ConnectRequestId(0) , m_PendingConnect(false) + , m_Server(server) , m_PingTime(0) { netHost->intercept = TraversalClient::InterceptCallback; @@ -113,6 +112,8 @@ void TraversalClient::Update() enet_packet_destroy(netEvent.packet); break; + default: + break; } } HandleResends(); @@ -343,9 +344,7 @@ bool EnsureTraversalClient(const std::string& server, u16 port) return false; } g_MainNetHost.reset(host); - g_TraversalClient.reset(new TraversalClient(g_MainNetHost.get(), server)); - } return true; } diff --git a/Source/Core/Common/TraversalClient.h b/Source/Core/Common/TraversalClient.h index 838ea6448a..c248e919e6 100644 --- a/Source/Core/Common/TraversalClient.h +++ b/Source/Core/Common/TraversalClient.h @@ -7,7 +7,6 @@ #include "Common/Common.h" #include "Common/Thread.h" #include "Common/TraversalProto.h" - #include "enet/enet.h" class TraversalClientClient @@ -28,7 +27,6 @@ public: Connected, Failure }; - enum FailureReason { BadHost = 0x300, @@ -38,14 +36,12 @@ public: ResendTimeout, ConnectFailedError = 0x400, }; - TraversalClient(ENetHost* netHost, const std::string& server); ~TraversalClient(); void Reset(); void ConnectToClient(const std::string& host); void ReconnectToServer(); void Update(); - // called from NetHost bool TestPacket(u8* data, size_t size, ENetAddress* from); void HandleResends(); @@ -63,14 +59,12 @@ private: int tries; enet_uint32 sendTime; }; - void HandleServerPacket(TraversalPacket* packet); void ResendPacket(OutgoingTraversalPacketInfo* info); TraversalRequestId SendTraversalPacket(const TraversalPacket& packet); void OnFailure(int reason); void HandlePing(); static int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event); - TraversalRequestId m_ConnectRequestId; bool m_PendingConnect; std::list m_OutgoingTraversalPackets; @@ -78,11 +72,9 @@ private: std::string m_Server; enet_uint32 m_PingTime; }; - extern std::unique_ptr g_TraversalClient; // the NetHost connected to the TraversalClient. extern std::unique_ptr g_MainNetHost; - // Create g_TraversalClient and g_MainNetHost if necessary. bool EnsureTraversalClient(const std::string& server, u16 port); void ReleaseTraversalClient(); diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index b3c0ec8fba..e98dbed7b7 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -247,6 +247,7 @@ set(LIBS bdisasm common discio + enet inputcommon ${LZO} sfml-network diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 3f2cfd8c6c..18264cac55 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -452,7 +452,7 @@ bool BeginRecordingInput(int controllers) if (NetPlay::IsNetPlayRunning()) { s_bNetPlay = true; - s_recordingStartTime = NETPLAY_INITIAL_GCTIME; + s_recordingStartTime = g_netplay_initial_gctime; } else { diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 77c9a06e71..55759b6f00 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -4,6 +4,8 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "Core/Movie.h" +#include "Core/NetPlayClient.h" #include "Core/HW/EXI_DeviceIPL.h" #include "Core/HW/SI.h" #include "Core/HW/SI_DeviceDanceMat.h" @@ -13,8 +15,6 @@ #include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/IPC_HLE/WII_IPC_HLE_Device_usb.h" #include "Core/IPC_HLE/WII_IPC_HLE_WiiMote.h" -#include "Core/Movie.h" -#include "Core/NetPlayClient.h" static std::mutex crit_netplay_client; static NetPlayClient * netplay_client = nullptr; @@ -57,7 +57,8 @@ NetPlayClient::~NetPlayClient() // called from ---GUI--- thread NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal) - : m_dialog(dialog) + : m_state(Failure) + , m_dialog(dialog) , m_client(nullptr) , m_server(nullptr) , m_is_running(false) @@ -69,7 +70,6 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay , m_pid(0) , m_connecting(false) , m_traversal_client(nullptr) - , m_state(Failure) { m_target_buffer_size = 20; ClearBuffers(); @@ -149,6 +149,8 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay m_thread = std::thread(&NetPlayClient::ThreadFunc, this); } return; + default: + break; } } } @@ -375,6 +377,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) g_NetPlaySettings.m_EXIDevice[0] = (TEXIDevices)tmp; packet >> tmp; g_NetPlaySettings.m_EXIDevice[1] = (TEXIDevices)tmp; + + packet >> g_netplay_initial_gctime; } m_dialog->OnMsgStartGame(); @@ -455,6 +459,8 @@ void NetPlayClient::Disconnect() case ENET_EVENT_TYPE_DISCONNECT: m_server = nullptr; return; + default: + break; } } //didn't disconnect gracefully force disconnect @@ -495,6 +501,8 @@ void NetPlayClient::ThreadFunc() netEvent.peer->data = nullptr; break; + default: + break; } } @@ -1050,7 +1058,7 @@ u32 CEXIIPL::NetPlay_GetGCTime() std::lock_guard lk(crit_netplay_client); if (netplay_client) - return NETPLAY_INITIAL_GCTIME; + return g_netplay_initial_gctime; else return 0; } diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index fab8e6548f..c6e39eb099 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "Common/CommonTypes.h" #include "Common/FifoQueue.h" #include "Common/Thread.h" @@ -14,7 +15,7 @@ #include "Common/TraversalClient.h" #include "Core/NetPlayProto.h" #include "InputCommon/GCPadStatus.h" -#include + class NetPlayUI { @@ -97,7 +98,7 @@ protected: Common::FifoQueue m_pad_buffer[4]; Common::FifoQueue m_wiimote_buffer[4]; - NetPlayUI* m_dialog; + NetPlayUI* m_dialog; ENetHost* m_client; ENetPeer* m_server; diff --git a/Source/Core/Core/NetPlayProto.h b/Source/Core/Core/NetPlayProto.h index b7409fa54b..8017933149 100644 --- a/Source/Core/Core/NetPlayProto.h +++ b/Source/Core/Core/NetPlayProto.h @@ -32,7 +32,7 @@ typedef std::vector NetWiimote; #define NETPLAY_VERSION "Dolphin NetPlay 2014-01-08" -static const int NETPLAY_INITIAL_GCTIME = 1272737767; +extern int g_netplay_initial_gctime; // messages enum diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 9282d71dbc..00b278ff87 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -4,13 +4,22 @@ #include #include - #include "Common/StdMakeUnique.h" #include "Common/StringUtil.h" -#include "Core/HW/EXI_DeviceIPL.h" #include "Core/NetPlayClient.h" //for NetPlayUI #include "Core/NetPlayServer.h" +#include "Core/HW/EXI_DeviceIPL.h" #include "InputCommon/GCPadStatus.h" +#if !defined(_WIN32) +#include +#include +#ifndef ANDROID +#include +#endif +#include +#endif + +int g_netplay_initial_gctime = 1272737767; NetPlayServer::~NetPlayServer() { @@ -175,6 +184,8 @@ void NetPlayServer::ThreadFunc() } } break; + default: + break; } } } @@ -285,7 +296,7 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket) // add client to the player list { std::lock_guard lkp(m_crit.players); - m_players.emplace(player.socket->connectID, player); + m_players.insert(std::pair(player.socket->connectID, player)); std::lock_guard lks(m_crit.send); UpdatePadMapping(); // sync pad mappings with everyone UpdateWiimoteMapping(); @@ -617,6 +628,8 @@ bool NetPlayServer::StartGame() // no change, just update with clients AdjustPadBufferSize(m_target_buffer_size); + g_netplay_initial_gctime = CEXIIPL::GetGCTime(); + // tell clients to start game sf::Packet spac; spac << (MessageId)NP_MSG_START_GAME; @@ -630,6 +643,7 @@ bool NetPlayServer::StartGame() spac << m_settings.m_OCFactor; spac << m_settings.m_EXIDevice[0]; spac << m_settings.m_EXIDevice[1]; + spac << g_netplay_initial_gctime; std::lock_guard lkp(m_crit.players); std::lock_guard lks(m_crit.send); @@ -712,44 +726,20 @@ std::vector> NetPlayServer::GetInterfaceList std::vector> result; #if defined(_WIN32) -#elif defined(__APPLE__) - // we do this to get the friendly names rather than the BSD ones. ew. - if (m_dynamic_store && m_prefs) - { - CFArrayRef ary = SCNetworkServiceCopyAll((SCPreferencesRef)m_prefs); - for (CFIndex i = 0; i < CFArrayGetCount(ary); i++) - { - SCNetworkServiceRef ifr = (SCNetworkServiceRef)CFArrayGetValueAtIndex(ary, i); - std::string name = CFStrToStr(SCNetworkServiceGetName(ifr)); - CFStringRef key = SCDynamicStoreKeyCreateNetworkServiceEntity(NULL, kSCDynamicStoreDomainState, SCNetworkServiceGetServiceID(ifr), kSCEntNetIPv4); - CFDictionaryRef props = (CFDictionaryRef)SCDynamicStoreCopyValue((SCDynamicStoreRef)m_dynamic_store, key); - CFRelease(key); - if (!props) - continue; - CFArrayRef ipary = (CFArrayRef)CFDictionaryGetValue(props, kSCPropNetIPv4Addresses); - if (ipary) - { - for (CFIndex j = 0; j < CFArrayGetCount(ipary); j++) - result.emplace_back(std::make_pair(name, CFStrToStr((CFStringRef)CFArrayGetValueAtIndex(ipary, j)))); - CFRelease(ipary); - } - } - CFRelease(ary); - } #elif defined(ANDROID) // Android has no getifaddrs for some stupid reason. If this // functionality ends up actually being used on Android, fix this. #else - ifaddrs* ifp; + ifaddrs* ifp = nullptr; char buf[512]; if (getifaddrs(&ifp) != -1) { - for (struct ifaddrs* curifp = ifp; curifp; curifp = curifp->ifa_next) + for (ifaddrs* curifp = ifp; curifp; curifp = curifp->ifa_next) { - struct sockaddr* sa = curifp->ifa_addr; + sockaddr* sa = curifp->ifa_addr; if (sa->sa_family != AF_INET) continue; - struct sockaddr_in* sai = (struct sockaddr_in*) sa; + sockaddr_in* sai = (struct sockaddr_in*) sa; if (ntohl(((struct sockaddr_in*) sa)->sin_addr.s_addr) == 0x7f000001) continue; const char* ip = inet_ntop(sa->sa_family, &sai->sin_addr, buf, sizeof(buf)); @@ -761,7 +751,7 @@ std::vector> NetPlayServer::GetInterfaceList } #endif if (result.empty()) - result.push_back(std::make_pair("!local!", "127.0.0.1")); + result.emplace_back(std::make_pair("!local!", "127.0.0.1")); return result; } diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index 6fa7909822..3a589aa2ca 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -8,12 +8,11 @@ #include #include #include - -#include "Common/Thread.h" -#include "Common/TraversalClient.h" -#include "Common/Timer.h" -#include "Core/NetPlayProto.h" #include +#include "Common/Thread.h" +#include "Common/Timer.h" +#include "Common/TraversalClient.h" +#include "Core/NetPlayProto.h" class NetPlayUI; @@ -127,4 +126,4 @@ private: static bool m_upnp_error; static std::thread m_upnp_thread; #endif -}; +}; \ No newline at end of file diff --git a/Source/Core/DolphinWX/NetWindow.cpp b/Source/Core/DolphinWX/NetWindow.cpp index 8d99a9403b..c06348be5f 100644 --- a/Source/Core/DolphinWX/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetWindow.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,7 @@ #include #include #include -#include + #include "Common/CommonTypes.h" #include "Common/FifoQueue.h" @@ -416,12 +417,12 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game : wxFrame(parent, wxID_ANY, _("Dolphin NetPlay")) , m_selected_game(game) , m_start_btn(nullptr) - , m_game_list(game_list) - , m_host_type_choice(nullptr) , m_host_label(nullptr) + , m_host_type_choice(nullptr) , m_host_copy_btn(nullptr) , m_host_copy_btn_is_retry(false) , m_is_hosting(is_hosting) + , m_game_list(game_list) { Bind(wxEVT_THREAD, &NetPlayDiag::OnThread, this); diff --git a/Source/Core/DolphinWX/NetWindow.h b/Source/Core/DolphinWX/NetWindow.h index 31cbf17b71..03dc0b5def 100644 --- a/Source/Core/DolphinWX/NetWindow.h +++ b/Source/Core/DolphinWX/NetWindow.h @@ -105,8 +105,8 @@ private: wxListBox* m_player_lbox; wxTextCtrl* m_chat_text; - wxTextCtrl* m_chat_msg_text; - wxCheckBox* m_memcard_write; + wxTextCtrl* m_chat_msg_text; + wxCheckBox* m_memcard_write; wxCheckBox* m_record_chkbox; std::string m_selected_game; diff --git a/Source/dolphin-emu.sln b/Source/dolphin-emu.sln index be749a56ae..1e21befeca 100644 --- a/Source/dolphin-emu.sln +++ b/Source/dolphin-emu.sln @@ -413,8 +413,8 @@ Global {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Debug|Win32.Build.0 = Debug|Win32 {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Debug|x64.ActiveCfg = Debug|x64 {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Debug|x64.Build.0 = Debug|x64 - {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Mixed Platforms.Build.0 = Release|Win32 + {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Mixed Platforms.Build.0 = Release|x64 {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Win32.ActiveCfg = Release|Win32 {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Win32.Build.0 = Release|Win32 {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|x64.ActiveCfg = Release|x64