bool CPotentialPlayer :: Update( void *fd ) { if( m_DeleteMe ) return true; if( !m_Socket ) return false; m_Socket->DoRecv( (fd_set *)fd ); ExtractPackets( ); ProcessPackets( ); // make sure we don't keep this socket open forever (disconnect after five seconds) if( m_ConnectionState == 0 && GetTicks( ) - m_ConnectionTime > m_Game->m_GHost->m_DenyMaxReqjoinTime && !m_Banned ) { CONSOLE_Print( "[DENY] Kicking player: REQJOIN not received within a few seconds" ); m_DeleteMe = true; m_Game->m_GHost->DenyIP( GetExternalIPString( ), m_Game->m_GHost->m_DenyReqjoinDuration, "REQJOIN not received within a few seconds" ); } // don't call DoSend here because some other players may not have updated yet and may generate a packet for this player // also m_Socket may have been set to NULL during ProcessPackets but we're banking on the fact that m_DeleteMe has been set to true as well so it'll short circuit before dereferencing return m_DeleteMe || m_Error || m_Socket->HasError( ) || !m_Socket->GetConnected( ); }
void CBNLSClient::socketDataReady() { ExtractPackets( ); ProcessPackets( ); while( !m_OutPackets.isEmpty( ) ) m_Socket->write( m_OutPackets.dequeue( ) ); }
void SendPacket(BYTE *data, UINT size, DWORD timestamp, PacketType type) { ProcessPackets(timestamp); NetworkPacket *newPacket = queuedPackets.CreateNew(); newPacket->data.CopyArray(data, size); newPacket->timestamp = timestamp; newPacket->type = type; lastTimestamp = timestamp; }
bool CBNLSClient :: Update( void *fd, void *send_fd ) { if( m_Socket->HasError( ) ) { CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] disconnected from BNLS server due to socket error" ); return true; } if( !m_Socket->GetConnecting( ) && !m_Socket->GetConnected( ) && m_WasConnected ) { CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] disconnected from BNLS server" ); return true; } if( m_Socket->GetConnected( ) ) { m_Socket->DoRecv( (fd_set *)fd ); ExtractPackets( ); ProcessPackets( ); if( GetTime( ) - m_LastNullTime >= 50 ) { m_Socket->PutBytes( m_Protocol->SEND_BNLS_NULL( ) ); m_LastNullTime = GetTime( ); } while( !m_OutPackets.empty( ) ) { m_Socket->PutBytes( m_OutPackets.front( ) ); m_OutPackets.pop( ); } m_Socket->DoSend( (fd_set *)send_fd ); return false; } if( m_Socket->GetConnecting( ) && m_Socket->CheckConnect( ) ) { CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] connected" ); m_WasConnected = true; m_LastNullTime = GetTime( ); return false; } if( !m_Socket->GetConnecting( ) && !m_Socket->GetConnected( ) && !m_WasConnected ) { CONSOLE_Print( "[BNLSC: " + m_Server + ":" + UTIL_ToString( m_Port ) + ":C" + UTIL_ToString( m_WardenCookie ) + "] connecting to server [" + m_Server + "] on port " + UTIL_ToString( m_Port ) ); m_Socket->Connect( string( ), m_Server, m_Port ); return false; } return false; }
GameState *ServerState::Update(App &app) { //std::cout << "updates per second: " << 1/APP(app).getFrameTime() << std::endl; while (!packetDataList->empty()) { sC->Broadcast(packetDataList->front()); packetDataList->pop(); } //delete packetDataList; sC->Run(); ProcessPackets(this); return this; }
~DelayedPublisher() { if(!outputStream || !outputStream->bStopping) { bStreamEnding = true; HWND hwndProgressDialog = CreateDialogParam(hinstMain, MAKEINTRESOURCE(IDD_ENDINGDELAY), hwndMain, (DLGPROC)EndDelayProc, (LPARAM)this); ProcessEvents(); ShowWindow(hwndProgressDialog, TRUE); DWORD totalTimeLeft = delayTime; String strTimeLeftVal = Str("EndingDelay.TimeLeft"); DWORD lastTimeLeft = -1; DWORD firstTime = OSGetTime(); while(queuedPackets.Num() && !bCancelEnd) { ProcessEvents(); DWORD timeElapsed = (OSGetTime()-firstTime); DWORD timeLeft = (totalTimeLeft-timeElapsed)/1000; DWORD timeLeftMinutes = timeLeft/60; DWORD timeLeftSeconds = timeLeft%60; if(timeLeft != lastTimeLeft) { String strTimeLeft = strTimeLeftVal; strTimeLeft.FindReplace(TEXT("$1"), FormattedString(TEXT("%u:%02u"), timeLeftMinutes, timeLeftSeconds)); SetWindowText(GetDlgItem(hwndProgressDialog, IDC_TIMELEFT), strTimeLeft); lastTimeLeft = timeLeft; } ProcessPackets(lastTimestamp+timeElapsed); if(outputStream && outputStream->bStopping) bCancelEnd = true; Sleep(10); } DestroyWindow(hwndProgressDialog); } for(UINT i=0; i<queuedPackets.Num(); i++) queuedPackets[i].data.Clear(); delete outputStream; }
bool CPotentialPlayer :: Update( void *fd ) { if( m_DeleteMe ) return true; if( !m_Socket ) return false; m_Socket->DoRecv( (fd_set *)fd ); ExtractPackets( ); ProcessPackets( ); // don't call DoSend here because some other players may not have updated yet and may generate a packet for this player // also m_Socket may have been set to NULL during ProcessPackets but we're banking on the fact that m_DeleteMe has been set to true as well so it'll short circuit before dereferencing return m_DeleteMe || m_Error || m_Socket->HasError( ) || !m_Socket->GetConnected( ); }
/** * Check for newly received packets. Called in the main loop: 'interrupt' mode is not * really supported :( * * @param adapter adapter handle received by a call to init_adapter */ void update_adapter(void *adapter) { struct packet_adapter *pa = (struct packet_adapter*)adapter; struct bpf_stat stat; /* print the capture statistics */ if(PacketGetStats(pa->lpAdapter, &stat) == FALSE) { printf("Warning: unable to get stats from the kernel!\n"); } else { if (pa->bs_drop != stat.bs_drop) { printf("%d packets received.\n%d Packets dropped.\n", stat.bs_recv, stat.bs_drop); pa->bs_drop = stat.bs_drop; } } if ((pa != NULL) && (PacketReceivePacket(pa->lpAdapter, pa->lpPacket, TRUE))) { ProcessPackets(adapter, pa->lpPacket); } }
BOOL CDCNeighbour::ProcessPackets() { CLockedBuffer pInputLocked( GetInput() ); if ( m_pZInput ) { if ( m_pZInput->m_nLength == 0 ) { if ( m_bZInputEOS ) { // Got "End of Stream" so turn decompression off m_bZInputEOS = FALSE; CBuffer::InflateStreamCleanup( m_pZSInput ); delete m_pZInput; m_pZInput = NULL; } return TRUE; } } CBuffer* pInput = m_pZInput ? m_pZInput : pInputLocked; return ProcessPackets( pInput ); }
void RTMPPublisher::SendPacketForReal(BYTE *data, UINT size, DWORD timestamp, PacketType type) { //OSDebugOut (TEXT("%u: SendPacketForReal (%d bytes - %08x @ %u, type %d)\n"), OSGetTime(), size, quickHash(data,size), timestamp, type); //Log(TEXT("packet| timestamp: %u, type: %u, bytes: %u"), timestamp, (UINT)type, size); OSEnterMutex(hDataMutex); if(bConnected) { ProcessPackets(); bool bSend = bSentFirstKeyframe; if(!bSentFirstKeyframe) { if(type == PacketType_VideoHighest) { bSend = true; OSDebugOut(TEXT("got keyframe: %u\r\n"), OSGetTime()); } } if(bSend) { if(!bSentFirstAudio && type == PacketType_Audio) { timestamp = 0; bSentFirstAudio = true; } totalFrames++; if(type != PacketType_Audio) totalVideoFrames++; bool bAddPacket = false; if(type >= packetWaitType) { if(type != PacketType_Audio) packetWaitType = PacketType_VideoDisposable; bAddPacket = true; } if(bAddPacket) { List<BYTE> paddedData; paddedData.SetSize(size+RTMP_MAX_HEADER_SIZE); mcpy(paddedData.Array()+RTMP_MAX_HEADER_SIZE, data, size); if(!bSentFirstKeyframe) { DataPacket sei; App->GetVideoEncoder()->GetSEI(sei); paddedData.InsertArray(RTMP_MAX_HEADER_SIZE+5, sei.lpPacket, sei.size); bSentFirstKeyframe = true; } currentBufferSize += paddedData.Num(); UINT droppedFrameVal = queuedPackets.Num() ? queuedPackets.Last().distanceFromDroppedFrame+1 : 10000; UINT id = FindClosestQueueIndex(timestamp); NetworkPacket *queuedPacket = queuedPackets.InsertNew(id); queuedPacket->distanceFromDroppedFrame = droppedFrameVal; queuedPacket->data.TransferFrom(paddedData); queuedPacket->timestamp = timestamp; queuedPacket->type = type; } else { if(type < PacketType_VideoHigh) numBFramesDumped++; else numPFramesDumped++; } } } OSLeaveMutex(hDataMutex); }
void processImpl() { if( server!=0 ) ProcessPackets( server ); }
BOOL CDCNeighbour::OnRead() { CNeighbour::OnRead(); return ProcessPackets(); }