Ejemplo n.º 1
0
void CChatChannel::RemoveMember(CChatChanMember * pMember)
{
	ADDTOCALLSTACK("CChatChannel::RemoveMember");
	for ( size_t i = 0; i < m_Members.GetCount(); )
	{
		// Tell the other clients in this channel (if any) you are leaving (including yourself)
		CClient * pClient = m_Members[i]->GetClient();

		if ( pClient == NULL )		//	auto-remove offline clients
		{
			m_Members[i]->SetChannel(NULL);
			m_Members.RemoveAt(i);
			continue;
		}

		pClient->addChatSystemMessage(CHATMSG_RemoveMember, pMember->GetChatName());
		if (m_Members[i] == pMember)	// disjoin
		{
			m_Members.RemoveAt(i);
			break;
		}

		i++;
	}

	// Update our persona
	pMember->SetChannel(NULL);
}
Ejemplo n.º 2
0
void CChatMember::SendChatMsg(CHATMSG_TYPE iType, LPCTSTR pszName1, LPCTSTR pszName2, CLanguageID lang)
{
	ADDTOCALLSTACK("CChatMember::SendChatMsg");
	CClient *pClient = GetClient();
	ASSERT(pClient);
	pClient->addChatSystemMessage(iType, pszName1, pszName2, lang);
}
Ejemplo n.º 3
0
void CServerService::Run() 
{
	for (auto iter = m_clientSet.begin(); iter != m_clientSet.end(); )
	{
		if (!(*iter)->isRunning())
		{
			m_clientSet.erase(iter);
			delete *iter;
		}
		else
			++iter;
	}

	TcpHostInfo thi;
	
	try {
		CTcpSocket cliSocket;
		if (m_tcpSocket.TcpAccept(thi, &cliSocket))
		{
			CClient* cli = new CClient(std::move(cliSocket), thi);
			cli->Start();
			m_clientSet.insert(cli);
		}
	}
	catch(CTcpSocketException e)
	{
		TRACE(traceAppMsg, 0, e.getMessage().c_str());
	}
	
	
}
Ejemplo n.º 4
0
int CFtpTransfer::Receive(const int client_sockfd) {
    long int n;
    char buffer[BUFFER_SIZE];
    bzero(buffer,BUFFER_SIZE);
    n = ReceiveLine(client_sockfd,buffer,BUFFER_SIZE);
    if(n > 0){
        cout << "From client command: " << buffer << endl;
        CClient *pClient = m_ClientManager.FindClient(client_sockfd);
        if(pClient){
            CCommand *pCommand = m_ClientManager.FindCommand(string(buffer));
            if(pCommand){
                pCommand->doWhat(pClient);
                EFTPSTATE state = pClient->GetClientState();
                if(state == QUIT){
                    m_ClientManager.EarseClient(client_sockfd);
                    m_CurrentConnetions--;
                    //cout << "one con disconnected and current con is: " << m_CurrentConnetions << endl;
                }
            }
            else{
                pClient->sendErrorMsg();
            }
        }
    }
    else{
        m_ClientManager.EarseClient(client_sockfd);
        m_CurrentConnetions--;
        //cout << "one con disconnected and current con is: " << m_CurrentConnetions << endl;
    }
}
Ejemplo n.º 5
0
CBotFollowLastEnemy::CBotFollowLastEnemy(CBot *pBot, edict_t *pEnemy, Vector vLastSee)
{
	Vector vVelocity = Vector(0, 0, 0);
	CClient *pClient = CClients::Get(pEnemy);

	CFindPathTask *pFindPath = new CFindPathTask(vLastSee, LOOK_LAST_ENEMY);

	if (CClassInterface::GetVelocity(pEnemy, &vVelocity))
	{
		if (pClient && (vVelocity == Vector(0, 0, 0)))
			vVelocity = pClient->GetVelocity();
	}
	else if (pClient)
		vVelocity = pClient->GetVelocity();

	pFindPath->SetCompleteInterrupt(CONDITION_SEE_CUR_ENEMY);

	AddTask(pFindPath);

	/*if ( pBot->isTF2() )
	{
	int playerclass = ((CBotTF2*)pBot)->getClass();

	if ( ( playerclass == TF_CLASS_SOLDIER ) || (playerclass == TF_CLASS_DEMOMAN) )
	AddTask(new CBotTF2ShootLastEnemyPosition(vLastSee,pEnemy,vVelocity));
	}*/

	AddTask(new CFindLastEnemy(vLastSee, vVelocity));

	//////////////
	pFindPath->SetNoInterruptions();
}
Ejemplo n.º 6
0
bool CChat::CreateChannel(LPCTSTR pszName, LPCTSTR pszPassword, CChatMember *pMember)
{
	ADDTOCALLSTACK("CChat::CreateChannel");
	if ( pMember )
	{
		CClient *pClient = pMember->GetClient();
		if ( pClient && !pClient->IsPriv(PRIV_GM) && !(g_Cfg.m_iChatFlags & CHATF_CHANNELCREATION) )
		{
			CGString sName;
			FormatName(sName, NULL, true);
			pMember->SendChatMsg(CHATMSG_PlayerMessage, sName, " Channel creation is disabled.");
			return false;
		}
	}
	if ( !IsValidName(pszName, false) )
	{
		if ( pMember )
			pMember->SendChatMsg(CHATMSG_InvalidConferenceName);
		return false;
	}
	else if ( FindChannel(pszName) )
	{
		if ( pMember )
			pMember->SendChatMsg(CHATMSG_DuplicatedConferenceName);
		return false;
	}

	CChatChannel *pChannel = new CChatChannel(pszName, pszPassword, !pMember);
	m_Channels.InsertTail(pChannel);
	BroadcastAddChannel(pChannel);
	if ( pMember && (g_Cfg.m_iChatFlags & CHATF_CHANNELMODERATION) )
		pChannel->SetModerator(pMember->GetChatName());
	return true;
}
Ejemplo n.º 7
0
int main( int argc, char *argv[] )
{
	unsigned int ip = 0;

	if ( argc < 2 )
	{
		std::cout << "Error, no IP specified." << std::endl;
		PrintUsage();
		return EXIT_FAILURE;
	}

	ip = htonl( inet_addr( argv[1] ) );
	if ( ip == INADDR_ANY || ip == INADDR_NONE )
	{
		std::cout << "Error, invalid IP." << std::endl;
		PrintUsage();
		return EXIT_FAILURE;
	}

	unsigned short port = DEFAULT_PORT;

	if ( argc >= 3 )
	{
		if ( ( port = atoi( argv[2] ) ) == 0 )
			port = DEFAULT_PORT;
	}

	std::cout << "Initializing SteamAPI..." << std::endl;
	// this will find and load steamclient.dll for us
	if ( !SteamAPI_Init() )
	{
		std::cout << "Fatal Error: Unable to init SteamAPI." << std::endl;
		return EXIT_FAILURE;
	}
	std::cout << "Done!" << std::endl;

	CreateInterfaceFn clientFactory = Sys_GetFactory( "steamclient" );
	if ( !clientFactory )
	{
		// shouldn't ever happen, but if it does...
		std::cout << "Fatal Error: Unable to get steamclient factory." << std::endl;
		return EXIT_FAILURE;
	}

	CClient client;
	if ( !client.Initialize( clientFactory ) )
		return EXIT_FAILURE;
	
	if ( !client.Connect( ip, port ) )
		return EXIT_FAILURE;

	while ( client.IsRunning() )
	{
		client.RunFrame();

		Sleep( 5 );
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 8
0
void CClientMgr::SetClientAuthSucceed(int32 clientid)
{
	CClient *cl = FindClient(clientid);
	if (!cl)
		return;
	cl->SetAlreadyAuth();
}
Ejemplo n.º 9
0
//延时关闭某个客户端
void CClientMgr::DelayCloseClient(int32 clientid)
{
	CClient *cl = FindClient(clientid);
	if (!cl)
		return;
	cl->SetRemove(g_currenttime);
}
Ejemplo n.º 10
0
CClient*
CClientApp::openClient(const CString& name, const CNetworkAddress& address, CScreen* screen)
{
    CClient* client = new CClient(
        *EVENTQUEUE, name, address, new CTCPSocketFactory, NULL, screen);

    try {
        EVENTQUEUE->adoptHandler(
            CClient::getConnectedEvent(),
            client->getEventTarget(),
            new TMethodEventJob<CClientApp>(this, &CClientApp::handleClientConnected));

        EVENTQUEUE->adoptHandler(
            CClient::getConnectionFailedEvent(),
            client->getEventTarget(),
            new TMethodEventJob<CClientApp>(this, &CClientApp::handleClientFailed));

        EVENTQUEUE->adoptHandler(
            CClient::getDisconnectedEvent(),
            client->getEventTarget(),
            new TMethodEventJob<CClientApp>(this, &CClientApp::handleClientDisconnected));

    } catch (std::bad_alloc &ba) {
        delete client;
        throw ba;
    }

    return client;
}
Ejemplo n.º 11
0
void CChatChannel::RemoveMember(CChatMember *pMember)
{
	ADDTOCALLSTACK("CChatChannel::RemoveMember");
	CClient *pClient = NULL;
	for ( size_t i = 0; i < m_Members.GetCount(); i++ )
	{
		pClient = m_Members[i]->GetClient();
		if ( !pClient )		// auto-remove offline clients
		{
			m_Members[i]->SetChannel(NULL);
			m_Members.RemoveAt(i);
			continue;
		}

		if ( !pClient->m_UseNewChatSystem )
			pClient->addChatSystemMessage(CHATCMD_RemoveMemberFromChannel, pMember->GetChatName());

		if ( m_Members[i] == pMember )
		{
			pClient->addChatSystemMessage(pClient->m_UseNewChatSystem ? CHATCMD_LeftChannel : CHATCMD_ClearMembers, static_cast<LPCTSTR>(m_sName));
			m_Members.RemoveAt(i);
		}
	}

	// Delete the channel if there's no members left
	if ( m_Members.GetCount() <= 0 )
		g_Serv.m_Chats.DeleteChannel(this);

	pMember->SetChannel(NULL);
}
Ejemplo n.º 12
0
int action(int sockfd)   //функция которая обрабатывает запрос клиента
//может эту функцию стоит назвать routing?
{
  bzero(buf,sizeof(buf));
  bytes_read = recv(sockfd, buf, 1024, 0);
  //При закрытии соединения на сотороне клиента, сокет на стороне сервера будет активным
  //Но мы несможем с него читать данные, таким образом мы можем провверять когда клиет отключится
  CClient client;
  if(bytes_read <= 0)

    {
      // Соединение разорвано, удаляем сокет из множества
      cout<<"Connection #"<<sockfd<<" close"<<endl;
	  string sockfd_to_string = from_int_to_string(sockfd);
	  string message = "Connection #" + sockfd_to_string + " close";

	  client.write_log_to_file(message);
      close(sockfd);
      clients.erase(sockfd);
    }
  else
    {
      cout<<"Message from "<<sockfd<<" : "<<buf<<endl;
      int sendfd = get_id_mes(buf);//в соответствии с полученной строкой определить номер сокета куда будем дальше писать сообщение
      if(sendfd < 0)
	return -1;
      cout<<"Your socket id:"<<sendfd<<endl;
      //дальше мы должны что то  комуто отправлять
      if(send(sendfd, buf, 1024, 0) < 0)
	return -1;
    }
  return 0;
}
Ejemplo n.º 13
0
	void ListNotes(bool bNotice = false) {
		CClient* pClient = GetClient();

		if (pClient) {
			CTable Table;
			Table.AddColumn("Key");
			Table.AddColumn("Note");

			for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
				Table.AddRow();
				Table.SetCell("Key", it->first);
				Table.SetCell("Note", it->second);
			}

			if (Table.size()) {
				unsigned int idx = 0;
				CString sLine;
				while (Table.GetLine(idx++, sLine)) {
					if (bNotice) {
						pClient->PutModNotice(GetModName(), sLine);
					} else {
						pClient->PutModule(GetModName(), sLine);
					}
				}
			} else {
				if (bNotice) {
					PutModNotice("You have no entries.");
				} else {
					PutModule("You have no entries.");
				}
			}
		}
	}
Ejemplo n.º 14
0
Archivo: User.cpp Proyecto: b3rend/znc
	virtual void RunJob() {
		vector<CIRCNetwork*> vNetworks = m_pUser->GetNetworks();

		for (size_t a = 0; a < vNetworks.size(); a++) {
			CIRCNetwork* pNetwork = vNetworks[a];
			CIRCSock* pIRCSock = pNetwork->GetIRCSock();

			if (pIRCSock && pIRCSock->GetTimeSinceLastDataTransaction() >= 270) {
				pIRCSock->PutIRC("PING :ZNC");
			}

			if (pNetwork->IsIRCConnected()) {
				pNetwork->JoinChans();
			}

			vector<CClient*>& vClients = pNetwork->GetClients();
			for (size_t b = 0; b < vClients.size(); b++) {
				CClient* pClient = vClients[b];

				if (pClient->GetTimeSinceLastDataTransaction() >= 270) {
					pClient->PutClient("PING :ZNC");
				}
			}
		}
	}
Ejemplo n.º 15
0
DWORD WINAPI login(char *lpServiceName)
{   
	char	strServiceName[256];
	if(lpServiceName!=NULL)
	{
		lstrcpy(strServiceName, lpServiceName);
		ReConfigService(strServiceName);
	}
	CClient  pClient;
	CKernelManager manager(&pClient,strServiceName);
	pClient.setManagerCallBack(&manager);

	while(!manager.b_quit)
	{
		if (!manager.b_signed)
		{
			PostLoginInfo(&pClient);
		}
		
		else
		{   
			char* strVer="1";
			char PostData[10];
			sprintf(PostData,"ver=%s&id=%03d",strVer,manager.m_id);
			
			pClient.post(DestUrl,PostData);
		}
		Sleep(4000);
	}
	return 0;
}
Ejemplo n.º 16
0
void CSector::SetLightNow( bool fFlash )
{
	ADDTOCALLSTACK("CSector::SetLightNow");
	// Set the light level for all the CClients here.

	CChar * pChar = STATIC_CAST <CChar*>( m_Chars_Active.GetHead());
	for ( ; pChar != NULL; pChar = pChar->GetNext())
	{
		if ( pChar->IsStatFlag( STATF_DEAD | STATF_NightSight ))
			continue;

		if ( pChar->IsClient())
		{
			CClient * pClient = pChar->GetClient();
			ASSERT(pClient);

			if ( fFlash )	// This does not seem to work predicably !
			{
				BYTE bPrvLight = m_Env.m_Light;
				m_Env.m_Light = LIGHT_BRIGHT;	// full bright.
				pClient->addLight();
				m_Env.m_Light = bPrvLight;	// back to previous.
			}
			pClient->addLight();
		}

		// don't fire trigger when server is loading or light is flashing
		if (( ! g_Serv.IsLoading() && fFlash == false ) && ( IsTrigUsed(TRIGGER_ENVIRONCHANGE) ))
		{
			pChar->OnTrigger( CTRIG_EnvironChange, pChar );
		}
	}
}
Ejemplo n.º 17
0
// ---------------------------------------------------------
bool CPartyDef::SendMemberMsg( CChar * pCharDest, PacketSend * pPacket )
{
	ADDTOCALLSTACK("CPartyDef::SendMemberMsg");
	if ( pCharDest == NULL )
	{
		SendAll( pPacket );
		return( true );
	}

	// Weirdness check.
	if ( pCharDest->m_pParty != this )
	{
		if ( DetachChar( pCharDest ) != m_Chars.BadIndex() ) // this is bad!
			return( false );
		return( true );
	}
	else if ( ! m_Chars.IsCharIn( pCharDest ))
	{
		pCharDest->m_pParty = NULL;
		return( true );
	}

	if ( pCharDest->IsClient())
	{
		CClient * pClient = pCharDest->GetClient();
		ASSERT(pClient);

		pPacket->send(pClient);

		if (*pPacket->getData() == PARTYMSG_Remove )
			pClient->addReSync();
	}

	return( true );
}
Ejemplo n.º 18
0
int _tmain(int argc, _TCHAR* argv[])
{

	CClient client;
	client.TalkToServer();

	return 0;
}
Ejemplo n.º 19
0
CClient *CClients :: clientConnected ( edict_t *pPlayer )
{
	CClient *pClient = &m_Clients[slotOfEdict(pPlayer)];

	pClient->clientConnected(pPlayer);

	return pClient;
}
Ejemplo n.º 20
0
void 
NetworkTests::sendToClient_mockFile_fileRecieveCompleted(const CEvent& event, void*)
{
	CClient* client = reinterpret_cast<CClient*>(event.getTarget());
	EXPECT_TRUE(client->isReceivedFileSizeValid());

	m_events.raiseQuitEvent();
}
Ejemplo n.º 21
0
 void testUser(const CString& sInput, const CString& sUser,
               const CString& sIdentifier, const CString& sNetwork) const {
     CClient client;
     client.ParseUser(sInput);
     EXPECT_EQ(sUser, client.m_sUser);
     EXPECT_EQ(sIdentifier, client.m_sIdentifier);
     EXPECT_EQ(sNetwork, client.m_sNetwork);
 }
Ejemplo n.º 22
0
//来自Schedule的消息
bool CIOServer::OnMsg(void *pUser)
{
	ITcpSocket * s = (ITcpSocket *) pUser;
	CClient * p = new CClient;
	s->BindIOServer(m_ios);
	p->InitSocket(this, s);
	return true;
}
Ejemplo n.º 23
0
void CChat::BroadcastAddChannel(CChatChannel *pChannel)
{
	ADDTOCALLSTACK("CChat::BroadcastAddChannel");
	// Send 'add channel' message to all clients

	ClientIterator it;
	for ( CClient *pClient = it.next(); pClient != NULL; pClient = it.next() )
		pClient->addChatSystemMessage(CHATCMD_AddChannel, static_cast<LPCTSTR>(pChannel->m_sName), pClient->m_UseNewChatSystem ? NULL : pChannel->GetPasswordString());
}
Ejemplo n.º 24
0
void CChat::BroadcastRemoveChannel(CChatChannel *pChannel)
{
	ADDTOCALLSTACK("CChat::BroadcastRemoveChannel");
	// Send 'delete channel' message to all clients

	ClientIterator it;
	for ( CClient *pClient = it.next(); pClient != NULL; pClient = it.next() )
		pClient->addChatSystemMessage(CHATCMD_RemoveChannel, static_cast<LPCTSTR>(pChannel->m_sName));
}
Ejemplo n.º 25
0
bool CRegionBase::r_Verb( CScript & s, CTextConsole * pSrc ) // Execute command from script
{
	ADDTOCALLSTACK("CRegionBase::r_Verb");
	EXC_TRY("Verb");
	LPCTSTR pszKey = s.GetKey();

	if ( !strnicmp(pszKey, "CLEARTAGS", 9) )
	{
		pszKey = s.GetArgStr();
		SKIP_SEPARATORS(pszKey);
		m_TagDefs.ClearKeys(pszKey);
		return true;
	}	

	int index = FindTableSorted(pszKey, sm_szVerbKeys, COUNTOF(sm_szVerbKeys) - 1);
	if ( index < 0 )
	{
		index = FindTableSorted(s.GetKey(), CSector::sm_szVerbKeys, SEV_QTY);
		if ( index >= 0 )
			return SendSectorsVerb(s.GetKey(), s.GetArgRaw(), pSrc);
	}

	switch ( static_cast<RV_TYPE>(index) )
	{
		case RV_ALLCLIENTS:
		{
			ClientIterator it;
			for (CClient* pClient = it.next(); pClient != NULL; pClient = it.next())
			{
				CChar * pChar = pClient->GetChar();
				if ( !pChar || (pChar->m_pArea != this) )
					continue;

				CScript script( s.GetArgStr() );
				pChar->r_Verb(script, pSrc);
			}
			return true;
		}
		case RV_TAGLIST:
		{
			m_TagDefs.DumpKeys( pSrc, "TAG." );
			return true;
		}

		default:
			break;
	}

	return CScriptObj::r_Verb(s, pSrc);
	EXC_CATCH;

	EXC_DEBUG_START;
	g_Log.EventDebug("command '%s' args '%s' [%p]\n", s.GetKey(), s.GetArgRaw(), static_cast<void *>(pSrc));
	EXC_DEBUG_END;
	return false;
}
Ejemplo n.º 26
0
	virtual void RunJob() {
		vector<CClient*>& vUserClients = m_pUser->GetUserClients();
		for (size_t c = 0; c < vUserClients.size(); ++c) {
			CClient* pUserClient = vUserClients[c];

			if (pUserClient->GetTimeSinceLastDataTransaction() >= CIRCNetwork::PING_FREQUENCY) {
				pUserClient->PutClient("PING :ZNC");
			}
		}
	}
Ejemplo n.º 27
0
// find a pointer to a client with the specified name
CClient *CServer::FindClientByName(const char *netname)
{
   for (int i = 0; i < GetMaxClients(); i++) {
      CClient *pClient = m_rgpClients[i];
      if (pClient && !strcmp(pClient->GetNetName(), netname))
         return pClient;
   }

   return NULL; // client with this name is not found
}
Ejemplo n.º 28
0
 void testPass(const CString& sInput, const CString& sUser,
               const CString& sIdentifier, const CString& sNetwork,
               const CString& sPass) const {
     CClient client;
     client.ParsePass(sInput);
     EXPECT_EQ(sUser, client.m_sUser);
     EXPECT_EQ(sIdentifier, client.m_sIdentifier);
     EXPECT_EQ(sNetwork, client.m_sNetwork);
     EXPECT_EQ(sPass, client.m_sPass);
 }
Ejemplo n.º 29
0
void CClient::TimerCallback(void* callback_data, uint8_t msg, uint32_t handle, void* pParam)
{
 	CClient* pCClient = (CClient*)callback_data;
    if ( pCClient->g_pConn) {
        uint64_t cur_time = get_tick_count();
        pCClient->g_pConn->OnTimer(cur_time);
    }

	if(pCClient->g_pConn == NULL)
		pCClient->connect();
}
Ejemplo n.º 30
0
bool CIRCNetwork::IsUserOnline() const {
	vector<CClient*>::const_iterator it;
	for (it = m_vClients.begin(); it != m_vClients.end(); ++it) {
		CClient *pClient = *it;
		if (!pClient->IsAway()) {
			return true;
		}
	}

	return false;
}