aboutsummaryrefslogtreecommitdiff
path: root/assets/oldmodels/trackvertical2.b3d
blob: 22dbb20008f88da268369727777669b32c7a2e75 (plain)
ofshex dumpascii
0000 42 42 33 44 5d 03 00 00 01 00 00 00 4e 4f 44 45 51 03 00 00 43 75 62 65 00 00 00 00 00 00 00 00 BB3D].......NODEQ...Cube........
0020 00 00 00 00 00 00 00 80 3f 00 00 80 3f 00 00 80 3f 00 00 80 3f 00 00 00 00 00 00 00 00 00 00 00 ........?...?...?...?...........
0040 00 4d 45 53 48 1c 03 00 00 ff ff ff ff 56 52 54 53 8c 02 00 00 01 00 00 00 01 00 00 00 02 00 00 .MESH........VRTS...............
0060 00 64 7e 3c 3f 00 00 00 bf 00 00 00 3f 5a e7 2c 3f 3f bd 9f 3e 56 0b 2b 3f a6 a4 3e 3f b4 f4 04 .d~<?.......?Z.,??..>V.+?..>?...
0080 3e 64 7e 3c bf 00 00 00 bf 00 00 00 3f 5a e7 2c bf 3f bd 9f 3e 56 0b 2b 3f aa b6 82 3e c0 f4 04 >d~<........?Z.,.?..>V.+?...>...
00a0 3e 00 00 00 bf 00 00 00 00 00 00 00 3f ae c1 d6 be 0e f7 06 3f 7a 2d 3d 3f 07 ec aa 3e 54 8e 97 >...........?.......?z-=?...>T..
00c0 3e 00 00 00 3f 00 00 00 00 00 00 00 3f ae c1 d6 3e 0e f7 06 3f 7a 2d 3d 3f f9 89 2a 3f 50 8e 97 >...?.......?...>...?z-=?..*?P..
00e0 3e 64 7e 3c bf 00 00 00 bf 00 00 00 3f 5a e7 2c bf 3f bd 9f 3e 56 0b 2b 3f 22 b8 29 3e 18 00 63 >d~<........?Z.,.?..>V.+?".)>..c
0100 3e 1c e2 74 bf 00 00 00 bf 00 00 00 bf 4a fb 24 bf 31 69 98 3e 69 4b 34 3f 40 99 c3 38 96 d9 04 >..t.........J.$.1i.>iK4?@..8...
0120 3f 00 00 00 bf 00 00 00 3f 00 00 00 bf 21 79 90 be 09 73 04 3f 9e d1 4e 3f 03 ec aa 3e e6 e5 2a ?.......?....!y...s.?..N?...>..*
0140 3f 00 00 00 bf 00 00 00 00 00 00 00 3f ae c1 d6 be 0e f7 06 3f 7a 2d 3d 3f 07 ec aa 3e 54 8e 97 ?...........?.......?z-=?...>T..
0160 3e 64 7e 3c 3f 00 00 00 bf 00 00 00 3f 5a e7 2c 3f 3f bd 9f 3e 56 0b 2b 3f f9 91 55 3f 10 00 63 >d~<?.......?Z.,??..>V.+?..U?..c
0180 3e 00 00 00 3f 00 00 00 00 00 00 00 3f ae c1 d6 3e 0e f7 06 3f 7a 2d 3d 3f f9 89 2a 3f 50 8e 97 >...?.......?...>...?z-=?..*?P..
01a0 3e 00 00 00 3f 00 00 00 3f 00 00 00 bf 21 79 90 3e 09 73 04 3f 9e d1 4e 3f fa 89 2a 3f e7 e5 2a >...?...?....!y.>.s.?..N?..*?..*
01c0 3f 1c e2 74 3f 00 00 00 bf 00 00 00 bf 4a fb 24 3f 31 69 98 3e 69 4b 34 3f e3 f9 7f 3f 9a d9 04 ?..t?........J.$?1i.>iK4?...?...
01e0 3f 00 00 00 bf 00 00 00 3f 00 00 00 bf 21 79 90 be 09 73 04 3f 9e d1 4e 3f 03 ec aa 3e e6 e5 2a ?.......?....!y...s.?..N?...>..*
0200 3f 00 00 00 3f 00 00 00 3f 00 00 00 bf 21 79 90 3e 09 73 04 3f 9e d1 4e 3f fa 89 2a 3f e7 e5 2a ?...?...?....!y.>.s.?..N?..*?..*
0220 3f 00 00 00 3f 00 00 00 00 00 00 00 3f ae c1 d6 3e 0e f7 06 3f 7a 2d 3d 3f f9 89 2a 3f 50 8e 97 ?...?.......?...>...?z-=?..*?P..
0240 3e 00 00 00 bf 00 00 00 00 00 00 00 3f ae c1 d6 be 0e f7 06 3f 7a 2d 3d 3f 07 ec aa 3e 54 8e 97 >...........?.......?z-=?...>T..
0260 3e 1c e2 74 3f 00 00 00 bf 00 00 00 bf 4a fb 24 3f 31 69 98 3e 69 4b 34 3f 2e 62 51 3f e3 f9 7f >..t?........J.$?1i.>iK4?.bQ?...
0280 3f 1c e2 74 bf 00 00 00 bf 00 00 00 bf 4a fb 24 bf 31 69 98 3e 69 4b 34 3f 2a 77 3a 3e e3 f9 7f ?..t.........J.$.1i.>iK4?*w:>...
02a0 3f 00 00 00 bf 00 00 00 3f 00 00 00 bf 21 79 90 be 09 73 04 3f 9e d1 4e 3f 03 ec aa 3e e6 e5 2a ?.......?....!y...s.?..N?...>..*
02c0 3f 00 00 00 3f 00 00 00 3f 00 00 00 bf 21 79 90 3e 09 73 04 3f 9e d1 4e 3f fa 89 2a 3f e7 e5 2a ?...?...?....!y.>.s.?..N?..*?..*
02e0 3f 54 52 49 53 7c 00 00 00 ff ff ff ff 02 00 00 00 01 00 00 00 00 00 00 00 03 00 00 00 02 00 00 ?TRIS|..........................
0300 00 00 00 00 00 06 00 00 00 05 00 00 00 04 00 00 00 07 00 00 00 06 00 00 00 04 00 00 00 0a 00 00 ................................
0320 00 09 00 00 00 08 00 00 00 0b 00 00 00 0a 00 00 00 08 00 00 00 0e 00 00 00 0d 00 00 00 0c 00 00 ................................
0340 00 0f 00 00 00 0e 00 00 00 0c 00 00 00 12 00 00 00 11 00 00 00 10 00 00 00 13 00 00 00 12 00 00 ................................
0360 00 10 00 00 00 .....
d='n194' href='#n194'>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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
-------------
-- lua sandboxed environment

-- function to cross out functions and userdata.
-- modified from dump()
function atlatc.remove_invalid_data(o, nested)
	if o==nil then return nil end
	local valid_dt={["nil"]=true, boolean=true, number=true, string=true}
	if type(o) ~= "table" then
		--check valid data type
		if not valid_dt[type(o)] then
			return nil
		end
		return o
	end
	-- Contains table -> true/nil of currently nested tables
	nested = nested or {}
	if nested[o] then
		return nil
	end
	nested[o] = true
	for k, v in pairs(o) do
		v = atlatc.remove_invalid_data(v, nested)
	end
	nested[o] = nil
	return o
end


local env_proto={
	load = function(self, envname, data)
		self.name=envname
		self.sdata=data.sdata and atlatc.remove_invalid_data(data.sdata) or {}
		self.fdata={}
		self.init_code=data.init_code or ""
		self.subscribers=data.subscribers or {}
	end,
	save = function(self)
		-- throw any function values out of the sdata table
		self.sdata = atlatc.remove_invalid_data(self.sdata)
		return {sdata = self.sdata, init_code=self.init_code, subscribers=self.subscribers}
	end,
}

--Environment
--Code modified from mesecons_luacontroller (credit goes to Jeija and mesecons contributors)

local safe_globals = {
	"assert", "error", "ipairs", "next", "pairs", "select",
	"tonumber", "tostring", "type", "unpack", "_VERSION"
}

local function safe_date(f, t)
	if not f then
		-- fall back to old behavior
		return(os.date("*t",os.time()))
	else
		--pass parameters
		return os.date(f,t)
	end
end

-- string.rep(str, n) with a high value for n can be used to DoS
-- the server. Therefore, limit max. length of generated string.
local function safe_string_rep(str, n)
	if #str * n > 2000 then
		debug.sethook() -- Clear hook
		error("string.rep: string length overflow", 2)
	end

	return string.rep(str, n)
end

-- string.find with a pattern can be used to DoS the server.
-- Therefore, limit string.find to patternless matching.
-- Note: Disabled security since there are enough security leaks and this would be unneccessary anyway to DoS the server
local function safe_string_find(...)
	--if (select(4, ...)) ~= true then
	--	debug.sethook() -- Clear hook
	--	error("string.find: 'plain' (fourth parameter) must always be true for security reasons.")
	--end

	return string.find(...)
end

local mp=minetest.get_modpath("advtrains_luaautomation")

