Esempio n. 1
0
 def unsubscribe_channel(self, channel):
     dg = Datagram()
     dg.add_uint8(1)
     dg.add_channel(CONTROL_MESSAGE)
     dg.add_uint16(CONTROL_REMOVE_CHANNEL)
     dg.add_channel(channel)
     self.send_datagram(dg)
Esempio n. 2
0
    def ai_format_generate(self, obj, do_id, parent_id, zone_id, district_channel_id, from_channel_id, optional_fields):
        dg = Datagram()
        dg.add_uint8(1)
        dg.add_channel(district_channel_id)
        dg.add_channel(from_channel_id)
        if optional_fields:
            dg.add_uint16(STATESERVER_OBJECT_GENERATE_WITH_REQUIRED_OTHER)
        else:
            dg.add_uint16(STATESERVER_OBJECT_GENERATE_WITH_REQUIRED)

        #if parent_id:
        dg.add_uint32(parent_id)

        dg.add_uint32(zone_id)
        dg.add_uint16(self.number)
        dg.add_uint32(do_id)

        for field in self.inherited_fields:
            if not isinstance(field, MolecularField) and field.is_required:
                self.pack_field(dg, obj, field)

        if optional_fields:
            dg.add_uint16(len(optional_fields))

            for field_name in optional_fields:
                field = self.fields_by_name[field_name]
                dg.add_uint16(field.number)
                self.pack_field(dg, obj, field)

        return dg
Esempio n. 3
0
    def unregisterForChannel(self, channel):
        if channel not in self._registedChannels:
            return
        self._registedChannels.remove(channel)

        dg = Datagram()
        dg.add_server_control_header(CONTROL_REMOVE_CHANNEL)
        dg.add_channel(channel)
        self.send(dg)
Esempio n. 4
0
    def registerForChannel(self, channel):
        if channel in self._registedChannels:
            return
        self._registedChannels.add(channel)

        dg = Datagram()
        dg.add_server_control_header(CONTROL_SET_CHANNEL)
        dg.add_channel(channel)
        self.send(dg)
Esempio n. 5
0
    def ai_format_update(self, do_id, to_id, from_id, args):
        dg = Datagram()

        dg.add_uint8(1)
        dg.add_channel(to_id)
        dg.add_channel(from_id)
        dg.add_uint16(STATESERVER_OBJECT_UPDATE_FIELD)
        dg.add_uint32(do_id)
        dg.add_uint16(self.number)
        self.pack_value(dg, args)
        return dg
Esempio n. 6
0
    def ai_database_generate_context(self, context_id, parent_id, zone_id, owner_channel, database_server_id, from_channel_id):
        dg = Datagram()
        dg.add_uint8(1)
        dg.add_channel(database_server_id)
        dg.add_channel(from_channel_id)
        dg.add_uint16(STATESERVER_OBJECT_CREATE_WITH_REQUIRED_CONTEXT)
        dg.add_uint32(parent_id)
        dg.add_uint32(zone_id)
        dg.add_uint32(owner_channel)
        dg.add_uint16(self.number)
        dg.add_uint32(context_id)

        for field in self.inherited_fields:
            if not isinstance(field, MolecularField) and field.is_required:
                field.pack_default(dg)

        return dg
