STATE StateNetwork::Update()
{
	if(m_pNetworkControler && (m_pNetworkControler->GetNetworkState() == CLIENT))
	{
		m_pNetworkControler->ReceivePacket();

		SmartPointer<PacketAddr> pAddr;
		if((pAddr = m_pNetworkControler->GetPacket()) != NULL)
		{
			if( pAddr->m_Packet.Protocolid() == CONNECT_REQ)
			{
				UserInfomationPacketMaker pkMaker;
				pkMaker.SetPacket(&pAddr->m_Packet);
				UserList lst = pkMaker.OutPutUserInformation();
				UserList::iterator iter;
				for(iter = lst.begin(); iter != lst.end(); iter++)
				{
					//여기에다가 이미 존재하는 유져가 있을경우 AddUser를 호출하지 않게 만들어야 함...
					m_pNetworkControler->AddUser((*iter));
					delete (*iter);
				}
				lst.clear();

				m_pNetworkControler->SetMyUserID(pAddr->m_Packet.ID());
				return STATE_WAITINGROOM;
			}
		}
	}

	if(m_bSelectState)
		return STATE_WAITINGROOM;
	else
		return STATE_NONE;
}
示例#2
0
//向客户端发送所有的用户信息
void getUserList(sockaddr_in sender)
{
	int len = (int)clientList.size();
	sendto(primarySock,(const char *)&len,sizeof(len),0,(SOCKADDR *)&sender,sizeof(sender));
	for(UserList::iterator UserIterator = clientList.begin(); UserIterator != clientList.end(); ++UserIterator)
	{
		sendto(primarySock,(const char *)(*UserIterator),sizeof(stUserListNode),0,(SOCKADDR *)&sender,sizeof(sender));
	}
}
示例#3
0
stUserListNode GetUser(char *username)
{
	for(UserList::iterator UserIterator=ClientList.begin();
						UserIterator!=ClientList.end();
							++UserIterator)
	{
		if( strcmp( ((*UserIterator)->userName), username) == 0 )
			return *(*UserIterator);
	}
	throw Exception("not find this user");
}
示例#4
0
void UploadQueueFrame::removeSelected() {
	int i = -1;
	UserList RemoveUsers;
	while((i = ctrlList.GetNextItem(i, LVNI_SELECTED)) != -1) {
		// Ok let's cheat here, if you try to remove more users here is not working :(
		RemoveUsers.push_back(((UploadQueueItem*)ctrlList.getItemData(i))->getUser());
	}
	for(auto i = RemoveUsers.begin(); i != RemoveUsers.end(); ++i) {
		UploadManager::getInstance()->clearUserFiles(*i, true);
	}
	updateStatus();
}
示例#5
0
stUserListNode GetUser(char *userName)
{
	for (auto ClientList_iter = ClientList.begin(); ClientList_iter != ClientList.end(); ++ClientList_iter)
	{
		if (strcmp((*ClientList_iter)->userName, userName) == 0)
			return *(*ClientList_iter);
	}
	
	std::cout << "can not find user: " << userName << std::endl;

	exit(0);
}
示例#6
0
void removeUser(char *name)
{
	stUserListNode *removeNode;
	
	removeNode = getUser(name);
	clientList.remove(removeNode);
	for(UserList::iterator UserIterator = clientList.begin(); UserIterator != clientList.end(); ++UserIterator)
	{
		stUserListNode *tmpNode = (stUserListNode *)(*UserIterator);
		u_long ip = htonl(tmpNode->ip);
		cout << "username :"******" ip:"<<inet_ntoa(*(in_addr *)&ip) <<" port:"<<tmpNode->port <<endl;
	}
}
示例#7
0
stUserListNode* getUser(char *name)
{
	stUserListNode *node = NULL;
	stUserListNode *removeNode = NULL;
	for(UserList::iterator UserIterator = clientList.begin(); UserIterator != clientList.end(); ++UserIterator)
	{
		node = (stUserListNode *)(*UserIterator);
		if(strcmp(node->stUserName,name) == 0)
		{
			removeNode = node;
			break;
		}
	}
	return removeNode;
}
示例#8
0
 /**
	用户登陆时,记录用户信息
	并输出所有登陆的用户信息
*/
void clientLogin(stMessage *message, sockaddr_in *sender)
{
	cout << "client connected :" << message->message.loginMessage.stUserName <<endl;
	stUserListNode *node = new stUserListNode;
	strcpy(node->stUserName,message->message.loginMessage.stUserName);
	node->ip = ntohl(sender->sin_addr.S_un.S_addr);
	
	node->port = ntohs(sender->sin_port);
	clientList.push_back(node);
	cout << "total client is " << clientList.size() <<endl;
	for(UserList::iterator UserIterator = clientList.begin(); UserIterator != clientList.end(); ++UserIterator)
	{
		stUserListNode *tmpNode = (stUserListNode *)(*UserIterator);
		u_long ip = htonl(tmpNode->ip);
		cout << "username :"******" ip:"<<inet_ntoa(*(in_addr *)&ip) <<" port:"<<tmpNode->port <<endl;
	}
}
示例#9
0
文件: EditUsers.C 项目: DTidd/wt
void EditUsers::limitList()
{
  WContainerWidget* list = new WContainerWidget;
  bindWidget("user-list",list);

  typedef dbo::collection<dbo::ptr<User> > UserList;
  dbo::Transaction t(session_);
  UserList users = session_.find<User>().where("name like ?").bind("%"+limitEdit_->text()+"%").orderBy("name");

  for (UserList::const_iterator i = users.begin(); i != users.end(); ++i) {
    WText* t = new WText((*i)->name, list);
    t->setStyleClass("link");
    new WBreak(list);
    t->clicked().connect(boost::bind(&EditUsers::onUserClicked, this, (*i).id()));
  }
  if (!users.size())
    new WText(tr("no-users-found"),list);
}
示例#10
0
bool DeadObjectElimination::processAllocStack(AllocStackInst *ASI) {
  // Trivial types don't have destructors. Let's try to zap this AllocStackInst.
  if (!ASI->getElementType().isTrivial(ASI->getModule()))
    return false;

  UserList UsersToRemove;
  if (hasUnremovableUsers(ASI, UsersToRemove)) {
    DEBUG(llvm::dbgs() << "    Found a use that cannot be zapped...\n");
    return false;
  }

  // Remove the AllocRef and all of its users.
  removeInstructions(
    ArrayRef<SILInstruction*>(UsersToRemove.begin(), UsersToRemove.end()));
  DEBUG(llvm::dbgs() << "    Success! Eliminating alloc_stack.\n");

  ++DeadAllocStackEliminated;
  return true;
}
示例#11
0
bool DeadObjectElimination::processAllocRef(AllocRefInst *ARI) {
  // Ok, we have an alloc_ref. Check the cache to see if we have already
  // computed the destructor behavior for its SILType.
  bool HasSideEffects;
  SILType Type = ARI->getType();
  auto CacheSearchResult = DestructorAnalysisCache.find(Type);
  if (CacheSearchResult != DestructorAnalysisCache.end()) {
    // Ok we found a value in the cache.
    HasSideEffects = CacheSearchResult->second;
  } else {
    // We did not find a value in the cache for our destructor. Analyze the
    // destructor to make sure it has no side effects. For now this only
    // supports alloc_ref of classes so any alloc_ref with a reference type
    // that is not a class this will return false for. Once we have analyzed
    // it, set Behavior to that value and insert the value into the Cache.
    //
    // TODO: We should be able to handle destructors that do nothing but release
    // members of the object.
    HasSideEffects = doesDestructorHaveSideEffects(ARI);
    DestructorAnalysisCache[Type] = HasSideEffects;
  }

  if (HasSideEffects) {
    DEBUG(llvm::dbgs() << " Destructor had side effects. \n");
    return false;
  }

  // Our destructor has no side effects, so if we can prove that no loads
  // escape, then we can completely remove the use graph of this alloc_ref.
  UserList UsersToRemove;
  if (hasUnremovableUsers(ARI, UsersToRemove)) {
    DEBUG(llvm::dbgs() << "    Found a use that cannot be zapped...\n");
    return false;
  }

  // Remove the AllocRef and all of its users.
  removeInstructions(
    ArrayRef<SILInstruction*>(UsersToRemove.begin(), UsersToRemove.end()));
  DEBUG(llvm::dbgs() << "    Success! Eliminating alloc_ref.\n");

  ++DeadAllocRefEliminated;
  return true;
}
示例#12
0
LRESULT UploadQueueFrame::onRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	if(usingUserMenu) {
		UserPtr User = getSelectedUser();
		if(User) {
			UploadManager::getInstance()->clearUserFiles(User);
		}
	} else {
		int i = -1;
		UserList RemoveUsers;
		while((i = ctrlList.GetNextItem(i, LVNI_SELECTED)) != -1) {
			RemoveUsers.push_back(((UploadQueueItem*)ctrlList.getItemData(i))->getUser());
		}
		for(UserList::const_iterator i = RemoveUsers.begin(); i != RemoveUsers.end(); ++i) {
			UploadManager::getInstance()->clearUserFiles(*i);
		}
	}
	updateStatus();
	return 0;
}
示例#13
0
/* ****************************************************************************
 * Limit List
 */
