@@ -21,148 +21,161 @@ proc(_warp_sanitize, @n,
21
21
)
22
22
23
23
proc(_warp_delete, @n,
24
- assign(@name, _warp_sanitize(@n))
24
+ @name = _warp_sanitize(@n)
25
+ @player = to_lower(player())
25
26
26
- if (_warp_exists(@name),
27
- assign( @warp, _get_warp(@name) )
27
+ if (_warp_exists(@name)) {
28
+ @warp = _get_warp(@name)
28
29
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' )) {
32
34
_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
+ }
40
42
)
41
43
42
44
proc(_warp_list,
43
45
# Get a list of warps, sensitive to if the warp
44
46
# is accessible by the user or not .
45
47
46
- assign( @warps, _get_warps() )
47
- assign( @player, to_lower(player() ))
48
+ @warps = _get_warps()
49
+ @player = to_lower(player())
48
50
49
51
msg(' Warps you have access to:' )
50
52
51
- foreach(@warps, @warp,
53
+ foreach(@warps, @warp) {
52
54
# User must be owner or shared, or warp must be
53
55
# public to be displayed.
54
56
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
61
64
msg(' -' @warp[' name' ])
62
- )
63
- )
65
+ }
66
+ }
64
67
)
65
68
66
- proc(_warp_update,
67
- assign( @warps, _get_warps() )
69
+ proc(_warp_update,
70
+ @warps = _get_warps()
68
71
69
72
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
+
77
78
_set_warp(@warp[' name' ], @warp)
78
79
)
79
80
)
80
81
81
82
proc(_warp_create, @n, assign(@private, false ),
82
- assign( @name, _warp_sanitize(@n) )
83
+ @name = _warp_sanitize(@n)
83
84
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
+
84
94
if (
85
95
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
+ }
89
99
90
100
# Don' t create a warp if this name is occupied.
91
- if(not( _warp_exists(@name)),
101
+ if(! _warp_exists(@name)) {
92
102
# Set the data for this warp.
93
103
# Default to private warps.
94
104
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
103
113
104
114
_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
+ }
109
119
)
110
120
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)
116
127
117
128
# 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
+ }
122
134
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)
126
138
127
139
# 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
+ }
132
144
)
133
145
134
146
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())
137
149
138
- if (_warp_exists(@name),
139
- assign( @warp, _get_warp(@name) )
150
+ if (_warp_exists(@name)) {
151
+ @warp = _get_warp(@name)
140
152
141
153
# 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
+ }
146
159
147
160
# 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)
150
163
151
164
# 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
+ }
160
173
)
161
174
162
- proc(_warp_share, @n, @p, assign(@s, true ) ,
175
+ proc(_warp_share, @n, @p, @s = true ,
163
176
# 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)
166
179
167
180
# Allow only true / false .
168
181
switch(@s,
@@ -171,84 +184,71 @@ proc(_warp_share, @n, @p, assign(@s, true),
171
184
die(' Invalid option.' )
172
185
)
173
186
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.
199
200
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)
213
203
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
+ }
223
222
)
224
223
225
224
proc(_warp_to, @n,
226
- assign( @name, _warp_sanitize(@n) )
225
+ @name = _warp_sanitize(@n)
227
226
228
- if (_warp_exists(@name),
227
+ if (_warp_exists(@name)) {
229
228
# 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())
233
232
234
233
# 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' )) {
239
239
# Poof.
240
240
pfacing(player(), @info[' facing' ][0 ], @info[' facing' ][1 ])
241
241
set_ploc(player(), @info[' location' ])
242
242
243
- if (and (
244
- is_string(@info[' welcome' ]),
245
- not (equals( @info[' welcome' ], ' ' ))),
243
+ if (
244
+ is_string(@info[' welcome' ]) &&
245
+ ! @info[' welcome' ] == ' ' ) {
246
246
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
+ }
254
254
)
0 commit comments