session creation fixed
This commit is contained in:
@@ -7,12 +7,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServerPixel", "ServerPixel\
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
build|x64 = build|x64
|
||||
build|x86 = build|x86
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{46B65B94-51FC-4B93-9B89-262FD262C49F}.build|x64.ActiveCfg = Release|x64
|
||||
{46B65B94-51FC-4B93-9B89-262FD262C49F}.build|x64.Build.0 = Release|x64
|
||||
{46B65B94-51FC-4B93-9B89-262FD262C49F}.build|x86.ActiveCfg = build|Win32
|
||||
{46B65B94-51FC-4B93-9B89-262FD262C49F}.build|x86.Build.0 = build|Win32
|
||||
{46B65B94-51FC-4B93-9B89-262FD262C49F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{46B65B94-51FC-4B93-9B89-262FD262C49F}.Debug|x64.Build.0 = Debug|x64
|
||||
{46B65B94-51FC-4B93-9B89-262FD262C49F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
|
||||
+51
-66
@@ -127,31 +127,33 @@ int main(int argc, char* argv[])
|
||||
|
||||
|
||||
|
||||
// args
|
||||
// 1 - copies amount
|
||||
// 2 - path_to_node.js
|
||||
// 3 - start_http_port
|
||||
// 4 - start_streamer_port
|
||||
// args
|
||||
// 1 - server ip
|
||||
// 2 - server port
|
||||
// 3 - copies amount
|
||||
// 4 - path_to_node.js
|
||||
// 5 - start_http_port
|
||||
// 6 - start_streamer_port
|
||||
|
||||
// 5 - path_to_application
|
||||
// 6 - application_args (without -pixelStreamingPort cos its argv[3])
|
||||
// 7 - path_to_application
|
||||
// 8 - application_args (without -pixelStreamingPort cos its argv[3])
|
||||
|
||||
// sessions
|
||||
uint16_t sessionLimit = std::atoi(argv[1]);
|
||||
uint16_t sessionLimit = std::atoi(argv[3]);
|
||||
sessionManager sessManager;
|
||||
sessManager.setlimit(sessionLimit);
|
||||
|
||||
// merging app arguments
|
||||
std::string appPath = argv[5];
|
||||
std::string appPath = argv[7];
|
||||
std::string appArgs;
|
||||
for (int i = 6; i < argc; ++i)
|
||||
for (int i = 8; i < argc; ++i)
|
||||
appArgs += argv[i] + std::string(" ");
|
||||
|
||||
appArgs += "-PixelStreamingPort=";
|
||||
|
||||
// first app ports
|
||||
uint16_t portHttp = std::atoi(argv[3]);
|
||||
uint16_t portStream = std::atoi(argv[4]);
|
||||
uint16_t portHttp = std::atoi(argv[5]);
|
||||
uint16_t portStream = std::atoi(argv[6]);
|
||||
|
||||
// node js
|
||||
/*std::string nodePath = "C:\\Program Files\\nodejs\\node.exe";
|
||||
@@ -160,14 +162,15 @@ int main(int argc, char* argv[])
|
||||
// starting node js servers
|
||||
for (uint16_t i = 0; i < sessionLimit; ++i)
|
||||
{
|
||||
system((std::string("start node ") + argv[2] + " " + std::to_string(portHttp + i) + " " + std::to_string(portStream + i)).c_str());
|
||||
system((std::string("start node ") + argv[4] + " " + std::to_string(portHttp + i) + " " + std::to_string(portStream + i)).c_str());
|
||||
}
|
||||
|
||||
// ip and socket init
|
||||
std::string ip("192.168.1.115");
|
||||
uint16_t sess_port = 13002;
|
||||
std::string ip(argv[1]);
|
||||
std::cout << "ip: " << ip << std::endl;
|
||||
auto const address = net::ip::make_address(ip);
|
||||
auto const port = static_cast<unsigned short>(std::atoi("13001"));
|
||||
auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
|
||||
std::cout << "port: " << port << std::endl;
|
||||
net::io_context ioc{ 1 };
|
||||
tcp::acceptor acceptor{ ioc, {address, port} };
|
||||
|
||||
@@ -183,7 +186,6 @@ int main(int argc, char* argv[])
|
||||
sock = std::move(socket),
|
||||
&sessManager,
|
||||
&ip,
|
||||
&sess_port,
|
||||
&user_n,
|
||||
appPath,
|
||||
appArgs,
|
||||
@@ -209,26 +211,16 @@ int main(int argc, char* argv[])
|
||||
res.set(http::field::server, std::string(BOOST_BEAST_VERSION_STRING) + " websocket-server-sync");
|
||||
}));*/
|
||||
|
||||
//session sessTmp;
|
||||
session* sessCur = nullptr;
|
||||
uint32_t sessId = 0;
|
||||
uint16_t sessMinPort = sessManager.getMinPort();
|
||||
uint16_t sessHttpPort = sessMinPort ? sessMinPort + 1 : portHttp;
|
||||
uint16_t sessStreamPort = portStream + (sessHttpPort - portHttp);
|
||||
|
||||
//std::cout << "minPort: " << sessMinPort << std::endl;
|
||||
|
||||
//std::cout << "httpPortDefault: " << portHttp << std::endl
|
||||
// << "streamPortDefault: " << portStream << std::endl;
|
||||
|
||||
//std::cout << "httpPort: " << sessHttpPort << std::endl
|
||||
// << "streamPort: " << sessStreamPort << std::endl;
|
||||
|
||||
|
||||
nlohmann::json jsonData;
|
||||
std::string message;
|
||||
std::string content;
|
||||
|
||||
|
||||
|
||||
//session sessTmp;
|
||||
session* sessCur = nullptr;
|
||||
uint32_t sessId = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
@@ -292,30 +284,35 @@ int main(int argc, char* argv[])
|
||||
ws.write(buffer.data());
|
||||
continue;
|
||||
}
|
||||
if (sessManager.existsOwnerIp(user_ip))
|
||||
if (sessManager.existsOwnerId(user_id))
|
||||
{
|
||||
boost::beast::ostream(buffer)
|
||||
<< std::string("{\"message\" : \"PERSON_LIMIT\"}").c_str();
|
||||
ws.write(buffer.data());
|
||||
continue;
|
||||
}
|
||||
|
||||
//sessManager
|
||||
|
||||
boost::beast::ostream(buffer)
|
||||
<< std::string("{\"message\" : \"CREATING_SESSION\", \"content\" : \"true\"}").c_str();
|
||||
ws.write(buffer.data());
|
||||
|
||||
// get session port
|
||||
uint16_t sessMinPort = sessManager.getMinPort();
|
||||
uint16_t sessHttpPort = sessMinPort ? sessMinPort + 1 : portHttp;
|
||||
uint16_t sessStreamPort = portStream + (sessHttpPort - portHttp);
|
||||
|
||||
|
||||
// creating process
|
||||
PROCESS_INFORMATION appProcInfo;
|
||||
//PROCESS_INFORMATION nodeProcInfo;
|
||||
|
||||
// create app process
|
||||
if (!CreateProc(appPath, appPath + " " + appArgs + std::to_string(sessStreamPort), &appProcInfo))
|
||||
{
|
||||
std::cout << "CreateProcess failed (" << GetLastError() << ")." << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
boost::beast::ostream(buffer)
|
||||
<< std::string("{\"message\" : \"CREATING_SESSION\", \"content\" : \"true\"}").c_str();
|
||||
ws.write(buffer.data());
|
||||
|
||||
|
||||
|
||||
// bind app process close listen
|
||||
std::thread([appProcInfo]()
|
||||
@@ -325,34 +322,13 @@ int main(int argc, char* argv[])
|
||||
CloseHandle(appProcInfo.hThread);
|
||||
}).detach();
|
||||
|
||||
//std::string nodeArgs = nodePath + " " + nodeFilePath + " "
|
||||
// + std::to_string(sessHttpPort) + " "
|
||||
// + std::to_string(sessStreamPort);
|
||||
|
||||
//// create node js server proc
|
||||
//if (!CreateProc(nodePath, nodePath + " " + nodeFilePath + " "
|
||||
// + std::to_string(sessHttpPort) + " "
|
||||
// + std::to_string(sessStreamPort), &nodeProcInfo))
|
||||
//{
|
||||
// std::cout << "CreateProcess failed (" << GetLastError() << ")." << std::endl;
|
||||
// continue;
|
||||
//}
|
||||
|
||||
////bind node js close listen
|
||||
//std::thread([nodeProcInfo]()
|
||||
// {
|
||||
// WaitForSingleObject(nodeProcInfo.hProcess, INFINITE);
|
||||
// CloseHandle(nodeProcInfo.hProcess);
|
||||
// CloseHandle(nodeProcInfo.hThread);
|
||||
// }).detach();
|
||||
|
||||
sessId = hash6(user_id);
|
||||
|
||||
// create session
|
||||
sessManager.add(
|
||||
session(
|
||||
sessId,
|
||||
ip + std::to_string(sess_port),
|
||||
ip + std::to_string(sessHttpPort),
|
||||
user_ip,
|
||||
sessHttpPort
|
||||
));
|
||||
@@ -367,7 +343,8 @@ int main(int argc, char* argv[])
|
||||
//sessCur->addProcId(GetProcessId(nodeProcInfo.hProcess));
|
||||
}
|
||||
|
||||
std::cout << "user(" << thisUserNum << ") created session (id: " << sessId << ")" << std::endl;
|
||||
std::cout << "user(" << thisUserNum << ") created session (id: " << sessId <<
|
||||
"), (httpPort: " << sessHttpPort << "), (streamPort: " << sessStreamPort << ")" << std::endl;
|
||||
|
||||
// send respond
|
||||
buffer.clear();
|
||||
@@ -378,7 +355,6 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else if (message == "SESS_CONNECT")
|
||||
{
|
||||
std::cout << "sess_connect" << std::endl;
|
||||
// read session id
|
||||
try
|
||||
{
|
||||
@@ -402,10 +378,17 @@ int main(int argc, char* argv[])
|
||||
std::cout << "Unknown exception" << e.what() << std::endl;
|
||||
}
|
||||
|
||||
sessId = atoi(content.c_str());
|
||||
// connect to session
|
||||
if (sessManager.getById(atoi(content.c_str()), &sessCur))
|
||||
if (sessManager.getById(sessId, &sessCur))
|
||||
{
|
||||
if (sessCur->existsUserId(user_id))
|
||||
{
|
||||
std::cout << "user exists: " << user_id << std::endl;
|
||||
continue;
|
||||
}
|
||||
sessCur->addUser(user(user_id));
|
||||
|
||||
std::cout << "user(" << thisUserNum << ") connected to session (id: " << sessCur->getId()
|
||||
<< "), (users: " << sessCur->getUsersCount() << ")" << std::endl;
|
||||
|
||||
@@ -431,6 +414,8 @@ int main(int argc, char* argv[])
|
||||
catch (beast::system_error const& se)
|
||||
{
|
||||
std::cout << "user(" << thisUserNum << ") disconnected" << std::endl;
|
||||
if (!sessManager.getById(sessId, &sessCur))
|
||||
std::cout << "no session with id: " << sessId << std::endl;
|
||||
if (sessCur)
|
||||
{
|
||||
sessCur->removeUserById(user_id);
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="build|Win32">
|
||||
<Configuration>build</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="build|x64">
|
||||
<Configuration>build</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
@@ -39,6 +47,13 @@
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='build|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
@@ -52,6 +67,13 @@
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='build|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
@@ -63,12 +85,18 @@
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='build|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='build|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@@ -98,6 +126,22 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='build|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
@@ -112,6 +156,23 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>C:\Libraries\json-develop\include;C:\Libraries\boost\include\boost_1_79_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='build|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
|
||||
@@ -33,11 +33,20 @@ public:
|
||||
if (users[i].getId() == id)
|
||||
users.erase(users.begin() + i);
|
||||
}
|
||||
bool existsUserId(uint32_t id) const
|
||||
{
|
||||
for (auto& u : users)
|
||||
if (u.getId() == id)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
inline size_t getUsersCount() const { return users.size(); }
|
||||
inline const uint32_t& getId() const { return sessId; }
|
||||
inline const uint32_t& getOwnerId() const { return sessId; }
|
||||
inline const std::vector<DWORD>& getProcIds() const { return procIds; }
|
||||
inline void addProcId(DWORD procId) { procIds.push_back(procId); }
|
||||
inline const std::string& getOwnerIp() const { return ownerIp; }
|
||||
inline const uint16_t getPort() const { return port; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -43,6 +43,14 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool existsOwnerId(uint32_t id)
|
||||
{
|
||||
for (auto& s : sessions)
|
||||
if (s.getOwnerId() == id)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t getCount() { return sessions.size(); }
|
||||
void setlimit(uint32_t limit) { this->limit = limit; }
|
||||
bool isLimitReached()
|
||||
|
||||
+4
-4
@@ -10,7 +10,7 @@
|
||||
#pragma once
|
||||
class user
|
||||
{
|
||||
public:
|
||||
private:
|
||||
std::string name = "";
|
||||
char age = 0;
|
||||
uint32_t id = 0;
|
||||
@@ -25,8 +25,8 @@ public:
|
||||
{
|
||||
this->id = id;
|
||||
}
|
||||
std::string getName() { return name; }
|
||||
char getAge() { return age; }
|
||||
uint32_t getId() { return id; }
|
||||
std::string getName() const { return name; }
|
||||
char getAge() const { return age; }
|
||||
uint32_t getId() const { return id; }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user