-
Notifications
You must be signed in to change notification settings - Fork 0
/
connections.py
41 lines (33 loc) · 1.08 KB
/
connections.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
from twisted.internet.protocol import Factory
from twisted.internet.protocol import ClientFactory
from twisted.internet.protocol import Protocol
from twisted.internet import reactor
import sys
#normal player factory
class PlayerFactory(Factory):
def __init__(self, pNum, poke):
self.playerConn = PlayerConnection(pNum, poke)
def buildProtocol(self, addr):
return self.playerConn
class PlayerConnection(Protocol):
def __init__(self, pNum, poke):
self.connected = 0
self.pNum = pNum
self.poke = poke
self.inp = ""
def connectionMade(self):
print "Connection made."
self.connected = 1
def dataReceived(self, data):
if data.startswith("getPoke"):
self.transport.write(self.poke)
elif data == "special":
self.inp = "special"
else:
self.inp = data
#client player factory
class PlayerCFactory(ClientFactory):
def __init__(self, pNum, poke):
self.playerConn = PlayerConnection(pNum, poke)
def buildProtocol(self, addr):
return self.playerConn