Skip to content

Commit d9f3265

Browse files
committed
Updated code to new syntax
Made code more consistent Made Messages more consistent Added simple permissions checking Added and Fixed comments
1 parent ba24b03 commit d9f3265

File tree

4 files changed

+220
-225
lines changed

4 files changed

+220
-225
lines changed

auto_include.ms

Lines changed: 153 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -21,148 +21,161 @@ proc(_warp_sanitize, @n,
2121
)
2222

2323
proc(_warp_delete, @n,
24-
assign(@name, _warp_sanitize(@n))
24+
@name = _warp_sanitize(@n)
25+
@player = to_lower(player())
2526

26-
if(_warp_exists(@name),
27-
assign(@warp, _get_warp(@name))
27+
if(_warp_exists(@name)) {
28+
@warp = _get_warp(@name)
2829

29-
if(or(
30-
equals_ic(@warp['owner'], player()),
31-
equals_ic(player(), '~console')),
30+
if(
31+
@warp['owner'] == @player ||
32+
player() == '~console' ||
33+
_warp_perm('admin')) {
3234
_delete_warp(@name)
33-
msg(color(green), 'Warp deleted.')
34-
, # else
35-
msg(color(red), 'You don\'t own this warp!')
36-
)
37-
, # else
38-
msg(color(red), 'No warp with this id exists!')
39-
)
35+
msg(color(green). 'Warp deleted.')
36+
} else {
37+
msg(color(red). 'You don\'t own this warp!')
38+
}
39+
} else {
40+
msg(color(red). 'No warp with this id exists!')
41+
}
4042
)
4143

4244
proc(_warp_list,
4345
# Get a list of warps, sensitive to if the warp
4446
# is accessible by the user or not.
4547

46-
assign(@warps, _get_warps())
47-
assign(@player, to_lower(player()))
48+
@warps = _get_warps()
49+
@player = to_lower(player())
4850

4951
msg('Warps you have access to:')
5052

51-
foreach(@warps, @warp,
53+
foreach(@warps, @warp) {
5254
# User must be owner or shared, or warp must be
5355
# public to be displayed.
5456

55-
if(or(
56-
equals(@warp['isprivate'], false),
57-
equals_ic(@warp['owner'], @player),
58-
array_contains(@warp['sharedto'], @player),
59-
equals(@player, '~console')),
60-
# x) WarpName
57+
if(
58+
@warp['isprivate'] == false ||
59+
@warp['owner'] == @player ||
60+
array_contains(@warp['sharedto'], @player) ||
61+
@player == '~console' ||
62+
_warp_perm('admin')) {
63+
# - WarpName
6164
msg('-' @warp['name'])
62-
)
63-
)
65+
}
66+
}
6467
)
6568

