Change netplay initial gctime to be determined by the hosts initial time

This commit is contained in:
Ziek 2015-02-02 02:08:58 -08:00
parent 4cdc307b87
commit 074d688884
14 changed files with 62 additions and 68 deletions

View File

@ -534,6 +534,8 @@ include_directories(Source/Core)
# #
add_subdirectory(Externals/Bochs_disasm) add_subdirectory(Externals/Bochs_disasm)
include_directories(Externals/Bochs_disasm) include_directories(Externals/Bochs_disasm)
include_directories(Externals)
add_subdirectory(Externals/enet)
if(NOT XXHASH_FOUND) if(NOT XXHASH_FOUND)
message("Using static xxhash from Externals") message("Using static xxhash from Externals")

View File

@ -24,6 +24,7 @@ set(SRCS BreakPoints.cpp
SysConf.cpp SysConf.cpp
Thread.cpp Thread.cpp
Timer.cpp Timer.cpp
TraversalClient.cpp
Version.cpp Version.cpp
x64ABI.cpp x64ABI.cpp
x64Analyzer.cpp x64Analyzer.cpp
@ -33,7 +34,7 @@ set(SRCS BreakPoints.cpp
Logging/ConsoleListener.cpp Logging/ConsoleListener.cpp
Logging/LogManager.cpp) Logging/LogManager.cpp)
set(LIBS enet)
if(_M_ARM) if(_M_ARM)
if (_M_ARM_32) #ARMv7 if (_M_ARM_32) #ARMv7
set(SRCS ${SRCS} set(SRCS ${SRCS}

View File

@ -1,8 +1,7 @@
// This file is public domain, in case it's useful to anyone. -comex // 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 "Timer.h"
#include "Common/TraversalClient.h"
static void GetRandomishBytes(u8* buf, size_t size) 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) TraversalClient::TraversalClient(ENetHost* netHost, const std::string& server)
: m_NetHost(netHost) : m_NetHost(netHost)
, m_Server(server)
, m_Client(nullptr) , m_Client(nullptr)
, m_FailureReason(0) , m_FailureReason(0)
, m_ConnectRequestId(0) , m_ConnectRequestId(0)
, m_PendingConnect(false) , m_PendingConnect(false)
, m_Server(server)
, m_PingTime(0) , m_PingTime(0)
{ {
netHost->intercept = TraversalClient::InterceptCallback; netHost->intercept = TraversalClient::InterceptCallback;
@ -113,6 +112,8 @@ void TraversalClient::Update()
enet_packet_destroy(netEvent.packet); enet_packet_destroy(netEvent.packet);
break; break;
default:
break;
} }
} }
HandleResends(); HandleResends();
@ -343,9 +344,7 @@ bool EnsureTraversalClient(const std::string& server, u16 port)
return false; return false;
} }
g_MainNetHost.reset(host); g_MainNetHost.reset(host);
g_TraversalClient.reset(new TraversalClient(g_MainNetHost.get(), server)); g_TraversalClient.reset(new TraversalClient(g_MainNetHost.get(), server));
} }
return true; return true;
} }

View File

@ -7,7 +7,6 @@
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/Thread.h" #include "Common/Thread.h"
#include "Common/TraversalProto.h" #include "Common/TraversalProto.h"
#include "enet/enet.h" #include "enet/enet.h"
class TraversalClientClient class TraversalClientClient
@ -28,7 +27,6 @@ public:
Connected, Connected,
Failure Failure
}; };
enum FailureReason enum FailureReason
{ {
BadHost = 0x300, BadHost = 0x300,
@ -38,14 +36,12 @@ public:
ResendTimeout, ResendTimeout,
ConnectFailedError = 0x400, ConnectFailedError = 0x400,
}; };
TraversalClient(ENetHost* netHost, const std::string& server); TraversalClient(ENetHost* netHost, const std::string& server);
~TraversalClient(); ~TraversalClient();
void Reset(); void Reset();
void ConnectToClient(const std::string& host); void ConnectToClient(const std::string& host);
void ReconnectToServer(); void ReconnectToServer();
void Update(); void Update();
// called from NetHost // called from NetHost
bool TestPacket(u8* data, size_t size, ENetAddress* from); bool TestPacket(u8* data, size_t size, ENetAddress* from);
void HandleResends(); void HandleResends();
@ -63,14 +59,12 @@ private:
int tries; int tries;
enet_uint32 sendTime; enet_uint32 sendTime;
}; };
void HandleServerPacket(TraversalPacket* packet); void HandleServerPacket(TraversalPacket* packet);
void ResendPacket(OutgoingTraversalPacketInfo* info); void ResendPacket(OutgoingTraversalPacketInfo* info);
TraversalRequestId SendTraversalPacket(const TraversalPacket& packet); TraversalRequestId SendTraversalPacket(const TraversalPacket& packet);
void OnFailure(int reason); void OnFailure(int reason);
void HandlePing(); void HandlePing();
static int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event); static int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event);
TraversalRequestId m_ConnectRequestId; TraversalRequestId m_ConnectRequestId;
bool m_PendingConnect; bool m_PendingConnect;
std::list<OutgoingTraversalPacketInfo> m_OutgoingTraversalPackets; std::list<OutgoingTraversalPacketInfo> m_OutgoingTraversalPackets;
@ -78,11 +72,9 @@ private:
std::string m_Server; std::string m_Server;
enet_uint32 m_PingTime; enet_uint32 m_PingTime;
}; };
extern std::unique_ptr<TraversalClient> g_TraversalClient; extern std::unique_ptr<TraversalClient> g_TraversalClient;
// the NetHost connected to the TraversalClient. // the NetHost connected to the TraversalClient.
extern std::unique_ptr<ENetHost> g_MainNetHost; extern std::unique_ptr<ENetHost> g_MainNetHost;
// Create g_TraversalClient and g_MainNetHost if necessary. // Create g_TraversalClient and g_MainNetHost if necessary.
bool EnsureTraversalClient(const std::string& server, u16 port); bool EnsureTraversalClient(const std::string& server, u16 port);
void ReleaseTraversalClient(); void ReleaseTraversalClient();

View File

@ -247,6 +247,7 @@ set(LIBS
bdisasm bdisasm
common common
discio discio
enet
inputcommon inputcommon
${LZO} ${LZO}
sfml-network sfml-network

View File

@ -452,7 +452,7 @@ bool BeginRecordingInput(int controllers)
if (NetPlay::IsNetPlayRunning()) if (NetPlay::IsNetPlayRunning())
{ {
s_bNetPlay = true; s_bNetPlay = true;
s_recordingStartTime = NETPLAY_INITIAL_GCTIME; s_recordingStartTime = g_netplay_initial_gctime;
} }
else else
{ {

View File

@ -4,6 +4,8 @@
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/Movie.h"
#include "Core/NetPlayClient.h"
#include "Core/HW/EXI_DeviceIPL.h" #include "Core/HW/EXI_DeviceIPL.h"
#include "Core/HW/SI.h" #include "Core/HW/SI.h"
#include "Core/HW/SI_DeviceDanceMat.h" #include "Core/HW/SI_DeviceDanceMat.h"
@ -13,8 +15,6 @@
#include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/IPC_HLE/WII_IPC_HLE_Device_usb.h" #include "Core/IPC_HLE/WII_IPC_HLE_Device_usb.h"
#include "Core/IPC_HLE/WII_IPC_HLE_WiiMote.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 std::mutex crit_netplay_client;
static NetPlayClient * netplay_client = nullptr; static NetPlayClient * netplay_client = nullptr;
@ -57,7 +57,8 @@ NetPlayClient::~NetPlayClient()
// called from ---GUI--- thread // called from ---GUI--- thread
NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal) 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_client(nullptr)
, m_server(nullptr) , m_server(nullptr)
, m_is_running(false) , m_is_running(false)
@ -69,7 +70,6 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
, m_pid(0) , m_pid(0)
, m_connecting(false) , m_connecting(false)
, m_traversal_client(nullptr) , m_traversal_client(nullptr)
, m_state(Failure)
{ {
m_target_buffer_size = 20; m_target_buffer_size = 20;
ClearBuffers(); ClearBuffers();
@ -149,6 +149,8 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
m_thread = std::thread(&NetPlayClient::ThreadFunc, this); m_thread = std::thread(&NetPlayClient::ThreadFunc, this);
} }
return; return;
default:
break;
} }
} }
} }
@ -375,6 +377,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
g_NetPlaySettings.m_EXIDevice[0] = (TEXIDevices)tmp; g_NetPlaySettings.m_EXIDevice[0] = (TEXIDevices)tmp;
packet >> tmp; packet >> tmp;
g_NetPlaySettings.m_EXIDevice[1] = (TEXIDevices)tmp; g_NetPlaySettings.m_EXIDevice[1] = (TEXIDevices)tmp;
packet >> g_netplay_initial_gctime;
} }
m_dialog->OnMsgStartGame(); m_dialog->OnMsgStartGame();
@ -455,6 +459,8 @@ void NetPlayClient::Disconnect()
case ENET_EVENT_TYPE_DISCONNECT: case ENET_EVENT_TYPE_DISCONNECT:
m_server = nullptr; m_server = nullptr;
return; return;
default:
break;
} }
} }
//didn't disconnect gracefully force disconnect //didn't disconnect gracefully force disconnect
@ -495,6 +501,8 @@ void NetPlayClient::ThreadFunc()
netEvent.peer->data = nullptr; netEvent.peer->data = nullptr;
break; break;
default:
break;
} }
} }
@ -1050,7 +1058,7 @@ u32 CEXIIPL::NetPlay_GetGCTime()
std::lock_guard<std::mutex> lk(crit_netplay_client); std::lock_guard<std::mutex> lk(crit_netplay_client);
if (netplay_client) if (netplay_client)
return NETPLAY_INITIAL_GCTIME; return g_netplay_initial_gctime;
else else
return 0; return 0;
} }

View File

@ -7,6 +7,7 @@
#include <map> #include <map>
#include <queue> #include <queue>
#include <sstream> #include <sstream>
#include <SFML/Network/Packet.hpp>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/FifoQueue.h" #include "Common/FifoQueue.h"
#include "Common/Thread.h" #include "Common/Thread.h"
@ -14,7 +15,7 @@
#include "Common/TraversalClient.h" #include "Common/TraversalClient.h"
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
#include <SFML/Network/Packet.hpp>
class NetPlayUI class NetPlayUI
{ {
@ -97,7 +98,7 @@ protected:
Common::FifoQueue<GCPadStatus> m_pad_buffer[4]; Common::FifoQueue<GCPadStatus> m_pad_buffer[4];
Common::FifoQueue<NetWiimote> m_wiimote_buffer[4]; Common::FifoQueue<NetWiimote> m_wiimote_buffer[4];
NetPlayUI* m_dialog; NetPlayUI* m_dialog;
ENetHost* m_client; ENetHost* m_client;
ENetPeer* m_server; ENetPeer* m_server;

View File

@ -32,7 +32,7 @@ typedef std::vector<u8> NetWiimote;
#define NETPLAY_VERSION "Dolphin NetPlay 2014-01-08" #define NETPLAY_VERSION "Dolphin NetPlay 2014-01-08"
static const int NETPLAY_INITIAL_GCTIME = 1272737767; extern int g_netplay_initial_gctime;
// messages // messages
enum enum

View File

@ -4,13 +4,22 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "Common/StdMakeUnique.h" #include "Common/StdMakeUnique.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/HW/EXI_DeviceIPL.h"
#include "Core/NetPlayClient.h" //for NetPlayUI #include "Core/NetPlayClient.h" //for NetPlayUI
#include "Core/NetPlayServer.h" #include "Core/NetPlayServer.h"
#include "Core/HW/EXI_DeviceIPL.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
#if !defined(_WIN32)
#include <sys/types.h>
#include <sys/socket.h>
#ifndef ANDROID
#include <ifaddrs.h>
#endif
#include <arpa/inet.h>
#endif
int g_netplay_initial_gctime = 1272737767;
NetPlayServer::~NetPlayServer() NetPlayServer::~NetPlayServer()
{ {
@ -175,6 +184,8 @@ void NetPlayServer::ThreadFunc()
} }
} }
break; break;
default:
break;
} }
} }
} }
@ -285,7 +296,7 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket)
// add client to the player list // add client to the player list
{ {
std::lock_guard<std::recursive_mutex> lkp(m_crit.players); std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
m_players.emplace(player.socket->connectID, player); m_players.insert(std::pair<u32, Client>(player.socket->connectID, player));
std::lock_guard<std::recursive_mutex> lks(m_crit.send); std::lock_guard<std::recursive_mutex> lks(m_crit.send);
UpdatePadMapping(); // sync pad mappings with everyone UpdatePadMapping(); // sync pad mappings with everyone
UpdateWiimoteMapping(); UpdateWiimoteMapping();
@ -617,6 +628,8 @@ bool NetPlayServer::StartGame()
// no change, just update with clients // no change, just update with clients
AdjustPadBufferSize(m_target_buffer_size); AdjustPadBufferSize(m_target_buffer_size);
g_netplay_initial_gctime = CEXIIPL::GetGCTime();
// tell clients to start game // tell clients to start game
sf::Packet spac; sf::Packet spac;
spac << (MessageId)NP_MSG_START_GAME; spac << (MessageId)NP_MSG_START_GAME;
@ -630,6 +643,7 @@ bool NetPlayServer::StartGame()
spac << m_settings.m_OCFactor; spac << m_settings.m_OCFactor;
spac << m_settings.m_EXIDevice[0]; spac << m_settings.m_EXIDevice[0];
spac << m_settings.m_EXIDevice[1]; spac << m_settings.m_EXIDevice[1];
spac << g_netplay_initial_gctime;
std::lock_guard<std::recursive_mutex> lkp(m_crit.players); std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
std::lock_guard<std::recursive_mutex> lks(m_crit.send); std::lock_guard<std::recursive_mutex> lks(m_crit.send);
@ -712,44 +726,20 @@ std::vector<std::pair<std::string, std::string>> NetPlayServer::GetInterfaceList
std::vector<std::pair<std::string, std::string>> result; std::vector<std::pair<std::string, std::string>> result;
#if defined(_WIN32) #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) #elif defined(ANDROID)
// Android has no getifaddrs for some stupid reason. If this // Android has no getifaddrs for some stupid reason. If this
// functionality ends up actually being used on Android, fix this. // functionality ends up actually being used on Android, fix this.
#else #else
ifaddrs* ifp; ifaddrs* ifp = nullptr;
char buf[512]; char buf[512];
if (getifaddrs(&ifp) != -1) 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) if (sa->sa_family != AF_INET)
continue; 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) if (ntohl(((struct sockaddr_in*) sa)->sin_addr.s_addr) == 0x7f000001)
continue; continue;
const char* ip = inet_ntop(sa->sa_family, &sai->sin_addr, buf, sizeof(buf)); const char* ip = inet_ntop(sa->sa_family, &sai->sin_addr, buf, sizeof(buf));
@ -761,7 +751,7 @@ std::vector<std::pair<std::string, std::string>> NetPlayServer::GetInterfaceList
} }
#endif #endif
if (result.empty()) 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; return result;
} }

