⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tvmeetingdlg.cpp

📁 用c++做的视频会议源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
						isWantConnect=true;
					}
				}
				if (isWantConnect==false)
				{
					break;
				}
				bool isExist=false;
				char szIP[100];
				strcpy(szIP,strIP.GetBuffer(strIP.GetLength()));
				SetCmdDst(szIP,PORT);
				SetAVDst(szIP,PORT+1);
				m_sockaddr=GetCurrentAddr();
				POSITION pos;
				if (m_ClientInfoList.GetCount()!=0)
				{
					for( pos = m_ClientInfoList.GetHeadPosition(); pos != NULL; )
					{				
						CClientInfo *pClientInfo=m_ClientInfoList.GetAt(pos);
						sTmpIP.Format("%d.%d.%d.%d",
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b1,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b2,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b3,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b4);

						if (strIP==sTmpIP)
						{
							isExist=true;
							if (pClientInfo!=NULL)
							{
								pClientInfo=NULL;
								delete pClientInfo;
							}
							break;
						}
						m_ClientInfoList.GetNext(pos);
					}// end of for                                                	
					
				}
				
				if (isExist==false)
				{
					for (int i=0;i<MAX_CONNECT_USER;i++)
					{
						sSelIP=sIP[i];
						if (sSelIP==strIP)
						{	
							m_LstJoin.AddString(sSelIP);
						}
					}

					CClientInfo *pClientInfo=new CClientInfo;
					pClientInfo->m_Cmddst=m_scIn;
					pClientInfo->m_szIP=strIP;
					pClientInfo->m_uDataRcv=0;
					pClientInfo->m_iZeroCount=0;
					pClientInfo->m_ChatNo=ppc->m_ChatNo;
					// added by rc 04031611
					uiCount=GetUi();
					pClientInfo->UID=uiCount;
					pClientInfo->bMain=FALSE;
					CStatic* name;
					if(uiCount<3)
					{
						switch(uiCount)
						{
						case 0:
							name=(CStatic *)GetDlgItem(IDC_NOne);
							break;
						case 1:
							name=(CStatic *)GetDlgItem(IDC_NTwo);
							break;
						case 2:
							name=(CStatic *)GetDlgItem(IDC_NThree);
							break;
						}
					}
					name->SetWindowText(pClientInfo->m_szIP);
					name=NULL;
					delete name;
					m_ClientInfoList.AddTail(pClientInfo);	
					if (pClientInfo!=NULL)
					{
						pClientInfo=NULL;
						delete pClientInfo;
					}
					ZeroMemory(&m_ds,sizeof(m_ds));
					m_ds.bVideoOut=true;//always ok

				}
					//////////////////////////////////////////////////////////////
					sprintf(sz,"Call From [%d.%d.%d.%d] ",
					sc.sin_addr.S_un.S_un_b.s_b1,
					sc.sin_addr.S_un.S_un_b.s_b2,
					sc.sin_addr.S_un.S_un_b.s_b3,
					sc.sin_addr.S_un.S_un_b.s_b4);
					
					WriteLogInfoToCtrl((LPCSTR)sz);
					PACK_CMD pc1;
					pc1.flag=FLAG_CMD;
					pc1.data_size_extra=0;	
					pc1.cmd=CMD_JOINOK;
					pc1.ext=VER_TVMEETING&0xff;
					pc1.type=1;
					pc1.id=ppc->id;
					pc1.m_ChatNo=ppc->m_ChatNo;
					m_CMDSocket.SendTo((char*)&pc1,sizeof(pc1),(sockaddr*)&m_scIn);					
					///////////////////////////////////////////////////////////////////////
			}// end of if (ppc->type==0)
			
			
		}break;
		
		
		case CMD_JOINOK:
		{
			if(ppc->type==1)
			{
				sockaddr_in sc= m_scIn;		
					strIP.Format("%d.%d.%d.%d",
					sc.sin_addr.S_un.S_un_b.s_b1,
					sc.sin_addr.S_un.S_un_b.s_b2,
					sc.sin_addr.S_un.S_un_b.s_b3,
					sc.sin_addr.S_un.S_un_b.s_b4);
				for (int i=0;i<MAX_CONNECT_USER;i++)
				{
					if (m_ChatNo[i]==ppc->m_ChatNo)
					{
						KillTimer(ppc->m_ChatNo);
						m_CmdQueue.Remove(ppc->m_ChatNo);
						
					}
				}
				///////////////////////////

				///////////////////////////
				POSITION pos;
                /////////////////////////////////////////////////////////////
				bool isExist=false;
			
				if (m_ClientInfoList.GetCount()!=0)
				{
					for( pos = m_ClientInfoList.GetHeadPosition(); pos != NULL; )
					{				
						CClientInfo *pClientInfo=m_ClientInfoList.GetAt(pos);
						sTmpIP.Format("%d.%d.%d.%d",
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b1,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b2,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b3,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b4);
						if (strIP==sTmpIP)
						{
							isExist=true;
							if (pClientInfo!=NULL)
							{
								pClientInfo=NULL;
								delete pClientInfo;
							}
						}
						m_ClientInfoList.GetNext(pos);
					}// end of for                                                	
					
				}
				if (isExist ==false)
				{
					CClientInfo *pClientInfo=new CClientInfo;
					pClientInfo->m_Cmddst=sc;
					pClientInfo->m_szIP=strIP;
					pClientInfo->m_uDataRcv=0;
					pClientInfo->m_iZeroCount=0;
					pClientInfo->m_ChatNo=ppc->m_ChatNo;
					// added by rc 04031611
					uiCount=GetUi();
					pClientInfo->UID=uiCount;
					pClientInfo->bMain=FALSE;
					CStatic* name;
					if(uiCount<3)
					{
						switch(uiCount)
						{
						case 0:
							name=(CStatic *)GetDlgItem(IDC_NOne);
							break;
						case 1:
							name=(CStatic *)GetDlgItem(IDC_NTwo);
							break;
						case 2:
							name=(CStatic *)GetDlgItem(IDC_NThree);
							break;
						}
					}
					name->SetWindowText(pClientInfo->m_szIP);
					m_ClientInfoList.AddTail(pClientInfo);				    
					for (int i=0;i<MAX_CONNECT_USER;i++)
					{
						sSelIP =sIP[i];
						strIP.Format("%d.%d.%d.%d",
						sc.sin_addr.S_un.S_un_b.s_b1,
						sc.sin_addr.S_un.S_un_b.s_b2,
						sc.sin_addr.S_un.S_un_b.s_b3,
						sc.sin_addr.S_un.S_un_b.s_b4);
						if (sSelIP==strIP)//||m_szLocalIP==sSelIP
						{	
							m_LstJoin.AddString(sSelIP);
							
						}
					}
					if (pClientInfo!=NULL)
					{
						pClientInfo=NULL;
						delete pClientInfo;
					}
					m_ds.bVideoOut=true;
				///////////////////////////////////////////////////////////////
				}

					// start to distribute the sending port for the IP address
					// 2003-4-10 wzz
				
					bIsPortChecking=true;
					char sDisIP[20];
					strcpy(sDisIP,strIP.GetBuffer(strIP.GetLength()));
					sockaddr_in m_DisPort;
					m_DisPort.sin_family=AF_INET;
					m_DisPort.sin_addr.s_addr=CUDPSocket::Name2Inet(sDisIP);
					PACK_PORT pp;
					pp.flag=FLAG_PORT;
					pp.cmd=CMD_DISPORT;
					pp.type=0;
					pp.m_Port=PORT+11;
					m_DisPort.sin_port=htons(PORT+11);
					m_AVSocket.SendTo((char*)&pp,sizeof(PACK_PORT),(sockaddr*)&m_DisPort);
			}
		}break;
		
		case CMD_EXIT:
		{
			if(ppc->type==0)
			{
				
					sockaddr_in sc= m_scIn;	
					szIP.Format("%d.%d.%d.%d",
						sc.sin_addr.S_un.S_un_b.s_b1,
						sc.sin_addr.S_un.S_un_b.s_b2,
						sc.sin_addr.S_un.S_un_b.s_b3,
						sc.sin_addr.S_un.S_un_b.s_b4);	
					//**************************************************************
					
					POSITION pos,delPos,tmpPos;

					if (m_ClientInfoList.GetCount()!=0)
					{
						for( pos = m_ClientInfoList.GetHeadPosition(); pos != NULL; )
						{	
							delPos=pos;
							tmpPos=pos;
							bool del=false;
							//////////////////////////////////////
							if(pos!=NULL)
							{
								
								CClientInfo *pClientInfo=m_ClientInfoList.GetAt(pos);
								strIP.Format("%d.%d.%d.%d",
								pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b1,
								pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b2,
								pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b3,
								pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b4);

								if (strIP==szIP)
								{
									// added by rc 04031611
									SetUi(pClientInfo->UID);
									if (delPos!=NULL)
									m_ClientInfoList.GetNext(delPos);
									if (tmpPos!=NULL)
									m_ClientInfoList.RemoveAt(tmpPos);
									del=true;
										//////////////////////////////////////////
										for (int i=0;i<m_LstJoin.GetCount();i++)
										{
											m_LstJoin.GetText(i,sTmpIP);
											sTmpIP.TrimLeft();
											sTmpIP.TrimRight();
											if (sTmpIP!="")
											{
												if (sTmpIP==strIP)//||m_szLocalIP==sTmpIP
												{
													m_LstJoin.DeleteString(i);
													strDisplay="*** ["+sTmpIP+"] OffLine!!";
													WriteLogInfoToCtrl(strDisplay);
												}
											}
										}
										ZeroMemory(m_AudioRemote,SIZE_AUDIO_FRAME);
										ZeroMemory(m_AudioRemote2,SIZE_AUDIO_FRAME);
										ZeroMemory(m_AudioRemote3,SIZE_AUDIO_FRAME);
										for (i=0;i<3;i++)
										{
											if (DistributeIP[i]==strIP)
											{
												PortBusy[i]	=0;
												DistributeIP[i]="";
												if (i==0)
												{
													m_nDistributePort1=0;
													
												}
												else if (i==1)
												{
													m_nDistributePort2=0;
													
												}
												else if (i==2)
												{
													
													m_nDistributePort3=0;
													
												}
											}

										}
										///////////////////////////////////////////

								}
								if (del==true)
								{
									pos=delPos;
								}
								else
								{
									if (pos!=NULL)
									m_ClientInfoList.GetNext(pos);
								}

								if (pClientInfo!=NULL)
								{
									pClientInfo=NULL;
									delete pClientInfo;
								}
								m_ds.bVideoOut=true;
							}// end of if (pos!=NULL)			
							//////////////////////////////////////
							
						}  // end of for
					}// end of if
					
					//**************************************************************
				

			}
		}break;
		case CMD_REQUEST_MAIN:
			{
				//dd
				szIP.Format("%d.%d.%d.%d",
					m_scIn.sin_addr.S_un.S_un_b.s_b1,
					m_scIn.sin_addr.S_un.S_un_b.s_b2,
					m_scIn.sin_addr.S_un.S_un_b.s_b3,
					m_scIn.sin_addr.S_un.S_un_b.s_b4);
				CClientInfo *pClientInfo;
				for(POSITION pos = m_ClientInfoList.GetHeadPosition(); pos != NULL; )
				{				
					pClientInfo=m_ClientInfoList.GetAt(pos);
					sTmpIP.Format("%d.%d.%d.%d",
					pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b1,
					pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b2,
					pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b3,
					pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b4);
					m_ClientInfoList.GetNext(pos);
					if (szIP==sTmpIP)
					{		
						if(bMainExist)
							MainExist->bMain=FALSE;
						bMainExist=TRUE;
						MainExist=pClientInfo;
						pClientInfo->bMain=TRUE;
						break;
					}
				}// end of for 
				if (pClientInfo!=NULL)
				{
					pClientInfo=NULL;
					delete pClientInfo;
				}
			}
			break;
	}
}
void CTVMeetingDlg::OnTextInfo(PACK_TEXT *pTxt, int len,sockaddr_in m_scIn)
{
	CString strIP;
	switch (pTxt->cmd)
	{
		case CMD_SENDTEXT:
		{
			if(pTxt->type==0)
			{	char sz[MAX_TEXT_BUFFER+20]; //wzz 2003-4-3
				char szIP[20];
				sockaddr_in sc= m_scIn;
				CString sRecive;
				sRecive=(LPCSTR)pTxt->data;
				sprintf(sz,"User [%d.%d.%d.%d] :%s",
				sc.sin_addr.S_un.S_un_b.s_b1,
				sc.sin_addr.S_un.S_un_b.s_b2,
				sc.sin_addr.S_un.S_un_b.s_b3,
				sc.sin_addr.S_un.S_un_b.s_b4,sRecive);

				strIP.Format("%d.%d.%d.%d",
				sc.sin_addr.S_un.S_un_b.s_b1,
				sc.sin_addr.S_un.S_un_b.s_b2,
				sc.sin_addr.S_un.S_un_b.s_b3,
				sc.sin_addr.S_un.S_un_b.s_b4);
				WriteLogInfoToCtrl((LPCSTR)sz);
				strcpy(szIP,strIP.GetBuffer(strIP.GetLength()));
				SetCmdDst(szIP,PORT);
				m_sockaddr=GetCurrentAddr();
				PACK_TEXT pT;
				pT.flag=FLAG_TEXT;
				strcpy(pT.data,pTxt->data);
				pT.cmd=CMD_SENDTEXTOK;
				pT.id=0;
				pT.type=1;
				m_CMDSocket.SendTo((char*)&pT,sizeof(pT),(sockaddr*)&m_scIn);	
				
			}	
		}
		case CMD_SENDTEXTOK:
		{
			if(pTxt->type==1)
			{	
				
				sockaddr_in sc= m_scIn;
				CString strIP;
				strIP.Format("%d.%d.%d.%d",
				sc.sin_addr.S_un.S_un_b.s_b1,
				sc.sin_addr.S_un.S_un_b.s_b2,
				sc.sin_addr.S_un.S_un_b.s_b3,
				sc.sin_addr.S_un.S_un_b.s_b4);
				SetDlgItemText(IDC_TXTSEND,"");
				GetDlgItem(IDC_TXTSEND)->SetFocus();
				
			}
		}
	}
}
sockaddr_in& CTVMeetingDlg::GetCurrentAddr()
{
	return m_sockaddr;
}
sockaddr_in CTVMeetingDlg::GetRemoteAddr()
{
	return m_Cmddst;
}
BOOL CTVMeetingDlg::Call(char *ip, unsigned short port,int flag)
{
	BOOL bRet=FALSE;
	CString strIP,ssIP;
	ssIP=(LPCSTR)ip;
	POSITION pos;
	if (m_ClientInfoList.GetCount()!=0)
	{
		for( pos = m_ClientInfoList.GetHeadPosition(); pos != NULL; )
		{				
			CClientInfo *pClientInfo=m_ClientInfoList.GetAt(pos);
			strIP.Format("%d.%d.%d.%d",
			pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b1,
			pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b2,
			pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b3,
			pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b4);
			if (strIP==ssIP)
			{
				AfxMessageBox(strIP+" have been joined in!");
				if (pClientInfo!=NULL)
				{
					pClientInfo=NULL;
					delete pClientInfo;
				}
				return FALSE;
				
			}
			m_ClientInfoList.GetNext(pos);
		}// end of for                                                			
	}

	SetCmdDst(ip,port);
	SetAVDst(ip,port+1);
	PACK_CMD pc;	
	pc.flag=FLAG_CMD;
	for (int i=0;i<MAX_CONNECT_USER;i++)
	{
		if (ssIP==sIP[i])
		{
			pc.m_ChatNo=m_ChatNo[i];
		}
	}	
	pc.cmd=CMD_JOIN;
	pc.type=0;
	pc.data_size_extra=0;
	pc.ext=VER_TVMEETING&0xff;//AVIO 的版本
	char sz[50];
	m_sockaddr=GetCurrentAddr();
	sprintf(sz,"%d.%d.%d.%d",
	m_sockaddr.sin_addr.S_un.S_un_b.s_b1,
	m_sockaddr.sin_addr.S_un.S_un_b.s_b2,
	m_sockaddr.sin_addr.S_un.S_un_b.s_b3,
	m_sockaddr.sin_addr.S_un.S_un_b.s_b4);
	if(!SendCmd(&pc,sizeof(pc),m_Cmddst,TRUE))
	{
		return FALSE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -