From 4c3e623e93155a6e76b4c9a07c2d632f06bc3d31 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 24 Feb 2015 20:09:21 +0000 Subject: [PATCH] Changes with logging --- mods/capturetheflag/ctf/area.lua | 12 ++++++------ mods/capturetheflag/ctf/cli.lua | 2 -- mods/capturetheflag/ctf/core.lua | 19 ++++++++----------- mods/capturetheflag/ctf/flag.lua | 3 +-- mods/capturetheflag/ctf/gui.lua | 11 ++++++----- mods/capturetheflag/ctf/hud.lua | 7 ++----- mods/capturetheflag/ctf/init.lua | 8 ++++++++ 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/mods/capturetheflag/ctf/area.lua b/mods/capturetheflag/ctf/area.lua index bfe8fc5..f70c788 100644 --- a/mods/capturetheflag/ctf/area.lua +++ b/mods/capturetheflag/ctf/area.lua @@ -53,7 +53,6 @@ function ctf.area.delete_flag(team, pos) return end - print(dump(ctf.team(team).flags)) for i = 1, #ctf.team(team).flags do if ( ctf.team(team).flags[i].x == pos.x and @@ -69,7 +68,7 @@ end -- Gets the nearest flag in a 25 metre radius block function ctf.area.nearest_flag(pos) if not pos then - print ("No position provided to nearest_flag()") + ctf.error("No position provided to nearest_flag()") return nil end @@ -153,13 +152,14 @@ function ctf.area.asset_flags(team) return false end - print("Checking the flags of "..team) + ctf.log("utils", "Checking the flags of "..team) local tmp = ctf.team(team).flags - + local get_res = minetest.env:get_node(tmp[i]) for i=1,#tmp do - if tmp[i] and (not minetest.env:get_node(tmp[i]) or not minetest.env:get_node(tmp[i]).name == "ctf:flag") then - print("Replacing flag...") + if tmp[i] and (not get_res or not get_res.name == "ctf:flag") then + ctf.log("utils", "Replacing flag...") + -- TODO: ctf.area.asset_flags end end end diff --git a/mods/capturetheflag/ctf/cli.lua b/mods/capturetheflag/ctf/cli.lua index 77d83b7..f7cbacb 100644 --- a/mods/capturetheflag/ctf/cli.lua +++ b/mods/capturetheflag/ctf/cli.lua @@ -24,8 +24,6 @@ minetest.register_chatcommand("team", { local create = string.match(param,"^add ([%a%d_]+)") local tplayer,tteam = string.match(param,"^join ([%a%d_]+) ([%a%d_]+)") if test then - print("is a player request "..test) - if ctf.player(test) then if ctf.player(test).team then if ctf.player(test).auth then diff --git a/mods/capturetheflag/ctf/core.lua b/mods/capturetheflag/ctf/core.lua index e3f7a53..f98837b 100644 --- a/mods/capturetheflag/ctf/core.lua +++ b/mods/capturetheflag/ctf/core.lua @@ -20,7 +20,7 @@ function ctf.log(area, msg) end function ctf.warning(area, msg) - minetest.log("warning", "[CaptureTheFlag] (" .. area .. ") " .. msg) + print("WARNING: [CaptureTheFlag] (" .. area .. ") " .. msg) end function ctf.init() @@ -143,11 +143,11 @@ end function ctf.team(name) -- get or add a team if type(name) == "table" then if not name.add_team then - error("Invalid table given to ctf.team") + ctf.error("Invalid table given to ctf.team") return end - print("Defining team "..name.name) + ctf.log("team", "Defining team "..name.name) ctf.teams[name.name]={ data = name, @@ -403,12 +403,9 @@ minetest.register_on_newplayer(function(player) return end local name = player:get_player_name() - -- TODO: make this work correctly. (ie no need for minetest.after) - minetest.after(1, function() - local team = ctf.autoalloc(name, alloc_mode) - if team then - ctf.log("autoalloc", name .. " was allocated to " .. team) - ctf.join(name, team) - end - end) + local team = ctf.autoalloc(name, alloc_mode) + if team then + ctf.log("autoalloc", name .. " was allocated to " .. team) + ctf.join(name, team) + end end) diff --git a/mods/capturetheflag/ctf/flag.lua b/mods/capturetheflag/ctf/flag.lua index 4b8897c..afcb65f 100644 --- a/mods/capturetheflag/ctf/flag.lua +++ b/mods/capturetheflag/ctf/flag.lua @@ -314,7 +314,6 @@ minetest.register_on_respawnplayer(function(player) if player and ctf.player(player:get_player_name()) then local team = ctf.player(player:get_player_name()).team if team and ctf.team(team) and ctf.area.get_spawn(team)==true then - print("Player "..player:get_player_name().." moved to team spawn") player:moveto(ctf.team(team).spawn, false) return true end @@ -337,7 +336,7 @@ minetest.register_abm({ local flag_team_data = ctf.area.get_flag(pos) if not flag_team_data or not ctf.team(flag_team_data.team)then - print("Flag does not exist! "..dump(pos)) + ctf.log("flag", "Flag does not exist! Deleting nodes. "..dump(pos)) minetest.env:set_node(pos,{name="air"}) minetest.env:set_node(top,{name="air"}) return diff --git a/mods/capturetheflag/ctf/gui.lua b/mods/capturetheflag/ctf/gui.lua index e7ce3df..f559893 100644 --- a/mods/capturetheflag/ctf/gui.lua +++ b/mods/capturetheflag/ctf/gui.lua @@ -23,6 +23,7 @@ end -- Team interface function ctf.gui.team_board(name,team) + ctf.log("gui", name .. " views team_board") if not ctf.setting("team_gui") or not ctf.setting("gui") then return end @@ -61,7 +62,6 @@ function ctf.gui.team_board(name,team) local height = (amount*0.5)+0.5 if height > 5 then - print("break!") break end @@ -88,6 +88,7 @@ end -- Team interface function ctf.gui.team_flags(name,team) + ctf.log("gui", name .. " views team_flags") if not ctf.setting("team_gui") or not ctf.setting("gui") then return end @@ -148,6 +149,7 @@ end -- Team interface function ctf.gui.team_dip(name,team) + ctf.log("gui", name .. " views team_dip") if not ctf.setting("team_gui") or not ctf.setting("gui") then return end @@ -210,6 +212,7 @@ end -- Team interface function ctf.gui.team_settings(name,team) + ctf.log("gui", name .. " views team_settings") if not ctf.setting("team_gui") or not ctf.setting("gui") then return end @@ -279,7 +282,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if ctf and ctf.team(ctf.players[name].team) and ctf.team(ctf.players[name].team).data then if minetest.registered_items["ctf:flag_top_"..fields.color] then - print("Setting color...") ctf.team(ctf.players[name].team).data.color = fields.color ctf.save() else @@ -399,6 +401,7 @@ end) -- Flag interface function ctf.gui.flag_board(name,pos) + ctf.log("gui", name .. " views team_board") local flag = ctf.area.get_flag(pos) if not flag then return @@ -479,8 +482,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) msg = "A flag was named "..fields.flag_name.." at ("..ctf.gui.flag_data[name].pos.x..","..ctf.gui.flag_data[name].pos.z..")" end - print(msg) - ctf.post(team,{msg=msg,icon="flag_info"}) return true @@ -490,7 +491,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local flag = ctf.area.get_flag(ctf.gui.flag_data[name].pos) if not flag then - print("No flag?!") + return end local team = flag.team diff --git a/mods/capturetheflag/ctf/hud.lua b/mods/capturetheflag/ctf/hud.lua index 8b26a1f..841b230 100644 --- a/mods/capturetheflag/ctf/hud.lua +++ b/mods/capturetheflag/ctf/hud.lua @@ -67,13 +67,12 @@ minetest.register_on_leaveplayer(function(player) end) function ctf.hud.update(player) - ctf.log("hud", "Updating player HUD") if not player then - ctf.log("hud", " - player not emerged") return end - local player_data = ctf.player(player:get_player_name()) + local name = player:get_player_name() + local player_data = ctf.player(name) if not player_data or not player_data.team or not ctf.team(player_data.team) then return @@ -97,8 +96,6 @@ function ctf.hud.update(player) ctf.hud:change(player, "ctf:hud_team", "text", player_data.team) ctf.hud:change(player, "ctf:hud_team", "number", color) end - - ctf.log("hud", " - Done.") end local count = 0 diff --git a/mods/capturetheflag/ctf/init.lua b/mods/capturetheflag/ctf/init.lua index 6b482ef..950f2c9 100644 --- a/mods/capturetheflag/ctf/init.lua +++ b/mods/capturetheflag/ctf/init.lua @@ -4,6 +4,14 @@ ctf = {} +-- Fix for https://github.com/minetest/minetest/issues/2383 +local csa = minetest.chat_send_all +function minetest.chat_send_all(msg) + minetest.after(0, function() + csa(msg) + end) +end + -- Modules dofile(minetest.get_modpath("ctf").."/core.lua") dofile(minetest.get_modpath("ctf").."/diplomacy.lua")