3232import java .security .MessageDigest ;
3333import java .security .NoSuchAlgorithmException ;
3434import java .security .SecureRandom ;
35+ import java .util .Arrays ;
3536import java .util .Optional ;
3637import java .util .UUID ;
3738import java .util .function .Supplier ;
@@ -47,21 +48,37 @@ public enum AssetType {
4748 public String subdir () {
4849 return "textures" ;
4950 }
51+
52+ @ Override
53+ public boolean is_valid_extension (String extension ) {
54+ return extension .equals ("png" ) || extension .equals ("mcmeta" );
55+ }
5056 },
5157 model {
5258 @ Override
5359 public String subdir () {
5460 return "models" ;
5561 }
62+
63+ @ Override
64+ public boolean is_valid_extension (String extension ) {
65+ return extension .equals ("json" );
66+ }
5667 },
5768 item_definition {
5869 @ Override
5970 public String subdir () {
6071 return "items" ;
6172 }
73+
74+ @ Override
75+ public boolean is_valid_extension (String extension ) {
76+ return extension .equals ("json" );
77+ }
6278 };
6379
6480 public abstract String subdir ();
81+ public abstract boolean is_valid_extension (String extension );
6582
6683 public static AssetType from_string (String type ) {
6784 switch (type ) {
@@ -123,6 +140,14 @@ public PackerManager(DedicatedServer server) {
123140 }
124141
125142 public void upload_file (UUID uploader , AssetType type , String name , byte [] contents ) throws IOException {
143+ // Check contents
144+ if (contents .length > PackerConfig .max_upload_bytes ) throw new IOException ("File too big. Limit: " +PackerConfig .max_upload_bytes +" Bytes" );
145+
146+ var split_name = name .split ("\\ ." );
147+ var ext = split_name [split_name .length -1 ];
148+ if (!type .is_valid_extension (ext )) throw new IOException ("Invalid extension for upload type!" );
149+
150+ // Preform upload
126151 Path user_path = assets_path .resolve (uploader .toString ());
127152 if (!Files .exists (user_path )) { Files .createDirectory (user_path ); }
128153 Path asset_path = user_path .resolve (type .subdir ());
@@ -173,8 +198,6 @@ public void rezip_pack() throws IOException{
173198
174199 String url = "http://" +PackerConfig .server_address + ":" + PackerConfig .port + "/api/pack.zip" ;
175200 String hash = getSHA1 (zip_path .toFile ());
176- Packer .LOGGER .info (url );
177- Packer .LOGGER .info (hash );
178201 packinfo = new MinecraftServer .ServerResourcePackInfo (UUID .randomUUID (), url ,
179202 hash , true , Component .literal ("Please accept the Packer resource pack!." ));
180203 }
@@ -285,7 +308,7 @@ public static void register_command(CommandDispatcher<CommandSourceStack> dispat
285308 return 0 ;
286309 }
287310 stack .set (DataComponents .ITEM_MODEL , stack .getItem ().components ().get (DataComponents .ITEM_MODEL ));
288-
311+
289312 return 1 ;
290313 }));
291314 node .then (model_node );
0 commit comments