Exemplo n.º 1
0
csRef<iStringArray> csScanPluginDirs (csPathsList* dirs, 
				    csRef<iStringArray>& plugins)
{
  iStringArray* messages = 0;

  if (!plugins)
    plugins.AttachNew (new scfStringArray ());

  for (size_t i = 0; i < dirs->Length (); i++)
  {
    iStringArray* dirMessages = 0;
    InternalScanPluginDir (dirMessages, (*dirs)[i].path, plugins, 
      (*dirs)[i].scanRecursive);
    
    if (dirMessages != 0)
    {
      csString tmp;
      tmp.Format ("The following error(s) occured while scanning '%s':",
	(*dirs)[i].path.GetDataSafe ());

      AppendStrVecString (messages, tmp);

      for (size_t i = 0; i < dirMessages->GetSize(); i++)
      {
	tmp.Format (" %s", dirMessages->Get (i));
	AppendStrVecString (messages, tmp);
      }
      dirMessages->DecRef();
    }
  }
	 
  return csPtr<iStringArray> (messages);
}
Exemplo n.º 2
0
csRef<iStringArray> csScanPluginDir (const char* dir, 
				   csRef<iStringArray>& plugins,
				   bool recursive)
{
  iStringArray* messages = 0;

  if (!plugins)
    plugins.AttachNew (new scfStringArray ());

  InternalScanPluginDir (messages, dir, plugins, 
    recursive);
	 
  return csPtr<iStringArray> (messages);
}
Exemplo n.º 3
0
    void Run()
    {
        {
            CS::Threading::MutexScopedLock lock (doneMutex);
            // construct the netManager is its own thread to avoid wrong warnings of dynamic thread checking via valgrind
            netManager.AttachNew(new NetManager(thread));
            if (!netManager->Initialize(client_firstmsg, npcclient_firstmsg,
                                        timeout))
            {
                Error1 ("Network thread initialization failed!\nIs there already a server running?");
                delete netManager;
                netManager = NULL;
                initDone.NotifyAll();
                return;
            }
            initDone.NotifyAll();
        }

        /* run the network loop */
        netManager->Run();
    }
