mirror of
https://github.com/minetest-mods/irc.git
synced 2025-07-01 07:30:30 +02:00
Various fixes
This commit is contained in:
@ -1,5 +0,0 @@
|
||||
|
||||
# :mode=cmake:noTabs=true:
|
||||
|
||||
add_subdirectory(lua)
|
||||
add_subdirectory(luasocket)
|
42
src/config.lua
Normal file
42
src/config.lua
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
-- *************************
|
||||
-- ** BASIC USER SETTINGS **
|
||||
-- *************************
|
||||
|
||||
-- Server to connect on joinplayer (string, default "irc.freenode.net")
|
||||
--mt_irc.server = nil;
|
||||
mt_irc.server = "localhost";
|
||||
|
||||
-- Port to connect on joinplayer (number, default 6667)
|
||||
mt_irc.port = nil;
|
||||
|
||||
-- Channel to connect on joinplayer (string, default "#minetest-irc-testing")
|
||||
mt_irc.channel = nil;
|
||||
|
||||
-- ***********************
|
||||
-- ** ADVANCED SETTINGS **
|
||||
-- ***********************
|
||||
|
||||
-- Time between chat updates in seconds (number, default 0.2).
|
||||
mt_irc.dtime = nil;
|
||||
|
||||
-- Underlying socket timeout in seconds (number, default 1.0).
|
||||
mt_irc.timeout = nil;
|
||||
|
||||
-- Nickname when using single conection (string, default "minetest-"..<server-id>);
|
||||
-- (<server-id> is the server IP address packed as a 32 bit integer).
|
||||
mt_irc.server_nick = nil;
|
||||
|
||||
-- Password to use when using single connection (string, default "")
|
||||
mt_irc.password = nil;
|
||||
|
||||
-- The format of messages sent to IRC server (string, default "<$(name)> $(message)")
|
||||
-- See `README.txt' for the macros supported here.
|
||||
mt_irc.message_format_out = "<$(name)> $(message)";
|
||||
|
||||
-- The format of messages sent to IRC server (string, default "<$(name)@IRC> $(message)")
|
||||
-- See `README.txt' for the macros supported here.
|
||||
mt_irc.message_format_in = "<$(name)@IRC> $(message)";
|
||||
|
||||
-- Enable debug output (boolean, default false)
|
||||
mt_irc.debug = true;
|
168
src/init.lua
168
src/init.lua
@ -1,3 +1,4 @@
|
||||
|
||||
-- IRC Mod for Minetest
|
||||
-- (C) 2012 Diego Martínez <kaeza@users.sf.net>
|
||||
--
|
||||
@ -10,63 +11,57 @@
|
||||
-- http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
--
|
||||
|
||||
-- *************************
|
||||
-- ** BEGIN USER SETTINGS **
|
||||
-- *************************
|
||||
|
||||
-- Server to connect on joinplayer (string, default "irc.freenode.net")
|
||||
local SERVER = "irc.freenode.net";
|
||||
|
||||
-- Channel to connect on joinplayer (string, default "#minetest-irc-testing")
|
||||
local CHANNEL = "#minetest-irc-testing";
|
||||
|
||||
-- Time between chat updates in seconds (number, default 0.2).
|
||||
local DTIME = 0.5;
|
||||
|
||||
-- Enable debug output (boolean, default false)
|
||||
local DEBUG = true;
|
||||
|
||||
local SERVER_NICK = "mt_game";
|
||||
|
||||
-- ***********************
|
||||
-- ** END USER SETTINGS **
|
||||
-- ***********************
|
||||
|
||||
-- **********************************************************************
|
||||
-- ** DO NOT EDIT ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!!! **
|
||||
-- **********************************************************************
|
||||
|
||||
|
||||
local MODPATH = minetest.get_modpath("irc");
|
||||
|
||||
mt_irc = { };
|
||||
|
||||
dofile(MODPATH.."/config.lua");
|
||||
|
||||
mt_irc.cur_time = 0;
|
||||
mt_irc.buffered_messages = { };
|
||||
|
||||
package.path = MODPATH.."/?.lua;"..package.path;
|
||||
package.cpath = MODPATH.."/lib?.so;"..MODPATH.."/?.dll;"..package.cpath;
|
||||
|
||||
local irc = require 'irc';
|
||||
|
||||
irc.DEBUG = ((DEBUG and true) or false);
|
||||
irc.DEBUG = ((mt_irc.debug and true) or false);
|
||||
|
||||
-- This could be made local.
|
||||
mt_irc = {
|
||||
cur_time = 0;
|
||||
buffered_messages = { };
|
||||
};
|
||||
|
||||
SERVER = (SERVER or "irc.freenode.net");
|
||||
CHANNEL = (CHANNEL or "#minetest-irc-testing");
|
||||
DTIME = (DTIME or 0.2);
|
||||
-- Set defaults if not specified.
|
||||
if (not mt_irc.server_nick) then
|
||||
local pr = PseudoRandom(os.time());
|
||||
-- Workaround for bad distribution in minetest PRNG implementation.
|
||||
local fmt = "minetest-%02X%02X%02X%02X";
|
||||
mt_irc.server_nick = fmt:format(
|
||||
pr:next(0, 255),
|
||||
pr:next(0, 255),
|
||||
pr:next(0, 255),
|
||||
pr:next(0, 255)
|
||||
);
|
||||
end
|
||||
mt_irc.server = (mt_irc.server or "irc.freenode.net");
|
||||
mt_irc.port = (mt_irc.port or 6667);
|
||||
mt_irc.channel = (mt_irc.channel or "#minetest-irc-testing");
|
||||
mt_irc.dtime = (mt_irc.dtime or 0.2);
|
||||
mt_irc.message_format_out = (mt_irc.message_format_out or "<$(nick)> $(message)");
|
||||
mt_irc.message_format_in = (mt_irc.message_format_in or "<$(name)@IRC[$(channel)]> $(message)");
|
||||
|
||||
minetest.register_globalstep(function ( dtime )
|
||||
mt_irc.cur_time = mt_irc.cur_time + dtime;
|
||||
if (mt_irc.cur_time >= DTIME) then
|
||||
if (mt_irc.cur_time >= mt_irc.dtime) then
|
||||
if (mt_irc.buffered_messages) then
|
||||
for _, t in ipairs(mt_irc.buffered_messages) do
|
||||
irc.say(CHANNEL, "[GAME:"..t.name.."]: "..(t.message or ""));
|
||||
for _, msg in ipairs(mt_irc.buffered_messages) do
|
||||
local t = {
|
||||
name=(msg.name or "<BUG:no one is saying this>");
|
||||
message=(msg.message or "<BUG:there is no message>");
|
||||
};
|
||||
local text = mt_irc.message_format_out:gsub("%$%(([^)]+)%)", t)
|
||||
irc.say(mt_irc.channel, text);
|
||||
end
|
||||
mt_irc.buffered_messages = nil;
|
||||
end
|
||||
irc.poll();
|
||||
mt_irc.cur_time = mt_irc.cur_time - DTIME;
|
||||
mt_irc.cur_time = mt_irc.cur_time - mt_irc.dtime;
|
||||
local plys = minetest.get_connected_players();
|
||||
if (#plys <= 0) then -- Just in case :)
|
||||
irc.quit("Closing.");
|
||||
@ -74,35 +69,67 @@ minetest.register_globalstep(function ( dtime )
|
||||
end
|
||||
end);
|
||||
|
||||
local function strltrim ( s )
|
||||
return s:gsub("^[[:space:]]*", "");
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function ( player )
|
||||
|
||||
minetest.chat_send_all("PLAYER JOINED: "..player:get_player_name());
|
||||
if (not mt_irc.connect_ok) then
|
||||
minetest.chat_send_player(player:get_player_name(), "IRC: Failed to connect to server.");
|
||||
return;
|
||||
end
|
||||
|
||||
irc.register_callback("connect", function ( )
|
||||
irc.join(CHANNEL);
|
||||
irc.join(mt_irc.channel);
|
||||
irc.say(mt_irc.channel, "*** "..player:get_player_name().." joined the game");
|
||||
end);
|
||||
|
||||
irc.register_callback("channel_msg", function ( channel, from, message )
|
||||
minetest.chat_send_all(from.."[IRC:"..channel.."]: "..message);
|
||||
local t = {
|
||||
name=(from or "<BUG:no one is saying this>");
|
||||
message=(message or "<BUG:there is no message>");
|
||||
server=mt_irc.server;
|
||||
port=mt_irc.port;
|
||||
channel=mt_irc.channel;
|
||||
};
|
||||
local text = mt_irc.message_format_in:gsub("%$%(([^)]+)%)", t)
|
||||
minetest.chat_send_all(text);
|
||||
end);
|
||||
|
||||
|
||||
irc.register_callback("private_msg", function ( from, message )
|
||||
local player_to;
|
||||
local msg;
|
||||
if (message:sub(1, 1) == ">") then
|
||||
local pos = message:find(" ", 1, true);
|
||||
if (not pos) then return; end
|
||||
player_to = message:sub(2, pos - 1);
|
||||
msg = message:sub(pos + 1);
|
||||
else
|
||||
irc.say(from, 'Please use the ">username message" syntax.');
|
||||
return;
|
||||
end
|
||||
local t = {
|
||||
name=(from or "<BUG:no one is saying this>");
|
||||
message=(msg or "<BUG:there is no message>");
|
||||
server=mt_irc.server;
|
||||
port=mt_irc.port;
|
||||
channel=mt_irc.channel;
|
||||
};
|
||||
local text = mt_irc.message_format_in:gsub("%$%(([^)]+)%)", t)
|
||||
minetest.chat_send_player(player_to, "PRIVATE: "..text);
|
||||
end);
|
||||
|
||||
irc.register_callback("action", function ( from, message )
|
||||
end);
|
||||
|
||||
|
||||
irc.register_callback("nick_change", function ( from, old_nick )
|
||||
end);
|
||||
|
||||
end);
|
||||
|
||||
minetest.register_on_leaveplayer(function ( player )
|
||||
irc.say(CHANNEL, "*** "..player:get_player_name().." left the game");
|
||||
irc.say(mt_irc.channel, "*** "..player:get_player_name().." left the game");
|
||||
end);
|
||||
|
||||
minetest.register_on_chat_message(function ( name, message )
|
||||
print("***DEBUG: CHAT: "..name.."|"..message);
|
||||
if (not mt_irc.buffered_messages) then
|
||||
mt_irc.buffered_messages = { };
|
||||
end
|
||||
@ -112,19 +139,28 @@ minetest.register_on_chat_message(function ( name, message )
|
||||
};
|
||||
end);
|
||||
|
||||
minetest.register_chatcommand("me", {
|
||||
params = "<action>";
|
||||
description = "chat action (eg. /me orders a pizza)";
|
||||
privs = {shout=true};
|
||||
func = function(name, param)
|
||||
minetest.chat_send_all("* "..name.." "..param);
|
||||
irc.say(CHANNEL, "* "..name.." "..param);
|
||||
end;
|
||||
})
|
||||
|
||||
irc.connect({
|
||||
network = SERVER;
|
||||
nick = SERVER_NICK;
|
||||
pass = "";
|
||||
timeout = 1.0;
|
||||
minetest.register_chatcommand("msg", {
|
||||
params = "<name> <message>";
|
||||
description = "Send a private message to an IRC user";
|
||||
privs = { shout=true; };
|
||||
func = function ( name, param )
|
||||
local pos = param:find(" ", 1, true);
|
||||
if (not pos) then return; end
|
||||
local nick = param:sub(1, pos - 1);
|
||||
local msg = param:sub(pos + 1);
|
||||
local t = {
|
||||
name=nick;
|
||||
message=msg;
|
||||
};
|
||||
local text = mt_irc.message_format_out:gsub("%$%(([^)]+)%)", t)
|
||||
irc.send("PRIVMSG", nick, text);
|
||||
end;
|
||||
});
|
||||
|
||||
mt_irc.connect_ok = pcall(irc.connect, {
|
||||
network = mt_irc.server;
|
||||
port = mt_irc.port;
|
||||
nick = mt_irc.server_nick;
|
||||
pass = mt_irc.password;
|
||||
timeout = mt_irc.timeout;
|
||||
});
|
||||
|
@ -1,50 +0,0 @@
|
||||
|
||||
# :mode=cmake:noTabs=true:tabSize=4:
|
||||
|
||||
set(TO_SOCKET_SHARE
|
||||
http.lua
|
||||
url.lua
|
||||
tp.lua
|
||||
ftp.lua
|
||||
smtp.lua
|
||||
)
|
||||
|
||||
set(TO_TOP_SHARE
|
||||
compat51.lua
|
||||
ltn12.lua
|
||||
socket.lua
|
||||
mime.lua
|
||||
)
|
||||
|
||||
set(LUASOCKET_SRCS
|
||||
compat51.c
|
||||
luasocket.c
|
||||
timeout.c
|
||||
buffer.c
|
||||
io.c
|
||||
auxiliar.c
|
||||
options.c
|
||||
inet.c
|
||||
tcp.c
|
||||
udp.c
|
||||
except.c
|
||||
select.c
|
||||
usocket.c
|
||||
buffer.c
|
||||
auxiliar.c
|
||||
options.c
|
||||
timeout.c
|
||||
io.c
|
||||
usocket.c
|
||||
unix.c
|
||||
mime.c
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
add_library(luasocket_lib MODULE ${LUASOCKET_SRCS})
|
||||
set_target_properties(luasocket_lib
|
||||
PROPERTIES
|
||||
OUTPUT_NAME luasocket
|
||||
COMPILE_FLAGS "-Wall -Werror"
|
||||
)
|
Reference in New Issue
Block a user