View File

@ -8,12 +8,11 @@
#include <queue> #include <queue>
#include <sstream> #include <sstream>
#include <unordered_set> #include <unordered_set>
#include "Common/Thread.h"
#include "Common/TraversalClient.h"
#include "Common/Timer.h"
#include "Core/NetPlayProto.h"
#include <SFML/Network/Packet.hpp> #include <SFML/Network/Packet.hpp>
#include "Common/Thread.h"
#include "Common/Timer.h"
#include "Common/TraversalClient.h"
#include "Core/NetPlayProto.h"
class NetPlayUI; class NetPlayUI;
@ -127,4 +126,4 @@ private:
static bool m_upnp_error; static bool m_upnp_error;
static std::thread m_upnp_thread; static std::thread m_upnp_thread;
#endif #endif
}; };

View File

@ -12,6 +12,7 @@
#include <wx/chartype.h> #include <wx/chartype.h>
#include <wx/checkbox.h> #include <wx/checkbox.h>
#include <wx/choice.h> #include <wx/choice.h>
#include <wx/clipbrd.h>
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/event.h> #include <wx/event.h>
@ -27,7 +28,7 @@
#include <wx/string.h> #include <wx/string.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/translation.h> #include <wx/translation.h>
#include <wx/clipbrd.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/FifoQueue.h" #include "Common/FifoQueue.h"
@ -416,12 +417,12 @@ NetPlayDiag::NetPlayDiag(wxWindow* const parent, const CGameListCtrl* const game
: wxFrame(parent, wxID_ANY, _("Dolphin NetPlay")) : wxFrame(parent, wxID_ANY, _("Dolphin NetPlay"))
, m_selected_game(game) , m_selected_game(game)
, m_start_btn(nullptr) , m_start_btn(nullptr)
, m_game_list(game_list)
, m_host_type_choice(nullptr)
, m_host_label(nullptr) , m_host_label(nullptr)
, m_host_type_choice(nullptr)
, m_host_copy_btn(nullptr) , m_host_copy_btn(nullptr)
, m_host_copy_btn_is_retry(false) , m_host_copy_btn_is_retry(false)
, m_is_hosting(is_hosting) , m_is_hosting(is_hosting)
, m_game_list(game_list)
{ {
Bind(wxEVT_THREAD, &NetPlayDiag::OnThread, this); Bind(wxEVT_THREAD, &NetPlayDiag::OnThread, this);

View File

@ -105,8 +105,8 @@ private:
wxListBox* m_player_lbox; wxListBox* m_player_lbox;
wxTextCtrl* m_chat_text; wxTextCtrl* m_chat_text;
wxTextCtrl* m_chat_msg_text; wxTextCtrl* m_chat_msg_text;
wxCheckBox* m_memcard_write; wxCheckBox* m_memcard_write;
wxCheckBox* m_record_chkbox; wxCheckBox* m_record_chkbox;
std::string m_selected_game; std::string m_selected_game;

View File

@ -413,8 +413,8 @@ Global
{CBC76802-C128-4B17-BF6C-23B08C313E5E}.Debug|Win32.Build.0 = Debug|Win32 {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.ActiveCfg = Debug|x64
{CBC76802-C128-4B17-BF6C-23B08C313E5E}.Debug|x64.Build.0 = 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.ActiveCfg = Release|x64
{CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Mixed Platforms.Build.0 = Release|Win32 {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.ActiveCfg = Release|Win32
{CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Win32.Build.0 = Release|Win32 {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|Win32.Build.0 = Release|Win32
{CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|x64.ActiveCfg = Release|x64 {CBC76802-C128-4B17-BF6C-23B08C313E5E}.Release|x64.ActiveCfg = Release|x64