Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot does not connect #75

Closed
Apocritas99 opened this issue Aug 15, 2024 · 14 comments
Closed

Bot does not connect #75

Apocritas99 opened this issue Aug 15, 2024 · 14 comments

Comments

@Apocritas99
Copy link

tried every version offline and online

2024-08-15 12:19:18.2051|DEBUG|MineSharp.Protocol.MinecraftClient|Connecting to 127.0.0.1:25565.
2024-08-15 12:19:18.2051|INFO|MineSharp.Protocol.MinecraftClient|Connected, starting handshake...
2024-08-15 12:19:18.4425|DEBUG|MineSharp.Protocol.MinecraftStream|Enabling encryption.
2024-08-15 12:19:20.3564|ERROR|MineSharp.Data.Protocol.ProtocolData|Failed to get PacketType for: flow = Clientbound, state = Login, id = 118
@psu-de
Copy link
Owner

psu-de commented Aug 15, 2024

Hi,
what server brand are you using? And are you using the nuget package or a clone of this repository?

@Klotzi111
Copy link
Contributor

Klotzi111 commented Aug 15, 2024

What version is the minecraft server?

From the line Failed to get PacketType for: flow = Clientbound, state = Login, id = 118 I can tell it is MC 1.20.6 or higher. Because in older versions there is no packet with such an high id 118 (0x76).
The repo's README says Supported Versions: 1.18.x - 1.20.4

There could also be a problem with encryption. But you said that you have tried offline server. Then there is no encryption

@Apocritas99
Copy link
Author

Apocritas99 commented Aug 16, 2024

i was in version 1.20.1, and the id changes a lot is not the same always

2024-08-16 01:38:29.6662|ERROR|MineSharp.Data.Protocol.ProtocolData|Failed to get PacketType for: flow = Clientbound, state = Login, id = 74
2024-08-16 01:39:06.6881|ERROR|MineSharp.Data.Protocol.ProtocolData|Failed to get PacketType for: flow = Clientbound, state = Login, id = 26
2024-08-16 01:39:25.1773|ERROR|MineSharp.Data.Protocol.ProtocolData|Failed to get PacketType for: flow = Clientbound, state = Login, id = 35

@Klotzi111
Copy link
Contributor

This sounds like a race condition then.

What server brand are you running? vanilla, paper, spigot?
Does the server have compression enabled (network-compression-threshold in server.properties)?
Is the server in online or offline mode?

Maybe I can reproduce the problem if I have this info.

@Apocritas99
Copy link
Author

Apocritas99 commented Aug 16, 2024

I tried in my localhost and in a paper server, both same issue, sometimes the bot connects when I try a lot of times, but it does nothing an disconnects after a few seconds.

And about the online mode it's false idk if the "open to lan" uses online-mode: true, but the server is in online-mode: false

edit: I'm building from source with the latest commits, the nuget one works.

@Klotzi111
Copy link
Contributor

Klotzi111 commented Aug 16, 2024

sometimes the bot connects when I try a lot of times

Typical for a race condition. Sadly I can not reproduce this. So I can not fix it. We need to add a lot of logs to be able to see whats going on. But logging might take so much time that the race condition gets healed. Race conditions are tough.

The old version (from nuget) had the login process less optimized which might made the race condition so unlikely it worked :D

What system are you running this on? Processor? OS? Release or Debug Build? DotNet Version (exact)?

Currently there is already logging for when packets are sent and received. So please set the global LogLevel to Verbose (aka. Trace) and send the log file. This might already be enough to find the problem

@Apocritas99
Copy link
Author

Apocritas99 commented Aug 16, 2024

Im running in my system Windows 10 with an Intel I5 10400 using the release version and DotNet 8

The logs shows this with "trace" level:

