Skip to content

Commit

Permalink
More work on custom protocol support
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Apr 25, 2022
1 parent 1bdb33e commit bebd36a
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 36 deletions.
6 changes: 3 additions & 3 deletions MCGalaxy/Bots/PlayerBot.cs
Expand Up @@ -192,10 +192,10 @@ public sealed class PlayerBot : Entity {
Position pos = bot.Pos; Orientation rot = bot.Rot;

Entities.GetPositionPacket(ref ptrSrc, bot.id, true, false,
pos, bot.lastPos, rot, bot.lastRot);
pos, bot._lastPos, rot, bot._lastRot);
Entities.GetPositionPacket(ref ptrExt, bot.id, true, true,
pos, bot.lastPos, rot, bot.lastRot);
bot.lastPos = pos; bot.lastRot = rot;
pos, bot._lastPos, rot, bot._lastRot);
bot._lastPos = pos; bot._lastRot = rot;
}

int countSrc = (int)(ptrSrc - src);
Expand Down
6 changes: 3 additions & 3 deletions MCGalaxy/Entity/Entities.cs
Expand Up @@ -50,7 +50,7 @@ public static class Entities
Spawn(other, p, pos, rot, possession);
} else if (p == other && self) {
other.Pos = pos; other.SetYawPitch(rot.RotY, rot.HeadX);
other.lastPos = other.Pos; other.lastRot = other.Rot;
other._lastPos = other.Pos; other._lastRot = other.Rot;
Spawn(other, p, pos, rot, possession);
}
}
Expand Down Expand Up @@ -293,15 +293,15 @@ public static class Entities
// Avoids the very rare issue of player's position changing mid-way through iteration,
// which can cause this player to show minorly offset to other players.
foreach (Player p in players) {
p.tempPos = p.Pos;
p._tempPos = p.Pos;
}

foreach (Player p in players) {
p.Session.UpdatePlayerPositions();
}

foreach (Player p in players) {
p.lastPos = p.tempPos; p.lastRot = p.Rot;
p._lastPos = p._tempPos; p._lastRot = p.Rot;
}
}
#endregion
Expand Down
6 changes: 3 additions & 3 deletions MCGalaxy/Entity/Entity.cs
Expand Up @@ -28,8 +28,8 @@ public abstract class Entity
long _pos;

// Last sent orientation/position, for delta calculation
protected internal Orientation lastRot;
protected internal Position lastPos;
public Orientation _lastRot;
public Position _lastPos;
internal bool hasExtPositions;

public string Model = "humanoid";
Expand All @@ -48,7 +48,7 @@ public abstract class Entity
}

public void SetInitialPos(Position pos) {
Pos = pos; lastPos = pos;
Pos = pos; _lastPos = pos;
}

public void SetYawPitch(byte yaw, byte pitch) {
Expand Down
1 change: 1 addition & 0 deletions MCGalaxy/MCGalaxy_.csproj
Expand Up @@ -76,6 +76,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
Expand Down
8 changes: 2 additions & 6 deletions MCGalaxy/Network/ClassicProtocol.cs
Expand Up @@ -27,8 +27,6 @@ public class ClassicProtocol : IGameSession, INetProtocol
{
// these are checked very frequently, so avoid overhead of .Supports(
bool hasEmoteFix, hasTwoWayPing, hasExtTexs, hasTextColors;

Player player;
int extensionCount;
bool finishedCpeLogin;
CpeExt[] extensions = CpeExtension.Empty;
Expand Down Expand Up @@ -75,8 +73,6 @@ public class ClassicProtocol : IGameSession, INetProtocol
BlockID ReadBlock(byte[] buffer, int offset) { return Block.FromRaw(buffer[offset]); }
#endif

public void Disconnect() { player.Disconnect(); }


#region Classic processing
int HandleLogin(byte[] buffer, int offset, int left) {
Expand Down Expand Up @@ -620,7 +616,7 @@ public class ClassicProtocol : IGameSession, INetProtocol
return raw;
}

internal void UpdateFallbackTable() {
protected void UpdateFallbackTable() {
for (byte b = 0; b <= Block.CPE_MAX_BLOCK; b++)
{
fallback[b] = hasCustomBlocks ? b : Block.ConvertLimited(b, ProtocolVersion);
Expand Down Expand Up @@ -673,7 +669,7 @@ public class ClassicProtocol : IGameSession, INetProtocol

rot.HeadX = pitch;
Entities.GetPositionPacket(ref ptr, p.id, p.hasExtPositions, dst.hasExtPositions,
p.tempPos, p.lastPos, rot, p.lastRot);
p._tempPos, p._lastPos, rot, p._lastRot);
}

int count = (int)(ptr - src);
Expand Down
19 changes: 11 additions & 8 deletions MCGalaxy/Network/IGameSession.cs
Expand Up @@ -23,7 +23,7 @@ namespace MCGalaxy.Network
/// <summary> Abstracts a network session with a client supporting a particular game protocol </summary>
/// <remarks> By default only the Minecraft Classic game protocol is supported </remarks>
/// <remarks> Generally, you should manipulate a session through wrapper methods in the Player class instead </remarks>
public abstract class IGameSession
public abstract class IGameSession : INetProtocol
{
public byte ProtocolVersion;
internal byte[] fallback = new byte[256]; // fallback for classic+CPE block IDs
Expand All @@ -33,6 +33,7 @@ public abstract class IGameSession
// these are checked very frequently, so avoid overhead of .Supports(
public bool hasCustomBlocks, hasExtBlocks, hasBlockDefs, hasBulkBlockUpdate;
protected INetSocket socket;
protected Player player;

public int ProcessReceived(byte[] buffer, int bufferLen) {
int read = 0;
Expand All @@ -51,6 +52,8 @@ public abstract class IGameSession
return read;
}

public void Disconnect() { player.Disconnect(); }


/// <summary> Sends raw data to the client </summary>
public void Send(byte[] data) { socket.Send(data, SendFlags.None); }
Expand Down Expand Up @@ -84,20 +87,20 @@ public abstract class IGameSession
public abstract void SendAddTabEntry(byte id, string name, string nick, string group, byte groupRank);
public abstract void SendRemoveTabEntry(byte id);
/// <summary> Sends a set reach/click distance packet to the client </summary>
public virtual bool SendSetReach(float reach) { return false; }
public abstract bool SendSetReach(float reach);
/// <summary> Sends a set held block packet to the client </summary>
public virtual bool SendHoldThis(BlockID block, bool locked) { return false; }
public abstract bool SendHoldThis(BlockID block, bool locked);
/// <summary> Sends an update environment color packet to the client </summary>
public virtual bool SendSetEnvColor(byte type, string hex) { return false; }
public abstract bool SendSetEnvColor(byte type, string hex);
public abstract void SendChangeModel(byte id, string model);
/// <summary> Sends an update weather packet </summary>
public virtual bool SendSetWeather(byte weather) { return false; }
public abstract bool SendSetWeather(byte weather);
/// <summary> Sends an update text color code packet to the client </summary>
public virtual bool SendSetTextColor(ColorDesc color) { return false; }
public abstract bool SendSetTextColor(ColorDesc color);
/// <summary> Sends a define custom block packet to the client </summary>
public virtual bool SendDefineBlock(BlockDefinition def) { return false; }
public abstract bool SendDefineBlock(BlockDefinition def);
/// <summary> Sends an undefine custom block packet to the client </summary>
public virtual bool SendUndefineBlock(BlockDefinition def) { return false; }
public abstract bool SendUndefineBlock(BlockDefinition def);

/// <summary> Sends a level to the client </summary>
public abstract void SendLevel(Level prev, Level level);
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Player/Player.Fields.cs
Expand Up @@ -216,7 +216,7 @@ public partial class Player : IDisposable {
public string PreTeleportMap;

public string summonedMap;
internal Position tempPos;
public Position _tempPos;

// Extra storage for custom commands
public ExtrasCollection Extras = new ExtrasCollection();
Expand Down
6 changes: 3 additions & 3 deletions MCGalaxy/Player/Player.Handlers.cs
Expand Up @@ -190,7 +190,7 @@ public partial class Player : IDisposable
return result;
}

internal void ProcessBlockchange(ushort x, ushort y, ushort z, byte action, BlockID held) {
public void ProcessBlockchange(ushort x, ushort y, ushort z, byte action, BlockID held) {
try {
if (spamChecker.CheckBlockSpam()) return;

Expand Down Expand Up @@ -223,7 +223,7 @@ public partial class Player : IDisposable
}
}

internal void ProcessMovement(int x, int y, int z, byte yaw, byte pitch, int held) {
public void ProcessMovement(int x, int y, int z, byte yaw, byte pitch, int held) {
if (held >= 0) ClientHeldBlock = (BlockID)held;

if (trainGrab || following.Length > 0) { CheckBlocks(Pos, Pos); return; }
Expand Down Expand Up @@ -327,7 +327,7 @@ public partial class Player : IDisposable
}
}

bool Moved() { return lastRot.RotY != Rot.RotY || lastRot.HeadX != Rot.HeadX; }
bool Moved() { return _lastRot.RotY != Rot.RotY || _lastRot.HeadX != Rot.HeadX; }

void AnnounceDeath(string msg) {
//Chat.MessageFrom(ChatScope.Level, this, msg.Replace("@p", "λNICK"), level, Chat.FilterVisible(this));
Expand Down
4 changes: 2 additions & 2 deletions MCGalaxy/Player/Player.Login.cs
Expand Up @@ -27,7 +27,7 @@ namespace MCGalaxy
{
public partial class Player : IDisposable
{
internal bool ProcessLogin(string user, string mppass) {
public bool ProcessLogin(string user, string mppass) {
LastAction = DateTime.UtcNow;
name = user; truename = user;
SkinName = user; DisplayName = user;
Expand All @@ -52,7 +52,7 @@ public partial class Player : IDisposable
return !Socket.Disconnected;
}

internal void CompleteLoginProcess() {
public void CompleteLoginProcess() {
Player clone = null;
OnPlayerFinishConnectingEvent.Call(this);
if (cancelconnecting) { cancelconnecting = false; return; }
Expand Down
9 changes: 2 additions & 7 deletions MCGalaxy/Server/ServerConfig.cs
Expand Up @@ -56,14 +56,9 @@ public sealed class ServerConfig : EnvConfig {
public string DefaultTerrain = "";
[ConfigString("default-texture-pack-url", "Level", "", true)]
public string DefaultTexture = "";

[ConfigString("ssl-certificate-path", "Other", "", true)]
public string SslCertPath = "";
[ConfigString("ssl-certificate-password", "Other", "", true)]
public string SslCertPass = "";

[ConfigString("HeartbeatURL", "Other", "http://www.classicube.net/heartbeat.jsp", false, ":/.,")]
public string HeartbeatURL = "http://www.classicube.net/heartbeat.jsp";

public string HeartbeatURL = "http://www.classicube.net/heartbeat.jsp";
[ConfigBool("core-secret-commands", "Other", true)]
public bool CoreSecretCommands = true;
[ConfigBool("restart-on-error", "Error handling", true)]
Expand Down

0 comments on commit bebd36a

Please sign in to comment.