Skip to content

Commit

Permalink
Make protocol version field public
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Oct 2, 2021
1 parent 366be0b commit 6317f0e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions MCGalaxy/Blocks/Block.Convert.cs
Expand Up @@ -99,7 +99,7 @@ public static partial class Block {
case Crate: block = Wood; break;
case StoneBrick: block = Stone; break;
}
if (p.version >= Server.VERSION_0030) return block;
if (p.ProtocolVersion >= Server.VERSION_0030) return block;

// protocol version 6 only supports up to Gold block
switch (block) {
Expand All @@ -112,13 +112,13 @@ public static partial class Block {
case MossyRocks: block = Cobblestone; break;
case Obsidian: block = Cobblestone; break;
}
if (p.version >= Server.VERSION_0020) return block;
if (p.ProtocolVersion >= Server.VERSION_0020) return block;

// protocol version 5 only supports up to Glass block
if (block == Block.Gold) block = Block.Sponge;
if (block >= Block.Dandelion) block = Block.Sapling;
if (block >= Block.Red) block = Block.Sand;
if (p.version >= Server.VERSION_0019) return block;
if (p.ProtocolVersion >= Server.VERSION_0019) return block;

// protocol version 4 only supports up to Leaves block
if (block == Block.Glass) block = Block.Leaves;
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/Moderation/ModActionCmd.cs
Expand Up @@ -89,7 +89,7 @@ public static class ModActionCmd {

Entities.DespawnEntities(who, false);
// this packet doesn't exist before protocol version 7
if (who.version >= Server.VERSION_0030)
if (who.ProtocolVersion >= Server.VERSION_0030)
who.Send(Packet.UserType(who.UserType()));

who.SendCurrentBlockPermissions();
Expand Down
4 changes: 2 additions & 2 deletions MCGalaxy/Network/Packets/Packet.cs
Expand Up @@ -29,10 +29,10 @@ public static class Packet
#region Classic

public static byte[] Motd(Player p, string motd) {
bool type = p.version >= Server.VERSION_0020;
bool type = p.ProtocolVersion >= Server.VERSION_0020;
byte[] buffer = new byte[130 + (type ? 1 : 0)];
buffer[0] = Opcode.Handshake;
buffer[1] = p.version;
buffer[1] = p.ProtocolVersion;

if (motd.Length > NetUtils.StringSize) {
NetUtils.Write(motd, buffer, 2, p.hasCP437);
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Network/Utils/BufferedBlockSender.cs
Expand Up @@ -111,7 +111,7 @@ public sealed class BufferedBlockSender
// supports all 255 blocks (classicube enhanced client)
if (normal == null) normal = MakeNormal();
return normal;
} else if (!p.hasCustomBlocks && p.version == Server.VERSION_0030) {
} else if (!p.hasCustomBlocks && p.ProtocolVersion == Server.VERSION_0030) {
// support original 45 blocks (classic client)
if (classic == null) classic = MakeLimited(p.fallback);
return classic;
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Player/Player.Fields.cs
Expand Up @@ -224,7 +224,7 @@ public partial class Player : IDisposable {
public bool verifiedName;
bool gotSQLData;

internal byte version; // protocol version
public byte ProtocolVersion;
internal byte[] fallback = new byte[256]; // fallback for classic+CPE block IDs


Expand Down
8 changes: 4 additions & 4 deletions MCGalaxy/Player/Player.Login.cs
Expand Up @@ -38,14 +38,14 @@ public partial class Player : IDisposable
// the packet must be at least old_size long
if (left < old_size) return 0;

LastAction = DateTime.UtcNow;
version = buffer[offset + 1];
if (version > Server.VERSION_0030) {
LastAction = DateTime.UtcNow;
ProtocolVersion = buffer[offset + 1];
if (ProtocolVersion > Server.VERSION_0030) {
Leave(null, "Unsupported protocol version", true); return -1;
}

// check size now that know whether usertype field is included or not
int size = version >= Server.VERSION_0020 ? new_size : old_size;
int size = ProtocolVersion >= Server.VERSION_0020 ? new_size : old_size;
if (left < size) return 0;
if (loggedIn) return size;

Expand Down

0 comments on commit 6317f0e

Please sign in to comment.