mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
Add public methods to send PlayerClick packets (code that calls them not yet implemented), simplify reading strings in FastNetReader and backspace key handler in TextInputWidget.
This commit is contained in:
parent
07471e54d7
commit
be7c17c6b8
@ -6,7 +6,7 @@ using System.Windows.Forms;
|
|||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
public sealed class TextInputWidget : Widget {
|
public sealed class TextInputWidget : Widget {
|
||||||
|
|
||||||
public TextInputWidget( Game window, Font font, Font boldFont ) : base( window ) {
|
public TextInputWidget( Game window, Font font, Font boldFont ) : base( window ) {
|
||||||
HorizontalDocking = Docking.LeftOrTop;
|
HorizontalDocking = Docking.LeftOrTop;
|
||||||
VerticalDocking = Docking.BottomOrRight;
|
VerticalDocking = Docking.BottomOrRight;
|
||||||
@ -166,17 +166,15 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BackspaceKey() {
|
void BackspaceKey() {
|
||||||
if( !chatInputText.Empty ) {
|
if( !chatInputText.Empty && caretPos != 0 ) {
|
||||||
if( caretPos == -1 ) {
|
if( caretPos == -1 ) {
|
||||||
chatInputText.DeleteAt( chatInputText.Length - 1 );
|
chatInputText.DeleteAt( chatInputText.Length - 1 );
|
||||||
Dispose();
|
} else {
|
||||||
Init();
|
|
||||||
} else if( caretPos > 0 ) {
|
|
||||||
caretPos--;
|
caretPos--;
|
||||||
chatInputText.DeleteAt( caretPos );
|
chatInputText.DeleteAt( caretPos );
|
||||||
Dispose();
|
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
Dispose();
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,52 +58,39 @@ namespace ClassicalSharp {
|
|||||||
Remove( length );
|
Remove( length );
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Reads a string, then converts control characters into the
|
public string ReadCp437String() {
|
||||||
/// unicode values of their equivalent code page 437 graphical representations. </summary>
|
int length = GetString( buffer, false );
|
||||||
public string ReadTextString() {
|
|
||||||
string value = GetTextString( buffer );
|
|
||||||
Remove( 64 );
|
Remove( 64 );
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal string ReadWoMTextString( ref byte messageType, bool useMessageTypes ) {
|
|
||||||
if( useMessageTypes ) return ReadTextString();
|
|
||||||
|
|
||||||
string value = GetWoMTextString( buffer, ref messageType );
|
|
||||||
Remove( 64 );
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ReadString() {
|
|
||||||
string value = GetAsciiString( buffer );
|
|
||||||
Remove( 64 );
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char[] characters = new char[64];
|
|
||||||
const string womDetail = "^detail.user=";
|
|
||||||
static string GetTextString( byte[] data ) {
|
|
||||||
int length = CopyTextStringToBuffer( data );
|
|
||||||
return new String( characters, 0, length );
|
return new String( characters, 0, length );
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetWoMTextString( byte[] data, ref byte messageType ) {
|
public string ReadAsciiString() {
|
||||||
|
int length = GetString( buffer, true );
|
||||||
|
Remove( 64 );
|
||||||
|
return new String( characters, 0, length );
|
||||||
|
}
|
||||||
|
|
||||||
|
internal string ReadChatString( ref byte messageType, bool useMessageTypes ) {
|
||||||
|
if( useMessageTypes )
|
||||||
|
return ReadCp437String();
|
||||||
|
|
||||||
messageType = (byte)CpeMessageType.Normal;
|
messageType = (byte)CpeMessageType.Normal;
|
||||||
int length = CopyTextStringToBuffer( data );
|
int length = GetString( buffer, false );
|
||||||
|
Remove( 64 );
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
if( IsWomDetailString( length ) ) {
|
if( length >= womDetail.Length && IsWomDetailString() ) {
|
||||||
length -= womDetail.Length;
|
length -= womDetail.Length;
|
||||||
offset += womDetail.Length;
|
offset = womDetail.Length;
|
||||||
messageType = (byte)CpeMessageType.Status3;
|
messageType = (byte)CpeMessageType.Status3;
|
||||||
}
|
}
|
||||||
return new String( characters, offset, length );
|
return new String( characters, offset, length );
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsWomDetailString( int length ) {
|
static char[] characters = new char[64];
|
||||||
if( length < womDetail.Length )
|
const string womDetail = "^detail.user=";
|
||||||
return false;
|
static bool IsWomDetailString() {
|
||||||
|
|
||||||
for( int i = 0; i < womDetail.Length; i++ ) {
|
for( int i = 0; i < womDetail.Length; i++ ) {
|
||||||
if( characters[i] != womDetail[i] )
|
if( characters[i] != womDetail[i] )
|
||||||
return false;
|
return false;
|
||||||
@ -111,91 +98,33 @@ namespace ClassicalSharp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GetAsciiString( byte[] data ) {
|
static int GetString( byte[] data, bool ascii ) {
|
||||||
int length = 0;
|
|
||||||
for( int i = 63; i >= 0; i-- ) {
|
|
||||||
byte code = data[i];
|
|
||||||
if( length == 0 && !( code == 0 || code == 0x20 ) )
|
|
||||||
length = i + 1;
|
|
||||||
|
|
||||||
characters[i] = code >= 0x80 ? '?' : (char)code;
|
|
||||||
}
|
|
||||||
return new String( characters, 0, length );
|
|
||||||
}
|
|
||||||
|
|
||||||
static int CopyTextStringToBuffer( byte[] data ) {
|
|
||||||
// code page 437 indices --> actual unicode characters
|
|
||||||
int length = 0;
|
int length = 0;
|
||||||
for( int i = 63; i >= 0; i-- ) {
|
for( int i = 63; i >= 0; i-- ) {
|
||||||
byte code = data[i];
|
byte code = data[i];
|
||||||
if( length == 0 && !( code == 0 || code == 0x20 ) )
|
if( length == 0 && !( code == 0 || code == 0x20 ) )
|
||||||
length = i + 1;
|
length = i + 1;
|
||||||
|
|
||||||
if( code < 0x20 ) { // general control characters
|
if( ascii ) {
|
||||||
|
characters[i] = code >= 0x7F ? '?' : (char)code;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Treat code as an index in code page 437
|
||||||
|
if( code < 0x20 ) {
|
||||||
characters[i] = controlCharReplacements[code];
|
characters[i] = controlCharReplacements[code];
|
||||||
} else if( code < 0x7F ) { // normal ascii character
|
} else if( code < 0x7F ) {
|
||||||
characters[i] = (char)code;
|
characters[i] = (char)code;
|
||||||
} else if( code == 0x7F ) { // delete control character
|
} else {
|
||||||
characters[i] = '\u2302';
|
characters[i] = extendedCharReplacements[code - 0x7F];
|
||||||
} else if( code >= 0x80 ){ // extended ascii character
|
|
||||||
characters[i] = extendedCharReplacements[code - 0x80];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char[] controlCharReplacements = new char[] { // 00 -> 1F
|
const string controlCharReplacements = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼";
|
||||||
'\u0000', '\u263A', '\u263B', '\u2665',
|
static string extendedCharReplacements = "⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»" +
|
||||||
'\u2666', '\u2663', '\u2660', '\u2022',
|
"░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌" +
|
||||||
'\u25D8', '\u25CB', '\u25D9', '\u2642',
|
"█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\u00a0";
|
||||||
'\u2640', '\u266A', '\u266B', '\u263C',
|
|
||||||
|
|
||||||
'\u25BA', '\u25C4', '\u2195', '\u203C',
|
|
||||||
'\u00B6', '\u00A7', '\u25AC', '\u21A8',
|
|
||||||
'\u2191', '\u2193', '\u2192', '\u2190',
|
|
||||||
'\u221F', '\u2194', '\u25B2', '\u25BC',
|
|
||||||
};
|
|
||||||
|
|
||||||
static char[] extendedCharReplacements = new char[] { // 80 -> FF
|
|
||||||
'\u00C7', '\u00FC', '\u00E9', '\u00E2',
|
|
||||||
'\u00E4', '\u00E0', '\u00E5', '\u00E7',
|
|
||||||
'\u00EA', '\u00EB', '\u00E8', '\u00EF',
|
|
||||||
'\u00EE', '\u00EC', '\u00C4', '\u00C5',
|
|
||||||
|
|
||||||
'\u00C9', '\u00E6', '\u00C6', '\u00F4',
|
|
||||||
'\u00F6', '\u00F2', '\u00FB', '\u00F9',
|
|
||||||
'\u00FF', '\u00D6', '\u00DC', '\u00A2',
|
|
||||||
'\u00A3', '\u00A5', '\u20A7', '\u0192',
|
|
||||||
|
|
||||||
'\u00E1', '\u00ED', '\u00F3', '\u00FA',
|
|
||||||
'\u00F1', '\u00D1', '\u00AA', '\u00BA',
|
|
||||||
'\u00BF', '\u2310', '\u00AC', '\u00BD',
|
|
||||||
'\u00BC', '\u00A1', '\u00AB', '\u00BB',
|
|
||||||
|
|
||||||
'\u2591', '\u2592', '\u2593', '\u2502',
|
|
||||||
'\u2524', '\u2561', '\u2562', '\u2556',
|
|
||||||
'\u2555', '\u2563', '\u2551', '\u2557',
|
|
||||||
'\u255D', '\u255C', '\u255B', '\u2510',
|
|
||||||
|
|
||||||
'\u2514', '\u2534', '\u252C', '\u251C',
|
|
||||||
'\u2500', '\u253C', '\u255E', '\u255F',
|
|
||||||
'\u255A', '\u2554', '\u2569', '\u2566',
|
|
||||||
'\u2560', '\u2550', '\u256C', '\u2567',
|
|
||||||
|
|
||||||
'\u2568', '\u2564', '\u2565', '\u2559',
|
|
||||||
'\u2558', '\u2552', '\u2553', '\u256B',
|
|
||||||
'\u256A', '\u2518', '\u250C', '\u2588',
|
|
||||||
'\u2584', '\u258C', '\u2590', '\u2580',
|
|
||||||
|
|
||||||
'\u03B1', '\u00DF', '\u0393', '\u03C0',
|
|
||||||
'\u03A3', '\u03C3', '\u00B5', '\u03C4',
|
|
||||||
'\u03A6', '\u0398', '\u03A9', '\u03B4',
|
|
||||||
'\u221E', '\u03C6', '\u03B5', '\u2229',
|
|
||||||
|
|
||||||
'\u2261', '\u00B1', '\u2265', '\u2264',
|
|
||||||
'\u2320', '\u2321', '\u00F7', '\u2248',
|
|
||||||
'\u00B0', '\u2219', '\u00B7', '\u221A',
|
|
||||||
'\u207F', '\u00B2', '\u25A0', '\u00A0',
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,6 +10,7 @@ using System.Net;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using ClassicalSharp.Network;
|
using ClassicalSharp.Network;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
@ -67,6 +68,18 @@ namespace ClassicalSharp {
|
|||||||
SendPacket();
|
SendPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendPlayerClick( MouseButton button, bool buttonDown, PickedPos pos ) {
|
||||||
|
Player p = Window.LocalPlayer;
|
||||||
|
MakePlayerClick( (byte)button, buttonDown, p.YawDegrees, p.PitchDegrees, 255,
|
||||||
|
pos.BlockPos, pos.BlockFace );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendPlayerClick( MouseButton button, bool buttonDown, byte targetId ) {
|
||||||
|
Player p = Window.LocalPlayer;
|
||||||
|
MakePlayerClick( (byte)button, buttonDown, p.YawDegrees, p.PitchDegrees, targetId,
|
||||||
|
new Vector3I( -100, -100, -100 ), 0 );
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
socket.Close();
|
socket.Close();
|
||||||
Disconnected = true;
|
Disconnected = true;
|
||||||
@ -251,8 +264,8 @@ namespace ClassicalSharp {
|
|||||||
case PacketId.Handshake:
|
case PacketId.Handshake:
|
||||||
{
|
{
|
||||||
byte protocolVer = reader.ReadUInt8();
|
byte protocolVer = reader.ReadUInt8();
|
||||||
ServerName = reader.ReadString();
|
ServerName = reader.ReadAsciiString();
|
||||||
ServerMotd = reader.ReadString();
|
ServerMotd = reader.ReadAsciiString();
|
||||||
byte userType = reader.ReadUInt8();
|
byte userType = reader.ReadUInt8();
|
||||||
if( !useBlockPermissions ) {
|
if( !useBlockPermissions ) {
|
||||||
Window.CanDelete[(int)Block.Bedrock] = userType == 0x64;
|
Window.CanDelete[(int)Block.Bedrock] = userType == 0x64;
|
||||||
@ -351,7 +364,7 @@ namespace ClassicalSharp {
|
|||||||
case PacketId.AddEntity:
|
case PacketId.AddEntity:
|
||||||
{
|
{
|
||||||
byte entityId = reader.ReadUInt8();
|
byte entityId = reader.ReadUInt8();
|
||||||
string name = reader.ReadString();
|
string name = reader.ReadAsciiString();
|
||||||
AddEntity( entityId, name, name, true );
|
AddEntity( entityId, name, name, true );
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@ -387,13 +400,13 @@ namespace ClassicalSharp {
|
|||||||
case PacketId.Message:
|
case PacketId.Message:
|
||||||
{
|
{
|
||||||
byte messageType = reader.ReadUInt8();
|
byte messageType = reader.ReadUInt8();
|
||||||
string text = reader.ReadWoMTextString( ref messageType, useMessageTypes );
|
string text = reader.ReadChatString( ref messageType, useMessageTypes );
|
||||||
Window.AddChat( text, messageType );
|
Window.AddChat( text, messageType );
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case PacketId.Kick:
|
case PacketId.Kick:
|
||||||
{
|
{
|
||||||
string reason = reader.ReadString();
|
string reason = reader.ReadAsciiString();
|
||||||
Window.Disconnect( "&eLost connection to the server", reason );
|
Window.Disconnect( "&eLost connection to the server", reason );
|
||||||
Dispose();
|
Dispose();
|
||||||
} break;
|
} break;
|
||||||
@ -409,14 +422,14 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
case PacketId.CpeExtInfo:
|
case PacketId.CpeExtInfo:
|
||||||
{
|
{
|
||||||
string appName = reader.ReadString();
|
string appName = reader.ReadAsciiString();
|
||||||
Utils.LogDebug( "Server identified itself as: " + appName );
|
Utils.LogDebug( "Server identified itself as: " + appName );
|
||||||
cpeServerExtensionsCount = reader.ReadInt16();
|
cpeServerExtensionsCount = reader.ReadInt16();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case PacketId.CpeExtEntry:
|
case PacketId.CpeExtEntry:
|
||||||
{
|
{
|
||||||
string extensionName = reader.ReadString();
|
string extensionName = reader.ReadAsciiString();
|
||||||
int extensionVersion = reader.ReadInt32();
|
int extensionVersion = reader.ReadInt32();
|
||||||
Utils.LogDebug( "cpe ext: " + extensionName + "," + extensionVersion );
|
Utils.LogDebug( "cpe ext: " + extensionName + "," + extensionVersion );
|
||||||
if( extensionName == "HeldBlock" ) {
|
if( extensionName == "HeldBlock" ) {
|
||||||
@ -475,9 +488,9 @@ namespace ClassicalSharp {
|
|||||||
case PacketId.CpeExtAddPlayerName:
|
case PacketId.CpeExtAddPlayerName:
|
||||||
{
|
{
|
||||||
short nameId = reader.ReadInt16();
|
short nameId = reader.ReadInt16();
|
||||||
string playerName = Utils.StripColours( reader.ReadString() );
|
string playerName = Utils.StripColours( reader.ReadAsciiString() );
|
||||||
string listName = reader.ReadString();
|
string listName = reader.ReadAsciiString();
|
||||||
string groupName = reader.ReadString();
|
string groupName = reader.ReadAsciiString();
|
||||||
byte groupRank = reader.ReadUInt8();
|
byte groupRank = reader.ReadUInt8();
|
||||||
if( nameId >= 0 && nameId <= 255 ) {
|
if( nameId >= 0 && nameId <= 255 ) {
|
||||||
CpeListInfo oldInfo = Window.CpePlayersList[nameId];
|
CpeListInfo oldInfo = Window.CpePlayersList[nameId];
|
||||||
@ -495,8 +508,8 @@ namespace ClassicalSharp {
|
|||||||
case PacketId.CpeExtAddEntity:
|
case PacketId.CpeExtAddEntity:
|
||||||
{
|
{
|
||||||
byte entityId = reader.ReadUInt8();
|
byte entityId = reader.ReadUInt8();
|
||||||
string displayName = reader.ReadString();
|
string displayName = reader.ReadAsciiString();
|
||||||
string skinName = reader.ReadString();
|
string skinName = reader.ReadAsciiString();
|
||||||
AddEntity( entityId, displayName, skinName, false );
|
AddEntity( entityId, displayName, skinName, false );
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@ -511,7 +524,7 @@ namespace ClassicalSharp {
|
|||||||
case PacketId.CpeMakeSelection:
|
case PacketId.CpeMakeSelection:
|
||||||
{
|
{
|
||||||
byte selectionId = reader.ReadUInt8();
|
byte selectionId = reader.ReadUInt8();
|
||||||
string label = reader.ReadString();
|
string label = reader.ReadAsciiString();
|
||||||
short startX = reader.ReadInt16();
|
short startX = reader.ReadInt16();
|
||||||
short startY = reader.ReadInt16();
|
short startY = reader.ReadInt16();
|
||||||
short startZ = reader.ReadInt16();
|
short startZ = reader.ReadInt16();
|
||||||
@ -578,7 +591,7 @@ namespace ClassicalSharp {
|
|||||||
case PacketId.CpeChangeModel:
|
case PacketId.CpeChangeModel:
|
||||||
{
|
{
|
||||||
byte playerId = reader.ReadUInt8();
|
byte playerId = reader.ReadUInt8();
|
||||||
string modelName = reader.ReadString().ToLowerInvariant();
|
string modelName = reader.ReadAsciiString().ToLowerInvariant();
|
||||||
Player player = playerId == 0xFF ? Window.LocalPlayer : Window.NetPlayers[playerId];
|
Player player = playerId == 0xFF ? Window.LocalPlayer : Window.NetPlayers[playerId];
|
||||||
if( player != null ) {
|
if( player != null ) {
|
||||||
player.SetModel( modelName );
|
player.SetModel( modelName );
|
||||||
@ -587,7 +600,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
case PacketId.CpeEnvSetMapApperance:
|
case PacketId.CpeEnvSetMapApperance:
|
||||||
{
|
{
|
||||||
string url = reader.ReadString();
|
string url = reader.ReadAsciiString();
|
||||||
byte sideBlock = reader.ReadUInt8();
|
byte sideBlock = reader.ReadUInt8();
|
||||||
byte edgeBlock = reader.ReadUInt8();
|
byte edgeBlock = reader.ReadUInt8();
|
||||||
short waterLevel = reader.ReadInt16();
|
short waterLevel = reader.ReadInt16();
|
||||||
@ -626,8 +639,8 @@ namespace ClassicalSharp {
|
|||||||
case PacketId.CpeExtAddEntity2:
|
case PacketId.CpeExtAddEntity2:
|
||||||
{
|
{
|
||||||
byte entityId = reader.ReadUInt8();
|
byte entityId = reader.ReadUInt8();
|
||||||
string displayName = reader.ReadString();
|
string displayName = reader.ReadAsciiString();
|
||||||
string skinName = reader.ReadString();
|
string skinName = reader.ReadAsciiString();
|
||||||
AddEntity( entityId, displayName, skinName, true );
|
AddEntity( entityId, displayName, skinName, true );
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user