示例#1
0
    def player_joined(self):
        global eobj_byid
        ServerProtocol.player_joined(self)

        self.ip = self.remote_addr.host
        self.eid = dats.getFreeId()
        self.fquid = self.username + "[/" + self.ip + "](" + str(self.uuid) + ")"
        eobj_byid[self.eid] = self
        self.logger.info("UUID of player Dragon5232 is " + str(self.uuid))
        
        p.game(self, self.eid, 1, 0, 1, options.maxplayers, "default", False)
        p.spawn_pos(self, 0, 64, 0)
        p.abilities(self, True, True, True, True, 0.2, 0.2)
        p.pos_look(self, 0, 64, 0, 0, 0, False)
        p.rain(self, True)
        p.empty_chunk(self, 0, 0)
        self.logger.info(self.username + "[/" + self.ip + "] logged in with entity id " + str(self.eid) + " at ([nonexistent](0.0, 64.0, 0.0))")
        
        # Schedule 6-second sending of keep-alive packets.
        self.tasks.add_loop(6, self.keepalive_send)
        
        pushChat(eobj_byid, "\u00A7e" + self.username + " has joined the game\u00A7r", 1)
        
        # Send welcome title and subtitle
        p.title(self, options.wtitle)
        p.subtitle(self, options.wst)
        
        p.chat_json(self, dats.join_json(self), 1)
