From 4e8f61dd8ecc8463e2642c3b166fd4d46d85f1f7 Mon Sep 17 00:00:00 2001 From: smasherprog Date: Thu, 5 May 2016 20:40:02 -0700 Subject: [PATCH] Updated typescript and mouse server code Fixed Mouse not displaying in web viewer Updated Mouse struct to account for padding added by compiler. --- Core/ApplicationDirectory.cpp | 1 - Core/Core.vcxitems | 1 + Core/Core.vcxitems.filters | 4 +++- Core/HttpHeader.cpp | 3 +-- Core/Mouse.h | 4 ++-- Core/Server.cpp | 4 ++-- Core/ServerNetworkDriver.cpp | 4 ++-- Core/SocketImpl.cpp | 2 -- wwwroot/Core.js | 17 +++++++---------- wwwroot/Core.ts | 19 +++++++------------ 10 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Core/ApplicationDirectory.cpp b/Core/ApplicationDirectory.cpp index 695d37e4..38978e49 100644 --- a/Core/ApplicationDirectory.cpp +++ b/Core/ApplicationDirectory.cpp @@ -8,7 +8,6 @@ std::string executable_path(const char *argv0) } #else - #include #include #include diff --git a/Core/Core.vcxitems b/Core/Core.vcxitems index c17e75ab..a5d81c25 100644 --- a/Core/Core.vcxitems +++ b/Core/Core.vcxitems @@ -112,6 +112,7 @@ tsc $(SolutionDir)wwwroot\Core.ts $(OutDir)wwwroot\Core.js true + false diff --git a/Core/Core.vcxitems.filters b/Core/Core.vcxitems.filters index d55edf80..cbc9aa50 100644 --- a/Core/Core.vcxitems.filters +++ b/Core/Core.vcxitems.filters @@ -234,6 +234,8 @@ wwwroot - + + wwwroot + \ No newline at end of file diff --git a/Core/HttpHeader.cpp b/Core/HttpHeader.cpp index 3eb17b27..9eb86c2c 100644 --- a/Core/HttpHeader.cpp +++ b/Core/HttpHeader.cpp @@ -14,7 +14,6 @@ namespace SL { { if (in[i] == '%') { - if (i + 3 <= in.size()) { int value = 0; @@ -26,7 +25,6 @@ namespace SL { } else { - return std::string("/"); } } @@ -51,6 +49,7 @@ namespace SL { } } + std::unordered_map SL::Remote_Access_Library::Network::HttpHeader::Parse(std::string defaultheaderversion, std::istream& stream) { std::unordered_map header; diff --git a/Core/Mouse.h b/Core/Mouse.h index 9f37d33d..3517f928 100644 --- a/Core/Mouse.h +++ b/Core/Mouse.h @@ -6,14 +6,14 @@ namespace SL { namespace Remote_Access_Library { namespace Input { - enum MouseEvents : unsigned char { + enum MouseEvents : unsigned int { LEFT, RIGHT, MIDDLE, SCROLL, NO_EVENTDATA }; - enum MousePress : unsigned char { + enum MousePress : unsigned int { UP, DOWN, NO_PRESS_DATA diff --git a/Core/Server.cpp b/Core/Server.cpp index 109f7809..1459aa14 100644 --- a/Core/Server.cpp +++ b/Core/Server.cpp @@ -76,6 +76,8 @@ namespace SL { } LastScreen = img;//swap } + + void OnMouseImg(std::shared_ptr img) { if (!LastMouse) { @@ -112,12 +114,10 @@ namespace SL { } } } - Server_Status get_Status() const { return Status; } }; - } } diff --git a/Core/ServerNetworkDriver.cpp b/Core/ServerNetworkDriver.cpp index 723ff610..b355ec3b 100644 --- a/Core/ServerNetworkDriver.cpp +++ b/Core/ServerNetworkDriver.cpp @@ -35,7 +35,7 @@ namespace SL { void MouseEvent(const std::shared_ptr& socket, std::shared_ptr& p) { - assert(p->Payload_Length == sizeof(Input::MouseEvent::EventData) + sizeof(Input::MouseEvent::Pos) + sizeof(Input::MouseEvent::ScrollDelta) + sizeof(Input::MouseEvent::PressData)); + assert(p->Payload_Length == sizeof(Input::MouseEvent)); _IServerDriver->OnMouse((Input::MouseEvent*) p->Payload); } public: @@ -53,7 +53,7 @@ namespace SL { virtual void OnClose(const std::shared_ptr& socket)override { _IServerDriver->OnClose(socket); std::lock_guard lock(_ClientsLock); - _Clients.erase(std::remove_if(begin(_Clients), end(_Clients), [socket](const std::shared_ptr& p) { return p == socket; }), _Clients.end()); + _Clients.erase(std::remove_if(begin(_Clients), end(_Clients), [&socket](const std::shared_ptr& p) { return p == socket; }), _Clients.end()); } virtual void OnReceive(const std::shared_ptr& socket, std::shared_ptr& p) override diff --git a/Core/SocketImpl.cpp b/Core/SocketImpl.cpp index feae1846..725c773f 100644 --- a/Core/SocketImpl.cpp +++ b/Core/SocketImpl.cpp @@ -39,8 +39,6 @@ SL::Remote_Access_Library::Network::SocketStats SL::Remote_Access_Library::Netwo { return _SocketStats; } - - char* SL::Remote_Access_Library::Network::SocketImpl::get_ReadBuffer() { _IncomingBuffer.reserve(ReadPacketHeader.Payload_Length); diff --git a/wwwroot/Core.js b/wwwroot/Core.js index e920218b..d49926a1 100644 --- a/wwwroot/Core.js +++ b/wwwroot/Core.js @@ -79,17 +79,14 @@ var SL; this.PressData = PressData; } MouseEvent.sizeof = function () { - return 1 + Utilities.Point.sizeof() + 4 + 1; + return 4 + Utilities.Point.sizeof() + 4 + 4; }; MouseEvent.prototype.Fill = function (d, offset) { var dt = new DataView(d, offset); - dt.setUint8(0, this.EventData); - - this.Pos.Fill(d, offset + 1); - - dt.setInt32(offset + 1 + Utilities.Point.sizeof(), this.ScrollDelta, true); - - dt.setUint8(offset + 1 + Utilities.Point.sizeof() + 4, this.PressData); + dt.setUint32(0, this.EventData, true); + this.Pos.Fill(d, offset + 4); + dt.setInt32(offset + 4 + Utilities.Point.sizeof(), this.ScrollDelta, true); + dt.setUint32(offset + 4 + Utilities.Point.sizeof() + 4, this.PressData, true); }; return MouseEvent; })(); @@ -160,7 +157,7 @@ var SL; _this._HTMLCanvasScreenImage.style.left = _this._HTMLCanvasScreenImage.style.top = _this._HTMLCanvasScreenImage.style.zIndex = '0'; _this._HTMLCanvasMouseImage = document.createElement('canvas'); - + _this._HTMLCanvasMouseImage.style.position = 'absolute'; _this._HTMLCanvasMouseImage.style.left = _this._HTMLCanvasMouseImage.style.top = '0'; _this._HTMLCanvasMouseImage.style.zIndex = '1'; @@ -446,7 +443,7 @@ var SL; _this._IClientDriver.OnReceive_ImageDif(_this._Socket, Utilities.Rect.FromArray(data), _this._arrayBufferToBase64(data, Utilities.Rect.sizeof())); }; this.MouseImage = function (data) { - _this._IClientDriver.OnReceive_MouseImage(_this._Socket, Utilities.Point.FromArray(data), new Uint8Array(data.buffer, Utilities.Point.sizeof())); + _this._IClientDriver.OnReceive_MouseImage(_this._Socket, Utilities.Point.FromArray(data), new Uint8Array(data.slice(Utilities.Point.sizeof()).buffer)); }; this.MousePos = function (data) { _this._IClientDriver.OnReceive_MousePos(_this._Socket, Utilities.Point.FromArray(data)); diff --git a/wwwroot/Core.ts b/wwwroot/Core.ts index 25aa2b4a..38e9e166 100644 --- a/wwwroot/Core.ts +++ b/wwwroot/Core.ts @@ -52,17 +52,13 @@ module SL { public ScrollDelta = 0, public PressData = MousePress.NO_PRESS_DATA) { } - static sizeof() { return 1 + Utilities.Point.sizeof() + 4 + 1; }//actual bytes used + static sizeof() { return 4 + Utilities.Point.sizeof() + 4 + 4; }//actual bytes used Fill(d: ArrayBuffer, offset: number): void { - var dt = new DataView(d, offset); - dt.setUint8(0, this.EventData); - - this.Pos.Fill(d, offset + 1); - - dt.setInt32(offset + 1 + Utilities.Point.sizeof(), this.ScrollDelta, true); - - dt.setUint8(offset + 1 + Utilities.Point.sizeof() + 4, this.PressData); + dt.setUint32(0, this.EventData, true); + this.Pos.Fill(d, offset + 4); + dt.setInt32(offset + 4 + Utilities.Point.sizeof(), this.ScrollDelta, true); + dt.setUint32(offset + 4 + Utilities.Point.sizeof() + 4, this.PressData, true); } }; @@ -137,7 +133,7 @@ module SL { this._HTMLCanvasScreenImage.style.left = this._HTMLCanvasScreenImage.style.top = this._HTMLCanvasScreenImage.style.zIndex = '0'; this._HTMLCanvasMouseImage = document.createElement('canvas'); - + this._HTMLCanvasMouseImage.style.position = 'absolute'; this._HTMLCanvasMouseImage.style.left = this._HTMLCanvasMouseImage.style.top = '0'; this._HTMLCanvasMouseImage.style.zIndex = '1'; @@ -436,8 +432,7 @@ module SL { this._arrayBufferToBase64(data, Utilities.Rect.sizeof())); } MouseImage = (data: Uint8Array): void => { - - this._IClientDriver.OnReceive_MouseImage(this._Socket, Utilities.Point.FromArray(data), new Uint8Array(data.buffer, Utilities.Point.sizeof())); + this._IClientDriver.OnReceive_MouseImage(this._Socket, Utilities.Point.FromArray(data), new Uint8Array(data.slice(Utilities.Point.sizeof()).buffer)); } MousePos = (data: Uint8Array): void => { this._IClientDriver.OnReceive_MousePos(this._Socket, Utilities.Point.FromArray(data));