2024-08-16 10:59:00.2277|INFO|MineSharp.Protocol.MinecraftClient|Connected, starting handshake...
2024-08-16 10:59:00.2277|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Handshake_SetProtocol was added to send queue
2024-08-16 10:59:00.2703|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Handshake_SetProtocol
2024-08-16 10:59:00.2703|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Login_LoginStart was added to send queue
2024-08-16 10:59:00.2703|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Login_LoginStart
2024-08-16 10:59:00.6572|TRACE|MineSharp.Protocol.MinecraftClient|Received packet CB_Login_EncryptionBegin. GameState = Login, PacketId = 1
2024-08-16 10:59:00.6572|TRACE|MineSharp.Protocol.MinecraftClient|Handling packet CB_Login_EncryptionBegin
2024-08-16 10:59:00.6783|DEBUG|MineSharp.Auth.MinecraftApi|Sending join server request to mojang.
2024-08-16 10:59:01.1551|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Login_EncryptionBegin was added to send queue
2024-08-16 10:59:01.1551|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Login_EncryptionBegin
2024-08-16 10:59:01.1551|DEBUG|MineSharp.Protocol.MinecraftStream|Enabling encryption.
2024-08-16 10:59:04.1517|ERROR|MineSharp.Data.Protocol.ProtocolData|Failed to get PacketType for: flow = Clientbound, state = Login, id = 27

running it for a second time shows:

2024-08-16 11:04:03.5703|INFO|MineSharp.Protocol.MinecraftClient|Connected, starting handshake...
2024-08-16 11:04:03.5703|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Handshake_SetProtocol was added to send queue
2024-08-16 11:04:03.6104|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Handshake_SetProtocol
2024-08-16 11:04:03.6104|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Login_LoginStart was added to send queue
2024-08-16 11:04:03.6104|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Login_LoginStart
2024-08-16 11:04:03.9977|TRACE|MineSharp.Protocol.MinecraftClient|Received packet CB_Login_EncryptionBegin. GameState = Login, PacketId = 1
2024-08-16 11:04:04.0032|TRACE|MineSharp.Protocol.MinecraftClient|Handling packet CB_Login_EncryptionBegin
2024-08-16 11:04:04.0032|DEBUG|MineSharp.Auth.MinecraftApi|Sending join server request to mojang.
2024-08-16 11:04:04.4417|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Login_EncryptionBegin was added to send queue
2024-08-16 11:04:04.4417|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Login_EncryptionBegin
2024-08-16 11:04:04.4417|DEBUG|MineSharp.Protocol.MinecraftStream|Enabling encryption.
2024-08-16 11:04:09.3285|ERROR|MineSharp.Data.Protocol.ProtocolData|Failed to get PacketType for: flow = Clientbound, state = Login, id = 12086

Third time:

2024-08-16 11:07:35.1127|DEBUG|MineSharp.Protocol.MinecraftClient|Connecting to 127.0.0.1:25565.
2024-08-16 11:07:35.1127|INFO|MineSharp.Protocol.MinecraftClient|Connected, starting handshake...
2024-08-16 11:07:35.1273|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Handshake_SetProtocol was added to send queue
2024-08-16 11:07:35.1659|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Handshake_SetProtocol
2024-08-16 11:07:35.1659|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Login_LoginStart was added to send queue
2024-08-16 11:07:35.1659|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Login_LoginStart
2024-08-16 11:07:35.1659|TRACE|MineSharp.Protocol.MinecraftClient|Received packet CB_Login_EncryptionBegin. GameState = Login, PacketId = 1
2024-08-16 11:07:35.1762|TRACE|MineSharp.Protocol.MinecraftClient|Handling packet CB_Login_EncryptionBegin
2024-08-16 11:07:35.1892|DEBUG|MineSharp.Auth.MinecraftApi|Sending join server request to mojang.
2024-08-16 11:07:35.5325|TRACE|MineSharp.Protocol.MinecraftClient|Packet SB_Login_EncryptionBegin was added to send queue
2024-08-16 11:07:35.5325|TRACE|MineSharp.Protocol.MinecraftClient|Sending packet SB_Login_EncryptionBegin
2024-08-16 11:07:35.5325|DEBUG|MineSharp.Protocol.MinecraftStream|Enabling encryption.
2024-08-16 11:07:35.8401|ERROR|MineSharp.Data.Protocol.ProtocolData|Failed to get PacketType for: flow = Clientbound, state = Login, id = 39049

