Settings fixed.P
This commit is contained in:
parent
54febdcfdc
commit
ffe288321a
0
.luacheckrc
Normal file → Executable file
0
.luacheckrc
Normal file → Executable file
4
api.md
4
api.md
@ -57,6 +57,10 @@ Receives a Line from the IRC and prints it, if it was from an user on the irc, o
|
||||
Sends text to the IRC.
|
||||
<br>
|
||||
|
||||
### void connect()
|
||||
Connects to the IRC.
|
||||
<br>
|
||||
|
||||
## Tables:
|
||||
|
||||
### Help-Entry
|
||||
|
3
api.txt
3
api.txt
@ -54,6 +54,9 @@ Receives a Line from the IRC and prints it, if it was from an user on the irc, o
|
||||
void send_2_irc(string playername, string text)
|
||||
Sends text to the IRC.
|
||||
|
||||
void connect()
|
||||
Connects to the IRC.
|
||||
|
||||
Tables:
|
||||
|
||||
Help-Entry:
|
||||
|
103
irc.lua
103
irc.lua
@ -3,15 +3,18 @@ local S = sc.S
|
||||
|
||||
-- sc.irc_on = true
|
||||
sc.irc_on = minetest.settings:get("smart_chat.irc_on") or false
|
||||
sc.host_ip = minetest.settings:get("smart_chat.host_ip")
|
||||
sc.host_port = tonumber(minetest.settings:get("smart_chat.host_port"))
|
||||
sc.irc_channel = minetest.settings:get("smart_chat.irc_channel")
|
||||
sc.irc_channel_topic = minetest.settings:get("smart_chat.irc_channel_topic")
|
||||
sc.automatic_reconnect = minetest.settings:get("smart_chat.automatic_reconnect") or true
|
||||
sc.servername = minetest.settings:get("smart_chat.servername")
|
||||
sc.host_ip = minetest.settings:get("smart_chat.host_ip") or "localhost"
|
||||
sc.host_port = tonumber(minetest.settings:get("smart_chat.host_port")) or 6667
|
||||
sc.irc_channel = minetest.settings:get("smart_chat.irc_channel") or "MT_Local"
|
||||
sc.irc_channel_topic = minetest.settings:get("smart_chat.irc_channel_topic") or "MT_Server_Local"
|
||||
sc.servername = minetest.settings:get("smart_chat.servername") or "Local"
|
||||
sc.client_timeout = minetest.settings:get("smart_chat.get_client_timeout") or 0.03
|
||||
sc.irc_automatic_reconnect = minetest.settings:get("smart_chat.automatic_reconnect") or true
|
||||
sc.irc_automatic_reconnect_max = tonumber(minetest.settings:get("smart_chat.automatic_reconnect_max")) or 5
|
||||
|
||||
sc.irc_running = false -- IRC is off
|
||||
|
||||
if (sc.irc_on) then
|
||||
|
||||
--[[
|
||||
-- Prepare the Connection to the IRC-Server
|
||||
-- You can found now all in the settings.
|
||||
@ -23,34 +26,45 @@ if (sc.irc_on) then
|
||||
sc.irc_channel_topic = "Minetestserver"
|
||||
sc.clienttimeout = 0.3
|
||||
]]--
|
||||
sc.client_timeout = 0.03
|
||||
--sc.client_timeout = 0.03
|
||||
local socket = require("socket")
|
||||
sc.reconnect = 0 -- counter for Reconnect
|
||||
|
||||
function sc.connect()
|
||||
function sc.irc_connect()
|
||||
if(~sc.irc_running) then
|
||||
sc.irc_running = true
|
||||
minetest.log("action", "Try to connect to: " .. sc.host_ip .. ":" .. sc.host_port)
|
||||
local cl, err = assert(socket.connect(sc.host_ip, sc.host_port)) -- connect to irc
|
||||
minetest.log("action", "Start connection: ", err)
|
||||
sc.client = cl
|
||||
|
||||
minetest.log("action", "Try to connect to: " .. sc.host_ip .. ":" .. sc.host_port)
|
||||
local cl, err = assert(socket.connect(sc.host_ip, sc.host_port)) -- connect to irc
|
||||
minetest.log("action", "Start connection: ", err)
|
||||
sc.client = cl
|
||||
minetest.log("action", "Set client_timeout to: " .. sc.client_timeout)
|
||||
err = sc.client:settimeout(sc.client_timeout) -- and set timeout
|
||||
minetest.log("action", "Settimeout: ", err)
|
||||
|
||||
err = sc.client:settimeout(sc.client_timeout) -- and set timeout
|
||||
minetest.log("action", "Settimeout: ", err)
|
||||
minetest.log("action", "Set Nick: " .. sc.servername)
|
||||
local line = "NICK " .. sc.servername .. " " .. sc.crlf
|
||||
err = sc.client:send(line)
|
||||
minetest.log("action", line, err)
|
||||
|
||||
local line = "NICK " .. sc.servername .. " " .. sc.crlf
|
||||
err = sc.client:send(line)
|
||||
minetest.log("action", line, err)
|
||||
minetest.log("action", "Set User: " .. sc.servername .. " 0 0 " .. sc.servername)
|
||||
line = "USER " .. sc.servername .. " 0 0 " .. sc.servername .. sc.crlf
|
||||
err = sc.client:send(line)
|
||||
minetest.log("action",line, err)
|
||||
|
||||
line = "USER " .. sc.servername .. " 0 0 " .. sc.servername .. sc.crlf
|
||||
err = sc.client:send(line)
|
||||
minetest.log("action",line, err)
|
||||
minetest.log("action", "Join Channel: " .. sc.irc_channel)
|
||||
line = "JOIN " .. sc.irc_channel .. sc.crlf
|
||||
err = sc.client:send(line)
|
||||
minetest.log("action",line, err)
|
||||
|
||||
line = "JOIN " .. sc.irc_channel .. sc.crlf
|
||||
err = sc.client:send(line)
|
||||
minetest.log("action",line, err)
|
||||
minetest.log("action", "Set Channeltopic: " .. sc.irc_channel_topic)
|
||||
line = "TOPIC " .. sc.irc_channel .. " :" .. sc.irc_channel_topic .. sc.crlf
|
||||
err = sc.client:send(line)
|
||||
minetest.log("action", line, err)
|
||||
else
|
||||
sc.report("SYS", "IRC is already connected.")
|
||||
|
||||
line = "TOPIC " .. sc.irc_channel .. " " .. sc.irc_channel_topic .. sc.crlf
|
||||
err = sc.client:send(line)
|
||||
minetest.log("action", line, err)
|
||||
end -- if(−sc.irc_running
|
||||
|
||||
end -- sc.connect
|
||||
|
||||
@ -61,41 +75,50 @@ if (sc.irc_on) then
|
||||
sc.client:send("QUIT" .. sc.crlf)
|
||||
sc.client:close()
|
||||
sc.client = nil
|
||||
sc.irc_running = false
|
||||
|
||||
end -- if(sc.client
|
||||
|
||||
end) -- minetest.register_on_shutdown
|
||||
|
||||
sc.connect() -- connect to IRC
|
||||
sc.irc_connect() -- connect to IRC
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime;
|
||||
if (timer >= 0.5) then
|
||||
local line, err = sc.client:receive("*l") -- get a line from the IRC
|
||||
local line, err = sc.client:receive("*l") -- get line from the IRC
|
||||
if (line ~= nil) then
|
||||
if(string.sub(line,1,4) == "PING") then -- Line was a Ping
|
||||
if(string.sub(line,1,4) == "PING") then -- Line was a Ping
|
||||
local ping = string.sub(line,5)
|
||||
sc.client:send("PONG" .. ping .. "\r\n") -- Answer with Pong
|
||||
|
||||
sc.client:send("PONG" .. ping .. "\r\n") -- Answer with Pong
|
||||
else
|
||||
if(sc.check_join(line)) then -- is it a Join-Report?
|
||||
sc.report("IRC", "*** " .. sc.get_nick_from_irc(line)
|
||||
.. "@IRC" .. " " .. S("join the channel."))
|
||||
if(sc.check_join(line)) then -- is it a Join-Report?
|
||||
sc.report( "IRC", "*** " .. sc.get_nick_from_irc(line)
|
||||
.. "@IRC" .. " " .. S("join the channel."))
|
||||
|
||||
else
|
||||
sc.receive_from_irc(line) -- a line of a user
|
||||
sc.receive_from_irc(line) -- a line of a user
|
||||
|
||||
end -- if(sc.check_join
|
||||
|
||||
end -- if(string.sub
|
||||
|
||||
elseif ((err ~= nil) and (err ~= "timeout")) then
|
||||
minetest.log("action","IRC: " .. err)
|
||||
if(sc.automatic_reconnect) then
|
||||
sc.connect()
|
||||
if(err == "closed") then -- Connection closed?
|
||||
minetest.log("action","IRC: " .. err)
|
||||
sc.client:close() -- Close the Connection
|
||||
sc.running = false
|
||||
|
||||
end -- if(sc.automatic_reconnect
|
||||
sc.report("IRC", "*** Disconnected") -- reconnect? yes ....
|
||||
if ((sc.automatic_reconnect) and (sc.reconnect <= sc.automatic_reconnect_max)) then
|
||||
sc.reconnect = sc.reconnect + 1
|
||||
sc.irc_connect()
|
||||
sc.running = true
|
||||
|
||||
end -- if(sc.automatic_reconnect
|
||||
|
||||
end -- if(err == "closed"
|
||||
|
||||
end -- if(line ~= nil
|
||||
|
||||
|
@ -1,39 +1,27 @@
|
||||
#Command help
|
||||
smart_chat.cmd_help (Enable Help) bool true
|
||||
|
||||
#Command all
|
||||
smart_chat.cmd_all (Enable all) bool true
|
||||
|
||||
#Command channels
|
||||
smart_chat.cmd_channels (Enable all) bool true
|
||||
|
||||
#Command free_channel
|
||||
smart_chat.cmd_free_channel (Enable all) bool true
|
||||
|
||||
#Command invite
|
||||
smart_chat.cmd_invite (Enable invite) bool true
|
||||
|
||||
#Command join
|
||||
smart_chat.cmd_join (Enable join) bool true
|
||||
|
||||
#Command kick
|
||||
smart_chat.cmd_kick (Enable kick) bool true
|
||||
|
||||
#Command leave
|
||||
smart_chat.cmd_leave (Enable leave) bool true
|
||||
|
||||
#Command list
|
||||
smart_chat.cmd_list (Enable list) bool true
|
||||
|
||||
#Command move
|
||||
smart_chat.cmd_move (Enable move) bool true
|
||||
|
||||
#Command store_channel
|
||||
smart_chat.cmd_store_channel (Enable store_channel) bool true
|
||||
|
||||
#Command toggle
|
||||
smart_chat.cmd_toggle (Enable toggle) bool true
|
||||
|
||||
#Command where
|
||||
smart_chat.cmd_where (Enable where) bool true
|
||||
|
||||
@ -43,5 +31,7 @@ smart_chat.host_ip (IP of the IRC) string localhost
|
||||
smart_chat.host_port (Port of the IRC) int 6667
|
||||
smart_chat.irc_channel (Channel on the IRC) string ##MT_Local
|
||||
smart_chat.irc_channel_topic (Topic of the IRC-Channel) string MT_Server
|
||||
smart_chat.irc_client_timeout (Set's the timeout of the IRC-Client) float 0.03
|
||||
smart_chat.automatic_reconnect (Reconnect on lose the connection) bool true
|
||||
smart_chat.servername (Name of the World) string Local
|
||||
smart_chat.automatic_reconnect_max (Max. trys to connect) int 5
|
||||
|
Loading…
x
Reference in New Issue
Block a user