|
@@ -0,0 +1,56 @@
|
|
|
+#include "customknight.h"
|
|
|
+
|
|
|
+#include <bearssl_hash.h>
|
|
|
+#include <stdlib.h>
|
|
|
+
|
|
|
+#include "player.h"
|
|
|
+#include "protocol.h"
|
|
|
+
|
|
|
+PacketReadResult handle_texture_receive(Player* player, char* data, int length,
|
|
|
+ int pos) {
|
|
|
+ (void)player;
|
|
|
+
|
|
|
+ int texture_length;
|
|
|
+ READ_INT(texture_length);
|
|
|
+ if (texture_length > 20000000) {
|
|
|
+ // Over 20mb really ? That's going to be a 'no from me'.
|
|
|
+ return PLAYER_DESERVES_KICK;
|
|
|
+ }
|
|
|
+
|
|
|
+ uv_fs_t open_req = {0};
|
|
|
+ open_req.data = malloc(texture_length);
|
|
|
+ READ_BYTES(open_req.data, texture_length);
|
|
|
+
|
|
|
+ /* br_sha1_context ctx = {0};
|
|
|
+ br_sha1_init(&ctx);
|
|
|
+ br_sha1_update(&ctx, open_req->data, texture_length);
|
|
|
+
|
|
|
+ unsigned char sha1[HASH_LENGTH];
|
|
|
+ br_sha1_out(&ctx, sha1);
|
|
|
+
|
|
|
+ char sha1_str[HASH_LENGTH * 2 + 7] = "skins/";
|
|
|
+ for (int i = 0; i < HASH_LENGTH; i++) {
|
|
|
+ sprintf(sha1_str + 6 + i * 2, "%02X", buf[i])
|
|
|
+ }
|
|
|
+ sha1_str[HASH_LENGTH * 2 + 6] = '\0';
|
|
|
+
|
|
|
+ int fd = uv_fs_open(uv_default_loop(), &open_req, sha1_str, O_CREAT,
|
|
|
+ O_WRONLY, save_texture);*/
|
|
|
+
|
|
|
+ /* FILE* outfile = fopen(sha1_str, "w");
|
|
|
+ fwrite(open_req->data, 1, texture_length, outfile);
|
|
|
+ fclose(outfile);*/
|
|
|
+
|
|
|
+ return DONE_READING;
|
|
|
+}
|
|
|
+
|
|
|
+PacketReadResult handle_texture_request(Player* player, char* data, int length,
|
|
|
+ int pos) {
|
|
|
+ unsigned char sha1[HASH_LENGTH];
|
|
|
+ READ_BYTES(sha1, HASH_LENGTH);
|
|
|
+
|
|
|
+ // TODO: send texture
|
|
|
+ (void)player;
|
|
|
+
|
|
|
+ return DONE_READING;
|
|
|
+}
|