66-
proc(_warp_update,
67-
assign(@warps, _get_warps())
69+
proc(_warp_update,
70+
@warps = _get_warps()
6871

6972
foreach(@warps, @warp,
70-
# User must be owner or shared, or warp must be
71-
# public to be displayed.
72-
73-
if(not(array_index_exists(@warp, 'welcome')),
74-
assign(@warp['welcome'], 'Welcome to' @warp['name'])
75-
)
76-
73+
if(!array_index_exists(@warp, 'welcome')) {
74+
@warp['welcome'] = 'Welcome to' @warp['name']
75+
}
76+
@warp['owner'] = to_lower(@warp['owner'])
77+
7778
_set_warp(@warp['name'], @warp)
7879
)
7980
)
8081

8182
proc(_warp_create, @n, assign(@private, false),
82-
assign(@name, _warp_sanitize(@n))
83+
@name = _warp_sanitize(@n)
8384

85+
if(player() == '~console') {
86+
die(color('red'). 'Player context is required.')
87+
}
88+
89+
if(
90+
!_warp_perm('create')) {
91+
die(color('red'). 'You don\'t have proper permissions.')
92+
}
93+
8494
if(
8595
is_null(@name) ||
86-
@name == '',
87-
die(color(red) . 'You must specify a name!')
88-
)
96+
@name == '') {
97+
die(color(red). 'You must specify a name!')
98+
}
8999

90100
# Don't create a warp if this name is occupied.
91-
if(not(_warp_exists(@name)),
101+
if(!_warp_exists(@name)) {
92102
# Set the data for this warp.
93103
# Default to private warps.
94104
95-
assign(@warp, array())
96-
array_set(@warp, 'owner', player())
97-
array_set(@warp, 'location', ploc())
98-
array_set(@warp, 'facing', pfacing())
99-
array_set(@warp, 'sharedto', array())
100-
array_set(@warp, 'isprivate', @private)
101-
array_set(@warp, 'welcome', 'Welcome to' @n)
102-
array_set(@warp, 'name', @n)
105+
@warp = array()
106+
@warp['owner'] = to_lower(player())
107+
@warp['location'] = ploc()
108+
@warp['facing'] = pfacing()
109+
@warp['sharedto'] = array()
110+
@warp['isprivate'] = @private
111+
@warp['welcome'] = 'Welcome to' @n
112+
@warp['name'] = @n
103113
104114
_set_warp(@name, @warp)
105-
msg(concat(color(green), 'Warp created successfully!'))
106-
, # else
107-
msg(concat(color(red), 'This warp already exists!'))
108-
)
115+
msg(color(green). 'Warp created successfully!')
116+
} else {
117+
msg(color(red). 'This warp already exists!')
118+
}
109119
)
110120
111-
proc(_warp_welcome, @n, @message,
112-
assign(@name, _warp_sanitize(@n))
113-
114-
if(_warp_exists(@name),
115-
assign(@warp, _get_warp(@name))
121+
proc(_warp_welcome, @n, assign(@message, 'Welcome to' @n),
122+
@name = _warp_sanitize(@n)
123+
@player = to_lower(player())
124+
125+
if(_warp_exists(@name)) {
126+
@warp = _get_warp(@name)
116127
117128
# Must be owner to change this.
118-
if(to_lower(player()) != @warp['owner'] &&
119-
player() == '~console',
120-
die(concat(color(red), 'You do not own this warp!'))
121-
)
129+
if(!(@player == @warp['owner'] ||
130+
player() == '~console' ||
131+
_warp_perm('admin'))) {
132+
die(color(red). 'You do not own this warp!')
133+
}
122134
123-
# Change the private bit.
124-
array_set(@warp, 'welcome', @message)
125-
_set_warp(@name, @warp)
135+
# Change the message
136+
@warp['welcome'] = @message
137+
_set_warp(@warp['name'], @warp)
126138
127139
# Notify.
128-
die(concat(color(green), 'Welcome message changed.'))
129-
, # else
130-
die(concat(color(red), 'This warp doesn\'t exist!'))
131-
)
140+
die(color(green). 'Welcome message changed.')
141+
} else {
142+
die(color(red). 'This warp doesn\'t exist!')
143+
}
132144
)
133145

134146
proc(_warp_private, @n, @private,
135-
assign(@name, _warp_sanitize(@n))
136-
assign(@player, to_lower(player()))
147+
@name = _warp_sanitize(@n)
148+
@player = to_lower(player())
137149

138-
if(_warp_exists(@name),
139-
assign(@warp, _get_warp(@name))
150+
if(_warp_exists(@name)) {
151+
@warp = _get_warp(@name)
140152

141153
# Must be owner to change this.
142-
if(@player != @warp['owner'] &&
143-
@player == '~console',
144-
die(concat(color(red), 'You do not own this warp!'))
145-
)
154+
if(!(@player == @warp['owner'] ||
155+
@player == '~console' ||
156+
_warp_perm('admin'))) {
157+
die(color(red). 'You do not own this warp!')
158+
}
146159

147160
# Change the private bit.
148-
array_set(@warp, 'isprivate', @private)
149-
_set_warp(@name, @warp)
161+
@warp['isprivate'] = @private
162+
_set_warp(@warp['name'], @warp)
150163

151164
# Notify.
152-
if(@private,
153-
die(concat(color(green), @name 'is now private.'))
154-
, # else
155-
die(concat(color(green), @name 'is now public.'))
156-
)
157-
, # else
158-
die(concat(color(red), 'This warp doesn\'t exist!'))
159-
)
165+
if(@private) {
166+
die(color(green). @name 'is now private.')
167+
} else {
168+
die(color(green). @name 'is now public.')
169+
}
170+
} else {
171+
die(color(red). 'This warp doesn\'t exist!')
172+
}
160173
)
161174

162-
proc(_warp_share, @n, @p, assign(@s, true),
175+
proc(_warp_share, @n, @p, @s = true,
163176
# Share or unshare a (private) warp.
164-
assign(@player, to_lower(@p))
165-
assign(@name, _warp_sanitize(@n))
177+
@player = to_lower(@p)
178+
@name = _warp_sanitize(@n)
166179

167180
# Allow only true/false.
168181
switch(@s,
@@ -171,84 +184,71 @@ proc(_warp_share, @n, @p, assign(@s, true),
171184
die('Invalid option.')
172185
)
173186

174-
if(_warp_exists(@name),
175-
assign(@warp, _get_warp(@name))
176-
# Make sure the player is the warp's owner.
177-
if(player() == @warp['owner'] ||
178-
player() == '~console',
179-
if(@shared,
180-
# Have a cookie.
181-
182-
if(!array_contains(@warp['sharedto'], @player),
183-
# Only add if the player isn't already in the list.
184-
185-
array_push(@warp['sharedto'], @player)
186-
_set_warp(@name, @warp)
187-
188-
die(concat(color(green), 'Player granted access.'))
189-
, # else
190-
# Player already on list.
191-
192-
die(concat(color(red), 'That player already has access to this warp!'))
193-
)
194-
, # else
195-
# NO WARP 4 U!
196-
197-
if(array_contains(@warp['sharedto'], @player),
198-
assign(@i, 0)
187+
if(_warp_exists(@name)) {
188+
@warp = _get_warp(@name)
189+
190+
# Must be owner to change this.
191+
if(!(to_lower(player()) == @warp['owner'] ||
192+
player() == '~console' ||
193+
_warp_perm('admin'))) {
194+
die(color(red). 'You do not own this warp!')
195+
}
196+
197+
if(@shared) {
198+
if(!array_contains(@warp['sharedto'], @player)) {
199+
# Only add if the player isn't already in the list.
199200
200-
# Need to loop thru the whole list due to no array_remove_value (yet!).
201-
foreach(@warp['sharedto'], @item,
202-
if(@item == @player,
203-
array_remove(@warp['sharedto'], @i)
204-
_set_warp(@name, @warp)
205-
206-
die(concat(color(green), 'Player removed from access.'))
207-
, # else
208-
inc(@i)
209-
)
210-
)
211-
, # else
212-
# Player is already denied.
201+
array_push(@warp['sharedto'], @player)
202+
_set_warp(@name, @warp)
213203
214-
die(concat(color(red), 'This player does not have access to this warp!'))
215-
)
216-
)
217-
, # else
218-
die(concat(color(red), 'This is not your warp to modify!'))
219-
)
220-
, # else
221-
die(concat(color(red), 'This warp doesn\'t exist!'))
222-
)
204+
die(color(green). 'Player granted access.')
205+
} else {
206+
# Player already on list.
207+
die(color(red). 'That player already has access to this warp!')
208+
}
209+
} else {
210+
# remove player from shared list
211+
if(array_contains(@warp['sharedto'], @player)) {
212+
array_remove_values(@warp['sharedto'], @player)
213+
die(color(green). 'Player removed from access.')
214+
} else {
215+
# Player is already denied.
216+
die(color('red'). 'This Player did not have access to this warp!')
217+
}
218+
}
219+
} else {
220+
die(color(red). 'This warp doesn\'t exist!')
221+
}
223222
)
224223

225224
proc(_warp_to, @n,
226-
assign(@name, _warp_sanitize(@n))
225+
@name = _warp_sanitize(@n)
227226

228-
if(_warp_exists(@name),
227+
if(_warp_exists(@name)) {
229228
# Grab the info
230-
assign(@info, _get_warp(@name))
231-
assign(@shared, @info['sharedto'])
232-
assign(@player, to_lower(player()))
229+
@info = _get_warp(@name)
230+
@shared = @info['sharedto']
231+
@player = to_lower(player())
233232

234233
# Make sure the user has perms to go here!
235-
if(or(
236-
equals_ic(@info['owner'], @player),
237-
equals(@info['isprivate'], false),
238-
array_contains(@shared, @player)),
234+
if(
235+
@info['owner'] == @player ||
236+
@info['isprivate'] == false ||
237+
array_contains(@shared, @player) ||
238+
_warp_perm('admin')) {
239239
# Poof.
240240
pfacing(player(), @info['facing'][0], @info['facing'][1])
241241
set_ploc(player(), @info['location'])
242242

243-
if(and(
244-
is_string(@info['welcome']),
245-
not(equals(@info['welcome'], ''))),
243+
if(
244+
is_string(@info['welcome']) &&
245+
!@info['welcome'] == '') {
246246
die(@info['welcome'])
247-
)
248-
, # else
249-
die(concat(color(red), 'You do not have permission to visit this warp.'))
250-
)
251-
, # else
252-
die(concat(color(red), 'This warp does not exist!'))
253-
)
247+
}
248+
} else {
249+
die(color(red). 'You do not have permission to visit this warp.')
250+
}
251+
} else {
252+
die(color(red). 'This warp does not exist!')
253+
}
254254
)

config.msa

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
try(
33
_warp_dispatch($),
44
@ex,
5-
msg(color(red) 'Oops, an error occurred. Check the console!')
5+
msg(color(red). 'Oops, an error occurred. Check the console!')
66
console(@ex)
77
)
88
<<<

0 commit comments

Comments
 (0)