WiimoteNew Buildfix Debug/DebugFast x86/x64
[dolphin.git] / Source / Core / DolphinWX / Src / NetSockets.h
blobbee5e1e0ece00bfa14a7a5ae64325a00e6d88e53
1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
18 #ifndef _NETSOCKETS_H_
19 #define _NETSOCKETS_H_
21 #include <SFML/Network.hpp>
23 class NetPlay;
25 #include "Common.h"
26 #include "NetStructs.h"
28 #include <wx/wx.h>
31 struct Clients {
32 std::string nick;
33 sf::SocketTCP socket;
34 unsigned short port;
35 sf::IPAddress address;
36 bool ready;
39 class NetEvent
41 public:
42 NetEvent(NetPlay* netptr) { m_netptr = netptr; }
43 ~NetEvent() {};
45 void SendEvent(int EventType, std::string="NULL", int=NULL);
46 void AppendText(const wxString text);
48 private:
49 NetPlay *m_netptr;
52 class ServerSide : public wxThread
54 public:
55 ServerSide(NetPlay* netptr, sf::SocketTCP, sf::SocketUDP, int netmodel, std::string nick);
56 ~ServerSide() {};
58 virtual void *Entry();
60 void Write(int socknb, const char *data, size_t size, long *ping=NULL);
61 void WriteUDP(int socknb, const char *data, size_t size);
62 bool isNewPadData(u32 *netValues, bool current, int client=0);
64 private:
65 bool SyncValues(unsigned char, sf::IPAddress);
66 bool RecvT(sf::SocketUDP Socket, char * Data, size_t Max, size_t& Recvd, float Time = 0);
67 char GetSocket(sf::SocketTCP Socket);
68 void OnServerData(int sock, unsigned char data);
69 void IsEveryoneReady();
71 NetPlay *m_netptr;
72 NetEvent *Event;
74 u32 m_netvalues[3][3];
75 bool m_data_received; // New Pad data received ?
77 unsigned char m_numplayers;
78 int m_netmodel;
79 std::string m_nick;
81 Clients m_client[3]; // Connected client objects
82 sf::SelectorTCP m_selector;
83 sf::SocketTCP m_socket; // Server 'listening' socket
84 sf::SocketUDP m_socketUDP;
86 wxCriticalSection m_CriticalSection;
89 class ClientSide : public wxThread
91 public:
92 ClientSide(NetPlay* netptr, sf::SocketTCP, sf::SocketUDP, std::string addr, std::string nick);
93 ~ClientSide() {}
95 virtual void *Entry();
97 void Write(const char *data, size_t size, long *ping=NULL);
98 void WriteUDP(const char *data, size_t size);
99 bool isNewPadData(u32 *netValues, bool current, bool isVersus=true);
101 private:
102 bool SyncValues();
103 void CheckGameFound();
104 void OnClientData(unsigned char data);
105 bool RecvT(sf::SocketUDP Socket, char * Data, size_t Max, size_t& Recvd, float Time=0);
107 NetPlay *m_netptr;
108 NetEvent *Event;
110 u32 m_netvalues[3][3];
111 bool m_data_received; // New Pad data received ?
113 unsigned char m_numplayers;
114 int m_netmodel;
115 std::string m_nick;
116 std::string m_hostnick;
117 std::string m_selectedgame;
119 sf::SelectorTCP m_selector;
120 sf::SocketTCP m_socket; // Client I/O socket
121 sf::SocketUDP m_socketUDP;
122 unsigned short m_port;
123 std::string m_addr; // Contains the server addr
125 wxCriticalSection m_CriticalSection;
128 #endif