Ejemplo n.º 1
0
    def __init__(self, listenPort):
        BaseObjectManager.__init__(self, False)
        self.dcSuffix = 'AI'

        # The client that just sent us a message.
        self.clientSender = None

        self.listenPort = listenPort
        self.netSys = NetworkSystem()
        self.netCallbacks = NetworkCallbacks()
        self.netCallbacks.setCallback(self.__handleNetCallback)
        self.listenSocket = self.netSys.createListenSocket(listenPort)
        self.pollGroup = self.netSys.createPollGroup()
        self.clientIdAllocator = UniqueIdAllocator(0, 0xFFFF)
        self.objectIdAllocator = UniqueIdAllocator(0, 0xFFFF)
        self.numClients = 0
        self.clientsByConnection = {}
        self.zonesToClients = {}

        self.snapshotMgr = FrameSnapshotManager()

        self.objectsByZoneId = {}

        base.setTickRate(sv_tickrate.getValue())
        base.simTaskMgr.add(self.runFrame, "serverRunFrame", sort = -100)
Ejemplo n.º 2
0
def test_min_value_allocation():
    allocator = UniqueIdAllocator(1, 5)

    for i in range(1, 5 + 1):
        assert allocator.allocate() == i

    assert allocator.allocate() == IndexEnd
Ejemplo n.º 3
0
    def __init__(self):
        self._http_client = HTTPClient()

        max_http_requests = ConfigVariableInt('http-max-requests', 900).value
        self._request_allocator = UniqueIdAllocator(0, max_http_requests)
        self._poll_task = None
        self._requests = {}
Ejemplo n.º 4
0
 def handleSetDoIdrange(self, di):
     self.doIdBase = di.getUint32()
     self.doIdLast = self.doIdBase + di.getUint32()
     self.doIdAllocator = UniqueIdAllocator(self.doIdBase,
                                            self.doIdLast - 1)
     self.ourChannel = self.doIdBase
     self.createReady()
Ejemplo n.º 5
0
def test_initial_reserve_id_exhaustion():
    allocator = UniqueIdAllocator(1, 3)

    for i in range(1, 3 + 1):
        allocator.initial_reserve_id(i)

    assert allocator.allocate() == IndexEnd
Ejemplo n.º 6
0
def test_free():
    allocator = UniqueIdAllocator(0, 0)

    assert allocator.allocate() == 0
    assert allocator.is_allocated(0)
    assert allocator.free(0)
    assert not allocator.is_allocated(0)
Ejemplo n.º 7
0
    def __init__(self, port=None, host=6660):
        self.active_clients = {}
        self.allocate_channel = UniqueIdAllocator(1000000, 1999999)

        PacketHandler.__init__(self)
        SocketHandler.__init__(self, port, host)
        self.configure()
Ejemplo n.º 8
0
def test_normal_allocation():
    allocator = UniqueIdAllocator(0, 10)

    for i in range(10 + 1):
        assert allocator.allocate() == i

    assert allocator.allocate() == IndexEnd
Ejemplo n.º 9
0
def test_bounded_is_allocated():
    allocator = UniqueIdAllocator(1, 5)

    for i in range(1, 5 + 1):
        assert allocator.is_allocated(allocator.allocate())

    assert not allocator.is_allocated(0)  # Out of range, left side
    assert not allocator.is_allocated(10)  # Out of range, right side
Ejemplo n.º 10
0
def test_regular_is_allocated():
    allocator = UniqueIdAllocator(1, 5)

    for i in range(1, 5 + 1):
        assert not allocator.is_allocated(i)

    for i in range(1, 5 + 1):
        assert allocator.is_allocated(allocator.allocate())
Ejemplo n.º 11
0
def test_free_unallocated():
    allocator = UniqueIdAllocator(0, 2)

    assert allocator.allocate() == 0
    assert allocator.free(0)

    for i in range(0, 2 + 1):
        assert not allocator.free(i)
Ejemplo n.º 12
0
def test_free_initial_reserve_id():
    allocator = UniqueIdAllocator(1, 3)

    allocator.initial_reserve_id(1)
    assert allocator.free(1)
    assert allocator.allocate() == 2
    assert allocator.allocate() == 3
    assert allocator.allocate() == 1
    assert allocator.allocate() == IndexEnd
Ejemplo n.º 13
0
    def __init__(self, air):
        DistributedObjectAI.__init__(self, air)

        self.air.roomZoneAllocator = UniqueIdAllocator(
            ZonesGlobals.ROOM_MIN_ID_ZONE, ZonesGlobals.ROOM_MAX_ID_ZONE)

        self.roomList = []

        self.accept("Client-disconnect", self.handleClientDisconnect)
