Skip to content

Commit

Permalink
fixing chatserver when getting usertag before posting a message
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFola committed Jan 27, 2021
1 parent d2829dc commit e7a3d9c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/chatserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def __str__(self):


class User:
def __init__(self, key: str, ip: str):
self.key = key
def __init__(self, name: str, ip: str):
self.name = name
self.ip = ip
self.created_at = time.time()

Expand Down Expand Up @@ -104,11 +104,13 @@ def check_command(self, msg: str, ip: str) -> str:
self.messages = self.messages[-int(MESSAGE_LIMIT / 1000 + 1):]

usertag, *data = msg.split(' ')
# remove the @
usertag = usertag[1:]
if usertag not in self.users:
return ERROR_UNKNOWN_USERTAG
else:
self.messages.append(
Message(usertag, " ".join(data))
Message(self.users[usertag].name, " ".join(data))
)
return "OK."
else:
Expand Down

0 comments on commit e7a3d9c

Please sign in to comment.