示例#2
0
    def player_joined(self):
        ServerProtocol.player_joined(self)

        # Send "Join Game" packet
        self.send_packet("join_game",
                         self.buff_type.pack("iBqiB",
                                             0,  # entity id
                                             3,  # game mode
                                             0,  # dimension
                                             0,  # hashed seed
                                             0),  # max players
                         self.buff_type.pack_string("flat"),  # level type
                         self.buff_type.pack_varint(32),  # view distance
                         self.buff_type.pack("??",
                                             False,  # reduced debug info
                                             False))  # show respawn screen

        # Send "Player Position and Look" packet
        self.send_packet("player_position_and_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

        # Start sending "Keep Alive" packets
        self.ticker.add_loop(20, self.keep_alive())

        # Announce player joined
        self.factory.send_chat(u"\u00a7e%s has joined." % self.display_name)
示例#3
0
    def player_joined(self):
        Protocol.player_joined(self)
        ServerProtocol.switch_protocol_mode(self, "play")
        self.log = self.factory.log
        self.log.info("User {0}({1}) authorized.".format(
            self.display_name, self.remote_addr.host))

        token = secrets.token_hex(5)
        headers = {"Authorization": "Bearer " + self.factory.token}
        data = {"key": token, "username": self.display_name, "uuid": self.uuid}
        try:
            r = requests.post(self.factory.api, headers=headers, data=data)
            if r.status_code != 200:
                self.factory.log.error(
                    "HTTPS API return status code: {0}".format(r.status_code))
                self.close("Internal Server Error.")
            elif r.status_code == 200:
                self.factory.log.success(
                    "HTTPS API auth request sucess: {0}".format(r.status_code))
            else:
                self.factory.log.info(
                    "HTTPS API return status code: {0}".format(r.status_code))
        except:
            self.factory.log.error("HTTPS API cannot be requested")
            self.close("Internal Server Error.")

        self.close("Your token is: {0}".format(token))
示例#4
0
    def player_joined(self):
        ServerProtocol.player_joined(self)

        self.ip = self.remote_addr.host
        self.eid = dats.getFreeId()
        self.fquid = self.username + "[/" + self.ip + "](" + str(self.uuid) + ")"
        self.base_scba_split = list("PyMINESERVER")
        self.anim_i = 0
        eobj_byid[self.eid] = self
        self.logger.info("UUID of player Dragon5232 is " + str(self.uuid))
        
        p.game(self, self.eid, 1, 0, 1, options.maxplayers, "default", False)
        p.spawn_pos(self, 0, 66, 0)
        p.abilities(self, True, True, True, True, 0.2, 0.2)
        p.pos_look(self, 0, 66, 0, 0, 0, False)
        p.rain(self, True)
        p.empty_chunk(self, 0, 0)
        p.block_change(self, 0, 64, 0, 1)
        if self.protocol_version == 47: p.plist_head_foot(self, u"§6P§2yMINESERVER§r", u"§eEnjoy the Test§r")
        if self.protocol_version == 47: self.tasks.add_loop(1.0/20, self.anim_frame_scb)
        relayPlayerList()
        self.logger.info(self.username + "[/" + self.ip + "] logged in with entity id " + str(self.eid) + " at ([nonexistent](0.0, 64.0, 0.0))")
        
        # Schedule 6-second sending of keep-alive packets.
        self.tasks.add_loop(6, self.keepalive_send)
        
        self.eobj_byid = eobj_byid
        pushChat(self, "\u00A7e" + self.username + " has joined the game\u00A7r", 1)
        
        # Send welcome title and subtitle
        p.title(self, options.wtitle)
        p.subtitle(self, options.wst)
        
        p.chat_json(self, dats.join_json(self), 1)
示例#5
0
    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)

        # Send "Join Game" packet
        self.send_packet("join_game",
            self.buff_type.pack("iBiBB",
                0,                              # entity id
                3,                              # game mode
                0,                              # dimension
                0,                              # max players
                0),                             # unused
            self.buff_type.pack_string("flat"), # level type
            self.buff_type.pack("?", False))    # reduced debug info

        # Send "Player Position and Look" packet
        self.send_packet("player_position_and_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

        # Start sending "Keep Alive" packets
        self.ticker.add_loop(20, self.update_keep_alive)

        # Announce player joined
        self.factory.send_chat(u"\u00a7e%s has joined." % self.display_name)
示例#6
0
    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)

        # Send "Join Game" packet
        self.send_packet("join_game",
            self.buff_type.pack("iBiB",
                0,                              # entity id
                3,                              # game mode
                0,                              # dimension
                0),                             # max players
            self.buff_type.pack_string("flat"), # level type
            self.buff_type.pack_varint(1),      # view distance
            self.buff_type.pack("?", False))    # reduced debug info

        # Send "Player Position and Look" packet
        self.send_packet("player_position_and_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

        # Start sending "Keep Alive" packets
        self.ticker.add_loop(20, self.update_keep_alive)

        # Announce player joined
        self.factory.send_chat(u"\u00a7e%s has joined." % self.display_name)
示例#7
0
 def player_joined(self):
     ServerProtocol.player_joined(self)
     self.ip = self.remote_addr.host
     self.position = Position(0, 66, 0)
     self.entity_id = self.get_free_id()
     self.default_gamemode = 1  # 0: Survival, 1: Creative, 2: Adventure, 3: Spectator. Bit 3 (0x8) is the hardcore flag.
     self.dimension = 0  # -1: Nether, 0:Overworld, 1:End
     self.difficulty = 0  # 0:peaceful,1:easy,2:normal,3:hard
     self.level_type = "default"  # default, flat, largeBiomes, amplified, default_1_1
     self.reduced_debug_info = False  # If true, a Notchian client shows reduced information on the debug screen.
     players[
         self.
         entity_id] = self  # add player object to dict eid:player , so we can iterate over ALL players on the server
     self.logger.info("UUID of player {0} is {1}".format(
         self.username, self.uuid))
     self.nickname = self.username
     self.send_game(self.entity_id, self.default_gamemode, self.dimension,
                    self.difficulty, "default", False)
     self.send_spawn_pos(self.position)
     self.send_abilities(True, True, True, True, 0.2, 0.2)
     self.send_position_and_look(self.position, 0, 0, False)
     self.send_empty_chunk(0, 0)
     self.logger.info("{0} ({1}) logged in with entity id {2}".format(
         self.username, self.ip, self.entity_id) + " at ((0.0, 64.0, 0.0))")
     # Schedule 6-second sending of keep-alive packets.
     self.tasks.add_loop(1, self.keepalive_send)
     self.send_chat_json(serverdata.join_json(self),
                         1)  # Print welcome message
     self.plugin_event("player_join")
示例#8
0
    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
        game_mode = 3
        prev_game_mode = 3
        is_hardcore = False
        is_respawn_screen = True
        is_reduced_debug = False
        is_debug = False
        is_flat = False
        dimension_count = 1
        dimension_name = "chat"
        dimension_type = dimension_types[self.protocol_version,
                                         "minecraft:overworld"]
        data_pack = data_packs[self.protocol_version]

        # Send "Join Game" packet
        self.send_packet(
            "join_game",
            self.buff_type.pack("i?BB", entity_id, is_hardcore, game_mode,
                                prev_game_mode),
            self.buff_type.pack_varint(dimension_count),
            self.buff_type.pack_string(dimension_name),
            self.buff_type.pack_nbt(data_pack),
            self.buff_type.pack_nbt(dimension_type),
            self.buff_type.pack_string(dimension_name),
            self.buff_type.pack("q", hashed_seed),
            self.buff_type.pack_varint(max_players),
            self.buff_type.pack_varint(view_distance),
            self.buff_type.pack("????", is_reduced_debug, is_respawn_screen,
                                is_debug, is_flat))

        # Send "Player Position and Look" packet
        self.send_packet(
            "player_position_and_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

        # Start sending "Keep Alive" packets
        self.ticker.add_loop(20, self.update_keep_alive)

        # Announce player joined
        self.factory.send_chat(u"\u00a7e%s has joined." % self.display_name)
示例#9
0
文件: server.py 项目: wgaylord/PyMine
    def player_joined(self):

        ServerProtocol.player_joined(self)

        location = self.factory.world.spawn
        look = (0, 0)

        if self.display_name in self.factory.world.players:
            self.eid = self.factory.world.load(self.uuid)  #Load and save eid
        else:
            self.eid = self.factory.world.add_entity(self.factory.world.spawn,
                                                     (0, 0), 'Player',
                                                     self.display_name,
                                                     self.uuid, None)
            # Send "Join Game" packet
        self.send_packet(
            "join_game",
            self.buff_type.pack(
                "iBiBB",
                self.eid,  # entity id
                1,  # game mode
                0,  # dimension
                0,  # difficulty
                10),  # max players
            self.buff_type.pack_string("flat"),  # level type
            self.buff_type.pack("?", False))  # reduced debug info
        self.send_packet(
            "plugin_message",
            self.buff_type.pack_string("MC|Brand") +
            self.buff_type.pack_string("PyMine"))
        spawn = self.factory.world.spawn
        self.send_packet(
            "spawn_position",
            self.buff_type.pack_position(spawn[0], spawn[1], spawn[2]))

        self.send_packet("player_abilities",
                         self.buff_type.pack("?ff", 0b1111, 1.2, 10.0))
        location = self.factory.world.entities[self.eid].location
        look = self.factory.world.entities[self.eid].look
        # Send "Player Position and Look" packet
        self.send_packet(
            "player_position_and_look",
            self.buff_type.pack(
                "dddff?",
                location[0],  # x
                location[1],  # y
                location[2],  # z
                look[0],  # yaw
                look[1],  # pitch
                0b00000),  # flags
            self.buff_type.pack_varint(0))  # teleport id
        self.send_inital_chunks(0, 0)
        self.tasks.add_loop(1.0, self.update_keep_alive)
示例#10
0
    def player_left(self):
        ServerProtocol.player_left(self)

        for player in self.factory.players:
            player.send_packet(
                "player_list_item",
                self.buff_type.pack_varint(4),  # action
                self.buff_type.pack_varint(1),  # count
                self.buff_type.pack_uuid(self.uuid),  # uuid
            )

        # Announce player left
        self.factory.send_chat(u"\u00a7e%s has left." % self.display_name)
示例#11
0
    def packet_login_start(self, buff):
        if self.login_expecting != 0:
            raise ServerProtocol.ProtocolError("Out-of-order login")

        # Run normally if not velocity
        if not self.factory.config.getboolean('velocity'):
            ServerProtocol.packet_login_start(self, buff)

        else:
            self.velocityQueryId = randint(0, 320534324)
            self.send_packet("login_plugin_request",
                             self.buff_type.pack_varint(self.velocityQueryId),
                             self.buff_type.pack_string("velocity:player_info"),
                             self.buff_type.pack("B", 0))
            buff.discard()
示例#12
0
 def player_joined(self):
     ServerProtocol.player_joined(self)
     self.ip = self.remote_addr.host
     self.position = Position(0, 66, 0)
     self.entity_id = self.id
     display_name = self.display_name
     addr = self.remote_addr.host
     self.send_game(0, default_gamemode, default_dimension, max_players,
                    level_type, 10)
     self.send_spawn_pos(self.position)
     self.send_abilities(True, True, True, True, 0.2, 0.2)
     self.send_position_and_look(0, 25, 25, 0, 0)
     self.send_error = True
     #self.send_empty_chunk(0, 0)
     self.ticker.add_loop(20, self.update_keep_alive)
     event.SetEvent("on_join", self, display_name, addr)
示例#13
0
    def player_joined(self):
        """
        Player joined
        - on player join, do this
        """
        ServerProtocol.player_joined(self)

        self.send_packet('join_game',
                         self.buff_type.pack('iBiBB', 0, 3, 0, 0, 0),
                         self.buff_type.pack_string('flat'),
                         self.buff_type.pack('?', False))

        self.send_packet(
            'player_position_and_look',
            self.buff_type.pack('dddff?', 0, 255, 0, 0, 0, 0b00000),
            self.buff_type.pack_varint(0))

        self.tasks.add_loop(1.0, self.update_keep_alive)
示例#14
0
    def player_joined(self):
        # This method gets called when a player successfully joins the server.
        #   If we're in online mode (the default), this means auth with the
        #   session server was successful and the user definitely owns the
        #   display name they claim to.

        # Call super. This switches us to "play" mode, marks the player as
        #   in-game, and does some logging.
        ServerProtocol.player_joined(self)

        # Define your own logic here. It could be an HTTP request to an API,
        #   or perhaps an update to a database table.
        display_name = self.display_name
        ip_addr = self.remote_addr.host
        self.logger.info("[%s authed with IP %s]" % (display_name, ip_addr))

        # Kick the player.
        self.close("Thanks, you are now registered!")
示例#15
0
    def player_joined(self):
        # This method gets called when a player successfully joins the server.
        #   If we're in online mode (the default), this means auth with the
        #   session server was successful and the user definitely owns the
        #   display name they claim to.

        # Call super. This switches us to "play" mode, marks the player as
        #   in-game, and does some logging.
        ServerProtocol.player_joined(self)

        # Define your own logic here. It could be an HTTP request to an API,
        #   or perhaps an update to a database table.
        display_name = self.display_name
        ip_addr = self.remote_addr.host
        self.logger.info("[%s authed with IP %s]" % (display_name, ip_addr))

        # Kick the player.
        self.close("Thanks, you are now registered!")
    def player_joined(self):
        global con
        # This method gets called when a player successfully joins the server.
        #   If we're in online mode (the default), this means auth with the
        #   session server was successful and the user definitely owns the
        #   display name they claim to.

        # Call super. This switches us to "play" mode, marks the player as
        #   in-game, and does some logging.
        ServerProtocol.player_joined(self)
        id = self.uuid.to_hex(with_dashes=False)

        cur = con.cursor()

        try:
            cur.execute('SELECT pin FROM auths where minecraft_uuid=%s;', [id])
            pin = cur.fetchone()
            print(pin)
            if not pin:
                pin = randint(1000, 9999)
                cur.execute('SELECT pin FROM auths where pin=%s;', [pin])
                res = cur.fetchone()
                while res:
                    pin = randint(1000, 9999)
                    cur.execute('SELECT pin FROM auths where pin=%s;', [pin])
                    res = cur.fetchone()

                cur.execute('INSERT INTO auths (minecraft_uuid, pin) VALUES (%s, %s);', (str(id), str(pin)))
                con.commit()
            else:
                pin = pin[0]

            # Kick the player.
            self.close(f"Send command to Curator bot: ,auth {pin}")
        except Exception as e:
            print(e)
            self.close('No')
示例#17
0
    def player_joined(self):
        # This method gets called when a player successfully joins the server.
        #   If we're in online mode (the default), this means auth with the
        #   session server was successful and the user definitely owns the
        #   username they claim to.

        # Call super. This switches us to "play" mode, marks the player as
        #   in-game, and does some logging.
        ServerProtocol.player_joined(self)
        authed = "true"
        # Define your own logic here. It could be an HTTP request to an API,
        #   or perhaps an update to a database table.
        username = self.username
        uuid = self.uuid
        ip_addr = self.recv_addr.host
        self.logger.info("[%s (%s) authed with IP %s]" %
                         (username, uuid, ip_addr))

        # MYSQL Here
        db = MySQLdb.connect(host="localhost",
                             user="******",
                             passwd="pass",
                             db="database")
        user = db.cursor()
        verified = db.cursor()
        hours = db.cursor()
        ip = db.cursor()
        full = db.cursor()

        if authed == "true":
            print " --> OK!"
            user.execute("SELECT * FROM wp_auth_players where username = '******'")
            ip.execute("SELECT * FROM wp_auth_players where username = '******' and address <> '" + ip_addr + "'")
            verified.execute(
                "SELECT * FROM wp_auth_players where username = '******' and verified = 1")
            #hours.execute("SELECT * FROM wp_auth_players where username = '******' and time < DATE_ADD(NOW(), INTERVAL 1 HOUR)")
            full.execute("SELECT * FROM wp_auth_players where username = '******' and address = '" + ip_addr +
                         "' and verified = 0")
            print "Found %s entries" % full.rowcount
            if full.rowcount == 1:
                sql = "UPDATE wp_auth_players SET verified = '1' where username = '******' and address = '" + client_addr + "' and verified = '0'"
                try:
                    full.execute(sql)
                    db.commit()
                except:
                    db.rollback()
                print "The user has been verified"
                message = u"\u00A7eGood to see you own this account \u00A76" + username + u"\u00A7e!\n \u00A7eNow just click \u00A76Next\u00A7e on the website!"
            elif user.rowcount == 0:
                print "The user has NOT been verified (doesn't exist)"
                message = u"\u00A7eSorry \u00A76" + username + u"\u00A7e, apparently you haven't tried registering yet!\nVisit " + SITE_URL + "to begin the process."
            elif ip.rowcount == 1:
                print "The user has NOT been verified (different ip)"
                message = u"\u00A7eSorry \u00A76" + username + u"\u00A7e, it looks like you're connecting from a different IP!\nIf this is incorrect, contact a staff member."
            elif verified.rowcount == 1:
                print "The user is already verified"
                message = u"\u00A7eHold on \u00A76" + username + u"\u00A7e, it looks like you've already been authenticated!\nIf this is incorrect, contact a staff member."
            #elif hours.rowcount == 1: # this will be done soon!
            #    print "The user has NOT been verified (too late)"
            #    return u"\u00A7eSorry \u00A76" + username + u"\u00A7e, it looks like you've taken too long!\nTry again tomorrow, without waiting over an hour."
            else:
                print "Overall else"
                message = u"\u00A7eWhoops, something went horribly wrong. Contact WizardCM!"
            db.close()
        else:
            print " --> FAILED!"
            message = u"\u00A74Are you sure you own this account (" + username + u")? Try restarting your game!\n(this doesn't actually do anything yet, but it will!)"

        # Kick the player.
        self.close(message)
示例#18
0
    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)

        if self.protocol_version > 578:  # Minecraft 1.16.1
            # Send "Join Game" packet
            dim_name = "minecraft:the_end"
            dim_codec = TagRoot({
                '': TagCompound({
                    "dimension": TagList([
                        TagCompound({
                            "name"                : TagString(dim_name),
                            "natural"             : TagByte(0),
                            "ambient_light"       : TagFloat(0.0),
                            "has_ceiling"         : TagByte(0),
                            "has_skylight"        : TagByte(0),
                            "fixed_time"          : TagLong(6000),
                            "shrunk"              : TagByte(0),
                            "ultrawarm"           : TagByte(0),
                            "has_raids"           : TagByte(1),
                            "respawn_anchor_works": TagByte(0),
                            "bed_works"           : TagByte(0),
                            "piglin_safe"         : TagByte(0),
                            "logical_height"      : TagInt(256),
                            "infiniburn"          : TagString("minecraft:infiniburn_end"),
                        }),
                    ])
                })
            })
            self.send_packet("join_game",
                             self.buff_type.pack("iBB", 0, 3, 3),                   # entity id, game mode, previous game mode
                             self.buff_type.pack_varint(1),                         # world count
                             self.buff_type.pack_string(dim_name),                  # world name(s)
                             self.buff_type.pack_nbt(dim_codec),                    # dimension registry
                             self.buff_type.pack_string(dim_name),                  # dimension
                             self.buff_type.pack_string(dim_name),                  # world name
                             self.buff_type.pack("qB", 42, 0),                      # hashed seed, max players (unused)
                             self.buff_type.pack_varint(2),                         # view distance
                             self.buff_type.pack("????", True, True, False, True))  # respawn screen, debug world, flat world
        else:  # Minecraft 1.15
            # Send "Join Game" packet
            self.send_packet("join_game",
                self.buff_type.pack("iBiqB",
                    0,                              # entity id
                    3,                              # game mode
                    0,                              # dimension
                    0,                              # hashed seed
                    0),                             # max players
                self.buff_type.pack_string("flat"), # level type
                self.buff_type.pack_varint(1),      # view distance
                self.buff_type.pack("??",
                    False,                          # reduced debug info
                    True))                          # show respawn screen

        # Send "Player Position and Look" packet
        self.send_packet("player_position_and_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

        # Start sending "Keep Alive" packets
        self.ticker.add_loop(20, self.update_keep_alive)

        # Announce player joined
        self.factory.send_chat(u"\u00a7e%s has joined." % self.display_name)
示例#19
0
    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)
        print(self.protocol_version)

        # Send "Join Game" packet
        dim_name = "minecraft:the_end"

        if self.protocol_version > 736:  # Minecraft 1.16.2
            # Send "Join Game" packet
            biome_codec = TagCompound({
                "type":
                TagString("minecraft:worldgen/biome"),
                "value":
                TagList([
                    TagCompound({
                        "name":
                        TagString(
                            "minecraft:plains"
                        ),  # Client crashes if you do not define plains
                        "id":
                        TagInt(1),
                        "element":
                        TagCompound({
                            "precipitation":
                            TagString("none"),
                            "effects":
                            TagCompound({
                                "sky_color": TagInt(0xFFFFFF),
                                "water_fog_color": TagInt(0),
                                "fog_color": TagInt(0xFFFFFF),
                                "water_color": TagInt(0),
                            }),
                            "depth":
                            TagFloat(0.5),
                            "temperature":
                            TagFloat(1),
                            "scale":
                            TagFloat(0.2),
                            "downfall":
                            TagFloat(0.5),
                            "category":
                            TagString("plains"),
                        }),
                    })
                ]),
            })
            dim_settings = TagCompound({
                "natural":
                TagByte(1),
                "ambient_light":
                TagFloat(1.0),
                "has_ceiling":
                TagByte(0),
                "has_skylight":
                TagByte(1),
                "fixed_time":
                TagLong(9000),
                "ultrawarm":
                TagByte(0),
                "has_raids":
                TagByte(0),
                "respawn_anchor_works":
                TagByte(0),
                "bed_works":
                TagByte(0),
                "piglin_safe":
                TagByte(0),
                "logical_height":
                TagInt(256),
                "infiniburn":
                TagString("minecraft:infiniburn_overworld"),
                "coordinate_scale":
                TagFloat(1.0),
            })
            dim_codec = TagRoot({
                "":
                TagCompound({
                    "minecraft:dimension_type":
                    TagCompound({
                        "type":
                        TagString("minecraft:dimension_type"),
                        "value":
                        TagList([
                            TagCompound({
                                "name": TagString(dim_name),
                                "id": TagInt(0),
                                "element": dim_settings,
                            }),
                        ]),
                    }),
                    "minecraft:worldgen/biome":
                    biome_codec,
                })
            })
            current_dim = TagRoot({
                "": dim_settings,
            })

            self.send_packet(
                "join_game",
                self.buff_type.pack(
                    "i?BB", 0, False, 3,
                    3),  # entity id, hardcore, game mode, previous game mode
                self.buff_type.pack_varint(1),  # world count
                self.buff_type.pack_string(dim_name),  # world name(s)
                self.buff_type.pack_nbt(dim_codec),  # dimension registry
                self.buff_type.pack_nbt(current_dim),  # current dimension
                self.buff_type.pack_string(dim_name),  # world name
                self.buff_type.pack("q", 42),  # hashed seed
                self.buff_type.pack_varint(0),  # max players (unused)
                self.buff_type.pack_varint(2),  # view distance
                self.buff_type.pack("????", True, True, False, True),
            )  # respawn screen, debug world, flat world
        # self.send_packet(
        #     "join_game",
        #     self.buff_type.pack(
        #         "i?Bb",
        #         1,  # entity id
        #         False,
        #         2,  # game mode
        #         -1, # previous game mode
        #     ),
        #     self.buff_type.pack_varint(1),  # world count
        #     self.buff_type.pack_string("minecraft:the_end"), # world identifiers
        #     # self.buff_type.pack("qiB", )
        #     self.buff_type.pack_nbt(TagRoot({})), # dimension codec
        #     self.buff_type.pack_nbt(TagRoot({})), # dimension
        #     self.buff_type.pack_string("holdmusic"), # world identifiers
        #     self.buff_type.pack("L", 12345678),
        #     self.buff_type.pack_varint(0),
        #     self.buff_type.pack_varint(3),  # view distance
        #     self.buff_type.pack("????", False, True, False, False),  # reduced debug info
        # )  # show respawn screen

        for x in range(-7, 8):
            for y in range(-7, 8):
                self.send_air_chunk(x, y)

        self.send_air_chunk(1, 1)

        # Send "Player Position and Look" packet
        self.send_packet(
            "player_position_and_look",
            self.buff_type.pack(
                "dddff?",
                *self.pos,
                self.yaw,
                self.pitch,
                0b00000  # x  # y  # z  # yaw  # pitch
            ),  # flags
            self.buff_type.pack_varint(0),
        )  # teleport id

        # Send "Player Abilities" packet
        self.send_packet(
            "player_abilities",
            self.buff_type.pack("bff", 0b01111, 0.2, 0.1),
        )

        # Send "Server Difficulty" packet
        self.send_packet(
            "server_difficulty",
            self.buff_type.pack("B?", 3, False),
        )

        # Send "World Border" packet
        # self.send_packet(
        #     "world_border",
        #     self.buff_type.pack_varint(0),
        #     self.buff_type.pack("d", 100),
        # )

        # Send "Server Difficulty" packet
        # self.send_packet(
        #     "chat_message",
        #     self.buff_type.pack_chat(Message({"text": "Playing Stal -- C418", "color": "red"})) + self.buff_type.pack("B", 0),
        # )

        items: List[Optional[str]] = [[
            "minecraft:firework_rocket"
            if random() > 0.5 else "minecraft:pumpkin",
            int(random() * 127),
            None,
        ] for _ in range(46)]

        items[36] = [
            "minecraft:written_book",
            1,
            TagRoot({
                "":
                TagCompound({
                    "title":
                    TagString("Server Loading"),
                    "author":
                    TagString("Vin Howe"),
                    "pages":
                    TagList([
                        TagString(
                            "This is a dummy server to keep you distracted while the real server starts running. Hang tight!"
                        )
                    ]),
                })
            }),
        ]
        # items[6] = "minecraft:elytra"
        # items[36:45] = ["minecraft:firework_rocket" for _ in range(36, 45)]

        # self.send_packet(
        #     "window_items",
        #     self.buff_type.pack("Bh", 0, 46),
        #     *[self.buff_type.pack_slot(*item) for item in items]
        # )

        # self.send_packet("open_book", self.buff_type.pack_varint(0))

        self.update_music(create=True)

        # for player in self.factory.players:
        #     player.send_packet(
        #         "player_list_item",
        #         self.buff_type.pack_varint(0),  # action
        #         self.buff_type.pack_varint(1),  # count
        #         self.buff_type.pack_uuid(self.uuid),  # uuid
        #         self.buff_type.pack_string(self.display_name),  # name
        #         self.buff_type.pack_varint(
        #             0
        #         ),  # properties count (not really sure what to do with this)
        #         self.buff_type.pack_varint(0),  # gamemode (survival = 0)
        #         self.buff_type.pack_varint(0),  # ping (in ms)
        #         self.buff_type.pack("?", False),  # Has Display Name
        #     )

        # Start sending "Keep Alive" packets
        self.ticker.add_loop(20, self.update_keep_alive)

        self.ticker.add_loop(2, self.send_position_update)
示例#20
0
    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))