Ejemplo n.º 14
0
def test_initial_reserve_id():
    allocator = UniqueIdAllocator(1, 3)

    assert not allocator.is_allocated(2)
    allocator.initial_reserve_id(2)
    assert allocator.is_allocated(2)

    assert allocator.allocate() == 1
    assert allocator.allocate() == 3
    assert allocator.allocate() == IndexEnd
Ejemplo n.º 15
0
def test_fraction_used():
    allocator = UniqueIdAllocator(1, 4)

    assert allocator.fraction_used() == 0

    for fraction in (0.25, 0.5, 0.75, 1):
        allocator.allocate()
        assert allocator.fraction_used() == fraction

    assert allocator.allocate() == IndexEnd
Ejemplo n.º 16
0
def test_free_reallocation_mid():
    allocator = UniqueIdAllocator(1, 5)

    for i in range(1, 5 + 1):
        assert allocator.allocate() == i
        assert allocator.is_allocated(i)

    assert allocator.free(2)
    assert allocator.free(3)

    assert allocator.allocate() == 2
    assert allocator.allocate() == 3
    assert allocator.allocate() == IndexEnd
Ejemplo n.º 17
0
    def __init__(self):
        self.connection = None
        self.queue = queue.Queue()

        base_channel = 4000000

        max_channels = 1000000
        self.minChannel = base_channel
        self.maxChannel = base_channel + max_channels
        self.channelAllocator = UniqueIdAllocator(self.minChannel,
                                                  self.maxChannel)
        self.zoneAllocator = UniqueIdAllocator(DynamicZonesBegin,
                                               DynamicZonesEnd)

        self._registedChannels = set()

        self.__contextCounter = 0
        self.__callbacks = {}

        self.ourChannel = self.allocateChannel()

        self.doTable: Dict[int, 'DistributedObjectAI'] = {}
        self.zoneTable: Dict[int, set] = {}
        self.parentTable: Dict[int, set] = {}

        self.dcFile = parse_dc_file('toon.dc')

        self.currentSender = None
        self.loop = None
        self.net_thread = None
        self.hoods = None

        self.zoneDataStore = AIZoneData.AIZoneDataStore()

        self.vismap: Dict[int, Tuple[int]] = {}

        self.connected = Event()
Ejemplo n.º 18
0
def test_free_reallocation():
    allocator = UniqueIdAllocator(1, 5)

    for i in range(1, 5 + 1):
        assert allocator.allocate() == i
        assert allocator.is_allocated(i)

    for i in range(1, 5 + 1):
        assert allocator.free(i)

    for i in range(1, 5 + 1):
        assert not allocator.is_allocated(i)
        assert allocator.allocate() == i

    assert allocator.allocate() == IndexEnd
    def __init__(self, baseChannel, stateServerChannel):
        CogInvasionInternalRepository.__init__(
            self,
            baseChannel,
            stateServerChannel, [
                'resources/phase_3/etc/direct.dc',
                'resources/phase_3/etc/toon.dc'
            ],
            dcSuffix='AI')
        self.notify.setInfo(True)
        self.district = None
        self.zoneAllocator = UniqueIdAllocator(ZoneUtil.DynamicZonesBegin,
                                               ZoneUtil.DynamicZonesEnd)
        self.zoneDataStore = AIZoneDataStore()
        self.hoods = {}
        self.dnaStoreMap = {}
        self.dnaDataMap = {}
        self.districtNameMgr = self.generateGlobalObject(
            DO_ID_DISTRICT_NAME_MANAGER, 'DistrictNameManager')
        self.holidayMgr = self.generateGlobalObject(DO_ID_HOLIDAY_MANAGER,
                                                    'HolidayManager')
        self.uin = self.generateGlobalObject(DO_ID_UNIQUE_INTEREST_NOTIFIER,
                                             'UniqueInterestNotifier')
        self.csm = self.generateGlobalObject(DO_ID_CLIENT_SERVICES_MANAGER,
                                             'ClientServicesManager')
        self.statsMgr = self.generateGlobalObject(DO_ID_STATS_MANAGER,
                                                  'StatsManager')

        # Anything that is a DistributedAvatarAI (Toons, Suits, etc).
        # This is a per-zone list of avatars.
        self.avatars = {}
        self.numAvatars = 0

        self.battleZones = {}

        if DO_SIMULATION:
            self.zonePhysics = {}
            self.bspLoader = BSPLoader()
            self.bspLoader.setAi(True)
            self.bspLoader.setMaterialsFile("phase_14/etc/materials.txt")
            #self.bspLoader.setTextureContentsFile("phase_14/etc/texturecontents.txt")
            #self.bspLoader.setServerEntityDispatcher(self)
            self.bspLoader.read(
                "phase_14/etc/sewer_entrance_room_indoors/sewer_entrance_room_indoors.bsp"
            )
            PhysicsUtils.makeBulletCollFromGeoms(self.bspLoader.getResult(),
                                                 enableNow=False)
