📄 netplaydlg.cpp
字号:
goto _accept_error;
}
// Send Step
if( NetPlay.Send( nServerStep ) ) {
goto _accept_error;
}
// Recv Step dummy
if( NetPlay.RecvTime( nClientStep, 10*1000 ) < 0 ) {
goto _accept_error;
}
nLatency = nServerLatency;
DEBUGOUT( "Server: Network Latency:%d frames\n", nLatency );
NetPlay.SetLatency( nLatency );
NetPlay.SetMsgWnd( m_hWndParent );
::EndDialog( m_hWnd, IDOK );
return TRUE;
_accept_error:
SetStatusMessage( IDS_ERROR_NETWORKERROR );
_accept_error2:
NetPlay.Disconnect();
::EnableWindow( ::GetDlgItem( m_hWnd, IDC_NET_CONNECT ), TRUE );
SetControlEnable( TRUE );
return TRUE;
}
DLGMSG CNetPlayDlg::OnNetworkConnect( DLGMSGPARAM )
{
BYTE databuf;
DWORD dwStartTime, dwEndTime;
BYTE nServerLatency, nClientLatency;
BYTE nServerStep, nClientStep;
INT nLatency;
DWORD dwCRC;
INT i;
// 僯僢僋僱乕儉傪曐懚
CHAR szNick[_MAX_PATH+1];
::GetWindowText( ::GetDlgItem( m_hWnd, IDC_NET_NICKNAME ), szNick, _MAX_PATH );
::lstrcpy( Config.netplay.szNick, szNick );
DEBUGOUT( "cnn Nick:%s\n", szNick );
// 嵟嬤巊偭偨億乕僩偺峏怴
CHAR szHost[_MAX_PATH+1];
::GetWindowText( ::GetDlgItem( m_hWnd, IDC_NET_HOST_COMBO ), szHost, _MAX_PATH );
DEBUGOUT( "cnn Host:%s\n", szHost );
AddRecentHost( szHost );
// 捠怣儗僀僥儞僔偺寁應
CHAR str[256];
::wsprintf( str, "VirtuaNES version %01d.%01d%01d",
(VIRTUANES_VERSION&0xF00)>>8,
(VIRTUANES_VERSION&0x0F0)>>4,
(VIRTUANES_VERSION&0x00F) );
dwStartTime = ::timeGetTime();
for( i = 0; i < ::strlen(str); i++ ) {
if( NetPlay.Send( (BYTE)str[i] ) ) {
goto _connect_error;
}
if( NetPlay.RecvTime( databuf, 10*1000 ) < 0 ) {
goto _connect_error;
} else {
if( databuf != str[i] ) {
SetStatusMessage( IDS_ERROR_NETWORKERROR_VERSION );
goto _connect_error2;
}
}
}
dwEndTime = ::timeGetTime()-dwStartTime;
DEBUGOUT( "Client: Transfer Bytes: %d byte / Time: %d ms\n", ::strlen(str), dwEndTime );
// 僀儊乕僕偺CRC傪妋擣
NES* pNes;
if( !(pNes = Emu.GetNES()) ) {
goto _connect_error;
}
if( pNes->rom->GetMapperNo() != 20 ) {
dwCRC = pNes->rom->GetPROM_CRC();
} else {
dwCRC = pNes->rom->GetGameID();
}
for( i = 0; i < 32; i+=8 ) {
if( NetPlay.Send( (BYTE)(dwCRC>>i) ) ) {
goto _connect_error;
}
if( NetPlay.RecvTime( databuf, 10*1000 ) < 0 ) {
goto _connect_error;
} else if( databuf != (BYTE)(dwCRC>>i) ) {
SetStatusMessage( IDS_ERROR_NETWORKERROR_CRC );
goto _connect_error2;
}
}
nClientLatency = 0;
nServerStep = 0;
nClientStep = 0;
// Send Latency dummy
if( NetPlay.Send( nClientLatency ) ) {
goto _connect_error;
}
// Recv Latency
if( NetPlay.RecvTime( nServerLatency, 10*1000 ) < 0 ) {
goto _connect_error;
}
// Send Step
if( NetPlay.Send( nClientStep ) ) {
goto _connect_error;
}
// Recv Step dummy
if( NetPlay.RecvTime( nServerStep, 10*1000 ) < 0 ) {
goto _connect_error;
}
nLatency = nServerLatency;
DEBUGOUT( "Client: Network Latency:%d frames\n", nLatency );
NetPlay.SetLatency( nLatency );
NetPlay.SetMsgWnd( m_hWndParent );
::EndDialog( m_hWnd, IDOK );
return TRUE;
_connect_error:
SetStatusMessage( IDS_ERROR_NETWORKERROR );
_connect_error2:
NetPlay.Disconnect();
::EnableWindow( ::GetDlgItem( m_hWnd, IDC_NET_CONNECT ), TRUE );
SetControlEnable( TRUE );
return TRUE;
}
DLGMSG CNetPlayDlg::OnNetworkClose( DLGMSGPARAM )
{
NetPlay.SetMsgWnd( NULL );
SetStatusMessage( IDS_ERROR_NETWORKDISCONNECT );
::EnableWindow( ::GetDlgItem( m_hWnd, IDC_NET_CONNECT ), TRUE );
SetControlEnable( TRUE );
return TRUE;
}
DLGMSG CNetPlayDlg::OnNetworkError( DLGMSGPARAM )
{
NetPlay.SetMsgWnd( NULL );
SetStatusMessage( IDS_ERROR_NETWORKERROR );
::EnableWindow( ::GetDlgItem( m_hWnd, IDC_NET_CONNECT ), TRUE );
SetControlEnable( TRUE );
return TRUE;
}
DLGCMD CNetPlayDlg::OnServer( DLGCMDPARAM )
{
DEBUGOUT( "CNetPlayDlg::OnServer\n" );
SetControlEnable( TRUE );
}
DLGCMD CNetPlayDlg::OnClient( DLGCMDPARAM )
{
DEBUGOUT( "CNetPlayDlg::OnClient\n" );
SetControlEnable( TRUE );
}
DLGCMD CNetPlayDlg::OnConnect( DLGCMDPARAM )
{
DEBUGOUT( "CNetPlayDlg::OnConnect\n" );
CHAR szPort[_MAX_PATH+1];
CHAR szHost[_MAX_PATH+1];
CHAR szHostName[_MAX_PATH+1];
CHAR szNick[_MAX_PATH+1];
if( IsBTNCHECK(IDC_NET_SERVER) ) {
// 僒乕僶乕
::GetWindowText( ::GetDlgItem( m_hWnd, IDC_NET_PORT_COMBO ), szPort, _MAX_PATH );
::GetWindowText( ::GetDlgItem( m_hWnd, IDC_NET_NICKNAME ), szNick, _MAX_PATH );
INT porttemp = ::atoi( szPort );
if( porttemp < 1024 || porttemp > 65535 ) {
SetStatusMessage( IDS_ERROR_NETWORKERROR );
return;
}
m_uPort = porttemp;
m_nNetLatency = ::SendDlgItemMessage( m_hWnd, IDC_NET_LATENCY_COMBO, CB_GETCURSEL, 0, 0 );
DEBUGOUT( "Server Port:%d\n", m_uPort );
DEBUGOUT( "Latency :%d\n", m_nNetLatency );
} else {
// 僋儔僀傾儞僩
::GetWindowText( ::GetDlgItem( m_hWnd, IDC_NET_HOST_COMBO ), szHost, _MAX_PATH );
::GetWindowText( ::GetDlgItem( m_hWnd, IDC_NET_NICKNAME ), szNick, _MAX_PATH );
DEBUGOUT( "Host and Addr: %s\n", szHost );
DEBUGOUT( "NickName : %s\n", szNick );
INT i;
BOOL bFound;
bFound = FALSE;
::lstrcpy( szHostName, szHost );
for( i = 0; i < ::strlen( szHostName ); i++ ) {
if( szHostName[i] == ':' ) {
bFound = TRUE;
break;
}
}
if( !bFound ) {
SetStatusMessage( IDS_ERROR_NETWORKERROR );
return;
}
szHostName[i] = '\0';
LPSTR lpszPort = &szHostName[i+1];
INT porttemp = ::atoi( lpszPort );
if( porttemp < 1024 || porttemp > 65535 ) {
SetStatusMessage( IDS_ERROR_NETWORKERROR );
return;
}
m_uPort = porttemp;
DEBUGOUT( "Host:%s Port:%d\n", szHostName, m_uPort );
m_nNetLatency = ::SendDlgItemMessage( m_hWnd, IDC_NET_LATENCY_COMBO, CB_GETCURSEL, 0, 0 );
if( m_nNetLatency == CB_ERR ) {
SetStatusMessage( IDS_ERROR_UNKNOWN );
return;
}
}
if( IsBTNCHECK(IDC_NET_SERVER) ) {
// 僄儔乕偲偐偦偺懠傕傠傕傠傪偙偺僂僀儞僪僂偱庴偗庢傞堊
NetPlay.SetMsgWnd( m_hWnd );
if( NetPlay.Connect( TRUE, szHostName, m_uPort ) ) {
SetStatusMessage( IDS_NET_ACCEPTING );
::EnableWindow( ::GetDlgItem( m_hWnd, IDC_NET_CONNECT ), FALSE );
SetControlEnable( FALSE );
} else {
SetStatusMessage( IDS_ERROR_NETWORKERROR );
DEBUGOUT( "CNetPlayDlg::OnConnect error.\n" );
}
} else {
SetStatusMessage( IDS_NET_CONNECTING );
INT ret = NetPlay.ASyncHostCheck( m_hWnd, szHostName );
if( ret == 0 ) {
// 僄儔乕偲偐偦偺懠傕傠傕傠傪偙偺僂僀儞僪僂偱庴偗庢傞堊
NetPlay.SetMsgWnd( m_hWnd );
if( NetPlay.Connect( FALSE, szHostName, m_uPort ) ) {
SetStatusMessage( IDS_NET_CONNECTING );
::EnableWindow( ::GetDlgItem( m_hWnd, IDC_NET_CONNECT ), FALSE );
SetControlEnable( FALSE );
} else {
SetStatusMessage( IDS_ERROR_NETWORKERROR );
DEBUGOUT( "CNetPlayDlg::OnConnect error.\n" );
}
} else if( ret > 0 ) {
::EnableWindow( ::GetDlgItem( m_hWnd, IDC_NET_CONNECT ), FALSE );
SetControlEnable( FALSE );
} else if( ret < 0 ) {
SetStatusMessage( IDS_ERROR_NETWORKERROR );
DEBUGOUT( "CNetPlayDlg::OnConnect error.\n" );
}
}
// ::EndDialog( m_hWnd, IDOK );
}
DLGCMD CNetPlayDlg::OnCancel( DLGCMDPARAM )
{
DEBUGOUT( "CNetPlayDlg::OnCancel\n" );
NetPlay.Disconnect();
::EndDialog( m_hWnd, IDCANCEL );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -