Esempio n. 1
0
void exec_cmd()
{
	if (g_cmd_num == 0) {
		return;
	}
    
    if(g_cmd_string[0] == "login")
    {
        if(g_cmd_num == 3)
        {
            doLogin(g_cmd_string[1], g_cmd_string[2]);
        }
        else
        {
            print_help();
        }
    }
    else if (strcmp(g_cmd_string[0].c_str(), "close") == 0) {
        g_pClient->close();
    }
    else if (strcmp(g_cmd_string[0].c_str(), "quit") == 0) {
		exit(0);

    }
    else if(strcmp(g_cmd_string[0].c_str(), "list") == 0)
    {
        printf("+---------------------+\n");
        printf("|        用户名        |\n");
        printf("+---------------------+\n");
        CMapNick2User_t mapUser = g_pClient->getNick2UserMap();
        auto it = mapUser.begin();
        for(;it!=mapUser.end();++it)
        {
            uint32_t nLen = 21 - it->first.length();
            printf("|");
            for(uint32_t i=0; i<nLen/2; ++it)
            {
                printf(" ");
            }
            printf("%s", it->first.c_str());
            for(uint32_t i=0; i<nLen/2; ++it)
            {
                printf(" ");
            }
            printf("|\n");
            printf("+---------------------+\n");
        }
    }
    else {
		print_help();
	}
}
Esempio n. 2
0
void exec_cmd()
{
	if (g_cmd_num == 0) {
		return;
	}
    
    if(g_cmd_string[0] == "login")
    {
        if(g_cmd_num == 3)
        {	
            char *enPass = 0;
            uint32_t enLen = 0;
            
            EncryptPass(g_cmd_string[2].c_str() , g_cmd_string[2].length(),&enPass , enLen , 0);
            string pass(enPass , enLen);
            Free(enPass);
            doLogin(g_cmd_string[1], pass);
        }
        else
        {
            print_help();
        }
    }
    else if(strcmp(g_cmd_string[0].c_str() , "sendmsg") == 0){
	do_sendmsg(atoi(g_cmd_string[1].c_str()) , atoi(g_cmd_string[2].c_str()) , g_cmd_string[3]);	
    }
    else if (strcmp(g_cmd_string[0].c_str(), "close") == 0) {
        g_pClient->close();
    }
    else if (strcmp(g_cmd_string[0].c_str(), "quit") == 0) {
		exit(0);

    }
    else if(strcmp(g_cmd_string[0].c_str() , "getChangedUser") == 0){
		do_getChangedUser();

	}
    else if(strcmp(g_cmd_string[0].c_str() , "getUnreadMsgCnt")== 0){
    	do_getUnreadMsgCnt();

	}
   else if(strcmp(g_cmd_string[0].c_str() , "getRecentSession")== 0){
        do_getRecentSession(); 

   }
   else if(strcmp(g_cmd_string[0].c_str() , "getUserInfo") == 0){
        
	list<uint32_t> lst;
    for( int i = 1 ; i < g_cmd_num  ; ++i)
	{
		lst.push_back(atoi(g_cmd_string[i].c_str()));
	}
    g_pClient->getUserInfo(lst);

}
    else if(strcmp(g_cmd_string[0].c_str(), "list") == 0)
    {
    
        CMapNick2User_t mapUser = g_pClient->getNick2UserMap();
		printf("%d users:\n" , mapUser.size());
        auto it = mapUser.begin();
        for(;it!=mapUser.end();++it)
        {
           printf("id:%d user:%s status:%d\n" , it->second->user_id() , it->second->user_real_name().c_str() , it->second->status());
        }
    }
	else if(strcmp(g_cmd_string[0].c_str(), "getDepartMentInfo") == 0)
	{
		g_pClient->getDepartMentInfo();
	}
	else if(strcmp(g_cmd_string[0].c_str(), "getGroupListInfo") == 0)
	{
		g_pClient->getGroupList();
	}
    else {
		print_help();
	}
}