<commit_before>import blocks
import config
import packetFactory

from ships import get_ship_from_port

connectedClients = {}
"""
:type connectedClients: dict[int, ClientData]
"""


class ClientData(object):
    """docstring for ClientData"""

    def __init__(self, ip_address, segaid, ship, handle):
        self.ipAddress = ip_address
        self.segaId = segaid
        self.handle = handle
        self.ship = ship
        self.preferences = ClientPreferences(segaid)

    def get_handle(self):
        """
        :rtype : ShipProxy
        """
        return self.handle

    def set_handle(self, handle):
        self.handle = handle


class ClientPreferences():
    def __init__(self, segaid):
        self._config = config.YAMLConfig("cfg/user.preferences.yml")
        self.segaid = segaid
        if not self._config.key_exists(segaid):
            self._config.set_key(segaid, {})

    def has_preference(self, preference):
        my_preferences = self._config.get_key(self.segaid)
        if preference in my_preferences:
            return True
        else:
            return False

    def get_preference(self, preference):
        my_preferences = self._config.get_key(self.segaid)
        if self.has_preference(preference):
            return my_preferences[preference]
        else:
            return None

    def set_preference(self, preference, value):
        my_preferences = self._config.get_key(self.segaid)
        my_preferences[preference] = value
        self._config.set_key(self.segaid, my_preferences)


def add_client(handle):
    connectedClients[handle.playerId] = ClientData(handle.transport.getPeer().host, handle.myUsername.rstrip('\0'), get_ship_from_port(handle.transport.getHost().port), handle)
    print('[Clients] Registered client %s (ID:%i) in online clients' % (handle.myUsername, handle.playerId))
    if config.is_player_id_banned(handle.playerId):
        print('[Bans] Player %s (ID:%i) is banned!' % (handle.myUsername, handle.playerId))
        handle.send_crypto_packet(packetFactory.SystemMessagePacket("You are banned from connecting to this PSO2Proxy.", 0x1).build())
        handle.transport.loseConnection()<commit_msg>__getitem__ and __setitem__ for client prefrences<commit_after>import blocks
import config
import packetFactory

from ships import get_ship_from_port

connectedClients = {}
"""
:type connectedClients: dict[int, ClientData]
"""


class ClientData(object):
    """docstring for ClientData"""

    def __init__(self, ip_address, segaid, ship, handle):
        self.ipAddress = ip_address
        self.segaId = segaid
        self.handle = handle
        self.ship = ship
        self.preferences = ClientPreferences(segaid)

    def get_handle(self):
        """
        :rtype : ShipProxy
        """
        return self.handle

    def set_handle(self, handle):
        self.handle = handle


class ClientPreferences():
    def __init__(self, segaid):
        self._config = config.YAMLConfig("cfg/user.preferences.yml")
        self.segaid = segaid
        if not self._config.key_exists(segaid):
            self._config.set_key(segaid, {})

    def has_preference(self, preference):
        my_preferences = self._config.get_key(self.segaid)
        if preference in my_preferences:
            return True
        else:
            return False

    def get_preference(self, preference):
        my_preferences = self._config.get_key(self.segaid)
        if self.has_preference(preference):
            return my_preferences[preference]
        else:
            return None

    def set_preference(self, preference, value):
        my_preferences = self._config.get_key(self.segaid)
        my_preferences[preference] = value
        self._config.set_key(self.segaid, my_preferences)

    def __getitem__(self, item):
        return self.get_preference(item)

    def __setitem__(self, key, value):
        self.set_preference(key, value)


def add_client(handle):
    connectedClients[handle.playerId] = ClientData(handle.transport.getPeer().host, handle.myUsername.rstrip('\0'), get_ship_from_port(handle.transport.getHost().port), handle)
    print('[Clients] Registered client %s (ID:%i) in online clients' % (handle.myUsername, handle.playerId))
    if config.is_player_id_banned(handle.playerId):
        print('[Bans] Player %s (ID:%i) is banned!' % (handle.myUsername, handle.playerId))
        handle.send_crypto_packet(packetFactory.SystemMessagePacket("You are banned from connecting to this PSO2Proxy.", 0x1).build())
        handle.transport.loseConnection()
{'fraction_non_alphanumeric': 0.1048475542882211, 'fraction_numerical': 0.001754770783066462, 'mean_word_length': 3.164383561643836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6679782', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1360, 'n_words': 281}