mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Implemented .net 10 support. Updated all affected libraries and the code. Not testes yet.
This commit is contained in:
parent
5488140261
commit
28834e7a86
10 changed files with 107 additions and 94 deletions
|
|
@ -284,7 +284,7 @@ namespace MinecraftClient.ChatBots
|
|||
if (text != null)
|
||||
messageBuilder.WithContent(text);
|
||||
|
||||
messageBuilder.WithFiles(new Dictionary<string, Stream>() { { $"attachment://{filePath}", fs } });
|
||||
messageBuilder.AddFiles(new Dictionary<string, Stream>() { { filePath, fs } });
|
||||
|
||||
discordBotClient!.SendMessageAsync(discordChannel, messageBuilder).Wait(Config.Message_Send_Timeout * 1000);
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@ namespace MinecraftClient.ChatBots
|
|||
if (!CanSendMessages())
|
||||
return;
|
||||
|
||||
SendMessage(new DiscordMessageBuilder().WithFile(fileStream));
|
||||
SendMessage(new DiscordMessageBuilder().AddFile(fileStream));
|
||||
}
|
||||
|
||||
private bool CanSendMessages()
|
||||
|
|
|
|||
|
|
@ -259,7 +259,8 @@ namespace MinecraftClient.ChatBots
|
|||
{
|
||||
using (var image = new MagickImage(fileName))
|
||||
{
|
||||
var size = new MagickGeometry(Config.Resize_To, Config.Resize_To);
|
||||
uint resizeTo = (uint)Math.Max(Config.Resize_To, 1);
|
||||
var size = new MagickGeometry(resizeTo, resizeTo);
|
||||
size.IgnoreAspectRatio = true;
|
||||
|
||||
image.Resize(size);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ using Telegram.Bot.Exceptions;
|
|||
using Telegram.Bot.Polling;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using Telegram.Bot.Types.InputFiles;
|
||||
using Tomlet.Attributes;
|
||||
using File = System.IO.File;
|
||||
|
||||
|
|
@ -205,7 +204,7 @@ namespace MinecraftClient.ChatBots
|
|||
|
||||
try
|
||||
{
|
||||
botClient!.SendTextMessageAsync(Config.ChannelId.Trim(), message, ParseMode.Markdown).Wait(Config.Message_Send_Timeout);
|
||||
botClient!.SendMessage(Config.ChannelId.Trim(), message, parseMode: ParseMode.Markdown).Wait(Config.Message_Send_Timeout);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -224,9 +223,9 @@ namespace MinecraftClient.ChatBots
|
|||
string fileName = filePath[(filePath.IndexOf(Path.DirectorySeparatorChar) + 1)..];
|
||||
|
||||
Stream stream = File.OpenRead(filePath);
|
||||
botClient!.SendDocumentAsync(
|
||||
botClient!.SendDocument(
|
||||
Config.ChannelId.Trim(),
|
||||
document: new InputOnlineFile(content: stream, fileName),
|
||||
document: InputFile.FromStream(stream, fileName),
|
||||
caption: text,
|
||||
parseMode: ParseMode.Markdown).Wait(Config.Message_Send_Timeout * 1000);
|
||||
}
|
||||
|
|
@ -260,14 +259,14 @@ namespace MinecraftClient.ChatBots
|
|||
cancellationToken = new CancellationTokenSource();
|
||||
|
||||
botClient.StartReceiving(
|
||||
updateHandler: HandleUpdateAsync,
|
||||
pollingErrorHandler: HandlePollingErrorAsync,
|
||||
receiverOptions: new ReceiverOptions
|
||||
HandleUpdateAsync,
|
||||
HandlePollingErrorAsync,
|
||||
new ReceiverOptions
|
||||
{
|
||||
// receive all update types
|
||||
AllowedUpdates = Array.Empty<UpdateType>()
|
||||
},
|
||||
cancellationToken: cancellationToken.Token
|
||||
cancellationToken.Token
|
||||
);
|
||||
|
||||
IsConnected = true;
|
||||
|
|
@ -313,9 +312,9 @@ namespace MinecraftClient.ChatBots
|
|||
|
||||
if (text.ToLower().Contains(".chatid"))
|
||||
{
|
||||
await botClient.SendTextMessageAsync(chatId: chatId,
|
||||
replyToMessageId: message.MessageId,
|
||||
await botClient.SendMessage(chatId: chatId,
|
||||
text: $"Chat ID: {chatId}",
|
||||
replyParameters: message.MessageId,
|
||||
cancellationToken: _cancellationToken,
|
||||
parseMode: ParseMode.Markdown);
|
||||
return;
|
||||
|
|
@ -324,10 +323,10 @@ namespace MinecraftClient.ChatBots
|
|||
if (Config.Authorized_Chat_Ids.Length > 0 && !Config.Authorized_Chat_Ids.Contains(chatId))
|
||||
{
|
||||
LogDebugToConsole($"Unauthorized message '{messageText}' received in a chat with with an ID: {chatId} !");
|
||||
await botClient.SendTextMessageAsync(
|
||||
await botClient.SendMessage(
|
||||
chatId: chatId,
|
||||
replyToMessageId: message.MessageId,
|
||||
text: Translations.bot_TelegramBridge_unauthorized,
|
||||
replyParameters: message.MessageId,
|
||||
cancellationToken: _cancellationToken,
|
||||
parseMode: ParseMode.Markdown);
|
||||
return;
|
||||
|
|
@ -347,10 +346,10 @@ namespace MinecraftClient.ChatBots
|
|||
|
||||
if (command.ToLower().Contains("quit") || command.ToLower().Contains("exit"))
|
||||
{
|
||||
await botClient.SendTextMessageAsync(
|
||||
await botClient.SendMessage(
|
||||
chatId: chatId,
|
||||
replyToMessageId: message.MessageId,
|
||||
text: $"{Translations.bot_TelegramBridge_quit_disabled}",
|
||||
replyParameters: message.MessageId,
|
||||
cancellationToken: _cancellationToken,
|
||||
parseMode: ParseMode.Markdown);
|
||||
return;;
|
||||
|
|
@ -359,11 +358,10 @@ namespace MinecraftClient.ChatBots
|
|||
CmdResult result = new();
|
||||
PerformInternalCommand(command, ref result);
|
||||
|
||||
await botClient.SendTextMessageAsync(
|
||||
await botClient.SendMessage(
|
||||
chatId: chatId,
|
||||
replyToMessageId:
|
||||
message.MessageId,
|
||||
text: $"{Translations.bot_TelegramBridge_command_executed}:\n\n{result}",
|
||||
replyParameters: message.MessageId,
|
||||
cancellationToken: _cancellationToken,
|
||||
parseMode: ParseMode.Markdown);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
|
|
@ -28,25 +28,22 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Brigadier.NET" Version="1.2.13" />
|
||||
<PackageReference Include="DnsClient" Version="1.7.0" />
|
||||
<PackageReference Include="DotNetZip" Version="1.16.0" />
|
||||
<PackageReference Include="DSharpPlus" Version="4.2.0" />
|
||||
<PackageReference Include="DynamicExpresso.Core" Version="2.13.0" />
|
||||
<PackageReference Include="DnsClient" Version="1.8.0" />
|
||||
<PackageReference Include="DSharpPlus" Version="4.5.1" />
|
||||
<PackageReference Include="DynamicExpresso.Core" Version="2.19.3" />
|
||||
<PackageReference Include="FuzzySharp" Version="2.0.2" />
|
||||
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.3.0" />
|
||||
<PackageReference Include="MessagePack" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.3" />
|
||||
<PackageReference Include="Samboy063.Tomlet" Version="5.0.1" />
|
||||
<PackageReference Include="Sentry" Version="4.1.0" />
|
||||
<PackageReference Include="SingleFileExtractor.Core" Version="1.0.1" />
|
||||
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.11.0" />
|
||||
<PackageReference Include="MessagePack" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Windows.Compatibility" Version="10.0.5" />
|
||||
<PackageReference Include="Samboy063.Tomlet" Version="6.2.0" />
|
||||
<PackageReference Include="Sentry" Version="6.2.0" />
|
||||
<PackageReference Include="SingleFileExtractor.Core" Version="2.3.0" />
|
||||
<PackageReference Include="starksoft.aspen" Version="1.1.8">
|
||||
<NoWarn>NU1701</NoWarn>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
|
||||
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
|
||||
<PackageReference Include="Telegram.Bot" Version="22.9.5.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="config\ChatBots\AutoLeaveOnLowHp.cs" />
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ namespace MinecraftClient
|
|||
options.Dsn = SentryDSN;
|
||||
options.AutoSessionTracking = true;
|
||||
options.IsGlobalModeEnabled = true;
|
||||
options.EnableTracing = true;
|
||||
options.TracesSampleRate = 1.0;
|
||||
options.SendDefaultPii = false;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
break;
|
||||
}
|
||||
catch (Ionic.Zlib.ZlibException)
|
||||
catch (System.IO.InvalidDataException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
using Ionic.Zlib;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Quick Zlib compression handling for network packet compression.
|
||||
/// Note: Underlying compression handling is taken from the DotNetZip Library.
|
||||
/// This library is open source and provided under the Microsoft Public License.
|
||||
/// More info about DotNetZip at dotnetzip.codeplex.com.
|
||||
/// </summary>
|
||||
public static class ZlibUtils
|
||||
{
|
||||
|
|
@ -17,16 +15,13 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Compressed data as a byte array</returns>
|
||||
public static byte[] Compress(byte[] to_compress)
|
||||
{
|
||||
byte[] data;
|
||||
using (System.IO.MemoryStream memstream = new())
|
||||
using MemoryStream memstream = new();
|
||||
using (ZLibStream stream = new(memstream, CompressionMode.Compress, leaveOpen: true))
|
||||
{
|
||||
using (ZlibStream stream = new(memstream, CompressionMode.Compress))
|
||||
{
|
||||
stream.Write(to_compress, 0, to_compress.Length);
|
||||
}
|
||||
data = memstream.ToArray();
|
||||
stream.Write(to_compress, 0, to_compress.Length);
|
||||
}
|
||||
return data;
|
||||
|
||||
return memstream.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -37,10 +32,20 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Decompressed data as a byte array</returns>
|
||||
public static byte[] Decompress(byte[] to_decompress, int size_uncompressed)
|
||||
{
|
||||
ZlibStream stream = new(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
|
||||
using MemoryStream compressedStream = new(to_decompress, writable: false);
|
||||
using ZLibStream stream = new(compressedStream, CompressionMode.Decompress);
|
||||
|
||||
byte[] packetData_decompressed = new byte[size_uncompressed];
|
||||
stream.Read(packetData_decompressed, 0, size_uncompressed);
|
||||
stream.Close();
|
||||
int totalRead = 0;
|
||||
while (totalRead < size_uncompressed)
|
||||
{
|
||||
int read = stream.Read(packetData_decompressed, totalRead, size_uncompressed - totalRead);
|
||||
if (read <= 0)
|
||||
break;
|
||||
|
||||
totalRead += read;
|
||||
}
|
||||
|
||||
return packetData_decompressed;
|
||||
}
|
||||
|
||||
|
|
@ -51,12 +56,14 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Decompressed data as byte array</returns>
|
||||
public static byte[] Decompress(byte[] to_decompress)
|
||||
{
|
||||
ZlibStream stream = new(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
|
||||
using MemoryStream compressedStream = new(to_decompress, writable: false);
|
||||
using ZLibStream stream = new(compressedStream, CompressionMode.Decompress);
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
using System.IO.MemoryStream decompressedBuffer = new();
|
||||
using MemoryStream decompressedBuffer = new();
|
||||
int read;
|
||||
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
decompressedBuffer.Write(buffer, 0, read);
|
||||
|
||||
return decompressedBuffer.ToArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using Ionic.Zip;
|
||||
using MinecraftClient.Mapping;
|
||||
using MinecraftClient.Protocol.Handlers;
|
||||
using MinecraftClient.Protocol.Handlers.PacketPalettes;
|
||||
|
|
@ -138,12 +138,18 @@ namespace MinecraftClient.Protocol
|
|||
using (Stream recordingFile = new FileStream(Path.Combine(temporaryCache, recordingTmpFileName), FileMode.Open))
|
||||
{
|
||||
using Stream metaDataFile = new FileStream(Path.Combine(temporaryCache, MetaData.MetaDataFileName), FileMode.Open);
|
||||
using ZipOutputStream zs = new(Path.Combine(ReplayFileDirectory, replayFileName));
|
||||
zs.PutNextEntry(recordingTmpFileName);
|
||||
recordingFile.CopyTo(zs);
|
||||
zs.PutNextEntry(MetaData.MetaDataFileName);
|
||||
metaDataFile.CopyTo(zs);
|
||||
zs.Close();
|
||||
using FileStream replayArchiveFile = new(Path.Combine(ReplayFileDirectory, replayFileName), FileMode.Create, FileAccess.Write);
|
||||
using ZipArchive replayArchive = new(replayArchiveFile, ZipArchiveMode.Create);
|
||||
|
||||
ZipArchiveEntry recordingEntry = replayArchive.CreateEntry(recordingTmpFileName);
|
||||
using (Stream recordingEntryStream = recordingEntry.Open())
|
||||
{
|
||||
recordingFile.CopyTo(recordingEntryStream);
|
||||
}
|
||||
|
||||
ZipArchiveEntry metadataEntry = replayArchive.CreateEntry(MetaData.MetaDataFileName);
|
||||
using Stream metadataEntryStream = metadataEntry.Open();
|
||||
metaDataFile.CopyTo(metadataEntryStream);
|
||||
}
|
||||
|
||||
File.Delete(Path.Combine(temporaryCache, recordingTmpFileName));
|
||||
|
|
@ -167,18 +173,29 @@ namespace MinecraftClient.Protocol
|
|||
|
||||
using (Stream metaDataFile = new FileStream(Path.Combine(temporaryCache, MetaData.MetaDataFileName), FileMode.Open))
|
||||
{
|
||||
using ZipOutputStream zs = new(replayFileName);
|
||||
zs.PutNextEntry(recordingTmpFileName);
|
||||
// .CopyTo() method start from stream current position
|
||||
// We need to reset position in order to get full content
|
||||
var lastPosition = recordStream!.BaseStream.Position;
|
||||
recordStream.BaseStream.Position = 0;
|
||||
recordStream.BaseStream.CopyTo(zs);
|
||||
recordStream.BaseStream.Position = lastPosition;
|
||||
using FileStream replayArchiveFile = new(replayFileName, FileMode.Create, FileAccess.Write);
|
||||
using ZipArchive replayArchive = new(replayArchiveFile, ZipArchiveMode.Create);
|
||||
|
||||
zs.PutNextEntry(MetaData.MetaDataFileName);
|
||||
metaDataFile.CopyTo(zs);
|
||||
zs.Close();
|
||||
ZipArchiveEntry recordingEntry = replayArchive.CreateEntry(recordingTmpFileName);
|
||||
using (Stream recordingEntryStream = recordingEntry.Open())
|
||||
{
|
||||
// .CopyTo() method start from stream current position
|
||||
// We need to reset position in order to get full content
|
||||
long lastPosition = recordStream!.BaseStream.Position;
|
||||
try
|
||||
{
|
||||
recordStream.BaseStream.Position = 0;
|
||||
recordStream.BaseStream.CopyTo(recordingEntryStream);
|
||||
}
|
||||
finally
|
||||
{
|
||||
recordStream.BaseStream.Position = lastPosition;
|
||||
}
|
||||
}
|
||||
|
||||
ZipArchiveEntry metadataEntry = replayArchive.CreateEntry(MetaData.MetaDataFileName);
|
||||
using Stream metadataEntryStream = metadataEntry.Open();
|
||||
metaDataFile.CopyTo(metadataEntryStream);
|
||||
}
|
||||
|
||||
WriteDebugLog("Backup replay file created.");
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ https://github.com/laurentkempe/DynamicRun/blob/master/LICENSE
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
|
@ -117,10 +116,11 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
File.Copy(executablePath, tempFile);
|
||||
|
||||
// Access the contents of the executable.
|
||||
ExecutableReader e = new();
|
||||
var viewAccessor = MemoryMappedFile.CreateFromFile(tempFile, FileMode.Open).CreateViewAccessor();
|
||||
var manifest = e.ReadManifest(viewAccessor);
|
||||
var files = manifest.Files;
|
||||
using ExecutableReader executableReader = new(tempFile);
|
||||
if (!executableReader.IsSingleFile)
|
||||
throw new InvalidOperationException("[Script Error] The executable is not a single-file bundle.");
|
||||
|
||||
var files = executableReader.Bundle.Files;
|
||||
|
||||
Stream? assemblyStream;
|
||||
|
||||
|
|
@ -133,8 +133,8 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
if (string.IsNullOrEmpty(loadedAssembly.Location)) {
|
||||
// Check if we can access the file from the executable.
|
||||
var reference = files.FirstOrDefault(x =>
|
||||
x.RelativePath.Remove(x.RelativePath.Length - 4) == refs.Name);
|
||||
var refCount = files.Count(x => x.RelativePath.Remove(x.RelativePath.Length - 4) == refs.Name);
|
||||
Path.GetFileNameWithoutExtension(x.RelativePath) == refs.Name);
|
||||
var refCount = files.Count(x => Path.GetFileNameWithoutExtension(x.RelativePath) == refs.Name);
|
||||
if (refCount > 1) {
|
||||
// Safety net for the case where the assembly is referenced multiple times.
|
||||
// Should not happen normally, but we can make exceptions when it does happen.
|
||||
|
|
@ -147,17 +147,13 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
"[Script Error] The executable does not contain a referenced assembly. Assembly name: " + refs.Name);
|
||||
}
|
||||
|
||||
assemblyStream = GetStreamForFileEntry(viewAccessor, reference);
|
||||
assemblyStream = reference.AsStream();
|
||||
references.Add(MetadataReference.CreateFromStream(assemblyStream!));
|
||||
continue;
|
||||
}
|
||||
|
||||
references.Add(MetadataReference.CreateFromFile(loadedAssembly.Location));
|
||||
}
|
||||
|
||||
// Cleanup.
|
||||
viewAccessor.Flush();
|
||||
viewAccessor.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -176,14 +172,6 @@ namespace MinecraftClient.Scripting.DynamicRun.Builder
|
|||
assemblyIdentityComparer: DesktopAssemblyIdentityComparer.Default));
|
||||
}
|
||||
|
||||
private static Stream? GetStreamForFileEntry(MemoryMappedViewAccessor viewAccessor, FileEntry file)
|
||||
{
|
||||
if (typeof(BundleExtractor).GetMethod("GetStreamForFileEntry", BindingFlags.NonPublic | BindingFlags.Static)!.Invoke(null, new object[] { viewAccessor, file }) is not Stream stream)
|
||||
throw new InvalidOperationException("[Script Error] The executable does not contain the assembly. Assembly name: " + file.RelativePath);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
internal struct CompileResult
|
||||
{
|
||||
internal byte[]? Assembly;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue