-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path@Brook2.py
More file actions
74 lines (54 loc) · 1.87 KB
/
@Brook2.py
File metadata and controls
74 lines (54 loc) · 1.87 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import socket
import threading as th
from colorama import *
# socket.gethostname() = "Client-3"
nick = '<Brook2>'
init()
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# trying to connect to server
try:
client.connect(("127.0.0.1", 9898))
print(Fore.LIGHTBLUE_EX+nick+Fore.RESET+Fore.GREEN+" you are online now\n"+Fore.RESET)
except:
print(Fore.RED+"SERVER OFFLINE"+Fore.RESET)
exit()
# to get all the messages continously
def recv_msg():
while True:
try:
msg = client.recv(1024).decode()
if msg == 'nick':
client.send(nick.encode())
elif "CLoSuR3 has occured" in msg:
msg = msg.replace("<", "")
msg = msg.replace(">", "")
msg = msg.split()[0]
msg = "[OFFLINE]"+" @"+msg
msg = msg.split()
msg = Fore.LIGHTYELLOW_EX+msg[0]+Fore.RESET+Fore.RED+" "+msg[1]+Fore.RESET
print(msg)
elif "ac @" in msg:
msg = msg[msg.find('ac ')+3:]
msg = msg.replace("<", "")
msg = msg.replace(">", "")
msg = "[ONLINE]"+" "+msg
msg = msg.split()
msg = Fore.LIGHTYELLOW_EX+msg[0]+Fore.RESET+Fore.BLUE+" "+msg[1]+Fore.RESET
print(msg)
else:
msg = msg.split(">")
print(Fore.RED+msg[0][1:]+Fore.RESET+ msg[1])
except:
client.close()
break
def server_send():
while True:
sn = input()
# nothing input
if len(sn) == 0:
continue
client.send(sn.encode())
recv_thread = th.Thread(target=recv_msg)
recv_thread.start()
server_send_thread = th.Thread(target=server_send)
server_send_thread.start()