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>
26 #include "NetStructs.h"
35 sf::IPAddress address
;
42 NetEvent(NetPlay
* netptr
) { m_netptr
= netptr
; }
45 void SendEvent(int EventType
, std::string
="NULL", int=NULL
);
46 void AppendText(const wxString text
);
52 class ServerSide
: public wxThread
55 ServerSide(NetPlay
* netptr
, sf::SocketTCP
, sf::SocketUDP
, int netmodel
, std::string nick
);
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);
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();
74 u32 m_netvalues
[3][3];
75 bool m_data_received
; // New Pad data received ?
77 unsigned char m_numplayers
;
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
92 ClientSide(NetPlay
* netptr
, sf::SocketTCP
, sf::SocketUDP
, std::string addr
, std::string nick
);
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);
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);
110 u32 m_netvalues
[3][3];
111 bool m_data_received
; // New Pad data received ?
113 unsigned char m_numplayers
;
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
;