示例#21
0
 def packet_login_start(self, buff):
     ServerProtocol.packet_login_start(self, buff)
示例#22
0
 def connection_lost(self, reason=None):
     ServerProtocol.connection_lost(self, reason)
     if self.bridge:
         self.bridge.downstream_disconnected()
示例#23
0
 def packet_login_start(self, buff):
     if not options.down:
         ServerProtocol.packet_login_start(self, buff)
     else:
         buff.discard()
         self.close(options.downmsg)
示例#24
0
    def player_joined(self):
        self.eid = 0
        # Call super. This switches us to "play" mode, marks the player as
        # in-game, and does some logging.
        ServerProtocol.player_joined(self)
    
        # Send "Join Game" packets
        # Send "Player Position and Look" packet
        self.send_packet("join_game",
            self.buff_type.pack("iBiBB",
                self.eid,                              # entity id
                1,                              # game mode
                0,                              # dimension
                0,                              # max players
                0),                             # unused
            self.buff_type.pack_string("flat"), # level type
            self.buff_type.pack("?", False))    # reduced debug info
        
        self.send_packet("player_position_and_look",
            self.buff_type.pack("dddff?",
                0,                         # x
                101,                       # y
                0,                         # z
                0,                         # yaw
                90,                         # pitch
                0b00000),                  # flags
            self.buff_type.pack_varint(0)) # teleport id
        self.isProtocol = True
        self.logger.setLevel(self.factory.level)
        self.username_ = self.display_name
        self.bt = self.buff_type
        self.pk = self.buff_type.pack
        self.send_chat('hi')
        self.xr = self.yr = 0   
        self.on_ground = False
            # set world
        self.factory.w[0].add_players(self)
        self.position = (0,255,0)
        self.plugin_event('pre_player_joined') # tell plugins that the player joined
        # start ticking 
        loop = task.LoopingCall(self.plugin_event,'tick')
        loopDeferred = loop.start(0.05)
        # send 7x7 chunks  around the player
        #for i in range(-3,3):
        #    for j in range(-3,3):
        #        self.send_empty_chunk(i,j)

        
      
        # make a small parkour
        self.x,self.y,self.z = (0,101,0)
        #self.send_packet('entity',self.bt.pack_varint(123))
        #self.send_mob(123,40,90,(0,101,0),0,0,0) # spawn a pig for testing purposes
        #print("Player %s has the following permissions: "%self.display_name,*self.factory.c.listPermissions(self.display_name))
        # Start sending "Keep Alive" packets
        self.ticker.add_loop(20, self.update_keep_alive)
        self.f = self.factory
        self.inv = {}
        self.hand = 0 # int from 0 to 8 
        self.flying = False
        self.world.post_play_add(self)
        self.plugin_event('player_joined')
        # Announce player joined
        self.factory.send_chat(u"\u00a7e%s has joined." % self.display_name)
