Beispiel #1
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);
  }
}
Beispiel #2
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;
}
Beispiel #3
0
void RoomPool::SendPrivateMsg(const JidPtr& sender, const MucUserIdentityPtr& recidentity, const string& msg){
	MCE_DEBUG("RoomPool::SendPrivateMsg --> sender = " << jidToString(sender) << " recidentity = " << mucUserIdentityToString(recidentity) << " msg = " << msg);
	RoomInfoPtr riptr;
	MucActiveUserPtr opaptr, targetptr;
	{
  	IceUtil::RWRecMutex::RLock lock(_rwmutex);
  	riptr = GetRoom(recidentity->roomid);
  	opaptr = riptr->GetActiveUser(sender);
  	if(!opaptr){
			MCE_WARN("RoomPool::SendPrivateMsg --> get sender : " << jidToString(sender) << " 'S activeuser error");
    	return;
  	}
  	targetptr = riptr->GetActiveUser(recidentity->nickname);
  	if(!targetptr){
			MCE_WARN("RoomPool::SendPrivateMsg --> get targetptr ERROR");
    	return;
  	}
	}
	MCE_DEBUG("RoomPool::SendPrivateMsg --> CALL MucGate.NotifyPrivateChat");
  MucGateAdapter::instance().NotifyPrivateChat(opaptr, targetptr->jid->userId, msg);
}
Beispiel #4
0
RoomInfoPtr RoomPool::JoinRoom(const MucActiveUserPtr& activeuser){
  MCE_DEBUG("RoomPool::JoinRoom --> activeuser info : jid = " << jidToString(activeuser->jid) << " roomname = " << activeuser->identity->roomid->roomname << " domain = " << activeuser->identity->roomid->domain);
  RoomInfoPtr riptr;
	bool isnewroom = false;
	bool enterok = true;
	riptr = GetRoom(activeuser->identity->roomid);
	if(!riptr){
		isnewroom = true;
		riptr = CreateRoom(activeuser->identity->roomid);
	}
	if(riptr){
		if(TEMPORARY == activeuser->identity->roomid->domain){
			if(isnewroom){
				MCE_DEBUG("RoomPool::JoinRoom --> the room " << activeuser->identity->roomid->roomname << " is confrenc group and the user = "******" is the creater of the group so he is the owner");
				MucActiveUserPtr changePermisionuser = new MucActiveUser();
				changePermisionuser->identity = activeuser->identity;
				changePermisionuser->jid = activeuser->jid;
				changePermisionuser->permision = POwner;
				enterok = riptr->AddActiveUser(changePermisionuser);
			}
			else{
				MucActiveUserPtr temporary_user = riptr->GetActiveUser(activeuser->jid->userId);
				if(temporary_user){
					if(POutcast == temporary_user->permision){
						MCE_DEBUG("RoomPool::JoinRoom --> the user " << activeuser->jid->userId << " is an outcast user so ignore the request");
						return 0;
					}
					MCE_DEBUG("RoomPool::JoinRoom --> the user " << activeuser->jid->userId << " has joined the room befor  so change the permision to " << temporary_user->permision << " and add the jid " << jidToString(activeuser->jid));
					MucActiveUserPtr changePermisionuser = new MucActiveUser();
					changePermisionuser->identity = activeuser->identity;
					changePermisionuser->jid = activeuser->jid;
					changePermisionuser->permision = temporary_user->permision;
					enterok = riptr->AddActiveUser(changePermisionuser);
				}
				else{
					MCE_DEBUG("RoomPool::JoinRoom --> add activeuser for confrence.xiaonei.com jid = " << jidToString(activeuser->jid));
					enterok = riptr->AddActiveUser(activeuser);
				}
			}
		}
		else{
			enterok = riptr->AddActiveUser(activeuser);
		}
	}
	MCE_DEBUG("RoomPool::JoinRoom --> jid = " << jidToString(activeuser->jid) << " activeuser's roomname = " << activeuser->identity->roomid->roomname << " domain = " << activeuser->identity->roomid->domain << " enterok = " << enterok);

	if(enterok){
		return riptr;
	}
	return 0;
}
Beispiel #5
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);
  }
}
Beispiel #6
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);
}
Beispiel #7
0
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);
  }
}