Corretta gestione utenti e connesioni
git-svn-id: svn://10.65.10.50/trunk@6776 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
017422bc2c
commit
bfe23363bc
@ -33,7 +33,7 @@ public:
|
||||
|
||||
const CString& User() const { return m_strUser; }
|
||||
|
||||
TPrassiConnection(TLanManager* lm, DWORD id);
|
||||
TPrassiConnection(TLanManager* lm, DWORD id);
|
||||
virtual ~TPrassiConnection();
|
||||
};
|
||||
|
||||
|
@ -34,7 +34,7 @@ BOOL TPrassiConnection::DoUserLogin(const CString& user,
|
||||
|
||||
if (ok)
|
||||
{
|
||||
m_strUser = user;
|
||||
m_strUser = user; m_strUser.MakeUpper();
|
||||
m_strApp = app;
|
||||
}
|
||||
}
|
||||
@ -52,7 +52,7 @@ int f_UserLogin(TConnection& conn, void* pJolly)
|
||||
const int argc = argv.GetSize();
|
||||
if (argc > 3)
|
||||
{
|
||||
TPrassiConnection& c = (TPrassiConnection&)conn;
|
||||
TPrassiConnection& c = (TPrassiConnection&)conn;
|
||||
return c.DoUserLogin(argv[1], argv[2], argv[3]);
|
||||
}
|
||||
return FALSE;
|
||||
|
Binary file not shown.
@ -15,11 +15,11 @@ Class3=CFrontEndView
|
||||
Class4=CMainFrame
|
||||
|
||||
ResourceCount=3
|
||||
Resource1=IDD_STATUS
|
||||
Resource1=IDR_MAINFRAME
|
||||
Class5=CAboutDlg
|
||||
Resource2=IDD_ABOUTBOX
|
||||
Class6=CStatusDlg
|
||||
Resource3=IDR_MAINFRAME
|
||||
Resource3=IDD_STATUS
|
||||
|
||||
[CLS:CFrontEndApp]
|
||||
Type=0
|
||||
@ -68,13 +68,15 @@ LastObject=IDC_GRID1
|
||||
[DLG:IDD_ABOUTBOX]
|
||||
Type=1
|
||||
Class=CAboutDlg
|
||||
ControlCount=6
|
||||
ControlCount=8
|
||||
Control1=IDC_STATIC,static,1342177283
|
||||
Control2=IDC_STATIC,static,1342312576
|
||||
Control3=IDC_DISK_SPACE,static,1342312448
|
||||
Control4=IDOK,button,1342373889
|
||||
Control5=IDC_STATIC,static,1342312448
|
||||
Control6=IDC_PHYSICAL_MEM,static,1342312448
|
||||
Control7=IDC_STATIC,static,1342308352
|
||||
Control8=IDC_STATIC,static,1342308352
|
||||
|
||||
[MNU:IDR_MAINFRAME]
|
||||
Type=1
|
||||
@ -110,6 +112,7 @@ CommandCount=13
|
||||
|
||||
[TB:IDR_MAINFRAME]
|
||||
Type=1
|
||||
Class=?
|
||||
Command1=ID_FILE_SAVE_AS
|
||||
Command2=ID_VIEW_TRACE
|
||||
Command3=ID_EDIT_CLEAR_ALL
|
||||
@ -121,9 +124,12 @@ CommandCount=6
|
||||
[DLG:IDD_STATUS]
|
||||
Type=1
|
||||
Class=CStatusDlg
|
||||
ControlCount=2
|
||||
ControlCount=5
|
||||
Control1=IDOK,button,1342242817
|
||||
Control2=IDC_GRID,{A8C3B720-0B5A-101B-B22E-00AA0037B2FC},1342242816
|
||||
Control2=IDC_STATIC,static,1342308352
|
||||
Control3=IDC_USERS,static,1342308352
|
||||
Control4=IDC_STATIC,static,1342308352
|
||||
Control5=IDC_CONNECTIONS,static,1342308352
|
||||
|
||||
[CLS:CStatusDlg]
|
||||
Type=0
|
||||
|
@ -18,6 +18,8 @@
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
#define DONGLE_SERVER_ATOM "DONGLE_SERVER_ATOM"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CFrontEndApp
|
||||
|
||||
@ -83,9 +85,20 @@ BOOL CFrontEndApp::InitInstance()
|
||||
if (!ProcessShellCommand(cmdInfo))
|
||||
return FALSE;
|
||||
|
||||
StartServer();
|
||||
BOOL ok = ::GlobalFindAtom(DONGLE_SERVER_ATOM) == 0;
|
||||
if (ok)
|
||||
{
|
||||
ok = StartServer();
|
||||
if (ok)
|
||||
::GlobalAddAtom(DONGLE_SERVER_ATOM);
|
||||
}
|
||||
else
|
||||
{
|
||||
AfxMessageBox("Non e' possibile attivare due server contemporaneamente!",
|
||||
MB_ICONEXCLAMATION);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return ok;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -147,7 +160,12 @@ void CFrontEndApp::OnAppAbout()
|
||||
|
||||
int CFrontEndApp::ExitInstance()
|
||||
{
|
||||
StopServer();
|
||||
if (StopServer())
|
||||
{
|
||||
ATOM atom = ::GlobalFindAtom(DONGLE_SERVER_ATOM);
|
||||
if (atom)
|
||||
::GlobalDeleteAtom(atom);
|
||||
}
|
||||
return CWinApp::ExitInstance();
|
||||
}
|
||||
|
||||
@ -156,8 +174,8 @@ void CFrontEndApp::OnAppExit()
|
||||
BOOL bCanExit = !GetServer().HasConnections();
|
||||
if (!bCanExit)
|
||||
{
|
||||
int nCode = AfxMessageBox("There are still active connections:\n"
|
||||
"Do you really want to exit anyway?",
|
||||
int nCode = AfxMessageBox("Ci sono ancora degli utenti collegati:\n"
|
||||
"Si desidera uscire ugualmete?",
|
||||
MB_YESNO | MB_ICONQUESTION);
|
||||
if (nCode == IDYES)
|
||||
bCanExit = TRUE;
|
||||
|
@ -159,23 +159,27 @@ STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Server PRASSI"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
ICON IDR_MAINFRAME,IDC_STATIC,7,7,21,20
|
||||
ICON IDR_MAINFRAME,IDC_STATIC,7,7,20,20
|
||||
LTEXT "Server Versione 1.0",IDC_STATIC,49,7,119,10,SS_NOPREFIX |
|
||||
SS_SUNKEN
|
||||
LTEXT "Disk space",IDC_DISK_SPACE,49,54,119,9,SS_SUNKEN
|
||||
LTEXT "Disk space",IDC_DISK_SPACE,84,54,84,9,SS_SUNKEN
|
||||
DEFPUSHBUTTON "OK",IDOK,178,7,32,14,WS_GROUP
|
||||
LTEXT "Copyright © 1997",IDC_STATIC,49,23,119,9,SS_SUNKEN
|
||||
LTEXT "Physical memory",IDC_PHYSICAL_MEM,49,38,119,9,SS_SUNKEN
|
||||
LTEXT "Copyright © 1998",IDC_STATIC,49,23,119,9,SS_SUNKEN
|
||||
LTEXT "Physical memory",IDC_PHYSICAL_MEM,84,38,84,9,SS_SUNKEN
|
||||
LTEXT "Memoria",IDC_STATIC,50,41,28,8
|
||||
LTEXT "Disco",IDC_STATIC,50,55,19,8
|
||||
END
|
||||
|
||||
IDD_STATUS DIALOG DISCARDABLE 0, 0, 186, 122
|
||||
IDD_STATUS DIALOGEX 0, 0, 152, 71
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Utenti del sistema"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,68,101,50,14
|
||||
CONTROL "",IDC_GRID,"{A8C3B720-0B5A-101B-B22E-00AA0037B2FC}",
|
||||
WS_TABSTOP,7,7,172,84
|
||||
DEFPUSHBUTTON "OK",IDOK,50,45,50,14
|
||||
LTEXT "Numero connessioni",IDC_STATIC,7,23,84,8
|
||||
LTEXT "0",IDC_USERS,111,7,34,10,0,WS_EX_RIGHT
|
||||
LTEXT "Numero utenti",IDC_STATIC,7,7,84,8
|
||||
LTEXT "0",IDC_CONNECTIONS,111,20,34,10,0,WS_EX_RIGHT
|
||||
END
|
||||
|
||||
|
||||
@ -186,8 +190,8 @@ END
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,1
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEVERSION 1998,1,3,75
|
||||
PRODUCTVERSION 1998,1,3,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -200,17 +204,16 @@ VS_VERSION_INFO VERSIONINFO
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904B0"
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "\0"
|
||||
VALUE "FileDescription", "FRONTEND Applicazione MFC\0"
|
||||
VALUE "FileVersion", "1, 0, 0, 1\0"
|
||||
VALUE "CompanyName", "AGA\0"
|
||||
VALUE "FileDescription", "Network Dongle Server \0"
|
||||
VALUE "FileVersion", "1998, 1, 3, 75\0"
|
||||
VALUE "InternalName", "FRONTEND\0"
|
||||
VALUE "LegalCopyright", "Copyright © 1997\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "LegalCopyright", "Copyright © 1998\0"
|
||||
VALUE "OriginalFilename", "FRONTEND.EXE\0"
|
||||
VALUE "ProductName", "FRONTEND Applicazione\0"
|
||||
VALUE "ProductVersion", "1, 0, 0, 1\0"
|
||||
VALUE "ProductVersion", "1998, 1, 3, 0\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
@ -241,36 +244,14 @@ BEGIN
|
||||
IDD_STATUS, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 179
|
||||
RIGHTMARGIN, 145
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 115
|
||||
BOTTOMMARGIN, 59
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog Info
|
||||
//
|
||||
|
||||
IDD_STATUS DLGINIT
|
||||
BEGIN
|
||||
IDC_GRID, 0x376, 164, 0
|
||||
0x0024, 0x0000, 0x0041, 0x0036, 0x0044, 0x0041, 0x0038, 0x0035, 0x0038,
|
||||
0x0030, 0x002d, 0x0035, 0x0039, 0x0044, 0x0036, 0x002d, 0x0031, 0x0030,
|
||||
0x0031, 0x0042, 0x002d, 0x0041, 0x0033, 0x0043, 0x0039, 0x002d, 0x0030,
|
||||
0x0038, 0x0030, 0x0030, 0x0032, 0x0042, 0x0032, 0x0046, 0x0034, 0x0039,
|
||||
0x0046, 0x0042, 0x0000, 0x0001, 0x1aaa, 0x0000, 0x0e29, 0x0000, 0x004d,
|
||||
0x0000, 0x0000, 0x0080, 0xffff, 0x00ff, 0x0300, 0xe352, 0x910b, 0xce8f,
|
||||
0x9d11, 0x00e3, 0x00aa, 0xb84b, 0x0151, 0x0000, 0x9000, 0x4401, 0x0142,
|
||||
0x0d00, 0x534d, 0x5320, 0x6e61, 0x2073, 0x6553, 0x6972, 0x0166, 0x0001,
|
||||
0x0002, 0x0002, 0x0001, 0x0001, 0x0002, 0x0101, 0x0000, 0x0100, 0x0000,
|
||||
0x00ff,
|
||||
0
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
|
@ -112,13 +112,8 @@ void CMainFrame::OnUpdateNotepad(CCmdUI* pCmdUI)
|
||||
pCmdUI->Enable(TRUE);
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
_declspec(dllimport) int Aga_exec(const char* p);
|
||||
}
|
||||
|
||||
void CMainFrame::OnNotepad()
|
||||
{
|
||||
Aga_exec("notepad");
|
||||
CString cmd = "notepad";
|
||||
WinExec(cmd, SW_SHOWNORMAL);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#define IDC_DISK_SPACE 1006
|
||||
#define IDC_USERS 1008
|
||||
#define IDC_GRID 1009
|
||||
#define IDC_CONNECTIONS 1009
|
||||
#define stc32 0x045f
|
||||
#define ID_BUTTON32772 32772
|
||||
#define ID_VIEW_TRACE 32773
|
||||
|
@ -145,7 +145,7 @@ BOOL TDongleServer::HardlockLogin()
|
||||
ReadHardlockWords(60, 4, Val);
|
||||
HL_CODE(EYECAST Val, 1);
|
||||
_AssistanceYear = Val[0];
|
||||
_Users = Val[1];
|
||||
_MaxUsers = Val[1];
|
||||
|
||||
int index = 0;
|
||||
for (unsigned short reg = 48; reg < 60; reg += 4)
|
||||
@ -202,7 +202,7 @@ BOOL TDongleServer::EutronLogin()
|
||||
_SerNo = (unsigned long)atol(serno);
|
||||
if (eh._max_users > 0)
|
||||
{
|
||||
_Users = eh._max_users;
|
||||
_MaxUsers = eh._max_users;
|
||||
_AssistanceYear = eh._year_assist;
|
||||
ReadEutronWords(16, 16, _int_tab);
|
||||
}
|
||||
@ -218,25 +218,25 @@ BOOL TDongleServer::Login()
|
||||
BOOL ok = HardlockLogin() || EutronLogin();
|
||||
if (ok)
|
||||
{
|
||||
if (_SerNo == 0 || _Users == 0)
|
||||
if (_SerNo == 0 || _MaxUsers == 0)
|
||||
{
|
||||
const CTime tNow = CTime::GetCurrentTime();
|
||||
_AssistanceYear = tNow.GetYear();
|
||||
if (_SerNo == 0)
|
||||
{
|
||||
_Users = 4;
|
||||
_MaxUsers = 4;
|
||||
memset(_int_tab, 0xFF, sizeof(_int_tab));
|
||||
}
|
||||
else
|
||||
{
|
||||
_Users = 1;
|
||||
_MaxUsers = 1;
|
||||
memset(_int_tab, 0x00, sizeof(_int_tab));
|
||||
}
|
||||
}
|
||||
|
||||
Trace(-1, "Numero di serie %u", _SerNo);
|
||||
Trace(-1, "Anno assistenza %u", _AssistanceYear);
|
||||
Trace(-1, "Numero utenti %u", _Users);
|
||||
Trace(-1, "Numero utenti %u", _MaxUsers);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@ -253,14 +253,14 @@ void TDongleServer::Logout()
|
||||
HL_LOGOUT();
|
||||
}
|
||||
_SerNo = 0xFFFF;
|
||||
_Users = 0;
|
||||
_MaxUsers = 0;
|
||||
_AssistanceYear = 0;
|
||||
memset(_int_tab, 0, sizeof(_int_tab));
|
||||
}
|
||||
|
||||
BOOL TDongleServer::OnConnect(const CString& topic)
|
||||
{
|
||||
BOOL ok = Connections() <= MaxUsers();
|
||||
BOOL ok = Users() < MaxUsers();
|
||||
if (!ok)
|
||||
Trace(0, "Refusing Topic %s", (const char*)topic);
|
||||
return ok;
|
||||
@ -270,7 +270,7 @@ BOOL TDongleServer::OnConnect(const CString& topic)
|
||||
TConnection* TDongleServer::OnCreateConnection(DWORD id)
|
||||
{
|
||||
TConnection* c = NULL;
|
||||
if (Connections() <= MaxUsers())
|
||||
if (Users() < MaxUsers())
|
||||
{
|
||||
Trace(0, "Connecting %lu", id);
|
||||
c = new TPrassiConnection(this, id);
|
||||
@ -286,11 +286,31 @@ BOOL TDongleServer::OnRemoveConnection(DWORD id)
|
||||
return BASE_SERVER::OnRemoveConnection(id);
|
||||
}
|
||||
|
||||
int CountUsers(TConnection& conn, void* pJolly)
|
||||
{
|
||||
CMapStringToOb& users = *(CMapStringToOb*)pJolly;
|
||||
const TPrassiConnection& c = (TPrassiConnection&)conn;
|
||||
const CString& name = c.User();
|
||||
BOOL ok = name != "******";
|
||||
if (ok)
|
||||
users.SetAt(name, NULL);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
unsigned short TDongleServer::Users() const
|
||||
{
|
||||
CMapStringToOb u;
|
||||
((TDongleServer*)this)->ForEachConnection(CountUsers, &u);
|
||||
unsigned short nTotal = (unsigned short)u.GetCount();
|
||||
return nTotal;
|
||||
}
|
||||
|
||||
TDongleServer::TDongleServer()
|
||||
: BASE_SERVER("DONGLE")
|
||||
{
|
||||
_SerNo = 0xFFFF;
|
||||
_Users = 0;
|
||||
_MaxUsers = 0;
|
||||
_AssistanceYear = 0;
|
||||
memset(_int_tab, 0, sizeof(_int_tab));
|
||||
Login();
|
||||
|
@ -18,15 +18,15 @@
|
||||
|
||||
class TDongleServer : public BASE_SERVER
|
||||
{
|
||||
enum { MAX_MODULES = 256 };
|
||||
enum { MAX_MODULES = 256 };
|
||||
|
||||
unsigned int _SerNo, _Users, _AssistanceYear;
|
||||
unsigned int _SerNo, _MaxUsers, _AssistanceYear;
|
||||
unsigned short _int_tab[MAX_MODULES/16];
|
||||
|
||||
protected:
|
||||
virtual BOOL OnConnect(const CString& topic);
|
||||
virtual TConnection* OnCreateConnection(DWORD id);
|
||||
virtual BOOL OnRemoveConnection(DWORD id);
|
||||
virtual BOOL OnRemoveConnection(DWORD id);
|
||||
|
||||
BOOL HardlockLogin();
|
||||
BOOL EutronLogin();
|
||||
@ -47,9 +47,11 @@ public:
|
||||
{ nSize = sizeof(_int_tab); return _int_tab; }
|
||||
|
||||
unsigned short MaxUsers() const
|
||||
{ return _Users; }
|
||||
{ return _MaxUsers; }
|
||||
|
||||
TDongleServer();
|
||||
unsigned short Users() const;
|
||||
|
||||
TDongleServer();
|
||||
virtual ~TDongleServer();
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,6 @@ void CStatusDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(CStatusDlg)
|
||||
DDX_Control(pDX, IDC_GRID, m_grid);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
@ -42,41 +41,17 @@ END_MESSAGE_MAP()
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CStatusDlg message handlers
|
||||
|
||||
static int AddConnectionToGrid(TConnection& conn, void* pJolly)
|
||||
{
|
||||
const TPrassiConnection& user = (const TPrassiConnection&)conn;
|
||||
CGridCtrl* pGrid = (CGridCtrl*)pJolly;
|
||||
|
||||
int nPos = pGrid->GetRow()+1;
|
||||
pGrid->SetRow(nPos);
|
||||
|
||||
pGrid->SetCol(0);
|
||||
CString str; str.Format("%d", nPos);
|
||||
pGrid->SetText(str);
|
||||
|
||||
pGrid->SetCol(1);
|
||||
pGrid->SetText(user.User());
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL CStatusDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
m_grid.SetColWidth(1, 4100);
|
||||
m_grid.SetRow(0);
|
||||
m_grid.SetCol(0);
|
||||
m_grid.SetText("N.");
|
||||
m_grid.SetCol(1);
|
||||
m_grid.SetText("Name");
|
||||
|
||||
TDongleServer& srv = GetServer();
|
||||
const int nUsers = srv.Connections();
|
||||
if (nUsers > 0)
|
||||
{
|
||||
m_grid.SetRows(nUsers+1);
|
||||
srv.ForEachConnection(AddConnectionToGrid, &m_grid);
|
||||
}
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
const int nUsers = srv.Users();
|
||||
const int nConns = srv.Connections();
|
||||
SetDlgItemInt(IDC_USERS, nUsers);
|
||||
SetDlgItemInt(IDC_CONNECTIONS, nConns);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
@ -3,9 +3,6 @@
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CStatusDlg dialog
|
||||
//{{AFX_INCLUDES()
|
||||
#include "gridctrl.h"
|
||||
//}}AFX_INCLUDES
|
||||
|
||||
class CStatusDlg : public CDialog
|
||||
{
|
||||
@ -16,7 +13,6 @@ public:
|
||||
// Dialog Data
|
||||
//{{AFX_DATA(CStatusDlg)
|
||||
enum { IDD = IDD_STATUS };
|
||||
CGridCtrl m_grid;
|
||||
//}}AFX_DATA
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@ BOOL Trace(int level, const char* fmt, ...)
|
||||
ASSERT(pFrame);
|
||||
CTreeView* pTreeView = (CTreeView*)pFrame->GetActiveView();
|
||||
ASSERT(pTreeView);
|
||||
CTreeCtrl& pTreeCtrl = pTreeView->GetTreeCtrl();
|
||||
CTreeCtrl& pTreeCtrl = pTreeView->GetTreeCtrl();
|
||||
|
||||
char msg[256];
|
||||
va_list argptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user