Skip to content

Commit adfab1e

Browse files
committed
Core updates
Cleaned up much of the network code. Next is cleaning up the gatewayserver code and brining most of it into c++ code
1 parent 9b1a54b commit adfab1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1534
-1063
lines changed

RemoteDesktopServer_Library/MainServer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void RemoteDesktop::Startup(LPWSTR* argv, int argc, bool reverseconnect_to_gatew
2121
{
2222
Sleep(3000);//give enough time for the previous programs to shut down
2323
UninstallService(Service_Name());
24-
}
24+
}
2525
else if (_wcsicmp(L"service_mon", argv[1] + 1) == 0)
2626
{
2727
ServerService service(Service_Name());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Server">
5+
<UniqueIdentifier>{08388162-7190-4f84-a024-b46101efd16b}</UniqueIdentifier>
6+
</Filter>
7+
<Filter Include="Service">
8+
<UniqueIdentifier>{bd207d27-58d6-4a86-b0a7-30943bea89ca}</UniqueIdentifier>
9+
</Filter>
10+
<Filter Include="SysTray">
11+
<UniqueIdentifier>{28c569a5-24bc-4956-a7be-f3524e2450da}</UniqueIdentifier>
12+
</Filter>
13+
<Filter Include="Server\Dialogs">
14+
<UniqueIdentifier>{6a0eab8e-e403-48f4-a45b-e6dbd1f39c6c}</UniqueIdentifier>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="MainServer.h">
19+
<Filter>Server</Filter>
20+
</ClInclude>
21+
<ClInclude Include="MouseCapture.h">
22+
<Filter>Server</Filter>
23+
</ClInclude>
24+
<ClInclude Include="SoftwareCAD.h">
25+
<Filter>Server</Filter>
26+
</ClInclude>
27+
<ClInclude Include="ServerService.h">
28+
<Filter>Service</Filter>
29+
</ClInclude>
30+
<ClInclude Include="ServiceBase.h">
31+
<Filter>Service</Filter>
32+
</ClInclude>
33+
<ClInclude Include="ServiceHelpers.h">
34+
<Filter>Service</Filter>
35+
</ClInclude>
36+
<ClInclude Include="ServiceInstaller.h">
37+
<Filter>Service</Filter>
38+
</ClInclude>
39+
<ClInclude Include="ServiceMonitor.h">
40+
<Filter>Service</Filter>
41+
</ClInclude>
42+
<ClInclude Include="SystemTray.h">
43+
<Filter>SysTray</Filter>
44+
</ClInclude>
45+
<ClInclude Include="EventLogMessages.h" />
46+
<ClInclude Include="resource.h" />
47+
<ClInclude Include="stdafx.h" />
48+
<ClInclude Include="NewConnectDialog.h">
49+
<Filter>Server\Dialogs</Filter>
50+
</ClInclude>
51+
<ClInclude Include="GatewayConnectDialog.h">
52+
<Filter>Server\Dialogs</Filter>
53+
</ClInclude>
54+
<ClInclude Include="Server.h">
55+
<Filter>Server</Filter>
56+
</ClInclude>
57+
</ItemGroup>
58+
<ItemGroup>
59+
<ClCompile Include="ServiceInstaller.cpp">
60+
<Filter>Service</Filter>
61+
</ClCompile>
62+
<ClCompile Include="ServiceBase.cpp">
63+
<Filter>Service</Filter>
64+
</ClCompile>
65+
<ClCompile Include="ServerService.cpp">
66+
<Filter>Service</Filter>
67+
</ClCompile>
68+
<ClCompile Include="ServiceMonitor.cpp">
69+
<Filter>Service</Filter>
70+
</ClCompile>
71+
<ClCompile Include="MouseCapture.cpp">
72+
<Filter>Server</Filter>
73+
</ClCompile>
74+
<ClCompile Include="ServiceHelpers.cpp">
75+
<Filter>Service</Filter>
76+
</ClCompile>
77+
<ClCompile Include="SystemTray.cpp">
78+
<Filter>SysTray</Filter>
79+
</ClCompile>
80+
<ClCompile Include="MainServer.cpp">
81+
<Filter>Server</Filter>
82+
</ClCompile>
83+
<ClCompile Include="SoftwareCAD.cpp">
84+
<Filter>Service</Filter>
85+
</ClCompile>
86+
<ClCompile Include="stdafx.cpp" />
87+
<ClCompile Include="NewConnectDialog.cpp">
88+
<Filter>Server\Dialogs</Filter>
89+
</ClCompile>
90+
<ClCompile Include="GatewayConnectDialog.cpp">
91+
<Filter>Server\Dialogs</Filter>
92+
</ClCompile>
93+
<ClCompile Include="Server.cpp">
94+
<Filter>Server</Filter>
95+
</ClCompile>
96+
</ItemGroup>
97+
<ItemGroup>
98+
<Image Include="icon1.ico" />
99+
<Image Include="logo.bmp" />
100+
</ItemGroup>
101+
<ItemGroup>
102+
<CustomBuild Include="EventLogMessages.mc" />
103+
</ItemGroup>
104+
<ItemGroup>
105+
<ResourceCompile Include="RemoteDesktopServer_Library.rc" />
106+
</ItemGroup>
107+
</Project>

RemoteDesktopServer_Library/Server.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ RemoteDesktop::Server::~Server(){
5858
}
5959
else Cleanup_System_Configuration();
6060
}
61+
//i need to make sure these shut down before cointinuing
62+
_NetworkServer = nullptr;
63+
mousecapturing = nullptr;
64+
_DesktopMonitor = nullptr;
65+
_ClipboardMonitor = nullptr;
66+
_SystemTray = nullptr;
67+
_VirtualScreen = nullptr;
68+
6169
}
6270
void RemoteDesktop::Server::_CreateSystemMenu(){
6371
_SystemTray->AddMenuItem(L"Exit", DELEGATE(&RemoteDesktop::Server::_TriggerShutDown));
@@ -262,13 +270,11 @@ void RemoteDesktop::Server::_Handle_ConnectionRequest(Packet_Header* header, con
262270
_NewClients.push_back(sh);
263271
}
264272
else {// show pop up asking for permission to connect
265-
266273
_NewConnect_Dialog = std::make_shared<NewConnect_Dialog>();
267274
_NewConnect_Dialog->Show(uname);
268275
_NewConnect_Dialog->OnAllow = DELEGATE(&RemoteDesktop::Server::_OnAllowConnection);
269276
_NewConnect_Dialog->OnDeny = DELEGATE(&RemoteDesktop::Server::_OnDenyConnection);
270277
}
271-
272278
}
273279
else {
274280
DEBUG_MSG("Setting user to disconnected because there was no name sent with the access request.");
@@ -334,9 +340,7 @@ void RemoteDesktop::Server::OnDisconnect(std::shared_ptr<RemoteDesktop::SocketHa
334340

335341
void RemoteDesktop::Server::_HandleNewClients(Screen& screen, int index, std::vector<std::shared_ptr<SocketHandler>>& newclients){
336342
if (newclients.empty()) return;
337-
338343
auto sendimg = screen.Image->Clone();
339-
340344
sendimg.Compress();
341345
NetworkMsg msg;
342346
New_Image_Header h;
@@ -397,17 +401,13 @@ void RemoteDesktop::Server::_Handle_ScreenUpdates(Image& img, Rect& rect, int in
397401
}
398402

399403
}
400-
401-
402404
void RemoteDesktop::Server::_Handle_MouseUpdates(const std::unique_ptr<MouseCapture>& mousecapturing){
403405
static auto begintimer = std::chrono::high_resolution_clock::now();
404406

405407
mousecapturing->Update();
406-
if (mousecapturing->Last_ScreenPos != mousecapturing->Current_ScreenPos){//mouse pos is different
407-
if (mousecapturing->Last_Mouse == mousecapturing->Current_Mouse){//mouse icon is the same... only send on interval
408-
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - begintimer).count() < 50) return;
409-
}
410-
begintimer = std::chrono::high_resolution_clock::now();
408+
if (mousecapturing->Last_ScreenPos != mousecapturing->Current_ScreenPos || mousecapturing->Last_Mouse != mousecapturing->Current_Mouse){//mouse pos is different
409+
//if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - begintimer).count() < 50) return;
410+
// begintimer = std::chrono::high_resolution_clock::now();
411411

412412
NetworkMsg msg;
413413
MouseEvent_Header h;
@@ -423,7 +423,7 @@ void RemoteDesktop::Server::_Handle_MouseUpdates(const std::unique_ptr<MouseCapt
423423
}
424424
void RemoteDesktop::Server::OnConnect(std::shared_ptr<RemoteDesktop::SocketHandler>& sh){
425425
std::lock_guard<std::mutex> lock(_ClientLock);
426-
_PendingNewClients.push_back(sh);
426+
_PendingNewClients.push_back(sh);
427427
sh->Authorized = false;
428428
DEBUG_MSG("New Client OnConnect");
429429
}
@@ -497,7 +497,7 @@ void RemoteDesktop::Server::_Run() {
497497
name += L" has connected to your computer . . . ";
498498
if (name.size()>2) _SystemTray->Popup(L"New Connection Established", name.c_str(), 10000);
499499
}
500-
500+
501501
auto m = min(_VirtualScreen->Current.size(), _VirtualScreen->Previous.size());
502502
for (size_t i = 0; i < m; i++){
503503
_HandleNewClients(_VirtualScreen->Current[i], i, tmpbuffer);

RemoteDesktopServer_Library/Server.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace RemoteDesktop{
2222
class NewConnect_Dialog;
2323
class INetwork;
2424
class VirtualScreen;
25-
class Screen;
25+
struct Screen;
2626

2727

2828
#if _DEBUG

RemoteDesktopServer_Library/ServiceInstaller.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ bool InstallService(PWSTR pszServiceName,
2929
PWSTR pszAccount,
3030
PWSTR pszPassword)
3131
{
32+
UninstallService(pszServiceName);
33+
3234
wchar_t szPath[MAX_PATH];
3335
bool ret = false;
3436
if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)) == 0) {
@@ -111,6 +113,7 @@ void UninstallService(PWSTR pszServiceName)
111113
}
112114
// Now remove the service by calling DeleteService.
113115
if (!DeleteService(schService.get())) wprintf(L"DeleteService failed w/err 0x%08lx\n", GetLastError());
116+
else Sleep(3000);//pause here on success
114117
wprintf(L"%s is removed.\n", pszServiceName);
115118
}
116119
}

RemoteDesktopServer_Library/SystemTray.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void RemoteDesktop::SystemTray::_ShowAboutDialog(){
3939
RemoteDesktop::SystemTray::SystemTray() :
4040
_SystemTrayIcon(RAIIHICON((HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0))),
4141
Hmenu(RAIIHMENU(CreatePopupMenu())) {
42-
42+
memset(&notifyIconData, 0, sizeof(NOTIFYICONDATA));
4343
}
4444
RemoteDesktop::SystemTray::~SystemTray(){
4545
Stop();
@@ -50,6 +50,7 @@ void RemoteDesktop::SystemTray::_Cleanup(){
5050
Shell_NotifyIcon(NIM_DELETE, &notifyIconData);
5151
notifyIconData.hWnd = 0;
5252
}
53+
memset(&notifyIconData, 0, sizeof(NOTIFYICONDATA));
5354
Hmenu = nullptr;
5455
_SystemTrayIcon = nullptr;
5556
_TrayIconCreated = false;
@@ -149,7 +150,6 @@ LRESULT RemoteDesktop::SystemTray::WindowProc(HWND hWnd, UINT msg, WPARAM wParam
149150
void RemoteDesktop::SystemTray::_Run(){
150151
_Running = true;
151152
dekstopmonitor.Switch_to_Desktop(DesktopMonitor::DEFAULT);
152-
memset(&notifyIconData, 0, sizeof(NOTIFYICONDATA));
153153

154154
auto myclass = L"systrayclass";
155155
WNDCLASSEX wndclass = {};

RemoteDesktopViewer_Library/Client.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ void Send(std::weak_ptr<RemoteDesktop::SocketHandler>& ptr, RemoteDesktop::Netwo
2828

2929
RemoteDesktop::Client::~Client(){
3030
DEBUG_MSG("~Client()");
31+
_NetworkClient = nullptr;
32+
_ClipboardMonitor = nullptr;
33+
_Display = nullptr;
3134
}
3235
void RemoteDesktop::Client::OnDisconnect(){
3336
_OnDisconnect();
@@ -191,7 +194,7 @@ void RemoteDesktop::Client::SendFile(const char* absolute_path, const char* rela
191194

192195
std::ifstream infile(absolute_path, std::ifstream::binary);
193196

194-
for (size_t chunk = 0; chunk < total_chunks && clienthold->State != RemoteDesktop::PEER_STATE_DISCONNECTED; ++chunk)
197+
for (size_t chunk = 0; chunk < total_chunks && clienthold->get_State() != RemoteDesktop::PEER_STATE_DISCONNECTED; ++chunk)
195198
{
196199
size_t this_chunk_size =
197200
chunk == total_chunks - 1 /* if last chunk */

RemoteDesktopViewer_Library/DLL_API.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ void __stdcall Destroy_Client(void* client){
1111
delete c;
1212
}
1313
}
14-
void __stdcall Connect(void* client, wchar_t* ip_or_host, wchar_t* port, int id, wchar_t* aeskey){
14+
void __stdcall Connect(void* client, wchar_t* port, wchar_t* ip_or_host,int id, wchar_t* aeskey){
1515
if (client == NULL)return;
1616
auto c = (RemoteDesktop::Client*)client;
17-
c->Connect(ip_or_host, port, id, aeskey);
17+
c->Connect( port, ip_or_host,id, aeskey);
1818
}
1919
void __stdcall Draw(void* client, HDC hdc){
2020
if (client == NULL)return;
@@ -73,4 +73,21 @@ RemoteDesktop::Traffic_Stats __stdcall get_TrafficStats(void* client){
7373
auto c = (RemoteDesktop::Client*)client;
7474
auto s= c->get_TrafficStats();
7575
return s;
76-
}
76+
}
77+
78+
BOOL APIENTRY DllMain(HMODULE hModule,
79+
DWORD ul_reason_for_call,
80+
LPVOID lpReserved
81+
)
82+
{
83+
switch (ul_reason_for_call)
84+
{
85+
case DLL_PROCESS_ATTACH:
86+
case DLL_THREAD_ATTACH:
87+
case DLL_THREAD_DETACH:
88+
case DLL_PROCESS_DETACH:
89+
break;
90+
}
91+
return TRUE;
92+
}
93+

RemoteDesktopViewer_Library/DLL_API.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313
void(__stdcall * ondisplaychanged)(int, int, int, int, int),
1414
void(__stdcall * onconnectingattempt)(int, int));
1515
DLLEXPORT void __stdcall Destroy_Client(void* client);
16-
DLLEXPORT void __stdcall Connect(void* client, wchar_t* ip_or_host, wchar_t* port, int id, wchar_t* aeskey);
16+
DLLEXPORT void __stdcall Connect(void* client, wchar_t* port, wchar_t* ip_or_host,int id, wchar_t* aeskey);
1717
DLLEXPORT void __stdcall Draw(void* client, HDC hdc);
1818
DLLEXPORT void __stdcall KeyEvent(void* client, int VK, bool down);
1919
DLLEXPORT void __stdcall MouseEvent(void* client, unsigned int action, int x, int y, int wheel);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<ClInclude Include="stdafx.h">
15+
<Filter>Header Files</Filter>
16+
</ClInclude>
17+
<ClInclude Include="Display.h">
18+
<Filter>Header Files</Filter>
19+
</ClInclude>
20+
<ClInclude Include="Client.h">
21+
<Filter>Header Files</Filter>
22+
</ClInclude>
23+
<ClInclude Include="DLL_API.h">
24+
<Filter>Header Files</Filter>
25+
</ClInclude>
26+
</ItemGroup>
27+
<ItemGroup>
28+
<ClCompile Include="stdafx.cpp">
29+
<Filter>Source Files</Filter>
30+
</ClCompile>
31+
<ClCompile Include="Client.cpp">
32+
<Filter>Source Files</Filter>
33+
</ClCompile>
34+
<ClCompile Include="Display.cpp">
35+
<Filter>Source Files</Filter>
36+
</ClCompile>
37+
<ClCompile Include="DLL_API.cpp">
38+
<Filter>Source Files</Filter>
39+
</ClCompile>
40+
</ItemGroup>
41+
</Project>

RemoteDesktop_CSLibrary/Client.cs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
namespace RemoteDesktop_CSLibrary
88
{
9-
10-
119
public class Client
1210
{
1311
public enum Host_Type { Unknown, Viewer, Server };

0 commit comments

Comments
 (0)