Files
dolphin/Source/Core/Core/Src/NetPlayServer.h
Jasper St. Pierre 3b32d3c90d NetPlay: Split the server out, and make the local system manage a client as well
This should be transparent, but it may cause regressions.

The idea here is that now all players, including the host of the server,
talk to the server through TCP/IP networking. This significantly reduces
our codepaths through netplay, and will prevent strange local-only bugs
from happening.

The cleanup isn't 100% finished yet. The NetPlay dialog still drives the
server through private APIs. I eventually want to sanction off the server
entirely, so all communication is done through TCP/IP. This will allow us
to have high-traffic public servers that can relay multiple games and
lobbies at a time, and split off channel and game management to people
other than the host.

This is all still just a pipe dream, though.
2013-08-05 04:42:26 -04:00

117 lines
2.4 KiB
C++

// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#ifndef _NETPLAY_SERVER_H
#define _NETPLAY_SERVER_H
#include "Common.h"
#include "CommonTypes.h"
#include "Thread.h"
#include "Timer.h"
#include <SFML/Network.hpp>
#include "NetPlayProto.h"
#include <functional>
#include <map>
#include <queue>
#include <sstream>
class NetPlayServer
{
public:
void ThreadFunc();
NetPlayServer(const u16 port);
~NetPlayServer();
void GetPlayerList(std::string& list, std::vector<int>& pid_list);
bool ChangeGame(const std::string& game);
void SendChatMessage(const std::string& msg);
void SetNetSettings(const NetSettings &settings);
bool StartGame(const std::string &path);
bool StopGame();
bool GetPadMapping(const int pid, int map[]);
bool SetPadMapping(const int pid, const int map[]);
void AdjustPadBufferSize(unsigned int size);
bool is_connected;
#ifdef USE_UPNP
void TryPortmapping(u16 port);
#endif
private:
class Client
{
public:
Client();
std::string ToString() const;
PlayerId pid;
std::string name;
PadMapping pad_map[4];
std::string revision;
sf::SocketTCP socket;
u64 ping;
u32 current_game;
};
void SendToClients(sf::Packet& packet, const PlayerId skip_pid = 0);
unsigned int OnConnect(sf::SocketTCP& socket);
unsigned int OnDisconnect(sf::SocketTCP& socket);
unsigned int OnData(sf::Packet& packet, sf::SocketTCP& socket);
void UpdatePadMapping();
NetSettings m_settings;
bool m_is_running;
bool m_do_loop;
Common::Timer m_ping_timer;
u32 m_ping_key;
bool m_update_pings;
u32 m_current_game;
unsigned int m_target_buffer_size;
std::map<sf::SocketTCP, Client> m_players;
struct
{
std::recursive_mutex game;
// lock order
std::recursive_mutex players, send;
} m_crit;
std::string m_selected_game;
sf::SocketTCP m_socket;
std::thread m_thread;
sf::Selector<sf::SocketTCP> m_selector;
#ifdef USE_UPNP
static void mapPortThread(const u16 port);
static void unmapPortThread();
static bool initUPnP();
static bool UPnPMapPort(const std::string& addr, const u16 port);
static bool UPnPUnmapPort(const u16 port);
static struct UPNPUrls m_upnp_urls;
static struct IGDdatas m_upnp_data;
static u16 m_upnp_mapped;
static bool m_upnp_inited;
static bool m_upnp_error;
static std::thread m_upnp_thread;
#endif
};
#endif