📄 vncserver.cpp
字号:
void vncServer::TextChatClient(LPSTR szClientName)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
vncClient *pClient = NULL;
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
pClient = GetClient(*i);
if (!stricmp(pClient->GetClientName(), szClientName))
{
if (!pClient->IsUltraViewer())
{
vnclog.Print(LL_INTINFO, VNCLOG("Client %s is not Ultra. Doesn't know TextChat\n"), szClientName);
vncTimedMsgBox::Do(
sz_ID_ULTRAVNC_TEXTCHAT,
sz_ID_ULTRAVNC_WARNING,
MB_ICONINFORMATION | MB_OK
);
break;
}
vnclog.Print(LL_INTINFO, VNCLOG("TextChat with client named: %s\n"), szClientName);
pClient->GetTextChatPointer()->OrderTextChat();
break;
}
}
vnclog.Print(LL_INTINFO, VNCLOG("KillClient() from name done\n"));
}
void
vncServer::KillAuthClients()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Tell all the authorised clients to die!
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
vnclog.Print(LL_INTINFO, VNCLOG("killing auth client\n"));
// Kill the client
GetClient(*i)->Kill();
}
vnclog.Print(LL_INTINFO, VNCLOG("KillAuthClients() done\n"));
}
//
// sf@2002 - Fill the passed ListBox with clients names
//
void vncServer::ListAuthClients(HWND hListBox)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
SendMessage(hListBox,
LB_ADDSTRING,
0,
(LPARAM) GetClient(*i)->GetClientName()
);
}
}
/*
//
// sf@2003 - Returns the first client name (IP)
//
void vncServer::FirstClientName()
{
omni_mutex_lock l(m_clientsLock);
return GetClient(*(m_authClients.begin()))->GetClientName();
}
*/
//
// sf@2002 - test if there's a slow client connected
// The criteria is a client that has been using a slow
// encoding for more than 10 seconds after its connection
//
bool vncServer::IsThereASlowClient()
{
vncClientList::iterator i;
bool fFound = false;
omni_mutex_lock l(m_clientsLock);
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
if (GetClient(*i)->IsSlowEncoding())
{
if (timeGetTime() - GetClient(*i)->GetConnectTime() > 10000)
{
fFound = true;
break;
}
else
continue;
}
else
continue;
}
return fFound;
}
bool vncServer::IsThereAUltraEncodingClient()
{
vncClientList::iterator i;
bool fFound = false;
omni_mutex_lock l(m_clientsLock);
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
if (GetClient(*i)->IsUltraEncoding())
{
return true;
}
}
return false;
}
void
vncServer::KillUnauthClients()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Tell all the authorised clients to die!
for (i = m_unauthClients.begin(); i != m_unauthClients.end(); i++)
{
vnclog.Print(LL_INTINFO, VNCLOG("killing unauth client\n"));
// Kill the client
GetClient(*i)->Kill();
}
vnclog.Print(LL_INTINFO, VNCLOG("KillUnauthClients() done\n"));
}
UINT
vncServer::AuthClientCount()
{
omni_mutex_lock l(m_clientsLock);
return m_authClients.size();
}
UINT
vncServer::UnauthClientCount()
{
omni_mutex_lock l(m_clientsLock);
return m_unauthClients.size();
}
BOOL
vncServer::UpdateWanted()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Iterate over the authorised clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
if (GetClient(*i)->UpdateWanted())
return TRUE;
}
return FALSE;
}
BOOL
vncServer::RemoteEventReceived()
{
vncClientList::iterator i;
BOOL result = FALSE;
omni_mutex_lock l(m_clientsLock);
// Iterate over the authorised clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
result = result || GetClient(*i)->RemoteEventReceived();
}
return result;
}
void
vncServer::WaitUntilAuthEmpty()
{
omni_mutex_lock l(m_clientsLock);
// Wait for all the clients to exit
while (!m_authClients.empty())
{
// Wait for a client to quit
m_clientquitsig->wait();
}
}
void
vncServer::WaitUntilUnauthEmpty()
{
omni_mutex_lock l(m_clientsLock);
// Wait for all the clients to exit
while (!m_unauthClients.empty())
{
// Wait for a client to quit
m_clientquitsig->wait();
}
}
// Client info retrieval/setup
vncClient*
vncServer::GetClient(vncClientId clientid)
{
if ((clientid >= 0) && (clientid < MAX_CLIENTS))
return m_clientmap[clientid];
return NULL;
}
vncClientList
vncServer::ClientList()
{
vncClientList clients;
omni_mutex_lock l(m_clientsLock);
clients = m_authClients;
return clients;
}
void
vncServer::SetCapability(vncClientId clientid, int capability)
{
omni_mutex_lock l(m_clientsLock);
vncClient *client = GetClient(clientid);
if (client != NULL)
client->SetCapability(capability);
}
void
vncServer::SetKeyboardEnabled(vncClientId clientid, BOOL enabled)
{
omni_mutex_lock l(m_clientsLock);
vncClient *client = GetClient(clientid);
if (client != NULL)
client->EnableKeyboard(enabled);
}
void
vncServer::SetPointerEnabled(vncClientId clientid, BOOL enabled)
{
omni_mutex_lock l(m_clientsLock);
vncClient *client = GetClient(clientid);
if (client != NULL)
client->EnablePointer(enabled);
}
int
vncServer::GetCapability(vncClientId clientid)
{
omni_mutex_lock l(m_clientsLock);
vncClient *client = GetClient(clientid);
if (client != NULL)
return client->GetCapability();
return 0;
}
const char*
vncServer::GetClientName(vncClientId clientid)
{
omni_mutex_lock l(m_clientsLock);
vncClient *client = GetClient(clientid);
if (client != NULL)
return client->GetClientName();
return NULL;
}
// RemoveClient should ONLY EVER be used by the client to remove itself.
void
vncServer::RemoveClient(vncClientId clientid)
{
vncClientList::iterator i;
BOOL done = FALSE;
// vnclog.Print(LL_INTINFO, VNCLOG("Lock1\n"));
omni_mutex_lock l1(m_desktopLock);
// vnclog.Print(LL_INTINFO, VNCLOG("Lock3\n"));
{ omni_mutex_lock l2(m_clientsLock);
// Find the client in one of the two lists
for (i = m_unauthClients.begin(); i != m_unauthClients.end(); i++)
{
// Is this the right client?
if ((*i) == clientid)
{
vnclog.Print(LL_INTINFO, VNCLOG("removing unauthorised client\n"));
// Yes, so remove the client and kill it
m_unauthClients.erase(i);
m_clientmap[clientid] = NULL;
done = TRUE;
break;
}
}
if (!done)
{
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Is this the right client?
if ((*i) == clientid)
{
vnclog.Print(LL_INTINFO, VNCLOG("removing authorised client\n"));
// Yes, so remove the client and kill it
m_authClients.erase(i);
m_clientmap[clientid] = NULL;
done = TRUE;
break;
}
}
}
// Signal that a client has quit
m_clientquitsig->signal();
} // Unlock the clientLock
// Are there any authorised clients connected?
if (m_authClients.empty() && (m_desktop != NULL))
{
vnclog.Print(LL_STATE, VNCLOG("deleting desktop server\n"));
// Are there locksettings set?
if (LockSettings() == 1)
{
// Yes - lock the machine on disconnect!
vncService::LockWorkstation();
} else if (LockSettings() > 1)
{
char username[UNLEN+1];
vncService::CurrentUser((char *)&username, sizeof(username));
if (strcmp(username, "") != 0)
{
// Yes - force a user logoff on disconnect!
if (!ExitWindowsEx(EWX_LOGOFF, 0))
vnclog.Print(LL_CONNERR, VNCLOG("client disconnect - failed to logoff user!\n"));
}
}
// Delete the screen server
delete m_desktop;
m_desktop = NULL;
vnclog.Print(LL_STATE, VNCLOG("desktop deleted\n"));
}
// Notify anyone interested of the change
DoNotify(WM_SRV_CLIENT_DISCONNECT, 0, 0);
vnclog.Print(LL_INTINFO, VNCLOG("RemoveClient() done\n"));
}
// NOTIFICATION HANDLING!
// Connect/disconnect notification
BOOL
vncServer::AddNotify(HWND hwnd)
{
omni_mutex_lock l(m_clientsLock);
// Add the window handle to the list
m_notifyList.push_front(hwnd);
return TRUE;
}
BOOL
vncServer::RemNotify(HWND hwnd)
{
omni_mutex_lock l(m_clientsLock);
// Remove the window handle from the list
vncNotifyList::iterator i;
for (i=m_notifyList.begin(); i!=m_notifyList.end(); i++)
{
if ((*i) == hwnd)
{
// Found the handle, so remove it
m_notifyList.erase(i);
return TRUE;
}
}
return FALSE;
}
// Send a notification message
void
vncServer::DoNotify(UINT message, WPARAM wparam, LPARAM lparam)
{
omni_mutex_lock l(m_clientsLock);
// Send the given message to all the notification windows
vncNotifyList::iterator i;
for (i=m_notifyList.begin(); i!=m_notifyList.end(); i++)
{
PostMessage((*i), message, wparam, lparam);
}
}
void
vncServer::UpdateMouse()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this mouse update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->UpdateMouse();
}
}
void
vncServer::UpdateClipText(const char* text)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->UpdateClipText(text);
}
}
void
vncServer::UpdateCursorShape()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->UpdateCursorShape();
}
}
void
vncServer::UpdatePalette()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->UpdatePalette();
}
}
void
vncServer::UpdateLocalFormat()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->UpdateLocalFormat();
}
}
void
vncServer::UpdateLocalClipText(LPSTR text)
{
// vnclog.Print(LL_INTINFO, VNCLOG("Lock5\n"));
omni_mutex_lock l(m_desktopLock);
if (m_desktop != NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -