aboutsummaryrefslogtreecommitdiff
path: root/client/shaders/3d_interlaced_merge/opengl_fragment.glsl
blob: 25945ad7f7c9ceaec5529f88edddeb3960c4a752 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
uniform sampler2D baseTexture;
uniform sampler2D normalTexture;
uniform sampler2D textureFlags;

#define leftImage baseTexture
#define rightImage normalTexture
#define maskImage textureFlags

void main(void)
{
	vec2 uv = gl_TexCoord[0].st;
	vec4 left = texture2D(leftImage, uv).rgba;
	vec4 right = texture2D(rightImage, uv).rgba;
	vec4 mask = texture2D(maskImage, uv).rgba;
	vec4 color;
	if (mask.r > 0.5)
		color = right;
	else
		color = left;
	gl_FragColor = color;
}
d='n86' href='#n86'>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 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 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
xban = { MP = minetest.get_modpath(minetest.get_current_modname()) }

dofile(xban.MP.."/serialize.lua")

local db = { }
local tempbans = { }

local DEF_SAVE_INTERVAL = 300 -- 5 minutes
local DEF_DB_FILENAME = minetest.get_worldpath().."/xban.db"
local CLEAN_IP_SECONDS = 24*60*60*7 -- time after which innocent player IPs should get removed
local CLEAN_INTERVAL = 3600 -- interval at which the db should be purged of old IPs

local DB_FILENAME = minetest.settings:get("xban.db_filename")
local SAVE_INTERVAL = tonumber(
  minetest.settings:get("xban.db_save_interval")) or DEF_SAVE_INTERVAL

if (not DB_FILENAME) or (DB_FILENAME == "") then
	DB_FILENAME = DEF_DB_FILENAME
end

local function make_logger(level)
	return function(text, ...)
		minetest.log(level, "[xban] "..text:format(...))
	end
end

local ACTION = make_logger("action")
local WARNING = make_logger("warning")
local ERROR = make_logger("error")

local unit_to_secs = {
	s = 1, m = 60, h = 3600,
	D = 86400, W = 604800, M = 2592000, Y = 31104000,
	[""] = 1,
}

local function parse_time(t) --> secs
	local secs = 0
	for num, unit in t:gmatch("(%d+)([smhDWMY]?)") do
		secs = secs + (tonumber(num) * (unit_to_secs[unit] or 1))
	end
	return secs
end


function xban.is_ip(name)
	-- checks if name is an ipv4 or ipv6 address
	return string.match(name, "%.") or string.match(name, "%:")
end