示例#25
0
    def player_joined(self):
        ServerProtocol.player_joined(self)

        # Some logic here

        self.close("Thanks, you are now registered!")
示例#26
0
 def packet_login_start(self, buff):
     if not options.down:
         ServerProtocol.packet_login_start(self, buff)
     else:
         buff.discard()
         self.close(options.downmsg)
示例#27
0
 def packet_unhandled(self, buff, name):
     if name == "keep_alive":
         if buff != self.alive_key:
             ServerProtocol.close(self, "Invalid keep-alive packet.")
     else:
         buff.discard()
示例#28
0
    def player_joined(self):
        # This method gets called when a player successfully joins the server.
        #   If we're in online mode (the default), this means auth with the
        #   session server was successful and the user definitely owns the
        #   username they claim to.

        # Call super. This switches us to "play" mode, marks the player as
        #   in-game, and does some logging.
        ServerProtocol.player_joined(self)
        authed = "true"
        # Define your own logic here. It could be an HTTP request to an API,
        #   or perhaps an update to a database table.
        username = self.username
        uuid = self.uuid
        ip_addr = self.recv_addr.host
        self.logger.info("[%s (%s) authed with IP %s]" % (username, uuid, ip_addr))

        # MYSQL Here
        db = MySQLdb.connect(host="localhost", user="******", passwd="pass", db="database")
        user = db.cursor()
        verified = db.cursor()
        hours = db.cursor()
        ip = db.cursor()
        full = db.cursor()

        if authed == "true":
            print " --> OK!"
            user.execute("SELECT * FROM wp_auth_players where username = '******'")
            ip.execute(
                "SELECT * FROM wp_auth_players where username = '******' and address <> '" + ip_addr + "'"
            )
            verified.execute("SELECT * FROM wp_auth_players where username = '******' and verified = 1")
            # hours.execute("SELECT * FROM wp_auth_players where username = '******' and time < DATE_ADD(NOW(), INTERVAL 1 HOUR)")
            full.execute(
                "SELECT * FROM wp_auth_players where username = '******' and address = '"
                + ip_addr
                + "' and verified = 0"
            )
            print "Found %s entries" % full.rowcount
            if full.rowcount == 1:
                sql = (
                    "UPDATE wp_auth_players SET verified = '1' where username = '******' and address = '"
                    + client_addr
                    + "' and verified = '0'"
                )
                try:
                    full.execute(sql)
                    db.commit()
                except:
                    db.rollback()
                print "The user has been verified"
                message = (
                    u"\u00A7eGood to see you own this account \u00A76"
                    + username
                    + u"\u00A7e!\n \u00A7eNow just click \u00A76Next\u00A7e on the website!"
                )
            elif user.rowcount == 0:
                print "The user has NOT been verified (doesn't exist)"
                message = (
                    u"\u00A7eSorry \u00A76"
                    + username
                    + u"\u00A7e, apparently you haven't tried registering yet!\nVisit "
                    + SITE_URL
                    + "to begin the process."
                )
            elif ip.rowcount == 1:
                print "The user has NOT been verified (different ip)"
                message = (
                    u"\u00A7eSorry \u00A76"
                    + username
                    + u"\u00A7e, it looks like you're connecting from a different IP!\nIf this is incorrect, contact a staff member."
                )
            elif verified.rowcount == 1:
                print "The user is already verified"
                message = (
                    u"\u00A7eHold on \u00A76"
                    + username
                    + u"\u00A7e, it looks like you've already been authenticated!\nIf this is incorrect, contact a staff member."
                )
            # elif hours.rowcount == 1: # this will be done soon!
            #    print "The user has NOT been verified (too late)"
            #    return u"\u00A7eSorry \u00A76" + username + u"\u00A7e, it looks like you've taken too long!\nTry again tomorrow, without waiting over an hour."
            else:
                print "Overall else"
                message = u"\u00A7eWhoops, something went horribly wrong. Contact WizardCM!"
            db.close()
        else:
            print " --> FAILED!"
            message = (
                u"\u00A74Are you sure you own this account ("
                + username
                + u")? Try restarting your game!\n(this doesn't actually do anything yet, but it will!)"
            )

        # Kick the player.
        self.close(message)
