Skip to content

Commit

Permalink
Support InstantdMOTD CPE extension, to allow /wset motd to apply inst…
Browse files Browse the repository at this point in the history
…antly.
  • Loading branch information
UnknownShadow200 committed Jan 12, 2018
1 parent 4d721ae commit d28cc17
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
9 changes: 7 additions & 2 deletions fCraft/Commands/WorldCommands.cs
Expand Up @@ -3023,8 +3023,13 @@ static void WorldClearHandler(Player player, CommandReader cmd)


Player[] players = world.Players; Player[] players = world.Players;
foreach (Player pl in players) { foreach (Player pl in players) {
if (!pl.Supports(CpeExt.HackControl)) continue; if (pl.Supports(CpeExt.HackControl)) {
pl.Send(PlayerHacks.MakePacket(pl, world.MOTD)); pl.Send(PlayerHacks.MakePacket(pl, world.MOTD));
}
if (pl.Supports(CpeExt.InstantMOTD)) {
string motd = world.MOTD ?? "";
pl.Send(Packet.MakeHandshake(pl, ConfigKey.ServerName.GetString(), motd));
}
} }
WorldManager.SaveWorldList(); WorldManager.SaveWorldList();
} }
Expand Down
3 changes: 3 additions & 0 deletions fCraft/Network/CpeConstants.cs
Expand Up @@ -104,6 +104,9 @@ public enum CpeExt


/// <summary> Allows hiding blocks from and reordering blocks in the inventory. </summary> /// <summary> Allows hiding blocks from and reordering blocks in the inventory. </summary>
InventoryOrder, InventoryOrder,

/// <summary> Allows sending motd/handshake packets, without also needing to resend world. </summary>
InstantMOTD,
} }




Expand Down
4 changes: 2 additions & 2 deletions fCraft/Network/Packet.cs
Expand Up @@ -49,11 +49,11 @@ public partial struct Packet {
/// <param name="player"> Player to whom this packet is being sent. /// <param name="player"> Player to whom this packet is being sent.
/// Used to determine DeleteAdmincrete permission, for client-side checks. May not be null. </param> /// Used to determine DeleteAdmincrete permission, for client-side checks. May not be null. </param>
/// <param name="motd"> Message-of-the-day (text displayed below the server name). May not be null. </param> /// <param name="motd"> Message-of-the-day (text displayed below the server name). May not be null. </param>
/// <param name="hasCP437"> Whether client supports extended code page 437 characters. </param>
/// <exception cref="ArgumentNullException"> player, serverName, or motd is null </exception> /// <exception cref="ArgumentNullException"> player, serverName, or motd is null </exception>
public static Packet MakeHandshake( [NotNull] Player player, [NotNull] string serverName, [NotNull] string motd, bool hasCP437 ) { public static Packet MakeHandshake( [NotNull] Player player, [NotNull] string serverName, [NotNull] string motd ) {
if( serverName == null ) throw new ArgumentNullException( "serverName" ); if( serverName == null ) throw new ArgumentNullException( "serverName" );
if( motd == null ) throw new ArgumentNullException( "motd" ); if( motd == null ) throw new ArgumentNullException( "motd" );
bool hasCP437 = player.HasCP437;


Packet packet = new Packet( OpCode.Handshake ); Packet packet = new Packet( OpCode.Handshake );
//Logger.Log(LogType.Debug, "Send: MakeHandshake({0}, {1}, {2})", player, serverName, motd); //Logger.Log(LogType.Debug, "Send: MakeHandshake({0}, {1}, {2})", player, serverName, motd);
Expand Down
3 changes: 3 additions & 0 deletions fCraft/Network/Player.Handshake.cs
Expand Up @@ -375,6 +375,9 @@ public class Players {
case InventoryOrderExtName: case InventoryOrderExtName:
if (version == 1) ext = CpeExt.InventoryOrder; if (version == 1) ext = CpeExt.InventoryOrder;
break; break;
case InstantMOTDExtName:
if (version == 1) ext = CpeExt.InstantMOTD;
break;
} }
if (ext != CpeExt.None) if (ext != CpeExt.None)
supportedExts.Add(ext); supportedExts.Add(ext);
Expand Down
6 changes: 3 additions & 3 deletions fCraft/Network/Player.Networking.cs
Expand Up @@ -753,7 +753,7 @@ bool LoginSequence()
if (ConfigKey.PaidPlayersOnly.Enabled() && Info.AccountType != AccountType.Paid) if (ConfigKey.PaidPlayersOnly.Enabled() && Info.AccountType != AccountType.Paid)
{ {
SendNow(Packet.MakeHandshake(this, ConfigKey.ServerName.GetString(), SendNow(Packet.MakeHandshake(this, ConfigKey.ServerName.GetString(),
"Please wait; Checking paid status...", HasCP437)); "Please wait; Checking paid status..."));
writer.Flush(); writer.Flush();


Info.AccountType = CheckPaidStatus(Name); Info.AccountType = CheckPaidStatus(Name);
Expand Down Expand Up @@ -833,7 +833,7 @@ bool LoginSequence()
motd = "&0=&c=&e= " + motd + " &e=&c=&0="; motd = "&0=&c=&e= " + motd + " &e=&c=&0=";
} }
} }
SendNow(Packet.MakeHandshake(this, serverName, motd, HasCP437)); SendNow(Packet.MakeHandshake(this, serverName, motd));


// AutoRank // AutoRank
if (ConfigKey.AutoRankEnabled.Enabled()) if (ConfigKey.AutoRankEnabled.Enabled())
Expand Down Expand Up @@ -1106,7 +1106,7 @@ bool LoginSequence()


// Start sending over the level copy // Start sending over the level copy
if (oldWorld != null) { if (oldWorld != null) {
SendNow(Packet.MakeHandshake(this, textLine1, textLine2, HasCP437)); SendNow(Packet.MakeHandshake(this, textLine1, textLine2));
} }


if (Supports(CpeExt.BlockPermissions)) if (Supports(CpeExt.BlockPermissions))
Expand Down
1 change: 1 addition & 0 deletions fCraft/Player/Player.cs
Expand Up @@ -2151,6 +2151,7 @@ public void ResetIdleTimer()
const string EntityPropertyExtName = "EntityProperty"; const string EntityPropertyExtName = "EntityProperty";
const string TwoWayPingExtName = "TwoWayPing"; const string TwoWayPingExtName = "TwoWayPing";
const string InventoryOrderExtName = "InventoryOrder"; const string InventoryOrderExtName = "InventoryOrder";
const string InstantMOTDExtName = "InstantMOTD";


bool supportsBlockDefs, supportsCustomBlocks; bool supportsBlockDefs, supportsCustomBlocks;
internal bool supportsExtPositions; internal bool supportsExtPositions;
Expand Down

0 comments on commit d28cc17

Please sign in to comment.