-
Notifications
You must be signed in to change notification settings - Fork 18
/
cd.c
58 lines (50 loc) · 1.84 KB
/
cd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//*****************************************************************************
// Copyright (c) 2018 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/commands/baseCommand.c";
/////////////////////////////////////////////////////////////////////////////
public nomask void reset(int arg)
{
if (!arg)
{
addCommandTemplate("cd [##Target##]");
}
}
/////////////////////////////////////////////////////////////////////////////
public nomask int execute(string command, object initiator)
{
int ret = 0;
if (canExecuteCommand(command) && initiator->hasExecuteAccess("cd"))
{
string newDirectory = getTargetString(initiator, command);
string homeDir = sprintf("/players/%s",
lower_case(initiator->RealName()));
if (!newDirectory || (newDirectory == "") || (newDirectory == "~"))
{
newDirectory = homeDir;
}
newDirectory = regreplace(newDirectory, "^~/", homeDir);
newDirectory = regreplace(newDirectory, "^~", "/players/");
if (newDirectory[0] != '/')
{
newDirectory = sprintf("%s/%s", initiator->pwd(), newDirectory);
}
newDirectory = initiator->hasReadAccess(newDirectory);
if (newDirectory && (file_size(newDirectory) == -2))
{
ret = 1;
initiator->pwd(newDirectory);
tell_object(initiator, sprintf("%s\n", newDirectory));
}
else if(!newDirectory)
{
notify_fail("You do not have the read access for that.\n");
}
else if (file_size(newDirectory) == -1)
{
notify_fail("That directory does not exist.\n");
}
}
return ret;
}