/* */ package NET.worlds.network; /* */ /* */ import NET.worlds.console.StatNetMUNode; /* */ import java.io.ByteArrayInputStream; /* */ import java.io.IOException; /* */ import java.io.PrintStream; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class netPacketReader /* */ extends Thread /* */ { /* */ private Vector _msgQ; /* */ private ServerInputStream _in; /* */ private WorldServer _serv; /* */ private static Class[] msgTable; /* */ /* */ public netPacketReader(ServerInputStream in) /* */ { /* 95 */ this._in = in; /* 96 */ this._msgQ = new Vector(); /* */ } /* */ /* */ public netPacketReader(WorldServer serv, ServerInputStream in) { /* 100 */ this._serv = serv; /* 101 */ this._in = in; /* 102 */ this._msgQ = new Vector(); /* 103 */ this._in.setVersion(getVersion()); /* */ } /* */ /* */ /* */ /* */ public void setVersion(int vers) /* */ { /* 110 */ this._in.setVersion(vers); /* */ } /* */ /* */ /* */ /* */ public int getVersion() /* */ { /* 117 */ return this._serv.getVersion(); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public void put(receivedNetPacket pkt) /* */ { /* 126 */ this._msgQ.addElement(pkt); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public receivedNetPacket get() /* */ { /* 139 */ assert (this._msgQ != null); /* 140 */ if (this._msgQ.isEmpty()) { /* 141 */ return null; /* */ } /* 143 */ receivedNetPacket packet = (receivedNetPacket)this._msgQ.firstElement(); /* 144 */ this._msgQ.removeElement(packet); /* 145 */ return packet; /* */ } /* */ /* */ public int count() /* */ { /* 150 */ return this._msgQ.size(); /* */ } /* */ /* */ /* */ static /* */ { /* 156 */ msgTable = new Class['ΓΏ']; /* */ /* 158 */ String basePath = "NET.worlds.network."; /* */ /* 160 */ Vector cmdList = new netCmds().recvCmdList(); /* */ /* */ /* */ /* */ /* 165 */ for (int i = 0; i < cmdList.size(); i++) { /* 166 */ String cmdName = basePath + (String)cmdList.elementAt(i); /* */ /* */ try /* */ { /* 170 */ Class tmpCmdClass = Class.forName(cmdName); /* 171 */ receivedNetPacket tmpInstance = (receivedNetPacket)tmpCmdClass.newInstance(); /* 172 */ int indx = tmpInstance.msgID(); /* 173 */ assert (indx > -1); /* 174 */ assert (msgTable[indx] == null); /* 175 */ msgTable[indx] = tmpCmdClass; /* */ /* */ } /* */ catch (NoSuchMethodError e) /* */ { /* */ /* 181 */ synchronized (System.out) { /* 182 */ System.out.println("netPacketReader:: " + /* 183 */ e.getClass().getName() + " creating " + cmdName); /* 184 */ System.out.println("netPacketReader:: Exception: " + /* 185 */ e.getMessage()); /* 186 */ e.printStackTrace(System.out); /* */ } /* 188 */ if (!$assertionsDisabled) throw new AssertionError(); /* */ } /* */ catch (Exception e) { /* 191 */ synchronized (System.out) { /* 192 */ System.out.println("netPacketReader:: " + /* 193 */ e.getClass().getName() + " creating " + /* 194 */ cmdName); /* 195 */ System.out.println("netPacketReader:: Exception: " + /* 196 */ e.getMessage()); /* 197 */ e.printStackTrace(System.out); /* */ } /* */ /* 200 */ if (!$assertionsDisabled) { throw new AssertionError(); /* */ } /* */ } /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private final void buildMsg() /* */ throws IOException /* */ { /* 245 */ this._in.readPacketSize(); /* */ /* */ /* */ /* 249 */ byte[] packetData = new byte[this._in.bytesLeft() + 1]; /* */ /* 251 */ packetData[0] = ((byte)(this._in.bytesLeft() + 1)); /* 252 */ this._in.readFully(packetData, 1, this._in.bytesLeft()); /* */ /* */ /* 255 */ StatNetMUNode netStat = StatNetMUNode.getNode(); /* 256 */ netStat.addBytesRcvd(packetData.length); /* 257 */ netStat.addPacketsRcvd(1); /* */ /* */ /* 260 */ ServerInputStream in = new ServerInputStream(new ByteArrayInputStream( /* 261 */ packetData)); /* 262 */ in.readPacketSize(); /* */ /* 264 */ if ((WorldServer.getDebugLevel() & 0x800) > 0) { /* 265 */ synchronized (System.out) { /* 266 */ System.out.print(this._serv + ": recv["); /* 267 */ for (int i = 0; i < packetData.length; i++) /* 268 */ System.out.print(Integer.toString( /* 269 */ packetData[i] & 0xFF, 16) + " "); /* 270 */ System.out.println("]"); /* */ } /* */ } /* */ /* */ /* */ /* 276 */ receivedNetPacket packet = null; /* 277 */ ObjID objID = new ObjID(); /* */ /* 279 */ objID.parseNetData(in); /* */ /* 281 */ boolean isCO = objID.shortID() == 254; /* */ /* 283 */ int cmdType = in.readUnsignedByte(); /* */ /* 285 */ if ((cmdType >= msgTable.length) || (msgTable[cmdType] == null)) /* */ { /* 287 */ System.out.println("UNKNOWN SERVER MSG#" + String.valueOf(cmdType)); /* */ /* 289 */ in.skipBytes(in.bytesLeft()); /* 290 */ assert (in.isEmpty()); /* */ } /* */ else /* */ { /* */ do { /* 295 */ if (isCO) /* */ { /* 297 */ objID = new ObjID(); /* 298 */ objID.parseNetData(in); /* */ } /* */ try { /* 301 */ packet = (receivedNetPacket)msgTable[cmdType].newInstance(); /* */ } catch (Exception e) { /* 303 */ System.out.println(e + ": " + e.getMessage()); /* 304 */ if (!$assertionsDisabled) throw new AssertionError(); /* */ } /* 306 */ packet.init(objID); /* */ /* 308 */ packet.parseNetData(in); /* */ /* */ /* */ /* */ /* */ /* 314 */ this._msgQ.addElement(packet); /* 315 */ yield(); /* */ } /* 317 */ while ((!in.isEmpty()) && (isCO)); /* 318 */ assert (in.isEmpty()); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void run() /* */ { /* */ try /* */ { /* */ for (;;) /* */ { /* 342 */ buildMsg(); /* */ } /* */ /* */ } /* */ catch (IOException e) /* */ { /* 348 */ this._msgQ.addElement(new ExceptionCmd(e)); /* */ } /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\network\netPacketReader.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */