Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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);
  }
}
Ejemplo n.º 3
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);
  }
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
JidSeq RoomPool::GetActiveJids(const MucRoomIdPtr& roomid){
	MCE_DEBUG("RoomPool::GetActiveJids --> roomname = " << roomid->roomname << " roomdomain = " << roomid->domain);
	bool hasroom = false;
	JidSeq imusers;
	MucActiveUserSeq activeusers;
	JidSeq ans;
	RoomInfoPtr riptr;
	{
		IceUtil::RWRecMutex::RLock lock(_rwmutex);
		riptr = GetRoom(roomid);
		if(riptr){
			hasroom = true;
			ans = riptr->GetAllActiveJids();
		}
	}
	if(!hasroom && PERMANENT == roomid->domain){
		MCE_DEBUG("RoomPool::GetActiveJids --> roomname = " << roomid->roomname << " pull from MucTalkRoom");
		try{
			activeusers = MucTalkRoomAdapter::instance().GetRoomActiveUserSeq(roomid);
		}
		catch(Ice::Exception& e){
			MCE_WARN("RoomPool::GetActiveJids --> call MucTalkRoom.GetRoomActiveUserSeq ERR  line:"<<__LINE__<<" err:"<<e);
		}
		catch(std::exception& e){
			MCE_WARN("RoomPool::GetActiveJids --> call MucTalkRoom.GetRoomActiveUserSeq ERR  line:"<<__LINE__<<" err:"<<e.what());
		}
		if(activeusers.empty()){
			MCE_DEBUG("RoomPool::GetActiveJids --> call MucTalkRoom.GetRoomActiveUserSeq empty result so return@@");
			for(MucActiveUserSeq::iterator ait = activeusers.begin(); ait != activeusers.end(); ++ait){
				ans.push_back((*ait)->jid);
			}
			return ans;
		}
		bool checkagain = false;
		IceUtil::RWRecMutex::WLock lock(_rwmutex);
		riptr = GetRoom(roomid);
		if(riptr){
			MCE_DEBUG("RoomPool::GetActiveJids --> after check again bool againcheck = true so only return room's all activeusers ");
			checkagain = true;
			ans = riptr->GetAllActiveJids();
		}
		if(!checkagain){
			MCE_DEBUG("RoomPool::GetActiveJids --> 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::GetActiveJids--> 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)->jid);
				}
			}
			if(!hasaddroom){
				CreateRoom(roomid);
			}
		}
	}
	if(!imusers.empty()){
		MCE_DEBUG("RoomPool::GetActiveJids send invite to imusers : size = " << imusers.size());
		MucGateAdapter::instance().InviteIMusers(roomid, imusers);
	}
	MCE_DEBUG("RoomPool::GetActiveJids --> roomname = " << roomid->roomname << " all activeusers.size = " << ans.size());
	for(JidSeq::iterator logit = ans.begin(); logit != ans.end(); ++logit){
		MCE_DEBUG("RoomPool::GetActiveJids --> activeuser info : roomname = " << roomid->roomname << " jid = " << jidToString((*logit)));
	}
	return ans;

}