-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
113 lines (98 loc) · 3.16 KB
/
client.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import socket
import threading
import os
def encrypted(a):
b = list(reversed(a))
c = []
s = ''
for i in range(len(b)):
c = c + [chr(ord(b[i])+120)]
for i in c:
s = s + i
return s
def decrypted(a):
b = list(a)
c = []
s = ''
for i in range(len(b)):
c = c + [chr(ord(b[i]) - 120)]
for i in list(reversed(c)):
s = s + i
return s
os.system('clear')
messages_to_display = []
print('''
┏━━━┓╋╋╋┏┓┏┓╋╋╋╋╋╋╋╋┏━━━┳┓╋╋╋╋┏┓
┃┏━┓┃╋╋┏┛┗┫┃╋╋╋╋╋╋╋╋┃┏━┓┃┃╋╋╋┏┛┗┓
┃┗━┛┣┓╋┣┓┏┫┗━┳━━┳━┓╋┃┃╋┗┫┗━┳━┻┓┏┛
┃┏━━┫┃╋┃┃┃┃┏┓┃┏┓┃┏┓┓┃┃╋┏┫┏┓┃┏┓┃┃
┃┃╋╋┃┗━┛┃┗┫┃┃┃┗┛┃┃┃┃┃┗━┛┃┃┃┃┏┓┃┗┓
┗┛╋╋┗━┓┏┻━┻┛┗┻━━┻┛┗┛┗━━━┻┛┗┻┛┗┻━┛
╋╋╋╋┏━┛┃╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋
╋╋╋╋┗━━┛╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋
''')
while True:
username = input('\t\t\t\tEnter your Name:')
if ' ' in username:
print('\t\t\t\t\033[91mInvalid Username, You are not allowed to use Space(" ")\033[0m')
else:
break
def display(messages_list):
os.system('clear')
print('\n'*40)
print('\a', end=None)
for msg in messages_list:
if msg.startswith('ø'):
author = msg.split('|')[0]
message = msg.split('|')[1]
print('\033[93m'+author[1::]+':\033[0m')
print(decrypted(message), '\n')
elif msg.startswith('∑'):
author = msg.split('|')[0]
message = msg.split('|')[1]
print('\033[96m'+author[1::]+':\033[0m')
print(decrypted(message), '\n')
else:
if msg.startswith('β'):
print('\033[90m'+msg[1::]+'\033[0m', end='\n\n')
elif msg.startswith('γ'):
print('\033[92m'+msg[1::]+'\033[0m', end='\n\n')
else:
print(msg, end='\n\n')
print('_________________________________________________________')
print('Enter Message:', end='', flush=True)
def background_thread():
global messages_to_display
while True:
message = sock.recv(2048)
y = message.decode('utf-8')
if y == '':
print('\033[91m[ERROR]The server has CRASHED!\033[0m')
break
else:
messages_to_display.append(y)
display(messages_to_display)
sock = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
name = socket.gethostname()
try:
sock.connect(('localhost' , 5050)) # change this depending on where the server is hosted
except:
print('\033[91mSorry, the Server is Currently Offline!\033[0m')
exit()
print('We have successfully connected to the host')
print('\n\n')
sock.send(bytes('α'+username, 'utf-8'))
print('\n\n')
os.system('clear')
x = threading.Thread(target = background_thread, daemon=True)
x.start()
while True:
m = input()
if m == 'exit':
sock.send(bytes('exit', 'utf-8'))
break
elif m.startswith('/w'):
encrypted_whisper = m.split()[0]+' '+m.split()[1]+' '+encrypted(' '.join(m.split()[2::]))
sock.send(bytes(encrypted_whisper, 'utf-8'))
elif m:
sock.send(bytes(encrypted(m),'utf-8'))