~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Core/Core/Src/NetPlayServer.h

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Dolphin Emulator Project
 
2
// Licensed under GPLv2
 
3
// Refer to the license.txt file included.
 
4
 
 
5
#ifndef _NETPLAY_SERVER_H
 
6
#define _NETPLAY_SERVER_H
 
7
 
 
8
#include "Common.h"
 
9
#include "CommonTypes.h"
 
10
#include "Thread.h"
 
11
#include "Timer.h"
 
12
 
 
13
#include <SFML/Network.hpp>
 
14
 
 
15
#include "NetPlayProto.h"
 
16
 
 
17
#include <functional>
 
18
#include <map>
 
19
#include <queue>
 
20
#include <sstream>
 
21
 
 
22
class NetPlayServer
 
23
{
 
24
public:
 
25
        void ThreadFunc();
 
26
 
 
27
        NetPlayServer(const u16 port);
 
28
        ~NetPlayServer();
 
29
 
 
30
        bool ChangeGame(const std::string& game);
 
31
        void SendChatMessage(const std::string& msg);
 
32
 
 
33
        void SetNetSettings(const NetSettings &settings);
 
34
 
 
35
        bool StartGame(const std::string &path);
 
36
 
 
37
        void GetPadMapping(PadMapping map[]);
 
38
        void SetPadMapping(const PadMapping map[]);
 
39
 
 
40
        void GetWiimoteMapping(PadMapping map[]);
 
41
        void SetWiimoteMapping(const PadMapping map[]);
 
42
 
 
43
        void AdjustPadBufferSize(unsigned int size);
 
44
 
 
45
        bool is_connected;
 
46
 
 
47
#ifdef USE_UPNP
 
48
        void TryPortmapping(u16 port);
 
49
#endif
 
50
 
 
51
private:
 
52
        class Client
 
53
        {
 
54
        public:
 
55
                PlayerId                pid;
 
56
                std::string             name;
 
57
                std::string             revision;
 
58
 
 
59
                sf::SocketTCP   socket;
 
60
                u32 ping;
 
61
                u32 current_game;
 
62
        };
 
63
 
 
64
        void SendToClients(sf::Packet& packet, const PlayerId skip_pid = 0);
 
65
        unsigned int OnConnect(sf::SocketTCP& socket);
 
66
        unsigned int OnDisconnect(sf::SocketTCP& socket);
 
67
        unsigned int OnData(sf::Packet& packet, sf::SocketTCP& socket);
 
68
        void UpdatePadMapping();
 
69
        void UpdateWiimoteMapping();
 
70
 
 
71
        NetSettings     m_settings;
 
72
 
 
73
        bool            m_is_running;
 
74
        bool            m_do_loop;
 
75
        Common::Timer   m_ping_timer;
 
76
        u32             m_ping_key;
 
77
        bool            m_update_pings;
 
78
        u32             m_current_game;
 
79
        unsigned int    m_target_buffer_size;
 
80
        PadMapping      m_pad_map[4];
 
81
        PadMapping      m_wiimote_map[4];
 
82
 
 
83
        std::map<sf::SocketTCP, Client> m_players;
 
84
 
 
85
        struct
 
86
        {
 
87
                std::recursive_mutex game;
 
88
                // lock order
 
89
                std::recursive_mutex players, send;
 
90
        } m_crit;
 
91
 
 
92
        std::string m_selected_game;
 
93
 
 
94
        sf::SocketTCP m_socket;
 
95
        std::thread m_thread;
 
96
        sf::Selector<sf::SocketTCP> m_selector;
 
97
 
 
98
#ifdef USE_UPNP
 
99
        static void mapPortThread(const u16 port);
 
100
        static void unmapPortThread();
 
101
 
 
102
        static bool initUPnP();
 
103
        static bool UPnPMapPort(const std::string& addr, const u16 port);
 
104
        static bool UPnPUnmapPort(const u16 port);
 
105
 
 
106
        static struct UPNPUrls m_upnp_urls;
 
107
        static struct IGDdatas m_upnp_data;
 
108
        static u16 m_upnp_mapped;
 
109
        static bool m_upnp_inited;
 
110
        static bool m_upnp_error;
 
111
        static std::thread m_upnp_thread;
 
112
#endif
 
113
};
 
114
 
 
115
#endif