-
Notifications
You must be signed in to change notification settings - Fork 0
/
servermain - no shell.py
197 lines (177 loc) · 5.93 KB
/
servermain - no shell.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import concurrent.futures
import socket, time
import win32gui, win32con
the_program_to_hide = win32gui.GetForegroundWindow()
win32gui.ShowWindow(the_program_to_hide , win32con.SW_HIDE)
def createnewconvo(name,contact,ss):
try:
f = open(str(name + contact + ".chat"),"w")
f.write("\n")
ss.send(b"new file made")
f.close()
except:
return "Error"
def returner(name,ss):
contact = str((ss.recv(1024)).decode())
ss.send(b"attempting to get contact data")
try:
try:
f = open(str(name + contact + ".chat"),"r")
sendablebytes = str(f.read())
sendablebytes = sendablebytes.encode()
time.sleep(1)
ss.send(sendablebytes)
f.close()
return True
except:
f = open(str(contact + name + ".chat"),"r")
sendablebytes = str(f.read())
sendablebytes = sendablebytes.encode()
time.sleep(1)
ss.send(sendablebytes)
f.close()
return True
except:
time.sleep(1)
ss.send(b"you have no active chain messages with that contact. Creating new chain.")
choice = str(ss.recv(1024).decode())
if choice == "yes":
ret = createnewconvo(name, contact, ss)
if ret == "error":
return False
else:
return False
else:
return False
def sender(name,ss):
contact = str((ss.recv(1024)).decode())
message = ss.recv(1024).decode()
ss.send(b"attempting to send contact message data")
try:
try:
f = open(str(name + contact + ".chat"),"r")
f.close()
f = open(str(name + contact + ".chat"),"a")
f.write(str(name) + " says: \n")
f.write(str(message))
f.write("\n")
f.close()
ss.send(b"successfully sent")
return True
except:
f = open(str(contact + name + ".chat"),"r")
f.close()
f = open(str(contact + name + ".chat"),"a")
f.write(str(name) + " says: \n")
f.write(str(message))
f.write("\n")
f.close()
ss.send(b"successfully sent")
return True
except:
ss.send(b"you have no active chain messages with that contact. Creating new chain.")
choice = str(ss.recv(1024).decode())
if choice == "yes":
ret = createnewconvo(name, contact, ss)
if ret == "error":
return False
else:
return False
else:
return False
def closesocket(ss):
ss.shutdown(SHUT_RDWR)
ss.close()
def requesthandler(ss):
ss.send(b"login needed by user")
run = True
while run == True:
run2 = True
while run2 == True:
try:
choice2 = (int((ss.recv(1024)).decode()))
run2 = False
ss.send(b"int accepted")
except:
ss.send(b"must be int")
if choice2 == 1:
user = str((ss.recv(1024)).decode())
pss = str((ss.recv(1024)).decode())
result = userloginsignup(ss,user,pss)
elif choice2 == 2:
user = "sign"
pss = "up"
result = userloginsignup(ss,user,pss)
if result != False:
try:
user = result[0]
pss = result[1]
result = True
except:
result = False
if result == True:
run == False
ss.send(b"login success")
run2 = False
run = False
else:
ss.send(b"login failure")
import time
time.sleep(5)
run3 = True
while run3 == True:
choice = str((ss.recv(1024)).decode())
if choice == "1":
recvcheck = returner(user, ss)
if recvcheck != True:
ss.send(b"unable to get data.. Try again later with the correct/different contact")
if choice == "2":
recvcheck = sender(user, ss)
if recvcheck != True:
ss.send(b"unable to send the data.. Try again later with the correct/different contact")
if choice == "3":
closesocket(ss)
run3 = False
def userloginsignup(ss,user,pss):
if user == "sign" and pss == "up":
user = str(ss.recv(1024).decode())
pss = str(ss.recv(1024).decode())
try:
f = open(user + ".login","r")
f.close()
return False
except:
try:
f = open(user + ".login","w")
f.write(str(pss))
f.close()
return [user,pss]
except:
return False
else:
try:
f = open(user + ".login","r")
psc = str(f.readline())
f.close()
if psc != pss:
return False
else:
return True
except:
return False
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
hostip = "192.168.0.55"
hostport = 25565
server.bind((hostip,hostport))
print("server ready!")
print("address: " + hostip + ":" +str(25565))
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
while True:
server.listen(10)
conn, addr = server.accept()
print("someone connected adding to thread " + str(addr))
try:
executor.submit(requesthandler,conn)
except:
print("no spaces left")
server.close()