Esempio n. 7
0
    def createObjects(self):
        self.registerForChannel(self.ourChannel)

        from .Objects import ToontownDistrictAI, ToontownDistrictStatsAI, DistributedInGameNewsMgrAI, NewsManagerAI, FriendManagerAI
        from .TimeManagerAI import TimeManagerAI

        self.district = ToontownDistrictAI(self)
        self.district.name = 'Nutty River'
        self.generateWithRequired(self.district, OTP_DO_ID_TOONTOWN,
                                  OTP_ZONE_ID_DISTRICTS)

        post_remove = Datagram()
        post_remove.add_server_control_header(CONTROL_ADD_POST_REMOVE)
        post_remove.add_server_header([
            STATESERVERS_CHANNEL,
        ], self.ourChannel, STATESERVER_SHARD_REST)
        post_remove.add_channel(self.ourChannel)
        self.send(post_remove)

        dg = Datagram()
        dg.add_server_header([STATESERVERS_CHANNEL], self.ourChannel,
                             STATESERVER_ADD_AI_RECV)
        dg.add_uint32(self.district.do_id)
        dg.add_channel(self.ourChannel)
        self.send(dg)

        stats = ToontownDistrictStatsAI(self)
        stats.settoontownDistrictId(self.district.do_id)
        self.generateWithRequired(stats, OTP_DO_ID_TOONTOWN,
                                  OTP_ZONE_ID_DISTRICTS_STATS)

        dg = Datagram()
        dg.add_server_header([STATESERVERS_CHANNEL], self.ourChannel,
                             STATESERVER_ADD_AI_RECV)
        dg.add_uint32(stats.do_id)
        dg.add_channel(self.ourChannel)
        self.send(dg)

        self.timeManager = TimeManagerAI(self)
        self.timeManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.ingameNewsMgr = DistributedInGameNewsMgrAI(self)
        self.ingameNewsMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.newsManager = NewsManagerAI(self)
        self.newsManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.friendManager = FriendManagerAI(self)
        self.friendManager.generateGlobalObject(OTP_ZONE_ID_MANAGEMENT)

        self.loadZones()

        self.district.b_setAvailable(True)
Esempio n. 8
0
    def receive_set_avatar(self, dgi):
        av_id = dgi.get_uint32()

        self.service.log.debug(
            f'client {self.channel} is setting their avatar to {av_id}')

        if not av_id:
            if self.avatar_id:
                # Client is logging out of their avatar.
                self.delete_avatar_ram()
                self.owned_objects.clear()
                self.visible_objects.clear()

                self.unsubscribe_channel(
                    getClientSenderChannel(self.account.disl_id,
                                           self.avatar_id))
                self.unsubscribe_channel(getPuppetChannel(self.avatar_id))
                self.channel = getClientSenderChannel(self.account.disl_id, 0)
                self.subscribe_channel(self.channel)

                self.state = ClientState.AUTHENTICATED
                self.avatar_id = 0
                return
            else:
                # Do nothing.
                return
        elif self.state == ClientState.PLAY_GAME:
            self.service.log.debug(
                f'Client {self.channel} tried to set their avatar {av_id} while avatar is already set to {self.avatar_id}.'
            )
            return

        pot_av = None

        for pa in self.potential_avatars:
            if pa and pa.do_id == av_id:
                pot_av = pa
                break

        if pot_av is None:
            self.disconnect(ClientDisconnect.INTERNAL_ERROR,
                            'Could not find avatar on account.')
            return

        self.avatar_id = av_id
        self.created_av_id = 0

        self.state = ClientState.SETTING_AVATAR

        self.channel = getClientSenderChannel(self.account.disl_id,
                                              self.avatar_id)
        self.subscribe_channel(self.channel)
        self.subscribe_channel(getPuppetChannel(self.avatar_id))

        dclass = self.service.dc_file.namespace['DistributedToon']

        access = 2 if self.account.access == b'FULL' else 1

        # These Fields are REQUIRED but not stored in db.
        other_fields = [(dclass['setAccess'], (access, )),
                        (dclass['setPreviousAccess'], (access, )),
                        (dclass['setAsGM'], (False, )),
                        (dclass['setBattleId'], (0, ))]

        if pot_av.approved_name:
            other_fields.append((dclass['setName'], (pot_av.approved_name, )))
            pot_av.approved_name = ''

        dg = Datagram()
        dg.add_server_header(
            [STATESERVERS_CHANNEL], self.channel,
            STATESERVER_OBJECT_CREATE_WITH_REQUIR_OTHER_CONTEXT)
        dg.add_uint32(av_id)
        dg.add_uint32(0)
        dg.add_uint32(0)
        dg.add_channel(self.channel)
        dg.add_uint16(dclass.number)
        dg.add_uint16(len(other_fields))

        for f, arg in other_fields:
            dg.add_uint16(f.number)
            f.pack_value(dg, arg)

        self.service.send_datagram(dg)