Skip to content

Commit 36c47a5

Browse files
committed
Fixed time not appearing for insta-connects/host errors, and reuse existing flash policy file
I keep saying final, eventually it'll be true! Fixed the time not appearing if clients are trying to connect before timer first ticks, or if there's a host error. Timer tick is what updates the time used in console. Allows flash policy file to be used (and not deleted on app close) if it already exists on app startup.
1 parent 627d191 commit 36c47a5

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

Main.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ lacewing::eventpump globalpump;
3535
lacewing::timer globalmsgrecvcounttimer;
3636
lacewing::relayserver * globalserver;
3737
std::string flashpolicypath;
38+
bool deleteFlashPolicyAtEndOfApp;
3839
static char timeBuffer[10];
3940

4041
// In case of idiocy
@@ -153,9 +154,14 @@ int main()
153154
GenerateFlashPolicy(port);
154155
#endif
155156

157+
// Update the current time in case host() errors, or try to connect before first tick
158+
OnTimerTick(globalmsgrecvcounttimer);
159+
160+
156161
// Host the thing
157162
std::cout << green << "Host started. Port " << port << ", build " << globalserver->buildnum << ". " <<
158-
(flashpolicypath.empty() ? "Flash not hosting" : "Flash policy hosting on TCP port 843") << ".\r\n" << yellow;
163+
(flashpolicypath.empty() ? "Flash not hosting" : "Flash policy hosting on TCP port 843") << "." <<
164+
std::string(flashpolicypath.empty() ? 30 : 5, ' ') << "\r\n" << yellow;
159165

160166
globalserver->host(port);
161167

@@ -188,7 +194,7 @@ int main()
188194
delete globalserver;
189195
lacewing::pump_delete(globalpump);
190196

191-
if (!flashpolicypath.empty())
197+
if (!flashpolicypath.empty() && deleteFlashPolicyAtEndOfApp)
192198
DeleteFileA(flashpolicypath.c_str());
193199

