Exemple #1
0
 def handle_session_auth(self, event_id, packet):
     # Server ID is blank for Notchian servers, but some custom servers sitll
     # use it
     sev_id = packet.serverId.encode('ascii')
     digest = sha1(sev_id + self.io.shared_secret +
                   packet.publicKey).digest()
     data = json.dumps({
         'accessToken':
         self.core.ygg.access_token,
         'selectedProfile':
         self.core.ygg.selected_profile['id'],
         'serverId':
         format(int.from_bytes(digest, 'big', signed=True), 'x')
     }).encode('utf-8')
     url = 'https://sessionserver.mojang.com/session/minecraft/join'
     req = request.Request(url, data, {'Content-Type': 'application/json'})
     try:
         rep = request.urlopen(req, timeout=self.auth_timeout)
         rep = rep.read().decode('utf-8')
     except error.URLError:
         rep = "Couldn't connect to sessionserver.mojang.com"
     if rep:
         logger.warning(rep)
     else:
         logger.info("Successful Session Auth")
         self.event.emit(self.session_auth, packet,
                         "mcd::ClientboundEncryptionBegin *")
Exemple #2
0
 def login(self):
   if not self.online_mode:
     self._username = self.ygg.username
     return True
   if self.ygg.login():
     self._username = self.ygg.selected_profile['name']
     logger.info(f"Successful Login, username is: {self._username}")
     self.event.emit(self.login_success)
     return True
   self.event.emit(self.login_error)
  def handle_incoming_chat(self, event_id, packet):
    # Riker provides its own logging facilities, the interface is similar to
    # the Python logging module
    logger.info(f"Received Message: {packet.message}")

    # Packets have no useful methods, they are just collections of fields to be
    # filled and then sent to I/O. Typically only lower level plugins should
    # be dealing with raw packets, but for this Example it's convenient to
    # illustrate the capability.
    response = proto.ServerboundChat()

    # The fields of packets are named based on the Minecraft Data naming
    # conventions.
    response.message = self.core.greeting_string

    self.io.encode_packet(response)

    # Events with no data will be emitted to Python and C++ plugins with the
    # data field of their callbacks filled with None/nullptr. When a PyObject
    # is emitted as data, it will be emitted in its native form unless a
    # TypeQuery string is provided to convert it to a C/C++ object. That is
    # advanced usage that you don't usually need to worry about though.
    self.event.emit(self.greeting_sent)