📄 clientconnection.h
字号:
// Copyright (C) 2002 Ultr@VNC Team Members. All Rights Reserved.
// Copyright (C) 2000-2002 Const Kaplinsky. All Rights Reserved.
//
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
// This file is part of TeamViewer.
//
// TeamViewer is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
// If the source code for TeamViewer is not available from the place
// whence you received this file, check http://www.teamviewer.com
// for information on obtaining it.
#ifndef CLIENTCONNECTION_H__
#define CLIENTCONNECTION_H__
#pragma once
#include "VNCOptions.h"
class ClientConnection;
#include "VNCviewerApp.h"
#include "KeyMap.h"
#include "..\winvnc\winvnc\vncserver.h"
#include "..\winvnc\winvnc\roGateway.h"
#include "AuthDialog.h"
extern "C"
{
#include "libjpeg/jpeglib.h" // For Tight encoding
}
#include "FileTransfer.h" // sf@2002
#include "TextChatViewer.h" // sf@2002
#include "MRU.h"
//#include "FullScreenTitleBar.h" //Added by: Lars Werner (http://lars.werner.no)
extern const UINT FileTransferSendPacketMessage;
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#define SETTINGS_KEY_NAME "Software\\TeamViewer\\Settings"
#define MAX_HOST_NAME_LEN 250
#define ZLIBHEX_DECOMP_UNINITED (-1)
#define BZIP2HEX_DECOMP_UNINITED (-1)
// Messages used by VNCon - Copyright (C) 2001-2003 - Alastair Burr
#define WM_SETSCALING WM_USER+101
#define WM_SETVIEWONLY WM_USER+102
#define WM_GETSCALING WM_USER+103
////// Staudenmeyer
#define WM_CLOSE_AFTER_EXCEPTION WM_USER+104
//////
// 30 = 2*3*5, high probability to get a high value when calculating gcd(m_opts.m_scale_num, AUTOSCALE_GRANULARITY)
// which will result in a small value of m_opts.m_scale_den
#define AUTOSCALE_GRANULARITY 30
enum ConnectionType { CC_OUTGOING_INTERNET = 1, CC_OUTGOING_LAN, CC_ENDDIALOG };
// Lizard - stall avoidance
//class MousePointerMotionDelayThread : public omni_thread
//{
// public:
// //~MousePointerMotionDelayThread(void);
//
// virtual void *run_undetached(void *arg);
// void Init(void *c);
// void MouseEvent(int x, int y, int buttonMask);
//
// bool Running() { return m_running; }
// void set_Running(bool b) {m_running = b;}
// void set_EnableSend(bool b) { m_enablesend = b; }
//
// protected:
// void send();
// void *m_ClientConnection;
// int m_pointerX, m_pointerY, m_buttonMask, m_lastpointerX, m_lastpointerY, m_lastbuttonMask;
// BOOL m_running;
// BOOL m_enablesend;
//};
// End Lizard
#define TIGHT_ZLIB_BUFFER_SIZE 512 // Tight encoding
class ClientConnection;
typedef void (ClientConnection:: *tightFilterFunc)(int);
struct myVbool {
bool b0 : 1;
bool b1 : 1;
bool b2 : 1;
bool b3 : 1;
bool b4 : 1;
bool b5 : 1;
bool b6 : 1;
bool b7 : 1;
};
struct BitmapInfo {
BITMAPINFOHEADER bmiHeader;
union {
struct {
DWORD red;
DWORD green;
DWORD blue;
} mask;
RGBQUAD color[256];
};
};
namespace rdr { class InStream; class FdInStream; class ZlibInStream; }
class CroGateway; // forward declaration
class TeamviewerInfo;
typedef BOOL (__stdcall *AlphaBlendFn) (
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of upper-left corner
int nYOriginDest, // y-coord of upper-left corner
int nWidthDest, // destination width
int nHeightDest, // destination height
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of upper-left corner
int nYOriginSrc, // y-coord of upper-left corner
int nWidthSrc, // source width
int nHeightSrc, // source height
BLENDFUNCTION blendFunction // alpha-blending function
);
const int EXCEPTION_WARNING = 1;
const int EXCEPTION_QUITE = 2;
const int EXCEPTION_REGULAR = 3;
class ClientConnection : public omni_thread
{
public:
HWND m_hSessionDialog;
int m_port;
vncServer *m_server;
//TR@2003: roGateway
bool m_roGateway; // are we using the roGateway?
CroGateway *roGateway;
TeamviewerInfo *m_tvinfo;
bool saved_set;
TCHAR m_host[MAX_HOST_NAME_LEN];
AuthDialog ad;
void AbortConnection();
int LoadConnection(char *fname, bool fFromDialog);
void CreateButtons();
ClientConnection(VNCviewerApp *pApp, ConnectionType ct);
ClientConnection(VNCviewerApp *pApp, SOCKET sock, int connectionmode = 0);
ClientConnection(VNCviewerApp *pApp, LPTSTR host, int port);
ClientConnection(VNCviewerApp *pApp, LPTSTR configFile);
virtual ~ClientConnection();
int Run(bool internet=false);
void KillThread();
// Exceptions
class UserCancelExc {};
class AuthenticationExc {};
class SocketExc {};
class ProtocolExc {};
class Fatal {};
HANDLE KillEvent;
bool IsDormant(){ return m_dormant;};
ConnectionType GetConnectionType() { return m_ConnectionType; }
// Lizard - stall avoidance
friend class MousePointerMotionDelayThread;
void ReadExact(char *buf, int bytes);
void WriteExact(char *buf, int bytes);
protected:
void ExternalSendPointerEvent(int x, int y, int buttonMask);
// End Lizard
private:
static LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK WndProcTBwin(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK WndProchwnd(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
void DoBlit();
VNCviewerApp *m_pApp;
SOCKET m_sock;
bool m_serverInitiated;
public:
HWND m_hwnd, m_hbands,m_hwndTB,m_hwndTBwin,m_hwndMain;
HIMAGELIST m_hTBImageList; // image list
HIMAGELIST m_hTBHottrack; // image list
int m_borderWidth;
int m_borderHeight;
int borderWidth() { return m_borderWidth; }
int borderHeight() { return m_borderHeight; };
bool m_sizing;
RECT m_last_autoscale;
//contains the last time difference of a viewer session in miliseconds
long m_lConnectionTime;
/*getConnectionTime returns the time amount of the last viewer session.
@param(hours Hours will contain how many hours the user used the connection)
@param(minutes Minutes will contain how many minutes the user used the connection)
@param(seconds Seconds will contain how many seconds the user used the connection)
*/
void getConnectionTime(int &hours, int &minutes, int &seconds);
SYSTEMTIME connectionLogStartTime;
string connectionLogUser;
FileTransfer *m_pFileTransfer; // Modif sf@2002 - FileTransfer
int m_lastServermode; // is set after modechange from servermode to clientmode
private:
bool logConnection;
bool m_send_incremental;
bool m_WaitForFullUpdate;
HANDLE m_statusThread;
// bool m_ToolbarEnable;
bool m_SWselect;
POINT m_SWpoint;
HCURSOR hNewCursor;
HCURSOR hOldCursor;
BOOL skipprompt2;
void Init(VNCviewerApp *pApp);
void CreateDisplay();
void CreateToolbar();
bool Connect();
bool m_abort_connection;
void SetSocketOptions();
void Authenticate();
void NegotiateProtocolVersion();
void ReadServerInit();
void SendClientInit();
void CreateLocalFramebuffer();
void SetupPixelFormat();
void SetFormatAndEncodings();
void SendSetPixelFormat(rfbPixelFormat newFormat);
void SendIncrementalFramebufferUpdateRequest();
void SendFullFramebufferUpdateRequest();
void SendAppropriateFramebufferUpdateRequest();
void SendFramebufferUpdateRequest(int x, int y, int w, int h, bool incremental);
// TR@2004
//switch to server mode
bool SwitchToServermode();
//sends a new mode to the other side
void SendModeChangeRequest(int newmode);
void ProcessPointerEvent(int x, int y, DWORD keyflags, UINT msg);
void SubProcessPointerEvent(int x, int y, DWORD keyflags);
void ProcessMouseWheel(int delta); // RealVNC 335 method
void SendPointerEvent(int x, int y, int buttonMask);
void ProcessKeyEvent(int virtkey, DWORD keyData);
void SendKeyEvent(CARD32 key, bool down);
void ReadScreenUpdate();
void Update(RECT *pRect);
void SizeWindow();
void BeginAutoScaling();
void AutoScale();
void StopAutoScaling();
void CenterMainWindow();
void AdjustScrollbars();
bool ScrollScreen(int dx, int dy);
void UpdateScrollbars();
void ReadRawRect(rfbFramebufferUpdateRectHeader *pfburh);
void ReadUltraRect(rfbFramebufferUpdateRectHeader *pfburh);
void ReadUltraZip(rfbFramebufferUpdateRectHeader *pfburh,HRGN *prgn);
void ReadCopyRect(rfbFramebufferUpdateRectHeader *pfburh);
void ReadRRERect(rfbFramebufferUpdateRectHeader *pfburh);
void ReadCoRRERect(rfbFramebufferUpdateRectHeader *pfburh);
void ReadHextileRect(rfbFramebufferUpdateRectHeader *pfburh);
void ReadZlibRect(rfbFramebufferUpdateRectHeader *pfburh,int XOR);
void ReadSolidRect(rfbFramebufferUpdateRectHeader *pfburh);
void HandleHextileEncoding8(int x, int y, int w, int h);
void HandleHextileEncoding16(int x, int y, int w, int h);
void HandleHextileEncoding32(int x, int y, int w, int h);
void ReadRBSRect(rfbFramebufferUpdateRectHeader *pfburh);
BOOL DrawRBSRect8(int x, int y, int w, int h, CARD8 **pptr);
BOOL DrawRBSRect16(int x, int y, int w, int h, CARD8 **pptr);
BOOL DrawRBSRect32(int x, int y, int w, int h, CARD8 **pptr);
// ClientConnectionFullScreen.cpp
void ToggleFullScreen();
void SetFullScreenMode(bool enable);
bool InFullScreenMode();
void RealiseFullScreenMode();
bool BumpScroll(int x, int y);
//CTitleBar TitleBar; //Added by: Lars Werner (http://lars.werner.no)
//SINGLE WINDOW
void ReadNewFBSize(rfbFramebufferUpdateRectHeader *pfburh);
// Caching
void SaveArea(RECT &r);
void CleanCache(RECT &r);
void RestoreArea(RECT &r);
void ReadCacheRect(rfbFramebufferUpdateRectHeader *pfburh);
void ClearCache();
void ReadCacheZip(rfbFramebufferUpdateRectHeader *pfburh,HRGN *prgn);
void ReadSolMonoZip(rfbFramebufferUpdateRectHeader *pfburh,HRGN *prgn);
// ClientConnectionTight.cpp
void ReadTightRect(rfbFramebufferUpdateRectHeader *pfburh);
int ReadCompactLen();
int InitFilterCopy (int rw, int rh);
int InitFilterGradient (int rw, int rh);
int InitFilterPalette (int rw, int rh);
void FilterCopy8 (int numRows);
void FilterCopy16 (int numRows);
void FilterCopy24 (int numRows);
void FilterCopy32 (int numRows);
void FilterGradient8 (int numRows);
void FilterGradient16 (int numRows);
void FilterGradient24 (int numRows);
void FilterGradient32 (int numRows);
void FilterPalette (int numRows);
void DecompressJpegRect(int x, int y, int w, int h);
// Tight ClientConnectionCursor.cpp
bool prevCursorSet;
HDC m_hSavedAreaDC;
HBITMAP m_hSavedAreaBitmap;
COLORREF *rcSource;
bool *rcMask;
int rcHotX, rcHotY, rcWidth, rcHeight;
int rcCursorX, rcCursorY;
int rcLockX, rcLockY, rcLockWidth, rcLockHeight;
bool rcCursorHidden, rcLockSet;
void ReadCursorShape(rfbFramebufferUpdateRectHeader *pfburh);
void SoftCursorLockArea(int x, int y, int w, int h);
void SoftCursorUnlockScreen();
void SoftCursorMove(int x, int y);
void SoftCursorFree();
bool SoftCursorInLockedArea();
void SoftCursorSaveArea();
void SoftCursorRestoreArea();
void SoftCursorDraw();
void SoftCursorToScreen(RECT *screenArea, POINT *cursorOffset);
void InvalidateScreenRect(const RECT *pRect);
void InvalidateRegion(const RECT *pRect,HRGN *prgn);
// ClientConnectionZlibHex.cpp
void HandleZlibHexEncoding8(int x, int y, int w, int h);
void HandleZlibHexEncoding16(int x, int y, int w, int h);
void HandleZlibHexEncoding32(int x, int y, int w, int h);
void HandleZlibHexSubencodingStream8(int x, int y, int w, int h, int subencoding);
void HandleZlibHexSubencodingStream16(int x, int y, int w, int h, int subencoding);
void HandleZlibHexSubencodingStream32(int x, int y, int w, int h, int subencoding);
void HandleZlibHexSubencodingBuf8(int x, int y, int w, int h, int subencoding, unsigned char * buffer);
void HandleZlibHexSubencodingBuf16(int x, int y, int w, int h, int subencoding, unsigned char * buffer);
void HandleZlibHexSubencodingBuf32(int x, int y, int w, int h, int subencoding, unsigned char * buffer);
void ReadZlibHexRect(rfbFramebufferUpdateRectHeader *pfburh);
bool zlibDecompress(unsigned char *from_buf, unsigned char *to_buf, unsigned int count, unsigned int size, z_stream *decompressor);
// ClientConnectionClipboard.cpp
void ProcessLocalClipboardChange();
void UpdateLocalClipboard(char *buf, int len);
void SendClientCutText(char *str, int len);
void ReadServerCutText();
void ReadBell();
void SendRFBMsg(CARD8 msgType, void* data, int length);
void ReadString(char *buf, int length);
void WriteExact(char *buf, int bytes, CARD8 msgType);
void GetFriendlySizeString(__int64 Size, char* szText);
void UpdateStatusFields(); // sf@2002
// This is what controls the thread
void * run_undetached(void* arg);
bool m_bKillThread;
// Modif sf@2002 - FileTransfer
friend class FileTransfer;
friend class TextChatViewer;
// Modif sf@2002 - Server Scaling
bool SendServerScale(int nScale);
// Modif rdv@2002 - Server dis/enable input
bool SendServerInput(BOOL enabled);
bool SendSW(int x, int y);
void CheckNetRectBufferSize(int nBufSize);
void CheckZRLENetRectBufferSize(int nBufSize);
//
int EncodingStatusWindow,OldEncodingStatusWindow;
// Utilities
// These draw a solid rectangle of colour on the bitmap
// They assume the bitmap is already selected into the DC, and the
// DC is locked if necessary.
#ifndef UNDER_CE
// Normally this is an inline call to a GDI method.
inline void FillSolidRect(RECT *pRect, COLORREF color) {
COLORREF oldbgcol = SetBkColor(m_hBitmapDC, color);
// This is the call MFC uses for FillSolidRect. Who am I to argue?
::ExtTextOut(m_hBitmapDC, 0, 0, ETO_OPAQUE, pRect, NULL, 0, NULL);
};
#else
// Under WinCE this is a manual insert into a pixmap,
// and is a little too complicated for an inline.
void FillSolidRect(RECT *pRect, COLORREF color);
#endif // UNDER_CE
inline void FillSolidRect(int x, int y, int w, int h, COLORREF color) {
RECT r;
r.left = x; r.right = x + w;
r.top = y; r.bottom = y + h;
FillSolidRect(&r, color);
};
// how many other windows are owned by this process?
unsigned int CountProcessOtherWindows();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -