Skip to content

Commit

Permalink
Merge 64c62d2 into eb84df8
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAFile committed May 21, 2019
2 parents eb84df8 + 64c62d2 commit 57767ff
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
8 changes: 7 additions & 1 deletion piqueserver/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ default_duration = "1day"


[rights]
# Rights allow you to specify the roles available and what permissions they have
# Rights allow you to specify the roles available and what permissions they have.
# Role names are arbitrary. For a user to gain one of the below roles, they
# must /login with a password given in the corresponding passwords list.
#
# Special built-in roles include `team_1`, `team_2`, `spectator`, and `all`
# (self explanatory). The server automatically manages these roles for users,
# and rights for these roles can be given below too.
moderator = [
"advancemap", "cancel", "dban", "fog",
"from", "hackinfo", "hban",
Expand Down
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 57767ff

Please sign in to comment.