private void handleReadyKey(SelectionKey key) throws IOException {
		if ((key.readyOps() & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT) {
			// accept the new connection
			ServerSocketChannel newChannel = (ServerSocketChannel)key.channel();
			SocketChannel sc = newChannel.accept();
			sc.configureBlocking(false);
			sc.register(selector, SelectionKey.OP_READ);
			pendingConnections.put(sc, new PlayerConnection(sc, sc.getRemoteAddress()));
			System.out.println("[Server] Accepted connection from " + sc.getRemoteAddress());
		} else if ((key.readyOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
			SocketChannel sc = (SocketChannel) key.channel();
			PlayerConnection conn = pendingConnections.get(sc);
			ServerPlayer player = null;
			if (conn == null) {
				player = clients.get(sc);
				conn = player.getConnection();
			}

			Packet packet = conn.read();
			if (packet == null) {
				if (!conn.isConnected()) {
					pendingConnections.remove(sc);
					// TODO: possibly notify of unexpected disconnect
					ServerPlayer removed = clients.remove(sc);
					if (removed != null) game.removePlayer(removed);
					System.out.println("[Server] Connection from " + conn.getRemoteAddress() + " disconnected");
				} else {
					System.out.println("[Server] Malformed data received from " + conn.getRemoteAddress());
				}
				return;
			}

			System.out.println("[Server] Received data from " + conn.getRemoteAddress() + ": " + packet.toString());
			if (player == null) {
				if (packet instanceof ConnectPacket) {
					ConnectPacket connect = (ConnectPacket)packet;
					pendingConnections.remove(sc);
					player = new ServerPlayer(game, conn, connect.name);
					clients.put(sc, player);
					game.addPlayer(player);
					System.out.println("[Server] " + connect.name + " connected from " + conn.getRemoteAddress());
				} else {
					System.err.println("[Server] Pending connection from " + conn.getRemoteAddress() + " sent something other than ConnectPacket: " + packet.getClass().getSimpleName());
					return;
				}
			}

			player.handle(packet);
		} else {
			System.out.println("[Server] Unknown readyops: " + key.readyOps());
		}
	}