-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (64 loc) · 2.55 KB
/
main.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
#!/usr/bin/env python
# coding: utf-8
from functions import *
version = "1.0.9"
check_cfg()
check_db()
class ClientThread(threading.Thread):
def __init__(self, ip, port, clientsocket):
threading.Thread.__init__(self)
self.ip = ip
self.port = port
self.clientsocket = clientsocket
def run(self):
print("Connection de %s %s" % (self.ip, self.port,))
r = self.clientsocket.recv(1024)
received_message = pickle.loads(r)
print("Reçu {}".format(received_message))
command = str(received_message[0])
if command == "login":
login(received_message, self)
if command == "register":
register(received_message, self)
if command == "sendmsg":
sendmsg(received_message, self)
if command == "loadidslist":
loadidslist(received_message, self)
if command == "get_msg":
get_msg(received_message, self)
if command == "connexion_channel":
channel = received_message[1]
tablename = "channel_" + channel
password = received_message[2]
a = check_channel(tablename, self)
b = check_password_channel(channel, password, self)
if a is True and b is True:
self.clientsocket.send(pickle.dumps(True))
elif a is False or b is False:
self.clientsocket.send(pickle.dumps(False))
if command == "new_channel":
new_channel(received_message, self)
if command == "get_chan_name":
id = str(received_message[1])
chan_name = get_chan_name(id)
self.clientsocket.send(pickle.dumps(chan_name))
if command == "del_channel":
del_channel(received_message, self)
if command == "clear_channel":
clear_channel(received_message, self)
if command == "check_version":
clientversion = received_message[1]
if clientversion == version:
self.clientsocket.send(pickle.dumps(True))
else:
self.clientsocket.send(pickle.dumps(False))
if command == "rename_chan":
rename_chan(received_message, self)
tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcpsock.bind((readcfg(['SOCKET', 'host']), int(readcfg(['SOCKET', 'port']))))
while True:
tcpsock.listen(10)
(clientsocket, (ip, port)) = tcpsock.accept()
newthread = ClientThread(ip, port, clientsocket)
newthread.start()