Add support for FullCP437 CPE extension, add support for LongerMessages CPE extension

This commit is contained in:
UnknownShadow200 2015-10-30 08:24:35 +11:00
parent 8f5f869ab5
commit 043c14fad7
10 changed files with 47 additions and 27 deletions

View File

@ -148,9 +148,17 @@ namespace ClassicalSharp {
static char[] trimChars = { ' ' };
public void SendTextInBufferAndReset() {
int packetsCount = 0;
for( int i = 0; i < parts.Length; i++ ) {
if( parts[i] == null ) break;
game.Chat.Send( parts[i].TrimEnd( trimChars ) );
packetsCount++;
}
// split up into both partial and final packet.
if( packetsCount > 0 ) {
for( int i = 0; i < packetsCount - 1; i++ ) {
game.Chat.Send( parts[i].TrimEnd( trimChars ), true );
}
game.Chat.Send( parts[packetsCount - 1].TrimEnd( trimChars ), false );
}
typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1.

View File

@ -24,15 +24,15 @@ namespace ClassicalSharp {
public int FontSize = 12;
public void Send( string text ) {
public void Send( string text, bool partial ) {
if( String.IsNullOrEmpty( text ) ) return;
InputLog.Add( text );
if( CommandManager.IsCommandPrefix( text ) ) {
game.CommandManager.Execute( text );
return;
}
game.Network.SendChat( text );
game.Network.SendChat( text, partial );
}
public void Add( string text ) {

View File

@ -217,7 +217,11 @@ namespace ClassicalSharp {
MapRenderer.Render( e.Time );
SelectionManager.Render( e.Time );
WeatherRenderer.Render( e.Time );
InputHandler.PickBlocks( true );
bool left = IsMousePressed( MouseButton.Left );
bool middle = IsMousePressed( MouseButton.Middle );
bool right = IsMousePressed( MouseButton.Right );
InputHandler.PickBlocks( true, left, middle, right );
} else {
SelectedPos.SetAsInvalid();
}

View File

@ -59,10 +59,7 @@ namespace ClassicalSharp {
bool[] buttonsDown = new bool[3];
DateTime lastClick = DateTime.MinValue;
public void PickBlocks( bool cooldown ) {
bool left = game.IsMousePressed( MouseButton.Left );
bool right = game.IsMousePressed( MouseButton.Right );
bool middle = game.IsMousePressed( MouseButton.Middle );
public void PickBlocks( bool cooldown, bool left, bool middle, bool right ) {
DateTime now = DateTime.UtcNow;
double delta = (now - lastClick).TotalMilliseconds;
if( cooldown && delta < 250 ) return; // 4 times per second
@ -225,7 +222,10 @@ namespace ClassicalSharp {
void MouseButtonDown( object sender, MouseButtonEventArgs e ) {
if( game.activeScreen == null || !game.activeScreen.HandlesMouseClick( e.X, e.Y, e.Button ) ) {
PickBlocks( false );
bool left = e.Button == MouseButton.Left;
bool middle = e.Button == MouseButton.Middle;
bool right = e.Button == MouseButton.Right;
PickBlocks( false, left, middle, right );
} else {
lastClick = DateTime.UtcNow;
}
@ -286,7 +286,7 @@ namespace ClassicalSharp {
if( Hotkeys.IsHotkey( key, game.Keyboard, out text, out more ) ) {
if( !more )
game.Network.SendChat( text );
game.Network.SendChat( text, false );
else if( game.activeScreen is NormalScreen )
((NormalScreen)game.activeScreen).OpenTextInputBar( text );
}

View File

@ -39,7 +39,7 @@ namespace ClassicalSharp.Model {
}
ModelPart MakeLeg( float x1, float x2, float legX1, float legX2 ) {
const float y1 = 0f, y2 = 5/16f, z2 = 1/16f, z1 = -2/16f;
const float y1 = 1/64f, y2 = 5/16f, z2 = 1/16f, z1 = -2/16f;
YQuad( 32, 0, 3, 3, x2, x1, z1, z2, y1, false ); // bottom feet
ZQuad( 36, 3, 1, 5, legX1, legX2, y1, y2, z2, false ); // vertical part of leg
return new ModelPart( index - 2 * 4, 2 * 4 );

View File

@ -12,7 +12,7 @@ namespace ClassicalSharp {
public abstract void Connect( IPAddress address, int port );
public abstract void SendChat( string text );
public abstract void SendChat( string text, bool partial );
public abstract void SendPosition( Vector3 pos, float yaw, float pitch );

View File

@ -54,12 +54,15 @@ namespace ClassicalSharp {
int cpeServerExtensionsCount;
bool sendHeldBlock, useMessageTypes, usingTexturePack;
bool usePartialMessages;
static string[] clientExtensions = {
"ClickDistance", "CustomBlocks", "HeldBlock",
"EmoteFix", "TextHotKey", "ExtPlayerList",
"EnvColors", "SelectionCuboid", "BlockPermissions",
"ChangeModel", "EnvMapAppearance", "EnvWeatherType",
"HackControl", "MessageTypes", "PlayerClick",
// proposals
"FullCP437", "LongerMessages",
};
void HandleCpeExtInfo() {
@ -84,6 +87,8 @@ namespace ClassicalSharp {
} else if( extName == "EnvMapAppearance" && extVersion == 2 ) {
usingTexturePack = true;
packetSizes[(int)PacketId.CpeEnvSetMapApperance] += 4;
} else if( extName == "LongerMessages" ) {
usePartialMessages = true;
}
cpeServerExtensionsCount--;
@ -92,7 +97,7 @@ namespace ClassicalSharp {
SendPacket();
for( int i = 0; i < clientExtensions.Length; i++ ) {
string name = clientExtensions[i];
int version = (name == "ExtPlayerList" || name == "EnvMapApperance") ? 2 : 1;
int version = (name == "ExtPlayerList") ? 2 : 1;
MakeExtEntry( name, version );
SendPacket();
}
@ -268,6 +273,7 @@ namespace ClassicalSharp {
game.Map.SetEdgeBlock( (Block)reader.ReadUInt8() );
game.Map.SetEdgeLevel( reader.ReadInt16() );
if( usingTexturePack ) {
// TODO: proper envmapappearance version 2 support
game.Map.SetCloudsLevel( reader.ReadInt16() );
short maxViewDist = reader.ReadInt16(); // TODO: what to do with this?
}

View File

@ -48,12 +48,14 @@ namespace ClassicalSharp {
SendPacket();
}
public override void SendChat( string text ) {
if( !String.IsNullOrEmpty( text ) ) {
MakeMessagePacket( text );
public override void SendChat( string text, bool partial ) {
if( String.IsNullOrEmpty( text ) ) return;
byte payload = !usePartialMessages ? (byte)0xFF:
partial ? (byte)1 : (byte)0;
MakeMessagePacket( text, payload );
SendPacket();
}
}
public override void SendPosition( Vector3 pos, float yaw, float pitch ) {
byte payload = sendHeldBlock ? (byte)game.Inventory.HeldBlock : (byte)0xFF;
@ -162,9 +164,9 @@ namespace ClassicalSharp {
WriteUInt8( (byte)Utils.DegreesToPacked( pitch, 256 ) );
}
private static void MakeMessagePacket( string text ) {
private static void MakeMessagePacket( string text, byte payload ) {
WriteUInt8( (byte)PacketId.Message );
WriteUInt8( 0xFF ); // unused
WriteUInt8( payload );
WriteString( text );
}
@ -310,7 +312,7 @@ namespace ClassicalSharp {
map = null;
gzipStream.Dispose();
if( sendWomId && !sentWomId ) {
SendChat( "/womid WoMClient-2.0.7" );
SendChat( "/womid WoMClient-2.0.7", false );
sentWomId = true;
}
gzipStream = null;

View File

@ -29,7 +29,7 @@ namespace ClassicalSharp.Singleplayer {
game.CommandManager.RegisterCommand( new GenerateCommand() );
}
public override void SendChat( string text ) {
public override void SendChat( string text, bool partial ) {
if( !String.IsNullOrEmpty( text ) ) {
game.Chat.Add( text, CpeMessage.Normal );
}

View File

@ -125,7 +125,7 @@ namespace Launcher2 {
platformDrawer.Draw( Window.WindowInfo, Framebuffer );
}
internal FastColour clearColour = new FastColour( 101, 79, 119 );
internal FastColour clearColour = new FastColour( 30, 30, 30 );
public void MakeBackground() {
if( Framebuffer != null )
Framebuffer.Dispose();