@Override
	public void received(Connection connection, Object object)
	{
		// Check if this is the first message from that connection.
		if(!server.clientsByIP.containsKey(connection))
		{
			// New connection, add it to the client list, and do it concurrently
			Client new_client = new Client();
			Client previous_value = 
					server.clientsByIP.putIfAbsent(connection, new_client);
			
			// Now make sure we didn't have another thread trying to register itself
			// at the same time.
			if(previous_value != null)
			{
				Thread.dumpStack();
				System.out.println("Unhandled concurrency violation.");
				System.exit(1);
			}
			
			// Try to handle a login message
			boolean login_success = false;
			
			// Okay, looks like we're the only one. Try to register the client.
			if(object instanceof LoginRequest)
			{
				LoginRequest request = (LoginRequest) object;
				if(server.handleLoginRequest(request.account_name, request.password))
				{
					login_success = true; // We're good, bro

					// Notify the client that the login was successful
					LoginAccepted data = new LoginAccepted();
					data.tick = server.getTick();
					connection.sendTCP(data);
					
					// Finish initializing the client.
					new_client.account_name = request.account_name;
					new_client.connection = new ClientConnection(new_client, connection);
					new_client.initialize();
				}
			}
			
			if(!login_success)
			{
				// Login seems to have failed, kill the connection
				connection.close();
			}
		}
	}