194200
// Lacewing uses a sync inside lw_trace, which is singleton and never freed.
@@ -469,14 +475,6 @@ void OnChannelMessage(lacewing::relayserver &server, std::shared_ptr<lacewing::r
469475

470476
void GenerateFlashPolicy(int port)
471477
{
472-
std::stringstream flashPolicy;
473-
flashPolicy << "<?xml version=\"1.0\"?>\r\n"
474-
"<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\r\n"
475-
"<cross-domain-policy>\r\n"
476-
"\t<site-control permitted-cross-domain-policies=\"master-only\"/>\r\n"
477-
"\t<allow-access-from domain=\"*\" to-ports=\"843," << port << ",583\" secure=\"false\" />\r\n"
478-
"</cross-domain-policy>";
479-
480478
char filenameBuf[1024];
481479
// Get full path of EXE, including EXE filename + ext
482480
size_t bytes = GetModuleFileNameA(NULL, filenameBuf, sizeof(filenameBuf));
@@ -497,15 +495,32 @@ void GenerateFlashPolicy(int port)
497495
}
498496

499497
filename = filename.substr(0U, lastSlash + 1U) + "FlashPlayerPolicy.xml";
498+
499+
// File already exists; just use it
500+
DWORD policyAttr = GetFileAttributesA(filename.c_str());
501+
if (policyAttr != INVALID_FILE_ATTRIBUTES && !(policyAttr & FILE_ATTRIBUTE_DIRECTORY))
502+
{
503+
flashpolicypath = filename;
504+
return;
505+
}
506+
500507
HANDLE forWriting = CreateFileA(filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
501508
if (forWriting == NULL || forWriting == INVALID_HANDLE_VALUE)
502509
{
503510
std::cout << "Flash policy couldn't be created. Opening file " << filename << " for writing in current app folder failed.\r\n";
504511
return;
505512
}
506513

507-
std::string policyStr = flashPolicy.str();
514+
deleteFlashPolicyAtEndOfApp = true;
508515

516+
std::stringstream flashPolicy;
517+
flashPolicy << "<?xml version=\"1.0\"?>\r\n"
518+
"<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\r\n"
519+
"<cross-domain-policy>\r\n"
520+
"\t<site-control permitted-cross-domain-policies=\"master-only\"/>\r\n"
521+
"\t<allow-access-from domain=\"*\" to-ports=\"843," << port << ",583\" secure=\"false\" />\r\n"
522+
"</cross-domain-policy>";
523+
const std::string policyStr = flashPolicy.str();
509524
if (!WriteFile(forWriting, policyStr.c_str(), (DWORD)policyStr.size(), NULL, NULL))
510525
{
511526
std::cout << "Flash policy couldn't be created. Writing to file " << filename << " failed.\r\n";

bluewing-cpp-server.vcxproj

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,23 @@
3232
<ConfigurationType>Application</ConfigurationType>
3333
<UseDebugLibraries>true</UseDebugLibraries>
3434
<PlatformToolset>v141_xp</PlatformToolset>
35-
<CharacterSet>NotSet</CharacterSet>
3635
</PropertyGroup>
3736
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3837
<ConfigurationType>Application</ConfigurationType>
3938
<UseDebugLibraries>false</UseDebugLibraries>
4039
<PlatformToolset>v141_xp</PlatformToolset>
4140
<WholeProgramOptimization>true</WholeProgramOptimization>
42-
<CharacterSet>NotSet</CharacterSet>
4341
</PropertyGroup>
4442
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4543
<ConfigurationType>Application</ConfigurationType>
4644
<UseDebugLibraries>true</UseDebugLibraries>
4745
<PlatformToolset>v141_xp</PlatformToolset>
48-
<CharacterSet>Unicode</CharacterSet>
4946
</PropertyGroup>
5047
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
5148
<ConfigurationType>Application</ConfigurationType>
5249
<UseDebugLibraries>false</UseDebugLibraries>
5350
<PlatformToolset>v141_xp</PlatformToolset>
5451
<WholeProgramOptimization>true</WholeProgramOptimization>
55-
<CharacterSet>Unicode</CharacterSet>
5652
</PropertyGroup>
5753
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
5854
<ImportGroup Label="ExtensionSettings">
@@ -74,18 +70,27 @@
7470
<PropertyGroup Label="UserMacros" />
7571
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7672
<LinkIncremental>true</LinkIncremental>
77-
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
73+
<GenerateManifest>false</GenerateManifest>
74+
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\</OutDir>
75+
<IntDir>$(PlatformTarget)\$(Configuration)\</IntDir>
7876
</PropertyGroup>
7977
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
8078
<LinkIncremental>true</LinkIncremental>
79+
<GenerateManifest>false</GenerateManifest>
80+
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\</OutDir>
81+
<IntDir>$(PlatformTarget)\$(Configuration)\</IntDir>
8182
</PropertyGroup>
8283
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
8384
<LinkIncremental>false</LinkIncremental>
84-
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
85+
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\</OutDir>
8586
<GenerateManifest>false</GenerateManifest>
87+
<IntDir>$(PlatformTarget)\$(Configuration)\</IntDir>
8688
</PropertyGroup>
8789
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
8890
<LinkIncremental>false</LinkIncremental>
91+
<GenerateManifest>false</GenerateManifest>
92+
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\</OutDir>
93+
<IntDir>$(PlatformTarget)\$(Configuration)\</IntDir>
8994
</PropertyGroup>
9095
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
9196
<ClCompile>
@@ -96,7 +101,6 @@
96101
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;WIN32;lw_import=;_lacewing_static=;_WINSOCK_DEPRECATED_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
97102
<SDLCheck>true</SDLCheck>
98103
<MultiProcessorCompilation>true</MultiProcessorCompilation>
99-
<ExceptionHandling>Async</ExceptionHandling>
100104
<CompileAs>CompileAsCpp</CompileAs>
101105
<MinimalRebuild>false</MinimalRebuild>
102106
<BufferSecurityCheck>true</BufferSecurityCheck>
@@ -131,12 +135,10 @@
131135
<PrecompiledHeader>
132136
</PrecompiledHeader>
133137
<Optimization>MaxSpeed</Optimization>
134-
<FunctionLevelLinking>true</FunctionLevelLinking>
135138
<IntrinsicFunctions>true</IntrinsicFunctions>
136139
<PreprocessorDefinitions>WIN32;lw_import=;_lacewing_static=;_WINSOCK_DEPRECATED_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
137140
<SDLCheck>true</SDLCheck>
138141
<MultiProcessorCompilation>true</MultiProcessorCompilation>
139-
<ExceptionHandling>Async</ExceptionHandling>
140142
<CompileAs>CompileAsCpp</CompileAs>
141143
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
142144
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@@ -164,6 +166,9 @@
164166
<SDLCheck>true</SDLCheck>
165167
<LanguageStandard>stdcpp17</LanguageStandard>
166168
<CompileAs>CompileAsCpp</CompileAs>
169+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
170+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
171+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
167172
</ClCompile>
168173
<Link>
169174
<SubSystem>Console</SubSystem>

0 commit comments

Comments
 (0)