diff --git a/commands.lua b/commands.lua index 11d64da..8b80c8f 100644 --- a/commands.lua +++ b/commands.lua @@ -1353,4 +1353,117 @@ basic_robot.commands.puzzle = { end return true end, -} \ No newline at end of file +} + +-- VIRTUAL PLAYER -- + + +local Vplayer = {}; +function Vplayer:new(name) -- constructor + if not basic_robot.data[name].obj then return end -- only make it for existing robot + if basic_robot.virtual_players[name] then return end -- already exists + + local o = {} + setmetatable(o, self) + self.__index = self + o.obj = basic_robot.data[name].obj; + o.data = basic_robot.data[name]; + + local spawnpos = o.data.spawnpos; + local meta = minetest.get_meta(spawnpos); if not meta then return end + o.inv = meta:get_inventory(); + + basic_robot.virtual_players[name] = o; +end + + -- functions + function Vplayer:getpos() return self.obj:getpos() end + function Vplayer:remove() end + function Vplayer:setpos() end + function Vplayer:move_to() end + function Vplayer:punch() end + function Vplayer:rightlick() end + function Vplayer:get_hp() return 20 end + function Vplayer:set_hp() return 20 end + + function Vplayer:get_inventory() return self.inv end + function Vplayer:get_wield_list() return "main" end + function Vplayer:get_wield_index() return 1 end + function Vplayer:get_wielded_item() return self.inv:get_stack("main", 1) end + function Vplayer:set_wielded_item() end + function Vplayer:set_armor_groups() end + function Vplayer:get_armor_groups() return {fleshy = 100} end + function Vplayer:set_animation() end + function Vplayer:get_animation() end + function Vplayer:set_attach() end + function Vplayer:get_attach() end + function Vplayer:set_detach() end + function Vplayer:set_bone_position() end + function Vplayer:get_bone_position() end + function Vplayer:set_properties() end + function Vplayer:get_properties() end + function Vplayer:is_player() return true end + function Vplayer:get_nametag_attributes() end + function Vplayer:set_nametag_attributes() end + + function Vplayer:set_velocity() end + function Vplayer:get_velocity() end + function Vplayer:set_acceleration() end + function Vplayer:get_acceleration() end + function Vplayer:set_yaw() end + function Vplayer:get_yaw() end + function Vplayer:set_texture_mod() end + function Vplayer:get_luaentity() end + + function Vplayer:get_player_name() return self.data.name end + function Vplayer:get_player_velocity() return {x=0,y=0,z=0} end + function Vplayer:get_look_dir() return {x=1,y=0,z=0} end + function Vplayer:get_look_vertical() return 0 end + function Vplayer:get_look_horizontal() return 0 end + function Vplayer:set_look_vertical() end + function Vplayer:set_look_horizontal() end + function Vplayer:get_breath() return 1 end + function Vplayer:set_breath() end + function Vplayer:set_attribute() end + function Vplayer:get_attribute() end + function Vplayer:set_inventory_formspec() end + function Vplayer:get_inventory_formspec() return "" end + function Vplayer:get_player_control() return {} end + function Vplayer:get_player_control_bits() return 0 end + function Vplayer:set_physics_override() end + function Vplayer:get_physics_override() return {} end + function Vplayer:hud_add() end + function Vplayer:hud_remove() end + function Vplayer:hud_change() end + function Vplayer:hud_get() end + function Vplayer:hud_set_flags() end + function Vplayer:hud_get_flags() return {} end + function Vplayer:hud_set_hotbar_itemcount() end + function Vplayer:hud_get_hotbar_itemcount() return 0 end + function Vplayer:hud_set_hotbar_image() end + function Vplayer:hud_get_hotbar_image() return "" end + function Vplayer:hud_set_hotbar_selected_image() end + function Vplayer:hud_get_hotbar_selected_image() return "" end + function Vplayer:set_sky() end + function Vplayer:get_sky() end + function Vplayer:set_clouds() end + function Vplayer:get_clouds() end + function Vplayer:override_day_night_ratio() end + function Vplayer:get_day_night_ratio() end + function Vplayer:set_local_animation() end + function Vplayer:get_local_animation() end + function Vplayer:set_eye_offset() end + function Vplayer:get_eye_offset() end + + + -- code for act borrowed from: https://github.com/minetest-mods/pipeworks/blob/fa4817136c8d1e62dafd6ab694821cba255b5206/wielder.lua, line 372 + + + + + + + + + + diff --git a/init.lua b/init.lua index c925578..5483929 100644 --- a/init.lua +++ b/init.lua @@ -18,7 +18,7 @@ basic_robot.dig_require_energy = true; -- does robot require energy to dig? basic_robot.http_api = minetest.request_http_api(); -basic_robot.version = "2017/12/18a"; +basic_robot.version = "2018/02/06a"; basic_robot.data = {}; -- stores all robot related data --[[ @@ -28,6 +28,8 @@ robot object = object of entity, used to manipulate movements and more basic_robot.ids = {}; -- stores maxid for each player --[name] = {id = .., maxid = .. }, current id for robot controller, how many robot ids player can use +basic_robot.virtual_players = {}; -- this way robot can interact with the world as "player" TODO + basic_robot.data.listening = {}; -- which robots listen to chat dofile(minetest.get_modpath("basic_robot").."/commands.lua") @@ -524,8 +526,6 @@ function getSandboxEnv (name) end - - --special sandbox for admin if authlevel<3 then -- is admin? env._G = env; @@ -836,7 +836,7 @@ minetest.register_entity("basic_robot:robot",{ --textures={"character.png"}, visual="cube", - textures={"arrow.png","basic_machine_side.png","face.png","basic_machine_side.png","basic_machine_side.png","basic_machine_side.png"}, + textures={"topface.png","legs.png","face.png","face-back.png","left-hand.png","right-hand.png"}, visual_size={x=1,y=1}, running = 0, -- does it run code or is it idle? @@ -994,7 +994,7 @@ local spawn_robot = function(pos,node,ttl) local sec_hash = minetest.get_password_hash("",data.authlevel.. owner .. basic_robot.password) if meta:get_string("sec_hash")~= sec_hash then - minetest.chat_send_all("#ROBOT: " .. name .. " is using fake auth level. dig and place again.") + minetest.chat_send_player(owner,"#ROBOT: " .. name .. " is using fake auth level. dig and place again.") return end @@ -1074,7 +1074,7 @@ local spawn_robot = function(pos,node,ttl) local sec_hash = minetest.get_password_hash("",luaent.authlevel.. owner .. basic_robot.password) if meta:get_string("sec_hash")~= sec_hash then - minetest.chat_send_all("#ROBOT: " .. name .. " is using fake auth level. dig and place again.") + minetest.chat_send_player(owner,"#ROBOT: " .. name .. " is using fake auth level. dig and place again.") obj:remove(); return end @@ -1270,6 +1270,9 @@ local on_receive_robot_form = function(pos, formname, fields, sender) if fields.code then local code = fields.code or ""; + if string.len(code) > 64000 then + minetest.chat_send_all("#ROBOT: " .. name .. " is spamming with long text.") return + end if meta:get_int("admin") == 1 then local privs = minetest.get_player_privs(name); -- only admin can edit admin robot code @@ -1537,6 +1540,9 @@ minetest.register_on_player_receive_fields( local name = string.sub(formname, string.len(robot_formname)+1); -- robot name if fields.OK and fields.code then local item = player:get_wielded_item(); --set_wielded_item(item) + if string.len(fields.code) > 1000 then + minetest.chat_send_player(player,"#ROBOT: text too long") return + end item:set_metadata(fields.code); player:set_wielded_item(item); if fields.id then @@ -1678,6 +1684,9 @@ minetest.register_on_player_receive_fields( local data = itemstack:get_meta():to_table().fields -- 0.4.16, old minetest.deserialize(itemstack:get_metadata()) if not data then data = {} end local text = fields.book or ""; + if string.len(text) > 64000 then + minetest.chat_send_all("#ROBOT: " .. sender .. " is spamming with long text.") return + end data.text = text or "" data.title = fields.title or "" data.text_len = #data.text @@ -1997,4 +2006,6 @@ minetest.register_craft({ minetest.register_privilege("robot", "increased number of allowed active robots") -minetest.register_privilege("puzzle", "allow player to use puzzle. namespace in robots") \ No newline at end of file +minetest.register_privilege("puzzle", "allow player to use puzzle. namespace in robots") + +print('[MOD]'.. " basic_robot " .. basic_robot.version .. " loaded.") \ No newline at end of file diff --git a/textures/arrow.png b/textures/arrow.png index 5bb1116..c8116e8 100644 Binary files a/textures/arrow.png and b/textures/arrow.png differ diff --git a/textures/cpu.png b/textures/cpu.png index d178edb..6e99d78 100644 Binary files a/textures/cpu.png and b/textures/cpu.png differ diff --git a/textures/face.png b/textures/face.png index 7ec5976..b991d22 100644 Binary files a/textures/face.png and b/textures/face.png differ