Ejemplo n.º 20
0
    def __init__(self):
        ShowBase.__init__(self)

        self.activeConnections = {}

        maxChannels = self.config.GetInt('max-channel-id', 1000000)
        self.channelAllocator = UniqueIdAllocator(0, 0+maxChannels-1)

        self.configManager = None

        self.logManager = LogManager()
        self.dcManager = DCManager()
        self.dcManager.readDCFile()
        self.notify.warning(str(self.dcManager.dclassesByName))
        self.connectionManager = ConnectionManager()
        self.messageManager = MessageManager()
        self.doManager = DistributedObjectManager()
        self.interestManager = InterestManager()
Ejemplo n.º 21
0
 def __init__(self, baseChannel, stateServerChannel):
     CogInvasionInternalRepository.__init__(
         self,
         baseChannel,
         stateServerChannel,
         ['phase_3/etc/direct.dc', 'phase_3/etc/toon.dc'],
         dcSuffix='AI')
     self.notify.setInfo(True)
     self.district = None
     #self.aiWorld = AIWorld(render) # Used for cogs
     self.zoneAllocator = UniqueIdAllocator(CIGlobals.DynamicZonesBegin,
                                            CIGlobals.DynamicZonesEnd)
     self.zoneDataStore = AIZoneDataStore()
     self.hoods = {}
     self.dnaStoreMap = {}
     self.dnaDataMap = {}
     self.districtNameMgr = self.generateGlobalObject(
         DO_ID_DISTRICT_NAME_MANAGER, 'DistrictNameManager')
Ejemplo n.º 22
0
    def __init__(self, *args, **kwargs):
        ModClientRepository.__init__(self, *args, **kwargs)

        # Anything that is a DistributedAvatarAI (Toons, Suits, etc).
        # This is a per-zone list of avatars.
        self.avatars = {}
        self.numAvatars = 0

        self.battleZones = {}

        self.districtId = 0

        self.zoneDataStore = AIZoneDataStore()

        self.zoneAllocator = UniqueIdAllocator(DynamicZonesBegin,
                                               DynamicZonesEnd)

        self.netMessenger = NetMessenger(self)

        # We deal with attacks on the server side as well
        from src.coginvasion.attack.AttackManagerAI import AttackManagerAI
        self.attackMgr = AttackManagerAI()
Ejemplo n.º 23
0
render.setAntialias(AntialiasAttrib.MMultisample)
render.show()

sm.doSunriseFor(sunrise=SHOWBASE_POSTINIT)

base.initStuff()

if metadata.USE_LIGHTING:
    render.setShaderAuto()
else:
    render.clearShader()

from direct.distributed.ClientRepository import ClientRepository
base.cr = ClientRepository(['phase_3/etc/direct.dc', 'phase_3/etc/toon.dc'])
base.cr.isShowingPlayerIds = None
base.cr.doIdAllocator = UniqueIdAllocator(0, 999)


def isChristmas():
    return 0


base.cr.isChristmas = isChristmas

from src.coginvasion.base.CIAudio3DManager import CIAudio3DManager
base.audio3d = CIAudio3DManager(base.sfxManagerList[0], camera)
base.audio3d.setDistanceFactor(25)
base.audio3d.setDropOffFactor(0.025)

from src.coginvasion.nametag import NametagGlobals
from direct.gui import DirectGuiGlobals
Ejemplo n.º 24
0
def test_free_bounds():
    allocator = UniqueIdAllocator(1, 3)

    assert not allocator.free(0)  # Out of range, left side
    assert not allocator.free(4)  # Out of range, right side
Ejemplo n.º 25
0
def test_inclusive_allocation():
    allocator = UniqueIdAllocator(0, 0)
    assert allocator.allocate() == 0
    assert allocator.allocate() == IndexEnd
Ejemplo n.º 26
0
 def __init__(self, uno_game):
     self.game = uno_game
     self.players = []
     self.idAllocator = UniqueIdAllocator(1, 4)
Ejemplo n.º 27
0
 def setup(self):
     self._tracker = self.open_file(
         self.get_filename(self._tracker_filename))
     self._min_id = self._tracker.set_default_value('next', self._min_id)
     self._allocator = UniqueIdAllocator(self._min_id, self._max_id)