示例#1
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);
  }
}
示例#2
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);
  }
}