CHECKOUT.C

LIB3/OBJ/HANDLERS/CHECKOUT.C · 3.2 KB

From the archive nm4dos.zip

Download the archive   « Back to the archive contents

#define COL "%^CYAN%^"
#define SAVEFILE "/save/checkout"

mapping files;

int     query_owners_files( string str )
{
    mixed   entry;

    if( !str )
	str = (string)this_player()->query_cap_name();
    else
	str = capitalize( str );
    write( COL + "Files checked out by " + str + " :- \n" );

    while( (entry = each( files )) != ({ }) )
	if( entry[ 1 ] == str )
	    if( "/secure/master"->valid_read( entry[ 0 ], this_player() ) )
		write( "    " + entry[ 0 ] + "\n" );
    write( "%^RESET%^\n" );
    return 1;
}

int     check_file_out( string str )
{
    string  name;

    if( !str )
    {
	write( COL + "Useage : " + query_verb() + " <filename>%^RESET%^\n" );
	return 1;
    }
    if( file_size( str ) < 0 )
	str = (string)this_player()->query_current_path() + "/" + str;
    if( file_size( str ) < 0 )
    {
	write( COL + "File not found.%^RESET%^\n" );
	return 1;
    }
    if( !files )
	files = ([ ]);
    if( files[ str ] )
    {
	write( COL + str + " is currently checked out by "
	       + files[ str ] + ".%^RESET%^\n" );
	return 1;
    }
    name = (string)this_player()->query_cap_name();
  files += ([ str:name ]);
    write( COL + "File " + str + " checked out under your name.%^RESET%^\n" );
    log_file( "CHECKOUT",
	      name + " checked out " + str + " at " + ctime( time() ) + "\n" );
    return 1;
}

int     return_file( string str )
{
    string  name;

    if( !str )
    {
	write( COL + "Useage : " + query_verb() + " <filename>%^RESET%^\n" );
	return 1;
    }
    if( file_size( str ) < 0 )
	str = (string)this_player()->query_current_path() + "/" + str;
    if( file_size( str ) < 0 )
    {
	write( COL + "File not found.%^RESET%^\n" );
	return 1;
    }
    if( !files )
	files = ([ ]);
    if( !files[ str ] )
    {
	write( COL + str + " is not checked out.%^RESET%^\n" );
	return 1;
    }

    name = (string)this_player()->query_cap_name();

    if( files[ str ] != name )
    {
	write( COL + str + " is checked out by "
	       + files[ str ] + ", not you!%^RESET%^\n" );
	return 1;
    }
    files = m_delete( files, str );
    write( COL + "File " + str + " returned.%^RESET%^\n" );
    log_file( "CHECKOUT",
	      name + " returned " + str + " at "
	      + ctime( time() ) + "\n" );
    return 1;
}

int     whois_owner( string str )
{
    string  name;

    if( !str )
    {
	write( COL + "Useage : " + query_verb() + " <filename>%^RESET%^\n" );
	return 1;
    }
    if( file_size( str ) < 0 )
	str = (string)this_player()->query_current_path() + "/" + str;
    if( file_size( str ) < 0 )
    {
	write( COL + "File not found.%^RESET%^\n" );
	return 1;
    }
    if( !files )
	files = ([ ]);
    if( !files[ str ] )
    {
	write( COL + str + " is not checked out.%^RESET%^\n" );
	return 1;
    }
    write( COL + "File " + str + " is checked out by " + files[ str ] + ".%^RESET%^\n" );
    return 1;
}

string  query_file_owner( string str )
{
    if( !files )
	files = ([ ]);;
    if( files[ str ] )
	return files[ str ];
    return "";
}

create()
{
    string  old;

    old = geteuid();
    seteuid( "Room" );
    restore_object( SAVEFILE, 1 );
    seteuid( old );
}

dest_me()
{
    string  old;

    old = geteuid();
    seteuid( "Room" );
    save_object( SAVEFILE, 1 );
    seteuid( old );
    destruct( this_object() );
}

Site Stats

Snippets: 1791
Codebases: 571