forked from sin365/AxibugEmuOnline
154 lines
3.3 KiB
C
154 lines
3.3 KiB
C
|
//
|
|||
|
// <20>l<EFBFBD>b<EFBFBD>g<EFBFBD>v<EFBFBD><76><EFBFBD>C<EFBFBD>N<EFBFBD><4E><EFBFBD>X
|
|||
|
//
|
|||
|
#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();
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F>J<EFBFBD><4A>
|
|||
|
BOOL Initialize( HWND hWnd );
|
|||
|
void Release();
|
|||
|
|
|||
|
// <20>l<EFBFBD>b<EFBFBD>g<EFBFBD>v<EFBFBD><76><EFBFBD>C<EFBFBD><43><EFBFBD>H
|
|||
|
BOOL IsNetPlay() { return m_hWnd?TRUE:FALSE; }
|
|||
|
// <20>ڑ<EFBFBD><DA91><EFBFBD><EFBFBD>H
|
|||
|
BOOL IsConnect() { return m_hWnd?m_bConnect:FALSE; }
|
|||
|
// <20>ڑ<EFBFBD><DA91><EFBFBD><EFBFBD>H
|
|||
|
BOOL IsServer() { return m_bServer; }
|
|||
|
|
|||
|
// <20>ʐM<CA90><4D><EFBFBD>C<EFBFBD>e<EFBFBD><65><EFBFBD>V
|
|||
|
void SetLatency( INT nLatency ) { m_nLatency = nLatency; }
|
|||
|
INT GetLatency() { return m_nLatency; }
|
|||
|
|
|||
|
// <20><EFBFBD><F193AF8A><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD>ԑ<EFBFBD><D491>E<EFBFBD>C<EFBFBD><43><EFBFBD>h<EFBFBD>E<EFBFBD>̐ݒ<CC90>
|
|||
|
void SetMsgWnd( HWND hWnd ) { m_hWndMsg = hWnd; }
|
|||
|
|
|||
|
// <20>`<60><><EFBFBD>b<EFBFBD>g<EFBFBD><67><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD><EFBFBD><F382AF8E><EFBFBD><EFBFBD>E<EFBFBD>C<EFBFBD><43><EFBFBD>h<EFBFBD>E<EFBFBD>̐ݒ<CC90>
|
|||
|
void SetChatWnd( HWND hWnd ) { m_hWndChat = hWnd; }
|
|||
|
|
|||
|
// <20>z<EFBFBD>X<EFBFBD>g<EFBFBD><67><EFBFBD><EFBFBD>IP<49><50><EFBFBD>ǂ<EFBFBD><C782><EFBFBD><EFBFBD><EFBFBD><EFBFBD>`<60>F<EFBFBD>b<EFBFBD>N<EFBFBD><4E><EFBFBD><EFBFBD>(0:IP -:Error +:Host search)
|
|||
|
INT ASyncHostCheck( HWND hWnd, const char* lpszHost );
|
|||
|
HRESULT ASyncWndProc( HWND hWnd, WPARAM wParam, LPARAM lParam );
|
|||
|
|
|||
|
// <20>ڑ<EFBFBD><DA91>Ɛؒf
|
|||
|
BOOL Connect( BOOL bServer, const char* lpszIP, unsigned short Port );
|
|||
|
void Disconnect();
|
|||
|
|
|||
|
// <20>f<EFBFBD>[<5B>^<5E><><EFBFBD>M 0:<3A><><EFBFBD>M<EFBFBD>f<EFBFBD>[<5B>^<5E>҂<EFBFBD> 1<>ȏ<EFBFBD>:<3A><><EFBFBD>M<EFBFBD>f<EFBFBD>[<5B>^<5E><><EFBFBD><EFBFBD> 0<><30><EFBFBD><EFBFBD>:<3A>ڑ<EFBFBD><DA91><EFBFBD><D882><EFBFBD><EFBFBD>G<EFBFBD><47><EFBFBD>[
|
|||
|
INT Send( BYTE data );
|
|||
|
// <20>f<EFBFBD>[<5B>^<5E><><EFBFBD>M
|
|||
|
// 0:<3A><><EFBFBD>M<EFBFBD>f<EFBFBD>[<5B>^<5E>҂<EFBFBD> 1<>ȏ<EFBFBD>:<3A><><EFBFBD>M<EFBFBD>f<EFBFBD>[<5B>^<5E><><EFBFBD><EFBFBD> 0<><30><EFBFBD><EFBFBD>:<3A>ڑ<EFBFBD><DA91><EFBFBD><D882><EFBFBD><EFBFBD>G<EFBFBD><47><EFBFBD>[
|
|||
|
// <20>^<5E>C<EFBFBD><43><EFBFBD>A<EFBFBD>E<EFBFBD>g<EFBFBD><67><EFBFBD><EFBFBD>
|
|||
|
INT Recv( BYTE& data );
|
|||
|
// <20>^<5E>C<EFBFBD><43><EFBFBD>A<EFBFBD>E<EFBFBD>g<EFBFBD>L<EFBFBD><4C>
|
|||
|
INT RecvTime( BYTE& data, unsigned long timeout );
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40>ւ̎<D682><CC8E>荞<EFBFBD><E88D9E>
|
|||
|
BOOL RecvBuffer();
|
|||
|
// <20>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40>`<60>F<EFBFBD>b<EFBFBD>N(0:No change +:frame add -:no frame)
|
|||
|
INT BufferCheck();
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40>̃o<CC83>b<EFBFBD>t<EFBFBD>@<40><><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD>o<EFBFBD>C<EFBFBD>g<EFBFBD><67><EFBFBD>擾
|
|||
|
INT GetRecvBufferSize();
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
INT Sync();
|
|||
|
// <20>v<EFBFBD><76><EFBFBD>C<EFBFBD><43><EFBFBD>[<5B><><EFBFBD>Ԃ̍X<CC8D>V
|
|||
|
INT ModifyPlayer( LPBYTE p1, LPBYTE p2 );
|
|||
|
|
|||
|
// <20>`<60><><EFBFBD>b<EFBFBD>g<EFBFBD><67><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD><57><EFBFBD>M
|
|||
|
void ChatSend( LPCSTR lpStr );
|
|||
|
|
|||
|
// Windows<77><73><EFBFBD>b<EFBFBD>Z<EFBFBD>[<5B>W<EFBFBD>v<EFBFBD><76><EFBFBD>V<EFBFBD>[<5B>W<EFBFBD><57>
|
|||
|
HRESULT WndProc( HWND hWnd, WPARAM wParam, LPARAM lParam );
|
|||
|
|
|||
|
// <20>ʐM<CA90>o<EFBFBD>b<EFBFBD>t<EFBFBD>@
|
|||
|
enum {
|
|||
|
// <20>f<EFBFBD>[<5B>^<5E>u<EFBFBD><75><EFBFBD>b<EFBFBD>N<EFBFBD>T<EFBFBD>C<EFBFBD>Y
|
|||
|
SOCKET_BLOCK_SIZE = 8,
|
|||
|
// <20>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40>T<EFBFBD>C<EFBFBD>Y
|
|||
|
SOCKET_BUFFER_SIZE = (SOCKET_BLOCK_SIZE*32),
|
|||
|
// <20><><EFBFBD>M<EFBFBD><4D><EFBFBD>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40>T<EFBFBD>C<EFBFBD>Y
|
|||
|
SOCKET_RECEIVE_SIZE = (SOCKET_BLOCK_SIZE*8)
|
|||
|
};
|
|||
|
protected:
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>o<EFBFBD>ϐ<EFBFBD>
|
|||
|
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; // <20>ڑ<EFBFBD><DA91><EFBFBD><EFBFBD>H
|
|||
|
INT m_nLatency; // <20><><EFBFBD>C<EFBFBD>e<EFBFBD><65><EFBFBD>V(<28>o<EFBFBD>b<EFBFBD>t<EFBFBD>@<40>T<EFBFBD>C<EFBFBD>Y)
|
|||
|
INT m_nFrameStep; // <20>ʐM<CA90>t<EFBFBD><74><EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>[<5B>g
|
|||
|
INT m_nFrameCount; // <20>J<EFBFBD>E<EFBFBD><45><EFBFBD>^
|
|||
|
|
|||
|
// 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__
|