Connection & GameFrame
This commit is contained in:
1 parent
52ffdc89c9
commit
cc9ff929b2
4 files changed
+720
-808
No files matched your search
+142
-142
@@ -9,155 +9,155 @@ import java.net.Socket;
|
||||
|
||||
public class Connection implements Runnable {
|
||||
|
||||
public final Socket aSocket421;
|
||||
public final GameShell anShell_423;
|
||||
public InputStream anInputStream419;
|
||||
public OutputStream anOutputStream420;
|
||||
public boolean closed = false;
|
||||
public byte[] aByteArray424;
|
||||
public int anInt425;
|
||||
public int anInt426;
|
||||
public boolean aBoolean427 = false;
|
||||
public boolean aBoolean428 = false;
|
||||
public final Socket socket;
|
||||
public final GameShell shell;
|
||||
public InputStream in;
|
||||
public OutputStream out;
|
||||
public boolean closed = false;
|
||||
public byte[] buf;
|
||||
public int tcycl;
|
||||
public int tnum;
|
||||
public boolean writer = false;
|
||||
public boolean ioerror = false;
|
||||
|
||||
public Connection(GameShell shell, Socket socket) throws IOException {
|
||||
anShell_423 = shell;
|
||||
aSocket421 = socket;
|
||||
aSocket421.setSoTimeout(30000);
|
||||
aSocket421.setTcpNoDelay(true);
|
||||
anInputStream419 = aSocket421.getInputStream();
|
||||
anOutputStream420 = aSocket421.getOutputStream();
|
||||
}
|
||||
public Connection(GameShell shell, Socket socket) throws IOException {
|
||||
this.shell = shell;
|
||||
this.socket = socket;
|
||||
this.socket.setSoTimeout(30000);
|
||||
this.socket.setTcpNoDelay(true);
|
||||
in = this.socket.getInputStream();
|
||||
out = this.socket.getOutputStream();
|
||||
}
|
||||
|
||||
public void method267() {
|
||||
closed = true;
|
||||
try {
|
||||
if (anInputStream419 != null) {
|
||||
anInputStream419.close();
|
||||
}
|
||||
if (anOutputStream420 != null) {
|
||||
anOutputStream420.close();
|
||||
}
|
||||
if (aSocket421 != null) {
|
||||
aSocket421.close();
|
||||
}
|
||||
} catch (IOException _ex) {
|
||||
System.out.println("Error closing stream");
|
||||
}
|
||||
aBoolean427 = false;
|
||||
synchronized (this) {
|
||||
notify();
|
||||
}
|
||||
aByteArray424 = null;
|
||||
}
|
||||
public void close() {
|
||||
closed = true;
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (socket != null) {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException _ex) {
|
||||
System.out.println("Error closing stream");
|
||||
}
|
||||
writer = false;
|
||||
synchronized (this) {
|
||||
notify();
|
||||
}
|
||||
buf = null;
|
||||
}
|
||||
|
||||
public int method268() throws IOException {
|
||||
if (closed) {
|
||||
return 0;
|
||||
} else {
|
||||
return anInputStream419.read();
|
||||
}
|
||||
}
|
||||
public int read() throws IOException {
|
||||
if (closed) {
|
||||
return 0;
|
||||
} else {
|
||||
return in.read();
|
||||
}
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
if (closed) {
|
||||
return 0;
|
||||
} else {
|
||||
return anInputStream419.available();
|
||||
}
|
||||
}
|
||||
public int available() throws IOException {
|
||||
if (closed) {
|
||||
return 0;
|
||||
} else {
|
||||
return in.available();
|
||||
}
|
||||
}
|
||||
|
||||
public void method270(byte[] abyte0, int i, int j) throws IOException {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
int k;
|
||||
for (; j > 0; j -= k) {
|
||||
k = anInputStream419.read(abyte0, i, j);
|
||||
if (k <= 0) {
|
||||
throw new IOException("EOF");
|
||||
}
|
||||
i += k;
|
||||
}
|
||||
}
|
||||
public void read(byte[] dst, int off, int len) throws IOException {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
int k;
|
||||
for (; len > 0; len -= k) {
|
||||
k = in.read(dst, off, len);
|
||||
if (k <= 0) {
|
||||
throw new IOException("EOF");
|
||||
}
|
||||
off += k;
|
||||
}
|
||||
}
|
||||
|
||||
public void method271(int i, byte[] abyte0, int k) throws IOException {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
if (aBoolean428) {
|
||||
aBoolean428 = false;
|
||||
throw new IOException("Error in writer thread");
|
||||
}
|
||||
if (aByteArray424 == null) {
|
||||
aByteArray424 = new byte[5000];
|
||||
}
|
||||
synchronized (this) {
|
||||
for (int l = 0; l < i; l++) {
|
||||
aByteArray424[anInt426] = abyte0[l + k];
|
||||
anInt426 = (anInt426 + 1) % 5000;
|
||||
if (anInt426 == ((anInt425 + 4900) % 5000)) {
|
||||
throw new IOException("buffer overflow");
|
||||
}
|
||||
}
|
||||
if (!aBoolean427) {
|
||||
aBoolean427 = true;
|
||||
anShell_423.startThread(this, 3);
|
||||
}
|
||||
notify();
|
||||
}
|
||||
}
|
||||
public void write(byte[] src, int off, int len) throws IOException {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
if (ioerror) {
|
||||
ioerror = false;
|
||||
throw new IOException("Error in writer thread");
|
||||
}
|
||||
if (buf == null) {
|
||||
buf = new byte[5000];
|
||||
}
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
buf[tnum] = src[i + off];
|
||||
tnum = (tnum + 1) % 5000;
|
||||
if (tnum == ((tcycl + 4900) % 5000)) {
|
||||
throw new IOException("buffer overflow");
|
||||
}
|
||||
}
|
||||
if (!writer) {
|
||||
writer = true;
|
||||
shell.startThread(this, 3);
|
||||
}
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (aBoolean427) {
|
||||
int i;
|
||||
int j;
|
||||
synchronized (this) {
|
||||
if (anInt426 == anInt425) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
if (!aBoolean427) {
|
||||
return;
|
||||
}
|
||||
j = anInt425;
|
||||
if (anInt426 >= anInt425) {
|
||||
i = anInt426 - anInt425;
|
||||
} else {
|
||||
i = 5000 - anInt425;
|
||||
}
|
||||
}
|
||||
if (i > 0) {
|
||||
try {
|
||||
anOutputStream420.write(aByteArray424, j, i);
|
||||
} catch (IOException _ex) {
|
||||
aBoolean428 = true;
|
||||
}
|
||||
anInt425 = (anInt425 + i) % 5000;
|
||||
try {
|
||||
if (anInt426 == anInt425) {
|
||||
anOutputStream420.flush();
|
||||
}
|
||||
} catch (IOException _ex) {
|
||||
aBoolean428 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
while (writer) {
|
||||
int i;
|
||||
int j;
|
||||
synchronized (this) {
|
||||
if (tnum == tcycl) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
if (!writer) {
|
||||
return;
|
||||
}
|
||||
j = tcycl;
|
||||
if (tnum >= tcycl) {
|
||||
i = tnum - tcycl;
|
||||
} else {
|
||||
i = 5000 - tcycl;
|
||||
}
|
||||
}
|
||||
if (i > 0) {
|
||||
try {
|
||||
out.write(buf, j, i);
|
||||
} catch (IOException _ex) {
|
||||
ioerror = true;
|
||||
}
|
||||
tcycl = (tcycl + i) % 5000;
|
||||
try {
|
||||
if (tnum == tcycl) {
|
||||
out.flush();
|
||||
}
|
||||
} catch (IOException _ex) {
|
||||
ioerror = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void method272() {
|
||||
System.out.println("closed:" + closed);
|
||||
System.out.println("tcycl:" + anInt425);
|
||||
System.out.println("tnum:" + anInt426);
|
||||
System.out.println("writer:" + aBoolean427);
|
||||
System.out.println("ioerror:" + aBoolean428);
|
||||
try {
|
||||
System.out.println("available:" + available());
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
public void debug() {
|
||||
System.out.println("closed:" + closed);
|
||||
System.out.println("tcycl:" + tcycl);
|
||||
System.out.println("tnum:" + tnum);
|
||||
System.out.println("writer:" + writer);
|
||||
System.out.println("ioerror:" + ioerror);
|
||||
try {
|
||||
System.out.println("available:" + available());
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user