-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathPSO2Proxy.py
More file actions
executable file
·147 lines (126 loc) · 5.21 KB
/
PSO2Proxy.py
File metadata and controls
executable file
·147 lines (126 loc) · 5.21 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
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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
try:
from twisted.internet import epollreactor
epollreactor.install()
from twisted.internet import reactor
except ImportError:
from twisted.internet import reactor
import codecs
import commands
import config
from config import bindIp
from config import myIpAddress as myIp
import data
import locale
import os
import plugins.proxyplugins as plugin_manager
from queryProtocols import BlockScraperFactory
from queryProtocols import ShipAdvertiserFactoryPC
from queryProtocols import ShipAdvertiserFactoryVita
import sys
import time
import traceback
from twisted.internet import endpoints
from twisted.internet import stdio
from twisted.protocols import basic
from twisted.python import log
from twisted.python import logfile
useFaulthandler = True
try:
import faulthandler
except ImportError:
useFaulthandler = False
class ServerConsole(basic.LineReceiver):
def __init__(self):
self.delimiter = os.linesep
def connectionMade(self):
self.transport.write(b'>>> ')
def lineReceived(self, line):
try:
command = line.split(' ')[0]
if command != "":
if command in commands.commandList:
f = commands.commandList[command][0]
out = f(line).call_from_console()
if out is not None:
print(out)
elif command in plugin_manager.commands:
plugin_f = plugin_manager.commands[command][0]
out = plugin_f(line).call_from_console()
if out is not None:
print(out)
else:
print("[Command] Command %s not found!" % command)
except Exception as e:
e = traceback.format_exc()
print("[ShipProxy] Error Occurred: %s" % e)
self.transport.write(b'>>> ')
def main():
log_file = logfile.LogFile.fromFullPath('log/serverlog.log')
log.addObserver(log.FileLogObserver(log_file).emit)
print("===== PSO2Proxy vGIT %s =====" % config.proxy_ver)
time_string = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
print("[ServerStart] Trying to start server at %s" % time_string)
if myIp == "0.0.0.0":
print("==== ERROR 001 ====")
print("You have NOT configured the IP address for PSO2Proxy!")
print(
"Please edit cfg/pso2proxy.config.yml and change myIpAddr to your IP public IP address "
"(Not LAN address if you're on a LAN!) ")
print("After you fix this, please restart PSO2Proxy.")
sys.exit(0)
if bindIp == "0.0.0.0":
interface_ip = myIp
else:
interface_ip = bindIp
if not os.path.isfile("keys/myKey.pem"):
print("==== ERROR 002 ====")
print("You do NOT have your local RSA private key installed to 'keys/myKey.pem'!")
print("Please see README.md's section on RSA keys for more information.")
print("After you fix this, please restart PSO2Proxy.")
sys.exit(0)
if not os.path.isfile("keys/SEGAKey.pem"):
print("==== ERROR 003 ====")
print("You do NOT have a SEGA RSA public key installed to 'keys/SEGAKey.pem'!")
print("Please see README.md's section on RSA keys for more information.")
print("After you fix this, please restart PSO2Proxy.")
sys.exit(0)
for shipNum in range(0, 10):
# PSO2 Checks all ships round robin,
# so sadly for max compatibility we have to open these no matter what ships are enabled...
ship_endpoint = endpoints.TCP4ServerEndpoint(reactor, 12099 + (100 * shipNum), interface=interface_ip)
ship_endpoint.listen(ShipAdvertiserFactoryPC())
for shipNum in range(0, 10):
# PSO2 Checks all ships round robin,
# so sadly for max compatibility we have to open these no matter what ships are enabled...
ship_endpoint = endpoints.TCP4ServerEndpoint(reactor, 12094 + (100 * shipNum), interface=interface_ip)
ship_endpoint.listen(ShipAdvertiserFactoryVita())
for shipNum in config.globalConfig['enabledShips']:
query_endpoint = endpoints.TCP4ServerEndpoint(reactor, 12000 + (100 * shipNum), interface=interface_ip)
query_endpoint.listen(BlockScraperFactory())
print("[ShipProxy] Bound port %i for ship %i query server!" % ((12000 + (100 * shipNum)), shipNum))
query_endpoint = endpoints.TCP4ServerEndpoint(reactor, 13000, interface=interface_ip)
query_endpoint.listen(BlockScraperFactory())
stdio.StandardIO(ServerConsole())
print("[ShipProxy] Loading plugins...")
import glob
for plug in glob.glob("plugins/*.py"):
plug = plug[:-3]
plug = plug.replace(os.sep, '.')
print("[ShipProxy] Importing %s..." % plug)
__import__(plug)
for f in plugin_manager.onStart:
f()
reactor.suggestThreadPoolSize(30)
reactor.run()
data.clients.dbManager.close_db()
for f in plugin_manager.onStop:
f()
if __name__ == "__main__":
if not os.path.exists("log/"):
os.makedirs("log/")
if useFaulthandler:
faulthandler.enable(file=open('log/tracestack.log', 'w+'), all_threads=True)
# faulthandler.dump_traceback_later()
main()