local static_env = {
	--core LUA functions
	string = {
		byte = string.byte,
		char = string.char,
		format = string.format,
		len = string.len,
		lower = string.lower,
		upper = string.upper,
		rep = safe_string_rep,
		reverse = string.reverse,
		sub = string.sub,
		find = safe_string_find,
	},
	math = {
		abs = math.abs,
		acos = math.acos,
		asin = math.asin,
		atan = math.atan,
		atan2 = math.atan2,
		ceil = math.ceil,
		cos = math.cos,
		cosh = math.cosh,
		deg = math.deg,
		exp = math.exp,
		floor = math.floor,
		fmod = math.fmod,
		frexp = math.frexp,
		huge = math.huge,
		ldexp = math.ldexp,
		log = math.log,
		log10 = math.log10,
		max = math.max,
		min = math.min,
		modf = math.modf,
		pi = math.pi,
		pow = math.pow,
		rad = math.rad,
		random = math.random,
		sin = math.sin,
		sinh = math.sinh,
		sqrt = math.sqrt,
		tan = math.tan,
		tanh = math.tanh,
	},
	table = {
		concat = table.concat,
		insert = table.insert,
		maxn = table.maxn,
		remove = table.remove,
		sort = table.sort,
	},
	os = {
		clock = os.clock,
		difftime = os.difftime,
		time = os.time,
		date = safe_date,
	},
	POS = function(x,y,z) return {x=x, y=y, z=z} end,
	getstate = advtrains.getstate,
	setstate = advtrains.setstate,
	is_passive = advtrains.is_passive,
	--interrupts are handled per node, position unknown. (same goes for digilines)
	--however external interrupts can be set here.
	interrupt_pos = function(parpos, imesg)
		local pos=atlatc.pcnaming.resolve_pos(parpos, "interrupt_pos")
		atlatc.interrupt.add(0, pos, {type="ext_int", ext_int=true, message=imesg})
	end,
	train_parts = function(train_id)
		if not train_id then return false end
		local train = advtrains.trains[train_id]
		if not train then return false end
		return table.copy(train.trainparts or {})
	end,
	-- sends an atc command to train regardless of where it is in the world
	atc_send_to_train = function(train_id, command)
		assertt(command, "string")
		local train = advtrains.trains[train_id]
		if train then
			advtrains.atc.train_set_command(train, command, true)
			return true
		else
			return false
		end
	end,
	get_slowdown = function()
		return advtrains.global_slowdown
	end
}

