Exemplo n.º 1
0
class RadarClientServerTestCase(SBAGUIWithServerTestCase):
    def get_config_filename(self):
        return "test_server.cfg"

    def test_add_two_ships_get_radar_results(self):
        """
        Test adding two networked clients to a server and that one can radar the other
        """
        self.__env_target = None
        self.__env_radar = None

        self.targetship = AIShip_Network_Harness("Target", self.__target_ship)
        self.assertTrue(
            self.targetship.connect(self.cfg.getint("Server", "port")),
            "Target Didn't connect to server.")

        self.radarship = AIShip_Network_Harness("Radar", self.__radar_ship)
        self.assertTrue(
            self.radarship.connect(self.cfg.getint("Server", "port")),
            "Radar Didn't connect to server.")

        time.sleep(0.5)

        self.assertTrue(self.targetship.isconnected(),
                        "Target Client not connected to server.")
        self.assertTrue(self.radarship.isconnected(),
                        "Radar Client not connected to server.")

        self.assertIsNotNone(self.__env_target,
                             "Target Never received environment.")
        self.assertIsNotNone(self.__env_radar,
                             "Radar Never received environment.")

        tship = None
        rship = None

        for obj in self.game.world:
            if "Target" in obj.player.name:
                tship = obj
            elif "Radar" in obj.player.name:
                rship = obj

        self.assertIsNotNone(tship, "Couldn't find Target Ship")
        self.assertIsNotNone(rship, "Couldn't find Radar Ship")

        tship.body.position = self.game.world.mid_point(-75, 0)
        rship.body.position = self.game.world.mid_point(75, 0)

        time.sleep(1)

        self.assertEqual(len(self.__env_radar["RADARDATA"]), 1,
                         "Radar Data Doesn't Contain 1 Item")
        self.assertEqual(self.__env_radar["RADARDATA"][0]["ID"], tship.id,
                         "Radar Doesn't Contain Target Ship")

        self.assertIsNone(self.__env_target["RADARDATA"],
                          "Target Radar Should Not Contain Data")

        time.sleep(1)

        self._endServer()

        time.sleep(2)

        self.assertFalse(
            self.targetship.isconnected(),
            "Target Client still connected to server after disconnect.")
        self.assertFalse(
            self.radarship.isconnected(),
            "Radar Client still connected to server after disconnect.")

        time.sleep(0.5)

    def test_two_ships_no_radar_when_cloaked(self):
        """
        Test adding two networked clients to a server and that one can't radar the other when it's cloaked
        """
        self.__env_target = None
        self.__env_radar = None

        self.targetship = AIShip_Network_Harness("Cloak", self.__cloak_ship)
        self.assertTrue(
            self.targetship.connect(self.cfg.getint("Server", "port")),
            "Target Didn't connect to server.")

        self.radarship = AIShip_Network_Harness("Radar", self.__radar_ship)
        self.assertTrue(
            self.radarship.connect(self.cfg.getint("Server", "port")),
            "Radar Didn't connect to server.")

        time.sleep(0.5)

        self.assertTrue(self.targetship.isconnected(),
                        "Target Client not connected to server.")
        self.assertTrue(self.radarship.isconnected(),
                        "Radar Client not connected to server.")

        self.assertIsNotNone(self.__env_target,
                             "Target Never received environment.")
        self.assertIsNotNone(self.__env_radar,
                             "Radar Never received environment.")

        tship = None
        rship = None

        for obj in self.game.world:
            if "Cloak" in obj.player.name:
                tship = obj
            elif "Radar" in obj.player.name:
                rship = obj

        self.assertIsNotNone(tship, "Couldn't find Target Ship")
        self.assertIsNotNone(rship, "Couldn't find Radar Ship")

        tship.body.position = self.game.world.mid_point(-75, 0)
        rship.body.position = self.game.world.mid_point(75, 0)

        time.sleep(1)

        self.assertEqual(len(self.__env_radar["RADARDATA"]), 0,
                         "Radar Data Contains Cloaked Ship")
        self.assertIsNone(self.__env_target["RADARDATA"],
                          "Target Radar Should Not Contain Data")

        time.sleep(1)

        self._endServer()

        time.sleep(2)

        self.assertFalse(
            self.targetship.isconnected(),
            "Target Client still connected to server after disconnect.")
        self.assertFalse(
            self.radarship.isconnected(),
            "Radar Client still connected to server after disconnect.")

        time.sleep(0.5)

    def test_two_ships_cant_read_command_queue_and_energy(self):
        """
        Test adding two networked clients to a server and that one can't read the command queue of the other
        """
        self.__env_target = None
        self.__env_radar = None

        self.targetship = AIShip_Network_Harness("Target", self.__target_ship)
        self.assertTrue(
            self.targetship.connect(self.cfg.getint("Server", "port")),
            "Target Didn't connect to server.")

        self.radarship = AIShip_Network_Harness("Radar", self.__radar_ship)
        self.assertTrue(
            self.radarship.connect(self.cfg.getint("Server", "port")),
            "Radar Didn't connect to server.")

        time.sleep(0.5)

        self.assertTrue(self.targetship.isconnected(),
                        "Target Client not connected to server.")
        self.assertTrue(self.radarship.isconnected(),
                        "Radar Client not connected to server.")

        self.assertIsNotNone(self.__env_target,
                             "Target Never received environment.")
        self.assertIsNotNone(self.__env_radar,
                             "Radar Never received environment.")

        tship = None
        rship = None

        for obj in self.game.world:
            if "Target" in obj.player.name:
                tship = obj
            elif "Radar" in obj.player.name:
                rship = obj

        self.assertIsNotNone(tship, "Couldn't find Target Ship")
        self.assertIsNotNone(rship, "Couldn't find Radar Ship")

        tship.body.position = self.game.world.mid_point(-75, 0)
        rship.body.position = self.game.world.mid_point(75, 0)

        time.sleep(1)

        self.assertEqual(len(self.__env_radar["RADARDATA"]), 1,
                         "Radar Data Doesn't Contain 1 Item")
        self.assertEqual(self.__env_radar["RADARDATA"][0]["ID"], tship.id,
                         "Radar Doesn't Contain Target Ship")
        self.assertFalse(self.__env_radar["RADARDATA"][0].has_key("CURENERGY"),
                         "Radar shouldn't contain Target's Energy Level")
        self.assertFalse(self.__env_radar["RADARDATA"][0].has_key("CMDQ"),
                         "Radar shouldn't contain Target's Command Queue")

        self.assertIsNone(self.__env_target["RADARDATA"],
                          "Target Radar Should Not Contain Data")
        self.assertIsNotNone(self.__env_target["SHIPDATA"],
                             "Target Should Contain Ship Data")
        self.assertIsNotNone(self.__env_target["SHIPDATA"]["CURENERGY"],
                             "Target Ship Should Know It's Energy Level.")
        self.assertEqual(self.__env_target["SHIPDATA"]["CURENERGY"],
                         self.__env_target["SHIPDATA"]["MAXENERGY"],
                         "Target Ship Should have all its energy.")
        self.assertIsNotNone(self.__env_target["SHIPDATA"]["CMDQ"],
                             "Target Ship Should Know It's Command Queue.")

        time.sleep(1)

        self._endServer()

        time.sleep(2)

        self.assertFalse(
            self.targetship.isconnected(),
            "Target Client still connected to server after disconnect.")
        self.assertFalse(
            self.radarship.isconnected(),
            "Radar Client still connected to server after disconnect.")

        time.sleep(0.5)

    def __target_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Target Ship")
        self.__env_target = env
        return RotateCommand(ship, 6)

    def __cloak_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Cloak Ship")
        if self.__env_target == None:
            self.__env_target = env
            return CloakCommand(ship, 8.0)

        self.__env_target = env
        return IdleCommand(ship, 2.0)

    def __radar_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Radar Ship")
        self.__env_radar = env
        return RadarCommand(ship, 5)
