summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/WorldValidator.java
blob: fb0e6bfdc9fdedcf6926823fdb406bcd34b0be25 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*     */ 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.Galaxy;
/*     */ import NET.worlds.network.NetUpdate;
/*     */ import NET.worlds.network.URL;
/*     */ import java.io.PrintStream;
/*     */ import java.io.RandomAccessFile;
/*     */ import java.util.Vector;
/*     */ 
/*     */ 
/*     */ public class WorldValidator
/*     */ {
/*  17 */   static Vector<String> worldList = null;
/*     */   
/*     */   private static final boolean debug = true;
/*     */   
/*     */   public static boolean allow(String worldName)
/*     */   {
/*  23 */     if (IniFile.gamma().getIniInt("FreeFreeFree", 1) == 1) {
/*  24 */       return true;
/*     */     }
/*  26 */     if (NetUpdate.isInternalVersion()) {
/*  27 */       return true;
/*     */     }
/*  29 */     Console c = Console.getActive();
/*  30 */     if ((c != null) && (!c.getGalaxy().getOnline())) {
/*  31 */       return true;
/*     */     }
/*  33 */     if (worldList == null)
/*     */     {
/*     */       try
/*     */       {
/*  37 */         initializeList();
/*     */ 
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/*  42 */         return true;
/*     */       }
/*     */     }
/*     */     
/*  46 */     if (worldList == null) {
/*  47 */       return true;
/*     */     }
/*  49 */     worldName = normalize(worldName);
/*     */     
/*     */ 
/*  52 */     System.out.println("Validating " + worldName);
/*     */     
/*  54 */     boolean allow = worldList.contains(worldName);
/*     */     
/*     */ 
/*  57 */     System.out.println(allow);
/*     */     
/*  59 */     return allow;
/*     */   }
/*     */   
/*     */   public static void initializeList() throws Exception
/*     */   {
/*  64 */     String worldListFile = NetUpdate.getUpgradeServerURL() + 
/*  65 */       "tables/worlds.txt";
/*  66 */     URL worldListURL = URL.make(worldListFile);
/*  67 */     CacheFile cf = Cache.getFile(worldListURL, true);
/*  68 */     cf.waitUntilLoaded();
/*  69 */     if (!cf.error())
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  75 */       boolean foundAtLeastOneEntry = false;
/*     */       
/*  77 */       worldList = new Vector();
/*     */       
/*  79 */       RandomAccessFile f = new RandomAccessFile(
/*  80 */         cf.getLocalName(), "r");
/*  81 */       while (f.getFilePointer() < f.length())
/*     */       {
/*  83 */         String line = f.readLine();
/*     */         
/*  85 */         if (line.indexOf(".world") != -1)
/*     */         {
/*  87 */           line = normalize(line);
/*  88 */           foundAtLeastOneEntry = true;
/*     */           
/*  90 */           System.out.println("Adding world " + line);
/*  91 */           worldList.addElement(line);
/*     */         }
/*     */       }
/*     */       
/*  95 */       f.close();
/*     */       
/*  97 */       if (!foundAtLeastOneEntry) {
/*  98 */         throw new Exception();
/*     */       }
/*     */     }
/*     */     else {
/* 102 */       throw new Exception();
/*     */     }
/*     */   }
/*     */   
/*     */   private static String normalize(String worldName)
/*     */   {
/* 108 */     String out = URL.make(worldName).getAbsolute();
/* 109 */     if (out.startsWith("home:/"))
/* 110 */       out = "home:" + out.substring(6);
/* 111 */     return out.toLowerCase().trim();
/*     */   }
/*     */ }


/* Location:              C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\WorldValidator.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */