Archived
0

SpawnPosition

This commit is contained in:
2018-04-19 08:18:00 +03:00
parent 848f6c02e6
commit f839be6079
3 changed files with 41 additions and 23 deletions

View File

@@ -3,24 +3,6 @@
* 2018-04-10
*/
/*
http://wiki.vg/index.php?title=Protocol_FAQ&oldid=76
-- -- --
C - Client
S - Server
-- -- --
C -> S : Connects
C -> S : Sends handshake
S -> C : Sends handshake response
C -> S : After authenticating (if needed), sends the login packet
S -> C : Either kicks (invalid login) or sends a login response
S -> C : Sends pre-chunks and chunks and entities
S -> C : Sends spawn position
S -> C : Sends inventory [Need to verify this since inventory changed] (beta 1.1_02: looks like Window items with type=0, then a Set slot with window id = -1 and slot = -1)
S -> C : Tell the client they're ready to spawn by sending a position + look packet. Note: The stance and Y should be swapped when the server sends it to the client
C -> S : Sends a position + look packet to confirm the spawn position, with the stance and Y swapped back to the correct positions
*/
package mc.core.network.proto_125.netty;
import io.netty.channel.Channel;
@@ -77,19 +59,26 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
public void onLoginPacket(Channel channel, LoginPacket packet) {
int pId = random.nextInt(9999);
Location spawnLoc = new Location(0, 65, 0);
NettyPlayer player = new NettyPlayer();
player.setId(pId);
player.setName(packet.getPlayerName());
player.setChannel(new WrapperNetChannel(channel));
// Response login
packet.setPlayerId(pId);
packet.setLevelType("FLAT");
packet.setLevelType("flat");
packet.setServerMode(1/*creative*/);
packet.setDimension(0/*Overworld*/);
packet.setDifficulty(0/*Peaceful*/);
packet.setMaxPlayers(config.getMaxPlayers());
channel.write(packet);
NettyPlayer player = new NettyPlayer();
player.setId(pId);
player.setName(packet.getPlayerName());
player.setChannel(new WrapperNetChannel(channel));
// send Spawn position
SpawnPositionPacket spawnPkt = new SpawnPositionPacket();
spawnPkt.setLocation(spawnLoc);
channel.write(spawnPkt);
PositionAndLookPacket pkt = new PositionAndLookPacket();
pkt.setLocation(new Location(0, 0, 0));

View File

@@ -14,6 +14,7 @@ public class PacketManager {
private static final BiMap<Integer, Class<?>> packetMap = ImmutableBiMap.<Integer, Class<?>>builder()
.put(0x01, LoginPacket.class)
.put(0x02, HandshakePacket.class)
.put(0x06, SpawnPositionPacket.class)
.put(0x0D, PositionAndLookPacket.class)
.put(0xFE, PingPacket.class)
.put(0xFF, KickPacket.class)

View File

@@ -0,0 +1,28 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2018-04-19
*/
package mc.core.network.proto_125.packets;
import lombok.Setter;
import lombok.ToString;
import mc.core.Location;
import mc.core.network.SCPacket;
import mc.core.network.proto_125.ByteArrayOutputNetStream;
@Setter
@ToString
public class SpawnPositionPacket implements SCPacket {
private Location location;
@Override
public byte[] toByteArray() {
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
netStream.writeInt((int) location.getX());
netStream.writeInt((int) location.getY());
netStream.writeInt((int) location.getZ());
return netStream.toByteArray();
}
}