Code Monkey home page Code Monkey logo

Comments (2)

ctian1 avatar ctian1 commented on July 28, 2024

Actually, I tried to turn the Proxy into offline mode, then I created a profile in a new QuietUpstreamFactory instead of in QuietBridge, and now I get this:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\twisted\python\log.py", line 101, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "C:\Python34\lib\site-packages\twisted\python\log.py", line 84, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "C:\Python34\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "C:\Python34\lib\site-packages\twisted\python\context.py", line 81, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "C:\Python34\lib\site-packages\twisted\internet\selectreactor.py", line 149, in _doReadOrWrite
    why = getattr(selectable, method)()
  File "C:\Python34\lib\site-packages\twisted\internet\tcp.py", line 209, in doRead
    return self._dataReceived(data)
  File "C:\Python34\lib\site-packages\twisted\internet\tcp.py", line 215, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "C:\Python34\lib\site-packages\quarry\net\protocol.py", line 98, in dataReceived
    return self.data_received(data)
  File "C:\Python34\lib\site-packages\quarry\net\protocol.py", line 264, in data_received
    self.packet_received(packet_buff, name)
  File "C:\Python34\lib\site-packages\quarry\net\protocol.py", line 284, in packet_received
    dispatched = self.dispatch((name,), buff)
  File "C:\Python34\lib\site-packages\quarry\net\protocol.py", line 28, in dispatch
    handler(buff)
  File "C:\Python34\lib\site-packages\quarry\net\server.py", line 151, in packet_login_start
    self.uuid = types.UUID.from_offline_player(self.username)
  File "C:\Python34\lib\site-packages\quarry\util\types.py", line 16, in from_offline_player
    base_uuid = uuid.uuid3(FakeNamespace(), username)
  File "C:\Python34\lib\uuid.py", line 561, in uuid3
    hash = md5(namespace.bytes + bytes(name, "utf-8")).digest()
builtins.TypeError: Can't convert 'bytes' object to str implicitly

probably because of python 3.

from quarry.

ctian1 avatar ctian1 commented on July 28, 2024

Here's my changed proxy.py:

"""
"Quiet mode" example proxy

Allows a client to turn on "quiet mode" which hides chat messages
"""

from quarry.net.proxy import UpstreamFactory, DownstreamFactory, Bridge
from quarry.mojang.profile import Profile
import getpass


class QuietBridge(Bridge):
    quiet_mode = False

    def packet_upstream_chat_message(self, buff):
        buff.save()
        chat_message = self.read_chat(buff, "upstream")
        self.logger.info(" >> %s" % chat_message)

        if chat_message.startswith("/quiet"):
            # Switch mode
            self.quiet_mode = not self.quiet_mode

            action = self.quiet_mode and "enabled" or "disabled"
            msg = "Quiet mode %s" % action
            self.downstream.send_packet("chat_message",
                                        self.write_chat(msg, "downstream"))

        elif self.quiet_mode and not chat_message.startswith("/"):
            # Don't let the player send chat messages in quiet mode
            msg = "Can't send messages while in quiet mode"
            self.downstream.send_packet("chat_message",
                                        self.write_chat(msg, "downstream"))

        else:
            # Pass to upstream
            buff.restore()
            self.upstream.send_packet("chat_message", buff.read())

    def packet_downstream_chat_message(self, buff):
        chat_message = self.read_chat(buff, "downstream")
        self.logger.info(" :: %s" % chat_message)

        if self.quiet_mode and chat_message.startswith("<"):
            # Ignore message we're in quiet mode and it looks like chat
            pass

        else:
            # Pass to downstream
            buff.restore()
            self.downstream.send_packet("chat_message", buff.read())

    def read_chat(self, buff, direction):
        buff.save()
        if direction == "upstream":
            p_text = buff.unpack_string()
            return p_text
        elif direction == "downstream":
            p_text = buff.unpack_chat()

            # 1.7.x
            if self.upstream.protocol_version <= 5:
                p_position = 0

            # 1.8.x
            else:
                p_position = buff.unpack('B')

            if p_position in (0, 1):
                return p_text

    def write_chat(self, text, direction):
        if direction == "upstream":
            return self.buff_type.pack_string(text)
        elif direction == "downstream":
            data = self.buff_type.pack_chat(text)

            # 1.7.x
            if self.downstream.protocol_version <= 5:
                pass

            # 1.8.x
            else:
                data += self.buff_type.pack('B', 0)

            return data

class QuietUpstreamFactory(UpstreamFactory):
    profile = Profile()
    profile.username = "MyUsername"
    profile.login("[email protected]", getpass.getpass())

class QuietDownstreamFactory(DownstreamFactory):
    bridge_class = QuietBridge
    upstream_factory_class = QuietUpstreamFactory
    motd = "Proxy Server"
    online_mode = False


def main(args):
    # Parse options
    import optparse
    parser = optparse.OptionParser(
        usage="usage: %prog [options] <connect-host> <connect-port>")
    parser.add_option("-a", "--listen-host",
                      dest="listen_host", default="",
                      help="address to listen on")
    parser.add_option("-p", "--listen-port",
                      dest="listen_port", default="25565", type="int",
                      help="port to listen on")
    (options, args) = parser.parse_args(args)

    if len(args) != 2:
        return parser.print_usage()

    # Create factory
    factory = QuietDownstreamFactory()
    factory.motd = "Proxy Server"
    factory.connect_host = args[0]
    factory.connect_port = int(args[1])

    # Listen
    factory.listen(options.listen_host, options.listen_port)
    factory.run()


if __name__ == "__main__":
    import sys
    main(sys.argv[1:])

from quarry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.