Beispiel #1
0
    def online(self):
        try:
            index_from_uniqueid(self.uniqueid)
        except ValueError:
            return False

        return True
Beispiel #2
0
    def __init__(self, uniqueid):
        self._uniqueid = uniqueid
        self._races = _RaceContainer(self)
        self._items = _ItemContainer(self)
        self._userid = None
        self._index = None
        self._player = None
        self._ready = False
        self._is_bot = uniqueid.startswith('BOT_')
        self._privileges = privileges['players'].get(uniqueid, {})

        self._id = None
        self._name = None
        self._current_race = None
        self._lastconnect = None

        self.data = {}

        try:
            self._index = index_from_uniqueid(uniqueid)
        except ValueError:
            name = None
        else:
            self._userid = userid_from_index(self._index)

            Player._cache_userids[self.userid] = self
            Player._cache_indexes[self.index] = self

            name = playerinfo_from_index(self.index).name

        if not _thread.unloading:
            database_manager.execute('player get', (uniqueid, ),
                                     callback=self._query_get_player,
                                     name=name)
Beispiel #3
0
def on_player_rank_update(wcsplayer, old, new):
    if cfg_top_announcement_enable.get_int():
        min_rank = cfg_top_min_rank_announcement.get_int()

        if not min_rank or new <= min_rank:
            if cfg_top_public_announcement.get_int():
                top_public_announcement_message.send(
                    name=wcsplayer.name,
                    min_rank=min_rank if min_rank else '',
                    old=old + 1,
                    new=new + 1)
            else:
                if not wcsplayer._is_bot:
                    top_private_announcement_message.send(
                        wcsplayer.index,
                        min_rank=min_rank if min_rank else '',
                        old=old + 1,
                        new=new + 1)

        if new < old:
            if cfg_top_stolen_notify.get_int():
                for i, uniqueid in enumerate(rank_manager[new + 1:old + 1]):
                    try:
                        index = index_from_uniqueid(uniqueid)
                    except ValueError:
                        pass
                    else:
                        top_stolen_notify_message.send(index,
                                                       name=wcsplayer.name,
                                                       old=new + i,
                                                       new=new + i + 1)
Beispiel #4
0
 def from_uniqueid(cls, uniqueid):
     try:
         index = index_from_uniqueid(uniqueid)
     except ValueError:
         return cls(uniqueid)
     else:
         return cls(index)
Beispiel #5
0
    def _query_save(self, result):
        # We don't want them to have previous data
        # This has to be done here, as it'll cause errors if it's done in OnClientDisconnect
        self.data.clear()

        _save_queue.discard(self.uniqueid)

        try:
            self._index = index_from_uniqueid(self.uniqueid)
        except ValueError:
            OnPlayerDestroy.manager.notify(self)
        else:
            self._baseplayer = BasePlayer(self._index)

            Player._players[self.index] = self

            Player._reconnect_cache[self.uniqueid] = self

            on_client_authorized(self._baseplayer)

            if self.ready:
                if self.active_race.settings.usable_by(
                        self) is not RaceReason.ALLOWED or (
                            self.fake_client
                            and cfg_bot_random_race.get_int()):
                    usable_races = self.available_races

                    if not usable_races:
                        self._ready = False

                        raise RuntimeError(
                            f'Unable to find a usable race to "{self.name}".')

                    self._current_race = choice(usable_races)

                OnPlayerQuery.manager.notify(self)

                team = self.player.team_index

                if team >= 2:
                    key = f'_internal_{self._current_race}_limit_allowed'

                    if key not in team_data[team]:
                        team_data[team][key] = []

                    team_data[team][key].append(self.userid)

                OnPlayerReady.manager.notify(self)
Beispiel #6
0
    def _query_save(self, result):
        # We don't want them to have previous data
        # This has to be done here, as it'll cause errors if it's done in OnClientDisconnect
        self.data.clear()

        try:
            self._index = index_from_uniqueid(self.uniqueid)
        except ValueError:
            OnPlayerDestroy.manager.notify(self)

            del Player._players[self.uniqueid]

            self._userid = None
            self._index = None
        else:
            self._userid = userid_from_index(self.index)