Exemplo n.º 2
0
class ServerGUISingleShipRemoteTestCase(SBAGUIWithServerTestCase):

    def get_config_filename(self):
        return "test_server.cfg"

    def test_add_host_close_ship(self):
        """
        Test adding a networked client and having the server close connection
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Add Me", self.__rotate_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")), "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env, "Never received environment.")
        
        ang = self.__env["SHIPDATA"]["ROTATION"]

        time.sleep(2)

        self.assertNotEqual(ang, self.__env["SHIPDATA"]["ROTATION"], "Angle didn't change over time.")

        self._endServer() # Note, Ship will still be visible as we're not removing it from world in this test.

        time.sleep(3)

        self.assertFalse(self.ship.isconnected(), "Client still connected to server after disconnect.")

    def test_add_client_disconnect_ship(self):
        """
        Pure client connect/disconnect test running single command
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Add Me", self.__rotate_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")), "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env, "Never received environment.")
        
        ang = self.__env["SHIPDATA"]["ROTATION"]

        time.sleep(2)

        self.assertNotEqual(ang, self.__env["SHIPDATA"]["ROTATION"], "Angle didn't change over time.")

        self.ship.disconnect()

        time.sleep(2)

        self.assertFalse(self.ship.isconnected(), "Client still connected to server after disconnect.")

    def test_add_host_remove_ship(self):
        """
        Test disconnect_on_death setting by remove object from world on server
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Add Me", self.__rotate_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")), "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env, "Never received environment.")
        
        ang = self.__env["SHIPDATA"]["ROTATION"]

        time.sleep(2)

        self.assertNotEqual(ang, self.__env["SHIPDATA"]["ROTATION"], "Angle didn't change over time.")

        #SERVER
        self.assertEqual(len(self.game.world), 1, "More than one object in the world.")
        for obj in self.game.world:
            self.game.world.remove(obj) # we turned disconnect on death on to make this also disconnect

        time.sleep(3)

        self.assertEqual(len(self.game.world), 0, "Ship still in world.")
        #end SERVER

        self.assertFalse(self.ship.isconnected(), "Client still connected to server after disconnect.")

    def test_client_removed_on_error(self):
        """
        Test disconnect_on_death setting by remove object from world on server
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Add Me", self.__error_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")), "Didn't connect to server.")

        time.sleep(2)

        self.assertEqual(len(self.game.world), 1, "Client didn't connect as no object in world.") # Server

        self.assertIsNotNone(self.__env, "Never received environment.")
       
        # Wait for server to remove
        time.sleep(12)
        
        self.assertEqual(len(self.game.world), 0, "Ship still in world.") #SERVER

        time.sleep(3)

        self.assertFalse(self.ship.isconnected(), "Client still connected after failure?")

    def __rotate_ship(self, env):
        logging.info("Test Case got Callback from Network")
        self.__env = env
        return RotateCommand(self.ship, 6)

    def __error_ship(self, env):
        self.__env = env
        time.sleep(1)
        # want client thread to die to test server, seems to not effect test, which is kind of a bad thing, but we'll exploit it for now
        # means we should be more prudent with testing for those cases with asserts to prevent bad tests.
        raise Exception
class ServerGUITwoShipRemoteTestCase(SBAGUIWithServerTestCase):
    def get_config_filename(self):
        return "test_server.cfg"

    # TODO: Expected Failure - Issue #112
    def test_add_two_ships_and_disconnect(self):
        """
        Tests adding two networked clients to a server and that they can disconnect
        """
        self.__env_target = None
        self.__env_radar = None

        self.targetship = AIShip_Network_Harness("Target", self.__target_ship)
        self.assertTrue(
            self.targetship.connect(self.cfg.getint("Server", "port")),
            "Target Didn't connect to server.")

        self.radarship = AIShip_Network_Harness("Radar", self.__radar_ship)
        self.assertTrue(
            self.radarship.connect(self.cfg.getint("Server", "port")),
            "Radar Didn't connect to server.")

        time.sleep(0.25)

        self.assertTrue(self.targetship.isconnected(),
                        "Target Client not connected to server.")
        self.assertTrue(self.radarship.isconnected(),
                        "Radar Client not connected to server.")

        self.assertIsNotNone(self.__env_target,
                             "Target Never received environment.")
        self.assertIsNotNone(self.__env_radar,
                             "Radar Never received environment.")

        self.assertEqual(len(self.game.world), 2, "Both Ships not in world.")

        tship = None
        rship = None

        for obj in self.game.world:
            if "Target" in obj.player.name:
                tship = obj
            elif "Radar" in obj.player.name:
                rship = obj

        self.assertIsNotNone(tship, "Couldn't find Target Ship")
        self.assertIsNotNone(rship, "Couldn't find Radar Ship")

        time.sleep(0.25)

        self._endServer(
        )  # Note, Ship will still be visible as we're not removing it from world in this test.

        time.sleep(0.5)

        self.assertFalse(
            self.targetship.isconnected(),
            "Target Client still connected to server after disconnect.")
        self.assertFalse(
            self.radarship.isconnected(),
            "Radar Client still connected to server after disconnect.")

        self.assertEqual(len(self.game.world), 0, "Objects still in world.")

        time.sleep(0.5)

    def __target_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Target Ship")
        self.__env_target = env
        return RotateCommand(ship, 240)

    def __radar_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Radar Ship")
        self.__env_radar = env
        return RotateCommand(ship, 240)
