/*
 * Copyright (c) 2022 Asynchronous Game Query Library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.ibasco.agql.examples;

import com.ibasco.agql.examples.base.BaseExample;
import com.ibasco.agql.protocols.valve.steam.master.MasterServerFilter;
import com.ibasco.agql.protocols.valve.steam.master.client.MasterServerQueryClient;
import com.ibasco.agql.protocols.valve.steam.master.enums.MasterServerRegion;
import com.ibasco.agql.protocols.valve.steam.master.enums.MasterServerType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

public class MasterQueryExample extends BaseExample {

    private static final Logger log = LoggerFactory.getLogger(MasterQueryExample.class);

    private MasterServerQueryClient client;

    private final Set<InetSocketAddress> addressSet = new HashSet<>();

    public static void main(String[] args) throws Exception {
        new MasterQueryExample().run(args);
    }

    @Override
    public void run(String[] args) throws Exception {
        client = new MasterServerQueryClient();
        this.listAllServers();
    }

    @Override
    public void close() throws IOException {
        client.close();
    }

    public void listAllServers() {
        int appId = Integer.parseInt(promptInput("Please enter an App ID (optional): ", false, "-1"));

        MasterServerFilter filter = MasterServerFilter.create().dedicated(true).isEmpty(false);

        if (appId > 0)
            filter.appId(appId);

        log.info("Displaying Non-Empty servers for App Id: {}", (appId > 0) ? appId : "N/A");
        Vector<InetSocketAddress> addresses = null;
        try {
            addressSet.clear();
            addresses = client.getServerList(MasterServerType.SOURCE, MasterServerRegion.REGION_ALL, filter, this::displayIpStream).join();
        } catch (Exception e) {
            e.printStackTrace(System.err);
        } finally {
            if (addresses != null)
                log.info("Done (Total: {})", addresses.size());
        }

    }

    public void displayIpStream(InetSocketAddress address, InetSocketAddress sender, Throwable error) {
        if (addressSet.add(address)) {
            log.info("Received Server Address : {}", address);
        } else {
            log.info("Received Server Address (DUPLICATE) : {}", address);
        }
    }
}

@@ -1721,24 +1721,48 @@
 lServers();%0A
+        System.exit(0);%0A
     %7D%0A%0A    @
@@ -1967,25 +1967,52 @@
 onal
+ %7C -1 default
 ): %22, 
-fals
+tru
 e, %22-1%22
+, %22masterAppId%22
 ));%0A
@@ -2648,34 +2648,77 @@
     
-log.info(%22Done (Total: %7B%7D)
+System.out.printf(%22%5C033%5B0;32mDONE%5C033%5B0m %5C033%5B0;36m(Total: %25d)%5C033%5B0m
 %22, a
@@ -2723,18 +2723,19 @@
  address
-es
+Set
 .size())
@@ -2742,25 +2742,24 @@
 ;%0A        %7D%0A
-%0A
     %7D%0A%0A    p
@@ -2912,46 +2912,91 @@
     
-log.info(%22Received Server Address : %7B%7D
+System.out.printf(%22%5C033%5B0;34mReceived Server Address :%5C033%5B0m %5C033%5B0;33m%25s%5C033%5B0m%5Cn
 %22, a
@@ -3033,26 +3033,45 @@
         
-log.info(%22
+System.out.printf(%22%5C033%5B0;31m
 Received
@@ -3100,18 +3100,27 @@
 CATE) : 
-%7B%7D
+%25s%5C033%5B0m%5Cn
 %22, addre

Add exit call