Exemplo n.º 4
0
csHandlerID RegisterWeakListener (iEventQueue *q, iEventHandler *listener,
  const csEventID ename[], csRef<iEventHandler> &handler)
{
  handler.AttachNew (new csWeakEventHandler (listener));
  return q->RegisterListener (handler, ename);
}
Exemplo n.º 5
0
bool LoadPrerequisiteXML(iDocumentNode * topNode, psQuest * self, csRef<psQuestPrereqOp>& prerequisite)
{
    // Recursively decode the xml document and generate prerequisite operators.

    if ( strcmp( topNode->GetValue(), "pre" ) == 0 )
    {
        // This is the top node. Only one node is legal.

        csRef<iDocumentNodeIterator> iter = topNode->GetNodes();

        while ( iter->HasNext() )
        {
            csRef<iDocumentNode> node = iter->Next();

            if ( node->GetType() != CS_NODE_ELEMENT )
                continue;

            if (!LoadPrerequisiteXML(node, self, prerequisite))
            {
                return false;
            }

            break;
        }
    }
    else if ( strcmp( topNode->GetValue(), "completed" ) == 0 )
    {
        if (topNode->GetAttributeValue("quest"))
        {
            csString name = topNode->GetAttributeValue("quest");
            psQuest * quest;
            if (name == "self")
            {
                quest = self;
            }
            else
            {
                quest = CacheManager::GetSingleton().GetQuestByName( name );
            }

            if (quest)
            {
                prerequisite.AttachNew(new psQuestPrereqOpQuestCompleted(quest));
            }
            else
            {
                Error2("Can't find quest %s while loading prerequisite script",
                       topNode->GetAttributeValue("quest"));
            }
        }
        else if (topNode->GetAttributeValue("category"))
        {
            int min = -1,max = -1;
            csString category = topNode->GetAttributeValue("category");
            if (topNode->GetAttributeValue("min")) min = topNode->GetAttributeValueAsInt("min");
            if (topNode->GetAttributeValue("max")) max = topNode->GetAttributeValueAsInt("max");
            if (min == -1 && max == -1)
            {
                Error1("Both min and max is -1, seting min to 1");
                min = 1;
            }
            prerequisite.AttachNew(new psQuestPrereqOpQuestCompletedCategory(category,min,max));
        }
        else
        {
            Error1("No attrib of quest or category in the completed node.");
            return false;
        }
    }
    else if ( strcmp( topNode->GetValue(), "assigned" ) == 0 )
    {
        csString name = topNode->GetAttributeValue("quest");
        psQuest * quest;
        if (name == "self")
        {
            quest = self;
        } else
        {
            quest = CacheManager::GetSingleton().GetQuestByName( name );
        }
        if (quest)
        {
            prerequisite.AttachNew(new psQuestPrereqOpQuestAssigned(quest));
        }
        else
        {
            Error2("Can't find quest %s while loading prerequisite script",
                   topNode->GetAttributeValue("quest"));
            return false;
        }
    }
    else if ( strcmp( topNode->GetValue(), "and" ) == 0 )
    {
        csRef<psQuestPrereqOpList> list;
        list.AttachNew(new psQuestPrereqOpAnd());
        prerequisite = list;

        csRef<iDocumentNodeIterator> iter = topNode->GetNodes();

        while ( iter->HasNext() )
        {
            csRef<iDocumentNode> node = iter->Next();

            if (node->GetType() != CS_NODE_ELEMENT)
                continue;

            csRef<psQuestPrereqOp> op;

            if (!LoadPrerequisiteXML(node, self, op))
            {
                return false;
            }

            if (op)
            {
                list->Push(op);
            }
            else
                return false;
        }
    }
    else if ( strcmp( topNode->GetValue(), "or" ) == 0 )
    {
        csRef<psQuestPrereqOpList> list;
        list.AttachNew(new psQuestPrereqOpOr());
        prerequisite = list;

        csRef<iDocumentNodeIterator> iter = topNode->GetNodes();

        while ( iter->HasNext() )
        {
            csRef<iDocumentNode> node = iter->Next();

            if ( node->GetType() != CS_NODE_ELEMENT )
                continue;

            csRef<psQuestPrereqOp> op;

            if (!LoadPrerequisiteXML(node, self, op))
            {
                return false;
            }

            if (op)
            {
                list->Push(op);
            }
            else
                return false;
        }
    }
    else if ( strcmp( topNode->GetValue(), "xor" ) == 0 )
    {
        csRef<psQuestPrereqOpList> list;
        list.AttachNew(new psQuestPrereqOpXor());
        prerequisite = list;

        csRef<iDocumentNodeIterator> iter = topNode->GetNodes();

        while ( iter->HasNext() )
        {
            csRef<iDocumentNode> node = iter->Next();

            if ( node->GetType() != CS_NODE_ELEMENT )
                continue;

            csRef<psQuestPrereqOp> op;

            if (!LoadPrerequisiteXML(node, self, op))
            {
                return false;
            }

            if (op)
            {
                list->Push(op);
            }
            else
                return false;
        }
    }
    else if ( strcmp( topNode->GetValue(), "require" ) == 0 )
    {
        int min = -1,max = -1;
        if (topNode->GetAttributeValue("min"))
            min = topNode->GetAttributeValueAsInt("min");
        if (topNode->GetAttributeValue("max"))
            max = topNode->GetAttributeValueAsInt("max");

        csRef<psQuestPrereqOpList> list;
        list.AttachNew(new psQuestPrereqOpRequire(min,max));
        prerequisite = list;

        csRef<iDocumentNodeIterator> iter = topNode->GetNodes();

        while ( iter->HasNext() )
        {
            csRef<iDocumentNode> node = iter->Next();

            if ( node->GetType() != CS_NODE_ELEMENT )
            continue;

            csRef<psQuestPrereqOp> op;

            if (!LoadPrerequisiteXML(node, self, op))
            {
                return false;
            }
            if (op)
            {
                list->Push(op);
            }
        }
    }
    else if ( strcmp( topNode->GetValue(), "faction" ) == 0 )
    {
        csString name = topNode->GetAttributeValue("name");
        if (name.IsEmpty())
        {
            Error1("No name given for faction prerequisite operation");
            return false;
        }

        Faction * faction = CacheManager::GetSingleton().GetFaction(name);
        if (!faction)
        {
            Error2("Can't find faction '%s' for faction prerequisite operation",name.GetDataSafe());
            return false;
        }

        int value = topNode->GetAttributeValueAsInt("value");

        int max = topNode->GetAttributeValueAsInt("max");

        prerequisite.AttachNew(new psQuestPrereqOpFaction(faction,value,max!=0));

    }
    else if ( strcmp( topNode->GetValue(), "item" ) == 0 )
    {
        csString name = topNode->GetAttributeValue("name");
        csString category = topNode->GetAttributeValue("category");
        if (name.IsEmpty() && category.IsEmpty())
        {
            Error1("No name or category given for item prerequisite operation");
            return false;
        }

        bool includeInventory = topNode->GetAttributeValueAsBool("inventory", false);
        prerequisite.AttachNew(new psQuestPrereqOpItem(name, category, includeInventory));
    }
    else if ( strcmp( topNode->GetValue(), "activemagic" ) == 0 )
    {
        csString name = topNode->GetAttributeValue("name");
        if (name.IsEmpty())
        {
            Error1("No name given for activemagic prerequisite operation");
            return false;
        }

        prerequisite.AttachNew(new psQuestPrereqOpActiveMagic(name));
    }
    else if ( strcmp( topNode->GetValue(), "race" ) == 0 )
    {
        csString name = topNode->GetAttributeValue("name");
        if (name.IsEmpty())
        {
            Error1("No race name given for race prerequisite operation");
            return false;
        }

        prerequisite.AttachNew(new psQuestPrereqOpRace(name));
    }
    else if ( strcmp( topNode->GetValue(), "gender" ) == 0 )
    {
        csString type = topNode->GetAttributeValue("type");
        if (type.IsEmpty())
        {
            Error1("No type given for gender prerequisite operation");
            return false;
        }

        prerequisite.AttachNew(new psQuestPrereqOpGender(type));
    }
    else if ( strcmp( topNode->GetValue(), "knownspell" ) == 0 )
    {
        csString spell = topNode->GetAttributeValue("spell");
        if (spell.IsEmpty())
        {
            Error1("No spell given for kwownspell prerequisite operation");
            return false;
        }

        prerequisite.AttachNew(new psQuestPrereqOpKnownSpell(spell));
    }
    else if ( strcmp( topNode->GetValue(), "trait" ) == 0 )
    {
        csString name = topNode->GetAttributeValue("name");
        if (name.IsEmpty())
        {
            Error1("No name given for trait prerequisite operation");
            return false;
        }
        csString location = topNode->GetAttributeValue("name");
        if (location.IsEmpty())
        {
            Error1("No location given for trait prerequisite operation");
            return false;
        }

        prerequisite.AttachNew(new psQuestPrereqOpTrait(name, location));
    }
    else if ( strcmp( topNode->GetValue(), "guild" ) == 0 )
    {
        csString type = topNode->GetAttributeValue("type");
        if (type.IsEmpty())
        {
            Error1("No type given for guild prerequisite operation");
            return false;
        }
        
        csString name = topNode->GetAttributeValue("name");

        prerequisite.AttachNew(new psQuestPrereqOpGuild(type, name));
    }
    else if ( strcmp( topNode->GetValue(), "married" ) == 0 ) //wrap in <not></not> to reverse
    {
        prerequisite.AttachNew(new psQuestPrereqOpMarriage);
    }
    else if ( strcmp( topNode->GetValue(), "advisorpoints" ) == 0 )
    {
        int min = topNode->GetAttributeValueAsInt("min");

        int max = topNode->GetAttributeValueAsInt("max");

        csString type = topNode->GetAttributeValue("type");

        if (type.IsEmpty())
        {
            Error1("No type given for advisorpoints prerequisite operation");
            return false;
        }

        prerequisite.AttachNew(new psQuestPrereqOpAdvisorPoints(min,max,type));
    }
    else if ( strcmp( topNode->GetValue(), "timeofday" ) == 0 )
    {
        int min = topNode->GetAttributeValueAsInt("min");

        int max = topNode->GetAttributeValueAsInt("max");

        prerequisite.AttachNew(new psQuestPrereqOpTimeOfDay(min,max));

    }
    else if ( strcmp( topNode->GetValue(), "onlinetime" ) == 0 )
    {
        int min = topNode->GetAttributeValueAsInt("min");

        int max = topNode->GetAttributeValueAsInt("max");

        prerequisite.AttachNew(new psQuestPrereqOpTimeOnline(min,max));

    }
    else if ( strcmp( topNode->GetValue(), "not" ) == 0 )
    {
        csRef<iDocumentNodeIterator> iter = topNode->GetNodes();

        while ( iter->HasNext() )
        {
            csRef<iDocumentNode> node = iter->Next();

            if ( node->GetType() != CS_NODE_ELEMENT )
            continue;

            csRef<psQuestPrereqOp> op;
            if (!LoadPrerequisiteXML(node, self, op))
            {
                return false;
            }
            csRef<psQuestPrereqOpList> list;
            list.AttachNew(new psQuestPrereqOpNot());
            list->Push(op);
            prerequisite = list;
            break;
        }
    }
    else if ( strcmp( topNode->GetValue(), "skill" ) == 0 )
    {
        csString name = topNode->GetAttributeValue("name");
        if (name.IsEmpty())
        {
            Error1("No name given for skill prerequisite operation");
            return false;
        }

        psSkillInfo * skill = CacheManager::GetSingleton().GetSkillByName( name );
        if (!skill)
        {
            Error2("Can't find skill '%s' for skill prerequisite operation",name.GetDataSafe());
            return false;
        }

        unsigned int min = topNode->GetAttributeValueAsInt("min");

        unsigned int max = topNode->GetAttributeValueAsInt("max");

        prerequisite.AttachNew(new psQuestPrereqOpSkill(skill,min,max));
    }
    else
    {
        Error2("Node \"%s\" isn't supported in  prerequisite scripts",topNode->GetValue());
        return false;
    }
    return true;
}