-- If interlocking is present, enable route setting functions
if advtrains.interlocking then
	local function gen_checks(signal, route_name, noroutesearch)
		assertt(route_name, "string")
		local pos = atlatc.pcnaming.resolve_pos(signal)
		local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
		if not sigd then
			error("There's no signal at "..minetest.pos_to_string(pos))
		end
		local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
		if not tcbs then
			error("Inconsistent configuration, no tcbs for signal at "..minetest.pos_to_string(pos))
		end
		
		local routeid, route
		if not noroutesearch then
			for routeidt, routet in ipairs(tcbs.routes) do
				if routet.name == route_name then
					routeid = routeidt
					route = routet
					break
				end
			end
			if not route then
				error("No route called "..route_name.." at "..minetest.pos_to_string(pos))
			end
		end
		return pos, sigd, tcbs, routeid, route
	end


	static_env.can_set_route = function(signal, route_name)
		local pos, sigd, tcbs, routeid, route = gen_checks(signal, route_name)
		-- if route is already set on signal, return whether it's committed
		if tcbs.routeset == routeid then
			return tcbs.route_committed
		end
		-- actually try setting route (parameter 'true' designates try-run
		local ok = advtrains.interlocking.route.set_route(sigd, route, true)
		return ok
	end
	static_env.set_route = function(signal, route_name)
		local pos, sigd, tcbs, routeid, route = gen_checks(signal, route_name)
		return advtrains.interlocking.route.update_route(sigd, tcbs, routeid)
	end
	static_env.cancel_route = function(signal)
		local pos, sigd, tcbs, routeid, route = gen_checks(signal, "", true)
		return advtrains.interlocking.route.update_route(sigd, tcbs, nil, true)
	end
	static_env.get_aspect = function(signal)
		local pos = atlatc.pcnaming.resolve_pos(signal)
		return advtrains.interlocking.signal.get_aspect_info(pos)
	end
	static_env.set_aspect = function(signal, main_asp, rem_signal)
		if type(main_asp) == "table" then
			error("set_aspect: Parameters of this method have changed to (signal, main_asp, rem_signal) with introduction of distant signalling: parameter 2 is now the main aspect name (a string)")
		end
		local pos = atlatc.pcnaming.resolve_pos(signal)
		local rem_pos = rem_signal and atlatc.pcnaming.resolve_pos(rem_signal)
		return advtrains.interlocking.signal_set_aspect(pos, main_asp, rem_pos)
	end
	
	--section_occupancy()
	static_env.section_occupancy = function(ts_id)
		if not ts_id then return nil end
		ts_id = tostring(ts_id)
		local response = advtrains.interlocking.db.get_ts(ts_id)
		if not response then return false end
		return (response.trains and table.copy(response.trains)) or {}
	end
end

-- Lines-specific:
if advtrains.lines then
	local atlrwt = advtrains.lines.rwt
	static_env.rwt = {
		now = atlrwt.now,
		new = atlrwt.new,
		copy = atlrwt.copy,
		to_table = atlrwt.to_table,
		to_secs = atlrwt.to_secs,
		to_string = atlrwt.to_string,
		add = atlrwt.add,
		diff = atlrwt.diff,
		sub = atlrwt.sub,
		adj_diff = atlrwt.adj_diff,
		adjust_cycle = atlrwt.adjust_cycle,
		adjust = atlrwt.adjust,
		to_string = atlrwt.to_string,
		get_time_until = atlrwt.get_time_until,
		next_rpt = atlrwt.next_rpt,
		last_rpt = atlrwt.last_rpt,
		time_from_last_rpt = atlrwt.time_from_last_rpt,
		time_to_next_rpt = atlrwt.time_to_next_rpt,
	}
end


atlatc.register_function = function (name, f)
	static_env[name] = f
end

for _, name in pairs(safe_globals) do
	static_env[name] = _G[name]
end

--The environment all code calls get is a table that has set static_env as metatable.
--In general, every variable is local to a single code chunk, but kept persistent over code re-runs. Data is also saved, but functions and userdata and circular references are removed
--Init code and step code's environments are not saved
-- S - Table that can contain any save data global to the environment. Will be saved statically. Can't contain functions or userdata or circular references.
-- F - Table global to the environment, can contain volatile data that is deleted when server quits.
--     The init code should populate this table with functions and other definitions.

local proxy_env={}
--proxy_env gets a new metatable in every run, but is the shared environment of all functions ever defined.

-- returns: true, fenv if successful; nil, error if error 
function env_proto:execute_code(localenv, code, evtdata, customfct)
	-- create us a print function specific for this environment
	if not self.safe_print_func then
		local myenv = self
		self.safe_print_func = function(...)
			myenv:log("info", ...)
		end
	end
	
	local metatbl ={
		__index = function(t, i)
			if i=="S" then
				return self.sdata
			elseif i=="F" then
				return self.fdata
			elseif i=="event" then
				return evtdata
			elseif customfct and customfct[i] then
				return customfct[i]
			elseif localenv and localenv[i] then
				return localenv[i]
			elseif i=="print" then
				return self.safe_print_func
			end
			return static_env[i]
		end,
		__newindex = function(t, i, v)
			if i=="S" or i=="F" or i=="event" or (customfct and customfct[i]) or static_env[i] then
				debug.sethook()
				error("Trying to overwrite environment contents")
			end
			localenv[i]=v
		end,
	}
	setmetatable(proxy_env, metatbl)
	local fun, err=loadstring(code)
	if not fun then
		return false, err
	end
	
	setfenv(fun, proxy_env)
	local succ, data = pcall(fun)
	if succ then
		data=localenv
	end
	return succ, data
end

function env_proto:run_initcode()
	if self.init_code and self.init_code~="" then
		local old_fdata=self.fdata
		self.fdata = {}
		--atprint("[atlatc]Running initialization code for environment '"..self.name.."'")
		local succ, err = self:execute_code({}, self.init_code, {type="init", init=true})
		if not succ then
			self:log("error", "Executing InitCode for '"..self.name.."' failed:"..err)
			self.init_err=err
			if old_fdata then
				self.fdata=old_fdata
				self:log("warning", "The 'F' table has been restored to the previous state.")
			end
		end
	end
end

-- log to environment subscribers. severity can be "error", "warning" or "info" (used by internal print)
function env_proto:log(severity, ...)
	local text=advtrains.print_concat_table({"[atlatc "..self.name.." "..severity.."]", ...})
	minetest.log("action", text)
	for _, pname in ipairs(self.subscribers) do
		minetest.chat_send_player(pname, text)
	end
end

-- env.subscribers table may be directly altered by callers.


--- class interface

function atlatc.env_new(name)
	local newenv={
		name=name,
		init_code="",
		sdata={},
		subscribers={},
	}
	setmetatable(newenv, {__index=env_proto})
	return newenv
end
function atlatc.env_load(name, data)
	local newenv={}
	setmetatable(newenv, {__index=env_proto})
	newenv:load(name, data)
	return newenv
end

function atlatc.run_initcode()
	for envname, env in pairs(atlatc.envs) do
		env:run_initcode()
	end
end