-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUser.py
More file actions
51 lines (40 loc) · 1.23 KB
/
User.py
File metadata and controls
51 lines (40 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from Chatroom import chatroom
class user():
chatrooms = []
def __init__(self, username, conn):
self.username = username
self.connection = conn
self.permanentUser = False
self.chatrooms = []
# Returns the name of this user
def get_username(self):
return self.username
# Returns the socket of this user
def get_connection(self):
return self.connection
# Sets the socket of this user
# Used for when a permanent user goes offline (set to None) or comes back online
def set_connection(self, conn):
self.connection = conn
# Returns true if permanent user, or false if guest
def get_permanent_user(self):
return self.permanentUser
# Registers a user
def make_permanent(self):
self.permanentUser = True
# Get a list of all chatrooms this user is part of
def get_chatrooms(self):
return self.chatrooms[:]
# Appends the chatroom to the list of chatrooms.
# Returns false if user is already in the room
def add_chatroom(self,room):
if room in self.chatrooms:
return False
self.chatrooms.append(room)
return True
# Removes the chatroom from this user's list of chatrooms
def leave_chatroom(self,room):
if room not in self.chatrooms:
return False
self.chatrooms.remove(room)
return True