• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction [0.2 / 1.0] logging talkactions

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,327
Solutions
27
Reaction score
2,703
Location
Poland
Not sure if it exists in TFS 1.0 or 0.2, I didn't saw anything in sources
I like to control moderators of my server(gamemasters) if they're not abusing their positions(and proving them how big their lies are if they do) so I wrote this simple script(may lagg a bit when file is large or commands are used too often).

global.lua:
LUA:
log_talkactions = true

-- googled functions used to convert ip
-- source: dialectronics.com/Lua/code/BinDecHex.shtml
local hex2bin = {
	["0"] = "0000",
	["1"] = "0001",
	["2"] = "0010",
	["3"] = "0011",
	["4"] = "0100",
	["5"] = "0101",
	["6"] = "0110",
	["7"] = "0111",
	["8"] = "1000",
	["9"] = "1001",
	["a"] = "1010",
        ["b"] = "1011",
        ["c"] = "1100",
        ["d"] = "1101",
        ["e"] = "1110",
        ["f"] = "1111"
	}
	
function Hex2Bin(s)
local ret = ""
local i = 0
	for i in string.gfind(s, ".") do
		i = string.lower(i)

		ret = ret.." "..hex2bin[i]
	end
	return ret
end
function Bin2Dec(s)
local num = 0
local ex = string.len(s) - 1
local l = 0
	l = ex + 1
	for i = 1, l do
		b = string.sub(s, i, i)
		if b == "1" then
			num = num + 2^ex
		end
		ex = ex - 1
	end
	return string.format("%u", num)
end

-- source: forums.evilmana.com/psp-lua-codebase/string-replace-string-insert/
function string.replace(value, insert, place)
	if place == nil then
		place = string.len(value)+1
	end
	return string.sub( value, 1, place-1) .. string.gsub(string.sub(value, place,place), string.sub(value, place,place), insert) .. string.sub( value, place+string.len(insert), string.len(value))
end
-- end of googled functions

function getPlayerIPv4(pid)
local ip_bin = Hex2Bin(string.format("%x",getPlayerIp(pid)))
local a = string.replace(ip_bin,".",-10)
local b = string.replace(a,".",-20)
local c = string.replace(b,".",-30)
local d = string.gsub(c, " ", "")
local e = string.sub(d, -8, -1)
local f = string.sub(d, -17, -10)
local g = string.sub(d, -26, -19)
local h = string.sub(d, -35, -28)
return Bin2Dec(e).."."..Bin2Dec(f).."."..Bin2Dec(g).."."..Bin2Dec(h)
end

any talkaction, line 2:
LUA:
if log_talkactions then
	file = io.open("talkactions_log.txt", "a+") -- file directory, default - main ot folder
	file:write(os.date("%a %b %d %X %Y", os.time()).." - " .. getPlayerIPv4(cid) .. " - (player id "..getPlayerGUID(cid)..") "..getPlayerName(cid)..": ".. words .." \"".. param .."\n")
	file:close()
end

after using command with this code:
talkactions_log.txt:
Fri Aug 09 17:35:34 2013 - 127.0.0.1 - (player id 1) Faith: /anon "help, Test anonymous channel message

- - - Updated - - -

Updated. Added IPv4 logging
I'll rep++ if anyone manage to shorten it efficiently (1.0 doesn't support bit operations)
 
Last edited:
Back
Top