NetPlay: completely redone - should be somewhat usable when using Single Core and DSP LLE Plugin.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5425 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2010-05-01 19:10:35 +00:00
parent 1796cbc917
commit a6d6d27328
16 changed files with 1544 additions and 2497 deletions
+1
View File
@@ -86,6 +86,7 @@
#define HAVE_OPENAL 1
#define HAVE_ALSA 0
#define HAVE_PORTAUDIO 0
#define HAVE_SFML 1
// it is VERY DANGEROUS to mix _SECURE_SCL=0 and _SECURE_SCL=1 compiled libraries.
// You will get bizarre crash bugs whenever you use STL.
+6 -1
View File
@@ -415,7 +415,12 @@ u32 CEXIIPL::GetGCTime()
u64 ltime = Common::Timer::GetTimeSinceJan1970();
return ((u32)ltime - cJanuary2000 - Bias);
#else
u64 ltime = Common::Timer::GetLocalTimeSinceJan1970();
// hack in some netplay stuff
u64 ltime = GetNetGCTime();
if (0 == ltime)
ltime = Common::Timer::GetLocalTimeSinceJan1970();
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
return ((u32)ltime - cJanuary2000 - cWiiBias/* + 32434790*/);
else
+2
View File
@@ -32,6 +32,8 @@ public:
void DoState(PointerWrap &p);
static u32 GetGCTime();
static u32 GetNetGCTime();
static void Descrambler(u8* data, u32 size);
private:
+6 -176
View File
@@ -923,185 +923,15 @@
Name="NetPlay"
>
<File
RelativePath=".\Src\NetEvent.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Src\NetFunctions.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Src\NetSockets.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
ForcedIncludeFiles="$(NOINHERIT)"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Src\NetSockets.h"
RelativePath=".\Src\LockingQueue.h"
>
</File>
<File
RelativePath=".\Src\NetStructs.h"
RelativePath=".\Src\NetPlay.cpp"
>
</File>
<File
RelativePath=".\Src\NetPlay.h"
>
</File>
<File
+2 -3
View File
@@ -187,8 +187,7 @@ void CFrame::CreateMenu()
toolsMenu->Append(IDM_CHEATS, _T("Action &Replay Manager"));
#if defined(HAVE_SFML) && HAVE_SFML
// Disabled for now, netplay doesn't quite work currently
// toolsMenu->Append(IDM_NETPLAY, _T("Start &NetPlay"));
toolsMenu->Append(IDM_NETPLAY, _T("Start &NetPlay"));
#endif
if (DiscIO::CNANDContentManager::Access().GetNANDLoader(std::string (File::GetUserPath(D_WIIMENU_IDX))).IsValid())
@@ -1000,7 +999,7 @@ void CFrame::StatusBarMessage(const char * Text, ...)
void CFrame::OnNetPlay(wxCommandEvent& WXUNUSED (event))
{
#if defined(HAVE_SFML) && HAVE_SFML
new NetPlay(this, m_GameListCtrl->GetGamePaths(), m_GameListCtrl->GetGameNames());
new NetPlaySetupDiag(this, m_GameListCtrl);
#endif
}
+47
View File
@@ -0,0 +1,47 @@
#ifndef _LOCKINGQUEUE_H_
#define _LOCKINGQUEUE_H_
#include "Thread.h"
#include <queue>
// i should make one of those single reader/ single writer queues
template <typename T>
class LockingQueue
{
public:
size_t Size()
{
m_crit.Enter();
const size_t s = m_queue.size();
m_crit.Leave();
return s;
}
void Push(const T& t)
{
m_crit.Enter();
m_queue.push(t);
m_crit.Leave();
}
bool Pop(T& t)
{
m_crit.Enter();
if (m_queue.size())
{
t = m_queue.front();
m_queue.pop();
m_crit.Leave();
return true;
}
m_crit.Leave();
return false;
}
private:
std::queue<T> m_queue;
Common::CriticalSection m_crit;
};
#endif
-289
View File
@@ -1,289 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program 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.0.
// This program 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "NetSockets.h"
#include "NetWindow.h"
void ClientSide::OnClientData(unsigned char data)
{
unsigned char sent = 0;
u32 buffer_size;
size_t recv_size;
char *buffer = NULL;
switch (data)
{
case 0x10: // Player joined server
{
// Read GameFound
m_socket.Receive((char*)&sent, 1, recv_size);
// Read nickname
m_socket.Receive((char*)&buffer_size, 4, recv_size);
buffer = new char[buffer_size+1];
m_socket.Receive(buffer, buffer_size+1, recv_size);
Event->AppendText(wxString::FromAscii(StringFromFormat("*Player : %s is now connected to Host...\n", buffer).c_str()));
if (sent != 0x1F)
for (int i = 0; i < 4; i++)
Event->AppendText(_("WARNING : Game Not Found on Client Side!\n"));
m_numplayers++;
Event->SendEvent(HOST_NEWPLAYER);
break;
}
case 0x11: // Player left server
{
// Read Nickname
m_socket.Receive((char*)&buffer_size, 4, recv_size);
buffer = new char[buffer_size+1];
m_socket.Receive(buffer, buffer_size+1, recv_size);
Event->AppendText(wxString::FromAscii(StringFromFormat("*Player : %s left the game\n\n", buffer).c_str()));
m_numplayers--;
Event->SendEvent(HOST_PLAYERLEFT);
break;
}
case 0x15: // Ping Player
{
m_socket.Receive((char*)&buffer_size, 4, recv_size);
m_socket.Send((const char*)&buffer_size, 4);
break;
}
case 0x20: // IP request
{
//buffer_size = m_addr.size();
//m_socket.Send((const char*)&buffer_size, 4);
m_socket.Send((const char*)&data, 1);
m_socket.Send(m_addr.c_str(), m_addr.size() + 1);
break;
}
case 0x30: // Chat message received from server
{
m_socket.Receive((char*)&buffer_size, 4, recv_size);
buffer = new char[buffer_size+1];
m_socket.Receive(buffer, buffer_size+1, recv_size);
if (recv_size > 1024)
{
//something wrong...
delete[] buffer;
return;
}
Event->AppendText(wxString::FromAscii(buffer));
break;
}
case 0x35: // ChangeGame message received
{
m_socket.Receive((char*)&buffer_size, 4, recv_size);
buffer = new char[buffer_size+1];
m_socket.Receive(buffer, buffer_size+1, recv_size);
m_selectedgame = std::string(buffer);
Event->AppendText(wxString::FromAscii(StringFromFormat("*Host changed Game to : %s\n", buffer).c_str()));
// Tell the server if the game's been found
m_socket.Send((const char*)&data, 1);
CheckGameFound();
Event->SendEvent(GUI_UPDATE);
break;
}
case 0x40: // Ready message received
{
m_socket.Receive((char*)&buffer_size, 4, recv_size);
buffer = new char[buffer_size+1];
m_socket.Receive(buffer, buffer_size+1, recv_size);
if (recv_size > 1024)
{
delete[] buffer;
return;
}
Event->AppendText(wxString::FromAscii(buffer));
break;
}
case 0x50: // Everyone is Ready message received
{
// Load the game and start synching
m_netptr->LoadGame();
break;
}
case 0xA1: // Received pad data from host in versus mode
{
if (m_data_received)
wxThread::Sleep(10);
m_socket.Receive((char*)m_netvalues[0], 8, recv_size);
m_data_received = true;
#ifdef NET_DEBUG
char msgbuf[64];
sprintf(msgbuf, "Received Values: 0x%08x : 0x%08x \n", m_netvalues[0][0], m_netvalues[0][1]);
Event->AppendText(wxString::FromAscii(msgbuf));
#endif
break;
}
}
delete[] buffer;
}
void ServerSide::OnServerData(int sock, unsigned char data)
{
size_t recv_size;
char *buffer = NULL;
unsigned char sent;
unsigned int four_bytes;
switch (data)
{
case 0x15: // Ping Request
{
m_client[sock].socket.Receive((char*)&four_bytes, 4, recv_size);
m_client[sock].socket.Send((const char*)&four_bytes, 4);
break;
}
case 0x20: // IP request response
{
buffer = new char[24];
// Read IP Address
m_client[sock].socket.Receive(buffer, 24, recv_size);
Event->AppendText(wxString::FromAscii(StringFromFormat("> Your IP is : %s\n", buffer).c_str()));
break;
}
case 0x30: // Chat message
{
buffer = new char[1024];
m_client[sock].socket.Receive((char*)&four_bytes, 4, recv_size);
m_client[sock].socket.Receive((char*)buffer, four_bytes + 1, recv_size);
if (recv_size > 1024)
{
//something wrong...
delete[] buffer;
return;
}
sent = 0x30;
// Send to all
for (int i=0; i < m_numplayers ; i++)
{
if (i == sock)
continue;
m_client[i].socket.Send((const char*)&sent, 1);
m_client[1].socket.Send((const char*)&four_bytes, 4);
m_client[i].socket.Send(buffer, recv_size);
}
Event->AppendText(wxString::FromAscii(buffer));
break;
}
case 0x35: // Change game response received
{
// Receive isGameFound response (0x1F / 0x1A)
m_client[sock].socket.Receive((char*)&sent, 1, recv_size);
// If game is not found
if (sent != 0x1F)
{
sent = 0x30;
wxString error_str = wxString::FromAscii(
StringFromFormat("WARNING : Player %s does Not have this Game !\n", m_client[sock].nick.c_str()).c_str());
four_bytes = (int)error_str.size();
for (int i=0; i < 2; i++)
Event->AppendText(error_str);
// Send to all
for (int i=0; i < m_numplayers ; i++)
{
if (i == sock)
continue;
m_client[i].socket.Send((const char*)&sent, 1);
m_client[i].socket.Send((const char*)&four_bytes, 4);
m_client[i].socket.Send(error_str.mb_str(), four_bytes + 1);
}
}
break;
}
case 0x40: // Ready message received
{
std::string buffer_str;
m_client[sock].ready = !m_client[sock].ready;
if (m_client[sock].ready)
buffer_str = ">> "+m_client[sock].nick+" is now ready !\n";
else
buffer_str = ">> "+m_client[sock].nick+" is now Unready !\n";
four_bytes = (int)buffer_str.size();
// Send to all
for (int i=0; i < m_numplayers ; i++)
{
m_client[i].socket.Send((const char*)&data, 1);
m_client[i].socket.Send((const char*)&four_bytes, 4);
m_client[i].socket.Send(buffer_str.c_str(), four_bytes+1);
}
Event->AppendText(wxString::FromAscii(buffer_str.c_str()));
IsEveryoneReady();
break;
}
case 0xA1: // Received pad data from a client
{
if (m_data_received)
wxThread::Sleep(10);
m_client[sock].socket.Receive((char*)m_netvalues[sock], 8, recv_size);
m_data_received = true;
#ifdef NET_DEBUG
char msgbuf[64];
sprintf(msgbuf, "Received Values: 0x%08x : 0x%08x \n", m_netvalues[sock][0], m_netvalues[sock][1]);
Event->AppendText(wxString::FromAscii(msgbuf));
#endif
break;
}
}
delete[] buffer;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+190
View File
@@ -0,0 +1,190 @@
#ifndef _NETPLAY_H
#define _NETPLAY_H
#include "Common.h"
#include "CommonTypes.h"
//#define WIN32_LEAN_AND_MEAN
#include "Thread.h"
// hax, i hope something like this isn't needed on non-windows
#define _WINSOCK2API_
#include <SFML/Network.hpp>
#include "pluginspecs_pad.h"
#include "svnrev.h"
//#include <wx/wx.h>
#include <map>
#include <queue>
class NetPlayDiag;
class NetPad
{
public:
NetPad();
NetPad(const SPADStatus* const);
u32 nHi;
u32 nLo;
};
#define NETPLAY_VERSION "Dolphin NetPlay 2.0"
#ifdef _M_X64
#define NP_ARCH "x64"
#else
#define NP_ARCH "x86"
#endif
#ifdef _WIN32
#define NETPLAY_DOLPHIN_VER SVN_REV_STR" win-"NP_ARCH
#elif __APPLE__
#define NETPLAY_DOLPHIN_VER SVN_REV_STR" osx-"NP_ARCH
#else
#define NETPLAY_DOLPHIN_VER SVN_REV_STR" nix-"NP_ARCH
#endif
// messages
#define NP_MSG_PLAYER_JOIN 0x10
#define NP_MSG_PLAYER_LEAVE 0x11
#define NP_MSG_CHAT_MESSAGE 0x30
#define NP_MSG_PAD_DATA 0x60
#define NP_MSG_PAD_MAPPING 0x61
#define NP_MSG_PAD_BUFFER 0x62
#define NP_MSG_START_GAME 0xA0
#define NP_MSG_CHANGE_GAME 0xA1
#define NP_MSG_READY 0xD0
#define NP_MSG_NOT_READY 0xD1
#define NP_MSG_PING 0xE0
#define NP_MSG_PONG 0xE1
// end messages
// gui messages
#define NP_GUI_UPDATE 0x10
// end messages
typedef u8 MessageId;
typedef u8 PlayerId;
typedef s8 PadMapping;
class NetPlay
{
public:
NetPlay() : m_is_running(false), m_do_loop(true) {}
virtual ~NetPlay();
virtual void Entry() = 0;
bool is_connected;
// Send and receive pads values
virtual bool GetNetPads(const u8 pad_nb, const SPADStatus* const, NetPad* const netvalues) = 0;
virtual bool SetSelectedGame(const std::string& game) = 0;
virtual void GetPlayerList(std::string& list) = 0;
virtual void SendChatMessage(const std::string& msg) = 0;
virtual bool StartGame(const std::string &path) = 0;
protected:
//NetPlay(Common::ThreadFunc entry, void* arg) : m_thread(entry, arg) {}
void UpdateGUI();
struct
{
Common::CriticalSection send, players, buffer, other;
} m_crit;
//LockingQueue<NetPad> m_pad_buffer[4];
std::queue<NetPad> m_pad_buffer[4];
NetPlayDiag* m_dialog;
sf::SocketTCP m_socket;
Common::Thread* m_thread;
sf::Selector<sf::SocketTCP> m_selector;
std::string m_selected_game;
bool m_is_running;
volatile bool m_do_loop;
private:
};
class NetPlayServer : public NetPlay
{
public:
void Entry();
NetPlayServer(const u16 port, const std::string& name, NetPlayDiag* const npd = NULL, const std::string& game = "");
~NetPlayServer();
void GetPlayerList(std::string& list);
// Send and receive pads values
bool GetNetPads(const u8 pad_nb, const SPADStatus* const, NetPad* const netvalues);
bool SetSelectedGame(const std::string& game);
void SendChatMessage(const std::string& msg);
bool StartGame(const std::string &path);
private:
class Player
{
public:
Player();
PlayerId pid;
sf::SocketTCP socket;
std::string name;
PadMapping pad_map[4];
std::string revision;
};
void SendToClients(sf::Packet& packet, const u8 skip_pid = 0);
unsigned int OnConnect(sf::SocketTCP& socket);
unsigned int OnDisconnect(sf::SocketTCP& socket);
unsigned int OnData(sf::Packet& packet, sf::SocketTCP& socket);
std::map<sf::SocketTCP, Player> m_players;
};
class NetPlayClient : public NetPlay
{
public:
void Entry();
NetPlayClient(const std::string& address, const u16 port, const std::string& name, NetPlayDiag* const npd = NULL);
~NetPlayClient();
void GetPlayerList(std::string& list);
// Send and receive pads values
bool GetNetPads(const u8 pad_nb, const SPADStatus* const, NetPad* const netvalues);
bool SetSelectedGame(const std::string& game);
void SendChatMessage(const std::string& msg);
bool StartGame(const std::string &path);
private:
class Player
{
public:
Player();
PlayerId pid;
std::string name;
PadMapping pad_map[4];
std::string revision;
};
unsigned int OnData(sf::Packet& packet);
PlayerId m_pid;
std::map<u8, Player> m_players;
};
#endif
File diff suppressed because it is too large Load Diff
-128
View File
@@ -1,128 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program 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.0.
// This program 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _NETSOCKETS_H_
#define _NETSOCKETS_H_
#include <SFML/Network.hpp>
class NetPlay;
#include "Common.h"
#include "NetStructs.h"
#include <wx/wx.h>
struct Clients {
std::string nick;
sf::SocketTCP socket;
unsigned short port;
sf::IPAddress address;
bool ready;
};
class NetEvent
{
public:
NetEvent(NetPlay* netptr) { m_netptr = netptr; }
~NetEvent() {};
void SendEvent(int EventType, std::string="NULL", int=NULL);
void AppendText(const wxString text);
private:
NetPlay *m_netptr;
};
class ServerSide : public wxThread
{
public:
ServerSide(NetPlay* netptr, sf::SocketTCP, sf::SocketUDP, int netmodel, std::string nick);
~ServerSide() {};
virtual void *Entry();
void Write(int socknb, const char *data, size_t size, long *ping=NULL);
void WriteUDP(int socknb, const char *data, size_t size);
bool isNewPadData(u32 *netValues, bool current, int client=0);
private:
bool SyncValues(unsigned char, sf::IPAddress);
bool RecvT(sf::SocketUDP Socket, char * Data, size_t Max, size_t& Recvd, float Time = 0);
char GetSocket(sf::SocketTCP Socket);
void OnServerData(int sock, unsigned char data);
void IsEveryoneReady();
NetPlay *m_netptr;
NetEvent *Event;
u32 m_netvalues[3][3];
bool m_data_received; // New Pad data received ?
unsigned char m_numplayers;
int m_netmodel;
std::string m_nick;
Clients m_client[3]; // Connected client objects
sf::SelectorTCP m_selector;
sf::SocketTCP m_socket; // Server 'listening' socket
sf::SocketUDP m_socketUDP;
wxCriticalSection m_CriticalSection;
};
class ClientSide : public wxThread
{
public:
ClientSide(NetPlay* netptr, sf::SocketTCP, sf::SocketUDP, std::string addr, std::string nick);
~ClientSide() {}
virtual void *Entry();
void Write(const char *data, size_t size, long *ping=NULL);
void WriteUDP(const char *data, size_t size);
bool isNewPadData(u32 *netValues, bool current, bool isVersus=true);
private:
bool SyncValues();
void CheckGameFound();
void OnClientData(unsigned char data);
bool RecvT(sf::SocketUDP Socket, char * Data, size_t Max, size_t& Recvd, float Time=0);
NetPlay *m_netptr;
NetEvent *Event;
u32 m_netvalues[3][3];
bool m_data_received; // New Pad data received ?
unsigned char m_numplayers;
int m_netmodel;
std::string m_nick;
std::string m_hostnick;
std::string m_selectedgame;
sf::SelectorTCP m_selector;
sf::SocketTCP m_socket; // Client I/O socket
sf::SocketUDP m_socketUDP;
unsigned short m_port;
std::string m_addr; // Contains the server addr
wxCriticalSection m_CriticalSection;
};
#endif
-26
View File
@@ -1,26 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program 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.0.
// This program 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _NETSTRUCTS_H
#define _NETSTRUCTS_H
struct Netpads {
int nHi[128];
int nLow[128];
};
#endif // _NETSTRUCTS_H
File diff suppressed because it is too large Load Diff
+60 -175
View File
@@ -18,202 +18,87 @@
#ifndef _NETWINDOW_H_
#define _NETWINDOW_H_
#include "CommonTypes.h"
#include <queue>
#include <string>
#include <wx/wx.h>
#include <wx/sizer.h>
#include <wx/dialog.h>
#include <wx/notebook.h>
#include <wx/gbsizer.h>
#include <wx/listbox.h>
//#include <wx/thread.h>
#include <wx/thread.h>
#include "GameListCtrl.h"
#include "Globals.h"
#include "BootManager.h"
#include "Common.h"
#include "NetStructs.h"
#include "Core.h"
#include "pluginspecs_pad.h"
#include "HW/SI.h"
#include "HW/SI_Device.h"
#include "HW/SI_DeviceGCController.h"
#include "Timer.h"
// just leaving these here so i can find something later if i need it
//#include "Frame.h"
//#include "Globals.h"
//#include "BootManager.h"
//#include "Common.h"
//#include "NetStructs.h"
//#include "Core.h"
//#include "pluginspecs_pad.h"
//#include "HW/SI.h"
//#include "HW/SI_Device.h"
//#include "HW/SI_DeviceGCController.h"
//#include "Timer.h"
#ifdef _DEBUG
#define NET_DEBUG
#endif
#include "LockingQueue.h"
// Use TCP instead of UDP to send pad data @ 60fps. Suitable and better for LAN netplay,
// Unrealistic for Internet netplay, unless you have an uberfast connexion (<10ms ping)
// #define USE_TCP
class ServerSide;
class ClientSide;
class NetPlay : public wxFrame
class NetPlaySetupDiag : public wxFrame
{
public:
NetPlay(wxWindow* parent, std::string GamePath = "", std::string GameName = "");
~NetPlay();
public:
NetPlaySetupDiag(wxWindow* parent, const CGameListCtrl* const game_list);
void UpdateNetWindow(bool update_infos, wxString=wxT("NULL"));
void AppendText(const wxString text) { m_Logging->AppendText(text); }
private:
void OnJoin(wxCommandEvent& event);
void OnHost(wxCommandEvent& event);
void OnQuit(wxCommandEvent& event);
// Send and receive pads values
bool GetNetPads(u8 pad_nb, SPADStatus, u32 *netvalues);
void ChangeSelectedGame(std::string game);
void IsGameFound(unsigned char*, std::string);
std::string GetSelectedGame() { wxCriticalSectionLocker lock(m_critical); return m_selectedGame; }
wxTextCtrl *m_nickname_text,
*m_host_port_text,
*m_connect_port_text,
*m_connect_ip_text;
void LoadGame();
wxListBox* m_game_lbox;
protected:
// Protects our vars from being fuxored by threads
wxCriticalSection m_critical;
// this draws the GUI, ya rly
void DrawGUI();
void DrawNetWindow();
// event handlers
void OnGUIEvent(wxCommandEvent& event);
void OnDisconnect(wxCommandEvent& event);
void OnNetEvent(wxCommandEvent& event);
void OnQuit(wxCloseEvent& event);
void OnJoin(wxCommandEvent& event);
void OnHost(wxCommandEvent& event);
// Net play vars (used ingame)
int m_frame;
int m_lastframe;
Common::Timer m_timer;
int m_loopframe;
int m_frameDelay;
bool m_data_received;// True if first frame data received
// Basic vars
std::string m_paths; // Game paths list
std::string m_games; // Game names list
std::string m_selectedGame;// Selected game's string
std::string m_hostaddr; // Used with OnGetIP to cache it
bool m_ready, m_clients_ready;
std::string m_nick;
int m_NetModel; // Using P2P model (0) or Server model (1)
int m_isHosting; // 0 = false ; 1 = true ; 2 = Not set
unsigned char m_numClients; // starting from 0, 4 players max thus 3 clients
std::string m_address; // The address entered into connection box
unsigned short m_port;
Netpads m_pads[4]; // this struct is used to save synced pad values
IniFile ConfigIni;
// Sockets objects
ServerSide *m_sock_server;
ClientSide *m_sock_client;
// -----------
// GUI objects
// -----------
wxNotebook *m_Notebook;
wxPanel *m_Tab_Connect;
wxPanel *m_Tab_Host;
wxStaticText *m_SetNick_text;
wxTextCtrl *m_SetNick;
wxChoice *m_NetMode;
// Host tab :
wxArrayString m_GameList_str;
wxStaticText *m_GameList_text;
wxListBox *m_GameList;
wxStaticText *m_SetPort_text;
wxTextCtrl *m_SetPort;
wxButton *m_HostGame;
wxButton *m_ExitWindowH;
// Connect tab :
wxTextCtrl *m_ConAddr;
wxStaticText *m_ConAddr_text;
wxButton *m_JoinGame;
wxButton *m_ExitWindowC;
wxCheckBox *m_UseRandomPort;
// Connection window
wxButton *m_Game_str;
wxTextCtrl *m_Logging;
wxTextCtrl *m_Chat;
wxButton *m_Chat_ok;
// Right part
wxButton *m_wtfismyip;
wxButton *m_ChangeGame;
// Left Part
wxButton *m_Disconnect;
wxStaticText *m_ConInfo_text;
wxButton *m_GetPing;
wxCheckBox *m_Ready;
wxCheckBox *m_RecordGame;
// wxWidgets event table
DECLARE_EVENT_TABLE()
const CGameListCtrl* const m_game_list;
};
class GameListPopup : public wxDialog
class NetPlayDiag : public wxFrame
{
public:
GameListPopup(NetPlay *net_ptr, wxArrayString GameNames);
~GameListPopup() {}
protected:
void OnButtons(wxCommandEvent& event);
wxArrayString m_GameList_str;
NetPlay* m_netParent;
wxListBox *m_GameList;
wxButton *m_Accept;
wxButton *m_Cancel;
DECLARE_EVENT_TABLE()
public:
NetPlayDiag(wxWindow* parent, const CGameListCtrl* const game_list
, const std::string& game, const bool is_hosting = false);
~NetPlayDiag();
LockingQueue<std::string> chat_msgs;
//std::string chat_msg;
void OnStart(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE()
void OnChat(wxCommandEvent& event);
void OnQuit(wxCommandEvent& event);
void OnThread(wxCommandEvent& event);
wxListBox* m_player_lbox;
wxTextCtrl* m_chat_text;
wxTextCtrl* m_chat_msg_text;
std::string m_selected_game;
wxButton* m_game_btn;
const CGameListCtrl* const m_game_list;
//NetPlay* const m_netplay;
};
enum
{
ID_NOTEBOOK,
ID_TAB_HOST,
ID_TAB_CONN,
ID_BUTTON_HOST,
ID_BUTTON_JOIN,
ID_BUTTON_EXIT,
ID_NETMODE,
ID_GAMELIST,
ID_LOGGING_TXT,
ID_CHAT,
ID_SETNICK,
ID_SETPORT,
ID_CONNADDR,
ID_CONNINFO_TXT,
ID_USE_RANDOMPORT,
ID_BUTTON_GETPING,
ID_BUTTON_GETIP,
ID_CHANGEGAME,
ID_BUTTON_QUIT,
ID_BUTTON_CHAT,
ID_READY,
ID_RECORD,
ID_SOCKET,
ID_SERVER,
HOST_FULL = 200, // ...
HOST_ERROR, // Sent on socket error
HOST_DISCONNECTED,
HOST_NEWPLAYER,
HOST_PLAYERLEFT,
CLIENTS_READY,
CLIENTS_NOTREADY,
GUI_UPDATE, // Refresh the shown selectedgame on GUI
ADD_TEXT, // Add text to m_Logging (string)
ADD_INFO, // Sent when updating net infos (string)
NET_EVENT
};
DECLARE_EVENT_TYPE(wxEVT_THREAD, -1)
#endif // _NETWINDOW_H_
+1 -3
View File
@@ -37,9 +37,7 @@ if wxenv['HAVE_WX']:
'stdafx.cpp',
'WxUtils.cpp',
'MemoryCards/WiiSaveCrypted.cpp',
'NetEvent.cpp',
'NetFunctions.cpp',
'NetSockets.cpp',
'NetPlay.cpp',
'NetWindow.cpp',
]