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

@ -60,7 +60,7 @@ namespace ClassicalSharp {
caretPos = -1; realIndex = 500000; caretPos = -1; realIndex = 500000;
} }
int sum = 0, indexX = -1, indexY = 0; int sum = 0, indexX = -1, indexY = 0;
for( int i = 0; i < lines; i++ ) { for( int i = 0; i < lines; i++ ) {
if( partLens[i] == 0 ) break; if( partLens[i] == 0 ) break;
@ -70,7 +70,7 @@ namespace ClassicalSharp {
break; break;
} }
sum += partLens[i]; sum += partLens[i];
} }
if( indexX == -1 ) indexX = partLens[indexY]; if( indexX == -1 ) indexX = partLens[indexY];
if( indexX == 64 ) { if( indexX == 64 ) {
@ -148,9 +148,17 @@ namespace ClassicalSharp {
static char[] trimChars = { ' ' }; static char[] trimChars = { ' ' };
public void SendTextInBufferAndReset() { public void SendTextInBufferAndReset() {
int packetsCount = 0;
for( int i = 0; i < parts.Length; i++ ) { for( int i = 0; i < parts.Length; i++ ) {
if( parts[i] == null ) break; 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. typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1.

View File

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

View File

@ -116,7 +116,7 @@ namespace ClassicalSharp {
Animations = new Animations( this ); Animations = new Animations( this );
TexturePackExtractor extractor = new TexturePackExtractor(); TexturePackExtractor extractor = new TexturePackExtractor();
extractor.Extract( defaultTexPack, this ); extractor.Extract( defaultTexPack, this );
Inventory = new Inventory( this ); Inventory = new Inventory( this );
BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete ); BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete );
Map = new Map( this ); Map = new Map( this );
@ -217,7 +217,11 @@ namespace ClassicalSharp {
MapRenderer.Render( e.Time ); MapRenderer.Render( e.Time );
SelectionManager.Render( e.Time ); SelectionManager.Render( e.Time );
WeatherRenderer.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 { } else {
SelectedPos.SetAsInvalid(); SelectedPos.SetAsInvalid();
} }

View File

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

View File

@ -39,7 +39,7 @@ namespace ClassicalSharp.Model {
} }
ModelPart MakeLeg( float x1, float x2, float legX1, float legX2 ) { 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 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 ZQuad( 36, 3, 1, 5, legX1, legX2, y1, y2, z2, false ); // vertical part of leg
return new ModelPart( index - 2 * 4, 2 * 4 ); 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 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 ); public abstract void SendPosition( Vector3 pos, float yaw, float pitch );

View File

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

View File

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

View File

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

View File

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