Merge pull request #61 from KsaRedFx/develop
Updated mctools.py to read SRV Records
This commit is contained in:
commit
d517130082
3 changed files with 20 additions and 2 deletions
|
@ -98,6 +98,7 @@ Linux packages needed for install: python, python-dev, libenchant-dev, libenchan
|
||||||
CloudBot runs on **Python** *2.7.x*. It is developed on **Ubuntu** *12.04* with **Python** *2.7.3*.
|
CloudBot runs on **Python** *2.7.x*. It is developed on **Ubuntu** *12.04* with **Python** *2.7.3*.
|
||||||
|
|
||||||
It **requires the Python module** `lXML`, and `Enchant` is needed for the spellcheck plugin.
|
It **requires the Python module** `lXML`, and `Enchant` is needed for the spellcheck plugin.
|
||||||
|
It also **requires** `pydns` and is needed for SRV record lookup for the mctools plugin.
|
||||||
|
|
||||||
The programs `daemon` or `screen` are recomended for the launcher to run optimaly.
|
The programs `daemon` or `screen` are recomended for the launcher to run optimaly.
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from util import hook, http
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
import struct
|
import struct
|
||||||
|
import DNS ## Please remember to install the dependancy 'pydns'
|
||||||
|
|
||||||
def mccolorconvert(motd):
|
def mccolorconvert(motd):
|
||||||
empty = ""
|
empty = ""
|
||||||
|
@ -42,6 +43,15 @@ def mcping_connect(host, port):
|
||||||
return "Error pinging " + host + ":" + str(port) +\
|
return "Error pinging " + host + ":" + str(port) +\
|
||||||
", is it up? Double-check your address!"
|
", is it up? Double-check your address!"
|
||||||
|
|
||||||
|
def srvData(domain):
|
||||||
|
DNS.ParseResolvConf()
|
||||||
|
srv_req = DNS.Request(qtype = 'srv')
|
||||||
|
srv_result = srv_req.req('_minecraft._tcp.%s' % domain)
|
||||||
|
|
||||||
|
for getsrv in srv_result.answers:
|
||||||
|
if getsrv['typename'] == 'SRV':
|
||||||
|
data = [getsrv['data'][2],getsrv['data'][3]]
|
||||||
|
return data
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def mclogin(inp, bot=None):
|
def mclogin(inp, bot=None):
|
||||||
|
@ -106,6 +116,7 @@ def mcping(inp):
|
||||||
"mcping <server>[:port] - Ping a Minecraft server to check status."
|
"mcping <server>[:port] - Ping a Minecraft server to check status."
|
||||||
inp = inp.strip().split(" ")[0]
|
inp = inp.strip().split(" ")[0]
|
||||||
|
|
||||||
|
|
||||||
if ":" in inp:
|
if ":" in inp:
|
||||||
host, port = inp.split(":", 1)
|
host, port = inp.split(":", 1)
|
||||||
try:
|
try:
|
||||||
|
@ -113,7 +124,12 @@ def mcping(inp):
|
||||||
except:
|
except:
|
||||||
return "error: invalid port!"
|
return "error: invalid port!"
|
||||||
else:
|
else:
|
||||||
host = inp
|
try:
|
||||||
port = 25565
|
getdata = srvData(inp)
|
||||||
|
host = str(getdata[1])
|
||||||
|
port = int(getdata[0])
|
||||||
|
except:
|
||||||
|
host = inp
|
||||||
|
port = 25565
|
||||||
return mccolorconvert(mcping_connect(host, port))
|
return mccolorconvert(mcping_connect(host, port))
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
BeautifulSoup==3.2.1
|
BeautifulSoup==3.2.1
|
||||||
lxml==3.1beta1
|
lxml==3.1beta1
|
||||||
pyenchant==1.6.5
|
pyenchant==1.6.5
|
||||||
|
pydns>=2.3.6
|
||||||
|
|
Reference in a new issue