-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
93 lines (76 loc) · 2.07 KB
/
main.c
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <stdint.h>
#include <wiringPiSPI.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include "account.h"
#include "multiboot.h"
#include "udp.h"
uint32_t incoming_buffer[30];
uint32_t incoming_buffer_position = 0;
uint32_t expected_length = 0;
void transfer(uint32_t out) {
uint32_t data = Spi32(out);
if (expected_length == 0) {
expected_length = data;
incoming_buffer_position = 0;
return;
}
incoming_buffer[incoming_buffer_position++] = data;
if (incoming_buffer_position >= expected_length) {
udp_send_location(incoming_buffer, expected_length * 4);
expected_length = 0;
incoming_buffer_position = 0;
}
}
int main(int argc, char* argv[]) {
udp_init();
if (!login()) {
printf("Welcome to GBA-MMO! To create an account, first enter your email:\n");
char *email = NULL;
size_t email_len = 0;
getline(&email, &email_len, stdin);
printf("\nEnter your character name:\n");
char *name = NULL;
size_t name_len = 0;
getline(&name, &name_len, stdin);
// Remove trailing new line
name[strlen(name)-1] = '\0';
email[strlen(email)-1] = '\0';
printf("\n\nCreating account...\n");
if (!create_account(name, email)) {
printf("Failed to create account!\n\n");
return 0;
}
if (!login()) {
printf("Failed to log in after creating account!\n\n");
return 0;
}
printf("\nThanks for joining!\n\n");
}
printf("\nIf you haven't already, join the discord at: https://discord.gg/B3wJYnUswN\n\n");
multiboot("gba_mmo.gba");
uint32_t buffer_len = 512;
char buffer[512];
while (1) {
int rec_size = read_server_update(buffer, buffer_len);
if (rec_size > 0) {
uint32_t d;
transfer((rec_size + 4) | 0xBEEF0000);
usleep(1000);
for (int i = 0; i < rec_size; i++) {
d =
(buffer[i++] << 24) |
(buffer[i++] << 16) |
(buffer[i++] << 8) |
(buffer[i]);
transfer(d);
usleep(1000);
}
transfer(0xDEADBEEF);
usleep(1000);
}
}
return 0;
}