Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- # Copyright (c) 2012, Alfie "Azelphur" Day
- # All rights reserved.
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions are met:
- #
- # * Redistributions of source code must retain the above copyright notice,
- # this list of conditions, and the following disclaimer.
- # * Redistributions in binary form must reproduce the above copyright notice,
- # this list of conditions, and the following disclaimer in the
- # documentation and/or other materials provided with the distribution.
- # * Neither the name of the author of this software nor the name of
- # contributors to this software may be used to endorse or promote products
- # derived from this software without specific prior written consent.
- #
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- # POSSIBILITY OF SUCH DAMAGE.
- ###
- import supybot.utils as utils
- from supybot.commands import *
- import supybot.plugins as plugins
- import supybot.ircutils as ircutils
- import supybot.callbacks as callbacks
- import urllib2, socket
- LOGIN_URL = 'https://login.minecraft.net/?user=&password='
- SESSION_URL = 'http://session.minecraft.net/game/joinserver.jsp'
- MINECRAFT_ADDRESS = 'Minecraft.azelphur.com'
- MINECRAFT_PORT = 25567
- class Minecraft(callbacks.Plugin):
- """Add the help for "@plugin help Minecraft" here
- This should describe *how* to use this plugin."""
- threaded = True
- def mcstatus(self, irc, msg, args):
- login = 'Online'
- session = 'Online'
- server = 'Online'
- try:
- u = urllib2.urlopen(LOGIN_URL)
- if u.read() != 'Bad login':
- login = 'Behaving oddly'
- except urllib2.HTTPError, code:
- login = 'Offline (HTTP Code %d)' % (code)
- except urllib2.URLError, code
- login = 'Offline (Error %d, %s)' % (code[0], code[1])
- try:
- u = urllib2.urlopen(SESSION_URL)
- if u.read() != 'Bad login':
- session = 'Behaving oddly'
- except urllib2.HTTPError, code:
- session = 'Offline (HTTP Code %d)' % (code)
- except urllib2.URLError, code
- session = 'Offline (Error %d, %s)' % (code[0], code[1])
- try:
- #Set up our socket
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((MINECRAFT_ADDRESS, MINECRAFT_PORT))
- #Send 0xFE: Server list ping
- s.send('\xfe')
- #Read as much data as we can (max packet size: 241 bytes)
- d = s.recv(256)
- s.close()
- #Check we've got a 0xFF Disconnect
- assert d[0] == '\xff'
- #Remove the packet ident (0xFF) and the short containing the length of the string
- #Decode UCS-2 string
- #Split into list
- d = d[3:].decode('utf-16be').split(u'\xa7')
- server = 'Online, %d / %d' % (int(d[1]), int(d[2]))
- except socket.error:
- server = 'Offline'
- irc.reply("Login: %s, Session: %s, Our server: %s" % (login, session, server))
- Class = Minecraft
- # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement