Jump to content
Sign in to follow this  
Mock

Outro otserv checker em lua (melhor)

Recommended Posts

Mock    32
Mock

Naverdade é uma funçao:

function check(ip,port)
local c = socket.connect(ip,port)
if not c then
	return false,'Server offline'
end
c:send(string.char(0x06,0x00,0xff,0xff)..'info\n')
local s,cl,d = c:receive(1024)
local status = s or d
status = status:match('<tsqp version="1.0">(.+)</tsqp>')
if not status then
	return false,'No response'
end
local md = {}
for name,inside in status:gmatch('<(%l+) (.-)/>') do
	if not md[name] then
		md[name] = {}
	end
	for v,inf in inside:gmatch('(%l+)%s*=%s*"(.-)"') do
		md[name][v] = inf
	end
end
md['motd'] = {}
md['motd'][1] = status:match('<motd>(.+)</motd>')
return md,'Server online'
end

 

:coolface:

 

Em uso:

require('socket')
function check(ip,port)
local c = socket.connect(ip,port)
if not c then
	return false,'Server offline'
end
c:send(string.char(0x06,0x00,0xff,0xff)..'info\n')
local s,cl,d = c:receive(1024)
local status = s or d
status = status:match('<tsqp version="1.0">(.+)</tsqp>')
if not status then
	return false,'No response'
end
local md = {}
for name,inside in status:gmatch('<(%l+) (.-)/>') do
	if not md[name] then
		md[name] = {}
	end
	for v,inf in inside:gmatch('(%l+)%s*=%s*"(.-)"') do
		md[name][v] = inf
	end
end
md['motd'] = {}
md['motd'][1] = status:match('<motd>(.+)</motd>')
return md,'Server online'
end
local data,returned = check('localhost',7171)
print(returned)
if data then
for i,b in pairs(data) do
	for a,k in pairs( do
		print(i,'=>',a,k)
	end
end
end

>lua -e "io.stdout:setvbuf 'no'" "check.lua"

Server online

players => max 1000

players => online 1

players => peak 5

motd => 1 -----

npcs => total 236

monsters => total 29416

owner => name Team

owner => email [email protected]

map => height 36000

map => author (oi)

map => name semnome.otbm

map => width 36000

serverinfo => ip (segredo)

serverinfo => servername Chaos World

serverinfo => port 7171

serverinfo => version 0.4_DEV

serverinfo => client 8.57

serverinfo => location All World

serverinfo => url http://qqqqqqqqqqqqqqq.com.br

serverinfo => uptime 3027526

serverinfo => server Q

>Exit code: 0

Edited by Mickfern

Share this post


Link to post
Share on other sites
Notorious    1
Notorious

Hehe muito bom

Só podia colocar as tags de

 pra ficar mais bonitinho :coolface:

Share this post


Link to post
Share on other sites
Dartier    0
Dartier

Fiz um igual a um tempinho, mas só retorna se tá offline ou online uhaeuae:

 

require 'socket'

 

local config = {

ip = 'dartierotserver.servegame.com',

port = 7171

}

 

while true do

local check = socket.connect(config.ip,config.port)

if check then

print("["..os.date('%H:%M:%S').."] "..config.ip.." are online.")

else

print("["..os.date('%H:%M:%S').."] "..config.ip.." are offline.")

end

end

Dai tipo esse aí ele fica num loop dizendo o horário e se tá online/offline, se quiserem que ele diga só uma vez tirem o while true do. ;3

Edited by Dartier

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×