summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/WorldValidator.java
blob: dbfd629148be3325bf7f5ea2807ee9ed7eb51627 (plain) (blame)
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
package NET.worlds.scape;

import NET.worlds.console.Console;
import NET.worlds.core.IniFile;
import NET.worlds.network.Cache;
import NET.worlds.network.CacheFile;
import NET.worlds.network.NetUpdate;
import NET.worlds.network.URL;
import java.io.RandomAccessFile;
import java.util.Vector;

public class WorldValidator {
   static Vector worldList = null;
   private static final boolean debug = true;

   public static boolean allow(String worldName) {
      if (IniFile.gamma().getIniInt("FreeFreeFree", 1) == 1) {
         return true;
      } else if (NetUpdate.isInternalVersion()) {
         return true;
      } else {
         Console c = Console.getActive();
         if (c != null && !c.getGalaxy().getOnline()) {
            return true;
         } else {
            if (worldList == null) {
               try {
                  initializeList();
               } catch (Exception var3) {
                  return true;
               }
            }

            if (worldList == null) {
               return true;
            } else {
               worldName = normalize(worldName);
               System.out.println("Validating " + worldName);
               boolean allow = worldList.contains(worldName);
               System.out.println(allow);
               return allow;
            }
         }
      }
   }

   public static void initializeList() throws Exception {
      String worldListFile = NetUpdate.getUpgradeServerURL() + "tables/worlds.txt";
      URL worldListURL = URL.make(worldListFile);
      CacheFile cf = Cache.getFile(worldListURL, true);
      cf.waitUntilLoaded();
      if (!cf.error()) {
         boolean foundAtLeastOneEntry = false;
         worldList = new Vector();
         RandomAccessFile f = new RandomAccessFile(cf.getLocalName(), "r");

         while (f.getFilePointer() < f.length()) {
            String line = f.readLine();
            if (line.indexOf(".world") != -1) {
               line = normalize(line);
               foundAtLeastOneEntry = true;
               System.out.println("Adding world " + line);
               worldList.addElement(line);
            }
         }

         f.close();
         if (!foundAtLeastOneEntry) {
            throw new Exception();
         }
      } else {
         throw new Exception();
      }
   }

   private static String normalize(String worldName) {
      String out = URL.make(worldName).getAbsolute();
      if (out.startsWith("home:/")) {
         out = "home:" + out.substring(6);
      }

      return out.toLowerCase().trim();
   }
}