void EditUsers::LimitList()
{
    Wt::WContainerWidget* list = new Wt::WContainerWidget;
    bindWidget("user-list",list);

    typedef Wt::Dbo::collection<Wt::Dbo::ptr<User> > UserList;
    Wt::Dbo::Transaction t(session_);
    UserList users = session_.find<User>().where("name like ?").bind("%"+limitEdit_->text()+"%").orderBy("name");

    Wt::WSignalMapper<Wt::Dbo::dbo_traits<User>::IdType >* userLinkMap = new Wt::WSignalMapper<Wt::Dbo::dbo_traits<User>::IdType >(this);
    userLinkMap->mapped().connect(this,&EditUsers::OnUserClicked);
    for (UserList::const_iterator i = users.begin(); i != users.end(); ++i)
    {
        Wt::WText* t = new Wt::WText((*i)->name, list);
        t->setStyleClass("link");
        new Wt::WBreak(list);
        userLinkMap->mapConnect(t->clicked(), (*i).id());
    }
    if (!users.size())
    {
        new Wt::WText(tr("no-users-found"),list);
    }
} // end void EditUsers::LimitList
示例#14
0
int main(int argc, char* argv[])
{
	try{
		InitWinSock();
		
		SOCKET PrimaryUDP;
		PrimaryUDP = mksock(SOCK_DGRAM);

		sockaddr_in local;
		local.sin_family=AF_INET;
		local.sin_port= htons(SERVER_PORT); 
		local.sin_addr.s_addr = htonl(INADDR_ANY);
		int nResult=bind(PrimaryUDP,(sockaddr*)&local,sizeof(sockaddr));
		if(nResult==SOCKET_ERROR)
			throw Exception("bind error");

		sockaddr_in sender;
		stMessage recvbuf;
		memset(&recvbuf,0,sizeof(stMessage));

		// 开始主循环.
		// 主循环负责下面几件事情:
		// 一:读取客户端登陆和登出消息,记录客户列表
		// 二:转发客户p2p请求
		for(;;)
		{
			int dwSender = sizeof(sender);
			int ret = recvfrom(PrimaryUDP, (char *)&recvbuf, sizeof(stMessage), 0, (sockaddr *)&sender, &dwSender);
			if(ret <= 0)
			{
				printf("recv error");
				continue;
			}
			else
			{
				int messageType = recvbuf.iMessageType;
				switch(messageType){
				case LOGIN:
					{
						//  将这个用户的信息记录到用户列表中
						printf("has a user login : %s\n", recvbuf.message.loginmember.userName);
						stUserListNode *currentuser = new stUserListNode();
						strcpy(currentuser->userName, recvbuf.message.loginmember.userName);
						currentuser->ip = ntohl(sender.sin_addr.S_un.S_addr);
						currentuser->port = ntohs(sender.sin_port);
						
						ClientList.push_back(currentuser);
						
						// 发送已经登陆的客户信息
						int nodecount = (int)ClientList.size();
						sendto(PrimaryUDP, (const char*)&nodecount, sizeof(int), 0, (const sockaddr*)&sender, sizeof(sender));
						for(UserList::iterator UserIterator=ClientList.begin();
								UserIterator!=ClientList.end();
								++UserIterator)
						{
							sendto(PrimaryUDP, (const char*)(*UserIterator), sizeof(stUserListNode), 0, (const sockaddr*)&sender, sizeof(sender)); 
						}

						break;
					}
				case LOGOUT:
					{
						// 将此客户信息删除
						printf("has a user logout : %s\n", recvbuf.message.logoutmember.userName);
						UserList::iterator removeiterator = NULL;
						for(UserList::iterator UserIterator=ClientList.begin();
							UserIterator!=ClientList.end();
							++UserIterator)
						{
							if( strcmp( ((*UserIterator)->userName), recvbuf.message.logoutmember.userName) == 0 )
							{
								removeiterator = UserIterator;
								break;
							}
						}
						if(removeiterator != NULL)
							ClientList.remove(*removeiterator);
						break;
					}
				case P2PTRANS:
					{
						// 某个客户希望服务端向另外一个客户发送一个打洞消息
						printf("%s wants to p2p %s\n",inet_ntoa(sender.sin_addr),recvbuf.message.translatemessage.userName);
						stUserListNode node = GetUser(recvbuf.message.translatemessage.userName);
						sockaddr_in remote;
						remote.sin_family=AF_INET;
						remote.sin_port= htons(node.port); 
						remote.sin_addr.s_addr = htonl(node.ip);

						in_addr tmp;
						tmp.S_un.S_addr = htonl(node.ip);
						printf("the address is %s,and port is %d\n",inet_ntoa(tmp), node.port);

						stP2PMessage transMessage;
						transMessage.iMessageType = P2PSOMEONEWANTTOCALLYOU;
						transMessage.iStringLen = ntohl(sender.sin_addr.S_un.S_addr);
						transMessage.Port = ntohs(sender.sin_port);
                        
						sendto(PrimaryUDP,(const char*)&transMessage, sizeof(transMessage), 0, (const sockaddr *)&remote, sizeof(remote));

						break;
					}
				
				case GETALLUSER:
					{
						int command = GETALLUSER;
						sendto(PrimaryUDP, (const char*)&command, sizeof(int), 0, (const sockaddr*)&sender, sizeof(sender));

						int nodecount = (int)ClientList.size();
						sendto(PrimaryUDP, (const char*)&nodecount, sizeof(int), 0, (const sockaddr*)&sender, sizeof(sender));

						for(UserList::iterator UserIterator=ClientList.begin();
								UserIterator!=ClientList.end();
								++UserIterator)
						{
							sendto(PrimaryUDP, (const char*)(*UserIterator), sizeof(stUserListNode), 0, (const sockaddr*)&sender, sizeof(sender)); 
						}
						break;
					}
				}
			}
		}

	}
	catch(Exception &e)
	{
		printf(e.GetMessage());
		return 1;
	}

	return 0;
}
示例#15
0
/**
 * Do the actual DCOP call
 */
