bool KUser::CheckLogin(const char *user)
{
	KUser_int_map::iterator it;
	m_lock.Lock();
	for(it=m_user.begin();it!=m_user.end();it++){
		if((*it).second.user->user==user){
			m_lock.Unlock();
			return true;
		}
	}
	m_lock.Unlock();
	return false;
}
void KUser::SaveAll()
{	

	unsigned stay_time=0;
	KUser_int_map::iterator it;
	int now_time=time(NULL);
	m_lock.Lock();
	for(it=m_user.begin();it!=m_user.end();it++){
		(*it).second.user->total_time+=now_time-(*it).second.login_time;
	}
	m_lock.Unlock();	
	Save();
}
std::string KUser::ListLoginUser()
{
	stringstream s;
	int now_time=time(NULL);
//	std::vector<std::string> user_list;
	s << "<table><tr><td></td><td>user</td><td>from</td><td>stay time(sec)</td><td>inactive time(sec)</td></tr>\n";
	KUser_int_map::iterator it;
	m_lock.Lock();
	for(it=m_user.begin();it!=m_user.end();it++){
		s << "<tr><td><a href=/killloginuser?user="******">kill</a></td><td>" << (*it).second.user->user << "</td><td>" << make_ip((*it).first) << "</td><td>" << (now_time-(*it).second.login_time) << "</td><td>" << (now_time-(*it).second.last_active_time) << "</td></tr>\n";
	}
//		user_list.push_back((*it).second.user);
	m_lock.Unlock();
	s << "</table>";
	return s.str();
}
bool KUser::ForceLogout(const char *user,bool use_lock)
{
	KUser_int_map::iterator it;
	if(use_lock)
		m_lock.Lock();
	for(it=m_user.begin();it!=m_user.end();it++){
		if((*it).second.user->user==user){
			(*it).second.user->state=0;
			klog(RUN_LOG,"Force logou user %s success\n",(*it).second.user->user.c_str());
			m_user.erase(it);
			m_lock.Unlock();
			return true;
		}
	}
	if(use_lock)
		m_lock.Unlock();
	return false;
}
void KUser::FlushLoginUser()
{
	if(conf.user_time_out<=0)
		return;
	int now_time=time(NULL);
	KUser_int_map::iterator it;
	m_lock.Lock();
	for(it=m_user.begin();it!=m_user.end();){
		if(now_time-(*it).second.last_active_time>conf.user_time_out){
	#ifndef _WIN32
			(*it).second.user->state=0;
			m_user.erase(it);
			it++;
	#else
			it=m_user.erase(it);
	#endif
		}else{
			it++;
		}
	}
	m_lock.Unlock();
}