Trying to connect to a Minecraft server with sockets
2 replies, posted
I'm trying to connect to my Minecraft server with C#, but it seems I'm doing something wrong.
[cpp] TcpClient C = new TcpClient("localhost", 25565);
NetworkStream s = C.GetStream();
byte[] datac = { 0, 7 };
char[] username = "Dlaor".ToCharArray();
byte[] addstuff = Encoding.GetBytes(username);
addstuff.CopyTo(datac, 0);
s.Write(datac, 0, 131);[/cpp]
First problem: I don't get the byte array stuff at all.
See [url]http://www.minecraftwiki.net/wiki/Development_Resources[/url] the "Player identification" table. How the hell would I turn that into one big string to convert into a byte array for sending to the socket stream?
Second problem:
[cpp]byte[] addstuff = Encoding.GetBytes(username);[/cpp]
Gives me an error.
[code]An object reference is required for the non-static field, method, or property 'System.Text.Encoding.GetBytes(char[])'[/code]
Any help here?
[editline]09:22PM[/editline]
Ok, I found a good example on how to turn a string into a byte array.
[cpp] byte[] myWriteBuffer = Encoding.ASCII.GetBytes("Are you receiving this message?");
myNetworkStream.Write(myWriteBuffer, 0, myWriteBuffer.Length);[/cpp]
But I still don't know what the correct string is for sending a Player Identification packet. Any ideas?
I have no idea what this verification key is, but you need to add spaces either in front or after the username (the document doesn't seem to specify this) until it's 64 chars long.
[editline]09:59PM[/editline]
I think you should use a network sniffer to read packets the original client sends.
Look here: [URL="http://www.minecraftwiki.net/wiki/Development_Resources"]http://www.minecraftwiki.net/wiki/Development_Resources[/URL]
Also, you should come by #CCoalition @ irc.esper.net
We can probably help you there.
Sorry, you need to Log In to post a reply to this thread.