int runDCOP(KStringList args, UserList users, Session session, const QString sessionName, bool readStdin, bool updateUserTime)
{
    bool DCOPrefmode = false;
    QCString app;
    QCString objid;
    QCString function;
    KStringList params;
    DCOPClient *client = 0L;
    int retval = 0;
    if(!args.isEmpty() && args[0].find("DCOPRef(") == 0)
    {
        int delimPos = args[0].findRev(',');
        if(delimPos == -1)
        {
            cerr_ << "Error: '" << args[0] << "' is not a valid DCOP reference." << endl;
            exit(-1);
        }
        app = args[0].mid(8, delimPos - 8);
        delimPos++;
        objid = args[0].mid(delimPos, args[0].length() - delimPos - 1);
        if(args.count() > 1)
            function = args[1];
        if(args.count() > 2)
        {
            params = args;
            params.remove(params.begin());
            params.remove(params.begin());
        }
        DCOPrefmode = true;
    }
    else
    {
        if(!args.isEmpty())
            app = args[0];
        if(args.count() > 1)
            objid = args[1];
        if(args.count() > 2)
            function = args[2];
        if(args.count() > 3)
        {
            params = args;
            params.remove(params.begin());
            params.remove(params.begin());
            params.remove(params.begin());
        }
    }

    bool firstRun = true;
    UserList::Iterator it;
    QStringList sessions;
    bool presetDCOPServer = false;
    //    char *dcopStr = 0L;
    QString dcopServer;

    for(it = users.begin(); it != users.end() || firstRun; ++it)
    {
        firstRun = false;

        // cout_ << "Iterating '" << it.key() << "'" << endl;

        if(session == QuerySessions)
        {
            QStringList sessions = dcopSessionList(it.key(), it.data());
            if(sessions.isEmpty())
            {
                if(users.count() <= 1)
                {
                    cout_ << "No active sessions";
                    if(!(*it).isEmpty())
                        cout_ << " for user " << *it;
                    cout_ << endl;
                }
            }
            else
            {
                cout_ << "Active sessions ";
                if(!(*it).isEmpty())
                    cout_ << "for user " << *it << " ";
                cout_ << ":" << endl;

                QStringList::Iterator sIt = sessions.begin();
                for(; sIt != sessions.end(); ++sIt)
                    cout_ << "  " << *sIt << endl;

                cout_ << endl;
            }
            continue;
        }

        if(getenv("DCOPSERVER"))
        {
            sessions.append(getenv("DCOPSERVER"));
            presetDCOPServer = true;
        }

        if(users.count() > 1 || (users.count() == 1 && (getenv("DCOPSERVER") == 0 /*&& getenv( "DISPLAY" ) == 0*/)))
        {
            sessions = dcopSessionList(it.key(), it.data());
            if(sessions.isEmpty())
            {
                if(users.count() > 1)
                    continue;
                else
                {
                    cerr_ << "ERROR: No active KDE sessions!" << endl
                          << "If you are sure there is one, please set the $DCOPSERVER variable manually" << endl
                          << "before calling dcop." << endl;
                    exit(-1);
                }
            }
            else if(!sessionName.isEmpty())
            {
                if(sessions.contains(sessionName))
                {
                    sessions.clear();
                    sessions.append(sessionName);
                }
                else
                {
                    cerr_ << "ERROR: The specified session doesn't exist!" << endl;
                    exit(-1);
                }
            }
            else if(sessions.count() > 1 && session != AllSessions)
            {
                cerr_ << "ERROR: Multiple available KDE sessions!" << endl
                      << "Please specify the correct session to use with --session or use the" << endl
                      << "--all-sessions option to broadcast to all sessions." << endl;
                exit(-1);
            }
        }

        if(users.count() > 1 || (users.count() == 1 && (getenv("ICEAUTHORITY") == 0 || getenv("DISPLAY") == 0)))
        {
            // Check for ICE authority file and if the file can be read by us
            QString home = it.data();
            QString iceFile = it.data() + "/.ICEauthority";
            QFileInfo fi(iceFile);
            if(iceFile.isEmpty())
            {
                cerr_ << "WARNING: Cannot determine home directory for user " << it.key() << "!" << endl
                      << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
                      << "calling dcop." << endl;
            }
            else if(fi.exists())
            {
                if(fi.isReadable())
                {
                    char *envStr = strdup(("ICEAUTHORITY=" + iceFile).ascii());
                    putenv(envStr);
                    // cerr_ << "ice: " << envStr << endl;
                }
                else
                {
                    cerr_ << "WARNING: ICE authority file " << iceFile << "is not readable by you!" << endl
                          << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
                          << "calling dcop." << endl;
                }
            }
            else
            {
                if(users.count() > 1)
                    continue;
                else
                {
                    cerr_ << "WARNING: Cannot find ICE authority file " << iceFile << "!" << endl
                          << "Please check permissions or set the $ICEAUTHORITY"
                          << " variable manually before" << endl
                          << "calling dcop." << endl;
                }
            }
        }

        // Main loop
        // If users is an empty list we're calling for the currently logged
        // in user. In this case we don't have a session, but still want
        // to iterate the loop once.
        QStringList::Iterator sIt = sessions.begin();
        for(; sIt != sessions.end() || users.isEmpty(); ++sIt)
        {
            if(!presetDCOPServer && !users.isEmpty())
            {
                QString dcopFile = it.data() + "/" + *sIt;
                QFile f(dcopFile);
                if(!f.open(IO_ReadOnly))
                {
                    cerr_ << "Can't open " << dcopFile << " for reading!" << endl;
                    exit(-1);
                }

                QStringList l(QStringList::split('\n', f.readAll()));
                dcopServer = l.first();

                if(dcopServer.isEmpty())
                {
                    cerr_ << "WARNING: Unable to determine DCOP server for session " << *sIt << "!" << endl
                          << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
                          << "calling dcop." << endl;
                    exit(-1);
                }
            }

            delete client;
            client = new DCOPClient;
            if(!dcopServer.isEmpty())
                client->setServerAddress(dcopServer.ascii());
            bool success = client->attach();
            if(!success)
            {
                cerr_ << "ERROR: Couldn't attach to DCOP server!" << endl;
                retval = QMAX(retval, 1);
                if(users.isEmpty())
                    break;
                else
                    continue;
            }
            dcop = client;

            int argscount = args.count();
            if(DCOPrefmode)
                argscount++;
            switch(argscount)
            {
                case 0:
                    queryApplications("");
                    break;
                case 1:
                    if(endsWith(app, '*'))
                        queryApplications(app);
                    else
                        queryObjects(app, "");
                    break;
                case 2:
                    if(endsWith(objid, '*'))
                        queryObjects(app, objid);
                    else
                        queryFunctions(app, objid);
                    break;
                case 3:
                default:
                    if(updateUserTime)
                        sendUserTime(app);
                    if(readStdin)
                    {
                        KStringList::Iterator replaceArg = params.end();

                        KStringList::Iterator it = params.begin();
                        for(; it != params.end(); ++it)
                            if(*it == "%1")
                                replaceArg = it;

                        // Read from stdin until EOF and call function for each
                        // read line
                        while(!cin_.atEnd())
                        {
                            QString buf = cin_.readLine();

                            if(replaceArg != params.end())
                                *replaceArg = buf.local8Bit();

                            if(!buf.isNull())
                            {
                                int res = callFunction(app, objid, function, params);
                                retval = QMAX(retval, res);
                            }
                        }
                    }
                    else
                    {
                        // Just call function
                        //		    cout_ << "call " << app << ", " << objid << ", " << function << ", (params)" << endl;
                        int res = callFunction(app, objid, function, params);
                        retval = QMAX(retval, res);
                    }
                    break;
            }
            // Another sIt++ would make the loop infinite...
            if(users.isEmpty())
                break;
        }

        // Another it++ would make the loop infinite...
        if(it == users.end())
            break;
    }

    return retval;
}
示例#16
0
int main(int argc, char **argv)
{
	PrimaryUDP = socket(AF_INET, SOCK_DGRAM, 0);
	if (PrimaryUDP < 0)
	{
		std::cout << "创建 socket 失败!" << std::endl;
		return 0;
	}

	sockaddr_in addr;
	addr.sin_family = AF_INET;
	addr.sin_port = htons(SERVER_PORT);
	addr.sin_addr.s_addr = htonl(INADDR_ANY);
	if (bind(PrimaryUDP, (struct sockaddr*)&addr, sizeof(addr)) < 0)
	{
		std::cout << "bind socket failed!" << std::endl;
		return 0;
	}

	sockaddr_in sender;
	char buf[MAX_PACKET_SIZE] = {0};

	// 开始主循环
	// 1。读取客户端登陆和登出消息,记录客户端节点列表
	for ( ; ; )
	{
		stCommMsg* mRecvMsg = (stCommMsg*)buf;
		socklen_t nLen = sizeof (sender);
		int ret = recvfrom(PrimaryUDP, (char*)mRecvMsg , MAX_PACKET_SIZE, 0, (sockaddr*)&sender, &nLen);

		if (ret < 0)
		{
			std::cout << "recv error " << std::endl;
			continue;
		}
		else
		{
			unsigned int mMsgType = mRecvMsg->uiMsgType;
			switch (mMsgType)
			{
				case LOGIN:
					{
						std::cout << "has a client login, user name: " << mRecvMsg->cMyName << std::endl;
						stUserListNode* currentUser = new stUserListNode;
						memcpy(currentUser->userName, mRecvMsg->cMyName,MAX_NAME_SIZE);
						currentUser->uiIP = ntohl(sender.sin_addr.s_addr);
						currentUser->usPORT = ntohs(sender.sin_port);
						ClientList.push_back(currentUser);			//  do not exclude same name user

						char sendBuf[MAX_PACKET_SIZE] = {0};
						stCommMsg* sendbuf = (stCommMsg*) sendBuf;
						// 服务器应答消息
						sendbuf->uiMsgType = GETALLUSER;
						for (auto ClientList_iter = ClientList.begin(); ClientList_iter != ClientList.end(); ++ClientList_iter)
						{
							memcpy(sendbuf->userList[sendbuf->userNums].userName, (*ClientList_iter)->userName,MAX_NAME_SIZE);
							sendbuf->userList[sendbuf->userNums].uiIP = (*ClientList_iter)->uiIP;
							sendbuf->userList[sendbuf->userNums].usPORT = (*ClientList_iter)->usPORT;
							++sendbuf->userNums;
						}

						sendto(PrimaryUDP, (const char*)sendbuf, sendbuf->getSize(),0, 
								(const sockaddr*)&sender, sizeof(sender));
						break;
					}
				case LOGOUT:
					{
						std::cout << "has a client logout, name:" << mRecvMsg->cMyName << std::endl;
						for (auto ClientList_iter = ClientList.begin(); ClientList_iter != ClientList.end(); ++ClientList_iter)
						{
							if (strcmp((*ClientList_iter)->userName, mRecvMsg->cMyName) == 0)
							{
								ClientList_iter = ClientList.erase(ClientList_iter);
							}
						}

						break;
					}
				case GETALLUSER:
					{
						char sendBuf[MAX_PACKET_SIZE] = {0};
						stCommMsg* sendbuf = (stCommMsg*) sendBuf;
						// 服务器应答消息
						sendbuf->uiMsgType = GETALLUSER;
						for (auto ClientList_iter = ClientList.begin(); ClientList_iter != ClientList.end(); ++ClientList_iter)
						{
							memcpy(sendbuf->userList[sendbuf->userNums].userName, (*ClientList_iter)->userName,MAX_NAME_SIZE);
							sendbuf->userList[sendbuf->userNums].uiIP = (*ClientList_iter)->uiIP;
							sendbuf->userList[sendbuf->userNums].usPORT = (*ClientList_iter)->usPORT;
							++sendbuf->userNums;
						}

						sendto(PrimaryUDP, (const char*)sendbuf, sendbuf->getSize(),0, 
								(const sockaddr*)&sender, sizeof(sender));
						unsigned int nodecount = ClientList.size();
						std::cout << "want get all user list" << nodecount << std::endl;

						break;
					}
				case P2PTRANS:
					{
						//某个客户希望服务器向另一客户发送一“打洞”消息
						std::cout << mRecvMsg->cMyName << " wants to p2p with :" << mRecvMsg->cToName << std::endl;	
						stUserListNode user=GetUser(mRecvMsg->cToName);

						sockaddr_in remote;
						remote.sin_family=AF_INET;
						remote.sin_port=htons(user.usPORT);
						remote.sin_addr.s_addr=htonl(user.uiIP);

						in_addr temp;
						temp.s_addr=htonl(user.uiIP);
						printf("the address is %s,and the port is %d\n",inet_ntoa(temp),user.usPORT);

						stCommMsg mTransMsg;
						mTransMsg.uiMsgType = P2PSOMEONEWANTTOCALLYOU;
						mTransMsg.transMsg.uiIP = ntohl(sender.sin_addr.s_addr); 
						mTransMsg.transMsg.usPORT = ntohs(sender.sin_port);

						sendto(PrimaryUDP, (const char*)&mTransMsg, sizeof(stCommMsg),0,(const sockaddr*)&remote,sizeof(remote));

						break;
					}
			}
			
		}
	
	}


	return 0;
}