Skip to content

Disconnected from server even before the first packet was sent #105

@r58Playz

Description

@r58Playz
Starting internal server...
2019-06-10 12:51:09 [MainThread] [INFO] Mod loader has identified 1 mods to load
No seed set, generated random seed: 176701563921720149104828281598416444896
Server loop running in thread: Thread-1
Listening on 192.168.56.1 1486
Client PacketReceiver: We've been disconnected by the server
Game mode: creative
2019-06-10 12:51:17 [MainThread] [INFO] Average FPS: 593.075906

Process finished with exit code -1(manual stop in pycharm)

Started with singleplayer. I have changed the code to start the server on Singleplayer, similar to Nebual 's singleplayer server subprocess branch.
Here's the code:
utils.py:

cmd = None

def runserver():
    global cmd
    def run():
        global cmd
        with Popen([sys.executable, 'server.py']) as process:
            while True:
                if cmd == "stop":
                    process.stdin.write('stop')
                    process.stdin.flush()
                    return
                elif 'say' in cmd:
                    process.stdin.write(cmd)
                    process.stdin.flush()
                else:
                    continue
    threading.Thread(target=run).start()

controllers.py:

    def setup(self):
        if G.SINGLEPLAYER:
            try:
                print('Starting internal server...')
                # TODO: create world menu
                G.SAVE_FILENAME = "world"
                try:
                    utils.runserver()
                except:
                    print("Cannot run server with utils.runserver(), starting server with start_server(internal=True)")
                    start_server(internal=True)
                time.sleep(3)
                sock = socket.socket()
                sock.connect((socket.gethostbyname(socket.gethostname()), 1486))
            except socket.error as e:
                print("Socket Error:", e)
                # Otherwise back to the main menu we go
                return False
            except Exception as e:
                print('Unable to start internal server')
                import traceback
                traceback.print_exc()
                return False
        else:
            try:
                # Make sure the address they want to connect to works
                ipport = G.IP_ADDRESS.split(":")
                if len(ipport) == 1: ipport.append(1486)
                sock = socket.socket()
                sock.connect((tuple(ipport)))
            except socket.error as e:
                print("Socket Error:", e)
                # Otherwise back to the main menu we go
                return False

        self.init_gl()

        sky_rotation = -20.0  # -20.0

       # TERRAIN_CHOICE = self.biome_generator.get_biome_type(sector[0], sector[2])
        default_skybox = 'skydome.jpg'
        #if TERRAIN_CHOICE == G.NETHER:
        #    default_skybox = 'skydome_nether.jpg'
        #else:
        #    default_skybox = 'skybox.jpg'


        self.skydome = Skydome(
            G.RESOURCES + default_skybox,
            #'resources/skydome.jpg',
            0.7,
            100.0,
            sky_rotation,
        )

        self.player_ids = {}  # Dict of all players this session, indexes are their ID's [0: first Player on server,]

        self.focus_block = Block(width=1.05, height=1.05)
        self.earth = vec(0.8, 0.8, 0.8, 1.0)
        self.white = vec(1.0, 1.0, 1.0, 1.0)
        self.ambient = vec(1.0, 1.0, 1.0, 1.0)
        self.polished = GLfloat(100.0)
        self.crack_batch = pyglet.graphics.Batch()

        #if G.DISABLE_SAVE and world_exists(G.game_dir, G.SAVE_FILENAME):
        #    open_world(self, G.game_dir, G.SAVE_FILENAME)

        self.world = World()
        self.packetreceiver = PacketReceiver(self.world, self, sock)
        self.world.packetreceiver = self.packetreceiver
        G.CLIENT = self.packetreceiver
        self.packetreceiver.start()

        #Get our position from the server
        self.packetreceiver.request_spawnpos()
        #Since we don't know it yet, lets disable self.update, or we'll load the wrong chunks and fall
        self.update_disabled = self.update
        self.update = lambda dt: None
        #We'll re-enable it when the server tells us where we should be

        self.player = Player(game_mode=G.GAME_MODE)
        print(('Game mode: ' + self.player.game_mode))
        self.item_list = ItemSelector(self, self.player, self.world)
        self.inventory_list = InventorySelector(self, self.player, self.world)
        self.item_list.on_resize(self.window.width, self.window.height)
        self.inventory_list.on_resize(self.window.width, self.window.height)
        self.text_input = TextWidget(self.window, '',
                                     0, 0,
                                     self.window.width,
                                     visible=False,
                                     font_name=G.CHAT_FONT)
        self.text_input.push_handlers(on_toggled=self.on_text_input_toggled, key_released=self.text_input_callback)
        self.chat_box = TextWidget(self.window, '',
                                   0, self.text_input.y + self.text_input.height + 50,
                                   self.window.width // 2, height=min(300, self.window.height // 3),
                                   visible=False, multi_line=True, readonly=True,
                                   font_name=G.CHAT_FONT,
                                   text_color=(255, 255, 255, 255),
                                   background_color=(0, 0, 0, 100),
                                   enable_escape=True)
        self.camera = Camera3D(target=self.player)

        if G.HUD_ENABLED:
            self.label = pyglet.text.Label(
                '', font_name='Arial', font_size=8, x=10, y=self.window.height - 10,
                anchor_x='left', anchor_y='top', color=(255, 255, 255, 255))

        #if G.DEBUG_TEXT_ENABLED:
        #    self.debug_text = TextWidget(self.window, '',
        #                           0, self.window.height - 300,
        #                           500, 300,
        #                           visible=True, multi_line=True, readonly=True,
        #                           font_name='Arial', font_size=10,
        #                           text_color=(255, 255, 255, 255),
        #                           background_color=(0, 0, 0, 0))
        pyglet.clock.schedule_interval_soft(self.world.process_queue,
                                            1.0 / G.MAX_FPS)
        pyglet.clock.schedule_interval_soft(self.world.hide_sectors, 10.0, self.player)
        return True

G.RESOURCES was part of another change which allowed me to set the location of the resources folder. Currently that is set to pyglet.resource.get_settings_path("pyCraft") + "\\resources\\".
By the way, I didn't get any tracebacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions