/
people.c
129 lines (107 loc) · 4.05 KB
/
people.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//*****************************************************************************
// Copyright (c) 2019 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/commands/baseCommand.c";
object Configuration;
/////////////////////////////////////////////////////////////////////////////
public nomask void reset(int arg)
{
if (!arg)
{
CommandType = "Wizard";
addCommandTemplate("people [-w] [-p]");
Configuration = load_object("/lib/dictionaries/configurationDictionary.c");
}
}
/////////////////////////////////////////////////////////////////////////////
private string getPlayerStatus(object player)
{
string playerStatus = " ";
if (query_idle(player) > 300)
{
playerStatus = "I";
}
if ((member(inherit_list(player), "lib/realizations/wizard.c") > -1) &&
player->wizardStatus())
{
playerStatus = player->wizardStatus();
}
return playerStatus[0..0];
}
/////////////////////////////////////////////////////////////////////////////
private string getPlayerLevel(object player)
{
string level = to_string(player->effectiveLevel());
if (member(inherit_list(player), "lib/realizations/wizard.c") > -1)
{
level = capitalize(player->wizardLevel());
}
return sprintf("%-10s", level);
}
/////////////////////////////////////////////////////////////////////////////
private string getPlayerInfo(object player, object initiator)
{
string colorConfiguration = initiator->colorConfiguration();
string address = Configuration->decorate(
sprintf("%-16s", query_ip_number(player) || "<unknown>"),
"ip address", "people", colorConfiguration);
string name = Configuration->decorate(
sprintf("%-20s", capitalize(player->RealName())),
"name", "people", colorConfiguration);
string level = Configuration->decorate(getPlayerLevel(player),
"level", "people", colorConfiguration);
string playerStatus = Configuration->decorate(getPlayerStatus(player),
"status", "people", colorConfiguration);
string location = Configuration->decorate((environment(player) ?
object_name(environment(player)) : "<unknown>"),
"location", "people", colorConfiguration);
location = regreplace(location, "players/", "~");
return address + name + level + playerStatus + " " + location + "\n";
}
/////////////////////////////////////////////////////////////////////////////
private object *getListOfUsers(string command)
{
object *playerList = sort_array(users(),
(: $1->effectiveLevel() < $2->effectiveLevel() :));
object wizardDictionary = load_object("/lib/dictionaries/wizardDictionary.c");
object *wizardList = sort_array(filter(playerList,
(: (member(inherit_list($1), "lib/realizations/wizard.c") > -1) :)),
(: $3->getSortOrder($1) < $3->getSortOrder($2) :), wizardDictionary);
if (sizeof(regexp(({ command }), "-w")))
{
playerList = ({});
}
else
{
playerList -= wizardList;
}
if (sizeof(regexp(({ command }), "-p")))
{
wizardList = ({});
}
return wizardList + playerList;
}
/////////////////////////////////////////////////////////////////////////////
public nomask int execute(string command, object initiator)
{
int ret = 0;
if (canExecuteCommand(command) && initiator->hasExecuteAccess("people"))
{
ret = 1;
object *peopleList = getListOfUsers(command);
string details = sprintf("There are %d players (%d active)\n"
"%-16s%-20s%-10s %s\n", sizeof(peopleList),
sizeof(filter(peopleList, (: query_idle($1) < 300 :))),
"IP Address", "Player Name", "Level", "Location");
foreach(object player in peopleList)
{
if (objectp(player))
{
details += getPlayerInfo(player, initiator);
}
}
tell_object(initiator, details);
}
return ret;
}