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

📄 envinit.cpp

📁 网络转发器 用于运行在可以跨两个网段的机器上用来作为一个TCP应用层的一个桥
💻 CPP
字号:
#include "stdafx.h"
#include "afxsock.h"
#include "envInit.h"

#include "agentIni.h"

#include "../common/consoleTxtWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CConsoleTxtWnd2File *glo_pStatusWnd=NULL,*glo_pErrorWnd=NULL;
CAgentIni glo_iniAgent;
char glo_szAgentName[200]="net_agent";
HANDLE glo_hListenThread=NULL;
CSequenceGenerator *glo_pConnectionID=NULL;

CSequenceGenerator* GetConnectionIDSeq(void)
{
	return glo_pConnectionID;
}

LPCSTR GetAgentName(void)
{
	return glo_szAgentName;
}

void SetAgentName(LPCSTR pszName)
{
	ASSERT(pszName);
	strcpy(glo_szAgentName,pszName);
}

CAgentIni* GetAgentIni(void)
{
	return &glo_iniAgent;
}

CConsoleTxtWnd2File* GetConsoleWnd(int iID)
{
	if(iID==0)
		return glo_pStatusWnd;
	if(iID==1)
		return glo_pErrorWnd;
	return NULL;
}

void InitScreenLayout(void)
{
	for(int i=0;i<TXT_WND_WIDTH;i++)
	{
		CConsoleTxtWnd::PrintXY(i,0,"-",1);
	}
	for(i=0;i<TXT_WND_WIDTH;i++)
	{
		CConsoleTxtWnd::PrintXY(i,TXT_WND_HEIGHT-1,"-",1);
	}
	for(i=0;i<TXT_WND_WIDTH;i++)
	{
		CConsoleTxtWnd::PrintXY(i,15,"-",1);
	}
	for(i=0;i<TXT_WND_HEIGHT;i++)
	{
		CConsoleTxtWnd::PrintXY(0,i,"|",1);
	}
	for(i=0;i<TXT_WND_HEIGHT;i++)
	{
		CConsoleTxtWnd::PrintXY(TXT_WND_WIDTH-1,i,"|",1);
	}
	CString szTitle="代理线程状态";
	CConsoleTxtWnd::PrintXY(10,0,szTitle,szTitle.GetLength());
	szTitle="错误日志";
	CConsoleTxtWnd::PrintXY(10,15,szTitle,szTitle.GetLength());
}

void InitConsoleAndEnv(LPCSTR pszLogDir,LPCSTR pszName)
{
	char szScreen[200],szStatus[200],szError[200];
	sprintf(szScreen,"screen_%s",pszName);
	sprintf(szStatus,"sscreem_%s",pszName);
	sprintf(szError,"escreen_%s",pszName);
	glo_pStatusWnd=new CConsoleTxtWnd2File(NULL,1,1,TXT_WND_WIDTH-2,14,szScreen,pszLogDir,pszName);
	glo_pErrorWnd=new CConsoleTxtWnd2File(NULL,1,16,TXT_WND_WIDTH-2,8,szScreen,pszLogDir,pszName);
	
	glo_pConnectionID= new CSequenceGenerator(pszName,"connection_seq");
}

void ClearConsoleAndEnv(void)
{
	delete glo_pErrorWnd;
	delete glo_pStatusWnd;
	delete glo_pConnectionID;
}

//初始化,读取设置
BOOL InitIniInfo(LPCSTR pszName)
{
	glo_iniAgent.SetName(pszName);
	glo_iniAgent.SetFile(".\\netAgent.ini");
	BOOL fRet = glo_iniAgent.Init();
	GetConsoleWnd()->printf("[config] %s Started",glo_iniAgent.m_szDesc);
	GetConsoleWnd()->printf("[config] server=%s@%d local=%s@%d",
							glo_iniAgent.m_szServerIP,glo_iniAgent.m_iServerPort,glo_iniAgent.m_szLocalIP,glo_iniAgent.m_iLocalPort);
	GetConsoleWnd()->printf("[config] timeout=%d buffer=%d(bytes) debug=%s",
							glo_iniAgent.m_iTimeout,glo_iniAgent.m_iMaxLength,(glo_iniAgent.m_iDebugOut==1)?"Yes":"No");
	GetConsoleWnd()->printf("[config] record seq=%d,data will be saved to Data\\%d_xxxxxx.txt",
							glo_iniAgent.m_iCurrentSeq,glo_iniAgent.m_iCurrentSeq);
	return fRet;
}

//创建等待线程
BOOL CreateListenThread(void)
{
	DWORD dwID;
	glo_hListenThread = CreateThread(NULL,0,
									(LPTHREAD_START_ROUTINE)NetworkListenThread,
									(LPVOID)&glo_iniAgent,
									0,&dwID);
	return glo_hListenThread != NULL;
}

HANDLE GetListenThreadHandle(void)
{
	return glo_hListenThread;
}

void CloseAllThreadHandle(void)
{
	CloseHandle(glo_hListenThread);
}

⌨️ 快捷键说明

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