Minecraft Bot

I am working on a bot for mine craft for now I am just trying to get it to connect. If anyone can help it will be nice the protocol is here:http://www.wiki.vg/Protocol#Login_Request_.280x01.29
1
2
3
4
5
6
7
8
9
10
11
/*
Packets.h
This is a list of minecraft packets*/
#ifndef _Packets_H
#define _Packets_H
#include <winsock2.h>
#include <stdio.h>
#include <string.h>
char *handshake="  ' f e a f ; 1 2 7 . 0 . 0 . 1 : 2 5 5 6 5";
char *login="        f e a f              ";
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//Bot.c
#include "Packets.h"

int main()
{
    WORD Ver = MAKEWORD(2, 2);
    WSADATA wsaData;
    int err;
    SOCKET sock;
    err = WSAStartup(Ver, &wsaData);
    if (err != 0) 
    {                               
        printf("Error: %d\n", err);
        return 1;
    }
    sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (sock == INVALID_SOCKET) 
        {
        printf("Failed to create socket\n");
        WSACleanup();
        return 1;
    }
    sockaddr_in clientService;
    clientService.sin_family = AF_INET;
    clientService.sin_addr.s_addr = inet_addr("127.0.0.1");
    clientService.sin_port = htons(25565);
    err = connect(sock, (SOCKADDR *) & clientService, sizeof (clientService));
        if (err == SOCKET_ERROR) {
        printf("failed to connect\n");
        err = closesocket(sock);
        if (err == SOCKET_ERROR)
            printf("failed to close socket\n");
        WSACleanup();
        return 1;
    }
    printf("Connected\n");
    Sleep(1000);
    //This format must be preserved
    printf("Sending 0x02\n");
    //Send 0x02 Handshake
    err = send(sock, handshake, (int)strlen(handshake), 0);
    if (err == SOCKET_ERROR) {
        wprintf(L"send failed with error: %d\n", WSAGetLastError());
        closesocket(sock);
        WSACleanup();
        return 1;
    }
    char reciver[20];
    int recvbuflen = 20;
    err = recv(sock, reciver, recvbuflen, 0);
    if ( err > 0 )
            printf("Bytes received: %d\n", err);
        else if ( err == 0 )
            printf("Connection closed\n");
        else
            printf("recv failed: %d\n", WSAGetLastError());
            Sleep(3000);
    //Send 0x01 Login
    err = send(sock, login, (int)strlen(login), 0);
        if (err == SOCKET_ERROR) {
        wprintf(L"send failed with error: %d\n", WSAGetLastError());
        closesocket(sock);
        WSACleanup();
        return 1;
    }
    //Not used for now
    while(0);
    {
             char *Inside;
             err = recv(sock, Inside, recvbuflen, 0);
                     if ( err > 0 )
            printf("Bytes received: %d\n", err);
        else if ( err == 0 )
            printf("Connection closed\n");
        else
            printf("recv failed: %d\n", WSAGetLastError());
            Sleep(3000);
    }
}

The handshake is sent but it closes the connection soon afterwords
Note: I haven't added any code to handle the incoming data yet.
Topic archived. No new replies allowed.