示例#29
0
 def player_left(self):
     global eobj_byid
     ServerProtocol.player_left(self)
     pushChatCall(eobj_byid, "\u00A7e" + self.username + " has left the game\u00A7r", 1, self.destroy)
示例#30
0
    def player_left(self):
        ServerProtocol.player_left(self)

        # Announce player left
        self.factory.send_chat(u"\u00a7e%s has left." % self.display_name)
示例#31
0
 def player_left(self):
     ServerProtocol.player_left(self)
     self.eobj_byid = eobj_byid
     pushChatCall(self, "\u00A7e" + self.username + " has left the game\u00A7r", 1, self.destroy)
示例#32
0
    def player_joined(self):
        # This method gets called when a player successfully joins the server.
        #   If we're in online mode (the default), this means auth with the
        #   session server was successful and the user definitely owns the
        #   display name they claim to.

        # Call super. This switches us to "play" mode, marks the player as
        #   in-game, and does some logging.
        ServerProtocol.player_joined(self)

        # Define your own logic here. It could be an HTTP request to an API,
        #   or perhaps an update to a database table.
        display_name = self.display_name
        uuid = self.uuid

        # Monkey Patch for Forge deciding to append "\x00FML\x00" to the connection string
        if self.connect_host.endswith("\x00FML\x00"):
            ip_addr = self.connect_host[:-5]
        else:
            ip_addr = self.connect_host

        connect_port = self.connect_port

        self.logger.info("[AUTH SERVER] %s (%s) connected to address %s:%s",
                         display_name, uuid, ip_addr, connect_port)

        connection_token = ip_addr.split(".")[0]
        session = DATABASE_SESSION.get_session()
        token = session.query(AccountLinkToken).filter_by(token=connection_token).first()
        if not token:
            self.close("You have connected with an invalid token!")
            session.close()
            return
        discord_account = session.query(DiscordAccount).filter_by(link_token_id=token.id).first()
        if not discord_account:
            self.close("You have connected with an invalid token!")
            session.close()
            return
        if datetime.utcnow() < token.expiry:
            # Check if they already have a linked account and are re-linking
            if discord_account.minecraft_account_id is not None:
                existing_account = session.query(MinecraftAccount).filter_by(
                    id=discord_account.minecraft_account_id).first()
                self.logger.info("unlinking existing %s account and replacing it with %s",
                                 existing_account.minecraft_uuid, str(uuid))
                session.delete(existing_account)
            mc_account = MinecraftAccount(str(uuid), discord_account.id)
            discord_account.minecraft_account = mc_account
            session.add(mc_account)
            session.delete(token)
            session.commit()
            session.close()
            self.close("Your minecraft account has successfully been linked to your discord account!")
            return
        else:
            session.delete(token)
            session.commit()
            session.close()
            self.close("You have connected with an expired token! "
                       "Please run the mc!register command again to get a new token.")
            return

        # Kick the player.
        self.close("This shouldn't happen!")
示例#33
0
 def connection_lost(self, reason=None):
     ServerProtocol.connection_lost(self, reason)
     if self.bridge:
         self.bridge.downstream_disconnected()
示例#34
0
 def player_left(self):
     ServerProtocol.player_left(self)
     event.SetEvent("on_leave", self, self.display_name,
                    self.remote_addr.host)
示例#35
0
 def player_left(self):
     self.plugin_event("player_leave")
     del players[self.entity_id]
     ServerProtocol.player_left(self)
示例#36
0
 def player_joined(self):
     ServerProtocol.player_joined(self)
     self.bridge = self.factory.bridge_class(self.factory, self)
示例#37
0
 def player_joined(self):
     ServerProtocol.player_joined(self)
     self.bridge = self.factory.bridge_class(self.factory, self)
示例#38
0
    def player_left(self):
        ServerProtocol.player_left(self)

        # Announce player left
        self.factory.send_chat(u"\u00a7e%s has left." % self.display_name)
示例#39
0
 def player_joined(self):
     ServerProtocol.player_joined(self)
     self.bridge.downstream_ready()