syncplay/syncplayServer.py

69 lines
1.9 KiB
Python
Raw Normal View History

2018-07-20 17:21:52 +00:00
#!/usr/bin/env python3
2012-10-12 16:37:12 +00:00
#coding:utf8
import socket
2018-06-19 21:24:24 +00:00
import sys
2013-12-18 06:33:39 +00:00
# libpath
try:
if (sys.version_info.major != 3) or (sys.version_info.minor < 4):
raise Exception("You must run Syncplay with Python 3.4 or newer!")
except AttributeError:
import warnings
warnings.warn("You must run Syncplay with Python 3.4 or newer!")
2014-06-19 18:31:49 +00:00
from twisted.internet import reactor
from twisted.internet.endpoints import TCP4ServerEndpoint, TCP6ServerEndpoint
from twisted.internet.error import CannotListenError
2012-10-12 16:37:12 +00:00
from syncplay.server import SyncFactory, ConfigurationGetter
class ServerStatus: pass
def isListening6(f):
ServerStatus.listening6 = True
def isListening4(f):
ServerStatus.listening4 = True
def failed6(f):
ServerStatus.listening6 = False
print(f.value)
print("IPv6 listening failed.")
def failed4(f):
ServerStatus.listening4 = False
if f.type is CannotListenError and ServerStatus.listening6:
pass
else:
print(f.value)
print("IPv4 listening failed.")
if __name__ == '__main__':
argsGetter = ConfigurationGetter()
args = argsGetter.getConfiguration()
2019-02-03 15:30:20 +00:00
factory = SyncFactory(
args.port,
args.password,
args.motd_file,
args.isolate_rooms,
args.salt,
args.disable_ready,
args.disable_chat,
args.max_chat_message_length,
args.max_username_length,
args.stats_db_file,
args.tls
2019-02-03 15:30:20 +00:00
)
endpoint6 = TCP6ServerEndpoint(reactor, int(args.port))
endpoint6.listen(factory).addCallbacks(isListening6, failed6)
endpoint4 = TCP4ServerEndpoint(reactor, int(args.port))
endpoint4.listen(factory).addCallbacks(isListening4, failed4)
if ServerStatus.listening6 or ServerStatus.listening4:
reactor.run()
else:
print("Unable to listen using either IPv4 and IPv6 protocols. Quitting the server now.")
sys.exit()