Skip to content

Commit

Permalink
Merge pull request #679 from UnknownShadow200/ProtocolMod
Browse files Browse the repository at this point in the history
Start splitting off classic/CPE protocol into separate dedicated class
  • Loading branch information
UnknownShadow200 committed Jan 12, 2022
2 parents 603e82d + 5a92bbe commit f1a7ede
Show file tree
Hide file tree
Showing 18 changed files with 468 additions and 382 deletions.
13 changes: 6 additions & 7 deletions MCGalaxy/Commands/CPE/CmdHold.cs
Expand Up @@ -27,10 +27,7 @@ public sealed class CmdHold : Command2 {
public override bool SuperUseable { get { return false; } }

public override void Use(Player p, string message, CommandData data) {
if (message.Length == 0) { Help(p); return; }
if (!p.Supports(CpeExt.HeldBlock)) {
p.Message("Your client doesn't support changing your held block."); return;
}
if (message.Length == 0) { Help(p); return; }
string[] args = message.SplitSpaces(2);

BlockID block;
Expand All @@ -42,9 +39,11 @@ public sealed class CmdHold : Command2 {
p.Message("Cannot hold physics blocks"); return;
}

BlockID raw = p.ConvertBlock(block);
p.Send(Packet.HoldThis(raw, locked, p.hasExtBlocks));
p.Message("Set your held block to {0}.", Block.GetName(p, block));
if (p.Session.SendHoldThis(block, locked)) {
p.Message("Set your held block to {0}.", Block.GetName(p, block));
} else {
p.Message("Your client doesn't support changing your held block.");
}
}

public override void Help(Player p) {
Expand Down
14 changes: 7 additions & 7 deletions MCGalaxy/Commands/CPE/CmdReachDistance.cs
Expand Up @@ -25,10 +25,7 @@ public sealed class CmdReachDistance : Command2 {
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
public override bool SuperUseable { get { return false; } }

public override void Use(Player p, string message, CommandData data) {
if (!p.Supports(CpeExt.ClickDistance)) {
p.Message("Your client doesn't support changing your reach distance."); return;
}
public override void Use(Player p, string message, CommandData data) {
if (message.Length == 0) {
p.Message("Your reach distance is {0} blocks", p.ReachDistance); return;
}
Expand All @@ -38,13 +35,16 @@ public sealed class CmdReachDistance : Command2 {

int packedDist = (int)(dist * 32);
if (packedDist > short.MaxValue) {
p.Message("\"{0}\", is too long a reach distance. Max is 1023 blocks.", message);
} else {
p.Send(Packet.ClickDistance((short)packedDist));
p.Message("\"{0}\", is too long a reach distance. Max is 1023 blocks.", message); return;
}

if (p.Session.SendSetReach(dist)) {
p.ReachDistance = dist;
p.Message("Set your reach distance to {0} blocks.", dist);
Server.reach.Update(p.name, packedDist.ToString());
Server.reach.Save();
} else {
p.Message("Your client doesn't support changing your reach distance."); return;
}
}

Expand Down
5 changes: 3 additions & 2 deletions MCGalaxy/Commands/Chat/CmdClear.cs
Expand Up @@ -46,8 +46,9 @@ public sealed class CmdClear : Command2 {
}

static void ClearChat(Player p) {
for (int i = 0; i < 30; i++) {
p.Send(Packet.BlankMessage());
for (int i = 0; i < 30; i++)
{
p.Session.SendMessage(CpeMessageType.Normal, "");
}
}

Expand Down
11 changes: 7 additions & 4 deletions MCGalaxy/Commands/Information/CmdPClients.cs
Expand Up @@ -30,9 +30,10 @@ public sealed class CmdPClients : Command2 {
Dictionary<string, List<Player>> clients = new Dictionary<string, List<Player>>();
Player[] online = PlayerInfo.Online.Items;

foreach (Player pl in online) {
foreach (Player pl in online)
{
if (!p.CanSee(pl, data.Rank)) continue;
string appName = PlayerInfo.ClientName(pl);
string appName = pl.Session.ClientName();

List<Player> usingClient;
if (!clients.TryGetValue(appName, out usingClient)) {
Expand All @@ -43,11 +44,13 @@ public sealed class CmdPClients : Command2 {
}

p.Message("Players using:");
foreach (var kvp in clients) {
foreach (var kvp in clients)
{
StringBuilder builder = new StringBuilder();
List<Player> players = kvp.Value;

for (int i = 0; i < players.Count; i++) {
for (int i = 0; i < players.Count; i++)
{
string nick = Colors.StripUsed(p.FormatNick(players[i]));
builder.Append(nick);
if (i < players.Count - 1) builder.Append(", ");
Expand Down
4 changes: 1 addition & 3 deletions MCGalaxy/Commands/Moderation/ModActionCmd.cs
Expand Up @@ -88,9 +88,7 @@ public static class ModActionCmd {
who.SetPrefix();

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

who.SendCurrentBlockPermissions();
Entities.SpawnEntities(who, false);
Expand Down
7 changes: 3 additions & 4 deletions MCGalaxy/CorePlugin/ConnectHandler.cs
Expand Up @@ -51,10 +51,9 @@ internal static class ConnectHandler {

short reachDist;
if (!short.TryParse(reach, out reachDist)) return;
p.ReachDistance = reachDist / 32f;

if (p.Supports(CpeExt.ClickDistance))
p.Send(Packet.ClickDistance(reachDist));

p.ReachDistance = reachDist / 32f;
p.Session.SendSetReach(p.ReachDistance);
}

static void LoadWaypoints(Player p) {
Expand Down
18 changes: 5 additions & 13 deletions MCGalaxy/Entity/Entities.cs
Expand Up @@ -133,18 +133,8 @@ public static class Entities {

static void SpawnRaw(Player dst, byte id, Entity e, Position pos, Orientation rot,
string skin, string name, string model) {
// NOTE: Fix for standard clients
if (id == Entities.SelfID) pos.Y -= 22;
name = LineWrapper.CleanupColors(name, dst);

if (dst.Supports(CpeExt.ExtPlayerList, 2)) {
dst.Send(Packet.ExtAddEntity2(id, skin, name, pos, rot, dst.hasCP437, dst.hasExtPositions));
} else if (dst.hasExtList) {
dst.Send(Packet.ExtAddEntity(id, skin, name, dst.hasCP437));
dst.Send(Packet.Teleport(id, pos, rot, dst.hasExtPositions));
} else {
dst.Send(Packet.AddEntity(id, name, pos, rot, dst.hasCP437, dst.hasExtPositions));
}
dst.Session.SendSpawnEntity(id, name, skin, pos, rot);

if (dst.hasChangeModel) {
OnSendingModelEvent.Call(e, ref model, dst);
Expand All @@ -161,13 +151,15 @@ public static class Entities {
public static void Despawn(Player dst, Player other) {
OnEntityDespawnedEvent.Call(other, dst);
byte id = other == dst ? SelfID : other.id;
dst.Send(Packet.RemoveEntity(id));
dst.Session.SendRemoveEntity(id);

if (!Server.Config.TablistGlobal) TabList.Remove(dst, other);
}

public static void Despawn(Player dst, PlayerBot b) {
OnEntityDespawnedEvent.Call(b, dst);
dst.Send(Packet.RemoveEntity(b.id));
dst.Session.SendRemoveEntity(b.id);

if (Server.Config.TablistBots) TabList.Remove(dst, b);
}

Expand Down
28 changes: 2 additions & 26 deletions MCGalaxy/MCGalaxy_.csproj
Expand Up @@ -599,6 +599,7 @@
<Compile Include="Modules\Relay\RelayBotSender.cs" />
<Compile Include="Modules\Security\IPThrottler.cs" />
<Compile Include="Network\BaseWebSocket.cs" />
<Compile Include="Network\ClassicProtocol.cs" />
<Compile Include="Network\CPESupport.cs" />
<Compile Include="Network\Heartbeat\ClassiCube.cs" />
<Compile Include="Network\Heartbeat\Heartbeat.cs" />
Expand Down Expand Up @@ -727,32 +728,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Commands\Maintenance" />
<Folder Include="Config\Permissions" />
<Folder Include="Database\Stats" />
<Folder Include="Games\Weapons" />
<Folder Include="Games\RoundsGame" />
<Folder Include="Generator\LibNoise" />
<Folder Include="Generator\Classic" />
<Folder Include="Generator\Realistic" />
<Folder Include="Modules\Awards" />
<Folder Include="Modules\Moderation" />
<Folder Include="Modules\Moderation\Notes" />
<Folder Include="Modules\Security" />
<Folder Include="Modules\Relay\Discord" />
<Folder Include="Modules\Relay" />
<Folder Include="Network\Heartbeat" />
<Folder Include="Modules\Relay\IRC" />
<Folder Include="Network\Utils" />
<Folder Include="Network\Packets" />
<Folder Include="Entity" />
<Folder Include="Modules" />
<Folder Include="Server\Maintenance" />
<Folder Include="Server\Authentication" />
<Folder Include="util\Formatting" />
<Folder Include="util\Threading" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit f1a7ede

Please sign in to comment.