TalkAction Multi(-client) checking

elf

Sing, sing blue silver
Joined
Dec 11, 2007
Messages
3,665
Best answers
1
Reaction score
116
Location
Cracow, Poland
Note: This talkaction is included to TheForgottenServer 0.3 since Alpha 3.

Create multicheck.lua located in data/talkactions/scripts and paste there:
Code:
function onSay(cid, words, param)
	if(getPlayerAccess(cid) == 0) then
		return TRUE
	end

	local players = getOnlinePlayers()
	local IPs = {}
	local multiClients = {}
	local multiClientIPs = {}
	for i, player in ipairs(players) do
		local ip = getIPByName(player)
		local pos = table.find(IPs, ip)
		if(pos ~= nil) then
			if(not table.isStrIn(players[pos], multiClients)) then
				table.insert(multiClients, players[pos])
				table.insert(multiClientIPs, ip)
			end
			table.remove(players, pos)
			table.remove(IPs, pos)
			table.insert(multiClients, player)
			table.insert(multiClientIPs, ip)
		end
		table.insert(IPs, ip)
	end

	if(table.maxn(multiClients) > 0) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently online players with same IP address(es):")
		for i, multiClient in ipairs(multiClients) do
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, multiClient .. " (" .. convertIntToIP(multiClientIPs[i]) .. ")")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Currently there aren't any players with same IP address(es).")
	end
	return FALSE
end
Open talkactions.xml located in data/talkactions and add there:
Code:
<talkaction words="/mc" script="multicheck.lua"/>
Now you need to add the following functions to global.lua:
Code:
function convertIntToIP(int, mask)
	local mask = mask or 4294967295

	local b4 = bit.urshift(bit.uband(int, 4278190080), 24)
	local b3 = bit.urshift(bit.uband(int, 16711680), 16)
	local b2 = bit.urshift(bit.uband(int, 65280), 8)
	local b1 = bit.urshift(bit.uband(int, 255), 0)
	if(mask ~= nil) then
		local m4 = bit.urshift(bit.uband(mask, 4278190080), 24)
		local m3 = bit.urshift(bit.uband(mask, 16711680), 16)
		local m2 = bit.urshift(bit.uband(mask, 65280), 8)
		local m1 = bit.urshift(bit.uband(mask, 255), 0)
		if((m1 == 255 or m1 == 0) and (m2 == 255 or m2 == 0) and (m3 == 255 or m3 == 0) and (m4 == 255 or m4 == 0)) then
			if m1 == 0 then b1 = "x" end
			if m2 == 0 then b2 = "x" end
			if m3 == 0 then b3 = "x" end
			if m4 == 0 then b4 = "x" end
		else
			if(m1 ~= 255 or m2 ~= 255 or m3 ~= 255 or m4 ~= 255) then
				return b1 .. "." .. b2 .. "." .. b3 .. "." .. b4 .. " : " .. m1 .. "." .. m2 .. "." .. m3 .. "." .. m4
			end
		end
	end
	
	return b1 .. "." .. b2 .. "." .. b3 .. "." .. b4
end

table.isStrIn = function (txt, str)
	local result = false
	for i, v in pairs(str) do
		result = (string.find(txt, v) and not string.find(txt, '(%w+)' .. v) and not string.find(txt, v .. '(%w+)'))
		if(result) then
			break
		end
	end
	return result
end

getIPByName = getIPByPlayerName
Note: If you're using other distribution than TFS, please make sure that you have the following function: getIPByPlayerName or getIPByName.
 
Last edited:

Fare

Well-Known Member
Joined
Apr 3, 2008
Messages
2,386
Best answers
0
Reaction score
92
Location
Ukraine
nice ;D ThANkS! ;*
<Waiting for alhpa 3>
 

Ninkobi

Owner /Founder of Syphera
Joined
Apr 5, 2008
Messages
206
Best answers
0
Reaction score
1
Location
England
Will it work for TFS 0.2 if you add that function in global.lua?
 
OP
elf

elf

Sing, sing blue silver
Joined
Dec 11, 2007
Messages
3,665
Best answers
1
Reaction score
116
Location
Cracow, Poland
Elf
Excelent script :D

PD:
How to recognize a LAN connection?
You cannot. The script doesn't check for multi client, it actually finds all players (from 2 to more) with same IP.
 

Massen

Masserv RPG
Joined
Jul 23, 2007
Messages
325
Best answers
0
Reaction score
1
Location
Sweden
So if 2 people are playing on the same LAN and you banish them? :p
No, you investigate it. Go and ask one of them why they are Mcing, they will probably have a bad reason if they aint using the same lan. Otherwise they will probably say that they are using the same network. Its all about being a bit aggressive yet understanding.

//Massen
 

Ninkobi

Owner /Founder of Syphera
Joined
Apr 5, 2008
Messages
206
Best answers
0
Reaction score
1
Location
England
This don't work on 0.2, I added the function to global.lua too
 

Ninkobi

Owner /Founder of Syphera
Joined
Apr 5, 2008
Messages
206
Best answers
0
Reaction score
1
Location
England
error maybe, huh?
Code:
[19/10/2008  22:02:09] Lua Script Error: [TalkAction Interface] 
[19/10/2008  22:02:09] data/talkactions/scripts/mc.lua:onSay

[19/10/2008  22:02:09] data/talkactions/scripts/mc.lua:38: attempt to call global 'getIPByName' (a nil value)
[19/10/2008  22:02:09] stack traceback:
[19/10/2008  22:02:09] 	data/talkactions/scripts/mc.lua:38: in function <data/talkactions/scripts/mc.lua:28>
Sorry forgot :p
Heres a error report:
Code:
[19/10/2008  22:02:09] Lua Script Error: [TalkAction Interface] 
[19/10/2008  22:02:09] data/talkactions/scripts/mc.lua:onSay

[19/10/2008  22:02:09] data/talkactions/scripts/mc.lua:38: attempt to call global 'getIPByName' (a nil value)
[19/10/2008  22:02:09] stack traceback:
[19/10/2008  22:02:09] 	data/talkactions/scripts/mc.lua:38: in function <data/talkactions/scripts/mc.lua:28>
 
OP
elf

elf

Sing, sing blue silver
Joined
Dec 11, 2007
Messages
3,665
Best answers
1
Reaction score
116
Location
Cracow, Poland
Seems guy you're missing getIPByName lua function... It should be included in newest 0.2!
 

Ninkobi

Owner /Founder of Syphera
Joined
Apr 5, 2008
Messages
206
Best answers
0
Reaction score
1
Location
England
I am using patch 14, can anyone reproduce with latest patch?
 
Top