mcsock.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:YATE 作者: GarethNelson 项目源码 文件源码
def __init__(self,endpoint=None,protocol_version=packets.default_protocol_version,protocol_mode=0,handlers={},display_name='YATEBot'):
       """ endpoint is a tuple of (ip,port) or None - if None, use connect_to() later
           protocol_version is the version of the minecraft protocol to use
           protocol_mode should be 0 at start, but if you're a psycho you can of course set it to ANYTHING you want - think of the possibilities
           handlers maps packet names to handlers that accept the packet data - it's up to the handler to decode the packet at present
           display_name is what it sounds like
           despite this thing being in eventlet, it's pretty much blocking - because notch owes me now, also it's a TCP socket and there's probably ordering issues
       """
       self.endpoint              = endpoint
       self.protocol_version      = protocol_version
       self.protocol_mode         = protocol_mode
       self.display_name          = display_name
       self.compression_threshold = 0
       self.compression_enabled   = False

       self.handlers = {'login_set_compression':self.handle_login_set_compression,
                        'keep_alive':           self.handle_keep_alive,
                        'set_compression':      self.handle_set_compression}
       self.handlers.update(handlers)
       self.cipher   = crypto.Cipher()
       self.pool     = eventlet.GreenPool(1000)

       self.ready             = False
       self.blocking_handlers = False # if set to True, packet handlers will be invoked by the reader thread

       for k,v in packets.packet_idents.items():
           if k[0]==self.protocol_version:
              setattr(self,'send_%s' % k[3],MCSendMethod(k[3],self))
       if endpoint != None:
          self.connect_to(endpoint)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号