Skip to content

Commit 082133d

Browse files
authored
Merge pull request #53 from smasherprog/Development
Merging for .v35 release
2 parents 85bf1a8 + c7c5ba2 commit 082133d

File tree

200 files changed

+10119
-30097
lines changed

Some content is hidden

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

200 files changed

+10119
-30097
lines changed

Diff for: .build-debug/Core

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stam

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ bld/
2424
[Jj]ni[Ll]ibs/
2525
.vs/
2626
.codelite/
27+
.build-*/
2728
*.tlog
28-
.vs/
2929
# Roslyn cache directories
3030
*.ide/
3131

@@ -69,6 +69,8 @@ dlldata.c
6969
*.pidb
7070
*.svclog
7171
*.scc
72+
*.mk
73+
*.txt
7274

7375
# Chutzpah Test files
7476
_Chutzpah*

Diff for: Core/ApplicationDirectory.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ std::string executable_path_fallback(const char *argv0)
2929
return p.make_preferred().string();
3030
}
3131

32-
#if (_WIN32) // {
32+
#if (_WIN32)
3333

3434
# include <Windows.h>
3535

@@ -70,7 +70,7 @@ std::string executable_path(const char *argv0)
7070
# error "Unknown Apple platform"
7171
#endif
7272

73-
#elif (__linux__) // } {
73+
#elif (__linux__)
7474

7575
# include <unistd.h>
7676

@@ -90,13 +90,13 @@ std::string executable_path(const char *argv0)
9090
return p.make_preferred().string();
9191
}
9292

93-
#else // } {
93+
#else
9494

9595
std::string executable_path(const char *argv0)
9696
{
9797
return executable_path_fallback(argv0);
9898
}
9999

100-
#endif // }
100+
#endif
101101

102102
#endif

Diff for: Core/ClientNetworkDriver.cpp

+55-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "stdafx.h"
22
#include "ClientNetworkDriver.h"
3-
#include "WebSocket.h"
3+
#include "Socket.h"
44
#include "Shapes.h"
55
#include "IClientDriver.h"
66
#include "Image.h"
@@ -9,8 +9,8 @@
99
#include "Mouse.h"
1010
#include "Logging.h"
1111
#include "Keyboard.h"
12-
#include "ISocket.h"
1312
#include "Client_Config.h"
13+
#include "ISocket.h"
1414

1515
#include <assert.h>
1616

@@ -24,21 +24,19 @@ namespace SL {
2424
std::shared_ptr<Network::Client_Config> _Config;
2525
std::shared_ptr<Network::ISocket> _Socket;
2626
std::string _dst_host;
27-
28-
bool _ConectedToSelf;
29-
30-
31-
void MouseImage(const std::shared_ptr<ISocket>& socket, std::shared_ptr<Packet>& p) {
27+
Utilities::Point _LastMousePosition;
28+
29+
void MouseImage(std::shared_ptr<Packet>& p) {
3230
auto imgsize = (Utilities::Point*)p->Payload;
3331
auto img(Utilities::Image::CreateImage(imgsize->Y, imgsize->X, p->Payload + sizeof(Utilities::Rect), 4));
34-
_IClientDriver->OnReceive_MouseImage(socket, img);
32+
_IClientDriver->OnReceive_MouseImage(img);
3533
}
3634

37-
void MousePos(const std::shared_ptr<ISocket>& socket, std::shared_ptr<Packet>& p) {
35+
void MousePos(std::shared_ptr<Packet>& p) {
3836
assert(p->Payload_Length == sizeof(Utilities::Point));
39-
_IClientDriver->OnReceive_MousePos(socket, (Utilities::Point*)p->Payload);
37+
_IClientDriver->OnReceive_MousePos((Utilities::Point*)p->Payload);
4038
}
41-
void ImageDif(const std::shared_ptr<ISocket>& socket, std::shared_ptr<Packet>& p) {
39+
void ScreenImageDif(std::shared_ptr<Packet>& p) {
4240
auto imgrect = (Utilities::Rect*)p->Payload;
4341
auto compfree = [](void* handle) {tjDestroy(handle); };
4442
auto _jpegDecompressor(std::unique_ptr<void, decltype(compfree)>(tjInitDecompress(), compfree));
@@ -54,10 +52,10 @@ namespace SL {
5452
if (tjDecompress2(_jpegDecompressor.get(), src, static_cast<unsigned long>(p->Payload_Length - sizeof(Utilities::Rect)), (unsigned char*)img->data(), outwidth, 0, outheight, TJPF_RGBX, TJFLAG_FASTDCT | TJFLAG_NOREALLOC) == -1) {
5553
SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, tjGetErrorStr());
5654
}
57-
_IClientDriver->OnReceive_ImageDif(socket, imgrect->Origin, img);
55+
_IClientDriver->OnReceive_ImageDif(imgrect->Origin, img);
5856

5957
}
60-
void Image(const std::shared_ptr<ISocket>& socket, std::shared_ptr<Packet>& p) {
58+
void ScreenImage(std::shared_ptr<Packet>& p) {
6159

6260
auto compfree = [](void* handle) {tjDestroy(handle); };
6361
auto _jpegDecompressor(std::unique_ptr<void, decltype(compfree)>(tjInitDecompress(), compfree));
@@ -72,26 +70,32 @@ namespace SL {
7270
if (tjDecompress2(_jpegDecompressor.get(), src, static_cast<unsigned long>(p->Payload_Length - sizeof(Utilities::Rect)), (unsigned char*)img->data(), outwidth, 0, outheight, TJPF_RGBX, TJFLAG_FASTDCT | TJFLAG_NOREALLOC) == -1) {
7371
SL_RAT_LOG(Utilities::Logging_Levels::ERROR_log_level, tjGetErrorStr());
7472
}
75-
_IClientDriver->OnReceive_Image(socket, img);
73+
_IClientDriver->OnReceive_Image(img);
7674

7775
}
78-
76+
void ClipboardTextEvent(std::shared_ptr<Packet>& p) {
77+
78+
_IClientDriver->OnReceive_ClipboardText(p->Payload, p->Payload_Length);
79+
}
80+
7981
public:
8082
ClientNetworkDriverImpl(IClientDriver* r, std::shared_ptr<Network::Client_Config> config, const char * dst_host) :
81-
_IClientDriver(r), _Config(config), _dst_host(dst_host), _ConectedToSelf(false){
82-
83+
_IClientDriver(r), _Config(config), _dst_host(dst_host){
84+
memset(&_LastMousePosition, 0, sizeof(_LastMousePosition));
8385
}
8486

8587
void Start() {
8688
Stop();
87-
WebSocket::Connect(_Config.get(), this, _dst_host.c_str());
88-
_ConectedToSelf = (std::string("127.0.0.1") == _dst_host) || (std::string("localhost") == _dst_host) || (std::string("::1") == _dst_host);
89+
Connect(_Config.get(), this, _dst_host.c_str());
90+
8991

9092
}
9193

9294
void Stop() {
93-
if (_Socket) _Socket->close("Stopping Listener");
94-
_Socket.reset();//decrement count
95+
if (_Socket) {
96+
_Socket->close("Stopping Listener");
97+
_Socket.reset();//decrement count
98+
}
9599
}
96100
virtual ~ClientNetworkDriverImpl() {
97101
Stop();
@@ -112,16 +116,19 @@ namespace SL {
112116

113117
switch (p->Packet_Type) {
114118
case static_cast<unsigned int>(PACKET_TYPES::SCREENIMAGE) :
115-
Image(socket, p);
119+
ScreenImage(p);
116120
break;
117121
case static_cast<unsigned int>(PACKET_TYPES::SCREENIMAGEDIF) :
118-
ImageDif(socket, p);
122+
ScreenImageDif(p);
119123
break;
120124
case static_cast<unsigned int>(PACKET_TYPES::MOUSEIMAGE) :
121-
MouseImage(socket, p);
125+
MouseImage(p);
122126
break;
123127
case static_cast<unsigned int>(PACKET_TYPES::MOUSEPOS) :
124-
MousePos(socket, p);
128+
MousePos(p);
129+
break;
130+
case static_cast<unsigned int>(PACKET_TYPES::CLIPBOARDTEXTEVENT) :
131+
ClipboardTextEvent(p);
125132
break;
126133
default:
127134
_IClientDriver->OnReceive(socket, p);//pass up the chain
@@ -134,6 +141,12 @@ namespace SL {
134141
SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level, "SendMouse called on a socket that is not open yet");
135142
return;
136143
}
144+
if (_Socket->is_loopback()) return;//dont send mouse info to ourselfs as this will cause a loop
145+
//do checks to prevent sending redundant mouse information about its position
146+
if (m.EventData == Input::Mouse::NO_EVENTDATA && _LastMousePosition == m.Pos && m.PressData == Input::Mouse::NO_PRESS_DATA && m.ScrollDelta == 0) {
147+
return;//already did this event
148+
}
149+
_LastMousePosition = m.Pos;
137150
Packet p(static_cast<unsigned int>(PACKET_TYPES::MOUSEEVENT), sizeof(m));
138151
memcpy(p.Payload, &m, sizeof(m));
139152
_Socket->send(p);
@@ -147,9 +160,18 @@ namespace SL {
147160
memcpy(p.Payload, &m, sizeof(m));
148161
_Socket->send(p);
149162
}
150-
bool ConnectedToSelf() const {
151-
return _ConectedToSelf;
163+
void SendClipboardText(const char* data, unsigned int len) {
164+
if (!_Socket) {
165+
SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level, "SendKey called on a socket that is not open yet");
166+
return;
167+
}
168+
if (_Socket->is_loopback()) return;//dont send clipboard info to ourselfs as it will cause a loop
169+
Packet p(static_cast<unsigned int>(PACKET_TYPES::CLIPBOARDTEXTEVENT), len, (char*)data, false);
170+
_Socket->send(p);
152171
}
172+
std::shared_ptr<ISocket> get_Socket()const{
173+
return _Socket;
174+
}
153175
};
154176
}
155177
}
@@ -187,6 +209,10 @@ void SL::Remote_Access_Library::Network::ClientNetworkDriver::SendMouse(const In
187209
_ClientNetworkDriverImpl->SendMouse(m);
188210
}
189211

190-
bool SL::Remote_Access_Library::Network::ClientNetworkDriver::ConnectedToSelf() const {
191-
return _ClientNetworkDriverImpl->ConnectedToSelf();
212+
std::shared_ptr<SL::Remote_Access_Library::Network::ISocket> SL::Remote_Access_Library::Network::ClientNetworkDriver::get_Socket()const{
213+
return _ClientNetworkDriverImpl->get_Socket();
214+
}
215+
216+
void SL::Remote_Access_Library::Network::ClientNetworkDriver::SendClipboardText(const char* data, unsigned int len) {
217+
return _ClientNetworkDriverImpl->SendClipboardText(data, len);
192218
}

Diff for: Core/ClientNetworkDriver.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ namespace SL {
2727

2828
void SendKey(const Input::KeyEvent& m);
2929
void SendMouse(const Input::MouseEvent& m);
30-
bool ConnectedToSelf() const;
30+
void SendClipboardText(const char* data, unsigned int len);
31+
32+
std::shared_ptr<ISocket> get_Socket()const;
33+
3134
};
3235
}
3336
}

Diff for: Core/Client_Config.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace SL {
1515
unsigned short WebSocketTLSLPort = 6001;
1616
unsigned int Read_Timeout = 5;//in seconds
1717
unsigned int Write_Timeout = 5;//in seconds
18+
bool Share_Clipboard = true;//share your clipboard?
19+
bool Scale_Image = false;
1820

1921
std::string Password;//this is the password to connect to the endpoint or that the server requrires before allowing the connection
2022

Diff for: Core/Clipboard.cpp

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include "stdafx.h"
2+
#include "Clipboard.h"
3+
#include "Logging.h"
4+
5+
#include <FL/Fl.H>
6+
#include <FL/Fl_Widget.H>
7+
8+
#include <mutex>
9+
#include <vector>
10+
11+
namespace SL {
12+
namespace Remote_Access_Library {
13+
namespace Capturing {
14+
class ClipboardImpl : public Fl_Widget {
15+
public:
16+
const bool* Is_ClipboardShared;
17+
std::function<void(const char*, int)> OnChange;
18+
//contention on this mutex is low.. no need to try an optimize
19+
std::mutex LastClipDataLock;
20+
std::vector<char> LastClipData;
21+
ClipboardImpl(const bool* is_clipshared, std::function<void(const char*, int)>&& onchange) : Fl_Widget(0, 0, 0, 0), Is_ClipboardShared(is_clipshared), OnChange(std::move(onchange)) {
22+
Fl::add_clipboard_notify(clip_callback, this);
23+
}
24+
virtual ~ClipboardImpl() {
25+
Fl::remove_clipboard_notify(clip_callback);
26+
}
27+
virtual void draw() override {}//do nothing
28+
virtual int handle(int event) override {
29+
if (event == FL_PASTE) {
30+
31+
if (strcmp(Fl::event_clipboard_type(), Fl::clipboard_image) == 0) { // an image is being pasted
32+
//To Be implemeneted...... Probably not though because images can be large and seems like its an edge case any way
33+
}
34+
else {//text is being pasted
35+
bool emitclipevent = false;
36+
auto data = Fl::event_text();
37+
auto len = Fl::event_length();
38+
{
39+
std::lock_guard<std::mutex> lock(LastClipDataLock);
40+
emitclipevent = !is_datasame(data, len);
41+
if (emitclipevent) UpdateBuffer(data, len);
42+
}
43+
if (emitclipevent) {
44+
OnChange(data, len);
45+
}
46+
47+
}
48+
49+
}
50+
return 1;
51+
}
52+
53+
static void clip_callback(int source, void *data) {
54+
auto p = (ClipboardImpl*)data;
55+
56+
if (source == 1 && *(p->Is_ClipboardShared)) {
57+
SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level, "Clipboard Changed!");
58+
if (Fl::clipboard_contains(Fl::clipboard_plain_text)) {
59+
SL_RAT_LOG(Utilities::Logging_Levels::INFO_log_level, "Contains plain text");
60+
Fl::paste(*p, 1, Fl::clipboard_plain_text);
61+
}
62+
}
63+
}
64+
//caller should lock the mutex to prevent races
65+
bool is_datasame(const char* data, int len) {
66+
auto size = static_cast<size_t>(len);
67+
if (size != LastClipData.size()) return false;
68+
if (memcmp(LastClipData.data(), data, size) == 0) return true;
69+
return false;
70+
}
71+
//caller should lock the mutex to prevent races
72+
void UpdateBuffer(const char* data, int len) {
73+
auto size = static_cast<size_t>(len);
74+
LastClipData.resize(size);
75+
memcpy(LastClipData.data(), data, size);
76+
}
77+
void copy_to_clipboard(const char* data, int len) {
78+
bool updateclipboard = false;
79+
{
80+
std::lock_guard<std::mutex> lock(LastClipDataLock);
81+
updateclipboard = !is_datasame(data, len);
82+
if (updateclipboard) UpdateBuffer(data, len);
83+
}
84+
if (updateclipboard) Fl::copy(data, static_cast<int>(len), 1);
85+
}
86+
};
87+
}
88+
}
89+
}
90+
SL::Remote_Access_Library::Capturing::Clipboard::Clipboard(const bool* is_clipshared, std::function<void(const char*, int)>&& onchange)
91+
{
92+
_ClipboardImpl = new ClipboardImpl(is_clipshared, std::forward<std::function<void(const char*, int)>>(onchange));
93+
}
94+
95+
SL::Remote_Access_Library::Capturing::Clipboard::~Clipboard()
96+
{
97+
delete _ClipboardImpl;
98+
}
99+
void SL::Remote_Access_Library::Capturing::Clipboard::copy_to_clipboard(const char* data, int len) {
100+
_ClipboardImpl->copy_to_clipboard(data, len);
101+
}

Diff for: Core/Clipboard.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
#include <functional>
3+
4+
5+
namespace SL {
6+
namespace Remote_Access_Library {
7+
namespace Capturing {
8+
class ClipboardImpl;
9+
class Clipboard {
10+
ClipboardImpl* _ClipboardImpl = nullptr;
11+
public:
12+
//user must guarantee that is_clipshared is valid for the lifetime of this clipboard object!
13+
Clipboard(const bool* is_clipshared, std::function<void(const char*, int)>&& onchange);
14+
~Clipboard();
15+
void copy_to_clipboard(const char* data, int len);
16+
};
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)