CONTROL.C
LIB3/D/HOME/CONTROL.C · 3.9 KB
From the archive nm4dos.zip
Download the archive « Back to the archive contents
inherit "/std/room";
#define READ 1
#define WRITE 3
#define MASTER "/d/home/master.c"
#define DOMAIN "Home"
setup()
{
set_short("The "+DOMAIN+" domain control room.");
set_long("This is the domain access control room for "
+"the "+DOMAIN+" domain. If you ain't in a position "
+"to change permissions, there's very little point "
+"in your being here.\n\nCommands are :"
+"\n write <person> <path>"
+"\n read <person> <path>"
+"\n noperm <person> path"
+"\n summary <path>"
+"\n add <person>"
+"\n delete <person> ( or remove <person> )"
+"\n project [person] [new setting]"
+"\n" );
set_light(70);
set_zone("home");
}
void init()
{
::init();
add_action("add_perm", "read");
add_action("add_perm", "write");
add_action("alter_member", "add");
add_action("alter_member", "remove");
add_action("alter_member", "delete");
add_action("rem_perm", "noperm");
add_action("do_summary", "summary");
add_action("project", "project");
}
int project(string str)
{
string *members, name, project;
int i;
if(str)
if(sscanf(str, "%s %s", name, project) == 2)
{
notify_fail("Failed to set "+name+"'s project.\n");
if(MASTER->set_project(name, project))
write("Project set for "+name+" in domain "+DOMAIN+".\n");
else
return 0;
return 1;
}
else
{
write(capitalize(str)+"'s project is "+MASTER->query_project(str)+" in domain "+DOMAIN+".\n");
return 1;
}
members = (string *)MASTER->query_members();
str = "";
for(i=0; i<sizeof(members); i++)
str += members[i]+" : "+MASTER->query_project(members[i])+".\n";
write(str);
return 1;
}
int alter_member(string name)
{
if(!"/secure/login"->test_user(name))
{
notify_fail("There aint no such person.\n");
return 0;
}
if(query_verb() == "add")
{
notify_fail("Failed to add member "+name+" to domain "+DOMAIN+".\n");
if(MASTER->add_member(name))
if("/secure/login"->test_creator(name))
write("Creator "+name+" added to domain "+DOMAIN+".\n");
else
write("Player "+name+" added to domain "+DOMAIN+".\n");
else
return 0;
}
else
{
notify_fail("Failed to remove "+name+" from "+DOMAIN+".\n");
if(MASTER->remove_member(name))
write(capitalize(name)+" removed from domain "+DOMAIN+".\n");
else
return 0;
}
return 1;
}
int add_perm(string str)
{
string person, path;
notify_fail("Useage : "+query_verb()+" <person> <path>\n");
if(!str || sscanf(str, "%s %s", person, path) != 2)
return 0;
if(path[0..strlen(MASTER)-9] != MASTER[0..strlen(MASTER)-9])
{
notify_fail("That aint in your domain!\n");
return 0;
}
person = lower_case(person);
if(!"/secure/login"->test_creator(person))
{
notify_fail("Well you could, but they ain't a creator.\n");
return 0;
}
notify_fail("Permission denied.\n");
if(query_verb() == "write")
if(MASTER->add_permission(person, path, WRITE))
write("Okay, "+person+" can now write to "+path+"\n");
else
return 0;
else
if(MASTER->add_permission(person, path, READ))
write("Okay, "+person+" can now read "+path+"\n");
else
return 0;
return 1;
}
int rem_perm(string str)
{
string person, path;
if(sscanf(str, "%s %s", person, path) != 2)
{
notify_fail("Useage : "+query_verb()+" <path> <person>\n");
return 0;
}
person = lower_case(person);
notify_fail("Couldn't remove permission.\n");
if(MASTER->remove_permission(person, path, 0))
write("Okay permissions for "+person+" to "+path+" removed.\n");
else
return 0;
return 1;
}
string make_string_list( string *names )
{
int i;
if(!names || !(i = sizeof(names)) ) return "";
if(i == 1) return names[0];
return implode(names[0..i-2], ", ") + " and " + names[i-1];
}
int do_summary(string str)
{
mapping access;
string *paths, s;
int i;
access = MASTER->query_access();
if(!access || !sizeof(access) )
{
write("There are no permissions for the "+DOMAIN+" domain.\n");
return 1;
}
s = "";
paths = keys(access);
for(i=0; i<sizeof(paths); i++)
{
s += paths[i] + " : " +
make_string_list( keys(access[paths[i]]) ) +".\n";
}
write(s);
return 1;
}