@Override
	public void run() {
		try {
			new LoginProtocol(s, in, out, inStream, getOutStream(), playerId);
			flushOutStream();
		} catch (IOException e) {
			e.printStackTrace();
		}
		buffer = new byte[BUFFER_SIZE];
		readPtr = 0;
		writePtr = 0;

		int position, offset;

		while (!disconnected && online) {
			synchronized (this) {
				if (writePtr == readPtr) {
					try {
						wait();
					} catch (java.lang.InterruptedException _ex) {
					}
				}
				offset = readPtr;
				if (writePtr >= readPtr) {
					position = writePtr - readPtr;
				} else {
					position = BUFFER_SIZE - readPtr;
				}
			}
			if (position > 0) {
				try {
					out.write(buffer, offset, position);
					readPtr = (readPtr + position) % BUFFER_SIZE;
					if (writePtr == readPtr) {
						out.flush();
					}
				} catch (Exception e) {
					destruct();
				}
			}
		}
	}