Ejemplo n.º 1
0
bool _3dsLoadSubChunks(HANDLE h, CHUNK *root, DWORD offset, DWORD length)
{
	while(length)
	{
		SetFilePointer(h, offset, 0, 0);

		CHUNK *chunk;
		chunk = new CHUNK;
		memset(chunk, 0, sizeof(CHUNK));
		LINK(root->Child, chunk);
		chunk->offset = offset;

		DWORD dwR = 0;
		ReadFile(h, &chunk->hdr, sizeof(CHUNK_HDR), &dwR, 0);
		if(dwR != sizeof(CHUNK_HDR))
		{
			ErrorMsg("read error");
			return false;
		}

		length -= chunk->hdr.length;
		offset += chunk->hdr.length;

		switch(chunk->hdr.id)
		{
		// just read data
		case POINT_ARRAY:
		case MSH_MAT_GROUP:
		case MAT_NAME:
		case COLOR_24:
		case MAT_MAPNAME:
		case TEX_VERTS:
			chunk->data_size = chunk->hdr.length - sizeof(CHUNK_HDR);
			chunk->data = _3dsLoadData(h, chunk->offset + sizeof(CHUNK_HDR), chunk->data_size);
			if(!chunk->data) return false;
			break;

		// just read chunks
		case MDATA:
		case N_TRI_OBJECT:
		case MAT_ENTRY:
		case MAT_DIFFUSE:
		case MAT_SPECULAR:
		case MAT_TEXMAP:
			if(!_3dsLoadSubChunks(h, chunk, chunk->offset + sizeof(CHUNK_HDR), chunk->hdr.length - sizeof(CHUNK_HDR))) return false;
			break;

		case NAMED_OBJECT:
			{
				char str[11];
				dwR = 0;
				ReadFile(h, str, 11, &dwR, 0);
				if(dwR != 11)
				{
					ErrorMsg("read error");
					return false;
				}

				chunk->data_size = strlen(str) + 1;
				chunk->data = malloc(chunk->data_size);
				memcpy(chunk->data, str, chunk->data_size);

				if(!_3dsLoadSubChunks(h, chunk, chunk->offset + sizeof(CHUNK_HDR) + chunk->data_size, chunk->hdr.length - sizeof(CHUNK_HDR) - chunk->data_size)) return false;
			}
			break;

		case FACE_ARRAY:
			{
				WORD w;
				dwR = 0;
				ReadFile(h, &w, sizeof(WORD), &dwR, 0);
				if(dwR != sizeof(WORD))
				{
					ErrorMsg("read error");
					return false;
				}

				chunk->data_size = sizeof(WORD) + w * sizeof(_3DS_FACE);
				chunk->data = _3dsLoadData(h, chunk->offset + sizeof(CHUNK_HDR), chunk->data_size);

				if(!_3dsLoadSubChunks(h, chunk, chunk->offset + sizeof(CHUNK_HDR) + chunk->data_size, chunk->hdr.length - sizeof(CHUNK_HDR) - chunk->data_size)) return false;
			}
			break;

		default: // unknow
			UNLINK(root->Child, chunk);
			delete chunk;
		}
	}

	return true;
}
Ejemplo n.º 2
0
    virtual void process() override
    {
        ActPrintLog("INDEXWRITE: Start");
        init();

        IRowStream *stream = inputStream;
        ThorDataLinkMetaInfo info;
        input->getMetaInfo(info);
        outRowAllocator.setown(getRowAllocator(helper->queryDiskRecordSize()));
        start();
        if (refactor)
        {
            assertex(isLocal);
            if (active)
            {
                unsigned targetWidth = partDesc->queryOwner().numParts()-(buildTlk?1:0);
                assertex(0 == container.queryJob().querySlaves() % targetWidth);
                unsigned partsPerNode = container.queryJob().querySlaves() / targetWidth;
                unsigned myPart = queryJobChannel().queryMyRank();

                IArrayOf<IRowStream> streams;
                streams.append(*LINK(stream));
                --partsPerNode;

 // Should this be merging 1,11,21,31 etc.
                unsigned p=0;
                unsigned fromPart = targetWidth+1 + (partsPerNode * (myPart-1));
                for (; p<partsPerNode; p++)
                {
                    streams.append(*createRowStreamFromNode(*this, fromPart++, queryJobChannel().queryJobComm(), mpTag, abortSoon));
                }
                ICompare *icompare = helper->queryCompare();
                assertex(icompare);
                Owned<IRowLinkCounter> linkCounter = new CThorRowLinkCounter;
                myInputStream.setown(createRowStreamMerger(streams.ordinality(), streams.getArray(), icompare, false, linkCounter));
                stream = myInputStream;
            }
            else // serve nodes, creating merged parts
                rowServer.setown(createRowServer(this, stream, queryJobChannel().queryJobComm(), mpTag));
        }
        processed = THORDATALINK_STARTED;

        // single part key support
        // has to serially pull all data fron nodes 2-N
        // nodes 2-N, could/should start pushing some data (as it's supposed to be small) to cut down on serial nature.
        unsigned node = queryJobChannel().queryMyRank();
        if (singlePartKey)
        {
            if (1 == node)
            {
                try
                {
                    open(*partDesc, false, helper->queryDiskRecordSize()->isVariableSize());
                    loop
                    {
                        OwnedConstThorRow row = inputStream->ungroupedNextRow();
                        if (!row)
                            break;
                        if (abortSoon) return;
                        processRow(row);
                    }

                    unsigned node = 2;
                    while (node <= container.queryJob().querySlaves())
                    {
                        Linked<IOutputRowDeserializer> deserializer = ::queryRowDeserializer(input);
                        CMessageBuffer mb;
                        Owned<ISerialStream> stream = createMemoryBufferSerialStream(mb);
                        CThorStreamDeserializerSource rowSource;
                        rowSource.setStream(stream);
                        bool successSR;
                        loop
                        {
                            {
                                BooleanOnOff tf(receivingTag2);
                                successSR = queryJobChannel().queryJobComm().sendRecv(mb, node, mpTag2);
                            }
                            if (successSR)
                            {
                                if (rowSource.eos())
                                    break;
                                Linked<IEngineRowAllocator> allocator = ::queryRowAllocator(input);
                                do
                                {
                                    RtlDynamicRowBuilder rowBuilder(allocator);
                                    size32_t sz = deserializer->deserialize(rowBuilder, rowSource);
                                    OwnedConstThorRow fRow = rowBuilder.finalizeRowClear(sz);
                                    processRow(fRow);
                                }
                                while (!rowSource.eos());
                            }
                        }
                        node++;
                    }
                }
                catch (CATCHALL)
                {
                    close(*partDesc, partCrc, true);
                    throw;
                }
                close(*partDesc, partCrc, true);
                doStopInput();
            }
            else
            {
                CMessageBuffer mb;
                CMemoryRowSerializer mbs(mb);
                Linked<IOutputRowSerializer> serializer = ::queryRowSerializer(input);
                loop
                {
                    BooleanOnOff tf(receivingTag2);
                    if (queryJobChannel().queryJobComm().recv(mb, 1, mpTag2)) // node 1 asking for more..
                    {
                        if (abortSoon) break;
                        mb.clear();
                        do
                        {
                            OwnedConstThorRow row = inputStream->ungroupedNextRow();
                            if (!row) break;
                            serializer->serialize(mbs, (const byte *)row.get());
                        } while (mb.length() < SINGLEPART_KEY_TRANSFER_SIZE); // NB: at least one row
                        if (!queryJobChannel().queryJobComm().reply(mb))
                            throw MakeThorException(0, "Failed to send index data to node 1, from node %d", node);
                        if (0 == mb.length())
                            break;
                    }
                }
            }
        }
void LengauerTarjan::immediateDominators(){

    uint32_t dfsNo = 0;
    depthFirstSearch(rootLoc,&dfsNo);

    size[0]  = 0;
    label[0] = 0;
    semi[0]  = 0;

    for(int32_t i=reachableCount;i>1;i--){
        uint32_t vertexW =  vertex[i];

        BasicBlock* bb = locToBasicBlock[vertexW];
        ASSERT(bb && "Basic Block should be initialized");
        uint32_t numberOfSources = bb->getNumberOfSources();

        for(uint32_t j=0;j<numberOfSources;j++){
            BasicBlock* source = bb->getSourceBlock(j);
            if(!source->isUnreachable()){
                uint32_t vertexV = basicBlockToLoc[source->getIndex()];
                uint32_t vertexU = EVAL(vertexV);
                if(semi[vertexU] < semi[vertexW]){
                    semi[vertexW] = semi[vertexU];
                }
            }
        }

        bucket[vertex[semi[vertexW]]].insert(vertexW);

        LINK(parent[vertexW],vertexW);

        LinkedList<uint32_t>* bs = &(bucket[parent[vertexW]]);
        while(!bs->empty()){
            uint32_t vertexV = bs->shift();
            uint32_t vertexU = EVAL(vertexV);
            dom[vertexV] = ( semi[vertexU] < semi[vertexV] ) ? vertexU : parent[vertexW];
        }
    }
    for(uint32_t i=2;i<=reachableCount;i++){
        uint32_t vertexW = vertex[i];
        if(dom[vertexW] != vertex[semi[vertexW]]){
            dom[vertexW] = dom[dom[vertexW]];
        }
    }

    dom[rootLoc] = 0;
    PRINT_DEBUG("ROOT is %d",rootLoc);

    for(uint32_t i=1;i<=reachableCount;i++){
        uint32_t vertexW = vertex[i];
        BasicBlock* bb = locToBasicBlock[vertexW];
        ASSERT(!bb->isUnreachable());
        BasicBlock* immDom = locToBasicBlock[dom[vertexW]];
        if(immDom){
            PRINT_DEBUG("Reachable : Immediate Dominator of %d is %d",bb->getIndex(),immDom->getIndex());
            bb->setImmDominator(immDom);
        } else {
            PRINT_DEBUG("Reachable : Immediate Dominator of %d is Entry",bb->getIndex());
        }
    }
    for(int32_t i=nodeCount;i>reachableCount;i--){
        BasicBlock* bb = locToBasicBlock[i];
        ASSERT(bb->isUnreachable());
        BasicBlock* immDom = locToBasicBlock[rootLoc];
        PRINT_DEBUG("Un-Reachable : Immediate Dominator of %d is %d",bb->getIndex(),immDom->getIndex());
        bb->setImmDominator(immDom);
    }
}
Ejemplo n.º 4
0
inline void extendOrCondition(SharedHqlExpr & cond, IHqlExpression * r)
{
    cond.setown(extendConditionOwn(no_or, cond.getClear(), LINK(r)));
}
Ejemplo n.º 5
0
void cleanup_session(struct session *ses)
{
	push_call("cleanup_session(%p)",ses);

	if (HAS_BIT(ses->flags, SES_FLAG_CLOSED))
	{
		tintin_printf2(NULL, "\n#SESSION '%s' IS ALREADY CLOSED.", ses->name);
		dump_stack();

		pop_call();
		return;
	}

	if (ses == gtd->update)
	{
		gtd->update = ses->next;
	}

	UNLINK(ses, gts->next, gts->prev);

	if (ses->socket)
	{
		if (close(ses->socket) == -1)
		{
			syserr("close in cleanup");
		}

		// the PID is stored in the session's port.

		if (HAS_BIT(ses->flags, SES_FLAG_RUN))
		{
			kill(atoi(ses->port), SIGKILL);
		}

	}

	SET_BIT(ses->flags, SES_FLAG_CLOSED);

	if (HAS_BIT(ses->flags, SES_FLAG_CONNECTED))
	{
		check_all_events(ses, SUB_ARG|SUB_SEC, 0, 4, "SESSION DISCONNECTED", ses->name, ses->host, ses->ip, ses->port);

		tintin_printf(gtd->ses, "#SESSION '%s' DIED.", ses->name);
	}
	else
	{
		check_all_events(ses, SUB_ARG|SUB_SEC, 0, 4, "SESSION TIMED OUT", ses->name, ses->host, ses->ip, ses->port);

		tintin_printf(gtd->ses, "#SESSION '%s' TIMED OUT.", ses->name);
	}

	if (ses == gtd->ses)
	{
		gtd->ses = newactive_session();
	}

	if (ses->logfile)
	{
		fclose(ses->logfile);
	}

	if (ses->logline)
	{
		fclose(ses->logline);
	}

	LINK(ses, gtd->dispose_next, gtd->dispose_prev);

	pop_call();
	return;
}
Ejemplo n.º 6
0
IHqlExpression * PositionTransformer::createTransformed(IHqlExpression * _expr)
{
    OwnedHqlExpr transformed = NewHqlTransformer::createTransformed(_expr);

    switch (transformed->getOperator())
    {
    case no_table:
        {
            IHqlExpression * mode = transformed->queryChild(2);
            HqlExprArray fields;
            HqlExprArray args;

            if (mode->getOperator() == no_thor)
            {
                unwindChildren(fields, transformed->queryChild(1));
                IHqlExpression * filePosAttr = createComma(createAttribute(virtualAtom, createAttribute(filepositionAtom)), insertedAttr.getLink());
                IHqlExpression * sizeofAttr = createComma(createAttribute(virtualAtom, createAttribute(sizeofAtom)), insertedAttr.getLink());
                fields.append(*createField(fileposName, makeIntType(8, false), NULL, filePosAttr));
                fields.append(*createField(recordlenName, makeIntType(2, false), NULL, sizeofAttr));

                unwindChildren(args, transformed);
                args.replace(*createRecord(fields), 1);
                return transformed->clone(args);
            }
        }
        break;
    case no_iterate:
    case no_hqlproject:
        {
            HqlExprArray args;
            HqlExprArray assigns;
            IHqlExpression * transform = transformed->queryChild(1);
            unwindChildren(args, transformed);
            unwindChildren(assigns, transform);
            IHqlExpression * inRecord = transformed->queryChild(0)->queryRecord();
            IHqlExpression * outRecord = transform->queryRecord();

            HqlExprArray fields;
            unwindChildren(fields, outRecord);
            ForEachChild(idx, inRecord)
            {
                IHqlExpression * child = inRecord->queryChild(idx);
                if (child->hasProperty(insertedAtom))
                {
                    IHqlExpression * newTarget = createField(child->queryName(), child->getType(), LINK(child), insertedAttr.getLink());
                    fields.append(*newTarget);
                    assigns.append(*createValue(no_assign, makeVoidType(), newTarget, createSelectExpr(createValue(no_left), LINK(newTarget))));
                }
            }
            IHqlExpression * newRecord = createRecord(fields);
            args.replace(*createValue(no_transform, newRecord->getType(), assigns), 1);
            return transformed->clone(args);
        }
        break;
    case no_join:
        //only ok if join first
    case no_rollup:
    case no_newaggregate:
    case no_aggregate:
        fail();
        break;
    case no_usertable:
    case no_selectfields:
        {
            IHqlExpression * grouping = transformed->queryChild(2);
            if (grouping && (grouping->getOperator() != no_attr))
                fail();
            IHqlExpression * record = transformed->queryRecord();
            HqlExprArray fields;
            unwindChildren(fields, transformed->queryChild(1));
            ForEachChild(idx, record)
            {
                IHqlExpression * child = record->queryChild(idx);
                if (child->hasProperty(insertedAtom))
                    fields.append(*createField(child->queryName(), child->getType(), LINK(child), insertedAttr.getLink()));
            }

            HqlExprArray args;
            unwindChildren(args, transformed);
            args.replace(*createRecord(fields), 1);
            return transformed->clone(args);
        }
Ejemplo n.º 7
0
IHqlExpression * FullExpandMonitor::onExpandSelector()
{
    return LINK(createRow);
//  return createValue(no_newrow, LINK(createRow));
}
Ejemplo n.º 8
0
void addShutdownHook(IDaliClientShutdown &shutdown)
{
    shutdownHooks.append(*LINK(&shutdown));
}
Ejemplo n.º 9
0
extern jlib_decl IRecordSize *createDeltaRecordSize(IRecordSize * size, int delta)
{
    if (delta == 0)
        return LINK(size);
    return new CDeltaRecordSize(size, delta);
}
Ejemplo n.º 10
0
/* load the linked list from disk */
void load_news( void )
{
   FILE *fp = NULL;
   char filename[256];

   sprintf( filename, "%s%s", SYSTEM_DIR, NEWS_FILE );
   if( ( fp = fopen( filename, "r" ) ) == NULL )
   {
      perror( "load_news(): cannot open file" );
      return;
   }

   for( ;; )
   {
      NEWS_TYPE *type = NULL;
      NEWS *news = NULL;
      char *word;
      char letter;

      letter = fread_letter( fp );

      if( letter == '*' )
      {
         fread_to_eol( fp );
         continue;
      }

      if( letter != '#' )
      {
         bug( "load_news(): # not found" );
         break;
      }

      word = fread_word( fp );

      if( !str_cmp( word, "NEWS" ) )
      {
         CREATE( news, NEWS, 1 );
         news->type = -1;

         fread_news( news, fp );
         link_news_to_type( news );
         continue;
      }
      /*
       * added for new indexing - 5/5/02 
       */
      else if( !str_cmp( word, "NEWSTYPE" ) )
      {
         CREATE( type, NEWS_TYPE, 1 );

         fread_news_type( type, fp );
         LINK( type, first_news_type, last_news_type, next, prev );
         continue;
      }
      if( !str_cmp( word, "END" ) )
         break;
      else
      {
         bug( "load_news(): unknown section %s", word );
         continue;
      }
   }
   fclose( fp );
   fp = NULL;
   renumber_news(  );
   return;
}
Ejemplo n.º 11
0
/*
 * Add a reset to an area -Thoric
 */
RESET_DATA *add_reset( ROOM_INDEX_DATA * room, char letter, int extra, int arg1, int arg2, int arg3 )
{
	RESET_DATA *pReset;

	if ( !room )
	{
		bug( "%s: NULL room!", __FUNCTION__ );
		return NULL;
	}

	letter = UPPER( letter );
	pReset = make_reset( letter, extra, arg1, arg2, arg3 );
	pReset->sreset = TRUE;

	switch ( letter )
	{
		case 'M':
			room->last_mob_reset = pReset;
			break;

		case 'E':
		case 'G':
			if ( !room->last_mob_reset )
			{
				bug( "%s: Can't add '%c' reset to room: last_mob_reset is NULL.", __FUNCTION__, letter );
				return NULL;
			}
			room->last_obj_reset = pReset;
			LINK( pReset, room->last_mob_reset->first_reset, room->last_mob_reset->last_reset, next_reset, prev_reset );
			return pReset;

		case 'P':
			if ( !room->last_obj_reset )
			{
				bug( "%s: Can't add '%c' reset to room: last_obj_reset is NULL.", __FUNCTION__, letter );
				return NULL;
			}
			LINK( pReset, room->last_obj_reset->first_reset, room->last_obj_reset->last_reset, next_reset, prev_reset );
			return pReset;

		case 'O':
			room->last_obj_reset = pReset;
			break;

		case 'T':
			if ( IS_SET( extra, TRAP_OBJ ) )
			{
				pReset->prev_reset = NULL;
				pReset->next_reset = room->last_obj_reset->first_reset;
				if ( room->last_obj_reset->first_reset )
					room->last_obj_reset->first_reset->prev_reset = pReset;
				room->last_obj_reset->first_reset = pReset;
				if ( !room->last_obj_reset->last_reset )
					room->last_obj_reset->last_reset = pReset;
				return pReset;
			}
			break;

		case 'H':
			pReset->prev_reset = NULL;
			pReset->next_reset = room->last_obj_reset->first_reset;
			if ( room->last_obj_reset->first_reset )
				room->last_obj_reset->first_reset->prev_reset = pReset;
			room->last_obj_reset->first_reset = pReset;
			if ( !room->last_obj_reset->last_reset )
				room->last_obj_reset->last_reset = pReset;
			return pReset;
	}
	LINK( pReset, room->first_reset, room->last_reset, next, prev );
	return pReset;
}
Ejemplo n.º 12
0
/* olc editnews command */
void do_editnews( CHAR_DATA* ch, const char* argument)
{
   char arg[MAX_INPUT_LENGTH];

   if( IS_NPC( ch ) || !IS_IMMORTAL( ch ) )
   {
      send_to_char( "Huh?\r\n", ch );
      return;
   }

   set_char_color( AT_GREEN, ch );

   switch ( ch->substate )
   {
      default:
         break;

      case SUB_NEWS_POST:
      {
         NEWS *news = NULL;

         news = ( NEWS * ) ch->dest_buf;
         STRFREE( news->post );
         news->post = copy_buffer( ch );
         stop_editing( ch );
         ch->substate = ch->tempnum;
         renumber_news(  );
         save_news(  );
         return;
      }
         break;

      case SUB_NEWS_EDIT:
      {
         NEWS *news = NULL;

         news = ( NEWS * ) ch->dest_buf;
         STRFREE( news->post );
         news->post = copy_buffer( ch );
         stop_editing( ch );
         ch->substate = ch->tempnum;
         renumber_news(  );
         save_news(  );
         return;
      }
         break;
   }

   argument = one_argument( argument, arg );

   if( arg[0] == '\0' )
   {
      send_to_char( "Syntax: editnews addtype <name>\r\n"
                    "        editnews addnews <type> <subject>\r\n"
                    "        editnews removetype <number>\r\n"
                    "        editnews removenews <type> <number>\r\n"
                    "        editnews edittype <field> <value>\r\n"
                    "        editnews editnews <type> <number> <new subject [optional]>\r\n"
                    " Fields being one of the following:\r\n" " name header cmd_name level\r\n", ch );
      return;
   }

   if( !str_cmp( arg, "save" ) )
   {
      renumber_news(  );
      save_news(  );
      send_to_char( "News saved.\r\n", ch );
      return;
   }

   if( !str_cmp( arg, "addtype" ) )
   {
      NEWS_TYPE *type = NULL;

      if( argument[0] == '\0' )
      {
         send_to_char( "Syntax: editnews addtype <name>\r\n", ch );
         return;
      }

      if( top_news_type >= NEWS_MAX_TYPES )
      {
         send_to_char( "There are too many news types.\r\n", ch );
         return;
      }

      CREATE( type, NEWS_TYPE, 1 );
      type->name = STRALLOC( argument );
      type->cmd_name = STRALLOC( argument );
      type->vnum = top_news_type++;
      type->level = -1;

      news_command_table[type->vnum] = STRALLOC( type->cmd_name );

      LINK( type, first_news_type, last_news_type, next, prev );
      ch_printf( ch, "Newstype '%s' created.\r\n", argument );
      return;
   }

   if( !str_cmp( arg, "removetype" ) )
   {
      NEWS_TYPE *type = NULL;
      NEWS *news = NULL, *news_next;

      if( argument[0] == '\0' )
      {
         send_to_char( "Syntax: editnews removetype <name>\r\n", ch );
         return;
      }

      if( ( type = figure_type( argument ) ) == NULL )
      {
         send_to_char( "Invaild newstype.\r\n", ch );
         return;
      }

      UNLINK( type, first_news_type, last_news_type, next, prev );
      STRFREE( type->name );
      STRFREE( type->header );
      STRFREE( type->cmd_name );
      STRFREE( news_command_table[type->vnum] );
      STRFREE( news_command_table[type->level] );

      for( news = type->first_news; news; news = news_next )
      {
         news_next = news->next;

         UNLINK( news, type->first_news, type->last_news, next, prev );
         STRFREE( news->name );
         STRFREE( news->title );
         STRFREE( news->date );
         STRFREE( news->post );
         DISPOSE( news );
      }

      DISPOSE( type );
      --top_news_type;
      renumber_news(  );
      save_news(  );
      ch_printf( ch, "Newstype '%s' removed.\r\n", argument );
      return;
   }

   if( !str_cmp( arg, "edittype" ) )
   {
      char arg2[MAX_INPUT_LENGTH];
      char arg3[MAX_INPUT_LENGTH];
      NEWS_TYPE *type = NULL;

      argument = one_argument( argument, arg2 );
      argument = one_argument( argument, arg3 );
      if( arg2[0] == '\0' || arg3[0] == '\0' )
      {
         send_to_char( "Syntax: editnews edittype <type> <field> <value>\r\n", ch );
         send_to_char( "Fields being one of the following:\r\n" "name header cmd_name level\r\n", ch );
         return;
      }

      if( ( type = figure_type( arg2 ) ) == NULL )
      {
         send_to_char( "Invalid newstype.\r\n", ch );
         return;
      }

      if( !str_cmp( arg3, "cmd_name" ) )
      {
         type->cmd_name = STRALLOC( argument );
         news_command_table[type->vnum] = STRALLOC( type->cmd_name );
         send_to_char( "Cmd_name set.\r\n", ch );
         save_news(  );
         return;
      }
      else if( !str_cmp( arg3, "name" ) )
      {
         type->name = STRALLOC( argument );
         send_to_char( "Name set.\r\n", ch );
         save_news(  );
         return;
      }
      else if( !str_cmp( arg3, "level" ) )
      {
         if( argument[0] == '\0' )
         {
            ch_printf( ch, "%d\r\n", type->level );
            return;
         }
         else
            type->level = atoi( argument );
         send_to_char( "Level set.\r\n", ch );
         save_news(  );
         return;
      }
      else
      {
         send_to_char( "Syntax: editnews edittype <type> <field> <value>\r\n", ch );
         send_to_char( "Fields being one of the following:\r\n" "name header cmd_name level\r\n", ch );
         return;
      }
   }

   if( !str_cmp( arg, "addnews" ) )
   {
      char arg2[MAX_INPUT_LENGTH];
      NEWS_TYPE *type = NULL;
      NEWS *news = NULL;

      argument = one_argument( argument, arg2 );

      if( arg2[0] == '\0' || argument[0] == '\0' )
      {
         send_to_char( "Syntax: editnews addnews <type> <subject>\r\n", ch );
         return;
      }

      if( ( type = figure_type( arg2 ) ) == NULL )
      {
         send_to_char( "Invaild newstype. Use 'newstypes' to get a valid listing.\r\n", ch );
         return;
      }

      CREATE( news, NEWS, 1 );
      news->title = STRALLOC( argument );
      news->name = STRALLOC( ch->name );
      news->date = STRALLOC( stamp_time(  ) );
      news->post = STRALLOC( "" );

      /*
       * pop character into a writing buffer 
       */
      if( ch->substate == SUB_REPEATCMD )
         ch->tempnum = SUB_REPEATCMD;
      else
         ch->tempnum = SUB_NONE;

      ch->substate = SUB_NEWS_POST;
      ch->dest_buf = news;
      start_editing( ch, news->post );
      LINK( news, type->first_news, type->last_news, next, prev );
      return;
   }

   if( !str_cmp( arg, "editnews" ) )
   {
      char arg2[MAX_INPUT_LENGTH];
      char arg3[MAX_INPUT_LENGTH];
      NEWS *news = NULL;
      NEWS_TYPE *type = NULL;

      argument = one_argument( argument, arg2 );
      argument = one_argument( argument, arg3 );
      if( arg2[0] == '\0' )
      {
         send_to_char( "Syntax: editnews editnews <type> <number> <new subject [optional]>\r\n", ch );
         return;
      }

      /*
       * changed for new -newstype- indexing - 5/5/02 
       */
      if( ( type = figure_type( arg2 ) ) == NULL )
      {
         send_to_char( "Invalid newstype. Use 'newstypes' to get a valid listing.\r\n", ch );
         return;
      }

      if( ( news = grab_news( type, arg3 ) ) == NULL )
      {
         pager_printf_color( ch, "That's not a valid news number.\r\nUse '%s' to view the valid numbers.\r\n",
                             type->cmd_name );
         return;
      }

      /*
       * a changed title 
       */
      if( argument[0] != '\0' )
         news->title = STRALLOC( argument );

      /*
       * new date news was edited 
       */
      news->date = STRALLOC( stamp_time(  ) );
      /*
       * pop character into a writing buffer 
       */
      if( ch->substate == SUB_REPEATCMD )
         ch->tempnum = SUB_REPEATCMD;
      else
         ch->tempnum = SUB_NONE;

      ch->substate = SUB_NEWS_EDIT;
      ch->dest_buf = news;
      start_editing( ch, news->post );
      return;
   }

   if( !str_cmp( arg, "removenews" ) )
   {
      char arg2[MAX_INPUT_LENGTH];
      NEWS *news = NULL;
      NEWS_TYPE *type = NULL;

      argument = one_argument( argument, arg2 );
      if( argument[0] == '\0' || arg2[0] == '\0' )
      {
         send_to_char( "Syntax: editnews remove <number>\r\n", ch );
         return;
      }

      /*
       * changed for new -newstype- indexing - 5/5/02 
       */
      if( ( type = figure_type( arg2 ) ) == NULL )
      {
         send_to_char( "Invalid newstype. Use 'newstypes' to get a valid listing.\r\n", ch );
         return;
      }

      if( ( news = grab_news( type, argument ) ) == NULL )
      {
         send_to_char( "Type 'news' to gain a list of the news numbers.\r\n", ch );
         return;
      }

      UNLINK( news, type->first_news, type->last_news, next, prev );
      STRFREE( news->name );
      STRFREE( news->title );
      STRFREE( news->date );
      STRFREE( news->post );
      DISPOSE( news );
      renumber_news(  );
      save_news(  );
      send_to_char( "News item removed.\r\n", ch );
      return;
   }
}
Ejemplo n.º 13
0
void redit_parse( DESCRIPTOR_DATA *d , char *arg )
{
	ROOM_DATA		 *room  = d->character->dest_buf;
	ROOM_DATA		 *tmp;
	EXIT_DATA		 *pexit = d->character->spare_ptr;
	EXTRA_DESCR_DATA *ed	  = d->character->spare_ptr;
	char			  arg1[MIL];
	char			  buf[MSL];
	int				  number = 0;

	switch ( OLC_MODE(d) )
	{
	  case REDIT_CONFIRM_SAVESTRING:
		switch ( *arg )
		{
		  case 'y':
		  case 'Y':
			/* redit_save_internally(d); */
			send_log( NULL, LOG_OLC, "OLC: %s edits room %d", d->character->name, OLC_NUM(d) );
			cleanup_olc( d );
			send_to_char( d->character, "Room saved to memory.\r\n" );
			break;
		  case 'n':
		  case 'N':
			cleanup_olc( d );
			break;
		  default:
			send_to_char( d->character, "Invalid choice!\r\n" );
			send_to_char( d->character, "Do you wish to save this room internally? : " );
			break;
		}
		return;

	  case REDIT_MAIN_MENU:
		switch ( *arg )
		{
		  case 'q':
		  case 'Q':
/*			if ( OLC_CHANGE(d) )
			{ *. Something has been modified .*
				send_to_char( d->character, "Do you wish to save this room internally? : " );
				OLC_MODE(d) = REDIT_CONFIRM_SAVESTRING;
			}
			else */
			cleanup_olc( d );
			return;
		  case '1':
			send_to_char( d->character, "Enter room name:-\r\n| " );
			OLC_MODE(d) = REDIT_NAME;
			break;
		  case '2':
			OLC_MODE(d) = REDIT_DESC;
			d->character->substate = SUB_ROOM_DESCR;
			d->character->last_cmd = do_redit_reset;

			send_to_char( d->character, "Enter room description:-\r\n" );
			if ( !room->description )
				room->description = str_dup( "" );
			start_editing( d->character, room->description );
			break;
		  case '3':
			redit_disp_flag_menu(d);
			break;
		  case '4':
			redit_disp_sector_menu(d);
			break;
		  case '5':
			send_to_char( d->character, "How many people can fit in the room? " );
			OLC_MODE(d) = REDIT_TUNNEL;
			break;
		  case '6':
			send_to_char( d->character, "How long before people are teleported out? " );
			OLC_MODE(d) = REDIT_TELEDELAY;
			break;
		  case '7':
			send_to_char( d->character, "Where are they teleported to? " );
			OLC_MODE(d) = REDIT_TELEVNUM;
			break;
		  case 'a':
		  case 'A':
			redit_disp_exit_menu(d);
			break;
		  case 'b':
		  case 'B':
			redit_disp_extradesc_menu(d);
			break;

		  default:
			send_to_char( d->character, "Invalid choice!" );
			redit_disp_menu(d);
			break;
		}
		return;

	  case REDIT_NAME:
		DISPOSE( room->name );
		room->name = str_dup( arg );
		olc_log( d, "Changed name to %s", room->name );
		break;

	  case REDIT_DESC:
		/* we will NEVER get here */
		send_log( NULL, LOG_OLC, "redit_parse: reached REDIT_DESC case in redit_parse" );
		break;

	  case REDIT_FLAGS:
		if ( is_number(arg) )
		{
			number = atoi( arg );
			if ( number == 0 )
				break;
			else if ( number < 0 || number >= MAX_ROOM )
			{
				send_to_char( d->character, "Invalid flag, try again: " );
				return;
			}
			else
			{
				number--;	/* Offset for 0 */
				TOGGLE_BIT( room->flags, number );
				olc_log( d, "%s the room flag %s",
				HAS_BIT( room->flags, number ) ? "Added" : "Removed",
				code_name(NULL, number, CODE_ROOM) );
			}
		}
		else
		{
			while ( VALID_STR(arg) )
			{
				arg = one_argument( arg, arg1 );
				number = code_num( NULL, arg1, CODE_ROOM );
				if ( number > 0 )
				{
					TOGGLE_BIT( room->flags, number );
					olc_log( d, "%s the room flag %s",
						HAS_BIT( room->flags, number ) ? "Added" : "Removed",
						code_name( NULL, number, CODE_ROOM) );
				}
			}
		}
		redit_disp_flag_menu(d);
		return;

	  case REDIT_SECTOR:
		number = atoi( arg );
		if ( number < 0 || number >= MAX_SECTOR )
		{
			send_to_char( d->character, "Invalid choice!" );
			redit_disp_sector_menu(d);
			return;
		}
		else
			room->sector = number;

		olc_log( d, "Changed sector to %s", code_name(NULL, number, CODE_SECTOR) );
		break;

	  case REDIT_TUNNEL:
		number = atoi( arg );
		room->tunnel = URANGE( 0, number, 1000 );
		olc_log( d, "Changed tunnel amount to %d", room->tunnel );
		break;

	  case REDIT_TELEDELAY:
		number = atoi( arg );
		room->tele_delay = number;
		olc_log( d, "Changed teleportation delay to %d", room->tele_delay );
		break;

	  case REDIT_TELEVNUM:
		number = atoi( arg );
		room->tele_vnum = URANGE( 1, number, MAX_VNUM-1 );
		olc_log( d, "Changed teleportation vnum to %d", room->tele_vnum );
		break;

	  case REDIT_EXIT_MENU:
		switch ( toupper(arg[0]) )
		{
		  default:
			if ( is_number(arg) )
			{
				number = atoi( arg );
				pexit = get_exit_num( room, number );
				d->character->spare_ptr = pexit;
				redit_disp_exit_edit(d);
				return;
			}
			redit_disp_exit_menu( d );
			return;
		  case 'A':
			OLC_MODE(d) = REDIT_EXIT_ADD;
			redit_disp_exit_dirs( d );
			return;
		  case 'R':
			OLC_MODE(d) = REDIT_EXIT_DELETE;
			send_to_char( d->character, "Delete which exit? " );
			return;
		  case 'Q':
			d->character->spare_ptr = NULL;
			break;
		}
		break;

	  case REDIT_EXIT_EDIT:
		switch ( toupper(arg[0]) )
		{
		  case 'Q':
			d->character->spare_ptr = NULL;
			redit_disp_exit_menu(d);
			return;
		  case '1':
			/* OLC_MODE(d) = REDIT_EXIT_DIR;
			redit_disp_exit_dirs(d); */
			send_to_char( d->character, "This option can only be changed by remaking the exit.\r\n" );
			break;
		  case '2':
			OLC_MODE(d) = REDIT_EXIT_VNUM;
			send_to_char( d->character, "Which room does this exit go to? " );
			return;
		  case '3':
			OLC_MODE(d) = REDIT_EXIT_KEY;
			send_to_char( d->character, "What is the vnum of the key to this exit? " );
			return;
		  case '4':
			OLC_MODE(d) = REDIT_EXIT_KEYWORD;
			send_to_char( d->character, "What is the keyword to this exit? " );
			return;
		  case '5':
			OLC_MODE(d) = REDIT_EXIT_FLAGS;
			redit_disp_exit_flag_menu(d);
			return;
		  case '6':
			OLC_MODE(d) = REDIT_EXIT_DESC;
			send_to_char( d->character, "Description:\r\n] " );
			return;
		}
		redit_disp_exit_edit(d);
		return;

	  case REDIT_EXIT_DESC:
		if ( !VALID_STR(arg) )
		{
			DISPOSE( pexit->description );
			pexit->description = str_dup( "" );
		}
		else
		{
			sprintf( buf, "%s\r\n", arg );
			DISPOSE( pexit->description );
			pexit->description = str_dup( buf );
		}
		olc_log( d, "Changed %s description to %s", code_name( NULL, pexit->vdir, CODE_DIR), arg  ?  arg  :  "none" );
		redit_disp_exit_edit(d);
		return;

	  case REDIT_EXIT_ADD:
		if ( is_number( arg ) )
		{
			number = atoi( arg );
			if ( number < 0 || number >= MAX_DIR )
			{
				send_to_char( d->character, "Invalid direction, try again: " );
				return;
			}
			d->character->tempnum = number;
		}
		else
		{
			number = get_dir(arg);
			pexit = get_exit( room, number );
			if ( pexit )
			{
				send_to_char( d->character, "An exit in that direction already exists.\r\n" );
				redit_disp_exit_menu(d);
				return;
			}
			d->character->tempnum = number;
		}
		OLC_MODE(d) = REDIT_EXIT_ADD_VNUM;
		send_to_char( d->character, "Which room does this exit go to? " );
		return;

	  case REDIT_EXIT_ADD_VNUM:
		number = atoi( arg );
		if ( (tmp = get_room_index(NULL, number)) == NULL )
		{
			send_to_char( d->character, "Non-existant room.\r\n" );
			OLC_MODE(d) = REDIT_EXIT_MENU;
			redit_disp_exit_menu(d);
			return;
		}
		pexit = make_exit( room, tmp, d->character->tempnum );
		DISPOSE( pexit->keyword );
		DISPOSE( pexit->description );
		pexit->keyword		= str_dup( "" );
		pexit->description	= str_dup( "" );
		pexit->key			= -1;
		pexit->flags	= 0;
		act( AT_ADMIN, "$n reveals a hidden passage!", d->character, NULL, NULL, TO_ROOM );
		d->character->spare_ptr = pexit;

		olc_log( d, "Added %s exit to %d", code_name( NULL, pexit->vdir, CODE_DIR), pexit->vnum );

		OLC_MODE(d) = REDIT_EXIT_EDIT;
		redit_disp_exit_edit(d);
		return;

	  case REDIT_EXIT_DELETE:
		if ( !is_number( arg ) )
		{
			send_to_char( d->character, "Exit must be specified in a number.\r\n" );
			redit_disp_exit_menu(d);
		}
		number = atoi( arg );
		pexit = get_exit_num( room, number );

		if ( !pexit )
		{
			send_to_char( d->character, "That exit does not exist.\r\n" );
			redit_disp_exit_menu(d);
		}
		olc_log( d, "Removed %s exit", code_name( NULL, pexit->vdir, CODE_DIR) );
		extract_exit( room, pexit );
		redit_disp_exit_menu( d );
		return;

	  case REDIT_EXIT_VNUM:
		number = atoi( arg );
		if ( number < 1 || number >= MAX_VNUM )
		{
			send_to_char( d->character, "Invalid room number, try again : " );
			return;
		}

		if ( get_room_index(NULL, number) == NULL )
		{
			send_to_char( d->character, "That room does not exist, try again: " );
			return;
		}
		pexit->vnum = number;
		olc_log( d, "%s exit vnum changed to %d", code_name( NULL, pexit->vdir, CODE_DIR), pexit->vnum );
		redit_disp_exit_menu( d );
		return;

	  case REDIT_EXIT_KEYWORD:
		DISPOSE( pexit->keyword );
		pexit->keyword = str_dup( arg );
		olc_log( d, "Changed %s keyword to %s", code_name( NULL, pexit->vdir, CODE_DIR), pexit->keyword );
		redit_disp_exit_edit( d );
		return;

	  case REDIT_EXIT_KEY:
		number = atoi( arg );
		if ( number < 1 || number >= MAX_VNUM )
			send_to_char( d->character, "Invalid vnum, try again: " );
		else
		{
			pexit->key = number;
			redit_disp_exit_edit( d );
		}
		olc_log( d, "%s key vnum is now %d", code_name( NULL, pexit->vdir, CODE_DIR), pexit->key );
		return;

	  case REDIT_EXIT_FLAGS:
		number = atoi( arg );
		if ( number == 0 )
		{
			redit_disp_exit_edit( d );
			return;
		}

		if ( number < 0 || number >= MAX_EXIT
		  || ((number-1) == EXIT_RES1)
		  || ((number-1) == EXIT_RES2)
		  || ((number-1) == EXIT_PORTAL) )
		{
			send_to_char( d->character, "That's not a valid choice!\r\n" );
			redit_disp_exit_flag_menu( d );
		}
		number -= 1;
		TOGGLE_BIT( pexit->flags, number );
		olc_log( d, "%s %s to %s exit",
			HAS_BIT(pexit->flags, number)  ?  "Added"  :  "Removed",
			code_name(NULL, number, CODE_EXIT),
			code_name(NULL, pexit->vdir, CODE_DIR) );
		redit_disp_exit_flag_menu( d );
		return;

	  case REDIT_EXTRADESC_DELETE:
		ed = redit_find_extradesc( room, atoi(arg) );
		if ( !ed )
		{
			send_to_char( d->character, "Not found, try again: " );
			return;
		}
		olc_log( d, "Deleted exdesc %s", ed->keyword );
		UNLINK( ed, room->first_extradescr, room->last_extradescr, next, prev );
		DISPOSE( ed->keyword );
		DISPOSE( ed->description );
		DISPOSE( ed );
		top_ed--;
		redit_disp_extradesc_menu(d);
		return;

	  case REDIT_EXTRADESC_CHOICE:
		switch ( toupper( arg[0] ) )
		{
		  case 'Q':
			if ( !ed->keyword || !ed->description )
			{
				send_to_char( d->character, "No keyword and/or description, junking..." );
				UNLINK( ed, room->first_extradescr, room->last_extradescr, next, prev );
				DISPOSE( ed->keyword );
				DISPOSE( ed->keyword );
				DISPOSE( ed );
				top_ed--;
			}
			d->character->spare_ptr = NULL;
			redit_disp_extradesc_menu(d);
			return;
		  case '1':
			OLC_MODE(d) = REDIT_EXTRADESC_KEY;
			send_to_char( d->character, "Keywords, seperated by spaces: " );
			return;
		  case '2':
			OLC_MODE(d) = REDIT_EXTRADESC_DESCRIPTION;
			d->character->substate = SUB_ROOM_EXTRA;
			d->character->last_cmd = do_redit_reset;
			send_to_char( d->character, "Enter new extradesc description: \r\n" );
			start_editing( d->character, ed->description );
			return;
		}
		break;

	  case REDIT_EXTRADESC_KEY:
/*		if ( SetRExtra( room, arg ) )
		{
			send_to_char( d->character, "A extradesc with that keyword already exists.\r\n" );
			redit_disp_extradesc_menu(d);
			return;
		} */
		olc_log( d, "Changed exkey %s to %s", ed->keyword, arg );
		DISPOSE( ed->keyword );
		ed->keyword = str_dup( arg );
		oedit_disp_extra_choice(d);
		OLC_MODE(d) = REDIT_EXTRADESC_CHOICE;
		return;

	  case REDIT_EXTRADESC_MENU:
		switch ( toupper( arg[0] ) )
		{
		  case 'Q':
			break;
		  case 'A':
			CREATE( ed, EXTRA_DESCR_DATA, 1 );
			LINK( ed, room->first_extradescr, room->last_extradescr, next, prev );
			ed->keyword = str_dup( "" );
			ed->description = str_dup( "" );
			top_ed++;
			d->character->spare_ptr = ed;
			olc_log( d, "Added new exdesc" );
			oedit_disp_extra_choice(d);
			OLC_MODE(d) = REDIT_EXTRADESC_CHOICE;
			return;
		  case 'R':
			OLC_MODE(d) = REDIT_EXTRADESC_DELETE;
			send_to_char( d->character, "Delete which extra description? " );
			return;
		  default:
			if ( is_number(arg) )
			{
				ed = redit_find_extradesc( room, atoi(arg) );
				if ( !ed )
				{
					send_to_char( d->character, "Not found, try again: " );
					return;
				}
				d->character->spare_ptr = ed;
				oedit_disp_extra_choice(d);
				OLC_MODE(d) = REDIT_EXTRADESC_CHOICE;
			}
			else
				redit_disp_extradesc_menu(d);

			return;
		}
		break;

	  default:
		/* we should never get here */
		send_log( NULL, LOG_OLC, "redit_parse: reached default case in parse_redit" );
		break;
	} /* chiude lo switch */
	/* Log the changes, so we can keep track of those sneaky bastards */
	/* Don't log on the flags cause it does that above */
/*	if ( OLC_MODE(d) != REDIT_FLAGS )
		olc_log( d, arg );
*/
	/*. If we get this far, something has be changed .*/
	OLC_CHANGE(d) = TRUE;
	redit_disp_menu(d);
}
Ejemplo n.º 14
0
//-----------------------------------------------------
//
//-----------------------------------------------------
bool initLDAP(IPropertyTree * ldapProps)
{
    StringAttr serverType( ldapProps->queryProp("@serverType") );
    if (!serverType.length())
    {
        fprintf(stderr, "\nERROR: serverType not set in LDAPServer component");
        return false;
    }

    StringBuffer hpccUser;
    StringBuffer hpccPwd;
    ldapProps->getProp("@systemUser", hpccUser);
    ldapProps->getProp("@systemPassword", hpccPwd);
    if (0==hpccUser.length() || 0==hpccPwd.length())
    {
        fprintf(stderr, "\nERROR: HPCC systemUser credentials not found in configuration");
        return false;
    }

    StringBuffer ldapAddress;
    ldapProps->getProp("@ldapAddress", ldapAddress);

    //Get LDAP admin creds from user
    char buff[100];
    fprintf(stdout, "\nEnter the '%s' LDAP Admin User name on '%s'...",serverType.get(),ldapAddress.str());
    do
    {
        char * line = fgets(buff, sizeof(buff), stdin);
        if (!line)
            return false;
    }
    while (buff[0] == (char)'\n');

    if (buff[strlen(buff)-1] == '\n')
        buff[strlen(buff)-1] = (char)NULL;
    StringAttr ldapUser(buff);

    fprintf(stdout, "Enter the LDAP Admin user '%s' password...",ldapUser.get());
    char * line = fgets(buff, sizeof(buff), stdin);
    if (!line)
        return false;

    if (buff[strlen(buff)-1] == '\n')
        buff[strlen(buff)-1] = (char)NULL;
    StringAttr ldapPwd(buff);
    if (0==ldapUser.length() || 0==ldapPwd.length())
    {
        fprintf(stderr, "\nERROR: Invalid LDAP Admin account credentials entered");
        return false;
    }

    fprintf(stdout, "\nReady to initialize HPCC LDAP Environment, using the following settings");
    fprintf(stdout, "\n\tLDAP Server     : %s", ldapAddress.str());
    fprintf(stdout, "\n\tLDAP Type       : %s", serverType.get());
    fprintf(stdout, "\n\tHPCC Admin User : %s", hpccUser.str());
    fprintf(stdout, "\nProceed?  y/n ");
    for (;;)
    {
        int c = getchar();
        if (c == 'y' || c == 'Y')
            break;
        else if (c == 'n' || c == 'N')
            return true;
    }

    if (stricmp(serverType.get(),"ActiveDirectory"))
        ldapProps->setProp("@systemBasedn", "");

    //Replace system user with LDAP Admin credentials
    ldapProps->setProp("@systemUser", ldapUser);
    ldapProps->setProp("@systemCommonName", ldapUser);
    StringBuffer sb;
    encrypt(sb,ldapPwd);
    ldapProps->setProp("@systemPassword", sb.str());

    //Create security manager. This creates the required OUs
    Owned<ISecManager> secMgr;
    try
    {
        secMgr.setown(newLdapSecManager("initldap", *LINK(ldapProps)));
    }
    catch(IException *e)
    {
        StringBuffer buff;
        e->errorMessage(buff);
        e->Release();
        fprintf(stderr, "\nERROR: Unable to create security manager : %s", buff.str());
        return false;
    }

    //Create HPCC Admin user
    Owned<ISecUser> user = secMgr->createUser(hpccUser.str());
    StringBuffer pwd;
    decrypt(pwd, hpccPwd.str());
    user->credentials().setPassword(pwd.str());
    try { secMgr->addUser(*user.get()); }
    catch(...) {}//user may already exist, so just move on

    //Add HPCC admin user to Administrators group
    CLdapSecManager* ldapSecMgr = dynamic_cast<CLdapSecManager*>(secMgr.get());
    if (!ldapSecMgr)
    {
        fprintf(stderr, "\nERROR: Unable to access CLdapSecManager object");
        return false;
    }
    StringAttr adminGroup;
    bool isActiveDir = true;
    if (0 == stricmp(serverType.get(),"ActiveDirectory"))
        adminGroup.set("Administrators");
    else
        adminGroup.set("Directory Administrators");
    try { ldapSecMgr->changeUserGroup("add", hpccUser.str(), adminGroup); }
    catch(...) {}//user may already be in group so just move on

    fprintf(stdout, "\n\nLDAP Initialization successful\n");
    return true;
}
Ejemplo n.º 15
0
void LogicalGraphCreator::createGraphActivity(IHqlExpression * expr)
{
    LogicalGraphInfo * extra = queryExtra(expr);
    if (extra->globalId && !inSubQuery())
    {
        extra->id = extra->globalId;
        return;
    }

    //First generate children...
    //MORE: may want to do inputs first and dependents afterwards.
    IAtom * dependencyKind = dependencyAtom;
    unsigned first = getFirstActivityArgument(expr);
    unsigned last = first + getNumActivityArguments(expr);
    node_operator op = expr->getOperator();
    HqlExprArray inputs, dependents;
    bool defaultInputs = true;
    switch (op)
    {
    case no_setresult:
    case no_map:
        last = first;
        dependencyKind = NULL;
        break;
    case no_select:
        if (!isNewSelector(expr))
        {
            last = first;
        }
        break;
    case no_addfiles:
        expandUnnamedFunnel(inputs, expr->queryBody());
        defaultInputs = false;
        break;
    case no_colon:
        {
            if (!isWorkflowExpanded(expr))
                defaultInputs = false;

            gatherWorkflowActivities(expr, dependents);
            inputs.append(*LINK(expr->queryChild(0)));
            defaultInputs = false;
            break;
        }
    case no_forcelocal:
    case no_forcenolocal:
    case no_allnodes:
    case no_thisnode:
        {
            IHqlExpression * child = expr->queryChild(0);
            createSubGraphActivity(child);
            addDependent(dependents, child);
            defaultInputs = false;
            break;
        }
    }
    if (defaultInputs)
    {
        ForEachChild(i, expr)
        {
            IHqlExpression * cur = expr->queryChild(i);
            if ((i >= first && i < last) && !cur->isAttribute())
                inputs.append(*LINK(cur));
            else if (includeChildInDependents(expr, i))
                gatherGraphActivities(cur, dependents);
        }
    }
Ejemplo n.º 16
0
void do_plantbug( CHAR_DATA * ch, char *argument )
{
   CHAR_DATA *victim;
   BUG_DATA *pbug;
   BUG_DATA *cbug;
   OBJ_DATA *obj;
   bool checkbug = FALSE;
   int schance;

   if( IS_NPC( ch ) )
      return;

   if( ( victim = get_char_room( ch, argument ) ) == NULL )
   {
      send_to_char( "They aren't here.\n\r", ch );
      return;
   }

   if( IS_NPC( victim ) )
   {
      send_to_char( "You can't bug NPC's!\n\r", ch );
      return;
   }

   if( IS_IMMORTAL( victim ) )
   {
      send_to_char( "Don't try to plant bugs on immortals.\n\r", ch );
      return;
   }

   if( in_arena( ch ) )
   {
      send_to_char( "You're here to FIGHT, not spy.\n\r", ch );
      return;
   }

   if( ch == victim )
   {
      send_to_char( "You can't bug yourself!\n\r", ch );
      return;
   }

   for( obj = ch->last_carrying; obj; obj = obj->prev_content )
      if( obj->item_type == ITEM_BUG )
         checkbug = TRUE;

   if( checkbug == FALSE )
   {
      send_to_char( "You don't have any bugs to plant.\n\r", ch );
      return;
   }

   for( cbug = victim->first_bug; cbug; cbug = cbug->next_in_bug )
      if( !str_cmp( ch->name, cbug->name ) )
      {
         send_to_char( "You have already planted a bug on this person.\n\r", ch );
         return;
      }

   schance = number_percent(  ) - UMIN( 0, ( get_curr_lck( ch ) - 14 ) ) + UMIN( 0, ( get_curr_lck( victim ) - 13 ) );

   if( schance < ch->pcdata->learned[gsn_plantbug] )
   {
      act( AT_WHITE, "You carefully reach into $N's pocket and place a bug.", ch, NULL, victim, TO_CHAR );
      CREATE( pbug, BUG_DATA, 1 );
      pbug->name = ch->name;
      LINK( pbug, victim->first_bug, victim->last_bug, next_in_bug, prev_in_bug );
      learn_from_success( ch, gsn_plantbug );

      for( obj = ch->last_carrying; obj; obj = obj->prev_content )
      {
         if( obj->item_type == ITEM_BUG )
         {
            separate_obj( obj );
            obj_from_char( obj );
            extract_obj( obj );
            break;
         }
      }
      return;
   }
   else
   {
      send_to_char( "&RYou try to find a pocket to plant the bug in but fail!\n\r", ch );
      learn_from_failure( ch, gsn_plantbug );
      if( number_bits( 0 ) == 0 )
         ch_printf( victim, "You feel a slight brush against your pocket to find %s's hand there.\n\r", PERS( ch, victim ) );
      return;
   }
}
Ejemplo n.º 17
0
IHqlExpression * buildDiskOutputEcl(const char * logicalName, IHqlExpression * record)
{
    OwnedHqlExpr dataset = createNewDataset(createConstant(logicalName), LINK(record), createValue(no_thor), NULL, NULL, NULL);
    return addOutput(dataset);
}
Ejemplo n.º 18
0
//Contract System by Tawnos.
void do_contract( CHAR_DATA * ch, char *argument )
{
   CHAR_DATA *victim;
   CHAR_DATA *target;
   char arg1[MAX_INPUT_LENGTH];
   char arg2[MAX_INPUT_LENGTH];
   char arg3[MAX_INPUT_LENGTH];
   long amount = 0;
   CONTRACT_DATA *ccontract;
   CONTRACT_DATA *contract;

   argument = one_argument( argument, arg1 );
   argument = one_argument( argument, arg2 );
   argument = one_argument( argument, arg3 );

   if( IS_NPC( ch ) )
      return;

   if( arg1[0] == '\0' || arg2[0] == '\0' || arg3[0] == '\0' )
   {
      send_to_char( "&RSyntax: contract <person> <target> <amount>\n\r", ch );
      return;
   }

   if( ( victim = get_char_room( ch, arg1 ) ) == NULL )
   {
      send_to_char( "They aren't here.\n\r", ch );
      return;
   }

   if( ( target = get_char_world_ooc( ch, arg2 ) ) == NULL )
   {
      send_to_char( "Your target is currently not online.\n\r", ch );
      return;
   }

   if( ch == victim )
   {
      send_to_char( "You can't contract yourself!\n\r", ch );
      return;
   }

   if( IS_NPC( victim ) || IS_NPC( target ) )
   {
      send_to_char( "You can't contract NPC's.\n\r", ch );
      return;
   }

   if( ch == target )
   {
      send_to_char( "You can't contract against yourself!\n\r", ch );
      return;
   }

   if( target == victim )
   {
      send_to_char( "You can't contract them to kill themself!\n\r", ch );
      return;
   }

   amount = atoi( arg3 );

   if( amount < 5000 )
   {
      send_to_char( "&RYour contract must be for at least 5000 credits.\n\r", ch );
      return;
   }

   if( ch->gold < amount )
   {
      send_to_char( "&RYou don't have enough credits!\n\r", ch );
      return;
   }

   for( ccontract = victim->first_contract; ccontract; ccontract = ccontract->next_in_contract )
   {
      if( !str_cmp( ccontract->target, target->name ) )
      {
         ch->gold -= amount;
         ccontract->amount += amount;
         ch_printf( ch, "&GYou have contracted %s to kill %s for an amount of %d credits.\n\r", PERS( victim, ch ),
                    target->name, amount );
         ch_printf( victim, "&G%s has contracted you to kill %s, raising your contract reward by %d credits.\n\r",
                    PERS( ch, victim ), target->name, amount );
         return;
      }
   }

   CREATE( contract, CONTRACT_DATA, 1 );
   contract->target = target->name;
   contract->amount = amount;
   LINK( contract, victim->first_contract, victim->last_contract, next_in_contract, prev_in_contract );

   ch->gold -= amount;
   ch_printf( ch, "&GYou have contracted %s to kill %s for an amount of %d credits.\n\r", PERS( victim, ch ), target->name,
              amount );
   ch_printf( victim, "&G%s has contracted you to kill %s for an amount of %d credits.\n\r", PERS( ch, victim ),
              target->name, amount );

}
Ejemplo n.º 19
0
IHqlExpression * addOutput(IHqlExpression * dataset)
{
    return createValue(no_output, makeVoidType(), LINK(dataset));
}
Ejemplo n.º 20
0
Archivo: bits.c Proyecto: jmdjr/sdf-mud
/* Load the abits and qbits */
void load_bits( void )
{
   char buf[MAX_STRING_LENGTH];
   char *word;
   bool fMatch;
   int mode = 0;
   BIT_DATA *bit = NULL;
   FILE *fp;

   sprintf( buf, "%sabit.lst", SYSTEM_DIR );
   if( ( fp = fopen( buf, "r" ) ) == NULL )
   {
      perror( buf );
      return;
   }

   for( ;; )
   {
      word = feof( fp ) ? "End" : fread_word( fp );
      fMatch = FALSE;

      switch ( UPPER( word[0] ) )
      {
         case '*':
            fMatch = TRUE;
            fread_to_eol( fp );
            break;

         case '#':
            if( !str_cmp( word, "#END" ) )
            {
               fclose( fp );
               if( mode == 0 )
               {
                  mode = 1;   /* We have two files to read, I reused the same code to read both */
                  sprintf( buf, "%sqbit.lst", SYSTEM_DIR );
                  if( ( fp = fopen( buf, "r" ) ) == NULL )
                  {
                     perror( buf );
                     return;
                  }
               }
               else
                  return;
               fMatch = TRUE;
            }
            break;

         case 'D':
            if( !str_cmp( word, "Desc" ) )
            {
               fMatch = TRUE;
               strcpy( bit->desc, fread_string( fp ) );
            }
            break;

         case 'E':
            if( !strcmp( word, "End" ) )
            {
               if( mode == 0 )
                  LINK( bit, first_abit, last_abit, next, prev );
               else
                  LINK( bit, first_qbit, last_qbit, next, prev );
               bit = NULL;
               fMatch = TRUE;
            }
            break;

         case 'N':
            if( !strcmp( word, "Number" ) )
            {
               CREATE( bit, BIT_DATA, 1 );
               bit->number = fread_number( fp );
               fMatch = TRUE;
            }
            break;
      }

      if( !fMatch )
      {
         sprintf( buf, "load_bits: no match: %s", word );
         bug( buf, 0 );
      }
   }
}
Ejemplo n.º 21
0
static IHqlExpression * optimizedReplaceSelector(IHqlExpression * expr, IHqlExpression * oldDataset, IHqlExpression * newDataset)
{
    switch (expr->getOperator())
    {
    case no_constant:
    case no_attr:
        return LINK(expr);
    case no_select:
        {
            IHqlExpression * lhs = expr->queryChild(0);
            IHqlExpression * field = expr->queryChild(1);
            OwnedHqlExpr newLhs;
            if (expr->hasAttribute(newAtom))
            {
                newLhs.setown(optimizedReplaceSelector(lhs, oldDataset, newDataset));
            }
            else
            {
                if (lhs == oldDataset)
                {
                    if (newDataset->getOperator() == no_newrow)
                        return createNewSelectExpr(LINK(newDataset->queryChild(0)), LINK(field));

                    if (newDataset->getOperator() == no_activerow)
                        newDataset = newDataset->queryChild(0);

                    return createSelectExpr(LINK(newDataset->queryNormalizedSelector()), LINK(field));
                }
                else
                    newLhs.setown(optimizedReplaceSelector(lhs, oldDataset, newDataset));
            }

            if (newLhs)
                return replaceChild(expr, 0, newLhs);
            return NULL;
        }
    case no_implicitcast:
    case no_cast:
        {
            IHqlExpression * newUncast = optimizedReplaceSelector(expr->queryChild(0), oldDataset, newDataset);
            if (!newUncast)
                return NULL;
            OwnedHqlExpr ret = createValue(expr->getOperator(), expr->getType(), newUncast);
            return expr->cloneAllAnnotations(ret);
        }
    case no_hash:
    case no_hash32:
    case no_hash64:
    case no_sortlist:
    case no_concat:
    case no_trim:
    case no_negate:
    case no_eq:
    case no_ne:
    case no_sizeof:
    case no_attr_expr:
    case no_add:
        {
            HqlExprArray args;
            ForEachChild(i, expr)
            {
                IHqlExpression * cur = expr->queryChild(i);
                IHqlExpression * newCur = optimizedReplaceSelector(cur, oldDataset, newDataset);
                if (!newCur)
                    return NULL;
                args.append(*newCur);
            }
            return expr->clone(args);
        }
    }
Ejemplo n.º 22
0
 virtual CActivityBase *factory(ThorActivityKind kind)
 {
     CActivityBase *ret = NULL;
     switch (kind)
     {
         case TAKdiskread:
             ret = createDiskReadSlave(this);
             break;
         case TAKdisknormalize:
             ret = createDiskNormalizeSlave(this);
             break;
         case TAKdiskaggregate:
             ret = createDiskAggregateSlave(this);
             break;
         case TAKdiskcount:
             ret = createDiskCountSlave(this);
             break;
         case TAKdiskgroupaggregate:
             ret = createDiskGroupAggregateSlave(this);
             break;  
         case TAKindexread:
             ret = createIndexReadSlave(this);
             break;
         case TAKindexcount:
             ret = createIndexCountSlave(this);
             break;
         case TAKindexnormalize:
             ret = createIndexNormalizeSlave(this);
             break;
         case TAKindexaggregate:
             ret = createIndexAggregateSlave(this);
             break;
         case TAKindexgroupaggregate:
         case TAKindexgroupexists:
         case TAKindexgroupcount:
             ret = createIndexGroupAggregateSlave(this);
             break;
         case TAKchildaggregate:
             ret = createChildAggregateSlave(this);
             break;
         case TAKchildgroupaggregate:
             ret = createChildGroupAggregateSlave(this);
             break;
         case TAKchildthroughnormalize:
             ret = createChildThroughNormalizeSlave(this);
             break;
         case TAKchildnormalize:
             ret = createChildNormalizeSlave(this);
             break;
         case TAKspill:
             ret = createSpillSlave(this);
             break;
         case TAKdiskwrite:
             ret = createDiskWriteSlave(this);
             break;
         case TAKsort:
             if (queryGrouped())
                 ret = createGroupSortSlave(this);
             else if (queryLocal())
                 ret = createLocalSortSlave(this);
             else
                 ret = createMSortSlave(this);
             break;
         case TAKsorted:
             ret = createSortedSlave(this);
             break;
         case TAKdedup:
             if (queryGrouped())
                 ret = createGroupDedupSlave(this);
             else if (queryLocal())
                 ret = createLocalDedupSlave(this);
             else
                 ret = createDedupSlave(this);
             break;
         case TAKrollupgroup:
             ret = createRollupGroupSlave(this);
             break;
         case TAKrollup:
             if (queryGrouped())
                 ret = createGroupRollupSlave(this);
             else if (queryLocal())
                 ret = createLocalRollupSlave(this);
             else
                 ret = createRollupSlave(this);
             break;
         case TAKprocess:
             if (queryGrouped())
                 ret = createGroupProcessSlave(this);
             else if (queryLocal())
                 ret = createLocalProcessSlave(this);
             else
                 ret = createProcessSlave(this);
             break;
         case TAKfilter:
             ret = createFilterSlave(this);
             break;
         case TAKfilterproject:
             ret = createFilterProjectSlave(this);
             break;
         case TAKfiltergroup:
             ret = createFilterGroupSlave(this);
             break;
         case TAKsplit:
             ret = createNSplitterSlave(this);
             break;
         case TAKproject:
             ret = createProjectSlave(this);
             break;
         case TAKprefetchproject:
             ret = createPrefetchProjectSlave(this);
             break;
         case TAKprefetchcountproject:
             break;
         case TAKiterate:
             if (queryGrouped())
                 ret = createGroupIterateSlave(this);
             else if (queryLocal())
                 ret = createLocalIterateSlave(this);
             else
                 ret = createIterateSlave(this);
             break;
         case TAKaggregate:
         case TAKexistsaggregate:
         case TAKcountaggregate:
             if (queryLocalOrGrouped())
                 ret = createGroupAggregateSlave(this);
             else
                 ret = createAggregateSlave(this);
             break;
         case TAKhashaggregate:
             ret = createHashAggregateSlave(this);
             break;
         case TAKfirstn:
             ret = createFirstNSlave(this);
             break;
         case TAKsample:
             ret = createSampleSlave(this);
             break;
         case TAKdegroup:
             ret = createDegroupSlave(this);
             break;
         case TAKjoin:
             if (queryLocalOrGrouped())
                 ret = createLocalJoinSlave(this);
             else
                 ret = createJoinSlave(this);
             break;
         case TAKhashjoin:
         case TAKhashdenormalize:
         case TAKhashdenormalizegroup:
             ret = createHashJoinSlave(this);
             break;
         case TAKlookupjoin:
             ret = createLookupJoinSlave(this);
             break;
         case TAKalljoin:
             ret = createAllJoinSlave(this);
             break;
         case TAKselfjoin:
             if (queryLocalOrGrouped())
                 ret = createLocalSelfJoinSlave(this);
             else
                 ret = createSelfJoinSlave(this);
             break;
         case TAKselfjoinlight:
             ret = createLightweightSelfJoinSlave(this);
             break;
         case TAKkeyedjoin:
         case TAKkeyeddenormalize:
         case TAKkeyeddenormalizegroup:
             ret = createKeyedJoinSlave(this);
             break;
         case TAKgroup:
             if (queryLocalOrGrouped())
                 ret = createLocalGroupSlave(this);
             else
                 ret = createGroupSlave(this);
             break;
         case TAKworkunitwrite:
             ret = createWorkUnitWriteSlave(this);
             break;
         case TAKfunnel:
             ret = createFunnelSlave(this);
             break;
         case TAKcombine:
             ret = createCombineSlave(this);
             break;
         case TAKregroup:
             ret = createRegroupSlave(this);
             break;
         case TAKapply:
             ret = createApplySlave(this);
             break;
         case TAKtemptable:
         case TAKtemprow:
             ret = createTempTableSlave(this);
             break;
         case TAKkeyeddistribute:
             ret = createIndexDistributeSlave(this);
             break;
         case TAKhashdistribute:
             ret = createHashDistributeSlave(this);
             break;
         case TAKhashdistributemerge:
             ret = createHashDistributeMergeSlave(this);
             break;
         case TAKhashdedup:
             if (queryLocalOrGrouped())
                 ret = createHashLocalDedupSlave(this);
             else
                 ret = createHashDedupSlave(this);
             break;
         case TAKnormalize:
             ret = createNormalizeSlave(this);
             break;
         case TAKnormalizechild:
             ret = createNormalizeChildSlave(this);
             break;
         case TAKnormalizelinkedchild:
             ret = createNormalizeLinkedChildSlave(this);
             break;
         case TAKremoteresult:
             ret = createResultSlave(this);
             break;
         case TAKpull:
             ret = createPullSlave(this);
             break;
         case TAKdenormalize:
         case TAKdenormalizegroup:
             if (queryLocalOrGrouped())
                 ret = createLocalDenormalizeSlave(this);
             else
                 ret = createDenormalizeSlave(this);
             break;
         case TAKnwayinput:
             ret = createNWayInputSlave(this);
             break;
         case TAKnwayselect:
             ret = createNWaySelectSlave(this);
             break;
         case TAKnwaymerge:
             ret = createNWayMergeActivity(this);
             break;
         case TAKnwaymergejoin:
         case TAKnwayjoin:
             ret = createNWayMergeJoinActivity(this);
             break;
         case TAKalldenormalize:
         case TAKalldenormalizegroup:
             ret = createAllDenormalizeSlave(this);
             break;
         case TAKlookupdenormalize:
         case TAKlookupdenormalizegroup:
             ret = createLookupDenormalizeSlave(this);
             break;
         case TAKchilddataset:
             UNIMPLEMENTED;
         case TAKchilditerator:
             ret = createChildIteratorSlave(this);
             break;
         case TAKrawiterator:
             ret = createRawIteratorSlave(this);
             break;
         case TAKlinkedrawiterator:
             ret = createLinkedRawIteratorSlave(this);
             break;
         case TAKselectn:
             if (queryLocalOrGrouped())
                 ret = createLocalSelectNthSlave(this);
             else
                 ret = createSelectNthSlave(this);
             break;
         case TAKenth:
             if (queryLocalOrGrouped())
                 ret = createLocalEnthSlave(this);
             else
                 ret = createEnthSlave(this);
             break;
         case TAKnull:
             ret = createNullSlave(this);
             break;
         case TAKdistribution:
             ret = createDistributionSlave(this);
             break;
         case TAKcountproject:
             if (queryLocalOrGrouped())
                 ret = createLocalCountProjectSlave(this);
             else
                 ret = createCountProjectSlave(this);
             break;
         case TAKchoosesets:
             if (queryLocalOrGrouped())
                 ret = createLocalChooseSetsSlave(this);
             else
                 ret = createChooseSetsSlave(this);
             break;
         case TAKpiperead:
             ret = createPipeReadSlave(this);
             break;
         case TAKpipewrite:
             ret = createPipeWriteSlave(this);
             break;
         case TAKcsvread:
             ret = createCsvReadSlave(this);
             break;
         case TAKcsvwrite:
             ret = createCsvWriteSlave(this);
             break;
         case TAKpipethrough:
             ret = createPipeThroughSlave(this);
             break;
         case TAKindexwrite:
             ret = createIndexWriteSlave(this);
             break;
         case TAKchoosesetsenth:
             ret = createChooseSetsEnthSlave(this);
             break;
         case TAKchoosesetslast:
             ret = createChooseSetsLastSlave(this);
             break;
         case TAKfetch:
             ret = createFetchSlave(this);
             break;
         case TAKcsvfetch:
             ret = createCsvFetchSlave(this);
             break;
         case TAKxmlfetch:
             ret = createXmlFetchSlave(this);
             break;
         case TAKthroughaggregate:
             ret = createThroughAggregateSlave(this);
             break;
         case TAKcase:
         case TAKif:
             throwUnexpected();
             break;
         case TAKwhen_dataset:
             ret = createWhenSlave(this);
             break;
         case TAKworkunitread:
         {
             if (wuidread2diskread)
             {
                 Owned<IHThorDiskReadArg> diskReadHelper = createWorkUnitReadArg(wuidreadFilename, (IHThorWorkunitReadArg *)LINK(baseHelper));
                 Owned<CActivityBase> retAct = createDiskReadSlave(this, diskReadHelper);
                 return retAct.getClear();
             }
             else
                 ret = createWuidReadSlave(this);
             break;
         }
         case TAKparse:
             ret = createParseSlave(this);
             break;
         case TAKsideeffect:
             ret = createNullActionSlave(this);
             break;
         case TAKsimpleaction:
             ret = createNullSlave(this);
             break;
         case TAKtopn:
             if (queryGrouped())
                 ret = createGroupedTopNSlave(this);
             else if (queryLocal())
                 ret = createLocalTopNSlave(this);
             else
                 ret = createGlobalTopNSlave(this);
             break;
         case TAKxmlparse:
             ret = createXmlParseSlave(this);
             break;
         case TAKxmlread:
             ret = createXmlReadSlave(this);
             break;
         case TAKxmlwrite:
             ret = createXmlWriteSlave(this);
             break;
         case TAKmerge:
             if (queryLocalOrGrouped())
                 ret = createLocalMergeSlave(this);
             else
                 ret = createGlobalMergeSlave(this);
             break;
         case TAKsoap_rowdataset:
             ret = createSoapRowCallSlave(this);
             break;
         case TAKsoap_rowaction:
             ret = createSoapRowActionSlave(this);
             break;
         case TAKsoap_datasetdataset:
             ret = createSoapDatasetCallSlave(this);
             break;
         case TAKsoap_datasetaction:
             ret = createSoapDatasetActionSlave(this);
             break;
         case TAKcountdisk:
             return new CSlaveActivity(this); 
         case TAKkeydiff:
             ret = createKeyDiffSlave(this);
             break;
         case TAKkeypatch:
             ret = createKeyPatchSlave(this);
             break;
         case TAKlimit:
             ret = createLimitSlave(this);
             break;
         case TAKskiplimit:
             ret = createSkipLimitSlave(this);
             break;
         case TAKcreaterowlimit:
             ret = createRowLimitSlave(this);
             break;
         case TAKnonempty:
             ret = createNonEmptySlave(this);
             break;
         case TAKlocalresultread:
             ret = createLocalResultReadSlave(this);
             break;
         case TAKlocalresultwrite:
             ret = createLocalResultWriteSlave(this);
             break;
         case TAKlocalresultspill:
             ret = createLocalResultSpillSlave(this);
             break;
         case TAKchildif:
             ret = createIfSlave(this);
             break;
         case TAKcatch:
         case TAKskipcatch:
         case TAKcreaterowcatch:
             ret = createCatchSlave(this);
             break;
         case TAKlooprow:
         case TAKloopcount:
         case TAKloopdataset:
             ret = createLoopSlave(this);
             break;
         case TAKgraphloop:
         case TAKparallelgraphloop:
             ret = createGraphLoopSlave(this);
             break;
         case TAKgraphloopresultread:
             ret = createGraphLoopResultReadSlave(this);
             break;
         case TAKgraphloopresultwrite:
             ret = createGraphLoopResultWriteSlave(this);
             break;
         case TAKstreamediterator:
             ret = createStreamedIteratorSlave(this);
             break;
         case TAKifaction:
             ret = createIfActionSlave(this);
             break;
         default:
             throw MakeStringException(TE_UnsupportedActivityKind, "Unsupported activity kind: %s", activityKindStr(kind));
     }
     return ret;
 }
Ejemplo n.º 23
0
struct session *new_session(struct session *ses, char *name, char *arg, int desc)
{
	int cnt = 0;
	char host[BUFFER_SIZE], port[BUFFER_SIZE], file[BUFFER_SIZE];
	struct session *newsession;

	push_call("new_session(%p,%p,%p,%d)",ses,name,arg,desc);

	if (HAS_BIT(gtd->flags, TINTIN_FLAG_TERMINATE))
	{
		pop_call();
		return ses;
	}

	arg = sub_arg_in_braces(ses, arg, host, GET_ONE, SUB_VAR|SUB_FUN);
	arg = sub_arg_in_braces(ses, arg, port, GET_ONE, SUB_VAR|SUB_FUN);
	arg = sub_arg_in_braces(ses, arg, file, GET_ONE, SUB_VAR|SUB_FUN);

	if (desc == 0)
	{
		if (*host == 0)
		{
			tintin_puts(ses, "#HEY! SPECIFY AN ADDRESS WILL YOU?");

			pop_call();
			return ses;
		}

		if (*port == 0)
		{
			tintin_puts(ses, "#HEY! SPECIFY A PORT NUMBER WILL YOU?");

			pop_call();
			return ses;
		}
	}

	for (newsession = gts ; newsession ; newsession = newsession->next)
	{
		if (!strcmp(newsession->name, name))
		{
			tintin_puts(ses, "THERE'S A SESSION WITH THAT NAME ALREADY.");

			pop_call();
			return ses;
		}
	}

	newsession                = (struct session *) calloc(1, sizeof(struct session));

	newsession->name          = strdup(name);
	newsession->host          = strdup(host);
	newsession->ip            = strdup("");
	newsession->port          = strdup(port);

	newsession->group         = strdup(gts->group);
	newsession->flags         = gts->flags;
	newsession->telopts       = gts->telopts;
	newsession->auto_tab      = gts->auto_tab;

	newsession->cmd_color     = strdup(gts->cmd_color);

	newsession->read_max      = gts->read_max;
	newsession->read_buf      = (unsigned char *) calloc(1, gts->read_max);

	LINK(newsession, gts->next, gts->prev);

	for (cnt = 0 ; cnt < LIST_MAX ; cnt++)
	{
		newsession->list[cnt] = copy_list(newsession, gts->list[cnt], cnt);
	}

	newsession->rows          = gts->rows;
	newsession->cols          = gts->cols;
	newsession->top_row       = gts->top_row;
	newsession->bot_row       = gts->bot_row;

	init_buffer(newsession, gts->scroll_max);

	if (desc)
	{
		tintin_printf(ses, "#TRYING TO LAUNCH '%s' RUNNING '%s'.", newsession->name, newsession->host);
	}
	else
	{
		tintin_printf(ses, "#TRYING TO CONNECT '%s' TO '%s' PORT '%s'.", newsession->name, newsession->host, newsession->port);
	}

	gtd->ses = newsession;

	dirty_screen(newsession);

	if (desc == 0)
	{
		newsession = connect_session(newsession);
	}
	else
	{
		SET_BIT(newsession->flags, SES_FLAG_CONNECTED|SES_FLAG_RUN);

		SET_BIT(newsession->telopts, TELOPT_FLAG_SGA);
		DEL_BIT(newsession->telopts, TELOPT_FLAG_ECHO);

		gtd->ses = newsession;

		gtd->ses->socket = desc;
	}

	if (newsession)
	{
		if (*file)
		{
			do_read(newsession, file);
		}
	}

	pop_call();
	return gtd->ses;
}
Ejemplo n.º 24
0
void do_add_imm_host( CHAR_DATA* ch, const char* argument)
{
   char type[MAX_INPUT_LENGTH];
   char arg1[MAX_INPUT_LENGTH];
   char arg2[MAX_INPUT_LENGTH];
   char *arg3 = NULL;
   char *name;
   IMMORTAL_HOST *temp, *host;

   argument = one_argument( argument, type );
   argument = one_argument( argument, arg1 );
   argument = one_argument( argument, arg2 );

   set_char_color( AT_IMMORT, ch );

   if( type[0] == '\0' )
   {
      if( immortal_host_start == NULL )
      {
         send_to_char( "No immortals are protected at this time.\r\n", ch );
         return;
      }
      send_to_char( "Immortal   Host\r\n", ch );
      set_char_color( AT_PLAIN, ch );
      for( temp = immortal_host_start; temp; temp = temp->next )
         ch_printf( ch, "%-8s  %c%s%c\r\n",
                    temp->name, ( temp->prefix ? '*' : ' ' ), temp->host, ( temp->suffix ? '*' : ' ' ) );
      return;
   }

   /*
    * Ok we have a new entry make sure it doesn't contain a ~ 
    */
   if( !str_cmp( type, "save" ) )
   {
      do_write_imm_host(  );
      send_to_char( "Done.\r\n", ch );
      return;
   }

   if( arg2[0] == '\0' || arg1[0] == '\0' )
   {
      send_to_char( "Syntax: immhost add    <name> <host>\r\n", ch );
      send_to_char( "Syntax: immhost delete <name> <host>\r\n", ch );
      send_to_char( "Syntax: immhost save\r\n", ch );
      return;
   }

   if( !str_cmp( type, "delete" ) )
   {
      IMMORTAL_HOST *it = NULL;

      arg3 = arg2;
      if( arg3[0] == '*' )
         arg3++;
      if( arg3[strlen( arg3 ) - 1] == '*' )
         arg3[strlen( arg3 ) - 1] = '\0';

      for( temp = immortal_host_start; temp; temp = temp->next )
      {
         if( !str_cmp( arg1, temp->name ) && !str_cmp( arg3, temp->host ) )
         {
            it = temp;
            break;
         }
      }
      if( it == NULL )
      {
         send_to_char( "Didn't find that entry.\r\n", ch );
         return;
      }
      DISPOSE( temp->name );
      DISPOSE( temp->host );
      UNLINK( it, immortal_host_start, immortal_host_end, next, prev );
      DISPOSE( it );
   }
   else if( !str_cmp( type, "add" ) )
   {
      bool prefix = FALSE, suffix = FALSE;
      int i;

      smash_tilde( arg1 );
      smash_tilde( arg2 );
      name = arg2;

      if( arg2[0] == '*' )
      {
         prefix = TRUE;
         name++;
      }

      if( name[strlen( name ) - 1] == '*' )
      {
         suffix = TRUE;
         name[strlen( name ) - 1] = '\0';
      }

      arg1[0] = toupper( arg1[0] );
      for( i = 0; i < ( int )strlen( name ); i++ )
         name[i] = LOWER( name[i] );
      for( temp = immortal_host_start; temp; temp = temp->next )
      {
         if( !str_cmp( temp->name, arg1 ) && !str_cmp( temp->host, name ) )
         {
            send_to_char( "Entry already exists.\r\n", ch );
            return;
         }
      }
      CREATE( host, IMMORTAL_HOST, 1 );
      host->name = str_dup( arg1 );
      host->host = str_dup( name );
      host->prefix = prefix;
      host->suffix = suffix;
      LINK( host, immortal_host_start, immortal_host_end, next, prev );
   }
   else
   {
      send_to_char( "Syntax: immhost add    <name> <host>\r\n", ch );
      send_to_char( "Syntax: immhost delete <name> <host>\r\n", ch );
      send_to_char( "Syntax: immhost save\r\n", ch );
      return;
   }
   send_to_char( "Done.\r\n", ch );
   return;
}
Ejemplo n.º 25
0
static bool RegisterSelf(SocketEndpoint &masterEp)
{
    StringBuffer slfStr;
    StringBuffer masterStr;
    LOG(MCdebugProgress, thorJob, "registering %s - master %s",slfEp.getUrlStr(slfStr).str(),masterEp.getUrlStr(masterStr).str());
    try
    {
        SocketEndpoint ep = masterEp;
        ep.port = getFixedPort(getMasterPortBase(), TPORT_mp);
        Owned<INode> masterNode = createINode(ep);
        CMessageBuffer msg;
        if (!queryWorldCommunicator().recv(msg, masterNode, MPTAG_THORREGISTRATION))
            return false;
        PROGLOG("Initialization received");
        unsigned vmajor, vminor;
        msg.read(vmajor);
        msg.read(vminor);
        if (vmajor != THOR_VERSION_MAJOR || vminor != THOR_VERSION_MINOR)
        {
            replyError(TE_FailedToRegisterSlave, "Thor master/slave version mismatch");
            return false;
        }
        Owned<IGroup> rawGroup = deserializeIGroup(msg);
        globals->Release();
        globals = createPTree(msg);
        mergeCmdParams(globals); // cmd line

        unsigned slavesPerNode = globals->getPropInt("@slavesPerNode", 1);
        unsigned channelsPerSlave = globals->getPropInt("@channelsPerSlave", 1);
        unsigned localThorPortInc = globals->getPropInt("@localThorPortInc", DEFAULT_SLAVEPORTINC);
        unsigned slaveBasePort = globals->getPropInt("@slaveport", DEFAULT_THORSLAVEPORT);
        setClusterGroup(masterNode, rawGroup, slavesPerNode, channelsPerSlave, slaveBasePort, localThorPortInc);

        unsigned numStrands, blockSize;
        if (globals->hasProp("Debug/@forceNumStrands"))
            numStrands = globals->getPropInt("Debug/@forceNumStrands");
        else
        {
            numStrands = defaultForceNumStrands;
            globals->setPropInt("Debug/@forceNumStrands", defaultForceNumStrands);
        }
        if (globals->hasProp("Debug/@strandBlockSize"))
            blockSize = globals->getPropInt("Debug/@strandBlockSize");
        else
        {
            blockSize = defaultStrandBlockSize;
            globals->setPropInt("Debug/@strandBlockSize", defaultStrandBlockSize);
        }
        PROGLOG("Strand defaults: numStrands=%u, blockSize=%u", numStrands, blockSize);

        const char *_masterBuildTag = globals->queryProp("@masterBuildTag");
        const char *masterBuildTag = _masterBuildTag?_masterBuildTag:"no build tag";
        PROGLOG("Master build: %s", masterBuildTag);
        if (!_masterBuildTag || 0 != strcmp(BUILD_TAG, _masterBuildTag))
        {
            StringBuffer errStr("Thor master/slave build mismatch, master = ");
            errStr.append(masterBuildTag).append(", slave = ").append(BUILD_TAG);
            ERRLOG("%s", errStr.str());
#ifndef _DEBUG
            replyError(TE_FailedToRegisterSlave, errStr.str());
            return false;
#endif
        }
        msg.read((unsigned &)masterSlaveMpTag);
        msg.clear();
        msg.setReplyTag(MPTAG_THORREGISTRATION);
        if (!queryNodeComm().reply(msg))
            return false;

        PROGLOG("Registration confirmation sent");
        if (!queryNodeComm().recv(msg, 0, MPTAG_THORREGISTRATION)) // when all registered
            return false;

        ::masterNode = LINK(masterNode);

        PROGLOG("verifying mp connection to rest of cluster");
        if (!queryNodeComm().verifyAll())
            ERRLOG("Failed to connect to all nodes");
        else
            PROGLOG("verified mp connection to rest of cluster");
        LOG(MCdebugProgress, thorJob, "registered %s",slfStr.str());
    }
    catch (IException *e)
    {
        FLLOG(MCexception(e), thorJob, e,"slave registration error");
        e->Release();
        return false;
    }
    return true;
}
Ejemplo n.º 26
0
S sp(S k)//symbol from phrase: string interning, Ks(sp("aaa")). This should be called before introducing any sym to the instance
{ //We are using this to ensure any two 'character-identical' symbols are in fact represented by the same pointer S
  //See Knuth Algorithm 6.2.2T
  #define LINK(n,x) (n)->c[((x)+1)/2] // -1 => 0 , 1 => 1
  if(!k)R 0;//used in glue. used in _2m_4. used in parse. Probably a good argument to keep since it's exposed for libraries via 2: dyadic
  N t=SYMBOLS, s=t->c[1],p=s,q=p,r; I a,x;
  if(!s){s=t->c[1]=newN();P(!s,(S)ME);s->k=sdup(k); if(!s->k){free(s);t->c[1]=0;ME;} R s->k;} // <-- strdup here and below 
  while(q)
  { if(!(a=SC(k,p->k))){R p->k;}//In the usual tree put: p->k=k,p->v=v before returning
    if(!(q=LINK(p,a))){q=newN();P(!q,(S)ME);q->k=sdup(k);if(!q->k){free(q);ME; R 0;} LINK(p,a)=q;break;}//Usual tree would q->v=v. mmo
    else if(q->b){t=p;s=q;}
    p=q;
  }
  a=0>SC(k,s->k)?-1:1;
  r=p=LINK(s,a);
  while(p!=q){x=SC(k,p->k); p->b=x;p=LINK(p,x);}
  if(!s->b){s->b=a;R p->k;}
  else if(s->b==-a){s->b=0; R p->k;}
  if(r->b==a){p=r; LINK(s,a)=LINK(r,-a); LINK(r,-a)=s; s->b=r->b=0;}
  else if(r->b==-a)
  { p=LINK(r,-a); LINK(r,-a)=LINK(p,a); 
    LINK(p,a)=r; LINK(s,a)=LINK(p,-a); LINK(p,-a)=s;
    if     (p->b== a){s->b=-a; r->b=0;}
    else if(p->b== 0){s->b= 0; r->b=0;}
    else if(p->b==-a){s->b= 0; r->b=a;}
    p->b=0;
  }
  t->c[s==t->c[1]?1:0]=p;
  R q->k; 
}
Ejemplo n.º 27
0
void do_hintedit( CHAR_DATA* ch, const char* argument)
{
   char arg[MAX_STRING_LENGTH];
   char arg2[MAX_STRING_LENGTH];
   char arg3[MAX_STRING_LENGTH];
   HINT_DATA *hintData;
   int i;
   int no = 0;
   int ano = 0;
   bool found = FALSE;

   if( IS_NPC( ch ) )
      return;

   if( !IS_IMMORTAL( ch ) )
      return;

   set_char_color( AT_LBLUE, ch );
   argument = one_argument( argument, arg );
   argument = one_argument( argument, arg2 );
   argument = one_argument( argument, arg3 );
   if( !str_cmp( arg, "help" ) || arg[0] == '\0' )
   {
      do_help( ch, "imm_hints" );
      return;
   }

   if( !str_cmp( arg, "list" ) )
   {
      if( first_hint )
      {
         pager_printf( ch, "No | Low | High |            Text             \r\n" );
         pager_printf( ch, "---|-----|------|--------------------------------------------------\r\n" );
         i = 0;
         for( hintData = first_hint; hintData; hintData = hintData->next )
         {
            ++i;
            pager_printf( ch, "%2d | %3d | %4d | %-30s\r\n", i, hintData->low, hintData->high, hintData->text );
         }
         pager_printf( ch, "\r\n%d hints in file.\r\n", i );
      }
      else
         send_to_char( "No hints in file.\r\n", ch );
      return;
   }

   else if( !str_cmp( arg, "remove" ) )
   {
      no = 0;
      if( !is_number( arg2 ) )
      {
         send_to_char_color( "Remove which hint?\r\n", ch );
         return;
      }
      ano = atoi( arg2 );
      found = FALSE;
      for( hintData = first_hint; hintData; hintData = hintData->next )
      {
         ++no;
         if( no == ano )
         {
            ch_printf_color( ch, "&CHint Number %d removed\r\n", ano );
            UNLINK( hintData, first_hint, last_hint, next, prev );
            STRFREE( hintData->text );
            DISPOSE( hintData );
            found = TRUE;
            break;
         }
      }
      if( !found )
      {
         send_to_char( "Hint not found\r\n", ch );
         return;
      }
      return;
   }
   else if( !str_cmp( arg, "add" ) )
   {
      if( arg2 == '\0' )
      {
         send_to_char( "What is the minimum level for this hint?\r\n", ch );
         return;
      }
      if( arg3 == '\0' )
      {
         send_to_char( "What is the maximum level for this hint?\r\n", ch );
         return;
      }
      if( atoi( arg2 ) > atoi( arg3 ) )
      {
         send_to_char( "Aborting:  max less than min!\r\n", ch );
         return;
      }
      CREATE( hintData, HINT_DATA, 1 );
      hintData->low = atoi( arg2 );
      hintData->high = atoi( arg3 );
      hintData->text = STRALLOC( argument );
      LINK( hintData, first_hint, last_hint, next, prev );
      send_to_char( "Ok.  Hint created\r\n", ch );
      return;
   }
   else if( !str_cmp( arg, "force" ) )
   {
      ch_printf_color( ch, "&p( &wHINT&p ):  &P%s\r\n", get_hint( LEVEL_AVATAR ) );
      return;
   }
   else if( !str_cmp( arg, "edit" ) )
   {
      no = 0;
      i = 0;

      if( arg2[0] == '\0' )
      {
         send_to_char( "Edit which hint number?\r\n", ch );
         return;
      }
      else
         no = atoi( arg2 );
      if( arg3[0] == '\0' )
      {
         ch_printf( ch, "Edit which field of hint %d (low/high/text)?\r\n", no );
         return;
      }
      if( argument[0] == '\0' )
      {
         ch_printf( ch, "Change hint %d's field %s to what ?\r\n", no, arg3 );
         return;
      }
      for( hintData = first_hint; hintData; hintData = hintData->next )
      {
         ++i;
         if( i == no )
         {
            found = TRUE;
            break;
         }
      }
      if( !found )
      {
         ch_printf( ch, "Hint %d not found.\r\n", no );
         return;
      }
      else
      {
         if( !str_cmp( arg3, "text" ) )
         {
            STRFREE( hintData->text );
            hintData->text = STRALLOC( argument );
            send_to_char( "Hint text changed!\r\n", ch );
            return;
         }
         else if( !str_cmp( arg3, "low" ) )
         {
            if( atoi( argument ) > hintData->high )
            {
               send_to_char( "Aborting:  min higher than max.\r\n", ch );
               return;
            }
            hintData->low = atoi( argument );
            send_to_char( "Minimum level for hint changed.\r\n", ch );
            return;
         }
         else if( !str_cmp( arg3, "high" ) )
         {
            if( atoi( argument ) < hintData->low )
            {
               send_to_char( "Aborting:  max lower than min.\r\n", ch );
               return;
            }
            hintData->high = atoi( argument );
            send_to_char( "Maximum level for hint changed.\r\n", ch );
            return;
         }
         else
         {
            send_to_char( "Valid fields are:  low/high/text\r\n", ch );
            return;
         }
      }
   }
   else if( !str_cmp( arg, "save" ) )
   {
      write_hint(  );
      send_to_char( "Saved.\r\n", ch );
      return;
   }
   else
   {
      send_to_char( "Syntax:  hint (list/add/remove/edit/save/force)\r\n", ch );
      return;
   }
}
Ejemplo n.º 28
0
static void addDependent(HqlExprArray & dependents, IHqlExpression * expr)
{
    if (dependents.find(*expr) == NotFound)
        dependents.append(*LINK(expr));
}
Ejemplo n.º 29
0
void do_sharpen( CHAR_DATA * ch, char *argument )
{
   OBJ_DATA *obj;
   OBJ_DATA *pobj;
   char arg[MAX_INPUT_LENGTH];
   AFFECT_DATA *paf;
   int percent;
   int level;

   one_argument( argument, arg );

   if( arg[0] == '\0' )
   {
      send_to_char( "What do you wish to sharpen?\r\n", ch );
      return;
   }

   if( ms_find_obj( ch ) )
      return;

   if( !( obj = get_obj_carry( ch, arg ) ) )
   {
      send_to_char( "You do not have that weapon.\r\n", ch );
      return;
   }

   if( obj->item_type != ITEM_WEAPON )
   {
      send_to_char( "You can't sharpen something that's not a weapon.\r\n", ch );
      return;
   }

   /*
    * Let's not allow people to sharpen bludgeons and the like ;) 
    */
   /*
    * small mods to make it more generic.. --Cronel 
    */
   if( obj->value[3] != DAM_HIT
       && obj->value[3] != DAM_SLICE
       && obj->value[3] != DAM_STAB
       && obj->value[3] != DAM_SLASH
       && obj->value[3] != DAM_CLAW && obj->value[3] != DAM_BITE && obj->value[3] != DAM_PIERCE )
   {
      send_to_char( "You can't sharpen that type of weapon!\r\n", ch );
      return;
   }

   if( obj->value[5] == 1 )   /* see reason below when setting */
   {
      send_to_char( "It is already as sharp as it's going to get.\r\n", ch );
      return;
   }

   for( pobj = ch->first_carrying; pobj; pobj = pobj->next_content )
   {
      if( pobj->pIndexData->vnum == OBJ_VNUM_SHARPEN )
         break;
   }

   if( !pobj )
   {
      send_to_char( "You do not have a sharpening stone.\r\n", ch );
      return;
   }

   WAIT_STATE( ch, skill_table[gsn_sharpen]->beats );
   /*
    * Character must have the dexterity to sharpen the weapon nicely, 
    * * if not, damage weapon 
    */
   if( !IS_NPC( ch ) && get_curr_dex( ch ) < 17 )
   {
      separate_obj( obj );
      if( obj->value[0] <= 1 )
      {
         act( AT_OBJECT, "$p breaks apart and falls to the ground in pieces!.", ch, obj, NULL, TO_CHAR );
         extract_obj( obj );
         learn_from_failure( ch, gsn_sharpen );
         return;
      }
      else
      {
         obj->value[0]--;
         act( AT_GREEN, "You clumsily slip and damage $p!", ch, obj, NULL, TO_CHAR );
         return;
      }
   }

   percent = ( number_percent(  ) - get_curr_lck( ch ) - 15 ); /* too low a chance to damage? */

   separate_obj( pobj );
   if( !IS_NPC( ch ) && percent > ch->pcdata->learned[gsn_sharpen] )
   {
      act( AT_OBJECT, "You fail to sharpen $p correctly, damaging the stone.", ch, obj, NULL, TO_CHAR );
      if( pobj->value[0] <= 1 )
      {
         act( AT_OBJECT, "The sharpening stone crumbles apart from misuse.", ch, pobj, NULL, TO_CHAR );
         extract_obj( pobj );
         learn_from_failure( ch, gsn_sharpen );
         return;
      }
      pobj->value[0]--;
      learn_from_failure( ch, gsn_sharpen );
      return;
   }
   level = ch->level;
   separate_obj( obj );
   act( AT_SKILL, "With skill and precision, you sharpen $p to a fine edge.", ch, obj, NULL, TO_CHAR );
   act( AT_SKILL, "With skill and precision, $n sharpens $p.", ch, obj, NULL, TO_ROOM );
   CREATE( paf, AFFECT_DATA, 1 );
   paf->type = -1;
   paf->duration = -1;
   paf->location = APPLY_DAMROLL;
   paf->modifier = level / 10;
   xCLEAR_BITS( paf->bitvector );   /* changed to ext BVs in upgrade --Cronel */
   LINK( paf, obj->first_affect, obj->last_affect, next, prev );

   obj->value[5] = 1;
   /*
    * originaly a sharpened object flag was used, but took up a BV, 
    * * so I switched to giving it a value5, which is not used in weapons 
    * * besides to check for this 
    */
   learn_from_success( ch, gsn_sharpen );
   return;

}
Ejemplo n.º 30
0
void CDefRecordElement::appendChild(IDefRecordElement * elem)
{
    assertex(!closed);
    CDefRecordElement * cast = dynamic_cast<CDefRecordElement *>(elem);
    children.append(*LINK(cast));
}