def sendPlayerPlacement(app, hand: int, location: BlockPos, face: int, cx: float, cy: float, cz: float, insideBlock: bool): if hasattr(app, 'server'): server: ServerState = app.server player: Player = server.getLocalPlayer() blockId = server.getLocalDimension().world.getBlock(location) if blockId == 'crafting_table': windowId = server.getWindowId() kind = util.REGISTRY.encode('minecraft:menu', 'minecraft:crafting') title = Message.from_string('Crafting Table') server.openWindows[windowId] = Window(player.entityId, location, 'crafting') network.s2cQueue.put(network.OpenWindowS2C(windowId, kind, title)) syncWindowSlots(server, windowId) elif blockId == 'furnace': windowId = server.getWindowId() kind = util.REGISTRY.encode('minecraft:menu', 'minecraft:furnace') title = Message.from_string('Furnace') server.openWindows[windowId] = Window(player.entityId, location, 'furnace') network.s2cQueue.put(network.OpenWindowS2C(windowId, kind, title)) syncWindowSlots(server, windowId) elif not player.creative and blockId == 'air': stack = player.inventory[player.hotbarIdx].stack if not stack.isInfinite(): stack.amount -= 1 else: network.c2sQueue.put( network.PlayerPlacementC2S(hand, location, face, cx, cy, cz, insideBlock))
def status_response(self, data): self.close() detected_version = int(data["version"]["protocol"]) if detected_version in self.factory.minecraft_versions: self.factory.detected_protocol_version.callback(detected_version) else: message = "Unsupported protocol version (%d)" % detected_version if 'description' in data: motd = Message(data['description']) message = "%s: %s" % (message, motd.to_string()) self.factory.detected_protocol_version.errback( failure.Failure(ProtocolError(message)))
def send_title(self): if self.protocol_version >= 755: # 1.17+ self.send_packet("set_title_text", self.buff_type.pack_chat(Message(Text.MC_LINK))) self.send_packet("set_title_subtitle", self.buff_type.pack_chat(Message(Text.LOOK_AT_CHAT))) else: self.send_packet("title", self.buff_type.pack_varint(0), self.buff_type.pack_chat(Message(Text.MC_LINK))) self.send_packet("title", self.buff_type.pack_varint(1), self.buff_type.pack_chat(Message(Text.LOOK_AT_CHAT)))
def send_countdown_title(self): self.send_packet("title", self.buff_type.pack_varint(0), self.buff_type.pack_chat(Message({"text": self.countdown}))) self.countdown -= 1 if self.countdown <= 0: self.send_to_main()
def start_send_to_main(self): self.ticker.remove(self.title_tick) self.countdown = 10 self.send_countdown_title() self.send_packet("title", self.buff_type.pack_varint(1), self.buff_type.pack_chat(Message(Text.SEND_TO_MAIN))) self.ticker.add_loop(20, self.send_countdown_title)
(u'lvl', TagShort(4))))) ]) }) }) }, # hmm b'\x01\x14' # ID b'\x01' # Count b'\x0A\x00\x00\x09\x00\x04ench\n\x00\x00\x00\x01' # NBT container start b'\x02\x00\x02id\x00\x10' # Enchantment type b'\x02\x00\x03lvl\x00\x04' # Enchantment level b'\x00\x00'), # NBT container end ] entity_metadata_vectors = [ (OrderedDict( (((0, 0), 0), ((1, 1), 1), ((2, 2), 2.0), ((3, 3), u'three'), ((4, 4), Message({'text': u'four'})), ((5, 5), Message({'text': u'five'})), ((6, 6), { 'count': 1, 'item': 267, 'tag': TagRoot({}) }), ((7, 7), True), ((8, 8), (7.699999809265137, 7.699999809265137, 7.699999809265137)), ((9, 9), (8, 8, 8)), ((10, 10), (9, 9, 9)), ((11, 11), 10), ((12, 12), UUID.from_bytes(uuid_vector)), ((13, 13), 12), ((14, 14), TagRoot({u'foo': TagString(u'bar')})))), b'\x00\x00\x00' b'\x01\x01\x01' b'\x02\x02\x40\x00\x00\x00' b'\x03\x03\x05three'
def player_joined(self): # Call super. This switches us to "play" mode, marks the player as # in-game, and does some logging. ServerProtocol.player_joined(self) # Build up fields for "Join Game" packet entity_id = 0 max_players = 0 hashed_seed = 42 view_distance = 2 simulation_distance = 2 game_mode = 3 prev_game_mode = 3 is_hardcore = False is_respawn_screen = True is_reduced_debug = True is_debug = False is_flat = True dimension_count = 1 dimension_name = "mclink" dimension_type = dimension_types[self.protocol_version, "minecraft:the_end"] data_pack = data_packs[self.protocol_version] join_game = [ self.buff_type.pack("i?BB", entity_id, is_hardcore, game_mode, prev_game_mode), self.buff_type.pack_varint(dimension_count), # world count self.buff_type.pack_string(dimension_name), # world name(s) self.buff_type.pack_nbt(data_pack), # dimension registry self.buff_type.pack_nbt(dimension_type), # dimension self.buff_type.pack_string(dimension_name), # world name self.buff_type.pack("q", hashed_seed), # hashed seed self.buff_type.pack_varint(max_players), # max players (unused) self.buff_type.pack_varint(view_distance), # view distance ] if self.protocol_version >= 757: # 1.18 join_game.append(self.buff_type.pack_varint(simulation_distance)) # Send "Join Game" packet self.send_packet( "join_game", *join_game, self.buff_type.pack("????", is_reduced_debug, is_respawn_screen, is_debug, is_flat)) self.send_packet("plugin_message", self.buff_type.pack_string("minecraft:brand"), self.buff_type.pack_string("MCLink")) pos_look = [ self.buff_type.pack("dddff?", 0, # x 255, # y 0, # z 0, # yaw 0, # pitch 0b00000), # flags self.buff_type.pack_varint(0) # teleport id ] if self.protocol_version >= 755: # 1.17+ pos_look.append(self.buff_type.pack("?", True)) # Leave vehicle) # Send "Player Position and Look" packet self.send_packet( "player_position_and_look", *pos_look) # Start sending "Keep Alive" packets self.ticker.add_loop(20, self.update_keep_alive) self.send_commands() if self.protocol_version >= 755: # 1.17+ self.send_packet("set_title_time", self.buff_type.pack("iii", 10, 4200, 20)) else: self.send_packet("title", self.buff_type.pack_varint(3), self.buff_type.pack("iii", 10, 4200, 20)) self.send_title() self.title_tick = self.ticker.add_loop(4200, self.send_title) msg = [Text.HEADER] d = send_request("check", {'uuid': self.uuid.to_hex()}) if d['status'] == "denied": msg.append(Text.SETUP) else: self.valid = True msg.append(Text.LOGIN_VERIFIED) self.send_chat(Message(msg))
def packet_chat_message(self, buff): msg = buff.unpack_string() # Handle register commands, email is validated on backend too if msg.startswith("/register"): if msg.endswith("@student.chalmers.se"): d = send_request("register", {'email': msg.split(" ")[-1], 'uuid': self.uuid.to_hex(), 'name': self.display_name}) if 'uuid' in d and d['uuid'][0] == "uuid_taken": if self.valid: self.send_chat(Message(Text.ALREADY_VERIFIED)) else: self.send_chat(Message(Text.VALIDATION_MAIL)) elif 'email' in d: msg = [] for e in d['email']: msg.append({"text": e, "color": "red"}) self.send_chat(Message(intersperse(msg, {"text": "\n "}))) elif 'status' in d and d['status'] == "success": self.send_chat(Message(Text.VALIDATION_MAIL)) else: self.send_chat(Message(Text.UNKNOWN_ERROR)) self.logger.error("Unknown error!") self.logger.error(json.dumps(d, separators=(',', ':'))) else: self.send_chat(Message(Text.INVALID_EMAIL)) # Handle verify commands elif msg.startswith("/verify"): parts = msg.split(" ") if len(parts) == 2: d = send_request("verify", {'token': parts[1], 'uuid': self.uuid.to_hex()}) if 'status' in d and d['status'] == 'success': self.send_chat(Message(Text.VERIFICATION_DONE)) self.send_sound("entity.firework_rocket.launch") time.sleep(0.2) self.send_sound("entity.firework_rocket.blast") self.send_sound("entity.firework_rocket.blast_far") time.sleep(0.1) self.send_sound("entity.firework_rocket.large_blast") self.send_sound("entity.firework_rocket.twinkle_far") time.sleep(0.2) self.send_sound("ui.toast.challenge_complete") self.valid = True # self.start_send_to_main() elif 'status' in d and d['status'] == 'done': self.send_chat(Message(Text.ALREADY_VERIFIED)) else: self.send_chat(Message(Text.INVALID_VERIFY_CODE)) else: self.send_chat(Message(Text.INVALID_VERIFY_COMMAND)) # Let the users unregister them self elif msg.startswith("/unregister"): send_request("unregister", {'uuid': self.uuid.to_hex()}) self.send_chat(Message(Text.UNREGISTERED)) self.valid = False # Show help for the commands elif msg.startswith("/help"): self.send_chat(Message(Text.HELP)) else: self.send_chat(Message(Text.UNKNOWN_COMMAND))
def update_music(self, create=False): if not self.song_start: self.song_start = datetime.now() percent = (datetime.now() - self.song_start).seconds / ((2 * 60) + 32) if create: self.music_bar_uuid = UUID.random() self.send_packet( "boss_bar", self.buff_type.pack_uuid(self.music_bar_uuid), self.buff_type.pack_varint(0), self.buff_type.pack_chat( Message({ "text": "Server is loading -- Playing Stal by C418", "color": "bold", })), self.buff_type.pack("f", percent), self.buff_type.pack_varint(1), self.buff_type.pack_varint(0), self.buff_type.pack("B", 0b00000), ) # Play "Stal" by C418 self.send_packet( "sound_effect", self.buff_type.pack_varint(474), self.buff_type.pack_varint(2), self.buff_type.pack( "iiiff", int(default_pos[0] * 8), int(default_pos[1] * 8), int(default_pos[2] * 8), 1, 1, ), ) # teleport id elif self.playing_music: if percent > 1: self.send_packet( "boss_bar", self.buff_type.pack_uuid(self.music_bar_uuid), self.buff_type.pack_varint(2), self.buff_type.pack("f", 1), ) self.send_packet( "boss_bar", self.buff_type.pack_uuid(self.music_bar_uuid), self.buff_type.pack_varint(3), self.buff_type.pack_chat( Message({ "text": "Server is still loading -- hang tight!", "color": "bold", })), ) self.playing_music = False return self.send_packet( "boss_bar", self.buff_type.pack_uuid(self.music_bar_uuid), self.buff_type.pack_varint(2), self.buff_type.pack("f", percent), )