예제 #1
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
void RoomPool::ChatSetingChange(int userid, const MucRoomIdPtr& roomid, int set){
	RoomInfoPtr riptr;
	MucActiveUserSeq seq;
	MCE_DEBUG("RoomPool::ChatSetingChange --> userid = " << userid << " roomid = " << mucRoomIdToString(roomid) << " set = " << set);
	{
		IceUtil::RWRecMutex::RLock lock(_rwmutex);
		riptr = GetRoom(roomid);
		if(riptr){
			seq = riptr->GetActiveUserSeq(userid);
		}
	}
	if(seq.empty()){
		MCE_DEBUG("RoomPool::ChatSetingChange --> userid = " << userid << " roomid = " << mucRoomIdToString(roomid) << " set = " << set << " no MucActiveUserSeq");
		return;
	}
	JidSeq webjids;
	for(MucActiveUserSeq::iterator ait = seq.begin(); ait != seq.end(); ++ait){
		if('W' == (*ait)->jid->endpoint[0]){
			webjids.push_back((*ait)->jid);
		}
	}
	if(webjids.empty()){
		MCE_DEBUG("RoomPool::ChatSetingChange --> userid = " << userid << " roomid = " << mucRoomIdToString(roomid) << " set = " << set << " no webjids");
		return;
	}
	try{
		MucGateAdapter::instance().NotifyChatSetingChange(roomid, webjids, set);
	}catch(Ice::Exception& e){
		MCE_WARN("RoomPool::ChatSetingChange--> call MucGate.NotifyChatSetingChange ERR  line:"<<__LINE__<<" err:"<<e);
	}
	catch(std::exception& e){
		MCE_WARN("RoomPool::ChatSetingChange--> call MucGate.NotifyChatSetingChange ERR  line:"<<__LINE__<<" err:"<<e.what());
	}
}
예제 #2
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
void RoomPool::SetPermision(int opuser, Permisions permision, int targetuser, const MucRoomIdPtr& roomid){
  MCE_DEBUG("RoomPool::SetPermision --> opuser = "******" permision = " << permision << " targetuser = "******" roomname = " << roomid->roomname);
  MucActiveUserPtr opaptr;
  MucActiveUserSeq targetseq;
  JidSeq presenceUsers;
  RoomInfoPtr riptr;
  {
    IceUtil::RWRecMutex::WLock lock(_rwmutex);
    riptr = GetRoom(roomid);
    if(riptr){
      targetseq = riptr->GetActiveUserSeq(targetuser);
      riptr->SetPermision(targetuser, permision);
    }
  }
  if(riptr){
    IceUtil::RWRecMutex::RLock lock(_rwmutex);
    opaptr = riptr->GetActiveUser(opuser);
    if(opaptr){
      presenceUsers = riptr->GetAllActiveJids();
      if(permision == POutcast || permision == PNone){
				//如果是踢人的话,要把自己加上,notify self
        for(MucActiveUserSeq::iterator it = targetseq.begin(); it != targetseq.end(); ++it){
          presenceUsers.push_back((*it)->jid);
        }
      }
    }
  }
  if(riptr && opaptr && !presenceUsers.empty()){
    MucGateAdapter::instance().NotifySetPermision(opaptr, presenceUsers, targetseq, permision);
  }
}
예제 #3
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
bool RoomInfo::AwayRoom(int userid){
  bool awayok = false;
  JidPtr jid = new Jid();
  jid->userId = userid;
  jid->index = 0;
	

	JidSeq offlinejids;
  Jid2ActiveUserMap::iterator nit = _jid2activeuser.lower_bound(jid);
  for(; nit != _jid2activeuser.end(); ++nit){
    if(nit->second->jid->userId == userid){
      offlinejids.push_back(nit->second->jid);
			//TaskManager::instance().execute(new PageCacheNotifyTask("offline", userid, nit->second->identity->roomid));
      awayok = true;
    }
    else{
      break;
    }
  }
	for(JidSeq::iterator jit = offlinejids.begin(); jit != offlinejids.end(); ++jit){
		AwayRoom((*jit));
	}
  //MCE_DEBUG("RoomInfo::AwayRoom --> userid = " << userid << " awayok = " << awayok);
  return awayok;
}
예제 #4
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
bool RoomPool::SetPermisionForIM(int opuser, Permisions permision, int targetuser, const MucRoomIdPtr& roomid){
  bool setok = false;
  MucActiveUserPtr opaptr;
  MucActiveUserSeq targetseq;
  JidSeq presenceUsers;
  RoomInfoPtr riptr;
  {
    IceUtil::RWRecMutex::WLock lock(_rwmutex);
    riptr = GetRoom(roomid);
    if(riptr){
      targetseq = riptr->GetActiveUserSeq(targetuser);
      setok = riptr->SetPermisionForIM(opuser, permision, targetuser);
    }
    else{
      return false;
    }
  }
  if(setok){
    IceUtil::RWRecMutex::RLock lock(_rwmutex);
    opaptr = riptr->GetActiveUser(opuser);
    if(opaptr){
      presenceUsers = riptr->GetAllActiveJids();
      if(permision == POutcast || permision == PNone){
        for(MucActiveUserSeq::iterator it = targetseq.begin(); it != targetseq.end(); ++it){
          presenceUsers.push_back((*it)->jid);
        }
      }
    }
  }
  if(setok && opaptr && !presenceUsers.empty()){
    MucGateAdapter::instance().NotifySetPermision(opaptr, presenceUsers, targetseq, permision);
  }
  return setok;
}
예제 #5
0
파일: User.cpp 프로젝트: bradenwu/oce
bool User::remove(const string& endpoint, JidSeq &seq, NotifyType& type) {
	//MCE_WARN("User::remove --> " << endpoint);
	map<Ice::Long, list<AvatarPtr>::iterator >::iterator it = _avatars.begin();
	for (; it != _avatars.end();) {
		if ((*(it->second))->jid->endpoint != endpoint) {
			++it;
			continue;
		}
		seq.push_back((*(it->second))->jid);
		OnlineManagerI::instance().getPool((*(it->second))->jid->userId)->erase(it->second);
		_avatars.erase(it++);
	}
	OnlineStat oldStat = _onlineStat;
	if (!_avatars.empty()) {
		updateOnlineStatAndOnlineType((*(_avatars.begin()->second))->jid->userId);
	}
	if (!seq.empty()) {
		OnlineStat newStat = _onlineStat;
		if (oldStat==INVISIABLE && newStat==INVISIABLE) {
			type = AvatarToItsOtherAvatars;
		} else if (oldStat!=INVISIABLE && newStat!=INVISIABLE) {
			type = AvatarToAll;
		} else {
			type = AllAvatarsToBuddies;
		}
	}
	return _avatars.empty();
}
예제 #6
0
/*
void WebSession::handle() {
	MCE_DEBUG("WebSession::handle --> " << jidToString(_sessionJid));
	if (::time(NULL) - _timestamp >= MAX_DURATION) {
		WTalkProxyManagerI::instance().destroySession(this->_sessionJid);
	} else {
		if (_jidMap.empty()) {
			TaskManager::instance().schedule(this);
		}
	}
}
*/
JidSeq WebSession::getAccessJid() {
	JidSeq seq;
	for (map<Ice::Long,JidPtr>::iterator it = _jidMap.begin(); it
			!= _jidMap.end(); ++it) {
		seq.push_back(it->second);
	}
	return seq;
}
예제 #7
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
JidSeq RoomInfo::GetAllActiveJids(){
  JidSeq ans;
  Jid2ActiveUserMap::iterator nit = _jid2activeuser.begin();
  for(; nit != _jid2activeuser.end(); ++nit){
    if(POutcast != nit->second->permision && STATUSCODE_OFFLINE != nit->second->statuscode){
      ans.push_back(nit->first);
    }
  }
  MCE_DEBUG("RoomInfo::GetAllActiveJids --> ans.size = " << ans.size());
  return ans;
}
예제 #8
0
void IqHandlerI::NotifyBuddyApplyChange(int userId, const Ice::Current&){
	JidSeq jids;
	MCE_DEBUG("IqHandlerI::NotifyBuddyApplyChange --> userId : "<< userId);
	try {
		//jids = OnlineCenterAdapter::instance().getUserJids(userId, 4);
		jids = TalkFunStateAdapter::instance().getUserJids(userId, 4);
	}catch(Ice::Exception & e){
		MCE_WARN("IqHandlerI::NotifyBuddyApplyChange-->OnlineCenterAdapter::getUserJids-->"<<e);
	}
	if(!jids.empty()){
		for (JidSeq::iterator it = jids.begin(); it != jids.end() ; ++it){
			GetBuddyApply(*it);
		}
	}
}
예제 #9
0
void NotifyPrivateChatTask::handle(){
  string sender_identity_str = mucUserIdentityToString(sender->identity);
  if(sender_identity_str.empty()){
    return;
  }
	MCE_DEBUG("MucGateManagerI::NotifyPrivateChat--> senderjid = " << jidToString(sender->jid) << " roomid = " << mucRoomIdToString(sender->identity->roomid) << " targetuser = "******" msg = " << msg);
	JidSeq imusers;
  try{
    imusers = OnlineCenterAdapter::instance().getUserJids(targetuser, 4);
		MCE_DEBUG("MucGateManagerI::NotifyPrivateChat --> CALL ONLINECENTER  get IM jids.size = " << imusers.size());
  }
  catch(Ice::Exception& e){
    MCE_WARN("MucGateManagerI::NotifyPrivateChat --> call OnlineCenterAdapter.getUserJids ERR  line:"<<__LINE__<<" err:"<<e);
  }
  catch(std::exception& e){
    MCE_WARN("MucGateManagerI::NotifyPrivateChat --> call OnlineCenterAdapter.getUserJids ERR  line:"<<__LINE__<<" err:"<<e.what());
  }
	MessageSeq seq;
  JidSeq::const_iterator jit = imusers.begin();
  for(; jit != imusers.end(); ++jit){
    xml_document doc;
    xml_node messageNode = doc.append_child();
		messageNode.set_name("message");
    messageNode.append_attribute("from").set_value(sender_identity_str.c_str());
    messageNode.append_attribute("to").set_value(jidToString((*jit)).c_str());
		messageNode.append_attribute("type").set_value("chat");
    xml_node bodyNode = messageNode.append_child();
		bodyNode.set_name("body");
		bodyNode.append_child(node_pcdata).set_value(msg.c_str());
    MessagePtr msg = new Message();
    msg->from = sender->jid;
    msg->to = (*jit);
    msg->msg = doc.xml();
    msg->type = MESSAGE;//none
    msg->msgKey = -1;
    seq.push_back(msg);
  }
	try{
		MCE_INFO("MucGateManagerI::NotifyPrivateChat --> CALL MucDeliver.deliver seq.size = " << seq.size());
		MucDeliverAdapter::instance().deliver(seq);
	} catch(Ice::Exception& e){
    MCE_WARN("MucGateManagerI::NotifyPrivateChat --> call MucDeliver.deliver ERR  line:"<<__LINE__<<" err:"<<e);
  }
  catch(std::exception& e){
    MCE_WARN("MucGateManagerI::NotifyPritateChat--> call MucDeliver.deliver ERR  line:"<<__LINE__<<" err:"<<e.what());
  }

}
예제 #10
0
void IqHandlerI::RemoveNotifyBySource(int userId, int type, Ice::Long resource, const Ice::Current&){
	JidSeq jids;
	if(type > 0){
	  type = -type;
	}
	MCE_DEBUG("IqHandlerI::RemoveNotifyBySource --> userId : "<< userId << " type = " << type << " source = " << resource);
	try {
		//jids = OnlineCenterAdapter::instance().getUserJids(userId, 4);
		jids = TalkFunStateAdapter::instance().getUserJids(userId, 4);
	}catch(Ice::Exception & e){
		MCE_WARN("IqHandlerI::RemoveNotifyBySource-->OnlineCenterAdapter::getUserJids-->"<<e);
	}
	if(!jids.empty()){
		for (JidSeq::iterator it = jids.begin(); it != jids.end() ; ++it){
			xml_document doc;
			xml_node iqNode = doc.append_child();
			iqNode.set_name("iq");
			iqNode.append_attribute("type") = "set";
			iqNode.append_attribute("id") = (int)time(NULL);
			xml_node queryNode = iqNode.append_child();
			queryNode.set_name("query");
			queryNode.append_attribute("xmlns") = "http://talk.renren.com/removenotify";
			queryNode.append_attribute("type") = "removebysource";

			xml_node type_node = queryNode.append_child();
			type_node.set_name("stype");
			string str_type = boost::lexical_cast<string>(type);
			type_node.append_child(node_pcdata).set_value(str_type.c_str());

			xml_node resource_node = queryNode.append_child();
			resource_node.set_name("resource");
      string str_resource = boost::lexical_cast<string>(resource);
      resource_node.append_child(node_pcdata).set_value(str_resource.c_str());

			MessagePtr mPtr = new Message();
			mPtr->to = *it;
			mPtr->type = IQ_SET;
			mPtr->msg = doc.xml();
			MCE_DEBUG("IqHandlerI::RemoveNotifyBySource --> to : "<< (*it)->userId <<" xml:"<<doc.xml());
			try {
				TalkDeliverAdapter::instance().deliver(mPtr);
			}catch(Ice::Exception & e){
				MCE_WARN("IqHandlerI::RemoveNotifyBySource-->TalkDeliverAdapter::deliver-->"<<e);
			}
		}
	}
}
예제 #11
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
void RoomPool::UserOnline(const MucActiveUserPtr& activeuser){
  MCE_DEBUG("RoomPool::UserOnline --> jid = " << jidToString(activeuser->jid));
  MucActiveUserPtr opaptr;
  MucActiveUserSeq presenceUsers;
  RoomInfoPtr riptr;
  bool addok = false;
	int mucstatus = 0;
  {
    //针对频繁上下线,不能上写锁。
    IceUtil::RWRecMutex::RLock lock(_rwmutex);
    riptr = GetRoom(activeuser->identity->roomid);
    if(!riptr){
			//TaskManager::instance().execute(new PageCacheNotifyTask("online", activeuser->jid->userId, activeuser->identity->roomid));
      return;
    }
		presenceUsers = riptr->GetAllActiveUsers();
		presenceUsers.push_back(activeuser);    //加自己
  }
  if(riptr){
		//如果用户是IM用户,而且房间也cache了,这样发送邀请。
		if('T' == activeuser->jid->endpoint[0]){
			MCE_DEBUG("RoomPool::UserOnline --> user is an im user and room is in cache. so send invite to it!");
			try{
				JidSeq jids;
				jids.push_back(activeuser->jid);
				MucGateAdapter::instance().InviteIMusers(activeuser->identity->roomid, jids);
			}catch(Ice::Exception& e){
      	MCE_WARN("RoomPool::UserOnline--> call MucTalkRoom.GetRoomActiveUserSeq ERR  line:"<<__LINE__<<" err:"<<e);
   	 	}
    	catch(std::exception& e){
      	MCE_WARN("RoomPool::EnterRoom --> call MucTalkRoom.GetRoomActiveUserSeq ERR  line:"<<__LINE__<<" err:"<<e.what());
    	}
			return;
		}

    //如果这个房间被cache住了,在线中心会响应这个用户的上线行为
    IceUtil::RWRecMutex::WLock lock(_rwmutex);
    addok = riptr->AddActiveUser(activeuser);
		if(addok){
			mucstatus = riptr->GetUserMucStatus(activeuser->jid->userId);
		}
  }

  if(addok && !presenceUsers.empty()){
    MucGateAdapter::instance().NotifyUserEnterRoom(activeuser, presenceUsers, mucstatus);
  }
}
예제 #12
0
void IqHandlerI::SendClientFocuslist(int uid,const Ice::Current& ic) {
  string xml = "<presence ";
  int res = 0;
  MyUtil::IntSeq ans;
  try {
    ans = FeedFocusAdapter::instance().GetFocuses(uid);
    res = 1;
  } catch (Ice::Exception& e) {
    MCE_WARN("IqGetTask::getfocuslist-->FeedFocusAdapter::GetFocuses error!"<<e.what());
    res = 0;
  } catch(...) {
    MCE_WARN("IqGetTask::getfocuslist-->FeedFocusAdapter::GetFocuses error!");
    res = 0;
  }
  if (res==0) {
    xml += "res='0'><x xmlns='http://talk.xiaonei.com/focuslist'/>";
  } else {
    xml += "res='1'><x xmlns='http://talk.xiaonei.com/focuslist'>";
    for (int i=0;i<ans.size();++i) {
      ostringstream os;
      os << ans[i];
      xml += "<uid>";
      xml += os.str();
      xml += "</uid>";
    }
    xml += "</x>";
  }
  xml += "</presence>"; 
  MCE_DEBUG(xml);
  JidSeq jseq;
  try {
    jseq = TalkFunStateAdapter::instance().getUserJids(uid,4);
  } catch(Ice::Exception& e) {
    MCE_WARN("IqHandlerI::SendClientFocuslist-->TalkFunState::getUserJids error!"<<e.what());
    return ;
  }
  for (JidSeq::iterator it = jseq.begin();it != jseq.end() ;++it) {
    try {
      TalkProxyAdapter::instance().express((*it), xml);
    } catch(Ice::Exception& e) {
      MCE_WARN("IqHandlerI::SendClientFocuslist-->TalkProxyAdapter::express error!"<<e.what());
    }
  }
  return ;
}
예제 #13
0
void RoomPool::SendTalkMessage(const JidPtr& opuser, const MucRoomIdPtr& roomid, const string& msg){
  MCE_DEBUG("RoomPool::SendTalkMessage --> jid = " << jidToString(opuser) << " roomname = " << roomid->roomname << " msg = " << msg);
  MucActiveUserPtr opaptr;
  JidSeq presenceUsers;
	RoomInfoPtr riptr;

  {
    IceUtil::RWRecMutex::RLock lock(_rwmutex);
    riptr = GetRoom(roomid);
  }
  {
    MCE_DEBUG("RoomPool::SendTalkMessage -->GetRoom HERE");
		if(!riptr){
      GetActiveUsers(roomid);
      MCE_DEBUG("RoomPool::SendTalkMessage --> LOCATE NEW ROOM");
		}
  }

  {
  
    IceUtil::RWRecMutex::RLock lock(_rwmutex);
    if (!riptr)
      riptr = GetRoom(roomid);
		if(!riptr){
      MCE_WARN("RoomPool::SendTalkMessage --> LOCATE NEW ROOM ERROR"); 
      return;
      
		}
    MCE_DEBUG("RoomPool::SendTalkMessage -->GetRoom OK");
		opaptr = riptr->GetActiveUser(opuser);
		if(opaptr){
			presenceUsers = riptr->GetAllActiveJids();
		}else{
    	MCE_WARN("RoomPool::SendTalkMessage --> no activeuser in room.....it is so amazing pull the jid :" << jidToString(opuser) << " into the room");
			TaskManager::instance().execute(new PullLostUserTask(opuser));
		}
  }
  if(opaptr && !presenceUsers.empty()){
    MCE_DEBUG("RoomPool::SendTalkMessage --> presenceUsers.size = " << presenceUsers.size());
    MucGateAdapter::instance().NotifyGroupChat(opaptr, presenceUsers, msg);
  }
}
예제 #14
0
void WTalkProxyManagerI::deliver(const MessageSeq& msgs, const Ice::Current&) {
	MCE_DEBUG("WTalkProxyManagerI::deliver --> msgs.size:"<<msgs.size());
	for (size_t i = 0; i < msgs.size(); ++i) {
		if ((msgs.at(i)->type == MESSAGE) || (msgs.at(i)->type == OFFLINE_MESSAGE) || (msgs.at(i)->type == PHONE_NOTIFY)) {

			//MCE_DEBUG("msg:"<<msgs.at(i)->msg<<"  toid:"<<msgs.at(i)->to->userId);
			JidSeq jseq = _pools[msgs.at(i)->to->userId % POOLSIZE].getAccessJid(msgs.at(i)->to->userId);
			//MCE_DEBUG("jid size:"<<jseq.size()<<"  toid:"<<msgs.at(i)->to->userId);
			string body;
			xml_document doc;
			try{
				msgs.at(i)->msg = MsgFilterAdapter::instance().wapFilter(msgs.at(i)->msg);
			}catch(Ice::Exception& e){
				MCE_WARN("WTalkProxyManagerI::deliver --> invoke antispam err, " << e);
			}

			if(doc.load(msgs.at(i)->msg.c_str())){
				body = doc.child("message").child("body").first_child().value();
			}
			MCE_INFO("WTalkProxyManagerI::deliver --> from:" << jidToString(msgs.at(i)->from) << " to:" << jidToString(msgs.at(i)->to) << " msg:" << body);
			_pools[msgs.at(i)->to->userId % POOLSIZE].storeMsg(msgs.at(i));

			if (jseq.empty()) {
				//TalkLogicAdapter::instance().unbind(msgs.at(i)->to);
				MCE_WARN("WTalkProxyManagerI::deliver --> access jid size = 0");
				return;
			}

			for (size_t j = 0; j < jseq.size(); ++j) {
				MessagePtr msg = new Message();
				msg->from = msgs.at(i)->from;
				msg->to = jseq.at(j);
				msg->type = msgs.at(i)-> type;
				msg->msg = msgs.at(i)->msg;
				msg->msgKey = msgs.at(i)->msgKey;
				MCE_DEBUG("call pipepool   toid:"<<msg->to->userId);
				PipePool::instance().push(jseq.at(j)->endpoint, 0, msg);
			}
		}
	}
}
예제 #15
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
void RoomPool::AwayRoom(const JidPtr& opuser, const MucRoomIdPtr& roomid){
  //如果一个用户的副本进入了在线中心,那么这个用户退出在线中心的行为是下线。
  //第三方副本可以awayroom
  RoomInfoPtr riptr;
  MucActiveUserPtr opaptr;
  //MucActiveUserSeq presenceUsers;
  JidSeq presenceUsers;
  bool awayok = false;
  bool kickroomok = false;
	int mucstatus = 0;
  {
    IceUtil::RWRecMutex::WLock lock(_rwmutex);
    riptr = GetRoom(roomid);
		if(!riptr){
			return;
		}
    opaptr = riptr->GetActiveUser(opuser);
    awayok = riptr->AwayRoom(opuser);
    if(awayok && !riptr->GetUserCount()){
      MCE_DEBUG("RoomPool::AwayRoom --> user away ok and room is empty so kick it");
      kickroomok = KickRoom(roomid);
    }
  }

  if(awayok){
    if(!kickroomok){
      IceUtil::RWRecMutex::RLock lock(_rwmutex);
      presenceUsers = riptr->GetAllActiveJids();
			mucstatus = riptr->GetUserMucStatus(opuser->userId);
    }
		if(opaptr){
    	presenceUsers.push_back(opaptr->jid);
		}
  }

  if(awayok && opaptr && !presenceUsers.empty()){
    MucGateAdapter::instance().NotifyUserAwayRoom(opaptr, presenceUsers, mucstatus);
  }
  MCE_DEBUG("RoomPool::AwayRoom --> jid = " << jidToString(opuser) << " roomname = " << roomid->roomname << " awayok = " << awayok << " mucstatus = " << mucstatus);
}
예제 #16
0
void SessionPool::unbind(const string& sessionKey, const JidPtr& jid) {
	IceUtil::RWRecMutex::WLock lock(_mutex);
	Stat st(this, false);
	if(jid){
		MCE_INFO("SessionPool::unbind --> " << jidToString(jid));
	}
	map<int, WebSessionPtr>::iterator it = _pool.find(jid->userId);
	if (it != _pool.end()) {
		it->second->unbind(sessionKey, jid);
	} else {
		MCE_DEBUG("SessionPool::unbind --> not in pool jid:"<< jidToString(jid));
		JidSeq jseq = OnlineCenterAdapter::instance().getUserJids(jid->userId);
		for (size_t i = 0; i < jseq.size(); ++i) {
			if (jseq.at(i)->endpoint == ServiceI::instance().getName()) {
				try {
					MCE_DEBUG("SessionPool::unbind --> not in pool jid:"<< jidToString(jseq.at(i)));
					LoginMsgHandlerAdapter::instance().unbind(jseq.at(i));
					PresenceMsgHandlerAdapter::instance().offline(jseq.at(i));
				} catch(Ice::Exception & e) {
					MCE_WARN("do unbind err:"<<e);
				}
			}
		}
	}
}
예제 #17
0
void KickUserTimer::handle(){
	while(true){
		pair<int, int> p;
		{
			IceUtil::Mutex::Lock lock(_mutex);
			if(_users.empty()){
				break;
			}
			p = _users.front();
			if((time(NULL)-p.second) < 1*60){
				break;
			}
			_users.pop_front();
		}

		JidSeq jids;
		try{
			jids = OnlineCenterAdapter::instance().getUserJids(p.first);
		}catch(Ice::Exception& e){
			MCE_WARN("KickUserTimer::handle-->OnlineCenterAdapter::getUserJids-->" << e);
		}
		MCE_INFO("KickUserTimer::handle --> user:"******" onlinesize:" << jids.size() << " size:" << _users.size());
		if(jids.empty()){
			continue;
		}	
		for(int i=0; i<jids.size(); i++){
			try{
				MCE_INFO("KickUserTimer::handle -- > offline " << jidToString(jids.at(i)));
				OnlineCenterAdapter::instance().offline(jids.at(i));
			}catch(Ice::Exception& e){
				MCE_WARN("KickUserTimer::handle-->OnlineCenterAdapter::offline-->" << e << " " << jidToString(jids.at(i)));
			}
			try{
				MCE_INFO("KickUserTimer::handle -- > close " << jidToString(jids.at(i)));
				TalkProxyAdapter::instance().kick(jids.at(i));
			}catch(Ice::Exception& e){
				MCE_WARN("KickUserTimer::handle-->TalkProxyAdapter::kick-->" << e << " " << jidToString(jids.at(i)));
			}
		}
	}
}
예제 #18
0
void IqHandlerI::changeBuddyGroupNotify(const BuddyItemPtr& bi, const Ice::Current&) {
  if(!bi){
    return;
  }
	MCE_DEBUG("IqHandlerI::changeBuddyGroupNotify --> host:"<<bi->host);
	MyUtil::IntSeq buddys;

	for (map<int,MyUtil::StrSeq>::iterator it = bi->items.begin(); it != bi->items.end(); ++it) {
		buddys.push_back(it->first);
	}
  TalkUserMap buddyInfo;
  try{
		buddyInfo = TalkCacheClient::instance().GetUserBySeqWithLoad(bi->host, buddys);
		if(buddyInfo.size() != buddys.size()){
			MCE_INFO("IqHandlerI::changeBuddyGroupNotify --> may be warn get from TalkCacheClient size is not equal actor = " << bi->host << " ids.size = " << buddys.size() << " map.size = " << buddyInfo.size());
		}else{
			MCE_INFO("IqHandlerI::changeBuddyGroupNotify --> success get from TalkCacheClient size is equal actor = " << bi->host << " ids.size = " << buddys.size() << " map.size = " << buddyInfo.size());
    }
	}catch(Ice::Exception& e){
    MCE_WARN("IqHandlerI::changeBuddyGroupNotify --> TalkCacheClient err, " << e);
  }
	
  MessageSeq mSeq;
  JidSeq jids;
  try{
	  //jids = OnlineCenterAdapter::instance().getUserJids(bi->host, 4);
	  jids = TalkFunStateAdapter::instance().getUserJids(bi->host, 4);
  }catch(Ice::Exception& e){
    MCE_WARN("IqHandlerI::changeBuddyGroupNotify-->OnlineCenterAdapter::getUserJids-->" << e);
  }
	for (size_t j = 0; j < jids.size(); ++j) {
		for (map<int,MyUtil::StrSeq>::iterator it = bi->items.begin(); it
				!= bi->items.end(); ++it) {
			xml_document doc;
			xml_node iqNode = doc.append_child();
			iqNode.set_name("iq");
			iqNode.append_attribute("type") = "set";
			iqNode.append_attribute("id") = (int)time(NULL);
			iqNode.append_attribute("to") = jidToString(jids.at(j)).c_str();

			xml_node queryNode = iqNode.append_child();
			queryNode.set_name("query");
			queryNode.append_attribute("xmlns") = "jabber:iq:roster";

			xml_node itemNode = queryNode.append_child();
			itemNode.set_name("item");
			ostringstream jos;
			jos << it->first << "@talk.xiaonei.com";
			itemNode.append_attribute("jid") = jos.str().c_str();//jid.c_str();

      TalkUserMap::iterator oit = buddyInfo.find(it->first);
			if (oit != buddyInfo.end()) {
				itemNode.append_attribute("name") = oit->second->name.c_str();
			} else {
				itemNode.append_attribute("name") = boost::lexical_cast<string>(it->first).c_str();
			}

			//itemNode.append_attribute("name") = name.c_str();
			itemNode.append_attribute("subscription") = "both";

			for (size_t k = 0; k < it->second.size(); ++k) {
				xml_node groupNode = itemNode.append_child();
				groupNode.set_name("group");
				groupNode.append_child(node_pcdata).set_value(it->second.at(k).c_str());
			}

			MessagePtr mPtr = new Message();
			//mPtr->from = new Jid();
			mPtr->from = jids.at(j);
			mPtr->to = jids.at(j);
			mPtr->type = IQ_SET;
			mPtr->msg = doc.xml();
			mSeq.push_back(mPtr);
			MCE_DEBUG("IqHandlerI::changeBuddyGroupNotify --> xml:"<<doc.xml());
		}
	}
	try{
		TalkDeliverAdapter::instance().deliver(mSeq);
	}catch(Ice::Exception& e){
		MCE_WARN("IqHandlerI::changeBuddyGroupNotify-->TalkDeliverAdapter::deliver-->err" << e);
	}
}
예제 #19
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
MucUserIdentitySeq RoomPool::GetActiveUsers(const MucRoomIdPtr& roomid){
  MCE_DEBUG("RoomPool::GetActiveUsers --> roomname = " << roomid->roomname << " roomdomain = " << roomid->domain);
  bool hasroom = false;
  JidSeq imusers;
  MucActiveUserSeq activeusers;
  MucUserIdentitySeq ans;
  RoomInfoPtr riptr;
  {
    IceUtil::RWRecMutex::RLock lock(_rwmutex);
    riptr = GetRoom(roomid);
    if(riptr){
      hasroom = true;
      ans = riptr->GetAllUserIdentity();
    }
  }
  if(!hasroom && PERMANENT == roomid->domain){
    MCE_DEBUG("RoomPool::GetActiveUsers --> roomname = " << roomid->roomname << " pull from MucTalkRoom");
		try{
    	activeusers = MucTalkRoomAdapter::instance().GetRoomActiveUserSeq(roomid);
		}
		catch(Ice::Exception& e){
			MCE_WARN("RoomPool::GetActiveUsers --> call MucTalkRoom.GetRoomActiveUserSeq ERR  line:"<<__LINE__<<" err:"<<e);
		}
		catch(std::exception& e){
			MCE_WARN("RoomPool::GetActiveUsers --> call MucTalkRoom.GetRoomActiveUserSeq ERR  line:"<<__LINE__<<" err:"<<e.what());
		}
		if(activeusers.empty()){
			MCE_DEBUG("RoomPool::GetActiveUsers --> call MucTalkRoom.GetRoomActiveUserSeq empty result so return@@");
		  return ans;
		}
		bool checkagain = false;
		IceUtil::RWRecMutex::WLock lock(_rwmutex);
		riptr = GetRoom(roomid);
    if(riptr){
      MCE_DEBUG("RoomPool::GetActiveUsers --> after check again bool againcheck = true so only return room's all activeusers ");
      checkagain = true;
      ans = riptr->GetAllUserIdentity();
    }
    if(!checkagain){
      MCE_DEBUG("RoomPool::GetActiveUsers --> after check again bool againcheck = false we add web activeusers into server cache and send invite to imusers if have");
      bool hasaddroom = false;
      set<int> uids;
      MucActiveUserSeq::iterator it = activeusers.begin();
      for(; it != activeusers.end(); ++it){
        if((*it)->jid->endpoint[0] == 'W'){
          hasaddroom = true;
					MCE_DEBUG("RoomPool::GetActiveUsers --> PUSH ACIVEUSER INFO : jid = " << jidToString((*it)->jid) << " roomname = " << (*it)->identity->roomid->roomname << " domain = " << (*it)->identity->roomid->domain << " permision = " << (*it)->permision);
          JoinRoom((*it));
        }
        else if((*it)->jid->endpoint[0] == 'T'){
          imusers.push_back((*it)->jid);
        }
        pair<set<int>::iterator, bool > insertres = uids.insert((*it)->jid->userId);
        if(insertres.second){
          ans.push_back((*it)->identity);
        }
      }
      if(!hasaddroom){
        CreateRoom(roomid);
      }
    }
  }
  if(!imusers.empty()){
    MCE_DEBUG("RoomPool::GetActiveUsers send invite to imusers : size = " << imusers.size());
    MucGateAdapter::instance().InviteIMusers(roomid, imusers);
  }
  MCE_DEBUG("RoomPool::GetActiveUsers --> roomname = " << roomid->roomname << " all activeusers.size = " << ans.size());
	for(MucUserIdentitySeq::iterator logit = ans.begin(); logit != ans.end(); ++logit){
  	MCE_DEBUG("RoomPool::GetActiveUsers --> activeuser info : roomname = " << (*logit)->roomid->roomname << " nickname = " << (*logit)->nickname);
	}
  return ans;
}
예제 #20
0
void IqHandlerI::removeBuddyNotify(Ice::Int from, Ice::Int to,
		const Ice::Current&) {
	StatFunc statF("IqHandlerI::removeBuddyNotify");

	//JidSeq toJids = PresenceAdapter::instance().getOnlineUserJidSeq(to);
	//JidSeq fromJids = PresenceAdapter::instance().getOnlineUserJidSeq(from);
	JidSeq toJids;
	JidSeq fromJids;
	try{
		//toJids = OnlineCenterAdapter::instance().getUserJids(to, 4);
		toJids = TalkFunStateAdapter::instance().getUserJids(to, 4);
	}catch(Ice::Exception& e){
		MCE_WARN("IqHandlerI::removeBuddyNotify-->OnlineCenterAdapter::getUserJids-->err" << e);
	}
	try{
		//fromJids = OnlineCenterAdapter::instance().getUserJids(from, 4);
		fromJids = TalkFunStateAdapter::instance().getUserJids(from, 4);
	}catch(Ice::Exception& e){
		MCE_WARN("IqHandlerI::removeBuddyNotify-->OnlineCenterAdapter::getUserJids-->err" << e);	
	}
	if(toJids.empty() && fromJids.empty()){
		return;
	}
	MessageSeq seq;
	for (size_t i = 0; i < fromJids.size(); ++i) {

		ostringstream msg;
		msg<<"<iq type='set' id='"<<time(NULL)<<"'>"
				<<"<query xmlns='jabber:iq:roster'>" <<"<item jid='"<<to
				<<"@talk.xiaonei.com' subscription='remove' />"
				<<"</query></iq>";

		//			IqHandlerI::instance().getProxyServerOneway(fromJids.at(i)->endpoint)->deliver(fromJids.at(i), msg.str());
		MessagePtr mPtr = new Message();
		mPtr->from = new Jid();
		mPtr->from->userId = -1;
		mPtr->to = fromJids.at(i);
		mPtr->msg = msg.str();
		mPtr->type = IQ_SET;
		seq.push_back(mPtr);
	}

	for (size_t i = 0; i < toJids.size(); ++i) {

		JidPtr fromJid = new Jid();
		fromJid->userId = from;
		fromJid->endpoint = "talk.xiaonei.com";
		fromJid->index = -1;

		ostringstream msg;
		msg<<"<presence  from='"<<from<<"@talk.xiaonei.com' to='"
				<<jidToString(toJids.at(i))<<"' type='unsubscribed' id='"
				<<time(NULL) <<"'/>";

		MessagePtr mPtr = new Message();
		mPtr -> from = fromJid;
		mPtr -> to = toJids.at(i);
		mPtr -> msg = msg.str();
		mPtr -> type = PRESENCE_COMMON;
		seq.push_back(mPtr);

		msg.str("");
		msg<<"<iq type='set' id='"<<time(NULL)<<"'>"
				<<"<query xmlns='jabber:iq:roster'>" <<"<item jid='"<<from
				<<"@talk.xiaonei.com' subscription='remove' />"
				<<"</query></iq>";

		//			IqHandlerI::instance().getProxyServerOneway(toJids.at(i)->endpoint)->deliver(toJids.at(i), msg.str());
		mPtr = new Message();
		mPtr -> from = fromJid;
		mPtr -> to = toJids.at(i);
		mPtr -> msg = msg.str();
		mPtr -> type = IQ_SET;
		seq.push_back(mPtr);
	}
	try{
		TalkDeliverAdapter::instance().deliver(seq);
	}catch(Ice::Exception& e){
		MCE_WARN("IqHandlerI::removeBuddyNotify-->TalkDeliverAdapter::deliver-->err" << e);
	}
}
예제 #21
0
AvatarSeq OnlineCenterAdapter::getAvatars(const JidSeq& jids) {
	if(jids.empty()){
		return AvatarSeq();
	}
	return getManager(jids.at(0)->userId)->getAvatars(jids);
}
예제 #22
0
void OnlineStatSyncAdapter::offlineBatch(const JidSeq& seq) {
	if (!seq.empty()) {
		getManagerOneway(seq.size())->offlineBatch(seq);
	}
}
예제 #23
0
파일: RoomPool.cpp 프로젝트: bradenwu/oce
void RoomPool::EnterRoom(const MucActiveUserPtr& activeuser){
  MCE_DEBUG("RoomPool::EnterRoom --> activeuser info : jid = " << jidToString(activeuser->jid) << " roomname = " << activeuser->identity->roomid->roomname << " domain = " << activeuser->identity->roomid->domain);

  RoomInfoPtr riptr;
  MucActiveUserPtr opaptr;
  MucActiveUserSeq presenceUsers;
  bool hasroom = true;
	int mucstatus = 0;
	bool enterok = false;
  if(TEMPORARY == activeuser->identity->roomid->domain){
		//临时房间
		{
    	MCE_DEBUG("RoomPool::EnterRoom --> domain == " << TEMPORARY);
    	IceUtil::RWRecMutex::WLock lock(_rwmutex);
			riptr = JoinRoom(activeuser);
			if(riptr){
				//临时房间用户可能会改变他的权限。
				opaptr = riptr->GetActiveUser(activeuser->jid);
				if(opaptr){
					enterok = true;
				}
			}
		}
		if(!enterok){
			try{
				MCE_DEBUG("RoomPool::EnterRoom --> CALL MucGate.NotifyNicknameError jid:" << jidToString(activeuser->jid) << " room:" << mucRoomIdToString(activeuser->identity->roomid));
				MucGateAdapter::instance().NotifyNicknameError(activeuser->identity->roomid, activeuser->jid);
			}
			catch(Ice::Exception& e){
				MCE_WARN("RoomPool::EnterRoom --> call MucGate.NotifyNicknameError ERR  line:"<<__LINE__<<" err:"<<e);
			}
			catch(std::exception& e){
				MCE_WARN("RoomPool::EnterRoom --> call MucGate.NotifyNicknameError ERR  line:"<<__LINE__<<" err:"<<e.what());
			}
			return;
		}
		/*
		//临时房间聊天发起者多副本同步,要向其他副本发送邀请
		JidSeq imjids;
		try{
			MCE_DEBUG("RoomPool::EnterRoom --> CALL OnlineCenter.getUserJids for invite the other jids. userid = " << activeuser->jid->userId);
			imjids = OnlineCenterAdapter::instance().getUserJids(activeuser->jid->userId, 4);
		}
		catch(Ice::Exception& e){
			MCE_WARN("RoomPool::EnterRoom --> call OnlineCenter.getUserJids ERR  line:"<<__LINE__<<" err:"<<e);
		}
		catch(std::exception& e){
			MCE_WARN("RoomPool::EnterRoom --> call OnlineCenter.getUserJids ERR  line:"<<__LINE__<<" err:"<<e.what());
		}
		if(imjids.empty()){
			return;
		}
		for(JidSeq::iterator jit = imjids.begin(); jit != imjids.end(); ++jit){
			if(equal((*jit), activeuser->jid)){
				imjids.erase(jit);
				MCE_DEBUG("RoomPool::EnterRoom --> erase the activeuser->jid from want to invite");
				break;
			}
		}
		if(!imjids.empty()){
			MCE_DEBUG("RoomPool::EnterRoom --> invite the user : "******"'s other avatar into the room");
			try{
				MucGateAdapter::instance().InviteIMusers(activeuser->identity->roomid, imjids);
			}
			catch(Ice::Exception& e){
				MCE_WARN("RoomPool::EnterRoom --> call MucGate.InviteImUsers ERR  line:"<<__LINE__<<" err:"<<e);
			}
			catch(std::exception& e){
				MCE_WARN("RoomPool::EnterRoom --> call OnlineCenter.InviteImUsers ERR  line:"<<__LINE__<<" err:"<<e.what());
			}
		}
		*/
  }
  else if(PERMANENT == activeuser->identity->roomid->domain){
		opaptr = activeuser;
    MCE_DEBUG("RoomPool::EnterRoom --> domain == " << PERMANENT);
    {
      IceUtil::RWRecMutex::RLock lock(_rwmutex);
      riptr = GetRoom(activeuser->identity->roomid);
    }
    if(riptr){
			//如果房间存在,直接加人
      MCE_DEBUG("RoomPool::EnterRoom --> riptr is not null so call it AddActiveUser function");
      IceUtil::RWRecMutex::WLock lock(_rwmutex);
      enterok = riptr->AddActiveUser(activeuser);
    }
    else{
      MCE_DEBUG("RoomPool::EnterRoom --> riptr is null .No " << activeuser->identity->roomid->roomname << " in cache pull from MucTalkRoom");
      hasroom = false;
      JidSeq imusers;
      MCE_DEBUG("RoomPool::EnterRoom --> CALL MucTalkRoomAdapter.GetRoomActiveUserSeq roomname = " << activeuser->identity->roomid->roomname);
      try{
        presenceUsers = MucTalkRoomAdapter::instance().GetRoomActiveUserSeq(activeuser->identity->roomid);
      }
      catch(Ice::Exception& e){
        MCE_WARN("RoomPool::EnterRoom --> call MucTalkRoom.GetRoomActiveUserSeq ERR  line:"<<__LINE__<<" err:"<<e);
      }
      catch(std::exception& e){
        MCE_WARN("RoomPool::EnterRoom --> call MucTalkRoom.GetRoomActiveUserSeq ERR  line:"<<__LINE__<<" err:"<<e.what());
      }
      {
        IceUtil::RWRecMutex::WLock lock(_rwmutex);
        bool againcheck = false;
        riptr = GetRoom(activeuser->identity->roomid);
        if(riptr){
          MCE_DEBUG("RoomPool::EnterRoom --> after check again bool againcheck = true so it means the users has pull hera already so only add it");
          againcheck = true;
					hasroom = true;
          enterok = riptr->AddActiveUser(activeuser);
        }
        if(!againcheck){
          MCE_DEBUG("RoomPool::EnterRoom --> after check again  bool againcheck = false so push the web presenceUsers(get from MucTalkRoom) into room and send invite to IM users");
          bool hasaddroom = false;
          MucActiveUserSeq::iterator it = presenceUsers.begin();
          for(; it != presenceUsers.end();){
            if((*it)->jid->endpoint[0] == 'W'){
              hasaddroom = true;
              riptr = JoinRoom((*it));
							++it;
            }
						else if(equal(activeuser->jid, (*it)->jid)){
							MCE_DEBUG("RoomPool::EnterRoom --> the activeuser self enter room");
							//第三方客户端可能会起不同的名字所以在这里要加入房间的参数activeuser 并且修改这个seq里面的元素。
							hasaddroom = true;
							riptr = JoinRoom(activeuser);
							(*it) = activeuser;
							++it;
						}
            else if((*it)->jid->endpoint[0] == 'T'){
              imusers.push_back((*it)->jid);
							//对于客户端用户,我们发送邀请。所以,它并不在房间内,我们要从广播用户内删除他们。
							it = presenceUsers.erase(it);
            }
          }
          if(!hasaddroom){
            riptr = CreateRoom(activeuser->identity->roomid);
          }
					if(riptr){
						//判断拉进来的用户里面有没有自己
						opaptr = riptr->GetActiveUser(activeuser->jid);
						if(opaptr){
							enterok = true;
						}
					}
        }
      }
      if(enterok && !imusers.empty()){
        MCE_DEBUG("RoomPool::EnterRoom --> send invite to imiusers size = " << imusers.size());
        MucGateAdapter::instance().InviteIMusers(activeuser->identity->roomid, imusers);
      }
    }
  }
	
	if(!enterok){
		MCE_DEBUG("RoomPool::EnterRoom --> jid = " << jidToString(activeuser->jid) << " enterok = false return");
		return;
	}
	
  if(hasroom){
    IceUtil::RWRecMutex::RLock lock(_rwmutex);
    presenceUsers = riptr->GetAllActiveUsers();
  }
  if(opaptr && !presenceUsers.empty()){
    MCE_DEBUG("RoomPool::EnterRoom --> jid = " << jidToString(activeuser->jid) << " OK");
		for(MucActiveUserSeq::iterator logit = presenceUsers.begin(); logit != presenceUsers.end(); ++logit){
			MCE_DEBUG("RoomPool::EnterRoom --> presenceUser : info " << jidToString((*logit)->jid) << " room : " << mucUserIdentityToString((*logit)->identity) << " permision = " << (*logit)->permision);
		}
		if(PERMANENT == activeuser->identity->roomid->domain && riptr){
    	IceUtil::RWRecMutex::RLock lock(_rwmutex);
			mucstatus = riptr->GetUserMucStatus(activeuser->jid->userId);
		}
    MucGateAdapter::instance().NotifyUserEnterRoom(opaptr, presenceUsers, mucstatus);
  }
}