-
Notifications
You must be signed in to change notification settings - Fork 1
/
prog.py
49 lines (42 loc) · 1.46 KB
/
prog.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
from twisted.internet import protocol, error
from log import out
class Prog(protocol.ProcessProtocol):
"""
Program/process-side protocol
"""
def __init__(self, user):
self.user = user
self.state = 0
def connectionMade(self):
self.state = 1
def childDataReceived(self, fd, data):
if fd == 1:
self.dataReceived(data)
elif fd == 2:
self.errReceived(data)
def dataReceived(self, data):
if self.state is 1 and self.user.state is 1:
self.user.log.write(data)
self.user.send(data)
def send(self, data):
self.transport.write(data)
def errReceived(self, data):
"""
Errors should be logged and outputed
"""
self.user.log.write("ERROR: " + data)
out.write("{}'s process has errored: {}".format(self.user.name, data))
def processEnded(self, reason):
self.state = 2
if self.user.state is 1:
if reason.check(error.ProcessDone):
#Is it done?
quitmsg = 'cleanly'
else:
quitmsg = 'with errors!'
reason.printDetailedTraceback(self.user.log)
self.user.transport.write('You seem to of have crashed your '
'game, you insensitive clod!')
self.user.log.write("Ended", quitmsg)
out.write(self.user.name + "'s process has ended", quitmsg)
self.user.state = 2