Skip to content

Commit 87cab59

Browse files
committed
Added logistical changes to complement #90
Signed-off-by: t0xic0der <akashdeep.dhar@gmail.com>
1 parent 683e00d commit 87cab59

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

cnew.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def consumer_handler(cphrsuit, websocket, username, chatroom, servaddr):
3737
elif recvdata.split(sepr)[0] == "SNCTRYZERO" and recvdata.split(sepr)[1] == "USEREXITED" and recvdata.split(sepr)[3] == chatroom:
3838
print("[" + obtntime() + "] USEREXITED > " + recvdata.split(sepr)[2] + " left - " + recvdata.split(sepr)[4] + " are connected - Indexes updated")
3939
elif recvdata.split(sepr)[0] == "SNCTRYZERO" and recvdata.split(sepr)[1] == "USERSLIST" and recvdata.split(sepr)[3] == chatroom:
40-
print("[" + obtntime() + "] USERSLIST > " + recvdata.split(sepr)[2] + " are connected")
40+
print("[" + obtntime() + "] SNCTRYZERO > " + recvdata.split(sepr)[2] + " are connected")
4141
else:
4242
recvjson = json.loads(cphrsuit.decrjson(recvdata))
4343
if recvjson["chatroom"] == chatroom and recvjson["username"] != username:
@@ -89,7 +89,7 @@ async def hello(servaddr, username, chatroom, password):
8989
print_formatted_text(HTML("[" + obtntime() + "] " + "SNCTRYZERO > <red>A connection to the server was lost</red>".format(EXPT)))
9090
raise KeyboardInterrupt
9191

92-
92+
9393
def obtntime():
9494
timestmp = time.localtime()
9595
timehour = str(timestmp.tm_hour)
@@ -127,13 +127,17 @@ def chekpass(pswd):
127127

128128

129129
def formusnm(username):
130-
if len(username) < 10: return username + " " * (10 - len(username))
131-
elif len(username) > 10: return username[0:10]
132-
else: return username
130+
if len(username) < 10:
131+
return username + " " * (10 - len(username))
132+
elif len(username) > 10:
133+
return username[0:10]
134+
else:
135+
return username
136+
133137

134138
def check_socket(servaddr):
135-
addr= [x.strip().strip("/") for x in servaddr.split(":")] #['ws',ip, port_no]
136-
if addr[0]=='ws':
139+
addr = [x.strip().strip("/") for x in servaddr.split(":")] #['ws',ip, port_no]
140+
if addr[0] == "ws":
137141
try:
138142
addr[2]= int(addr[2])
139143
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
@@ -151,6 +155,7 @@ def check_socket(servaddr):
151155
print_formatted_text(HTML("[" + obtntime() + "] " + "SNCTRYZERO > <red>Invalid protocol used, example use, 'ws://127.0.0.1:9696' </red>"))
152156
return False
153157

158+
154159
@click.command()
155160
@click.option("-u", "--username", "username", help="Enter the username that you would identify yourself with", required=True)
156161
@click.option("-p", "--password", "password", help="Enter the chatroom password for decrypting the messages")

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ def chk_username_presence(mesg_json):
5555
else:
5656
return False
5757

58+
5859
async def send_chatroommembers_list(websoc):
5960
chatroom_id = USERS[websoc][1]
6061
users_list = "SNCTRYZERO" + sepr + "USERSLIST" + sepr + str(getallus(chatroom_id)) + sepr + chatroom_id
6162
await websoc.send(users_list)
6263

64+
6365
async def chatroom(websocket, path):
6466
if not websocket in USERS:
6567
USERS[websocket] = ""

0 commit comments

Comments
 (0)