AxibugEmuOnline/virtuanessrc097-master/NetPlay.h

156 lines
6.3 KiB
C
Raw Normal View History

<EFBFBD><EFBFBD>//
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
//
#ifndef __CNETPLAY_INCLUDED__
#define __CNETPLAY_INCLUDED__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <mmsystem.h>
#include <winsock.h>
#include "macro.h"
#include "typedef.h"
#include <string>
using namespace std;
#define WM_NETPLAY (WM_APP+100)
#define WM_NETPLAY_HOSTBYNAME (WM_APP+101)
#define WM_NETPLAY_ACCEPT (WM_APP+110)
#define WM_NETPLAY_CONNECT (WM_APP+111)
#define WM_NETPLAY_CLOSE (WM_APP+112)
#define WM_NETPLAY_ERROR (WM_APP+113)
// for BSD style
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
// for Winsock1.x
#ifndef SD_RECEIVE
#define SD_RECEIVE 0
#endif
#ifndef SD_SEND
#define SD_SEND 1
#endif
#ifndef SD_BOTH
#define SD_BOTH 2
#endif
class CNetPlay
{
public:
CNetPlay();
~CNetPlay();
// RgS/<EFBFBD><EFBFBD>>e
BOOL Initialize( HWND hWnd );
void Release();
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0-N<EFBFBD>
BOOL IsNetPlay() { return m_hWnd?TRUE:FALSE; }
// <EFBFBD>c<EFBFBD>}-N<EFBFBD>
BOOL IsConnect() { return m_hWnd?m_bConnect:FALSE; }
// <EFBFBD>c<EFBFBD>}-N<EFBFBD>
BOOL IsServer() { return m_bServer; }
// <EFBFBD><EFBFBD>O<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
void SetLatency( INT nLatency ) { m_nLatency = nLatency; }
INT GetLatency() { return m_nLatency; }
// ^<EFBFBD> Tg<EFBFBD>Qt<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0ԏ<EFBFBD><EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0n0-<EFBFBD><EFBFBD>[
void SetMsgWnd( HWND hWnd ) { m_hWndMsg = hWnd; }
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>SQ0<EFBFBD>S<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0n0-<EFBFBD><EFBFBD>[
void SetChatWnd( HWND hWnd ) { m_hWndChat = hWnd; }
// <EFBFBD>0<EFBFBD>0<EFBFBD>0 TL0IPK0i0F0K0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0Y0<EFBFBD>0(0:IP -:Error +:Host search)
INT ASyncHostCheck( HWND hWnd, const char* lpszHost );
HRESULT ASyncWndProc( HWND hWnd, WPARAM wParam, LPARAM lParam );
// <EFBFBD>c<EFBFBD>}h0R<EFBFBD>e
BOOL Connect( BOOL bServer, const char* lpszIP, unsigned short Port );
void Disconnect();
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD><EFBFBD>O 0:<EFBFBD>S<EFBFBD>O<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>_a0 1<EFBFBD>N
N:<EFBFBD>S<EFBFBD>O<EFBFBD>0<EFBFBD>0<EFBFBD>0B0<EFBFBD>0 0*g<EFBFBD>n:<EFBFBD>c<EFBFBD>}R<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
INT Send( BYTE data );
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>S<EFBFBD>O
// 0:<EFBFBD>S<EFBFBD>O<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>_a0 1<EFBFBD>N
N:<EFBFBD>S<EFBFBD>O<EFBFBD>0<EFBFBD>0<EFBFBD>0B0<EFBFBD>0 0*g<EFBFBD>n:<EFBFBD>c<EFBFBD>}R<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0!qW0
INT Recv( BYTE& data );
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0 g<EFBFBD>0
INT RecvTime( BYTE& data, unsigned long timeout );
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0x0n0<EFBFBD>S<EFBFBD>0<EFBFBD><EFBFBD>0
BOOL RecvBuffer();
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0(0:No change +:frame add -:no frame)
INT BufferCheck();
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0n0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0pe<EFBFBD>S<EFBFBD>_
INT GetRecvBufferSize();
// Tg<EFBFBD>Qt
INT Sync();
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>rKan0<EFBFBD>f<EFBFBD>e
INT ModifyPlayer( LPBYTE p1, LPBYTE p2 );
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD><EFBFBD>O
void ChatSend( LPCSTR lpStr );
// Windows<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
HRESULT WndProc( HWND hWnd, WPARAM wParam, LPARAM lParam );
// <EFBFBD><EFBFBD>O<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
enum {
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
SOCKET_BLOCK_SIZE = 8,
// <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
SOCKET_BUFFER_SIZE = (SOCKET_BLOCK_SIZE*32),
// <EFBFBD>S<EFBFBD>OBf<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
SOCKET_RECEIVE_SIZE = (SOCKET_BLOCK_SIZE*8)
};
protected:
// <EFBFBD>0<EFBFBD>0<EFBFBD>0 Ype
HWND m_hWnd;
HWND m_hWndMsg;
HWND m_hWndASync;
HWND m_hWndChat;
HANDLE m_hASyncTask;
CHAR m_HostEntry[MAXGETHOSTSTRUCT];
BOOL m_bServer;
BOOL m_bConnect; // <EFBFBD>c<EFBFBD>}-N<EFBFBD>
INT m_nLatency; // <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0(<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0)
INT m_nFrameStep; // <EFBFBD><EFBFBD>O<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
INT m_nFrameCount; // <EFBFBD>0<EFBFBD>0<EFBFBD>0<EFBFBD>0
// Ring buffer
INT m_nRingPtr;
INT m_nSendPtr;
INT m_nRecvPtr;
INT m_nRecvSize;
BYTE m_SendBuffer[SOCKET_BUFFER_SIZE];
BYTE m_RecvBuffer[SOCKET_BUFFER_SIZE];
// WINSOCK
WSADATA m_WSAdata;
SOCKET m_SocketConnect;
SOCKET m_SocketData;
SOCKET m_SocketChat;
struct sockaddr_in m_SAddr_Server;
struct sockaddr_in m_SAddr_Client;
private:
};
extern CNetPlay NetPlay;
#endif // !__CNETPLAY_INCLUDED__