Difference between revisions of "Proxies"

From wiki.vg
Jump to navigation Jump to search
(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...")
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Proxies =
+
= How does a proxy work? =
 
 
== 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.
 
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? ==
+
= How do the popular ones work? =
  
Currently, the most popular proxy implementations of proxies are [https://github.com/VelocityPowered/Velocity Velocity] and [https://github.com/SpigotMC/BungeeCord 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:
+
Currently, the most popular proxy implementations of proxies are [https://github.com/VelocityPowered/Velocity Velocity] and [https://github.com/SpigotMC/BungeeCord BungeeCord]. 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:
  
 
<syntaxhighlight lang="js">server = new Server(/* this will be the player facing server */)
 
<syntaxhighlight lang="js">server = new Server(/* this will be the player facing server */)
Line 16: Line 14:
 
   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
 
   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
 
})</syntaxhighlight>
 
})</syntaxhighlight>
Although shown in the example, you don’t necessarily have to modify the packets, you can just send the raw packets.
+
Although shown in the example, you don’t necessarily have to modify the packets, you can just send the raw packets. One thing you do have to do is handle that the Entity IDs are different, this is where one of the differences between Velocity and BungeeCord comes into play, BungeeCord rewrites all the Entity IDs and Velocity respawns you twice to reset your Entity ID.
 +
 
 +
[[Category:Minecraft Modern]]

Latest revision as of 18:44, 26 February 2024

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 BungeeCord. 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. One thing you do have to do is handle that the Entity IDs are different, this is where one of the differences between Velocity and BungeeCord comes into play, BungeeCord rewrites all the Entity IDs and Velocity respawns you twice to reset your Entity ID.