--- permalink: /posts/writeups/5 title: Implementing a CK3 Private Peer-to-Peer Multiplayer Server - Part 2- Implememting a Minimal Server categories: - Write Up tags: - write up - ck3 - mitm - reverse engenering layout: default.liquid is_draft: true --- # Implementing a CK3 Private Peer-to-Peer Multiplayer Server - Part 3 - Minimal Intermediary Server Now that we have an understanding of the architecture, the next step is to create our server emulator by building a minimal server that simply forwards requests to and from the real server. This will allow us to begin implementing our logic by simulating the requests sent to the server with our own implementation and comparing them to the normal execution. Eventually, once we're confident that the simulated requests are accurate, we will switch to our own logic and stop forwarding requests. By that point, we hope our server emulator will be robust enough to function properly. ## MITM redirection to localhost To redirect the requests we the MITM proxies describe [Part 2](/posts/writeups/4) but with script the redirect he request of the multiplayer to to our own server running on localhost on port 3030. ```python from mitmproxy import ctx import mitmproxy.http class LocalRedirect: def __init__(self): print("Loaded redirect addon") def request(self, flow: mitmproxy.http.HTTPFlow): if "ck3-new.online.paradox-interactive.com" in flow.request.pretty_host and "/ws" in flow.request.url: ctx.log.info(f"pretty host is: %s" % flow.request.pretty_host) ctx.log.info(f"url: %s" % flow.request.url) flow.request.host = "localhost" flow.request.port = 3030 flow.request.scheme = "http" addons = [LocalRedirect()] ``` ## Server implementation For server implenent we choose to implent it in rust using wrap, ```rust ```