-
Notifications
You must be signed in to change notification settings - Fork 0
/
isp.lua
342 lines (320 loc) · 11.7 KB
/
isp.lua
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
-- internet usage timer config
payment_bitcoin = 24000
payment_bitqu = 6000
payment_bitdi = 2400
payment_bitni = 1200
payment_bitcent = 600
local currency_mod = minetest.get_modpath("currency")
if currency_mod then
-- Currency usage timer config
payment_mg100 = 24000
payment_mg50 = 6000
payment_mg10 = 2400
payment_mg5 = 1200
payment_mg1 = 600
payment_mg25c = 150
payment_mg10c = 60
payment_mg5c = 30
end
function default.isp_on_formspec(pos)
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
local formspec = "size[10,10]"..
"label[1,2;Powered On...]"..
"label[1,2.6;Payment:]"..
"list[nodemeta:".. spos .. ";main;1,3;1,1;]"..
"list[current_player;main;1,6;8,4;]"..
"button_exit[4,5;2,1;exit;Exit]"
return formspec
end
function default.isp_off_formspec(pos)
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
local formspec = "size[10,10]"..
"label[1,2;Powered Off...]"..
"list[nodemeta:".. spos .. ";main;1,3;1,1;]"..
"list[current_player;main;1,6;8,4;]"..
"button_exit[4,5;2,1;exit;Exit]"
return formspec
end
function default.isp_on(pos)
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
local formspec = "size[10,10]"..
"label[2,2;Powered Off...]"..
"list[nodemeta:".. spos .. ";main;1,3;1,1;]"..
"list[current_player;main;1,6;8,4;]"..
"button_exit[4,5;2,1;exit;Exit]"
return formspec
end
local function isp_owner(meta, player)
if player:get_player_name() ~= meta:get_string("owner") then
return false
end
return true
end
-- ISP
minetest.register_node("cryptocoins:isp", {
description = "Internet Service Provider",
tiles = {
"cryptocoins_isp_tp.png",
"cryptocoins_isp_bt.png",
"cryptocoins_isp_rt.png",
"cryptocoins_isp_lt.png",
"cryptocoins_isp_bk.png",
"cryptocoins_isp_ft_off.png"
},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
is_ground_content = true,
groups = {snappy=3},
sound = default.node_sound_wood_defaults(),
drop = "cryptocoins:isp",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.153531, -0.5, -0.405738, 0.153531, -0.315951, 0.405738},
{-0.122825, -0.315951, -0.374616, 0.122825, 0.371166, 0.375},
},
},
on_punch = function(pos)
local node = minetest.get_node(pos)
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
minetest.swap_node(pos, {name = 'cryptocoins:isp_on', param2 = node.param2})
meta:set_string("formspec", default.isp_on_formspec(pos))
meta:set_string("infotext", "Internet Service Provider (owner "..meta:get_string("owner")..")")
inv:set_size("main", 1*1)
timer:start(2)
end,
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local timer = minetest.get_node_timer(pos)
local inv = meta:get_inventory()
meta:set_string("formspec", default.isp_off_formspec(pos))
meta:set_string("owner", placer:get_player_name() or "")
meta:set_string("infotext", "Internet Service Provider (owner "..meta:get_string("owner")..")")
inv:set_size("main", 1*1)
timer:stop()
end,
on_construct = function(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("formspec", default.isp_off_formspec(pos))
meta:set_string("infotext", "Internet Service Provider")
inv:set_size("main", 1*1)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and isp_owner(meta, player)
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if not isp_owner(meta, player) then
return 0
end
return count
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not isp_owner(meta, player) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not isp_owner(meta, player) then
return 0
end
return stack:get_count()
end,
})
minetest.register_node("cryptocoins:isp_on", {
description = "Internet Service Provider",
tiles = {
"cryptocoins_isp_tp.png",
"cryptocoins_isp_bt.png",
"cryptocoins_isp_rt.png",
"cryptocoins_isp_lt.png",
"cryptocoins_isp_bk.png",
{name="cryptocoins_isp_f_animated.png", animation={type="vertical_frames", aspect_w=32, aspect_h=32, length=1.0}},}, --"cryptocoins_isp_f.png"},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
is_ground_content = true,
groups = {snappy=3, not_in_creative_inventory = 1},
sound = default.node_sound_wood_defaults(),
drop = "cryptocoins:isp",
drawtype = "nodebox",
light_source = 4,
node_box = {
type = "fixed",
fixed = {
{-0.153531, -0.5, -0.405738, 0.153531, -0.315951, 0.405738},
{-0.122825, -0.315951, -0.374616, 0.122825, 0.371166, 0.375},
},
},
on_punch = function(pos)
local timer = minetest.get_node_timer(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
minetest.swap_node(pos, {name = 'cryptocoins:isp', param2 = node.param2})
meta:set_string("formspec", default.isp_off_formspec(pos))
meta:set_string("infotext", "Internet Service Provider (owner "..meta:get_string("owner")..")")
local inv = meta:get_inventory()
inv:set_size("main", 1*1)
timer:stop()
end,
on_timer = function(pos)
local meta = minetest.get_meta(pos)
if ( minetest.get_player_by_name(meta:get_string("owner")) == nil ) then
local timer = minetest.get_node_timer(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
minetest.swap_node(pos, {name = 'cryptocoins:isp', param2 = node.param2})
meta:set_string("formspec", default.isp_off_formspec(pos))
meta:set_string("infotext", "Internet Service Provider (owner "..meta:get_string("owner")..")")
local inv = meta:get_inventory()
inv:set_size("main", 1*1)
timer:stop()
else
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", default.isp_on_formspec(pos))
meta:set_string("infotext", "Internet Service Provider (owner "..meta:get_string("owner")..")")
local inv = meta:get_inventory()
inv:set_size("main", 1*1)
local payment = inv:get_stack("main", 1)
if payment:get_name()== "" then
local timer = minetest.get_node_timer(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
minetest.swap_node(pos, {name = 'cryptocoins:isp', param2 = node.param2})
meta:set_string("formspec", default.isp_off_formspec(pos))
meta:set_string("infotext", "Internet Service Provider (owner "..meta:get_string("owner")..")")
local inv = meta:get_inventory()
inv:set_size("main", 1*1)
timer:stop()
else
if currency_mod then
if payment:get_name()=="currency:minegeld_100" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_mg100)
else
if payment:get_name()=="currency:minegeld_50" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_mg50)
else
if payment:get_name()=="currency:minegeld_10" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_mg10)
else
if payment:get_name()=="currency:minegeld_5" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_mg5)
else
if payment:get_name()=="currency:minegeld" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_mg1)
else
if payment:get_name()=="currency:minegeld_cent_25" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_mg1)
else
if payment:get_name()=="currency:minegeld_cent_10" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_mg1)
else
if payment:get_name()=="currency:minegeld_cent_5" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_mg1)
else
if payment:get_name()=="cryptocoins:bitcoin" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_bitcoin)
else
if payment:get_name()=="cryptocoins:bitqu" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_bitqu)
else
if payment:get_name()=="cryptocoins:bitdi" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_bitdi)
else
if payment:get_name()=="cryptocoins:bitni" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_bitni)
else
if payment:get_name()=="cryptocoins:bitcent" then
payment:take_item()
inv:set_stack("main",1,payment)
timer:start(payment_bitcent)
else
local timer = minetest.get_node_timer(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
minetest.swap_node(pos, {name = 'cryptocoins:isp', param2 = node.param2})
meta:set_string("formspec", default.isp_off_formspec(pos))
meta:set_string("infotext", "Internet Service Provider (owner "..meta:get_string("owner")..")")
inv:set_size("main", 1*1)
timer:stop()
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and isp_owner(meta, player)
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if not isp_owner(meta, player) then
return 0
end
return count
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not isp_owner(meta, player) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not isp_owner(meta, player) then
return 0
end
return stack:get_count()
end,
})