Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
DefaultCert = cert/server.crt
DefaultKey = cert/server.key

[CENTRAL]
CentralIP = 0.0.0.0
CentralCrossconnectPort = 8300
CrossconnectSSL = ON

[SERVER1]
Name = Valor1
ServerType = 1
Capacity = 400
IP = 0.0.0.0
Port = 8204

[SERVER2]
Name = Greed1
ServerType = 4
Capacity = 400
IP = 0.0.0.0
Port = 8205

[OPN]
IP = 0.0.0.0
Port = 8200
Expand Down
16 changes: 14 additions & 2 deletions fmp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import struct

from mh.state import Players, get_instance
import mh.pat_item as pati
from mh.constants import PatID4
from mh.pat import PatRequestHandler, PatServer
Expand All @@ -14,7 +15,9 @@

class FmpServer(PatServer):
"""Basic FMP server class."""
pass
def close(self):
PatServer.close(self)
get_instance().close_cache()


class FmpRequestHandler(PatRequestHandler):
Expand All @@ -24,7 +27,16 @@ def recvAnsConnection(self, packet_id, data, seq):
"""AnsConnection packet."""
connection_data = pati.ConnectionData.unpack(data)
self.server.debug("Connection: {!r}".format(connection_data))
self.sendNtcLogin(3, connection_data, seq)
loaded_session = self.session.session_ready(connection_data)
if loaded_session:
if get_instance().server_id != 0:
self.session.set_session_ready(connection_data, False)
loaded_session.connection = self
self.session = loaded_session
get_instance().register_pat_ticket(self.session)
self.sendNtcLogin(3, connection_data, seq)
else:
self.session.set_session_ready(connection_data, (self, connection_data, seq))

def sendAnsLayerDown(self, layer_id, layer_set, seq):
"""AnsLayerDown packet.
Expand Down
33 changes: 24 additions & 9 deletions master_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,40 @@
from other.debug import register_debug_signal
from other.utils import create_server_from_base

from other.cache import Cache

def create_servers(silent=False, debug_mode=False):
def create_servers(server_id, silent=False, debug_mode=False, no_timeout=False):
"""Create servers and check if it has ui."""
servers = []
has_ui = False
for module in (OPN, LMP, FMP, RFP):
for module in ((OPN, LMP, FMP, RFP) if server_id==0 else (FMP,)):
server, has_window = create_server_from_base(*module.BASE,
server_id=server_id,
Comment on lines +24 to +26
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hackish and most likely have better places where they could be integrated (a proper config file, might be needed).

silent=silent,
debug_mode=debug_mode)
debug_mode=debug_mode,
no_timeout=no_timeout)
has_ui = has_ui or has_window
servers.append(server)
return servers, has_ui


def main(args):
"""Master server main function."""
register_debug_signal()

servers, has_ui = create_servers(silent=args.silent,
debug_mode=args.debug_mode)
servers, has_ui = create_servers(server_id=args.server_id,
silent=args.silent,
debug_mode=args.debug_mode,
no_timeout=args.no_timeout)
threads = [
threading.Thread(
target=server.serve_forever,
name="{}.serve_forever".format(server.__class__.__name__)
)
for server in servers
]
cache = Cache(server_id=args.server_id, debug_mode=args.debug_mode,
log_to_file=True, log_to_console=not args.silent,
log_to_window=False)
threads.append(threading.Thread(target=cache.maintain_connection))
for thread in threads:
thread.start()

Expand Down Expand Up @@ -92,7 +99,15 @@ def interactive_mode(local=locals()):
help="silent console logs")
parser.add_argument("-d", "--debug_mode", action="store_true",
dest="debug_mode",
help="enable debug mode, disabling timeouts and \
lower logging verbosity level")
help="enable debug mode, \
raising logging verbosity level")
parser.add_argument("-t", "--no_timeout", action="store_true",
dest="no_timeout",
help="disable player timeouts")
parser.add_argument("-S", "--server_id", type=int, default=0,
dest="server_id",
help="specifies the server id used to pull info \
from the config file (0 for central)")

args = parser.parse_args()
main(args)
8 changes: 7 additions & 1 deletion mh/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,16 @@ def slot(item, qty):
b"Roadmap for a list of features we are working on.",
b"<BR><CENTER><C=2>Welcome to Loc Lac!<END>"
])
MAINTENANCE = b"<BR><BODY>".join([
b"<BR><CENTER><BODY><SIZE=6>Monster Hunter 3 (Tri) Server Project",
b"<BR><CENTER><SIZE=4>MH3SP is currently down for maintenance.",
b"<BR><CENTER><C=2>Please check back later!<END>"
])
CHARGE = b"""<BODY><CENTER>MH3 Server Project - No charge.<END>"""
# VULGARITY_INFO = b"""MH3 Server Project - Vulgarity info (low)."""
VULGARITY_INFO = b""
FMP_VERSION = 1
FMP_CENTRAL_VERSION = 1
FMP_VERSION = 2

TIME_STATE = 0
IS_JAP = False
Expand Down
Loading