class ServerGUISingleShipRemoteTestCase(SBAGUIWithServerTestCase):
    def get_config_filename(self):
        return "test_server.cfg"

    def test_add_host_close_ship(self):
        """
        Test adding a networked client and having the server close connection
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Add Me", self.__rotate_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")),
                        "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env, "Never received environment.")

        ang = self.__env["SHIPDATA"]["ROTATION"]

        time.sleep(2)

        self.assertNotEqual(ang, self.__env["SHIPDATA"]["ROTATION"],
                            "Angle didn't change over time.")

        self._endServer(
        )  # Note, Ship will still be visible as we're not removing it from world in this test.

        time.sleep(3)

        self.assertFalse(self.ship.isconnected(),
                         "Client still connected to server after disconnect.")

    def test_add_client_disconnect_ship(self):
        """
        Pure client connect/disconnect test running single command
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Add Me", self.__rotate_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")),
                        "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env, "Never received environment.")

        ang = self.__env["SHIPDATA"]["ROTATION"]

        time.sleep(2)

        self.assertNotEqual(ang, self.__env["SHIPDATA"]["ROTATION"],
                            "Angle didn't change over time.")

        self.ship.disconnect()

        time.sleep(2)

        self.assertFalse(self.ship.isconnected(),
                         "Client still connected to server after disconnect.")

    def test_add_host_remove_ship(self):
        """
        Test disconnect_on_death setting by remove object from world on server
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Add Me", self.__rotate_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")),
                        "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env, "Never received environment.")

        ang = self.__env["SHIPDATA"]["ROTATION"]

        time.sleep(2)

        self.assertNotEqual(ang, self.__env["SHIPDATA"]["ROTATION"],
                            "Angle didn't change over time.")

        #SERVER
        self.assertEqual(len(self.game.world), 1,
                         "More than one object in the world.")
        for obj in self.game.world:
            self.game.world.remove(
                obj
            )  # we turned disconnect on death on to make this also disconnect

        time.sleep(3)

        self.assertEqual(len(self.game.world), 0, "Ship still in world.")
        #end SERVER

        self.assertFalse(self.ship.isconnected(),
                         "Client still connected to server after disconnect.")

    def test_client_removed_on_error(self):
        """
        Test disconnect_on_death setting by remove object from world on server
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Add Me", self.__error_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")),
                        "Didn't connect to server.")

        time.sleep(2)

        self.assertEqual(
            len(self.game.world), 1,
            "Client didn't connect as no object in world.")  # Server

        self.assertIsNotNone(self.__env, "Never received environment.")

        # Wait for server to remove
        time.sleep(12)

        self.assertEqual(len(self.game.world), 0,
                         "Ship still in world.")  #SERVER

        time.sleep(3)

        self.assertFalse(self.ship.isconnected(),
                         "Client still connected after failure?")

    def __rotate_ship(self, ship, env):
        logging.info("Test Case got Callback from Network")
        self.__env = env
        return RotateCommand(ship, 6)

    def __error_ship(self, ship, env):
        self.__env = env
        time.sleep(1)
        # want client thread to die to test server, seems to not effect test, which is kind of a bad thing, but we'll exploit it for now
        # means we should be more prudent with testing for those cases with asserts to prevent bad tests.
        raise Exception
class ServerDisableCommandsTestCase(SBAServerTestCase):
    def get_config_filename(self):
        return "test_server_disable.cfg"

    def test_rotate_ship_command_disable_fail(self):
        """
        Test that a ship using Rotate doesn't work with disable_commands Server property
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Rotator", self.__rotate_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")),
                        "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env, "Never received environment.")

        ang = self.__env["SHIPDATA"]["ROTATION"]

        time.sleep(2)

        self.assertGreater(self.ship.errors, 0,
                           "Ship didn't receive error message.")

        self.assertEqual(ang, self.__env["SHIPDATA"]["ROTATION"],
                         "Angle changed over time.")

        self._endServer(
        )  # Note, Ship will still be visible as we're not removing it from world in this test.

        time.sleep(3)

        self.assertFalse(self.ship.isconnected(),
                         "Client still connected to server after disconnect.")

    def test_thrust_ship_command_disabled(self):
        """
        Test that a ship using Thrust works with disable_commands Server property
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Thruster", self.__thrust_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")),
                        "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env, "Never received environment.")

        pos = self.__env["SHIPDATA"]["POSITION"]

        time.sleep(2)

        self.assertEqual(self.ship.errors, 0, "Ship received error message.")

        self.assertNotEqual(pos, self.__env["SHIPDATA"]["POSITION"],
                            "Position didn't change over time.")

        self._endServer(
        )  # Note, Ship will still be visible as we're not removing it from world in this test.

        time.sleep(3)

        self.assertFalse(self.ship.isconnected(),
                         "Client still connected to server after disconnect.")

    def test_other_ship_command_disable(self):
        """
        Test that a ship using a different command works with disable_commands Server property
        """
        self.__env = None

        self.ship = AIShip_Network_Harness("Idle", self.__idle_ship)

        self.assertTrue(self.ship.connect(self.cfg.getint("Server", "port")),
                        "Didn't connect to server.")

        time.sleep(2)

        self.assertIsNotNone(self.__env,
                             "Didn't received initial environment.")

        time.sleep(2)

        self.assertEqual(self.ship.errors, 0, "Ship received error message.")

        self._endServer(
        )  # Note, Ship will still be visible as we're not removing it from world in this test.

        time.sleep(3)

        self.assertFalse(self.ship.isconnected(),
                         "Client still connected to server after disconnect.")

    def __rotate_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Rotate Ship")
        self.__env = env
        return RotateCommand(ship, 6)

    def __thrust_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Thrust Ship")
        self.__env = env
        return ThrustCommand(ship, 'B', 4.0, 1.0, True)

    def __idle_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Idle Ship")
        self.__env = env
        return IdleCommand(ship, 1.0)
