bool UDemoNetDriver::InitListen( FNetworkNotify* InNotify, FURL& ListenURL, bool bReuseAddressAndPort, FString& Error ) { if ( !InitBase( false, InNotify, ListenURL, bReuseAddressAndPort, Error ) ) { return false; } check( World != NULL ); class AWorldSettings * WorldSettings = World->GetWorldSettings(); if ( !WorldSettings ) { Error = TEXT( "No WorldSettings!!" ); return false; } // Recording, local machine is server, demo stream acts "as if" it's a client. UDemoNetConnection* Connection = ConstructObject<UDemoNetConnection>( UDemoNetConnection::StaticClass() ); Connection->InitConnection( this, USOCK_Open, ListenURL, 1000000 ); Connection->InitSendBuffer(); FileAr = IFileManager::Get().CreateFileWriter( *DemoFilename ); ClientConnections.Add( Connection ); if( !FileAr ) { Error = FString::Printf( TEXT("Couldn't open demo file %s for writing"), *DemoFilename );//@todo demorec: localize return false; } // use the same byte format regardless of platform so that the demos are cross platform //@note: swap on non console platforms as the console archives have byte swapping compiled out by default //FileAr->SetByteSwapping(true); FNetworkDemoHeader DemoHeader; // NOTE - This must be the SAME string we write when we close the demo or it will throw the header off DemoHeader.LevelName = World->GetCurrentLevel()->GetOutermost()->GetName(); // Write the initial header (a lot of the fields will be placeholder until we fill them in later) (*FileAr) << DemoHeader; // Spawn the demo recording spectator. SpawnDemoRecSpectator( Connection ); return true; }
bool UDemoNetDriver::InitListen( FNetworkNotify* InNotify, FURL& ListenURL, bool bReuseAddressAndPort, FString& Error ) { if ( !InitBase( false, InNotify, ListenURL, bReuseAddressAndPort, Error ) ) { return false; } check( World != NULL ); class AWorldSettings * WorldSettings = World->GetWorldSettings(); if ( !WorldSettings ) { Error = TEXT( "No WorldSettings!!" ); return false; } // Recording, local machine is server, demo stream acts "as if" it's a client. UDemoNetConnection* Connection = ConstructObject<UDemoNetConnection>( UDemoNetConnection::StaticClass() ); Connection->InitConnection( this, USOCK_Open, ListenURL, 1000000 ); Connection->InitSendBuffer(); FileAr = IFileManager::Get().CreateFileWriter( *DemoFilename ); ClientConnections.Add( Connection ); if( !FileAr ) { Error = FString::Printf( TEXT("Couldn't open demo file %s for writing"), *DemoFilename );//@todo demorec: localize return false; } // use the same byte format regardless of platform so that the demos are cross platform //@note: swap on non console platforms as the console archives have byte swapping compiled out by default //FileAr->SetByteSwapping(true); // write engine version info int32 EngineVersion = GEngineNetVersion; (*FileAr) << EngineVersion; // write placeholder for total frames - will be updated when the demo is stopped PlaybackTotalFrames = 0; (*FileAr) << PlaybackTotalFrames; #if 0 // Create the control channel. Connection->CreateChannel( CHTYPE_Control, 1, 0 ); // Send initial message. uint8 IsLittleEndian = uint8( PLATFORM_LITTLE_ENDIAN ); check( IsLittleEndian == !!IsLittleEndian ); // should only be one or zero FNetControlMessage<NMT_Hello>::Send( Connection, IsLittleEndian, GEngineMinNetVersion, GEngineNetVersion, Cast<UGeneralProjectSettings>(UGeneralProjectSettings::StaticClass()->GetDefaultObject())->ProjectID ); Connection->FlushNet(); // WelcomePlayer will send the needed map name World->WelcomePlayer( Connection ); #else // Bypass UDemoPendingNetLevel FString LevelName = World->GetCurrentLevel()->GetOutermost()->GetName(); (*FileAr) << LevelName; #endif // Save out any levels that are in the streamed level list // This needs some work, but for now, to try and get games that use heavy streaming working int32 NumStreamingLevels = 0; for ( int32 i = 0; i < World->StreamingLevels.Num(); ++i ) { if ( World->StreamingLevels[i] != NULL ) { NumStreamingLevels++; } } (*FileAr) << NumStreamingLevels; for ( int32 i = 0; i < World->StreamingLevels.Num(); ++i ) { if ( World->StreamingLevels[i] != NULL ) { FString PackageName = World->StreamingLevels[i]->GetWorldAssetPackageName(); FString PackageNameToLoad = World->StreamingLevels[i]->PackageNameToLoad.ToString(); UE_LOG( LogDemo, Log, TEXT( " StreamingLevel: %s, %s" ), *PackageName, *PackageNameToLoad ); (*FileAr) << PackageName; (*FileAr) << PackageNameToLoad; (*FileAr) << World->StreamingLevels[i]->LevelTransform; } } // Spawn the demo recording spectator. SpawnDemoRecSpectator( Connection ); DemoDeltaTime = 0; LastRecordTime = 0; return true; }