GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 83a854...4f119b )
by Michael
01:14
created

server.Player.__init__()   C

Complexity

Conditions 7

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 7
dl 0
loc 42
rs 5.5
1
import weakref
2
3
from enum import IntEnum, unique
4
5
from .abc.base_player import BasePlayer
0 ignored issues
show
Bug introduced by
The name base_player does not seem to exist in module abc.
Loading history...
Configuration introduced by
The import abc.base_player could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
6
7
@unique
8
class PlayerState(IntEnum):
9
    IDLE = 1,
10
    PLAYING = 2,
11
    HOSTING = 3,
12
    JOINING = 4,
13
    SEARCHING_LADDER = 5,
14
15
class Player(BasePlayer):
16
    """
17
    Standard player object used for representing signed-in players.
18
19
    In the context of a game, the Game object holds game-specific
20
    information about players.
21
    """
22
    def __init__(self, login=None, session=0, ip=None, port=None, id=0,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
23
                 global_rating=None, ladder_rating=None, clan=None, numGames=0, permissionGroup=0, lobby_connection=None):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (122/120).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
24
        super().__init__(id, login)
25
26
        # The id of the user in the `login` table of the database.
27
        self.session = session
28
        self.ip = ip
29
        self._game_port = port
30
31
        if global_rating is None:
32
            global_rating = (1500, 500)
33
        if ladder_rating is None:
34
            ladder_rating = (1500, 500)
35
        self.global_rating = global_rating
36
        self.ladder_rating = ladder_rating
37
38
        #social
39
        self.avatar = None
40
        self.clan = clan
41
        self.country = None
42
43
        self.friends = set()
44
        self.foes = set()
45
46
        self.league = None
47
48
        self.admin = permissionGroup >= 2
49
        self.mod = permissionGroup >= 1
50
        
51
        self.numGames = numGames
52
53
        self.state = PlayerState.IDLE
54
55
        self.expandLadder = 0
56
        self.faction = 1
57
58
        self._lobby_connection = lambda: None
59
        if lobby_connection is not None:
60
            self.lobby_connection = lobby_connection
61
62
        self._game = lambda: None
63
        self._game_connection = lambda: None
64
65
    def getAddress(self):
66
        return "%s:%s" % (str(self.ip), str(self.game_port))
67
68
69
    @property
70
    def lobby_connection(self) -> "LobbyConnection":
71
        """
72
        Weak reference to the LobbyConnection of this player
73
        """
74
        return self._lobby_connection()
75
76
    @lobby_connection.setter
77
    def lobby_connection(self, value: "LobbyConnection"):
78
        self._lobby_connection = weakref.ref(value)
79
80
    @property
81
    def game(self):
82
        """
83
        Weak reference to the Game object that this player wants to join or is currently in
84
        """
85
        return self._game()
86
87
    @game.setter
88
    def game(self, value):
89
        self._game = weakref.ref(value)
90
91
    @game.deleter
92
    def game(self):
93
        self._game = lambda: None
94
95
    @property
96
    def game_connection(self):
97
        """
98
        Weak reference to the GameConnection object for this player
99
        :return:
100
        """
101
        return self._game_connection()
102
103
    @game_connection.setter
104
    def game_connection(self, value):
105
        self._game_connection = weakref.ref(value)
106
107
    @game_connection.deleter
108
    def game_connection(self):
109
        self._game_connection = lambda: None
110
111
    @property
112
    def in_game(self):
113
        return self.game is not None
114
115
    @property
116
    def game_port(self):
117
        return self._game_port or 6112
118
119
    @game_port.setter
120
    def game_port(self, value):
121
        self._game_port = value
122
123
    @property
124
    def address_and_port(self):
125
        return "{}:{}".format(self.ip, self.game_port)
126
127
    def notify_potential_match(self, player, potential):
0 ignored issues
show
Unused Code introduced by
The argument player seems to be unused.
Loading history...
128
        if self.lobby_connection:
129
            self.lobby_connection.sendJSON({
130
                'command': 'matchmaker_info',
131
                'potential': potential
132
            })
133
134
    def to_dict(self):
135
        """
136
        Return a dictionary representing this player object
137
        :return:
138
        """
139
        def filter_none(t):
140
            _, v = t
141
            return v is not None
142
        return dict(filter(filter_none, (
143
            ('id', self.id),
0 ignored issues
show
Bug introduced by
The Instance of Player does not seem to have a member named id.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
144
            ('login', self.login),
0 ignored issues
show
Bug introduced by
The Instance of Player does not seem to have a member named login.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
145
            ('global_rating', self.global_rating),
146
            ('ladder_rating', self.ladder_rating),
147
            ('number_of_games', self.numGames),
148
            ('avatar', self.avatar),
149
            ('country', self.country),
150
            ('clan', self.clan)
151
        )))
152
153
    def __str__(self):
154
        return "Player({}, {}, {}, {})".format(self.login, self.id, self.global_rating, self.ladder_rating)
0 ignored issues
show
Bug introduced by
The Instance of Player does not seem to have a member named login.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of Player does not seem to have a member named id.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
155
156
    def __repr__(self):
157
        return self.__str__()
158
159
    def __hash__(self):
160
        return self.id
0 ignored issues
show
Bug introduced by
The Instance of Player does not seem to have a member named id.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
161
162
    def __eq__(self, other):
163
        if not isinstance(other, BasePlayer):
164
            return False
165
        else:
166
            return self.id == other.id
0 ignored issues
show
Bug introduced by
The Instance of Player does not seem to have a member named id.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
167