forked from flyergo/PSO2Proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueryProtocols.py
More file actions
60 lines (44 loc) · 1.66 KB
/
Copy pathqueryProtocols.py
File metadata and controls
60 lines (44 loc) · 1.66 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
from config import myIpAddress
from config import noisy as verbose
import data.ships as ships
import plugins.plugins
from twisted.internet import protocol
from twisted.internet import threads
class BlockScraper(protocol.Protocol):
def __init__(self):
pass
def connectionMade(self):
port = self.transport.getHost().port
print('[BlockQuery] %s:%i wants to load-balance on port %i!' % (self.transport.getPeer().host, self.transport.getPeer().port, port))
d = threads.deferToThread(ships.get_first_block, port, myIpAddress)
d.addCallback(self.send_block_scrape)
ships.get_first_block(port, myIpAddress)
def send_block_scrape(self, data):
self.transport.write(data)
self.transport.loseConnection()
class BlockScraperFactory(protocol.Factory):
noisy = False
def __init__(self):
self.noisy = verbose
pass
def buildProtocol(self, address):
return BlockScraper()
class ShipAdvertiser(protocol.Protocol):
def __init__(self):
pass
def connectionMade(self):
for f in plugins.plugins.onQueryConnection:
f(self)
print("[ShipStatus] Client connected " + str(self.transport.getPeer()) + "! Sending ship list packet...")
d = threads.deferToThread(ships.get_ship_query, myIpAddress)
d.addCallback(self.send_ship_list)
def send_ship_list(self, data):
self.transport.write(data)
self.transport.loseConnection()
class ShipAdvertiserFactory(protocol.Factory):
noisy = False
def __init__(self):
self.noisy = verbose
pass
def buildProtocol(self, address):
return ShipAdvertiser()