Exemplo n.º 6
0
class RadarClientServerTestCase(SBAGUIWithServerTestCase):

    def get_config_filename(self):
        return "test_server.cfg"

    def test_add_two_ships_get_radar_results(self):
        """
        Test adding two networked clients to a server and that one can radar the other
        """
        self._env_target = None
        self._env_radar = None

        self.targetship = AIShip_Network_Harness("Target", self.__target_ship)
        self.assertTrue(self.targetship.connect(self.cfg.getint("Server", "port")), "Target Didn't connect to server.")

        self.radarship = AIShip_Network_Harness("Radar", self.__radar_ship)
        self.assertTrue(self.radarship.connect(self.cfg.getint("Server", "port")), "Radar Didn't connect to server.")

        time.sleep(0.5)

        self.assertTrue(self.targetship.isconnected(), "Target Client not connected to server.")
        self.assertTrue(self.radarship.isconnected(), "Radar Client not connected to server.")

        self.assertIsNotNone(self._env_target, "Target Never received environment.")
        self.assertIsNotNone(self._env_radar, "Radar Never received environment.")

        tship = None
        rship = None

        for obj in self.game.world:
            if "Target" in obj.player.name:
                tship = obj
            elif "Radar" in obj.player.name:
                rship = obj
        
        self.assertIsNotNone(tship, "Couldn't find Target Ship")
        self.assertIsNotNone(rship, "Couldn't find Radar Ship")

        tship.body.position = self.game.world.mid_point(-75, 0)
        rship.body.position = self.game.world.mid_point(75, 0)

        time.sleep(1)

        self.assertEqual(len(self._env_radar["RADARDATA"]), 1, "Radar Data Doesn't Contain 1 Item")
        self.assertEqual(self._env_radar["RADARDATA"][0]["ID"], tship.id, "Radar Doesn't Contain Target Ship")
        
        self.assertIsNone(self._env_target["RADARDATA"], "Target Radar Should Not Contain Data")

        time.sleep(1)

        self._endServer()

        time.sleep(2)

        self.assertFalse(self.targetship.isconnected(), "Target Client still connected to server after disconnect.")
        self.assertFalse(self.radarship.isconnected(), "Radar Client still connected to server after disconnect.")

        time.sleep(0.5)

    def test_two_ships_no_radar_when_cloaked(self):
        """
        Test adding two networked clients to a server and that one can't radar the other when it's cloaked
        """
        self._env_target = None
        self._env_radar = None

        self.targetship = AIShip_Network_Harness("Cloak", self.__cloak_ship)
        self.assertTrue(self.targetship.connect(self.cfg.getint("Server", "port")), "Target Didn't connect to server.")

        self.radarship = AIShip_Network_Harness("Radar", self.__radar_ship)
        self.assertTrue(self.radarship.connect(self.cfg.getint("Server", "port")), "Radar Didn't connect to server.")

        time.sleep(0.5)

        self.assertTrue(self.targetship.isconnected(), "Target Client not connected to server.")
        self.assertTrue(self.radarship.isconnected(), "Radar Client not connected to server.")

        self.assertIsNotNone(self._env_target, "Target Never received environment.")
        self.assertIsNotNone(self._env_radar, "Radar Never received environment.")

        tship = None
        rship = None

        for obj in self.game.world:
            if "Cloak" in obj.player.name:
                tship = obj
            elif "Radar" in obj.player.name:
                rship = obj
        
        self.assertIsNotNone(tship, "Couldn't find Target Ship")
        self.assertIsNotNone(rship, "Couldn't find Radar Ship")

        tship.body.position = self.game.world.mid_point(-75, 0)
        rship.body.position = self.game.world.mid_point(75, 0)

        time.sleep(1)

        self.assertEqual(len(self._env_radar["RADARDATA"]), 0, "Radar Data Contains Cloaked Ship")
        self.assertIsNone(self._env_target["RADARDATA"], "Target Radar Should Not Contain Data")

        time.sleep(1)

        self._endServer()

        time.sleep(2)

        self.assertFalse(self.targetship.isconnected(), "Target Client still connected to server after disconnect.")
        self.assertFalse(self.radarship.isconnected(), "Radar Client still connected to server after disconnect.")

        time.sleep(0.5)

    def test_two_ships_no_radar_when_nebula(self):
        """
        Test adding two networked clients to a server and that one can't radar the other when it's in a nebula
        """
        self._env_target = None
        self._env_radar = None

        self.targetship = AIShip_Network_Harness("Nebula", self.__target_ship)
        self.assertTrue(self.targetship.connect(self.cfg.getint("Server", "port")), "Target Didn't connect to server.")

        self.radarship = AIShip_Network_Harness("Radar", self.__radar_ship)
        self.assertTrue(self.radarship.connect(self.cfg.getint("Server", "port")), "Radar Didn't connect to server.")

        nebula = Nebula(self.game.world.mid_point(-128,0), (384, 256))
        self.game.world.append(nebula)

        time.sleep(0.5)

        self.assertTrue(self.targetship.isconnected(), "Target Client not connected to server.")
        self.assertTrue(self.radarship.isconnected(), "Radar Client not connected to server.")

        self.assertIsNotNone(self._env_target, "Target Never received environment.")
        self.assertIsNotNone(self._env_radar, "Radar Never received environment.")

        tship = None
        rship = None

        for obj in self.game.world:
            if isinstance(obj, Ship):
                if "Nebula" in obj.player.name:
                    tship = obj
                elif "Radar" in obj.player.name:
                    rship = obj
        
        self.assertIsNotNone(tship, "Couldn't find Target Ship")
        self.assertIsNotNone(rship, "Couldn't find Radar Ship")

        tship.body.position = self.game.world.mid_point(-75, 0)
        rship.body.position = self.game.world.mid_point(100, 0)

        time.sleep(1)

        self.assertEqual(len(self._env_radar["RADARDATA"]), 1, "Radar Data Contains more than Nebula")
        self.assertIsNone(self._env_target["RADARDATA"], "Target Radar Should Not Contain Data")

        time.sleep(1)

        self._endServer()

        time.sleep(2)

        self.assertFalse(self.targetship.isconnected(), "Target Client still connected to server after disconnect.")
        self.assertFalse(self.radarship.isconnected(), "Radar Client still connected to server after disconnect.")

        time.sleep(0.5)

    def test_two_ships_cant_read_command_queue_and_energy(self):
        """
        Test adding two networked clients to a server and that one can't read the command queue of the other
        """
        self._env_target = None
        self._env_radar = None

        self.targetship = AIShip_Network_Harness("Target", self.__target_ship)
        self.assertTrue(self.targetship.connect(self.cfg.getint("Server", "port")), "Target Didn't connect to server.")

        self.radarship = AIShip_Network_Harness("Radar", self.__radar_ship)
        self.assertTrue(self.radarship.connect(self.cfg.getint("Server", "port")), "Radar Didn't connect to server.")

        time.sleep(0.5)

        self.assertTrue(self.targetship.isconnected(), "Target Client not connected to server.")
        self.assertTrue(self.radarship.isconnected(), "Radar Client not connected to server.")

        self.assertIsNotNone(self._env_target, "Target Never received environment.")
        self.assertIsNotNone(self._env_radar, "Radar Never received environment.")

        tship = None
        rship = None

        for obj in self.game.world:
            if "Target" in obj.player.name:
                tship = obj
            elif "Radar" in obj.player.name:
                rship = obj
        
        self.assertIsNotNone(tship, "Couldn't find Target Ship")
        self.assertIsNotNone(rship, "Couldn't find Radar Ship")

        tship.body.position = self.game.world.mid_point(-75, 0)
        rship.body.position = self.game.world.mid_point(75, 0)

        time.sleep(1)

        self.assertEqual(len(self._env_radar["RADARDATA"]), 1, "Radar Data Doesn't Contain 1 Item")
        self.assertEqual(self._env_radar["RADARDATA"][0]["ID"], tship.id, "Radar Doesn't Contain Target Ship")
        self.assertFalse(self._env_radar["RADARDATA"][0].has_key("CURENERGY"), "Radar shouldn't contain Target's Energy Level")
        self.assertFalse(self._env_radar["RADARDATA"][0].has_key("CMDQ"), "Radar shouldn't contain Target's Command Queue")
        
        self.assertIsNone(self._env_target["RADARDATA"], "Target Radar Should Not Contain Data")
        self.assertIsNotNone(self._env_target["SHIPDATA"], "Target Should Contain Ship Data")
        self.assertIsNotNone(self._env_target["SHIPDATA"]["CURENERGY"], "Target Ship Should Know It's Energy Level.")
        self.assertEqual(self._env_target["SHIPDATA"]["CURENERGY"], self._env_target["SHIPDATA"]["MAXENERGY"], "Target Ship Should have all its energy.")
        self.assertIsNotNone(self._env_target["SHIPDATA"]["CMDQ"], "Target Ship Should Know It's Command Queue.")

        time.sleep(1)

        self._endServer()

        time.sleep(2)

        self.assertFalse(self.targetship.isconnected(), "Target Client still connected to server after disconnect.")
        self.assertFalse(self.radarship.isconnected(), "Radar Client still connected to server after disconnect.")

        time.sleep(0.5)

    def __target_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Target Ship")
        self._env_target = env
        return RotateCommand(ship, 6)

    def __cloak_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Cloak Ship")
        if self._env_target == None:
            self._env_target = env
            return CloakCommand(ship, 8.0)

        self._env_target = env
        return IdleCommand(ship, 2.0)

    def __radar_ship(self, ship, env):
        logging.info("Test Case got Callback from Network for Radar Ship")
        self._env_radar = env
        return RadarCommand(ship, 5)