local function concat_keys(t, sep)
	local keys = {}
	for k, _ in pairs(t) do
		keys[#keys + 1] = k
	end
	return table.concat(keys, sep)
end

function xban.find_entry(player, create) --> entry, index
	for index, e in ipairs(db) do
		for name in pairs(e.names) do
			if name == player then
				return e, index
			end
		end
	end
	if create then
		print(("Created new entry for `%s'"):format(player))
		local e = {
			names = { [player]=true },
			banned = false,
			record = { },
		}
		table.insert(db, e)
		return e, #db
	end
	return nil
end

function xban.get_info(player) --> ip_name_list, banned, last_record
	local e = xban.find_entry(player)
	if not e then
		return nil, "No such entry"
	end
	return e.names, e.banned, e.record[#e.record]
end

function xban.add_record(player, record)
   -- Add records for other punishments banned.
   local e = xban.find_entry(player, true)
   table.insert(e.record, record)
end

function xban.add_property(player, property, value)
   -- adds a property to a player, for instance a "jailed" property which indicates that a player is jailed
   local e = xban.find_entry(player, true)
   e[property] = value
end
function xban.get_property(player, property)
   local e = xban.find_entry(player, true)
   return e[property] 
end


function xban.ban_player(player, source, expires, reason) --> bool, err
	if xban.get_whitelist(player) then
		return nil, "Player is whitelisted; remove from whitelist first"
	end
	local e = xban.find_entry(player, true)
	if e.banned then
		return nil, "Already banned"
	end
	local rec = {
		source = source,
		time = os.time(),
		expires = expires,
		reason = reason,
		type = "ban",
	}
	table.insert(e.record, rec)
	e.names[player] = true
	local pl = minetest.get_player_by_name(player)
	if pl then
		local ip = minetest.get_player_ip(player)
		if ip then
			e.names[ip] = os.time()
		end
		e.last_pos = pl:getpos()
	end
	e.reason = reason
	e.time = rec.time
	e.expires = expires
	e.banned = true
	local msg
	local date = (expires and os.date("%c", expires)
	  or "the end of time")
	if expires then
		table.insert(tempbans, e)
		msg = ("Banned: Expires: %s, Reason: %s"):format(date, reason)
	else
		msg = ("Banned: Reason: %s"):format(reason)
	end
	for nm in pairs(e.names) do
		minetest.kick_player(nm, msg)
	end
	ACTION("%s bans %s until %s for reason: %s", source, player,
	  date, reason)
	ACTION("Banned Names/IPs: %s", concat_keys(e.names, ", "))
	return true
end

function xban.unban_player(player, source, reason) --> bool, err
	local e = xban.find_entry(player)
	if not e then
		return nil, "No such entry"
	end
	local rec = {
		source = source,
		time = os.time(),
		reason = (reason or ""),
		type = "unban"
	}
	table.insert(e.record, rec)
	e.banned = false
	e.reason = nil
	e.expires = nil
	e.time = nil
	ACTION("%s unbans %s", source, player)
	ACTION("Unbanned Names/IPs: %s", concat_keys(e.names, ", "))
	return true
end

function xban.get_whitelist(name_or_ip)
	return db.whitelist and db.whitelist[name_or_ip]
end

function xban.remove_whitelist(name_or_ip)
	if db.whitelist then
		db.whitelist[name_or_ip] = nil
	end
end

function xban.add_whitelist(name_or_ip, source)
	local wl = db.whitelist
	if not wl then
		wl = { }
		db.whitelist = wl
	end
	wl[name_or_ip] = {
		source=source,
	}
	return true
end
function xban.get_account_names(e, player)
	-- get accounts associated with entry
	local names = {}
	if not e then
		return nil, ("No entry for `%s'"):format(player)
	end
	for name in pairs(e.names) do
		if not xban.is_ip(name) and name ~= player then
			table.insert(names, name)
		end
	end
	return names
end

function xban.get_alt_accounts(player)
	local e = xban.find_entry(player)
	return xban.get_account_names(e, player)
end

function xban.get_record(player)
	local e = xban.find_entry(player)
	if not e then
		return nil, ("No entry for `%s'"):format(player)
	elseif (not e.record) or (#e.record == 0) then
		return nil, ("`%s' has no ban records"):format(player)
	end
	local record = { }
	for _, rec in ipairs(e.record) do
		local msg = rec.type or "ban"
		msg = msg .. ": " .. rec.reason or "No reason given."
		if rec.expires then
			msg = msg..(", Expires: %s"):format(os.date("%Y-%m-%d %H:%M:%S", rec.expires))
		end
		if rec.source then
			msg = msg..", Source: "..rec.source
		end
		table.insert(record, ("[%s]: %s"):format(os.date("%Y-%m-%d %H:%M:%S", rec.time), msg))
	end
	local last_pos
	if e.last_pos then
		last_pos = ("User was last seen at %s"):format(
		  minetest.pos_to_string(e.last_pos))
	end

	return record, last_pos
end

function xban.has_password(name)
	local handler = minetest.get_auth_handler()
	local auth = handler.get_auth(name)
	return auth and not minetest.check_password_entry(name, auth.password, "")
end

xban.present = {}

minetest.register_chatcommand("mod_afk", {
	description = "Set afk",
	params = "<on|off>",
	privs = { kick=true },
	func = function(name, params)
		local present = not xban.present[name]
		if params == "on" then
			present = nil
		elseif params == "off" then
			present = true 
		end
		xban.present[name] = present
		if not present then
			ACTION("Moderator %s is now afk", name)
			minetest.chat_send_player(name, "you are now afk")
		else
			ACTION("Moderator %s is now no longer afk", name)
			minetest.chat_send_player(name, "you are no longer afk")
		end
		return true
	end,
})

minetest.register_chatcommand("force_afk", {
   description = "Force moderator to be afk",
	params = "<name>",
	privs = { kick = true },
	func = function(name, params)
		local player = minetest.get_player_by_name(params)
		if not player then
			minetest.chat_send_player(name, "Player "..params.." is not online.")
			return true
		end
		xban.present[params] = nil
		minetest.chat_send_player(params, "[xban] You were set to afk by ".. name)
		ACTION("Moderator %s was set to afk by %s", params, name)
	end,
})
minetest.register_chatcommand("is_afk", {
	description = "Check if moderator is afk",
	params = "<name>",
	privs = { kick=true },
	func = function(name, params)
		local players = minetest:get_connected_players()
		if params == "" then
			minetest.chat_send_player(name, "You are"..(xban.present[name] and " not" or "").." afk")
		end
		for i=1,#players do
			local plname = players[i]:get_player_name() 
			if (params == "" and plname ~= name) or plname == params then
				if minetest.get_player_privs(plname).kick  then
					minetest.chat_send_player(name, "Player "..plname.." is"..(xban.present[plname] and " not" or "").." afk")
				end
				if plname == params then
					return true
				end
			end
		end
		if params ~= "" then
			minetest.chat_send_player(name, "Player "..params.." is not online")
		end
	end,
})

minetest.register_on_prejoinplayer(function(name, ip)
	local wl = db.whitelist or { }
	if wl[name] or wl[ip] then return end
	if minetest.player_exists(name) and not xban.has_password(name) then
		ACTION("Passwordless account %s attempted to log in", name)
		return "This account has been deactivated. Please, contact the server owner on the forums."
	end
	if minetest.settings:get("moderate_new_accounts") and not minetest.player_exists(name) then
		local players = minetest.get_connected_players()
		for i=1,#players do
			local pname = players[i]:get_player_name()
			if minetest.check_player_privs(pname, {ban = true}) and xban.present[pname] then
				return
			end
		end
		ACTION("New player %s tried to join while no active moderators were present, rejected.", name)
		return "No new accounts are allowed while there is no moderator online. Please try rejoining later!"
	end
	local e = xban.find_entry(name) or xban.find_entry(ip)
	if not e then return end
	if e.banned then
		local date = (e.expires and os.date("%c", e.expires)
		  or "the end of time")
		return ("Banned: Expires: %s, Reason: %s"):format(
		  date, e.reason)
	end
end)

minetest.register_on_newplayer(function(player)
		local players = minetest.get_connected_players()
		local pname = player:get_player_name()
		for i=1,#players do
			local name = players[i]:get_player_name()
			if minetest.check_player_privs(name, {ban = true}) or minetest.check_player_privs(name, {kick = true}) then
				minetest.chat_send_player(name, "*** xban: New player "..pname.." joined the game")
			end
		end
end)

minetest.register_on_joinplayer(function(player)
	local name = player:get_player_name()
	local e = xban.find_entry(name)
	local ip = minetest.get_player_ip(name)
	if not e then
		if ip then
			e = xban.find_entry(ip, true)
		else
			return
		end
	end
	e.names[name] = true
	if ip then
		e.names[ip] = os.time()
	end
	e.last_seen = os.time()
end)

minetest.register_chatcommand("xban", {
	description = "XBan a player",
	params = "<player> <reason>",
	privs = { ban=true },
	func = function(name, params)
		local plname, reason = params:match("(%S+)%s+(.+)")
		if not (plname and reason) then
			return false, "Usage: /xban <player> <reason>"
		end
		local ok, e = xban.ban_player(plname, name, nil, reason)
		return ok, ok and ("Banned %s."):format(plname) or e
	end,
})

minetest.register_chatcommand("xtempban", {
	description = "XBan a player temporarily",
	params = "<player> <time> <reason>",
	privs = { ban=true },
	func = function(name, params)
		local plname, time, reason = params:match("(%S+)%s+(%S+)%s+(.+)")
		if not (plname and time and reason) then