@Klotzi111
Copy link
Contributor

It seems that encryption handling is broken. I will look into this. But in the mean time you can try using an offline bot (on an offline server of course) and see if that works for you. Because encryption is only used in online mode.
Use the OfflineSession method on the BotBuilder for that. The README file of the repo has this as an example.

Thanks for reporting.

@Klotzi111
Copy link
Contributor

I fixed the problem. You can use the main branch of my forked repo. It should work now.
Please reply if it still does not work with that branch.

@Apocritas99
Copy link
Author

i tried with your repo and got the following error

2024-08-16 17:30:12.4170|INFO|MineSharp.Protocol.MinecraftClient|Connected, starting handshake...
2024-08-16 17:30:12.4855|DEBUG|MineSharp.Protocol.MinecraftStream|Enabling encryption.
2024-08-16 17:30:13.2211|DEBUG|MineSharp.Protocol.Packets.Handlers.LoginPacketHandler|Enabling compression, threshold = 256.
2024-08-16 17:30:13.2211|ERROR|MineSharp.Protocol.MinecraftClient|Encountered exception while dispatching packet SB_Configuration_Settings|System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Frozen.FrozenDictionary`2.get_Item(TKey key)
   at MineSharp.Data.Protocol.ProtocolData.GetPacketId(PacketType type) in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Data\MineSharp.Data\Protocol\ProtocolData.cs:line 25
   at MineSharp.Protocol.MinecraftClient.DispatchPacket(IPacket packet) in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 584
   at MineSharp.Protocol.MinecraftClient.SendPackets() in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 559
2024-08-16 17:30:13.2412|WARN|MineSharp.Protocol.MinecraftClient|An packet handler for packet of type CB_Login_Success threw an exception.|System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Frozen.FrozenDictionary`2.get_Item(TKey key)
   at MineSharp.Data.Protocol.ProtocolData.GetPacketId(PacketType type) in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Data\MineSharp.Data\Protocol\ProtocolData.cs:line 25
   at MineSharp.Protocol.MinecraftClient.DispatchPacket(IPacket packet) in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 584
   at MineSharp.Protocol.MinecraftClient.SendPackets() in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 559
   at MineSharp.Protocol.MinecraftClient.SendPacket(IPacket packet, CancellationToken cancellation) in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 289
   at MineSharp.Protocol.Packets.Handlers.PlayPacketHandler.StateEntered() in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\Packets\Handlers\PlayPacketHandler.cs:line 27
   at MineSharp.Protocol.MinecraftClient.ChangeGameState(GameState next) in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 444
   at MineSharp.Protocol.Packets.Handlers.LoginPacketHandler.HandleLoginSuccess(LoginSuccessPacket packet) in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\Packets\Handlers\LoginPacketHandler.cs:line 128
   at MineSharp.Protocol.MinecraftClient.HandleIncomingPacket(PacketType packetType, PacketBuffer buffer) in D:\Weas\Repos\C#\MyMineSharp\Klotzi\MineSharp\Components\MineSharp.Protocol\MinecraftClient.cs:line 710

@psu-de
Copy link
Owner

psu-de commented Aug 16, 2024

It will work on 1.20.4.
This exception is thrown because we send a packet used in 1.20.4 in all versions before.
I already fixed it on this main branch, however this branch doesn't have @Klotzi111's changes to the encryption.

@Klotzi111
Copy link
Contributor

Ok so the encryption problem is gone.
I messed up that there are 2 different ClientInformationPackets one for Play and one for Configuration.
But I fixed it now.
Please try again

@Klotzi111
Copy link
Contributor

Klotzi111 commented Aug 16, 2024

Oh we double fixed it :D
I like my fix better because I depend on the GameState rather than the version. But yours works too

I created #76

@Apocritas99
Copy link
Author

now it works good guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants