Skip to content

Commit d28cc17

Browse files
Support InstantdMOTD CPE extension, to allow /wset motd to apply instantly.
1 parent 4d721ae commit d28cc17

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

fCraft/Commands/WorldCommands.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,8 +3023,13 @@ static void SetMOTD(Player player, World world, string value) {
30233023

30243024
Player[] players = world.Players;
30253025
foreach (Player pl in players) {
3026-
if (!pl.Supports(CpeExt.HackControl)) continue;
3027-
pl.Send(PlayerHacks.MakePacket(pl, world.MOTD));
3026+
if (pl.Supports(CpeExt.HackControl)) {
3027+
pl.Send(PlayerHacks.MakePacket(pl, world.MOTD));
3028+
}
3029+
if (pl.Supports(CpeExt.InstantMOTD)) {
3030+
string motd = world.MOTD ?? "";
3031+
pl.Send(Packet.MakeHandshake(pl, ConfigKey.ServerName.GetString(), motd));
3032+
}
30283033
}
30293034
WorldManager.SaveWorldList();
30303035
}

fCraft/Network/CpeConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public enum CpeExt
104104

105105
/// <summary> Allows hiding blocks from and reordering blocks in the inventory. </summary>
106106
InventoryOrder,
107+
108+
/// <summary> Allows sending motd/handshake packets, without also needing to resend world. </summary>
109+
InstantMOTD,
107110
}
108111

109112

fCraft/Network/Packet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public Packet( [NotNull] byte[] rawBytes ) {
4949
/// <param name="player"> Player to whom this packet is being sent.
5050
/// Used to determine DeleteAdmincrete permission, for client-side checks. May not be null. </param>
5151
/// <param name="motd"> Message-of-the-day (text displayed below the server name). May not be null. </param>
52-
/// <param name="hasCP437"> Whether client supports extended code page 437 characters. </param>
5352
/// <exception cref="ArgumentNullException"> player, serverName, or motd is null </exception>
54-
public static Packet MakeHandshake( [NotNull] Player player, [NotNull] string serverName, [NotNull] string motd, bool hasCP437 ) {
53+
public static Packet MakeHandshake( [NotNull] Player player, [NotNull] string serverName, [NotNull] string motd ) {
5554
if( serverName == null ) throw new ArgumentNullException( "serverName" );
5655
if( motd == null ) throw new ArgumentNullException( "motd" );
56+
bool hasCP437 = player.HasCP437;
5757

5858
Packet packet = new Packet( OpCode.Handshake );
5959
//Logger.Log(LogType.Debug, "Send: MakeHandshake({0}, {1}, {2})", player, serverName, motd);

fCraft/Network/Player.Handshake.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ bool NegotiateProtocolExtension() {
375375
case InventoryOrderExtName:
376376
if (version == 1) ext = CpeExt.InventoryOrder;
377377
break;
378+
case InstantMOTDExtName:
379+
if (version == 1) ext = CpeExt.InstantMOTD;
380+
break;
378381
}
379382
if (ext != CpeExt.None)
380383
supportedExts.Add(ext);

fCraft/Network/Player.Networking.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ bool LoginSequence()
753753
if (ConfigKey.PaidPlayersOnly.Enabled() && Info.AccountType != AccountType.Paid)
754754
{
755755
SendNow(Packet.MakeHandshake(this, ConfigKey.ServerName.GetString(),
756-
"Please wait; Checking paid status...", HasCP437));
756+
"Please wait; Checking paid status..."));
757757
writer.Flush();
758758

759759
Info.AccountType = CheckPaidStatus(Name);
@@ -833,7 +833,7 @@ bool LoginSequence()
833833
motd = "&0=&c=&e= " + motd + " &e=&c=&0=";
834834
}
835835
}
836-
SendNow(Packet.MakeHandshake(this, serverName, motd, HasCP437));
836+
SendNow(Packet.MakeHandshake(this, serverName, motd));
837837

838838
// AutoRank
839839
if (ConfigKey.AutoRankEnabled.Enabled())
@@ -1106,7 +1106,7 @@ internal bool JoinWorldNow([NotNull] World newWorld, bool doUseWorldSpawn, World
11061106

11071107
// Start sending over the level copy
11081108
if (oldWorld != null) {
1109-
SendNow(Packet.MakeHandshake(this, textLine1, textLine2, HasCP437));
1109+
SendNow(Packet.MakeHandshake(this, textLine1, textLine2));
11101110
}
11111111

11121112
if (Supports(CpeExt.BlockPermissions))

fCraft/Player/Player.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,7 @@ public void ResetIdleTimer()
21512151
const string EntityPropertyExtName = "EntityProperty";
21522152
const string TwoWayPingExtName = "TwoWayPing";
21532153
const string InventoryOrderExtName = "InventoryOrder";
2154+
const string InstantMOTDExtName = "InstantMOTD";
21542155

21552156
bool supportsBlockDefs, supportsCustomBlocks;
21562157
internal bool supportsExtPositions;

0 commit comments

Comments
 (0)