Skip to content

Commit

Permalink
Merge b673305 into 2743aba
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAFile committed May 19, 2019
2 parents 2743aba + b673305 commit 68461dc
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions piqueserver/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def on_connect(self) -> None:
self.disconnect(ERROR_BANNED)
return

self.user_types = pyspades.types.AttributeSet()
self.rights = pyspades.types.AttributeSet()

ServerConnection.on_connect(self)

def on_join(self) -> None:
Expand All @@ -88,8 +91,6 @@ def on_login(self, name: str) -> None:
self.protocol.irc_say('* %s (IP %s, ID %s) entered the game!' %
(self.name, self.address[0], self.player_id))
if self.user_types is None:
self.user_types = pyspades.types.AttributeSet()
self.rights = pyspades.types.AttributeSet()
if self.protocol.everyone_is_admin:
self.on_user_login('admin', False)

Expand Down Expand Up @@ -265,8 +266,38 @@ def on_team_join(self, team: 'FeatureTeam') -> HookValue:
return False
self.send_chat('Team is full, moved to %s' % other_team.name)
return other_team

# Add the user to their relevant groups
self.user_types.add("all")

team_usertype = None

if team is self.protocol.team_1:
team_usertype = "team_1"
elif team is self.protocol.team_2:
team_usertype = "team_2"
elif team.spectator:
team_usertype = "spectator"

if team_usertype:
# remove existing special groups
self.user_types -= {"team_1", "team_2", "spectator"}
self.user_types.add(team_usertype)

self.regenerate_rights()

self.last_switch = reactor.seconds()

def regenerate_rights(self):
"""regenerate ``self.rights`` based on the user_types of the user"""
new_rights = pyspades.types.AttributeSet()

for user_type in self.user_types:
rights = set(commands.get_rights(user_type))
new_rights.update(rights)

self.rights = new_rights

def on_chat(self, value: str, global_message: bool) -> Union[str, bool]:
"""
notifies when the server receives a chat message
Expand Down Expand Up @@ -373,8 +404,9 @@ def on_user_login(self, user_type, verbose=True):
self.send_chat("!" * 30)

self.user_types.add(user_type)
rights = set(commands.get_rights(user_type))
self.rights.update(rights)

self.regenerate_rights()

if verbose:
message = ' logged in as %s' % (user_type)
self.send_chat('You' + message)
Expand Down

0 comments on commit 68461dc

Please sign in to comment.