Proxies

From wiki.vg
Revision as of 20:51, 20 August 2021 by U9G (talk | contribs) (Created page with "= Proxies = == How does a proxy work? == Proxies will often stand in the middle of a client and server, and can be used for many reasons, such as bridging two unsupported cl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Proxies

How does a proxy work?

Proxies will often stand in the middle of a client and server, and can be used for many reasons, such as bridging two unsupported client versions so they understand each other, or to simply allow one client to connect to many other servers without knowing all of their IPs.

How do the popular ones work?

Currently, the most popular proxy implementations of proxies are Velocity and Bungee. They work by having the the proxy start the server that is public facing, then having the proxy make the connections to the play server itself and relay the packets, in this way the proxy can change packets before they hit either the actual server or the player’s client. In a simple sense, this is what the code looks like very-oversimplified:

server = new Server(/* this will be the player facing server */)

server.on('connect', client => { // when a client connects to the player facing server
  serverClient = new Client(/* this will connect to the actual server */) // we make a new client that connects to our internal server
  client.on('packet', packet => serverClient.send(modifyC2S(packet))) // when our player facing server receives a packet, we relay that packet to the server after modifying the packet
  serverClient.on('packet', packet => server.send(modifyS2C(packet))) // when our internal server wants to send a packet to the client, we relay that packet to the client after modifying it
})

Although shown in the example, you don’t necessarily have to modify the packets, you can just send the raw packets.