mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
Add support for FullCP437 CPE extension, add support for LongerMessages CPE extension
This commit is contained in:
parent
8f5f869ab5
commit
043c14fad7
@ -60,7 +60,7 @@ namespace ClassicalSharp {
|
||||
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++ ) {
|
||||
if( partLens[i] == 0 ) break;
|
||||
|
||||
@ -70,7 +70,7 @@ namespace ClassicalSharp {
|
||||
break;
|
||||
}
|
||||
sum += partLens[i];
|
||||
}
|
||||
}
|
||||
if( indexX == -1 ) indexX = partLens[indexY];
|
||||
|
||||
if( indexX == 64 ) {
|
||||
@ -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.
|
||||
|
@ -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 ) {
|
||||
|
@ -116,7 +116,7 @@ namespace ClassicalSharp {
|
||||
Animations = new Animations( this );
|
||||
TexturePackExtractor extractor = new TexturePackExtractor();
|
||||
extractor.Extract( defaultTexPack, this );
|
||||
Inventory = new Inventory( this );
|
||||
Inventory = new Inventory( this );
|
||||
|
||||
BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete );
|
||||
Map = new Map( this );
|
||||
@ -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();
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -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?
|
||||
}
|
||||
|
@ -48,11 +48,13 @@ namespace ClassicalSharp {
|
||||
SendPacket();
|
||||
}
|
||||
|
||||
public override void SendChat( string text ) {
|
||||
if( !String.IsNullOrEmpty( text ) ) {
|
||||
MakeMessagePacket( text );
|
||||
SendPacket();
|
||||
}
|
||||
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 ) {
|
||||
@ -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;
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user