Example #1
0
bool Network::removeRelation(Node* node0, Node* node1){
	Relation* relation=relationList->findRelation(node0, node1);
	if (relation==NULL) {
		return false;
	}
	return removeRelation(relation);
}
Example #2
0
bool Network::removeNode(Node *node){
	RelationList* filteredRelations=relationList->findRelations(node);
	for(int i=0; i<filteredRelations->getNumRelations(); i++){
		removeRelation(filteredRelations->getRelationAt(i));
	}
	node->setNetwork(NULL);
	return nodeList->removeNode(node);
}
Example #3
0
/*!\func
 * add state with name
 * \param
 - name - name of new state
 * \return id of new state (or -1)
 */
bool Data::removeState(const qint32 id)
{
    if(states.contains(id))
    {
	QList<qint32> list;
	foreach(Relation relation, relations)
	    if((relation.getDest().getId() == id)||(relation.getSource().getId() == id))
		list<<relation.getId();
	foreach(qint32 id, list)
	    removeRelation(id);
	list.clear();
	foreach(Control control, controls)
	    if(control.getState().getId() == id)
		list<<control.getId();
	foreach(qint32 id, list)
	    removeControl(id);
	states.remove(id);
	emit sRemoveState(id);
	return true;
    }
Example #4
0
void RemoveElementOp::apply(OsmMapPtr& map)
{
  if (ElementType::Node == _eIdToRemove.getType().getEnum())
  {
    // Remove node fully (Removes node from relations & ways, then removes node from map)
    RemoveNodeOp removeNode(_eIdToRemove.getId(), _doCheck, true);
    removeNode.apply(map);
  }
  else if (ElementType::Way == _eIdToRemove.getType().getEnum())
  {
    RemoveWayOp removeWay(_eIdToRemove.getId(), _doCheck);
    removeWay.apply(map);
  }
  else if (ElementType::Relation == _eIdToRemove.getType().getEnum())
  {
    RemoveRelationOp removeRelation(_eIdToRemove.getId());
    removeRelation.apply(map);
  }
  else
  {
    throw HootException(QString("Unexpected element type: %1").arg(_eIdToRemove.toString()));
  }
}
Example #5
0
/**
* \brief 处理Gateway转发过来的客户端消息
* \param pNullCmd 消息体
* \param cmdLen 消息长度
* \return true 处理完毕,false 不在处理范围之中
*/
bool CRelationManager::processUserMessage(const Cmd::stNullUserCmd *pNullCmd,const DWORD cmdLen)
{
  switch(pNullCmd->byCmd)
  {
    case Cmd::RELATION_USERCMD:
      {
        switch(pNullCmd->byParam)
        {
          case UNMARRY_PARA:
            {
              CRelation* relation = NULL;
              relation = getMarryRelation();

              if (relation)
              {
                UserSession *otherUser = NULL;
                otherUser = UserSessionManager::getInstance()->getUserSessionByName(relation->name);
                if (otherUser) 
                {
                  removeRelation(relation->name);
                  otherUser->relationManager.removeRelation(user->name);
                  otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"%s选择和你离婚",user->name);
                  otherUser->updateConsort();
                }
                else
                {
                  CRelation *tRelation = NULL;

                  tRelation = (CRelation *)getEntryByName(relation->name);
                  if (tRelation) writeOfflineNotify(tRelation);
                  removeRelation(relation->name);
                }
                user->updateConsort();
              }
            }
            break;
          case Cmd::RELATION_STATUS_PARA:
            {
              Cmd::stRelationStatusCmd *rev = (Cmd::stRelationStatusCmd *)pNullCmd;
              switch(rev->byState)
              {
                case Cmd::RELATION_ADD:
                  {
                    if (!strncmp(rev->name,user->name,MAX_NAMESIZE))
                    {
                      user->sendSysChat(Cmd::INFO_TYPE_FAIL,"不能把自己加入名单中?");
                      return true;
                    }

                    if (300>size())
                    {
                      if (rev->type == Cmd::RELATION_TYPE_BAD)
                      {
                        addBadRelation(rev->name);
                      }
                      else
                      {
                        addEnemyRelation(rev->name);
                      }
                    }
                    else
                    {
                      user->sendSysChat(Cmd::INFO_TYPE_FAIL,"名单列表已满!");
                    }
                    return true;
                  }
                  break;
                case Cmd::RELATION_ANSWER_NO:
                  {
                    UserSession *otherUser = NULL;
                    otherUser = UserSessionManager::getInstance()->getUserByID(rev->userid);
                    if (otherUser)
                    {
                      switch(rev->type)
                      {
                        case Cmd::RELATION_TYPE_FRIEND:
                          {
                            otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方不同意与你结为好友");
                            return true;
                          }
                          break;
                        case Cmd::RELATION_TYPE_LOVE:
                          {
                            otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方不同意与你结为夫妻");
                          }
                          break;
                        default:
                          break;
                      }
                    }
                  }
                  break;
                case Cmd::RELATION_ANSWER_YES:
                  {
                    UserSession *otherUser = NULL;
                    otherUser = UserSessionManager::getInstance()->getUserByID(rev->userid);
                    if (otherUser)
                    {
                      if (300>otherUser->relationManager.size()|| rev->type == Cmd::RELATION_TYPE_LOVE)
                      {
                        if (300>size() || rev->type == Cmd::RELATION_TYPE_LOVE)
                        {
                          addRelation(rev->userid,rev->type);
                          otherUser->relationManager.addRelation(user->id,rev->type);
                          if (rev->type != Cmd::RELATION_TYPE_LOVE)
                          {
                            otherUser->sendSysChat(Cmd::INFO_TYPE_ADDFRIEND,"你与 %s 义结金兰,成为好友",user->name);
                            user->sendSysChat(Cmd::INFO_TYPE_ADDFRIEND,"你与 %s 义结金兰,成为好友",otherUser->name);
                          }
                        }
                        else
                        {
                          user->sendSysChat(Cmd::INFO_TYPE_FAIL,"我的好友列表已满");
                          otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方好友列表已满");
                        }
                      }
                      else
                      {
                        user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方好友列表已满");
                        otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"你的好友列表已满");
                      }
                    }
                  }
                  break;
                case Cmd::RELATION_QUESTION:
                     //free 禁止好友功能
//                     user->sendSysChat(Cmd::INFO_TYPE_FAIL, "好友系统正在开 发中!");
//                                     break;
//#if 0                     
					{
                    if (!strncmp(rev->name,user->name,MAX_NAMESIZE))
                    {
                      user->sendSysChat(Cmd::INFO_TYPE_FAIL,"你在开玩笑吗?加自己为好友!");
                      return true;
                    }
                    CRelation *relation = NULL;
                    relation = (CRelation *)getEntryByName(rev->name);
                    if (relation)
                    {
                      if (!strncmp(rev->name,relation->name,MAX_NAMESIZE) && Cmd::RELATION_TYPE_BAD != relation->type)
                      {
                        user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方已经在你的好友列表中了,无需再添加!");
                        return true;
                      }
                    }

                    UserSession *otherUser = NULL;
                    otherUser = UserSessionManager::getInstance()->getUserSessionByName(rev->name);
                    if (otherUser)
                    {
                      if (isset_state(otherUser->sysSetting,Cmd::USER_SETTING_FRIEND))
                      {

                        user->sendSysChat(Cmd::INFO_TYPE_GAME,"好友请求已发送,等待对方应答!");
                        rev->userid = user->id;
                        strncpy(rev->name,user->name,MAX_NAMESIZE);
                        otherUser->sendCmdToMe(rev,sizeof(Cmd::stRelationStatusCmd));
                      }
                      else
                        user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方添加好友未开启");
                    }
                    else
                    {
                      user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方不在线不能响应你的邀请");
                    }
//#endif 
                  break;
					}
                case Cmd::RELATION_REMOVE:
                  {
                    CRelation *rel = NULL;
                    rel = (CRelation *)getEntryByName(rev->name);
                    if (!rel) return true;
                    int type = rel->type;
                
                    if (Cmd::RELATION_TYPE_BAD == type || Cmd::RELATION_TYPE_ENEMY == type)
                    {
                      removeRelation(rev->name); // 删除黑名单成员
                    }
                    else
                    {
                      if (Cmd::RELATION_TYPE_LOVE == type)
                      {
                        user->sendSysChat(Cmd::INFO_TYPE_FAIL,"你必须到民政官那里去办理离婚手续!");
                        return true;
                      }
                      UserSession *otherUser = NULL;
                      otherUser = UserSessionManager::getInstance()->getUserSessionByName(rev->name);
                      if (otherUser) 
                      {
                        removeRelation(rev->name);
                        otherUser->relationManager.removeRelation(user->name);
                        otherUser->sendSysChat(Cmd::INFO_TYPE_BREAKFRIEND,"%s选择与你割席断交",user->name);
                        user->sendSysChat(Cmd::INFO_TYPE_BREAKFRIEND,"你选择与 %s 割席断交",otherUser->name);
                        otherUser->updateConsort();
                      }
                      else
                      {
                        user->sendSysChat(Cmd::INFO_TYPE_BREAKFRIEND,"你选择与 %s 割席断交",rev->name);
                        CRelation *relation = NULL;

                        relation = (CRelation *)getEntryByName(rev->name);
                        if (relation) writeOfflineNotify(relation);
                        removeRelation(rev->name);
                      }
                      user->updateConsort();
                    }
                  }
                  break;
              }
              return true;
            }
            break;
          default:
            break;
        }
      }
      break;
    default:
      break;
  }
  return false;
}