📄 rightlogin.cpp
字号:
void CRightLogin::parse_cmd_line()
{
CString cmd = AfxGetApp()->m_lpCmdLine;
if( cmd.IsEmpty() )
return;
int idx = 0;
int end = 0;
for( ;; )
{
idx = cmd.Find(_T("/open:"));
if( idx == -1 )
break;
idx = cmd.Find(_T("\""), idx);
if( idx == -1 )
break;
end = cmd.Find(_T("\""), idx+1);
if( end == -1 )
break;
CString item = cmd.Mid(idx+1, end-idx-1);
add_open_chnl(item);
cmd.Delete(0, end);
}
}
/*
* 对话框销毁, 释放所有资源
*/
//##ModelId=3F90BAB20142
void CRightLogin::OnDestroy()
{
close_all();
UpdateData();
write_string(rkLastStatus, rvIPPort, m_login_temip);
write_string(rkLastStatus, rvUser, m_login_temuser);
logout();
net_destroy(net);
CString m_str;
m_str.Format(IDS_OUTS);
write_log_file(m_str);
close_log_file();
close_log_alarm_file();
baseclass::OnDestroy();
}
void CRightLogin::OnChangetemip()
{
UpdateData(TRUE);
}
/*
* 尝试登录
*/
//##ModelId=3F90BAB003AC
void CRightLogin::login(LPCTSTR ipport, LPCTSTR dvrname, LPCTSTR user, LPCTSTR password, bool m_bool)
{
ip_port ipp(ipport);
ULONG ip = net_get_host_by_name(net, ipp.str_ip());
if(!ip)
{
if(m_bool)
AfxMessageBox(IDS_DNS_FAILURE);
return ;
}
ipp = ip_port(ip, ipp.look_port());
channel_info* ref = cmgr.find(ipp);
if(!ref)
{
channel_info ch(dvrname,ipp,0,0,0,-1);
cmgr.add(ch);
}
net_login(net, ipp.get_ip(), ipp.look_port(), user, password);
}
ip_port & CRightLogin::parseloginname(CString m_loginname)
{
ip_port ipp(m_loginname);
ULONG ip = net_get_host_by_name(net, ipp.str_ip());
if(!ip)
{
AfxMessageBox("failure");
return ip_port(1, 0);
}
return ip_port(ip, ipp.look_port());
}
//##ModelId=3F90BAB003A2
void CRightLogin::close_all()
{
if( CRightLocal::the_one()->m_close_on_exit )
{
for( int i=0; i<video_channel::count(); i++ )
{
if( m_close_remote_bool)
close_remote_channel(i);
else
close_local_channel(i);
}
}
}
/*
* 尝试登出
*/
//##ModelId=3F90BAB003CA
void CRightLogin::logout()
{
/*
* 如果未登录任何主机, 返回
*/
//int m_int=find_position();
//if(m_int==-1) return;
/*
* 从登录IP:Port得到要登出的主机地址
*/
for(int i=0;i<cmgr.count();i++)
{
channel_info& ci = cmgr[i];
/*
* 发送登出请求
*/
net_logout(net, ci.get_ip(), ci.look_port(), CRightLocal::the_one()->m_close_on_exit);
/*
* 删除列表中的登录项
*/
ci.logout();
// cmgr.remove(ci);
}
//update_list(m_scene);
/*
* 通知各个工具栏, 刚刚断开一个主机
*/
//AfxGetMainWnd()->SendMessage(WM_LOGGED_OUT, (WPARAM)(LPCTSTR)m_loginip);
}
/*
* 登录按钮响应
*/
void CRightLogin::OnSetfocusScene()
{
Cfileoperation <Scene_set_up> *m_fileoperation;
Scene_set_up m_temscene[120];
m_list_scence.ResetContent();
int m_length=m_fileoperation->openfile(m_scene_setup_directory,"rb",m_temscene);
m_list_scence.AddString(m_tem_login_scene);
for(int k=0;k<m_length;k++)
{
if(!strcmp(m_temscene[k].name,m_login_client_name))
m_list_scence.AddString(m_temscene[k].scene_name);
else continue;
}
}
void CRightLogin::OnSelchangeScene()
{
int index = m_list_scence.GetCurSel();
if (index!=CB_ERR)
{
m_list_scence.GetLBText(index,m_scene);
}
m_lstLogged.ResetContent();
if(m_scene == m_tem_login_scene)
{
update_list();
return;
}
Cfileoperation <Machine_Channel_Setting> *m_fileoperation;
m_machine_length=m_fileoperation->openfile(m_channel_window_directory,"rb",m_clientchannelsetting,300);
Cfileoperation <Remote_Station_setting> *m_pfileoperation;
m_station_length=m_pfileoperation->openfile(m_remote_station_directory,"rb",m_station);
CString m_str;
int m_station_nub=0;
for(int m=0;m<m_station_length;m++)
{
Remote_Station_setting * p = & m_station[m];
if(strcmp(p->name, m_login_client_name)) continue;
m_str.Format(p->dvrname);
if(!find_scene_dvrname(m_str,m_scene)) continue;
m_temstation[m_station_nub] = m_str;
update_list(m_str,m_station_nub);
m_station_nub++;
}
window_poll_clear();
for(int i=0; i<16; i++) set_window_poll(i+1);
}
void CRightLogin::update_list()
{
CString str;
CString alias;
m_lstLogged.ResetContent();
int m_station = 0;
for( int i=0; i<cmgr.count(); i++ )
{
channel_info& ref = cmgr[i];
// if(ref.get_dvrname() != m_tem_login_scene) continue;
if(!ref.logintrue()) continue;
ip_port ip = ref.get_ip_port();
alias = ipmgr.get_alias(ip);
str.Format(IDS_LOGGED_IN_FMT, alias, ref.get_channels());
m_lstLogged.InsertString(m_station,str);
m_station++;
}
m_lstLogged.SetCurSel(0);
PostMessage(WM_UPDATE_DATA, FALSE);
}
bool CRightLogin::find_scene_dvrname(CString dvrname,CString m_scene)
{
for(int m=0;m<m_machine_length;m++)
{
Machine_Channel_Setting * p = & m_clientchannelsetting[m];
if(!strcmp(p->name,m_login_client_name)&&!strcmp(p->scene_name,m_scene))
if(!strcmp(p->dvrname, dvrname))
return true;
}
return false;
}
//##ModelId=3F90BAB20138
void CRightLogin::OnLogin()
{
UpdateData(true);
Onuserlogout();
OnSelchangeScene();
channelopensetting(m_scene);
}
void CRightLogin::OnLogintemp()
{
UpdateData(TRUE);
login(m_login_temip, m_tem_login_scene, m_login_temuser, m_tem_password, true);
m_scene = m_tem_login_scene;
UpdateData(FALSE);
update_list();
}
void CRightLogin::Onlogouttemp()
{
int m_int = find_position();
if(m_int == -1) return;
channel_info& ci = cmgr[m_int];
net_logout(net, ci.get_ip(), ci.look_port(), m_close_remote_bool);
check_logout(ci.get_ip(), ci.look_port());
ci.logout();
cmgr.remove(ci);
OnSelchangeScene();
}
void CRightLogin::check_logout(ULONG ip, USHORT port)
{
for( int k=0; k<video_channel_count(); k++ )
{
video_channel* p = get_video_channel(k);
if(!p->is_video_opened() || ip == p->channel_ip().get_ip() && port == p->channel_ip().look_port() )
{
if(m_close_remote_bool)
close_remote_channel(k);
else
close_local_channel(k);
}
}
}
bool CRightLogin::onloginfuc(CString m_name,CString m_pass)
{
CString m_str;
set_directory();
open_log_file();
open_log_alarm_file();
if(openfile(m_name,m_pass))
{
m_str.Format(IDS_LOGIN_OK);
// AfxMessageBox(IDS_WELCOME);
write_log_file(m_str);
openpopedom(m_name);
return true;
}
else
{
AfxMessageBox(IDS_LOGIN_CUE);
return false;
}
}
void CRightLogin::set_directory()
{
strcpy(m_user_management_directory,m_system_directory);
strcat(m_user_management_directory,"/UserManagement.dat");
strcpy(m_popedom_directory,m_system_directory);
strcat(m_popedom_directory,"/Popedom Setting.dat");
strcpy(m_channel_window_directory,m_system_directory);
strcat(m_channel_window_directory,"/Channel and Window Setting.dat");
strcpy(m_remote_station_directory,m_system_directory);
strcat(m_remote_station_directory,"/Remote_station_setup.dat");
strcpy(m_scene_setup_directory,m_system_directory);
strcat(m_scene_setup_directory,"/Scene_setup.dat");
strcpy(m_inspect_date_query_directory,m_system_directory);
strcat(m_inspect_date_query_directory,"/Inspect Date.dat");
strcpy(m_alarm_server_directory,m_system_directory);
strcat(m_alarm_server_directory,"/alarm server.dat");
strcpy(m_alarm_server_link_directory,m_system_directory);
strcat(m_alarm_server_link_directory,"/alarm server link.dat");
}
bool CRightLogin::openfile(CString m_name,CString m_pass)
{
Cfileoperation <User_Information> *m_fileoperation;
User_Information m_user[120];
int m_length=m_fileoperation->openfile(m_user_management_directory,"rb",m_user);
for(int m=0;m<m_length;m++)
{
if(!strcmp(m_user[m].name,m_name))
{
if(!strcmp(m_user[m].password,m_pass))
{
m_login_client_name.Format(m_user[m].name);
return true;
}
else
return false;
}
}
return false;
}
void CRightLogin::openpopedom(CString m_name)
{
Cfileoperation <Popedom_Setting> *m_fileoperation;
Popedom_Setting m_popedom[120];
int m_length=m_fileoperation->openfile(m_popedom_directory,"rb",m_popedom);
for(int k=0;k<m_length;k++)
{
if(!strcmp(m_popedom[k].name,m_name))
{
m_login_client_popedom = m_popedom[k];
break ;
}
}
}
//发送的打开视频指令,存在时间间隔,不然会只处理一部分指令,所以使用timer来解决问题
void CRightLogin::channelopensetting(CString m_str)
{
m_open_vedio_nub=0;
SetTimer(ID_OPENVEDIO, 200, NULL);
}
void CRightLogin::opensetting()
{
Cfileoperation <Remote_Station_setting> *m_fileoperation;
m_station_length=m_fileoperation->openfile(m_remote_station_directory,"rb",m_station);
SetTimer(ID_LOGIN, 50, NULL);
}
/*
* 登出按钮响应
*/
//##ModelId=3F90BAB20156
/*void CRightLogin::OnLogout()
{
logout();
UpdateData();
}*/
void CRightLogin::Onuserlogout()
{
for(int i=0;i<video_channel_count();i++)
{
video_channel* p = get_video_channel(i);
if( !p->is_video_opened()) continue;
if(m_close_remote_bool)
close_remote_channel(i);
else
close_local_channel(i);
}
m_auto_poll = true;
m_alarm_window = 0;
UpdateData(true);
}
/*
* 刷新登录列表
*/
//##ModelId=3F90BAB100A1
void CRightLogin::OnDblclkList()
{
int m_int=find_position();
if(m_int>-1)
{
channel_info& ref = cmgr[m_int];
OnDbClkLogin(ref.str_ip());
CString m_str;
m_str.Format(ID_PINGIP,ref.str_ip());
write_log_file(m_str);
}
}
void CRightLogin::update_list(CString m_str,int m_station)
{
UpdateData(false);
CString str;
for( int i=0; i<cmgr.count(); i++ )
{
channel_info& ref = cmgr[i];
if(ref.get_dvrname() == m_str)
{
if(ref.logintrue())
str.Format(IDS_LOGGED_IN_FMT, ref.get_dvrname(), ref.get_channels());
else str.Format(IDS_LOGIN_FALSE,ref.get_dvrname());
int idx=m_lstLogged.InsertString(m_station,str);
}
}
//m_lstLogged.SetCurSel(0);
PostMessage(WM_UPDATE_DATA, FALSE);
}
/*
* 来自主机网络消息: 登录成功
* 附带信息: IP, Port, 该主机视频通道总数
*/
//void CRightLogin::on_login_success(IPPORT_TYPE, ULONG channel_count, int privilege)
nt_cmd_login_ok m_login_dvr_popedom[120];
int m_login_dvr_length=0;
int CRightLogin::check_init_popedom(nt_cmd_login_ok* clo)
{
nt_cmd_login_ok * kk ;
for(int m=0;m<m_login_dvr_length;m++)
{
kk = &m_login_dvr_popedom[m];
if(kk->ip == clo->ip && kk->port == clo->port)
return m;
}
return m_login_dvr_length++;
}
//初始化dvr的操作权限
void CRightLogin::init_login_dvr_popedom(nt_cmd_login_ok* clo)
{
nt_cmd_login_ok * kk ;
int index = check_init_popedom(clo);
kk = &m_login_dvr_popedom[index];
kk->ip = clo->ip;
kk->port = clo->port;
kk->version = clo->version;
kk->portpopedom = clo->portpopedom;
kk->actionpopedom = clo->actionpopedom;
}
//再次登录(站点修改发送的消息)
MSG3(on_login_again, CRightLogin)
{
Remote_Station_setting* p = (Remote_Station_setting*) w;
ip_port m_ipp(p->ip,p->port);
login(m_ipp, p->dvrname, p->logindvrname, p->logindvrpass,true);
OnSelchangeScene();
return 0;
}
//修改登录信息(站点修改发送的消息)
MSG3(on_login_update, CRightLogin)
{
Remote_Station_setting* p = (Remote_Station_setting*) w;
ip_port m_ipp(p->ip, p->port);
for(int i=0;i<cmgr.count();i++)
{
channel_info& ref = cmgr[i];
if(!strcmp(p->dvrname,ref.get_dvrname()))
{
cmgr.remove(ref);
break;
}
}
login(m_ipp, p->dvrname, p->logindvrname, p->logindvrpass,true);
OnSelchangeScene();
return 0;
}
//删除登录信息(站点删除发送的消息)
MSG3(on_del_close, CRightLogin)
{
Remote_Station_setting* pstation=(Remote_Station_setting*) w;
for(int i=0;i<cmgr.count();i++)
{
channel_info& ref = cmgr[i];
if(!strcmp(pstation->dvrname,ref.get_dvrname()))
{
cmgr.remove(ref);
break;
}
}
OnSelchangeScene();
return 0;
}
//登录站点后,返回的消息
MSG3(on_login, CRightLogin)
{
nt_cmd_login_ok* clo = (nt_cmd_login_ok*)w;
init_login_dvr_popedom(clo);
CString m_dvrname, m_ip;
for(int i=0;i<cmgr.count();i++)
{
channel_info& ref = cmgr[i];
if(clo->ip == ref.get_ip() && clo->port == ref.look_port())
{
m_dvrname = ref.get_dvrname();
m_ip = ref.str_ip();
channel_info ci(ref.get_dvrname(),clo->ip, clo->port, clo->channel_count, clo->privilege,TRUE,-1);
if(l == 2)
ci.set_udp(TRUE); //l = TRUE 必须在cmgr.add后面
else
ci.set_udp(FALSE);
cmgr.remove(ref);
cmgr.add(ci);
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -