@Override
	public void run() {
		try {
			try {
				System.out.println("opening streams");
				this.input = getBufferedReader(client.getInputStream());
				this.output = getPrintStream(client.getOutputStream());
				
				System.out.println("Opened streams");
				
				Command handshake = new Command(input, false);

				if (!handshake.getCommand().equals(ServerProtocol.HANDSHAKE)) {
					throw new ProtocolException(
							"First packet no handshake",
							ServerProtocol.ERROR_HANDSHAKE_MISSING);
				}
				for (String online : server.getUserNames()) {
					if (handshake.getArgument(0).equalsIgnoreCase(online)) {
						throw new ProtocolException("Double client", 
								ServerProtocol.ERROR_INVALID_LOGIN);
					}
				}
				
				

				user = new HumanPlayer(handshake.getArgument(0));
				server.addUser(user);
				clientSupports = Integer.parseInt(handshake.getArgument(1));
				clientVersion = handshake.getArgument(2);

				handshake(Server.GLOBAL_SUPPORTS, Server.GLOBAL_VERSION);
				
				server.sendGames(this);
				
				System.out.println("Start reading commands");
				while (true) {
					handlePacket(new Command(input, false));
				}
			} catch (ProtocolException e) {
				e.getMessage();
				error(e.getCode());
				client.close();
				System.out.println("Connection to Client closed");
			}
		} catch (IOException e) {
			e.getMessage();
		}
		
	}